-
-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters