Skip to content
Merged
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
5 changes: 4 additions & 1 deletion core/engine/src/builtins/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ impl Eval {

compiler.compile_statement_list(body.statements(), true, false);

let code_block = Gc::new(compiler.finish());
let code_block = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
compiler.finish(),
);

// Strict calls don't need extensions, since all strict eval calls push a new
// function environment before evaluating.
Expand Down
27 changes: 21 additions & 6 deletions core/engine/src/builtins/finalization_registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ impl BuiltInConstructor for FinalizationRegistry {
},
);

let weak_registry = WeakGc::new(registry.inner());
let weak_registry = WeakGc::new(
&unsafe { boa_gc::MutationContext::dummy() },
registry.inner(),
);

{
async fn inner_cleanup(
Expand All @@ -170,7 +173,10 @@ impl BuiltInConstructor for FinalizationRegistry {
return Ok(JsValue::undefined());
};

let Some(registry) = weak_registry.upgrade().map(JsObject::from_inner) else {
let Some(registry) = weak_registry
.upgrade(&unsafe { boa_gc::MutationContext::dummy() })
.map(JsObject::from_inner)
else {
return Ok(JsValue::undefined());
};

Expand Down Expand Up @@ -251,7 +257,10 @@ impl FinalizationRegistry {
//
// TODO: support Symbols
let unregister_token = match unregister_token.variant() {
JsVariant::Object(obj) => Some(WeakGc::new(obj.inner())),
JsVariant::Object(obj) => Some(WeakGc::new(
&unsafe { boa_gc::MutationContext::dummy() },
obj.inner(),
)),
// b. Set unregisterToken to empty.
JsVariant::Undefined => None,
// a. If unregisterToken is not undefined, throw a TypeError exception.
Expand All @@ -266,6 +275,7 @@ impl FinalizationRegistry {
// 6. Let cell be the Record { [[WeakRefTarget]]: target, [[HeldValue]]: heldValue, [[UnregisterToken]]: unregisterToken }.
let cell = RegistryCell {
target: Ephemeron::new(
&unsafe { boa_gc::MutationContext::dummy() },
target_obj.inner(),
CleanupSignaler(Cell::new(Some(
registry.cleanup_notifier.clone().downgrade(),
Expand Down Expand Up @@ -328,15 +338,20 @@ impl FinalizationRegistry {

// a. If cell.[[UnregisterToken]] is not empty and SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
if let Some(tok) = cell.unregister_token.as_ref()
&& let Some(tok) = tok.upgrade()
&& let Some(tok) = tok.upgrade(&unsafe { boa_gc::MutationContext::dummy() })
&& Gc::ptr_eq(&tok, unregister_token)
{
// i. Remove cell from finalizationRegistry.[[Cells]].
let cell = registry.cells.swap_remove(i);
let _key = cell.target.key();
let _key = cell
.target
.key(&unsafe { boa_gc::MutationContext::dummy() });

// TODO: it might be better to add a special ref for the value that
// also preserves the original key instead.
cell.target.value().and_then(|v| v.0.take());
cell.target
.value(&unsafe { boa_gc::MutationContext::dummy() })
.and_then(|v| v.0.take());

// ii. Set removed to true.
removed = true;
Expand Down
5 changes: 4 additions & 1 deletion core/engine/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ impl Json {
SourcePath::Json,
);
compiler.compile_statement_list(script.statements(), true, false);
Gc::new(compiler.finish())
Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
compiler.finish(),
)
};

let realm = context.realm().clone();
Expand Down
36 changes: 27 additions & 9 deletions core/engine/src/builtins/promise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,13 @@ impl PromiseCapability {

// 2. NOTE: C is assumed to be a constructor function that supports the parameter conventions of the Promise constructor (see 27.2.3.1).
// 3. Let promiseCapability be the PromiseCapability Record { [[Promise]]: undefined, [[Resolve]]: undefined, [[Reject]]: undefined }.
let promise_capability = Gc::new(GcRefCell::new(RejectResolve {
reject: JsValue::undefined(),
resolve: JsValue::undefined(),
}));
let promise_capability = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
GcRefCell::new(RejectResolve {
reject: JsValue::undefined(),
resolve: JsValue::undefined(),
}),
);

// 4. Let executorClosure be a new Abstract Closure with parameters (resolve, reject) that captures promiseCapability and performs the following steps when called:
// 5. Let executor be CreateBuiltinFunction(executorClosure, 2, "", « »).
Expand Down Expand Up @@ -653,7 +656,10 @@ impl Promise {
}

// 1. Let values be a new empty List.
let values = Gc::new(GcRefCell::new(Vec::new()));
let values = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
GcRefCell::new(Vec::new()),
);

// 2. Let remainingElementsCount be the Record { [[Value]]: 1 }.
let remaining_elements_count = Rc::new(Cell::new(1));
Expand Down Expand Up @@ -868,7 +874,10 @@ impl Promise {
}

// 1. Let values be a new empty List.
let values = Gc::new(GcRefCell::new(Vec::new()));
let values = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
GcRefCell::new(Vec::new()),
);

// 2. Let remainingElementsCount be the Record { [[Value]]: 1 }.
let remaining_elements_count = Rc::new(Cell::new(1));
Expand Down Expand Up @@ -1235,7 +1244,10 @@ impl Promise {
let keys = Rc::new(RefCell::new(Vec::new()));

// 3. Let values be a new empty List.
let values = Gc::new(GcRefCell::new(Vec::new()));
let values = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
GcRefCell::new(Vec::new()),
);

// 4. Let remainingElementsCount be the Record { [[Value]]: 1 }.
let remaining_elements_count = Rc::new(Cell::new(1));
Expand Down Expand Up @@ -1545,7 +1557,10 @@ impl Promise {
}

// 1. Let errors be a new empty List.
let errors = Gc::new(GcRefCell::new(Vec::new()));
let errors = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
GcRefCell::new(Vec::new()),
);

// 2. Let remainingElementsCount be the Record { [[Value]]: 1 }.
let remaining_elements_count = Rc::new(Cell::new(1));
Expand Down Expand Up @@ -2445,7 +2460,10 @@ impl Promise {
// 1. Let alreadyResolved be the Record { [[Value]]: false }.
// 5. Set resolve.[[Promise]] to promise.
// 6. Set resolve.[[AlreadyResolved]] to alreadyResolved.
let promise = Gc::new(Cell::new(Some(promise.clone())));
let promise = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
Cell::new(Some(promise.clone())),
);

// 2. Let stepsResolve be the algorithm steps defined in Promise Resolve Functions.
// 3. Let lengthResolve be the number of non-optional parameters of the function definition in Promise Resolve Functions.
Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/builtins/weak/weak_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl BuiltInConstructor for WeakRef {
let weak_ref = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
WeakGc::new(target.inner()),
WeakGc::new(&unsafe { boa_gc::MutationContext::dummy() }, target.inner()),
);

// 4. Perform AddToKeptObjects(target).
Expand Down Expand Up @@ -124,7 +124,7 @@ impl WeakRef {
// https://tc39.es/ecma262/multipage/managing-memory.html#sec-weakrefderef
// 1. Let target be weakRef.[[WeakRefTarget]].
// 2. If target is not empty, then
if let Some(object) = weak_ref.upgrade() {
if let Some(object) = weak_ref.upgrade(&unsafe { boa_gc::MutationContext::dummy() }) {
let object = JsObject::from(object);

// a. Perform AddToKeptObjects(target).
Expand Down
8 changes: 4 additions & 4 deletions core/engine/src/builtins/weak_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl BuiltInConstructor for WeakMap {
let map = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
NativeWeakMap::new(),
NativeWeakMap::new(&unsafe { boa_gc::MutationContext::dummy() }),
)
.upcast();

Expand Down Expand Up @@ -194,7 +194,7 @@ impl WeakMap {
// a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, return p.[[Value]].
// 6. Return undefined.
if let Some(entry) = map.get(key.inner())
&& let Some(val) = entry.value()
&& let Some(val) = entry.value(&unsafe { boa_gc::MutationContext::dummy() })
{
Ok(val.clone())
} else {
Expand Down Expand Up @@ -325,7 +325,7 @@ impl WeakMap {

// 4. For each Record { [[Key]], [[Value]] } p of M.[[WeakMapData]]
if let Some(existing) = map.borrow().data().get(key.inner())
&& let Some(value) = existing.value()
&& let Some(value) = existing.value(&unsafe { boa_gc::MutationContext::dummy() })
{
// a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, return p.[[Value]].
return Ok(value.clone());
Expand Down Expand Up @@ -387,7 +387,7 @@ impl WeakMap {

// 5. For each Record { [[Key]], [[Value]] } p of M.[[WeakMapData]]
if let Some(existing) = map.borrow().data().get(key_obj.inner())
&& let Some(value) = existing.value()
&& let Some(value) = existing.value(&unsafe { boa_gc::MutationContext::dummy() })
{
// a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, return p.[[Value]].
return Ok(value.clone());
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/weak_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl BuiltInConstructor for WeakSet {
let weak_set = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
prototype,
NativeWeakSet::new(),
NativeWeakSet::new(&unsafe { boa_gc::MutationContext::dummy() }),
)
.upcast();

Expand Down
24 changes: 18 additions & 6 deletions core/engine/src/bytecompiler/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ impl ByteCompiler<'_> {
class.super_ref.is_some(),
);

let code = Gc::new(compiler.finish());
let code = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
compiler.finish(),
);
let index = self.push_function_to_constants(code);

let class_register = self.register_allocator.alloc();
Expand Down Expand Up @@ -440,7 +443,10 @@ impl ByteCompiler<'_> {

field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

let code = Gc::new(field_compiler.finish());
let code = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
field_compiler.finish(),
);
let index = self.push_function_to_constants(code);

let dst = self.register_allocator.alloc();
Expand Down Expand Up @@ -486,7 +492,10 @@ impl ByteCompiler<'_> {

field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

let code = Gc::new(field_compiler.finish());
let code = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
field_compiler.finish(),
);
let index = self.push_function_to_constants(code);
let dst = self.register_allocator.alloc();
self.emit_get_function(&dst, index);
Expand Down Expand Up @@ -542,7 +551,7 @@ impl ByteCompiler<'_> {
field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

let code = field_compiler.finish();
let code = Gc::new(code);
let code = Gc::new(&unsafe { boa_gc::MutationContext::dummy() }, code);

static_elements.push(StaticElement::StaticField {
code,
Expand Down Expand Up @@ -586,7 +595,7 @@ impl ByteCompiler<'_> {
field_compiler.code_block_flags |= CodeBlockFlags::IN_CLASS_FIELD_INITIALIZER;

let code = field_compiler.finish();
let code = Gc::new(code);
let code = Gc::new(&unsafe { boa_gc::MutationContext::dummy() }, code);

static_elements.push(StaticElement::StaticField {
code,
Expand Down Expand Up @@ -629,7 +638,10 @@ impl ByteCompiler<'_> {
);
}

let code = Gc::new(compiler.finish());
let code = Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
compiler.finish(),
);
static_elements.push(StaticElement::StaticBlock(code));
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/bytecompiler/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,6 @@ impl FunctionCompiler {

let code = compiler.finish();

Gc::new(code)
Gc::new(&unsafe { boa_gc::MutationContext::dummy() }, code)
}
}
14 changes: 10 additions & 4 deletions core/engine/src/environments/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl EnvironmentStack {
let index = self.depth;

self.push_env(Environment::Declarative(Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
DeclarativeEnvironment::new(
DeclarativeEnvironmentKind::Lexical(LexicalEnvironment::new(bindings_count)),
poisoned,
Expand All @@ -242,6 +243,7 @@ impl EnvironmentStack {
let (poisoned, with) = self.compute_poisoned_with(global);

self.push_env(Environment::Declarative(Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
DeclarativeEnvironment::new(
DeclarativeEnvironmentKind::Function(FunctionEnvironment::new(
num_bindings,
Expand All @@ -258,6 +260,7 @@ impl EnvironmentStack {
pub(crate) fn push_module(&mut self, scope: Scope) {
let num_bindings = scope.num_bindings_non_local();
self.push_env(Environment::Declarative(Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
DeclarativeEnvironment::new(
DeclarativeEnvironmentKind::Module(ModuleEnvironment::new(num_bindings, scope)),
false,
Expand Down Expand Up @@ -410,10 +413,13 @@ impl EnvironmentStack {

/// Push an environment onto the chain.
fn push_env(&mut self, env: Environment) {
self.tip = Some(Gc::new(EnvironmentNode {
env,
parent: self.tip.take(),
}));
self.tip = Some(Gc::new(
&unsafe { boa_gc::MutationContext::dummy() },
EnvironmentNode {
env,
parent: self.tip.take(),
},
));
self.depth += 1;
}

Expand Down
Loading