diff --git a/boa_engine/src/context/mod.rs b/boa_engine/src/context/mod.rs index 32dd3008f71..60eb6313abd 100644 --- a/boa_engine/src/context/mod.rs +++ b/boa_engine/src/context/mod.rs @@ -513,6 +513,23 @@ impl<'host> Context<'host> { std::mem::replace(&mut self.realm, realm) } + /// Create a new Realm with the default global bindings. + pub fn create_realm(&mut self) -> JsResult { + let realm = Realm::create(&*self.host_hooks, &self.root_shape); + + let old_realm = self.enter_realm(realm); + + builtins::set_default_global_bindings(self)?; + + Ok(self.enter_realm(old_realm)) + } + + /// Get the remaining instruction count + #[cfg(feature = "fuzz")] + #[inline] + pub const fn instructions_remaining(&self) -> usize { + self.instructions_remaining + } /// Get the [`RootShape`]. #[inline] #[must_use] diff --git a/boa_engine/src/error.rs b/boa_engine/src/error.rs index 839f404c687..a103197d6b6 100644 --- a/boa_engine/src/error.rs +++ b/boa_engine/src/error.rs @@ -819,9 +819,7 @@ impl JsNativeError { JsNativeErrorKind::Uri => (constructors.uri_error().prototype(), ErrorKind::Uri), #[cfg(feature = "fuzz")] JsNativeErrorKind::NoInstructionsRemain => { - unreachable!( - "The NoInstructionsRemain native error cannot be converted to an opaque type." - ) + (constructors.eval_error().prototype(), ErrorKind::Eval) } JsNativeErrorKind::RuntimeLimit => { panic!("The RuntimeLimit native error cannot be converted to an opaque type.") diff --git a/boa_engine/src/value/conversions/serde_json.rs b/boa_engine/src/value/conversions/serde_json.rs index f4f73f63eeb..4413333aaaf 100644 --- a/boa_engine/src/value/conversions/serde_json.rs +++ b/boa_engine/src/value/conversions/serde_json.rs @@ -108,14 +108,12 @@ impl JsValue { /// # /// # assert_eq!(json, back_to_json); /// ``` - /// - /// # Panics - /// - /// Panics if the `JsValue` is `Undefined`. pub fn to_json(&self, context: &mut Context<'_>) -> JsResult { match self { Self::Null => Ok(Value::Null), - Self::Undefined => todo!("undefined to JSON"), + Self::Undefined => Err(JsNativeError::typ() + .with_message("cannot convert undefined to JSON") + .into()), &Self::Boolean(b) => Ok(b.into()), Self::String(string) => Ok(string.to_std_string_escaped().into()), &Self::Rational(rat) => Ok(rat.into()), diff --git a/boa_gc/src/lib.rs b/boa_gc/src/lib.rs index 698f6001bd8..90486557d2d 100644 --- a/boa_gc/src/lib.rs +++ b/boa_gc/src/lib.rs @@ -567,6 +567,18 @@ pub fn force_collect() { }); } +pub fn gc_reset() { + let new = BoaGc { + config: GcConfig::default(), + runtime: GcRuntimeData::default(), + strong_start: Cell::new(None), + weak_start: Cell::new(None), + weak_map_start: Cell::new(None), +}; + + BOA_GC.replace(new); +} + #[cfg(test)] mod test;