Skip to content

Truly independent web browser

LibJS+LibWeb: Keep what holds cells in heap memory within a deferral

Shannon Booth9de736b374fd
diff --git a/Libraries/LibJS/Rust/src/embedding/host/host_module.rs b/Libraries/LibJS/Rust/src/embedding/host/host_module.rs
index 7b917e82c94..b6b145f4d89 100644
--- a/Libraries/LibJS/Rust/src/embedding/host/host_module.rs
+++ b/Libraries/LibJS/Rust/src/embedding/host/host_module.rs
@@ -165,8 +165,8 @@ impl HostModule {
) -> Gc<HostModule> {
let (class, allocator) = runtime_class_and_allocator_of_host_class(vm, host_class, JS_HOST_CLASS_MODULE);
module_hooks_of(host_class);
- vm.heap().allocate_in(allocator, |_| HostModule {
- base: CyclicModule::new(class, realm, filename, false, requested_modules, host_defined),
+ vm.heap().allocate_in(allocator, |defer_gc| HostModule {
+ base: CyclicModule::new(defer_gc, class, realm, filename, false, requested_modules, host_defined),
host_class,
host_data,
})
diff --git a/Libraries/LibJS/Rust/src/gc/defer_gc.rs b/Libraries/LibJS/Rust/src/gc/defer_gc.rs
index dbe7486bf99..b6a26a91c69 100644
--- a/Libraries/LibJS/Rust/src/gc/defer_gc.rs
+++ b/Libraries/LibJS/Rust/src/gc/defer_gc.rs
@@ -18,6 +18,11 @@ impl<'heap> DeferGc<'heap> {
Self::of_heap(vm.heap())
}
+ /// Runs `body` while nothing collects garbage, so that what it holds by value needs no root.
+ pub fn scope<R>(vm: &Vm, body: impl FnOnce(&DeferGc<'_>) -> R) -> R {
+ body(&DeferGc::new(vm))
+ }
+
pub(super) fn of_heap(heap: &'heap Heap) -> Self {
heap.defer_gc();
Self(heap)
diff --git a/Libraries/LibJS/Rust/src/gc/gc_ref_cell.rs b/Libraries/LibJS/Rust/src/gc/gc_ref_cell.rs
index 374c5af498b..3f9583bc016 100644
--- a/Libraries/LibJS/Rust/src/gc/gc_ref_cell.rs
+++ b/Libraries/LibJS/Rust/src/gc/gc_ref_cell.rs
@@ -41,6 +41,10 @@ impl<T> GcRefCell<T> {
pub fn replace(&self, value: T) -> T {
self.0.replace(value)
}
+
+ pub fn swap(&self, other: &Self) {
+ self.0.swap(&other.0);
+ }
}
impl<T: Default> Default for GcRefCell<T> {
diff --git a/Libraries/LibJS/Rust/src/interpreter/vm.rs b/Libraries/LibJS/Rust/src/interpreter/vm.rs
index a94a8e0759a..0219a75080d 100644
--- a/Libraries/LibJS/Rust/src/interpreter/vm.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/vm.rs
@@ -682,7 +682,7 @@ impl Vm {
),
interned_strings: RefCell::default(),
json_parse_cache: JsonParseCache::default(),
- json_stringify_cache: JsonStringifyCache::default(),
+ json_stringify_cache: JsonStringifyCache::new(),
empty_string: OnceCell::new(),
cached_strings: OnceCell::new(),
single_ascii_character_strings: OnceCell::new(),
@@ -1378,7 +1378,7 @@ impl Vm {
fn remove_dead_cells_from_property_lookup_caches(&self, sweep: &Sweep<'_>) {
self.executables.borrow_mut().retain(|executable| {
if sweep.is_dead(*executable) {
- executable.free_jit_entry_slot(self);
+ executable.free_jit_entry_slot(self, sweep);
return false;
}
executable.remove_dead_cells(sweep);
diff --git a/Libraries/LibJS/Rust/src/jit/code.rs b/Libraries/LibJS/Rust/src/jit/code.rs
index cf9646fbe0a..f2534f7a5b1 100644
--- a/Libraries/LibJS/Rust/src/jit/code.rs
+++ b/Libraries/LibJS/Rust/src/jit/code.rs
@@ -18,6 +18,7 @@ use super::entry_table::{JIT_ENTRY_SLOT_MASK, JitEntryTable, NO_JIT_ENTRY_SLOT};
use super::executable_memory::ExecutableMemory;
use crate::bytecode::executable::{Executable, PropertyLookupCache, PropertyLookupCacheTier};
use crate::gc::defer_gc::DeferGc;
+use crate::gc::sweep::Sweep;
use crate::gc::visitor::{Trace, Visitor};
use crate::interpreter::vm::Vm;
use crate::layout::cell::{CellHeader, Gc};
@@ -220,10 +221,9 @@ impl JitCode {
}
/// Gives the code where its frames keep the index of a site and the register dump the runtime reads.
- pub fn with_frame_offsets(mut self, site_index_frame_offset: i32, register_dump_frame_offset: i32) -> Self {
+ pub fn set_frame_offsets(&mut self, site_index_frame_offset: i32, register_dump_frame_offset: i32) {
self.site_index_frame_offset = site_index_frame_offset;
self.register_dump_frame_offset = register_dump_frame_offset;
- self
}
pub fn register_dump_frame_offset(&self) -> i32 {
@@ -271,21 +271,18 @@ impl JitCode {
}
/// Gives the code its id among all code the VM installed, and the bytes that invalidate it.
- pub fn with_invalidation(mut self, id: u64, invalidation_patches: Vec<(u32, Vec<u8>)>) -> Self {
+ pub fn set_invalidation(&mut self, id: u64, invalidation_patches: Vec<(u32, Vec<u8>)>) {
self.id = id;
self.invalidation_patches = invalidation_patches;
- self
}
/// Gives the code the loop back edges in the loops around those of its on-stack replacement entries.
- pub fn with_osr_outer_loop_back_edges(mut self, osr_outer_loop_back_edges: Vec<u32>) -> Self {
+ pub fn set_osr_outer_loop_back_edges(&mut self, osr_outer_loop_back_edges: Vec<u32>) {
self.osr_outer_loop_back_edges = osr_outer_loop_back_edges;
- self
}
- pub fn with_uncaught_handlers(mut self, uncaught_handlers: Vec<u32>) -> Self {
+ pub fn set_uncaught_handlers(&mut self, uncaught_handlers: Vec<u32>) {
self.uncaught_handlers = uncaught_handlers;
- self
}
/// Whether the handler whose `Catch` is at `pc` has no catch entry only because it never caught an exception
@@ -495,11 +492,15 @@ impl Executable {
}
/// Frees the slot of the executable, which died, and drops its JIT code.
- pub fn free_jit_entry_slot(&self, vm: &Vm) {
+ pub fn free_jit_entry_slot(&self, vm: &Vm, sweep: &Sweep<'_>) {
let Some(table) = vm.jit.entry_table.as_ref() else {
return;
};
- let Some(mut code) = table.free(self.head.jit_entry_slot.get(), core::ptr::from_ref(&self.head) as u64) else {
+ let Some(mut code) = table.free(
+ self.head.jit_entry_slot.get(),
+ core::ptr::from_ref(&self.head) as u64,
+ sweep,
+ ) else {
return;
};
// OPTIMIZATION: The compile threads allocated the sites, so one of them frees them, outside the collection
@@ -625,12 +626,12 @@ impl Executable {
/// Makes new frames of the executable run in its JIT code. Frames of it that run in the interpreter count down
/// `tier_up_budget` from here, and continue in the code at an on-stack replacement entry once it runs out.
- pub fn install_jit_code(&self, vm: &Vm, code: JitCode, tier_up_budget: i32) {
+ pub fn install_jit_code(&self, vm: &Vm, code: JitCode, tier_up_budget: i32, defer_gc: &DeferGc<'_>) {
let (table, slot) = self
.jit_entry_table_slot(vm)
.expect("only executables with a JIT entry slot are compiled");
table.set_entry(slot, Some(code.entry() as *const c_void));
- table.attach_code(slot, code);
+ table.attach_code(slot, code, defer_gc);
self.set_jit_compile_state(CompileState::Installed);
self.head.tier_up_budget.set(tier_up_budget);
}
diff --git a/Libraries/LibJS/Rust/src/jit/disabled.rs b/Libraries/LibJS/Rust/src/jit/disabled.rs
index 49657040ec6..fce35264a76 100644
--- a/Libraries/LibJS/Rust/src/jit/disabled.rs
+++ b/Libraries/LibJS/Rust/src/jit/disabled.rs
@@ -77,6 +77,7 @@ pub mod options {
pub mod code {
use super::{Executable, Visitor, Vm};
+ use crate::gc::sweep::Sweep;
/// No return pc marks a call site in an inlined callee.
pub const INLINED_CALL_SITE_BIT: u32 = 0;
@@ -104,7 +105,7 @@ pub mod code {
impl Executable {
pub fn allocate_jit_entry_slot(&self, _vm: &Vm) {}
- pub fn free_jit_entry_slot(&self, _vm: &Vm) {}
+ pub fn free_jit_entry_slot(&self, _vm: &Vm, _sweep: &Sweep<'_>) {}
pub fn trace_jit_code(&self, _visitor: &mut Visitor) {}
diff --git a/Libraries/LibJS/Rust/src/jit/entry_table.rs b/Libraries/LibJS/Rust/src/jit/entry_table.rs
index c1d1ba82b94..fea07a910d5 100644
--- a/Libraries/LibJS/Rust/src/jit/entry_table.rs
+++ b/Libraries/LibJS/Rust/src/jit/entry_table.rs
@@ -18,6 +18,8 @@ use core::ffi::c_void;
use core::ptr::NonNull;
use super::code::JitCode;
+use crate::gc::defer_gc::DeferGc;
+use crate::gc::sweep::Sweep;
#[cfg(feature = "address-sanitizer")]
unsafe extern "C" {
@@ -149,7 +151,7 @@ impl JitEntryTable {
}
/// Frees the slot of the executable whose head is at `owner`, which died, and returns its code.
- pub fn free(&self, slot: u32, owner: u64) -> Option<JitCode> {
+ pub fn free(&self, slot: u32, owner: u64, _: &Sweep<'_>) -> Option<JitCode> {
let slot = slot & JIT_ENTRY_SLOT_MASK;
if slot == NO_JIT_ENTRY_SLOT {
return None;
@@ -182,7 +184,7 @@ impl JitEntryTable {
}
/// Attaches `code` to the slot, which has none.
- pub fn attach_code(&self, slot: u32, code: JitCode) {
+ pub fn attach_code(&self, slot: u32, code: JitCode, _: &DeferGc<'_>) {
assert_ne!(slot & JIT_ENTRY_SLOT_MASK, NO_JIT_ENTRY_SLOT);
assert!(self.code_cell(slot).replace(Some(Box::new(code))).is_none());
}
diff --git a/Libraries/LibJS/Rust/src/jit/tier_up.rs b/Libraries/LibJS/Rust/src/jit/tier_up.rs
index 9f01247ab71..8116711582a 100644
--- a/Libraries/LibJS/Rust/src/jit/tier_up.rs
+++ b/Libraries/LibJS/Rust/src/jit/tier_up.rs
@@ -353,7 +353,7 @@ fn install(
})
.collect();
let id = vm.jit.next_code_id();
- let code = JitCode::new(
+ let mut code = JitCode::new(
memory,
compiled.entry_offset,
&compiled.osr_entries,
@@ -362,17 +362,17 @@ fn install(
embedded_cells,
snapshot,
defer_gc,
- )
- .with_invalidation(id, compiled.invalidation_patches)
- .with_frame_offsets(compiled.site_index_frame_offset, compiled.register_dump_frame_offset)
- .with_osr_outer_loop_back_edges(compiled.osr_outer_loop_back_edges)
- .with_uncaught_handlers(compiled.uncaught_handlers);
+ );
+ code.set_invalidation(id, compiled.invalidation_patches);
+ code.set_frame_offsets(compiled.site_index_frame_offset, compiled.register_dump_frame_offset);
+ code.set_osr_outer_loop_back_edges(compiled.osr_outer_loop_back_edges);
+ code.set_uncaught_handlers(compiled.uncaught_handlers);
vm.jit.dependents.register(vm, executable, id, &compiled.dependencies);
// NB: Code may be installed while frames of the executable loop in the interpreter, because the compile was
// queued (from the tier-up check of another executable, like a callee's), or because they exited from the
// code before. Those frames keep counting, so that they continue in the code at its on-stack replacement
// entry rather than run in the interpreter until they return.
- executable.install_jit_code(vm, code, compile_wait_budget(&vm.jit.options));
+ executable.install_jit_code(vm, code, compile_wait_budget(&vm.jit.options), defer_gc);
}
type SnapshotExecutables = Vec<SnapshotExecutable>;
diff --git a/Libraries/LibJS/Rust/src/runtime/async_disposable_stack.rs b/Libraries/LibJS/Rust/src/runtime/async_disposable_stack.rs
index 55c37a6b068..f837e606ed5 100644
--- a/Libraries/LibJS/Rust/src/runtime/async_disposable_stack.rs
+++ b/Libraries/LibJS/Rust/src/runtime/async_disposable_stack.rs
@@ -10,6 +10,7 @@ use core::ops::Deref;
use libjs_runtime_macros::Trace;
use crate::gc::class::{Finalize, GcCell, define_cell};
+use crate::gc::defer_gc::DeferGc;
use crate::gc::gc_ref_cell::GcRefCell;
use crate::interpreter::vm::Vm;
use crate::layout::cell::Gc;
@@ -49,7 +50,7 @@ impl Finalize for AsyncDisposableStack {
impl AsyncDisposableStack {
/// A pending stack with a new dispose capability.
- pub fn new(vm: &Vm, prototype: Gc<Object>) -> AsyncDisposableStack {
+ pub fn new(_: &DeferGc<'_>, vm: &Vm, prototype: Gc<Object>) -> AsyncDisposableStack {
AsyncDisposableStack {
base: Object::new_with_prototype(vm, Self::CLASS, prototype, MayInterfereWithIndexedPropertyAccess::No),
async_disposable_state: Cell::new(AsyncDisposableState::Pending),
diff --git a/Libraries/LibJS/Rust/src/runtime/async_disposable_stack_constructor.rs b/Libraries/LibJS/Rust/src/runtime/async_disposable_stack_constructor.rs
index ef9267c9000..10218292df7 100644
--- a/Libraries/LibJS/Rust/src/runtime/async_disposable_stack_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/async_disposable_stack_constructor.rs
@@ -87,7 +87,7 @@ impl AsyncDisposableStackConstructor {
realm,
new_target,
Intrinsics::async_disposable_stack_prototype,
- |_, prototype| AsyncDisposableStack::new(vm, prototype),
+ |defer_gc, prototype| AsyncDisposableStack::new(defer_gc, vm, prototype),
)?;
Ok(async_disposable_stack.upcast())
}
diff --git a/Libraries/LibJS/Rust/src/runtime/async_disposable_stack_prototype.rs b/Libraries/LibJS/Rust/src/runtime/async_disposable_stack_prototype.rs
index 503cee4b9cc..fb809cd81c3 100644
--- a/Libraries/LibJS/Rust/src/runtime/async_disposable_stack_prototype.rs
+++ b/Libraries/LibJS/Rust/src/runtime/async_disposable_stack_prototype.rs
@@ -13,8 +13,7 @@ use crate::layout::cell::Gc;
use crate::layout::object::Object;
use crate::layout::value::Value;
use crate::runtime::abstract_operations::{
- add_disposable_resource, call_function_object, dispose_resources, new_dispose_capability,
- ordinary_create_from_constructor_of,
+ add_disposable_resource, call_function_object, dispose_resources, ordinary_create_from_constructor_of,
};
use crate::runtime::async_disposable_stack::{AsyncDisposableStack, AsyncDisposableState};
use crate::runtime::completion::{Completion, Must, ThrowCompletionOr};
@@ -291,18 +290,15 @@ impl AsyncDisposableStackPrototype {
realm,
realm.intrinsics().async_disposable_stack_constructor(vm).upcast(),
Intrinsics::async_disposable_stack_prototype,
- |_, prototype| AsyncDisposableStack::new(vm, prototype),
+ |defer_gc, prototype| AsyncDisposableStack::new(defer_gc, vm, prototype),
)?;
// 6. Set newAsyncDisposableStack.[[DisposeCapability]] to asyncDisposableStack.[[DisposeCapability]].
// 7. Set asyncDisposableStack.[[DisposeCapability]] to NewDisposeCapability().
- // NB: The resources move between the stacks once both exist, so that one of them always keeps them alive.
- let dispose_capability = async_disposable_stack
+ // NB: The new stack's capability is a new one, so swapping the two capabilities performs both steps.
+ async_disposable_stack
.dispose_capability()
- .replace(new_dispose_capability());
- new_async_disposable_stack
- .dispose_capability()
- .replace(dispose_capability);
+ .swap(new_async_disposable_stack.dispose_capability());
// 8. Set asyncDisposableStack.[[AsyncDisposableState]] to disposed.
async_disposable_stack.set_disposed();
diff --git a/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs b/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs
index 860e5a7dc5b..91d2ae28074 100644
--- a/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs
+++ b/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs
@@ -101,8 +101,8 @@ impl AsyncFunctionDriverWrapper {
let generator_object = GeneratorObject::create(vm, realm, generating_function, context.copy());
generator_object.set_generator_state(GeneratorState::SuspendedYield);
// Note: The top_level_promise is also kept alive by this Wrapper
- let wrapper = realm.create_object(vm, |_| AsyncFunctionDriverWrapper {
- base: Promise::new(vm, Self::CLASS, realm.intrinsics().promise_prototype(vm)),
+ let wrapper = realm.create_object(vm, |defer_gc| AsyncFunctionDriverWrapper {
+ base: Promise::new(defer_gc, vm, Self::CLASS, realm.intrinsics().promise_prototype(vm)),
generator_object: Cell::new(generator_object),
top_level_promise: Cell::new(top_level_promise),
current_promise: Cell::new(None),
diff --git a/Libraries/LibJS/Rust/src/runtime/cyclic_module.rs b/Libraries/LibJS/Rust/src/runtime/cyclic_module.rs
index 1e22c0f9b76..94eb4fb0f85 100644
--- a/Libraries/LibJS/Rust/src/runtime/cyclic_module.rs
+++ b/Libraries/LibJS/Rust/src/runtime/cyclic_module.rs
@@ -10,6 +10,7 @@ use core::ops::Deref;
use libjs_runtime_macros::Trace;
use crate::gc::class::{Class, define_cell};
+use crate::gc::defer_gc::DeferGc;
use crate::gc::foreign::ForeignCellSlot;
use crate::gc::gc_ref_cell::GcRefCell;
use crate::gc::root::MarkedVec;
@@ -111,6 +112,7 @@ fn new_intrinsic_promise_capability(vm: &Vm, realm: Gc<Realm>) -> Gc<PromiseCapa
impl CyclicModule {
/// A cyclic module of `realm`, for `class`, which extends CyclicModule.
pub fn new(
+ _: &DeferGc<'_>,
class: &'static Class,
realm: Gc<Realm>,
filename: String,
diff --git a/Libraries/LibJS/Rust/src/runtime/declarative_environment.rs b/Libraries/LibJS/Rust/src/runtime/declarative_environment.rs
index d08087b11c2..11b7234ffd3 100644
--- a/Libraries/LibJS/Rust/src/runtime/declarative_environment.rs
+++ b/Libraries/LibJS/Rust/src/runtime/declarative_environment.rs
@@ -334,11 +334,11 @@ impl DeclarativeEnvironment {
fn ensure_rare_data(&self) -> &DeclarativeEnvironmentRareData {
if self.rare_data.get().is_null() {
- let rare_data = Box::new(DeclarativeEnvironmentRareData {
- binding_flags: InterpreterBuffer::new(),
- storage: DeclarativeEnvironmentRareDataStorage::default(),
- });
- self.rare_data.set(Box::into_raw(rare_data));
+ self.rare_data
+ .set(Box::into_raw(Box::new(DeclarativeEnvironmentRareData {
+ binding_flags: InterpreterBuffer::new(),
+ storage: DeclarativeEnvironmentRareDataStorage::default(),
+ })));
}
self.rare_data().expect("the rare data was just allocated")
}
@@ -355,8 +355,7 @@ impl DeclarativeEnvironment {
return;
}
// SAFETY: ensure_rare_data allocated the rare data as a Box, and nothing refers to it anymore.
- let rare_data = unsafe { Box::from_raw(rare_data) };
- rare_data.binding_flags.clear();
+ unsafe { Box::from_raw(rare_data) }.binding_flags.clear();
}
fn increment_environment_serial_number(&self, vm: &Vm) {
diff --git a/Libraries/LibJS/Rust/src/runtime/disposable_stack.rs b/Libraries/LibJS/Rust/src/runtime/disposable_stack.rs
index af6cdda20d8..73ad5af6c91 100644
--- a/Libraries/LibJS/Rust/src/runtime/disposable_stack.rs
+++ b/Libraries/LibJS/Rust/src/runtime/disposable_stack.rs
@@ -10,6 +10,7 @@ use core::ops::Deref;
use libjs_runtime_macros::Trace;
use crate::gc::class::{Finalize, GcCell, define_cell};
+use crate::gc::defer_gc::DeferGc;
use crate::gc::gc_ref_cell::GcRefCell;
use crate::interpreter::vm::Vm;
use crate::layout::cell::Gc;
@@ -49,7 +50,7 @@ impl Finalize for DisposableStack {
impl DisposableStack {
/// A pending stack with a new dispose capability.
- pub fn new(vm: &Vm, prototype: Gc<Object>) -> DisposableStack {
+ pub fn new(_: &DeferGc<'_>, vm: &Vm, prototype: Gc<Object>) -> DisposableStack {
DisposableStack {
base: Object::new_with_prototype(vm, Self::CLASS, prototype, MayInterfereWithIndexedPropertyAccess::No),
disposable_state: Cell::new(DisposableState::Pending),
diff --git a/Libraries/LibJS/Rust/src/runtime/disposable_stack_constructor.rs b/Libraries/LibJS/Rust/src/runtime/disposable_stack_constructor.rs
index f094d61e512..18dae68b897 100644
--- a/Libraries/LibJS/Rust/src/runtime/disposable_stack_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/disposable_stack_constructor.rs
@@ -87,7 +87,7 @@ impl DisposableStackConstructor {
realm,
new_target,
Intrinsics::disposable_stack_prototype,
- |_, prototype| DisposableStack::new(vm, prototype),
+ |defer_gc, prototype| DisposableStack::new(defer_gc, vm, prototype),
)?;
Ok(disposable_stack.upcast())
}
diff --git a/Libraries/LibJS/Rust/src/runtime/disposable_stack_prototype.rs b/Libraries/LibJS/Rust/src/runtime/disposable_stack_prototype.rs
index f41e5aaa662..b26cb0dc35d 100644
--- a/Libraries/LibJS/Rust/src/runtime/disposable_stack_prototype.rs
+++ b/Libraries/LibJS/Rust/src/runtime/disposable_stack_prototype.rs
@@ -13,8 +13,7 @@ use crate::layout::cell::Gc;
use crate::layout::object::Object;
use crate::layout::value::Value;
use crate::runtime::abstract_operations::{
- add_disposable_resource, call_function_object, dispose_resources, new_dispose_capability,
- ordinary_create_from_constructor_of,
+ add_disposable_resource, call_function_object, dispose_resources, ordinary_create_from_constructor_of,
};
use crate::runtime::completion::{Completion, ThrowCompletionOr};
use crate::runtime::disposable_stack::{DisposableStack, DisposableState};
@@ -250,14 +249,15 @@ impl DisposableStackPrototype {
realm,
realm.intrinsics().disposable_stack_constructor(vm).upcast(),
Intrinsics::disposable_stack_prototype,
- |_, prototype| DisposableStack::new(vm, prototype),
+ |defer_gc, prototype| DisposableStack::new(defer_gc, vm, prototype),
)?;
// 6. Set newDisposableStack.[[DisposeCapability]] to disposableStack.[[DisposeCapability]].
// 7. Set disposableStack.[[DisposeCapability]] to NewDisposeCapability().
- // NB: The resources move between the stacks once both exist, so that one of them always keeps them alive.
- let dispose_capability = disposable_stack.dispose_capability().replace(new_dispose_capability());
- new_disposable_stack.dispose_capability().replace(dispose_capability);
+ // NB: The new stack's capability is a new one, so swapping the two capabilities performs both steps.
+ disposable_stack
+ .dispose_capability()
+ .swap(new_disposable_stack.dispose_capability());
// 8. Set disposableStack.[[DisposableState]] to disposed.
disposable_stack.set_disposed();
diff --git a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
index fcaeba43d11..c9b4279b1b0 100644
--- a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
@@ -157,8 +157,15 @@ impl EcmascriptFunctionObject {
prototype: Gc<Object>,
) -> Gc<EcmascriptFunctionObject> {
shared_data.note_closure_created();
- let function = allocate_object(vm, |_| {
- Self::new(vm, shared_data, parent_environment, private_environment, prototype)
+ let function = allocate_object(vm, |defer_gc| {
+ Self::new(
+ defer_gc,
+ vm,
+ shared_data,
+ parent_environment,
+ private_environment,
+ prototype,
+ )
});
function.initialize(vm, realm);
function
@@ -183,6 +190,7 @@ impl EcmascriptFunctionObject {
}
fn new(
+ _: &DeferGc<'_>,
vm: &Vm,
shared_data: Gc<SharedFunctionInstanceData>,
parent_environment: Option<Gc<Environment>>,
diff --git a/Libraries/LibJS/Rust/src/runtime/finalization_registry.rs b/Libraries/LibJS/Rust/src/runtime/finalization_registry.rs
index 253452cfcdf..7234e59b06b 100644
--- a/Libraries/LibJS/Rust/src/runtime/finalization_registry.rs
+++ b/Libraries/LibJS/Rust/src/runtime/finalization_registry.rs
@@ -9,6 +9,7 @@ use core::ops::Deref;
use libjs_runtime_macros::Trace;
use crate::gc::class::{Finalize, GcCell, define_cell};
+use crate::gc::defer_gc::DeferGc;
use crate::gc::gc_ref_cell::GcRefCell;
use crate::gc::sweep::Sweep;
use crate::gc::visitor::{Trace, Visitor};
@@ -81,6 +82,7 @@ impl Finalize for FinalizationRegistry {
impl FinalizationRegistry {
pub fn new(
+ _: &DeferGc<'_>,
vm: &Vm,
realm: Gc<Realm>,
cleanup_callback: Gc<JobCallback>,
diff --git a/Libraries/LibJS/Rust/src/runtime/finalization_registry_constructor.rs b/Libraries/LibJS/Rust/src/runtime/finalization_registry_constructor.rs
index 8c5bd575f86..5dfca032805 100644
--- a/Libraries/LibJS/Rust/src/runtime/finalization_registry_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/finalization_registry_constructor.rs
@@ -99,7 +99,9 @@ impl FinalizationRegistryConstructor {
realm,
new_target,
Intrinsics::finalization_registry_prototype,
- |_, prototype| FinalizationRegistry::new(vm, function_realm, cleanup_job_callback, prototype),
+ |defer_gc, prototype| {
+ FinalizationRegistry::new(defer_gc, vm, function_realm, cleanup_job_callback, prototype)
+ },
)?;
Ok(finalization_registry.upcast())
}
diff --git a/Libraries/LibJS/Rust/src/runtime/json_object.rs b/Libraries/LibJS/Rust/src/runtime/json_object.rs
index 49b209c5b84..c8957b26f21 100644
--- a/Libraries/LibJS/Rust/src/runtime/json_object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/json_object.rs
@@ -234,8 +234,8 @@ pub struct JsonStringifyCache {
last_text_length: Cell<usize>,
}
-impl Default for JsonStringifyCache {
- fn default() -> Self {
+impl JsonStringifyCache {
+ pub(crate) fn new() -> Self {
Self {
entries: RefCell::new(Box::new([const { None }; JsonStringifyCache::ENTRY_COUNT])),
objects: RefCell::new(Vec::new()),
diff --git a/Libraries/LibJS/Rust/src/runtime/map.rs b/Libraries/LibJS/Rust/src/runtime/map.rs
index 28507e7ff28..8b44a2646bc 100644
--- a/Libraries/LibJS/Rust/src/runtime/map.rs
+++ b/Libraries/LibJS/Rust/src/runtime/map.rs
@@ -11,6 +11,7 @@ use hashbrown::HashMap;
use libjs_runtime_macros::Trace;
use crate::gc::class::{ExternalMemorySize, Finalize, GcCell, define_cell};
+use crate::gc::defer_gc::DeferGc;
use crate::gc::gc_ref_cell::GcRefCell;
use crate::gc::visitor::{Trace, Visitor};
use crate::interpreter::vm::Vm;
@@ -137,7 +138,7 @@ impl Finalize for Map {
}
impl Map {
- pub fn new(vm: &Vm, prototype: Gc<Object>) -> Map {
+ pub fn new(_: &DeferGc<'_>, vm: &Vm, prototype: Gc<Object>) -> Map {
Map {
base: Object::new_with_prototype(vm, Self::CLASS, prototype, MayInterfereWithIndexedPropertyAccess::No),
storage: GcRefCell::new(MapStorage::default()),
@@ -145,7 +146,9 @@ impl Map {
}
pub fn create(vm: &Vm, realm: Gc<Realm>) -> Gc<Map> {
- realm.create_object(vm, |_| Map::new(vm, realm.intrinsics().map_prototype(vm)))
+ realm.create_object(vm, |defer_gc| {
+ Map::new(defer_gc, vm, realm.intrinsics().map_prototype(vm))
+ })
}
// 24.1.3.1 Map.prototype.clear ( ), https://tc39.es/ecma262/#sec-map.prototype.clear
diff --git a/Libraries/LibJS/Rust/src/runtime/map_constructor.rs b/Libraries/LibJS/Rust/src/runtime/map_constructor.rs
index c9a50f9006d..4bfa62c8ce7 100644
--- a/Libraries/LibJS/Rust/src/runtime/map_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/map_constructor.rs
@@ -180,10 +180,13 @@ impl MapConstructor {
fn construct(_: &NativeFunction, vm: &Vm, new_target: Gc<FunctionObject>) -> ThrowCompletionOr<Gc<Object>> {
let realm = vm.current_realm().expect("a constructor runs in a realm");
- let map =
- ordinary_create_from_constructor_of(vm, realm, new_target, Intrinsics::map_prototype, |_, prototype| {
- Map::new(vm, prototype)
- })?;
+ let map = ordinary_create_from_constructor_of(
+ vm,
+ realm,
+ new_target,
+ Intrinsics::map_prototype,
+ |defer_gc, prototype| Map::new(defer_gc, vm, prototype),
+ )?;
if vm.argument(0).is_nullish() {
return Ok(map.upcast());
diff --git a/Libraries/LibJS/Rust/src/runtime/object.rs b/Libraries/LibJS/Rust/src/runtime/object.rs
index adb1ff9a93b..0dd32a8cbba 100644
--- a/Libraries/LibJS/Rust/src/runtime/object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/object.rs
@@ -90,8 +90,8 @@ impl PrivateElements {
fn ensure(&self) -> &GcRefCell<Vec<PrivateElement>> {
if self.0.get().is_none() {
- let elements = Box::new(GcRefCell::new(Vec::new()));
- self.0.set(Some(NonNull::from(Box::leak(elements))));
+ self.0
+ .set(Some(NonNull::from(Box::leak(Box::new(GcRefCell::new(Vec::new()))))));
}
self.get().expect("the private elements were just allocated")
}
@@ -3910,27 +3910,29 @@ impl Object {
}
fn transition_to_dictionary(&self) {
- let mut dictionary = GenericIndexedPropertyStorage::default();
-
- let kind = self.indexed_storage_kind();
- if kind == IndexedStorageKind::Packed || kind == IndexedStorageKind::Holey {
- // Transfer existing elements
- let count = self.indexed_packed_element_count();
- for index in 0..count {
- let value = self.indexed_element(index);
- if !value.is_empty() {
- dictionary.put(index, value, DEFAULT_ATTRIBUTES);
+ DeferGc::scope(self.vm(), |_| {
+ let mut dictionary = GenericIndexedPropertyStorage::default();
+
+ let kind = self.indexed_storage_kind();
+ if kind == IndexedStorageKind::Packed || kind == IndexedStorageKind::Holey {
+ // Transfer existing elements
+ let count = self.indexed_packed_element_count();
+ for index in 0..count {
+ let value = self.indexed_element(index);
+ if !value.is_empty() {
+ dictionary.put(index, value, DEFAULT_ATTRIBUTES);
+ }
}
+ self.release_indexed_elements();
}
- self.release_indexed_elements();
- }
- // Set the array_like_size on the dictionary
- dictionary.set_array_like_size(self.indexed_array_like_size() as usize);
+ // Set the array_like_size on the dictionary
+ dictionary.set_array_like_size(self.indexed_array_like_size() as usize);
- let dictionary = Box::into_raw(Box::new(GcRefCell::new(dictionary)));
- self.indexed_elements.set(dictionary.cast::<Value>());
- self.indexed_storage_kind.set(IndexedStorageKind::Dictionary);
+ let dictionary = Box::into_raw(Box::new(GcRefCell::new(dictionary)));
+ self.indexed_elements.set(dictionary.cast::<Value>());
+ self.indexed_storage_kind.set(IndexedStorageKind::Dictionary);
+ });
}
#[cold]
diff --git a/Libraries/LibJS/Rust/src/runtime/promise.rs b/Libraries/LibJS/Rust/src/runtime/promise.rs
index afa7670d546..52487ea2973 100644
--- a/Libraries/LibJS/Rust/src/runtime/promise.rs
+++ b/Libraries/LibJS/Rust/src/runtime/promise.rs
@@ -11,6 +11,7 @@ use ak::Utf16String;
use libjs_runtime_macros::Trace;
use crate::gc::class::{Class, ExternalMemorySize, GcCell, define_cell};
+use crate::gc::defer_gc::DeferGc;
use crate::gc::gc_ref_cell::GcRefCell;
use crate::interpreter::vm::Vm;
use crate::layout::cell::Gc;
@@ -124,13 +125,13 @@ impl Deref for Promise {
impl Promise {
pub fn create(vm: &Vm, realm: Gc<Realm>) -> Gc<Promise> {
- realm.create_object(vm, |_| {
- Promise::new(vm, Self::CLASS, realm.intrinsics().promise_prototype(vm))
+ realm.create_object(vm, |defer_gc| {
+ Promise::new(defer_gc, vm, Self::CLASS, realm.intrinsics().promise_prototype(vm))
})
}
/// A promise with `prototype`, for `class`, which is Promise or a class that extends it.
- pub fn new(vm: &Vm, class: &'static Class, prototype: Gc<Object>) -> Promise {
+ pub fn new(_: &DeferGc<'_>, vm: &Vm, class: &'static Class, prototype: Gc<Object>) -> Promise {
Promise {
base: Object::new_with_prototype(vm, class, prototype, MayInterfereWithIndexedPropertyAccess::No),
state: Cell::new(PromiseState::Pending),
diff --git a/Libraries/LibJS/Rust/src/runtime/promise_capability.rs b/Libraries/LibJS/Rust/src/runtime/promise_capability.rs
index 3de72f827fc..a19a956542a 100644
--- a/Libraries/LibJS/Rust/src/runtime/promise_capability.rs
+++ b/Libraries/LibJS/Rust/src/runtime/promise_capability.rs
@@ -144,7 +144,7 @@ pub fn new_promise_capability(vm: &Vm, constructor: Value) -> ThrowCompletionOr<
realm,
constructor.as_function(),
|intrinsics, vm| intrinsics.promise_prototype(vm),
- |_, prototype| Promise::new(vm, Promise::CLASS, prototype),
+ |defer_gc, prototype| Promise::new(defer_gc, vm, Promise::CLASS, prototype),
)?;
let resolving_functions = promise.create_resolving_functions(vm);
return Ok(PromiseCapability::create(
diff --git a/Libraries/LibJS/Rust/src/runtime/promise_constructor.rs b/Libraries/LibJS/Rust/src/runtime/promise_constructor.rs
index 2ed206b39dc..0b82503f077 100644
--- a/Libraries/LibJS/Rust/src/runtime/promise_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/promise_constructor.rs
@@ -742,7 +742,7 @@ impl PromiseConstructor {
realm,
new_target,
|intrinsics, vm| intrinsics.promise_prototype(vm),
- |_, prototype| Promise::new(vm, Promise::CLASS, prototype),
+ |defer_gc, prototype| Promise::new(defer_gc, vm, Promise::CLASS, prototype),
)?;
// 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
diff --git a/Libraries/LibJS/Rust/src/runtime/shape.rs b/Libraries/LibJS/Rust/src/runtime/shape.rs
index 2e0580a8dec..a6fa1c2373e 100644
--- a/Libraries/LibJS/Rust/src/runtime/shape.rs
+++ b/Libraries/LibJS/Rust/src/runtime/shape.rs
@@ -11,6 +11,7 @@ use std::collections::{HashMap, HashSet};
use indexmap::IndexMap;
use crate::gc::class::{GcCell, define_cell};
+use crate::gc::defer_gc::DeferGc;
use crate::gc::gc_ref_cell::GcRefCell;
use crate::gc::root::MarkedVec;
use crate::gc::sweep::Sweep;
@@ -137,8 +138,8 @@ pub struct ShapeStorage {
special_property_cache: Cell<Option<Gc<SpecialPropertyCache>>>,
}
-impl Default for ShapeStorage {
- fn default() -> Self {
+impl ShapeStorage {
+ fn new(_: &DeferGc<'_>) -> Self {
Self {
property_storage: GcRefCell::new(PropertyStorage::Descriptors(None)),
forward_transitions: GcRefCell::new(ForwardTransitions::Empty),
@@ -297,7 +298,7 @@ impl Default for PrototypeTransitionCache {
}
impl Shape {
- fn new(realm: Gc<Realm>) -> Self {
+ fn new(defer_gc: &DeferGc<'_>, realm: Gc<Realm>) -> Self {
Self {
header: CellHeader::for_class(Self::CLASS),
flags: Cell::new(0),
@@ -307,12 +308,16 @@ impl Shape {
property_iterator_cache: Cell::new(None),
property_count: Cell::new(0),
dictionary_generation: Cell::new(0),
- storage: ShapeStorage::default(),
+ storage: ShapeStorage::new(defer_gc),
}
}
- fn new_from_previous_shape(previous_shape: &Shape, property_count_change: PropertyCountChange) -> Self {
- let shape = Self::new(previous_shape.realm());
+ fn new_from_previous_shape(
+ defer_gc: &DeferGc<'_>,
+ previous_shape: &Shape,
+ property_count_change: PropertyCountChange,
+ ) -> Self {
+ let shape = Self::new(defer_gc, previous_shape.realm());
shape
.flags
.set(previous_shape.flags.get() & shape_flag::HAS_PARAMETER_MAP);
@@ -335,11 +340,12 @@ impl Shape {
}
fn new_from_previous_shape_with_prototype(
+ defer_gc: &DeferGc<'_>,
previous_shape: &Shape,
realm: Gc<Realm>,
new_prototype: Option<Gc<Object>>,
) -> Self {
- let shape = Self::new(realm);
+ let shape = Self::new(defer_gc, realm);
shape
.flags
.set(previous_shape.flags.get() & shape_flag::HAS_PARAMETER_MAP);
@@ -353,7 +359,7 @@ impl Shape {
/// A new unique shape with no properties and no prototype.
pub fn create(vm: &Vm, realm: Gc<Realm>) -> Gc<Shape> {
- vm.heap().allocate(|_| Self::new(realm))
+ vm.heap().allocate(|defer_gc| Self::new(defer_gc, realm))
}
fn as_gc(&self) -> Gc<Shape> {
@@ -578,7 +584,7 @@ impl Shape {
}
let new_shape = vm
.heap()
- .allocate(|_| Self::new_from_previous_shape(self, PropertyCountChange::Increment));
+ .allocate(|defer_gc| Self::new_from_previous_shape(defer_gc, self, PropertyCountChange::Increment));
let property_count = self.property_count();
let metadata = PropertyMetadata {
@@ -619,7 +625,7 @@ impl Shape {
}
let new_shape = vm
.heap()
- .allocate(|_| Self::new_from_previous_shape(self, PropertyCountChange::Preserve));
+ .allocate(|defer_gc| Self::new_from_previous_shape(defer_gc, self, PropertyCountChange::Preserve));
let descriptors = self.copy_descriptors(vm);
new_shape.set_descriptors(Some(descriptors));
descriptors.set_attributes(vm, property_key, attributes, self.property_count());
@@ -675,7 +681,7 @@ impl Shape {
}
let new_shape = vm
.heap()
- .allocate(|_| Self::new_from_previous_shape_with_prototype(self, realm, new_prototype));
+ .allocate(|defer_gc| Self::new_from_previous_shape_with_prototype(defer_gc, self, realm, new_prototype));
if self.is_dictionary() && self.property_count() > MAX_DESCRIPTOR_COUNT {
new_shape.become_dictionary_shape();
self.copy_properties_to_dictionary_shape(vm, &new_shape);
@@ -695,7 +701,7 @@ impl Shape {
}
let new_shape = vm
.heap()
- .allocate(|_| Self::new_from_previous_shape(self, PropertyCountChange::Decrement));
+ .allocate(|defer_gc| Self::new_from_previous_shape(defer_gc, self, PropertyCountChange::Decrement));
let descriptors = self.copy_descriptors(vm);
new_shape.set_descriptors(Some(descriptors));
descriptors.remove(vm, property_key, self.property_count());
diff --git a/Libraries/LibJS/Rust/src/runtime/source_text_module.rs b/Libraries/LibJS/Rust/src/runtime/source_text_module.rs
index b6bbf7784f3..c8574c32679 100644
--- a/Libraries/LibJS/Rust/src/runtime/source_text_module.rs
+++ b/Libraries/LibJS/Rust/src/runtime/source_text_module.rs
@@ -444,8 +444,9 @@ impl SourceTextModule {
(Some(parts.executable), None)
};
- let module = vm.heap().allocate(|_| SourceTextModule {
+ let module = vm.heap().allocate(|defer_gc| SourceTextModule {
base: CyclicModule::new(
+ defer_gc,
Self::CLASS,
realm,
filename.to_string(),
diff --git a/Libraries/LibJS/Rust/src/runtime/weak_map.rs b/Libraries/LibJS/Rust/src/runtime/weak_map.rs
index d3dccc67d6c..d29552929e6 100644
--- a/Libraries/LibJS/Rust/src/runtime/weak_map.rs
+++ b/Libraries/LibJS/Rust/src/runtime/weak_map.rs
@@ -10,6 +10,7 @@ use hashbrown::HashMap;
use libjs_runtime_macros::Trace;
use crate::gc::class::{ExternalMemorySize, Finalize, GcCell, define_cell};
+use crate::gc::defer_gc::DeferGc;
use crate::gc::gc_ref_cell::GcRefCell;
use crate::gc::sweep::Sweep;
use crate::gc::visitor::{Trace, Visitor};
@@ -79,7 +80,7 @@ impl Finalize for WeakMap {
}
impl WeakMap {
- pub fn new(vm: &Vm, prototype: Gc<Object>) -> WeakMap {
+ pub fn new(_: &DeferGc<'_>, vm: &Vm, prototype: Gc<Object>) -> WeakMap {
WeakMap {
base: Object::new_with_prototype(vm, Self::CLASS, prototype, MayInterfereWithIndexedPropertyAccess::No),
values: GcRefCell::new(WeakMapValues::default()),
@@ -87,7 +88,9 @@ impl WeakMap {
}
pub fn create(vm: &Vm, realm: Gc<Realm>) -> Gc<WeakMap> {
- realm.create_object(vm, |_| WeakMap::new(vm, realm.intrinsics().weak_map_prototype(vm)))
+ realm.create_object(vm, |defer_gc| {
+ WeakMap::new(defer_gc, vm, realm.intrinsics().weak_map_prototype(vm))
+ })
}
/// Registers the new WeakMap as a weak container.
diff --git a/Libraries/LibJS/Rust/src/runtime/weak_map_constructor.rs b/Libraries/LibJS/Rust/src/runtime/weak_map_constructor.rs
index 6f1c54dbdfe..df7486de097 100644
--- a/Libraries/LibJS/Rust/src/runtime/weak_map_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/weak_map_constructor.rs
@@ -85,7 +85,7 @@ impl WeakMapConstructor {
realm,
new_target,
Intrinsics::weak_map_prototype,
- |_, prototype| WeakMap::new(vm, prototype),
+ |defer_gc, prototype| WeakMap::new(defer_gc, vm, prototype),
)?;
// 4. If iterable is either undefined or null, return map.
diff --git a/Libraries/LibJS/Rust/src/runtime/weak_set.rs b/Libraries/LibJS/Rust/src/runtime/weak_set.rs
index f85924412b6..2ad0af72643 100644
--- a/Libraries/LibJS/Rust/src/runtime/weak_set.rs
+++ b/Libraries/LibJS/Rust/src/runtime/weak_set.rs
@@ -10,6 +10,7 @@ use hashbrown::HashSet;
use libjs_runtime_macros::Trace;
use crate::gc::class::{ExternalMemorySize, Finalize, GcCell, define_cell};
+use crate::gc::defer_gc::DeferGc;
use crate::gc::gc_ref_cell::GcRefCell;
use crate::gc::sweep::Sweep;
use crate::gc::visitor::{Trace, Visitor};
@@ -74,7 +75,7 @@ impl Finalize for WeakSet {
}
impl WeakSet {
- pub fn new(vm: &Vm, prototype: Gc<Object>) -> WeakSet {
+ pub fn new(_: &DeferGc<'_>, vm: &Vm, prototype: Gc<Object>) -> WeakSet {
WeakSet {
base: Object::new_with_prototype(vm, Self::CLASS, prototype, MayInterfereWithIndexedPropertyAccess::No),
values: GcRefCell::new(WeakSetValues::default()),
@@ -82,7 +83,9 @@ impl WeakSet {
}
pub fn create(vm: &Vm, realm: Gc<Realm>) -> Gc<WeakSet> {
- realm.create_object(vm, |_| WeakSet::new(vm, realm.intrinsics().weak_set_prototype(vm)))
+ realm.create_object(vm, |defer_gc| {
+ WeakSet::new(defer_gc, vm, realm.intrinsics().weak_set_prototype(vm))
+ })
}
/// Registers the new WeakSet as a weak container.
diff --git a/Libraries/LibJS/Rust/src/runtime/weak_set_constructor.rs b/Libraries/LibJS/Rust/src/runtime/weak_set_constructor.rs
index 0d37a996cc9..baeba68e97e 100644
--- a/Libraries/LibJS/Rust/src/runtime/weak_set_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/weak_set_constructor.rs
@@ -83,7 +83,7 @@ impl WeakSetConstructor {
realm,
new_target,
Intrinsics::weak_set_prototype,
- |_, prototype| WeakSet::new(vm, prototype),
+ |defer_gc, prototype| WeakSet::new(defer_gc, vm, prototype),
)?;
// 4. If iterable is either undefined or null, return set.
diff --git a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs
index 3317495ab7a..5b492869a93 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs
@@ -18,7 +18,7 @@ use libcompositing_rust::display_list::canvas_2d_recorder::{AlphaType, ColorSpac
use libcompositing_rust::display_list::commands::{Canvas2DShadow, CanvasId};
use libgfx_rust::path::Path;
use libgfx_rust::{AffineTransform, Color, CompositingAndBlendingOperator, FloatRect, IntRect, IntSize, WindingRule};
-use libjs_rust::api::{ForeignCellSlot, Gc, GcRefCell, GcRefMut, Realm, Trace, Visitor, Vm};
+use libjs_rust::api::{DeferGc, ForeignCellSlot, Gc, GcRefCell, GcRefMut, Realm, Trace, Visitor, Vm};
use super::canvas::{Canvas, FontMetricsSource, FontSelection, ResolvedFont, StyleValue, parse_color};
use super::drawing_state::{CanvasColor, DrawingState, FillOrStrokeStyle};
@@ -50,7 +50,7 @@ pub(crate) struct RenderingContext2D<K: CanvasKind> {
}
impl<K: CanvasKind> RenderingContext2D<K> {
- pub(crate) fn new(state: ContextState) -> Self {
+ pub(crate) fn new(_: &DeferGc<'_>, state: ContextState) -> Self {
Self {
state,
kind: PhantomData,
@@ -192,7 +192,7 @@ pub(crate) fn paint_of<'a>(
}
impl ContextState {
- pub(crate) fn new(parameters: ContextParameters) -> Self {
+ pub(crate) fn new(_: &DeferGc<'_>, parameters: ContextParameters) -> Self {
let canvas_cell = ForeignCellSlot::empty();
// SAFETY: The canvas is a live cell of the heap that the runtime allocates from.
unsafe { canvas_cell.set(Some(parameters.canvas.cell)) };
diff --git a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/exports.rs
index dca64957376..23fc926400c 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/exports.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/exports.rs
@@ -78,7 +78,7 @@ pub unsafe extern "C" fn web_canvas_2d_context_create(
host: NonNull::new(arguments.canvas_host).expect("C++ passes the canvas"),
is_offscreen: arguments.canvas_is_offscreen,
};
- let state = ContextState::new(ContextParameters {
+ let parameters = ContextParameters {
canvas,
context_attributes: CanvasRenderingContext2DSettings {
alpha: arguments.alpha,
@@ -91,11 +91,15 @@ pub unsafe extern "C" fn web_canvas_2d_context_create(
width: arguments.width,
height: arguments.height,
},
- });
+ };
if arguments.canvas_is_offscreen {
- cell_into_abi(allocate(vm, |_| RenderingContext2D::<Offscreen>::new(state)))
+ cell_into_abi(allocate(vm, |defer_gc| {
+ RenderingContext2D::<Offscreen>::new(defer_gc, ContextState::new(defer_gc, parameters))
+ }))
} else {
- cell_into_abi(allocate(vm, |_| RenderingContext2D::<OnScreen>::new(state)))
+ cell_into_abi(allocate(vm, |defer_gc| {
+ RenderingContext2D::<OnScreen>::new(defer_gc, ContextState::new(defer_gc, parameters))
+ }))
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_rect_list.rs b/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_rect_list.rs
index 88c86991e9d..185029869ce 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_rect_list.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_rect_list.rs
@@ -6,7 +6,7 @@
//! https://drafts.fxtf.org/geometry/#domrectlist
-use libjs_rust::api::Trace;
+use libjs_rust::api::{DeferGc, Trace};
use super::dom_rect::DOMRect;
use crate::bindings::interface::{Ref, Wrappable};
@@ -21,7 +21,7 @@ pub(crate) struct DOMRectList {
impl Wrappable for DOMRectList {}
impl DOMRectList {
- pub(crate) fn new(rects: &[Ref<DOMRect>]) -> Self {
+ pub(crate) fn new(_: &DeferGc<'_>, rects: &[Ref<DOMRect>]) -> Self {
Self { rects: rects.to_vec() }
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/geometry/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/geometry/exports.rs
index c7b630480f2..92d26c8f6a4 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/geometry/exports.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/geometry/exports.rs
@@ -115,8 +115,7 @@ pub extern "C" fn web_dom_rect_list_create(vm: &Vm, rects: ak::Span<'_, [f64; 4]
for &[x, y, width, height] in rects.as_slice() {
created.push(allocate(vm, |_| DOMRect::new(x, y, width, height)));
}
- let list = DOMRectList::new(&created.values());
- cell_into_abi(allocate(vm, |_| list))
+ cell_into_abi(allocate(vm, |defer_gc| DOMRectList::new(defer_gc, &created.values())))
}
/// A new DOMMatrix whose elements m11, m12, m13, m14, m21, ..., m44 are the values, in that order.
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/cross_realm_transform.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/cross_realm_transform.rs
index 18f31f7f852..01b5c57f6ac 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/cross_realm_transform.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/cross_realm_transform.rs
@@ -335,7 +335,7 @@ pub(crate) fn set_up_cross_realm_transform_readable(
initialize_readable_stream(stream);
// 2. Let controller be a new ReadableStreamDefaultController.
- let controller = allocate(cx.vm(), |_| ReadableStreamDefaultController::new());
+ let controller = allocate(cx.vm(), ReadableStreamDefaultController::new);
let state = ReadableHandlerState {
port: PORT_CELL_CLASS.allocate(cx.vm(), |_| PortCell(port.clone())),
controller,
@@ -511,7 +511,7 @@ pub(crate) fn set_up_cross_realm_transform_writable(
initialize_writable_stream(cx.vm(), stream);
// 2. Let controller be a new WritableStreamDefaultController.
- let controller = allocate(cx.vm(), |_| WritableStreamDefaultController::new());
+ let controller = allocate(cx.vm(), WritableStreamDefaultController::new);
// 3. Let backpressurePromise be a new promise.
let state = CROSS_REALM_WRITABLE_STATE_CLASS.allocate(cx.vm(), |_| CrossRealmWritableState {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/queue_with_sizes.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/queue_with_sizes.rs
index 4d46581efd9..1084356d68e 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/queue_with_sizes.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/queue_with_sizes.rs
@@ -10,7 +10,7 @@ use std::collections::VecDeque;
use core::cell::Cell;
-use libjs_rust::api::{GcRefCell, Trace, Value, Vm};
+use libjs_rust::api::{DeferGc, GcRefCell, Trace, Value, Vm};
use crate::bindings::{Exception, WebIdlResult};
use crate::streams::abstract_operations::is_non_negative_number;
@@ -34,8 +34,8 @@ pub(crate) struct QueueWithSizes {
queue_total_size: Cell<f64>,
}
-impl Default for QueueWithSizes {
- fn default() -> Self {
+impl QueueWithSizes {
+ pub(crate) fn new(_: &DeferGc<'_>) -> Self {
Self {
queue: GcRefCell::new(VecDeque::new()),
queue_total_size: Cell::new(0.0),
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_byte_stream_controller.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_byte_stream_controller.rs
index 0dabe846b8f..24cfbebd902 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_byte_stream_controller.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_byte_stream_controller.rs
@@ -12,8 +12,9 @@ use std::collections::VecDeque;
use core::cell::Cell;
use libjs_rust::api::{
- ArrayBuffer, ArrayBufferShared, EmbedderCell, EmbedderClass, EmbedderValue, ErrorKind, ErrorType, FunctionObject,
- Gc, GcRefCell, MarkedVec, Must, Throw, Trace, TypedArrayBase, Value, Vm, clone_array_buffer, construct,
+ ArrayBuffer, ArrayBufferShared, DeferGc, EmbedderCell, EmbedderClass, EmbedderValue, ErrorKind, ErrorType,
+ FunctionObject, Gc, GcRefCell, MarkedVec, Must, Throw, Trace, TypedArrayBase, Value, Vm, clone_array_buffer,
+ construct,
};
use crate::bindings::conversions::{ArrayBufferView, BufferSource};
@@ -135,7 +136,7 @@ pub(crate) struct ReadableByteStreamController {
impl Wrappable for ReadableByteStreamController {}
impl ReadableByteStreamController {
- pub(crate) fn new() -> Self {
+ pub(crate) fn new(_: &DeferGc<'_>) -> Self {
Self {
auto_allocate_chunk_size: Cell::new(None),
byob_request: Cell::new(None),
@@ -1921,7 +1922,7 @@ pub(crate) fn set_up_readable_byte_stream_controller_from_underlying_source(
high_water_mark: f64,
) -> WebIdlResult<()> {
// 1. Let controller be a new ReadableByteStreamController.
- let controller = allocate(cx.vm(), |_| ReadableByteStreamController::new());
+ let controller = allocate(cx.vm(), ReadableByteStreamController::new);
// 2. Let startAlgorithm be an algorithm that returns undefined.
let mut start_algorithm = StartAlgorithm::ReturnsUndefined;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream.rs
index 4c77a867815..9b086456490 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream.rs
@@ -574,7 +574,7 @@ impl Transferable for ReadableStream {
let (port1, port2) = create_entangled_ports(cx);
// 5. Let writable be a new WritableStream in the current Realm.
- let writable = allocate(cx.vm(), |_| WritableStream::new(cx.realm()));
+ let writable = allocate(cx.vm(), |defer_gc| WritableStream::new(defer_gc, cx.realm()));
// 6. Perform ! SetUpCrossRealmTransformWritable(writable, port1).
set_up_cross_realm_transform_writable(cx, writable, port1);
@@ -631,7 +631,7 @@ impl ReadableStream {
// 4. Perform ! InitializeReadableStream(stream).
// 5. Let controller be a new ReadableByteStreamController.
- let controller = allocate(cx.vm(), |_| ReadableByteStreamController::new());
+ let controller = allocate(cx.vm(), ReadableByteStreamController::new);
// 6. Perform ! SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithmWrapper,
// cancelAlgorithmWrapper, highWaterMark, undefined).
@@ -820,7 +820,7 @@ pub(crate) fn acquire_readable_stream_byob_reader(
stream: Ref<ReadableStream>,
) -> WebIdlResult<Ref<ReadableStreamBYOBReader>> {
// 1. Let reader be a new ReadableStreamBYOBReader.
- let reader = allocate(cx.vm(), |_| ReadableStreamBYOBReader::new());
+ let reader = allocate(cx.vm(), ReadableStreamBYOBReader::new);
// 2. Perform ? SetUpReadableStreamBYOBReader(reader, stream).
set_up_readable_stream_byob_reader(cx, reader, stream)?;
@@ -835,7 +835,7 @@ pub(crate) fn acquire_readable_stream_default_reader(
stream: Ref<ReadableStream>,
) -> WebIdlResult<Ref<ReadableStreamDefaultReader>> {
// 1. Let reader be a new ReadableStreamDefaultReader.
- let reader = allocate(cx.vm(), |_| ReadableStreamDefaultReader::new());
+ let reader = allocate(cx.vm(), ReadableStreamDefaultReader::new);
// 2. Perform ? SetUpReadableStreamDefaultReader(reader, stream).
set_up_readable_stream_default_reader(cx, reader, stream)?;
@@ -893,7 +893,7 @@ pub(crate) fn create_readable_stream_with_existing_stream(
initialize_readable_stream(stream);
// 6. Let controller be a new ReadableStreamDefaultController.
- let controller = allocate(cx.vm(), |_| ReadableStreamDefaultController::new());
+ let controller = allocate(cx.vm(), ReadableStreamDefaultController::new);
// 7. Perform ? SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm,
// cancelAlgorithm, highWaterMark, sizeAlgorithm).
@@ -923,7 +923,7 @@ pub(crate) fn create_readable_byte_stream(
let stream = allocate(cx.vm(), |_| ReadableStream::new(cx.realm()));
// 3. Let controller be a new ReadableByteStreamController.
- let controller = allocate(cx.vm(), |_| ReadableByteStreamController::new());
+ let controller = allocate(cx.vm(), ReadableByteStreamController::new);
// 4. Perform ? SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm,
// cancelAlgorithm, 0, undefined).
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_byob_reader.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_byob_reader.rs
index 36a4fcee49e..a6de1c6f12f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_byob_reader.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_byob_reader.rs
@@ -8,7 +8,7 @@
use std::collections::VecDeque;
-use libjs_rust::api::{GcRefCell, MarkedVec, Trace, Value, Vm};
+use libjs_rust::api::{DeferGc, GcRefCell, MarkedVec, Trace, Value, Vm};
use crate::bindings::conversions::{ArrayBufferView, BufferSource};
use crate::bindings::interface::{Ref, Wrappable, allocate};
@@ -44,7 +44,7 @@ pub(crate) struct ReadableStreamBYOBReader {
impl Wrappable for ReadableStreamBYOBReader {}
impl ReadableStreamBYOBReader {
- pub(crate) fn new() -> Self {
+ pub(crate) fn new(_: &DeferGc<'_>) -> Self {
Self {
generic: ReadableStreamGenericReader::default(),
read_into_requests: GcRefCell::new(VecDeque::new()),
@@ -87,7 +87,7 @@ impl ReadableStreamBYOBReader {
// https://streams.spec.whatwg.org/#byob-reader-constructor
pub(crate) fn construct(cx: &mut CallContext, stream: Ref<ReadableStream>) -> WebIdlResult<Ref<Self>> {
- let reader = allocate(cx.vm(), |_| Self::new());
+ let reader = allocate(cx.vm(), Self::new);
// 1. Perform ? SetUpReadableStreamBYOBReader(this, stream).
set_up_readable_stream_byob_reader(cx, reader, stream)?;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_default_controller.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_default_controller.rs
index 07296a5f389..7c5e22fa002 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_default_controller.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_default_controller.rs
@@ -9,7 +9,7 @@
use core::cell::Cell;
-use libjs_rust::api::{GcRefCell, Throw, Trace, Value, Vm};
+use libjs_rust::api::{DeferGc, GcRefCell, Throw, Trace, Value, Vm};
use crate::bindings::interface::{Ref, Wrappable, allocate};
use crate::bindings::promise::{WebIdlPromise, create_resolved_promise, exception_value, react_to_promise};
@@ -55,14 +55,14 @@ pub(crate) struct ReadableStreamDefaultController {
impl Wrappable for ReadableStreamDefaultController {}
impl ReadableStreamDefaultController {
- pub(crate) fn new() -> Self {
+ pub(crate) fn new(defer_gc: &DeferGc<'_>) -> Self {
Self {
cancel_algorithm: GcRefCell::new(None),
close_requested: Cell::new(false),
pull_again: Cell::new(false),
pull_algorithm: GcRefCell::new(None),
pulling: Cell::new(false),
- queue: QueueWithSizes::default(),
+ queue: QueueWithSizes::new(defer_gc),
started: Cell::new(false),
strategy_hwm: Cell::new(0.0),
strategy_size_algorithm: GcRefCell::new(None),
@@ -557,7 +557,7 @@ pub(crate) fn set_up_readable_stream_default_controller_from_underlying_source(
size_algorithm: SizeAlgorithm,
) -> WebIdlResult<()> {
// 1. Let controller be a new ReadableStreamDefaultController.
- let controller = allocate(cx.vm(), |_| ReadableStreamDefaultController::new());
+ let controller = allocate(cx.vm(), ReadableStreamDefaultController::new);
// 2. Let startAlgorithm be an algorithm that returns undefined.
let mut start_algorithm = StartAlgorithm::ReturnsUndefined;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_default_reader.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_default_reader.rs
index ff7fd542853..3df74334963 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_default_reader.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_default_reader.rs
@@ -11,8 +11,8 @@ use std::collections::VecDeque;
use core::cell::Cell;
use libjs_rust::api::{
- EmbedderCell, EmbedderClass, EmbedderValue, Gc, GcRefCell, MarkedVec, Realm, Trace, TypedArrayBase, TypedArrayKind,
- Value, Vm,
+ DeferGc, EmbedderCell, EmbedderClass, EmbedderValue, Gc, GcRefCell, MarkedVec, Realm, Trace, TypedArrayBase,
+ TypedArrayKind, Value, Vm,
};
use crate::bindings::conversions::BufferSource;
@@ -56,7 +56,7 @@ pub(crate) struct ReadableStreamDefaultReader {
impl Wrappable for ReadableStreamDefaultReader {}
impl ReadableStreamDefaultReader {
- pub(crate) fn new() -> Self {
+ pub(crate) fn new(_: &DeferGc<'_>) -> Self {
Self {
generic: ReadableStreamGenericReader::default(),
read_requests: GcRefCell::new(VecDeque::new()),
@@ -104,7 +104,7 @@ impl ReadableStreamDefaultReader {
// https://streams.spec.whatwg.org/#default-reader-constructor
pub(crate) fn construct(cx: &mut CallContext, stream: Ref<ReadableStream>) -> WebIdlResult<Ref<Self>> {
- let reader = allocate(cx.vm(), |_| Self::new());
+ let reader = allocate(cx.vm(), Self::new);
// 1. Perform ? SetUpReadableStreamDefaultReader(this, stream).
set_up_readable_stream_default_reader(cx, reader, stream)?;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream.rs
index 6c433bd12fc..f6ee52f89f6 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream.rs
@@ -12,7 +12,7 @@ use std::collections::VecDeque;
use core::cell::Cell;
use ak::Utf16String;
-use libjs_rust::api::{Gc, GcRefCell, MarkedVec, Object, Realm, Trace, Value, Vm};
+use libjs_rust::api::{DeferGc, Gc, GcRefCell, MarkedVec, Object, Realm, Trace, Value, Vm};
use crate::bindings::conversions::FromJs;
use crate::bindings::interface::{Ref, Wrappable, allocate, with_temporary_execution_context_and_callbacks};
@@ -98,7 +98,7 @@ impl Wrappable for WritableStream {}
impl WritableStream {
/// A new WritableStream in the realm, which InitializeWritableStream has initialized.
- pub(crate) fn new(realm: Gc<Realm>) -> Self {
+ pub(crate) fn new(_: &DeferGc<'_>, realm: Gc<Realm>) -> Self {
Self {
realm: Cell::new(realm),
backpressure: Cell::new(false),
@@ -180,7 +180,7 @@ impl WritableStream {
}
// 4. Perform ! InitializeWritableStream(this).
- let this = allocate(cx.vm(), |_| Self::new(cx.realm()));
+ let this = allocate(cx.vm(), |defer_gc| Self::new(defer_gc, cx.realm()));
// 5. Let sizeAlgorithm be ! ExtractSizeAlgorithm(strategy).
let size_algorithm = extract_size_algorithm(&strategy);
@@ -294,7 +294,7 @@ impl Transferable for WritableStream {
fn transfer_receiving_steps(cx: &mut CallContext, data_holder: &mut TransferDataReader) -> WebIdlResult<Ref<Self>> {
let cx: &CallContext = cx;
with_temporary_execution_context_and_callbacks(cx.realm(), || {
- let value = allocate(cx.vm(), |_| Self::new(cx.realm()));
+ let value = allocate(cx.vm(), |defer_gc| Self::new(defer_gc, cx.realm()));
// 1. Let deserializedRecord be ! StructuredDeserializeWithTransfer(dataHolder.[[port]], the current
// Realm).
@@ -338,13 +338,13 @@ pub(crate) fn create_writable_stream(
assert!(is_non_negative_number(Value::from_f64(high_water_mark)));
// 2. Let stream be a new WritableStream.
- let stream = allocate(cx.vm(), |_| WritableStream::new(cx.realm()));
+ let stream = allocate(cx.vm(), |defer_gc| WritableStream::new(defer_gc, cx.realm()));
// 3. Perform ! InitializeWritableStream(stream).
initialize_writable_stream(cx.vm(), stream);
// 4. Let controller be a new WritableStreamDefaultController.
- let controller = allocate(cx.vm(), |_| WritableStreamDefaultController::new());
+ let controller = allocate(cx.vm(), WritableStreamDefaultController::new);
// 5. Perform ? SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm,
// closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm).
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream_default_controller.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream_default_controller.rs
index 39e3b1bfc6d..4cc08c38781 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream_default_controller.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream_default_controller.rs
@@ -9,7 +9,7 @@
use core::cell::Cell;
-use libjs_rust::api::{GcRefCell, Trace, Value, Vm};
+use libjs_rust::api::{DeferGc, GcRefCell, Trace, Value, Vm};
use crate::bindings::conversions::CppInterface;
use crate::bindings::interface::{Ref, Wrappable, allocate, wrap};
@@ -70,11 +70,11 @@ pub(crate) struct WritableStreamDefaultController {
impl Wrappable for WritableStreamDefaultController {}
impl WritableStreamDefaultController {
- pub(crate) fn new() -> Self {
+ pub(crate) fn new(defer_gc: &DeferGc<'_>) -> Self {
Self {
abort_algorithm: GcRefCell::new(None),
close_algorithm: GcRefCell::new(None),
- queue: QueueWithSizes::default(),
+ queue: QueueWithSizes::new(defer_gc),
signal: GcRefCell::new(None),
started: Cell::new(false),
strategy_hwm: Cell::new(0.0),
@@ -280,7 +280,7 @@ pub(crate) fn set_up_writable_stream_default_controller_from_underlying_sink(
size_algorithm: SizeAlgorithm,
) -> WebIdlResult<()> {
// 1. Let controller be a new WritableStreamDefaultController.
- let controller = allocate(cx.vm(), |_| WritableStreamDefaultController::new());
+ let controller = allocate(cx.vm(), WritableStreamDefaultController::new);
// 2. Let startAlgorithm be an algorithm that returns undefined.
let mut start_algorithm = StartAlgorithm::ReturnsUndefined;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs
index 34496cc2308..986d0440069 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs
@@ -149,7 +149,7 @@ pub unsafe extern "C" fn web_webgl_context_create(
} else {
WebGLVersion::WebGL1
};
- let state = ContextState::new(ContextParameters {
+ let parameters = ContextParameters {
// SAFETY: The caller hands over a reference to the transport.
proxy: Proxy::new(unsafe { CppTransport::from_raw(transport) }),
version,
@@ -157,15 +157,19 @@ pub unsafe extern "C" fn web_webgl_context_create(
canvas,
context_attributes: arguments.context_attributes.into(),
supported_opengl_extensions: extension_names(arguments.supported_extensions),
- });
+ };
match version {
WebGLVersion::WebGL1 => {
- let context = allocate(vm, |_| RenderingContext::<WebGL1>::new(state));
+ let context = allocate(vm, |defer_gc| {
+ RenderingContext::<WebGL1>::new(defer_gc, ContextState::new(defer_gc, parameters))
+ });
context.set_context_ref(ContextRef::WebGL1(context));
cell_into_abi(context)
}
WebGLVersion::WebGL2 => {
- let context = allocate(vm, |_| RenderingContext::<WebGL2>::new(state));
+ let context = allocate(vm, |defer_gc| {
+ RenderingContext::<WebGL2>::new(defer_gc, ContextState::new(defer_gc, parameters))
+ });
context.set_context_ref(ContextRef::WebGL2(context));
cell_into_abi(context)
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs
index 43d39757eee..4b106e4687e 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs
@@ -13,7 +13,7 @@ use core::marker::PhantomData;
use core::ops::Deref;
use ak::Utf16String;
-use libjs_rust::api::{ForeignCellSlot, Gc, GcRefCell, Realm, Trace, Visitor, Vm};
+use libjs_rust::api::{DeferGc, ForeignCellSlot, Gc, GcRefCell, Realm, Trace, Visitor, Vm};
use super::canvas::{
Canvas, TexImageSourceFrame, TexImageSourceKind, read_tex_image_frame, read_tex_image_pixels, read_tex_image_source,
@@ -66,7 +66,7 @@ pub(crate) struct RenderingContext<V: Version> {
}
impl<V: Version> RenderingContext<V> {
- pub(crate) fn new(state: ContextState) -> Self {
+ pub(crate) fn new(_: &DeferGc<'_>, state: ContextState) -> Self {
Self {
state,
version: PhantomData,
@@ -210,7 +210,7 @@ pub(crate) struct ContextParameters {
}
impl ContextState {
- pub(crate) fn new(parameters: ContextParameters) -> Self {
+ pub(crate) fn new(_: &DeferGc<'_>, parameters: ContextParameters) -> Self {
let canvas_cell = ForeignCellSlot::empty();
// SAFETY: The canvas is a live cell of the heap that the runtime allocates from.
unsafe { canvas_cell.set(Some(parameters.canvas.cell)) };