From b437c9ff4695057ee24200459201ad9c840076a9 Mon Sep 17 00:00:00 2001 From: joshwd36 Date: Wed, 22 Jul 2020 13:57:54 +0100 Subject: [PATCH] Implement and use Interpreter::global() --- boa/src/builtins/array/mod.rs | 2 +- boa/src/builtins/bigint/mod.rs | 2 +- boa/src/builtins/boolean/mod.rs | 2 +- boa/src/builtins/console/mod.rs | 2 +- boa/src/builtins/error/mod.rs | 2 +- boa/src/builtins/error/range.rs | 2 +- boa/src/builtins/error/reference.rs | 2 +- boa/src/builtins/error/syntax.rs | 2 +- boa/src/builtins/error/type.rs | 2 +- boa/src/builtins/function/mod.rs | 2 +- boa/src/builtins/global_this/mod.rs | 2 +- boa/src/builtins/json/mod.rs | 2 +- boa/src/builtins/map/mod.rs | 2 +- boa/src/builtins/math/mod.rs | 2 +- boa/src/builtins/mod.rs | 2 +- boa/src/builtins/number/mod.rs | 2 +- boa/src/builtins/object/mod.rs | 2 +- boa/src/builtins/regexp/mod.rs | 2 +- boa/src/builtins/string/mod.rs | 2 +- boa/src/builtins/symbol/mod.rs | 2 +- boa/src/builtins/value/mod.rs | 2 +- boa/src/exec/mod.rs | 5 +++++ 22 files changed, 26 insertions(+), 21 deletions(-) diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index 0e9db7cedd..d058fd0ffa 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -1115,7 +1115,7 @@ impl Array { /// Initialise the `Array` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create prototype diff --git a/boa/src/builtins/bigint/mod.rs b/boa/src/builtins/bigint/mod.rs index 7ec9dd3730..aac4b68ff4 100644 --- a/boa/src/builtins/bigint/mod.rs +++ b/boa/src/builtins/bigint/mod.rs @@ -201,7 +201,7 @@ impl BigInt { /// Initialise the `BigInt` object on the global object. #[inline] pub fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let prototype = Value::new_object(Some(global)); diff --git a/boa/src/builtins/boolean/mod.rs b/boa/src/builtins/boolean/mod.rs index 5a221c12da..1698f33c16 100644 --- a/boa/src/builtins/boolean/mod.rs +++ b/boa/src/builtins/boolean/mod.rs @@ -99,7 +99,7 @@ impl Boolean { /// Initialise the `Boolean` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create Prototype diff --git a/boa/src/builtins/console/mod.rs b/boa/src/builtins/console/mod.rs index f3f877888d..db823fed04 100644 --- a/boa/src/builtins/console/mod.rs +++ b/boa/src/builtins/console/mod.rs @@ -490,7 +490,7 @@ impl Console { /// Initialise the `console` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let console = Value::new_object(Some(global)); diff --git a/boa/src/builtins/error/mod.rs b/boa/src/builtins/error/mod.rs index 6d0dff1a43..99fc5f7af0 100644 --- a/boa/src/builtins/error/mod.rs +++ b/boa/src/builtins/error/mod.rs @@ -77,7 +77,7 @@ impl Error { /// Initialise the global object with the `Error` object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let prototype = Value::new_object(Some(global)); diff --git a/boa/src/builtins/error/range.rs b/boa/src/builtins/error/range.rs index d3c3da00ba..5fffaf63de 100644 --- a/boa/src/builtins/error/range.rs +++ b/boa/src/builtins/error/range.rs @@ -63,7 +63,7 @@ impl RangeError { /// Initialise the global object with the `RangeError` object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let prototype = Value::new_object(Some(global)); diff --git a/boa/src/builtins/error/reference.rs b/boa/src/builtins/error/reference.rs index 574dd45998..635fe17311 100644 --- a/boa/src/builtins/error/reference.rs +++ b/boa/src/builtins/error/reference.rs @@ -61,7 +61,7 @@ impl ReferenceError { /// Initialise the global object with the `ReferenceError` object. pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let prototype = Value::new_object(Some(global)); diff --git a/boa/src/builtins/error/syntax.rs b/boa/src/builtins/error/syntax.rs index 048d16a3dd..07b4497f29 100644 --- a/boa/src/builtins/error/syntax.rs +++ b/boa/src/builtins/error/syntax.rs @@ -65,7 +65,7 @@ impl SyntaxError { /// Initialise the global object with the `SyntaxError` object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let prototype = Value::new_object(Some(global)); diff --git a/boa/src/builtins/error/type.rs b/boa/src/builtins/error/type.rs index 57a7deaebc..5f0e861533 100644 --- a/boa/src/builtins/error/type.rs +++ b/boa/src/builtins/error/type.rs @@ -69,7 +69,7 @@ impl TypeError { /// Initialise the global object with the `RangeError` object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let prototype = Value::new_object(Some(global)); diff --git a/boa/src/builtins/function/mod.rs b/boa/src/builtins/function/mod.rs index 9131c850a7..3bad106252 100644 --- a/boa/src/builtins/function/mod.rs +++ b/boa/src/builtins/function/mod.rs @@ -534,7 +534,7 @@ where /// Initialise the `Function` object on the global object. #[inline] pub fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event("function", "init"); let prototype = Value::new_object(Some(global)); diff --git a/boa/src/builtins/global_this/mod.rs b/boa/src/builtins/global_this/mod.rs index 5a60a00640..481b619dec 100644 --- a/boa/src/builtins/global_this/mod.rs +++ b/boa/src/builtins/global_this/mod.rs @@ -25,7 +25,7 @@ impl GlobalThis { /// Initialize the `globalThis` property on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); (Self::NAME, global.clone()) diff --git a/boa/src/builtins/json/mod.rs b/boa/src/builtins/json/mod.rs index 107bc81820..033d486653 100644 --- a/boa/src/builtins/json/mod.rs +++ b/boa/src/builtins/json/mod.rs @@ -173,7 +173,7 @@ impl Json { /// Initialise the `JSON` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let json = Value::new_object(Some(global)); diff --git a/boa/src/builtins/map/mod.rs b/boa/src/builtins/map/mod.rs index ed7cd747a5..0de4d53619 100644 --- a/boa/src/builtins/map/mod.rs +++ b/boa/src/builtins/map/mod.rs @@ -285,7 +285,7 @@ impl Map { /// Initialise the `Map` object on the global object. pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create prototype diff --git a/boa/src/builtins/math/mod.rs b/boa/src/builtins/math/mod.rs index b1297b4a73..49189cb1f4 100644 --- a/boa/src/builtins/math/mod.rs +++ b/boa/src/builtins/math/mod.rs @@ -698,7 +698,7 @@ impl Math { /// Initialise the `Math` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); (Self::NAME, Self::create(global)) diff --git a/boa/src/builtins/mod.rs b/boa/src/builtins/mod.rs index 114b7ade47..91449bb704 100644 --- a/boa/src/builtins/mod.rs +++ b/boa/src/builtins/mod.rs @@ -75,7 +75,7 @@ pub fn init(interpreter: &mut Interpreter) { for init in &globals { let (name, value) = init(interpreter); - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); match global { Value::Object(ref global_object) => { global_object.borrow_mut().insert_field(name, value); diff --git a/boa/src/builtins/number/mod.rs b/boa/src/builtins/number/mod.rs index 0e2478d965..fa738d75c0 100644 --- a/boa/src/builtins/number/mod.rs +++ b/boa/src/builtins/number/mod.rs @@ -728,7 +728,7 @@ impl Number { /// Initialise the `Number` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let prototype = Value::new_object(Some(global)); diff --git a/boa/src/builtins/object/mod.rs b/boa/src/builtins/object/mod.rs index b7e7562100..193fa66d3a 100644 --- a/boa/src/builtins/object/mod.rs +++ b/boa/src/builtins/object/mod.rs @@ -578,7 +578,7 @@ pub fn property_is_enumerable(this: &Value, args: &[Value], ctx: &mut Interprete /// Initialise the `Object` object on the global object. #[inline] pub fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event("object", "init"); let prototype = Value::new_object(None); diff --git a/boa/src/builtins/regexp/mod.rs b/boa/src/builtins/regexp/mod.rs index 90f1ae1694..4e6f2b9eda 100644 --- a/boa/src/builtins/regexp/mod.rs +++ b/boa/src/builtins/regexp/mod.rs @@ -493,7 +493,7 @@ impl RegExp { /// Initialise the `RegExp` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); (Self::NAME, Self::create(global)) diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index a8957f9d36..5b4de41a1f 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -1024,7 +1024,7 @@ impl String { /// Initialise the `String` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create `String` `prototype` diff --git a/boa/src/builtins/symbol/mod.rs b/boa/src/builtins/symbol/mod.rs index 9b592f5dee..103e9f6c8a 100644 --- a/boa/src/builtins/symbol/mod.rs +++ b/boa/src/builtins/symbol/mod.rs @@ -133,7 +133,7 @@ impl Symbol { interpreter.generate_hash(), ); - let global = &interpreter.realm.global_obj; + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create prototype object diff --git a/boa/src/builtins/value/mod.rs b/boa/src/builtins/value/mod.rs index 61520f3dc0..0796e78ada 100644 --- a/boa/src/builtins/value/mod.rs +++ b/boa/src/builtins/value/mod.rs @@ -214,7 +214,7 @@ impl Value { new_obj } JSONValue::Object(obj) => { - let new_obj = Value::new_object(Some(&interpreter.realm.global_obj)); + let new_obj = Value::new_object(Some(interpreter.global())); for (key, json) in obj.into_iter() { let value = Self::from_json(json, interpreter); new_obj.set_property( diff --git a/boa/src/exec/mod.rs b/boa/src/exec/mod.rs index df53f1abbe..cbe3e79ec1 100644 --- a/boa/src/exec/mod.rs +++ b/boa/src/exec/mod.rs @@ -113,6 +113,11 @@ impl Interpreter { &mut self.realm } + #[inline] + pub(crate) fn global(&self) -> &Value { + &self.realm.global_obj + } + /// Generates a new `Symbol` internal hash. /// /// This currently is an incremented value.