Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the $262 object to Test262 test runner #1296

Merged
merged 4 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions boa/src/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ impl GcObject {
/// If a field was already in the object with the same name that a `Some` is returned
/// with that field, otherwise None is returned.
#[inline]
pub(crate) fn insert_property<K, V>(
pub fn insert_property<K, V>(
&mut self,
key: K,
value: V,
Expand Down Expand Up @@ -711,7 +711,7 @@ impl Object {
/// If a field was already in the object with the same name that a `Some` is returned
/// with that field, otherwise None is retuned.
#[inline]
pub(crate) fn insert_property<K, V>(
pub fn insert_property<K, V>(
&mut self,
key: K,
value: V,
Expand Down
1 change: 1 addition & 0 deletions boa_tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ fxhash = "0.2.1"
git2 = "0.13.20"
hex = "0.4.3"
num-format = "0.4.0"
gc = { version = "0.4.1", features = ["derive"] }
72 changes: 72 additions & 0 deletions boa_tester/src/exec/js262.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use boa::{
exec::Executable,
object::{GcObject, ObjectInitializer},
property::Attribute,
Context, Result, Value,
};

/// Initializes the object in the context.
pub(super) fn init(context: &mut Context) -> GcObject {
let global_obj = context.global_object();

let obj = ObjectInitializer::new(context)
.function(create_realm, "createRealm", 0)
.function(eval_script, "evalScript", 1)
.property("global", global_obj, Attribute::default())
// .property("agent", agent, Attribute::default())
.build();

context.register_global_property("$262", obj.clone(), Attribute::default());

obj
}

/// The `$262.createRealm()` function.
///
/// Creates a new ECMAScript Realm, defines this API on the new realm's global object, and
/// returns the `$262` property of the new realm's global object.
fn create_realm(_this: &Value, _: &[Value], _context: &mut Context) -> Result<Value> {
// eprintln!("called $262.createRealm()");

let mut context = Context::new();

// add the $262 object.
let js_262 = init(&mut context);

Ok(Value::from(js_262))
}

/// The `$262.detachArrayBuffer()` function.
///
/// Implements the `DetachArrayBuffer` abstract operation.
#[allow(dead_code)]
fn detach_array_buffer(_this: &Value, _: &[Value], _context: &mut Context) -> Result<Value> {
todo!()
}

/// The `$262.evalScript()` function.
///
/// Accepts a string value as its first argument and executes it as an ECMAScript script.
fn eval_script(_this: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
// eprintln!("called $262.evalScript()");

if let Some(source_text) = args.get(0).and_then(|val| val.as_string()) {
match boa::parse(source_text.as_str(), false) {
// TODO: check strict
Err(e) => context.throw_type_error(format!("Uncaught Syntax Error: {}", e)),
Ok(script) => script.run(context),
}
} else {
Ok(Value::undefined())
}
}

/// The `$262.gc()` function.
///
/// Wraps the host's garbage collection invocation mechanism, if such a capability exists.
/// Must throw an exception if no capability exists. This is necessary for testing the
/// semantics of any feature that relies on garbage collection, e.g. the `WeakRef` API.
#[allow(dead_code)]
fn gc(_this: &Value, _: &[Value], _context: &mut Context) -> Result<Value> {
todo!()
}
7 changes: 5 additions & 2 deletions boa_tester/src/exec.rs → boa_tester/src/exec/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Execution module for the test runner.

mod js262;

use super::{
Harness, Outcome, Phase, SuiteResult, Test, TestFlags, TestOutcomeResult, TestResult,
TestSuite, IGNORED,
Expand Down Expand Up @@ -260,7 +262,6 @@ impl Test {
/// Sets the environment up to run the test.
fn set_up_env(&self, harness: &Harness, strict: bool) -> Result<Context, String> {
// Create new Realm
// TODO: in parallel.
let mut context = Context::new();

// Register the print() function.
Expand All @@ -272,7 +273,9 @@ impl Test {
e.display()
)
})?;
// TODO: add the $262 object.

// add the $262 object.
let _ = js262::init(&mut context);

if strict {
context
Expand Down