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

Allow boa drop #3

Draft
wants to merge 5 commits into
base: ryutamago/fix-undefined-to-json
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions boa_engine/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Realm> {
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]
Expand Down
4 changes: 1 addition & 3 deletions boa_engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
8 changes: 3 additions & 5 deletions boa_engine/src/value/conversions/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> {
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()),
Expand Down
12 changes: 12 additions & 0 deletions boa_gc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down