Browse Source

Added `globalThis` property (#495)

* added builtin globalThis

* forgot to initialize globalThis in the builtin mod.rs file

* changed  to  to match naming conventions and fixed issue with suggested edits to globalThis' initial value

* updated the test for the  property as suggested
pull/499/head
Ryan Fickenscher 4 years ago committed by GitHub
parent
commit
474252324e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      boa/src/builtins/global_this/mod.rs
  2. 10
      boa/src/builtins/global_this/tests.rs
  3. 2
      boa/src/builtins/mod.rs

11
boa/src/builtins/global_this/mod.rs

@ -0,0 +1,11 @@
#[cfg(test)]
mod tests;
use crate::{builtins::value::Value, BoaProfiler};
/// Initialize the `globalThis` property on the global object.
#[inline]
pub fn init(global: &Value) {
let _timer = BoaProfiler::global().start_event("globalThis", "init");
global.set_field("globalThis", global.clone());
}

10
boa/src/builtins/global_this/tests.rs

@ -0,0 +1,10 @@
use crate::exec;
#[test]
fn global_this_exists_on_global_object_and_evaluates_to_an_object() {
let scenario = r#"
typeof globalThis;
"#;
assert_eq!(&exec(scenario), "object");
}

2
boa/src/builtins/mod.rs

@ -6,6 +6,7 @@ pub mod boolean;
pub mod console;
pub mod error;
pub mod function;
pub mod global_this;
pub mod json;
pub mod math;
pub mod nan;
@ -35,6 +36,7 @@ pub fn init(global: &Value) {
Array::init(global);
BigInt::init(global);
Boolean::init(global);
global_this::init(global);
json::init(global);
math::init(global);
nan::init(global);

Loading…
Cancel
Save