Skip to content

Truly independent web browser

LibJS+LibWeb: Defer collections while traced state is borrowed

Shannon Booth69122ccae957
diff --git a/Libraries/LibJS/Rust/src/api.rs b/Libraries/LibJS/Rust/src/api.rs
index 4b307273159..07628ad68ee 100644
--- a/Libraries/LibJS/Rust/src/api.rs
+++ b/Libraries/LibJS/Rust/src/api.rs
@@ -13,7 +13,7 @@ pub use crate::embedding::host::host_object::{HostObject, host_class_of, host_da
pub use crate::gc::class::ExternalMemorySize;
pub use crate::gc::embedder_cell::{EmbedderCell, EmbedderClass, EmbedderValue};
pub use crate::gc::foreign::ForeignCellSlot;
-pub use crate::gc::gc_ref_cell::GcRefCell;
+pub use crate::gc::gc_ref_cell::{GcRefCell, GcRefMut};
pub use crate::gc::root::{MarkedVec, Root};
pub use crate::gc::visitor::{Trace, Visitor};
pub use crate::gc::weak::GcWeak;
diff --git a/Libraries/LibJS/Rust/src/gc/gc_ref_cell.rs b/Libraries/LibJS/Rust/src/gc/gc_ref_cell.rs
index afb5119d51e..374c5af498b 100644
--- a/Libraries/LibJS/Rust/src/gc/gc_ref_cell.rs
+++ b/Libraries/LibJS/Rust/src/gc/gc_ref_cell.rs
@@ -5,11 +5,15 @@
*/
use core::cell::{Ref, RefCell, RefMut};
+use core::ops::{Deref, DerefMut};
+use super::defer_gc::DeferGc;
+use super::sweep::Sweep;
use super::visitor::{Trace, Visitor};
+use crate::interpreter::vm::Vm;
-/// Interior mutability for the compound state of a cell. A collection can happen at any allocation and needs to read
-/// the state, so nothing may allocate while holding a mutable borrow; a collection that finds one stops the process.
+/// Interior mutability for the compound state of a cell, which a collection reads. A mutable borrow defers collections
+/// for as long as it lives, so a collection never finds the state borrowed: allocating meanwhile only grows the heap.
pub struct GcRefCell<T>(RefCell<T>);
impl<T> GcRefCell<T> {
@@ -21,7 +25,16 @@ impl<T> GcRefCell<T> {
self.0.borrow()
}
- pub fn borrow_mut(&self) -> RefMut<'_, T> {
+ pub fn borrow_mut<'a>(&'a self, vm: &'a Vm) -> GcRefMut<'a, T> {
+ let defer_gc = DeferGc::new(vm);
+ GcRefMut {
+ borrow: self.0.borrow_mut(),
+ _defer_gc: defer_gc,
+ }
+ }
+
+ /// Borrows the state mutably from the sweep callback of a collection, which nothing collects during.
+ pub(crate) fn borrow_mut_in_sweep(&self, _: &Sweep<'_>) -> RefMut<'_, T> {
self.0.borrow_mut()
}
@@ -46,3 +59,34 @@ unsafe impl<T: Trace> Trace for GcRefCell<T> {
value.trace(visitor);
}
}
+
+/// A mutable borrow of the state in a GcRefCell, with the deferral of collections that it holds until it ends.
+pub struct GcRefMut<'a, T: ?Sized> {
+ // NB: Fields drop in order, so the borrow ends before the collection it may have deferred runs.
+ borrow: RefMut<'a, T>,
+ _defer_gc: DeferGc<'a>,
+}
+
+impl<'a, T: ?Sized> GcRefMut<'a, T> {
+ /// Borrows a part of the state, as RefMut::map() does.
+ pub fn map<U: ?Sized>(borrow: Self, part: impl FnOnce(&mut T) -> &mut U) -> GcRefMut<'a, U> {
+ GcRefMut {
+ borrow: RefMut::map(borrow.borrow, part),
+ _defer_gc: borrow._defer_gc,
+ }
+ }
+}
+
+impl<T: ?Sized> Deref for GcRefMut<'_, T> {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ &self.borrow
+ }
+}
+
+impl<T: ?Sized> DerefMut for GcRefMut<'_, T> {
+ fn deref_mut(&mut self) -> &mut T {
+ &mut self.borrow
+ }
+}
diff --git a/Libraries/LibJS/Rust/src/gc/root.rs b/Libraries/LibJS/Rust/src/gc/root.rs
index 6c3069915c4..772010252a4 100644
--- a/Libraries/LibJS/Rust/src/gc/root.rs
+++ b/Libraries/LibJS/Rust/src/gc/root.rs
@@ -6,10 +6,10 @@
//! Precise roots for values that live outside cells and outside the stack, where the collector would not find them.
-use core::cell::{OnceCell, Ref, RefCell, RefMut};
+use core::cell::{OnceCell, Ref, RefCell};
use core::ops::{Deref, DerefMut};
-use super::gc_ref_cell::GcRefCell;
+use super::gc_ref_cell::{GcRefCell, GcRefMut};
use super::visitor::{Trace, Visitor};
use crate::interpreter::vm::Vm;
@@ -96,7 +96,7 @@ impl<'vm, T: Trace + Clone + 'static> MarkedVec<'vm, T> {
pub fn with_capacity(vm: &'vm Vm, capacity: usize) -> Self {
let list = Self::new(vm);
if capacity > 0 {
- list.rooted_values().borrow_mut().reserve(capacity);
+ list.rooted_values().borrow_mut(vm).reserve(capacity);
}
list
}
@@ -108,25 +108,25 @@ impl<'vm, T: Trace + Clone + 'static> MarkedVec<'vm, T> {
}
pub fn push(&self, value: T) {
- self.rooted_values().borrow_mut().push(value);
+ self.rooted_values().borrow_mut(self.vm).push(value);
}
pub fn extend_from_slice(&self, values: &[T]) {
- self.rooted_values().borrow_mut().extend_from_slice(values);
+ self.rooted_values().borrow_mut(self.vm).extend_from_slice(values);
}
pub fn insert(&self, index: usize, value: T) {
- self.rooted_values().borrow_mut().insert(index, value);
+ self.rooted_values().borrow_mut(self.vm).insert(index, value);
}
pub fn clear(&self) {
if let Some(values) = self.values.get() {
- values.get().borrow_mut().clear();
+ values.get().borrow_mut(self.vm).clear();
}
}
pub fn pop(&self) -> Option<T> {
- self.values.get()?.get().borrow_mut().pop()
+ self.values.get()?.get().borrow_mut(self.vm).pop()
}
pub fn get(&self, index: usize) -> Option<T> {
@@ -134,11 +134,11 @@ impl<'vm, T: Trace + Clone + 'static> MarkedVec<'vm, T> {
}
pub fn resize(&self, length: usize, value: T) {
- self.rooted_values().borrow_mut().resize(length, value);
+ self.rooted_values().borrow_mut(self.vm).resize(length, value);
}
pub fn set(&self, index: usize, value: T) {
- self.rooted_values().borrow_mut()[index] = value;
+ self.rooted_values().borrow_mut(self.vm)[index] = value;
}
pub fn len(&self) -> usize {
@@ -154,10 +154,10 @@ impl<'vm, T: Trace + Clone + 'static> MarkedVec<'vm, T> {
MarkedValues(self.values.get().map(|values| values.get().borrow()))
}
- /// Lends the values to change in place until the result drops. Nothing may collect meanwhile, which stops the
- /// process, and using the list meanwhile panics.
+ /// Lends the values to change in place until the result drops, which collections wait for. Using the list meanwhile
+ /// panics.
pub fn values_mut(&self) -> MarkedValuesMut<'_, T> {
- MarkedValuesMut(self.values.get().map(|values| values.get().borrow_mut()))
+ MarkedValuesMut(self.values.get().map(|values| values.get().borrow_mut(self.vm)))
}
/// Copies the values out, for handing them to code that does not collect.
@@ -180,7 +180,7 @@ impl<T> Deref for MarkedValues<'_, T> {
}
/// The values of a MarkedVec, which stay alive while this lends them to change in place.
-pub struct MarkedValuesMut<'a, T>(Option<RefMut<'a, Vec<T>>>);
+pub struct MarkedValuesMut<'a, T>(Option<GcRefMut<'a, Vec<T>>>);
impl<T> Deref for MarkedValuesMut<'_, T> {
type Target = [T];
diff --git a/Libraries/LibJS/Rust/src/gc/sweep.rs b/Libraries/LibJS/Rust/src/gc/sweep.rs
index 8e581043d74..6527158b196 100644
--- a/Libraries/LibJS/Rust/src/gc/sweep.rs
+++ b/Libraries/LibJS/Rust/src/gc/sweep.rs
@@ -34,6 +34,6 @@ impl<'vm> Sweep<'vm> {
/// Hands `finalization_registry` to HostEnqueueFinalizationRegistryCleanupJob once the collection is over.
pub fn enqueue_finalization_registry_cleanup_job(&self, finalization_registry: Gc<FinalizationRegistry>) {
self.0
- .enqueue_finalization_registry_cleanup_job_after_collection(finalization_registry);
+ .enqueue_finalization_registry_cleanup_job_after_collection(self, finalization_registry);
}
}
diff --git a/Libraries/LibJS/Rust/src/interpreter/vm.rs b/Libraries/LibJS/Rust/src/interpreter/vm.rs
index c5aa71b7d03..f21ea1fad11 100644
--- a/Libraries/LibJS/Rust/src/interpreter/vm.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/vm.rs
@@ -1150,9 +1150,10 @@ impl Vm {
/// over. Only the sweep callback calls this, through its Sweep.
pub(crate) fn enqueue_finalization_registry_cleanup_job_after_collection(
&self,
+ sweep: &Sweep<'_>,
finalization_registry: Gc<FinalizationRegistry>,
) {
- let mut finalization_registries = self.finalization_registries_with_dead_cells.borrow_mut();
+ let mut finalization_registries = self.finalization_registries_with_dead_cells.borrow_mut_in_sweep(sweep);
if finalization_registries.is_empty() {
let context = core::ptr::from_ref::<Vm>(self).cast_mut().cast();
// SAFETY: The VM outlives its heap, which runs the task before it is destroyed.
@@ -1168,7 +1169,7 @@ impl Vm {
// NB: Each registry stays in the rooted list until it is handed to the host, which may allocate.
loop {
let finalization_registry = {
- let mut finalization_registries = self.finalization_registries_with_dead_cells.borrow_mut();
+ let mut finalization_registries = self.finalization_registries_with_dead_cells.borrow_mut(self);
if finalization_registries.is_empty() {
break;
}
@@ -1551,7 +1552,7 @@ impl Vm {
fn run_queued_promise_jobs_impl(&self) {
let job_queues = self.job_queues();
loop {
- let Some(job) = job_queues.promise_jobs.borrow_mut().pop_front() else {
+ let Some(job) = job_queues.promise_jobs.borrow_mut(self).pop_front() else {
break;
};
let _ = HeapFunction::call(job, self);
@@ -1565,13 +1566,14 @@ impl Vm {
// - FIXME: Let scriptOrModule be GetActiveScriptOrModule() at the time HostEnqueuePromiseJob is invoked. If realm is not null, each time job is invoked the implementation must perform implementation-defined steps
// such that scriptOrModule is the active script or module at the time of job's invocation.
// - Jobs must run in the same order as the HostEnqueuePromiseJob invocations that scheduled them.
- self.job_queues().promise_jobs.borrow_mut().push_back(job);
+ self.job_queues().promise_jobs.borrow_mut(self).push_back(job);
}
pub fn run_queued_finalization_registry_cleanup_jobs(&self) {
let job_queues = self.job_queues();
loop {
- let Some(finalization_registry) = job_queues.finalization_registry_cleanup_jobs.borrow_mut().pop() else {
+ let Some(finalization_registry) = job_queues.finalization_registry_cleanup_jobs.borrow_mut(self).pop()
+ else {
break;
};
// FIXME: Handle any uncatched exceptions here.
@@ -1579,7 +1581,7 @@ impl Vm {
if result.is_err() && finalization_registry.has_empty_cells() {
job_queues
.finalization_registry_cleanup_jobs
- .borrow_mut()
+ .borrow_mut(self)
.push(finalization_registry);
}
}
@@ -1589,7 +1591,7 @@ impl Vm {
pub fn enqueue_finalization_registry_cleanup_job(&self, finalization_registry: Gc<FinalizationRegistry>) {
self.job_queues()
.finalization_registry_cleanup_jobs
- .borrow_mut()
+ .borrow_mut(self)
.push(finalization_registry);
}
@@ -2233,13 +2235,16 @@ impl Vm {
}
fn store_module(&self, referrer: ImportedModuleReferrer, filename: String, module: Gc<Module>) {
- self.loaded_modules().stored_modules.borrow_mut().push(StoredModule {
- referrer,
- filename,
- module_type: String::new(),
- module,
- has_once_started_linking: true,
- });
+ self.loaded_modules()
+ .stored_modules
+ .borrow_mut(self)
+ .push(StoredModule {
+ referrer,
+ filename,
+ module_type: String::new(),
+ module,
+ has_once_started_linking: true,
+ });
}
pub fn link_and_eval_module(&self, module: Gc<CyclicModule>) -> ThrowCompletionOr<()> {
diff --git a/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs b/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
index 62269029caa..38aa985eee8 100644
--- a/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
+++ b/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
@@ -2152,7 +2152,7 @@ pub fn add_disposable_resource(
// 3. Append resource to disposeCapability.[[DisposableResourceStack]].
// NB: Creating the resource can run JavaScript, so the capability is only borrowed to append to it.
dispose_capability
- .borrow_mut()
+ .borrow_mut(vm)
.disposable_resource_stack
.get_or_insert_with(Vec::new)
.push(resource);
@@ -2417,7 +2417,7 @@ pub fn dispose_resources(
// collection, at this point.
// 6. Set disposeCapability.[[DisposableResourceStack]] to a new empty List.
- dispose_capability.borrow_mut().disposable_resource_stack = None;
+ dispose_capability.borrow_mut(vm).disposable_resource_stack = None;
// 7. Return completion.
completion
diff --git a/Libraries/LibJS/Rust/src/runtime/array_buffer.rs b/Libraries/LibJS/Rust/src/runtime/array_buffer.rs
index b5fc90d0913..53f603a3cff 100644
--- a/Libraries/LibJS/Rust/src/runtime/array_buffer.rs
+++ b/Libraries/LibJS/Rust/src/runtime/array_buffer.rs
@@ -1209,7 +1209,9 @@ impl ArrayBuffer {
let old_external_memory_size = self.external_memory_size();
let old_data_offset = self.data_offset();
- self.data_block.borrow_mut().try_resize(new_size, zero_fill_new_bytes)?;
+ self.data_block
+ .borrow_mut(vm)
+ .try_resize(new_size, zero_fill_new_bytes)?;
if self.data_offset() != old_data_offset {
self.invalidate_cached_typed_array_view_offsets();
}
@@ -1220,7 +1222,7 @@ impl ArrayBuffer {
pub fn try_ensure_capacity(&self, vm: &Vm, new_capacity: usize) -> Result<(), OutOfMemory> {
let old_external_memory_size = self.external_memory_size();
let old_data_offset = self.data_offset();
- self.data_block.borrow_mut().try_ensure_capacity(new_capacity)?;
+ self.data_block.borrow_mut(vm).try_ensure_capacity(new_capacity)?;
if self.data_offset() != old_data_offset {
self.invalidate_cached_typed_array_view_offsets();
}
@@ -1260,7 +1262,7 @@ impl ArrayBuffer {
pub fn register_cached_typed_array_view(&self, vm: &Vm, view: Gc<TypedArrayBase>) {
let view = GcWeak::new(vm.heap(), view);
- let mut cached_views = self.cached_views.borrow_mut();
+ let mut cached_views = self.cached_views.borrow_mut(vm);
// NB: Views that died stay in the list until it is full, which keeps registering amortized constant time.
if cached_views.len() == cached_views.capacity() {
cached_views.retain(|view| view.get().is_some());
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 867144fed28..51e054f994f 100644
--- a/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs
+++ b/Libraries/LibJS/Rust/src/runtime/async_function_driver_wrapper.rs
@@ -139,7 +139,7 @@ impl AsyncFunctionDriverWrapper {
.running_execution_context_if_any()
.expect("an async function awaits in an execution context")
.copy_without_values();
- *this.suspended_execution_context.borrow_mut() = Some(copy);
+ *this.suspended_execution_context.borrow_mut(vm) = Some(copy);
}
// OPTIMIZATION: Fast path for non-thenable values.
diff --git a/Libraries/LibJS/Rust/src/runtime/async_generator.rs b/Libraries/LibJS/Rust/src/runtime/async_generator.rs
index dec8199659d..487f5f2c57c 100644
--- a/Libraries/LibJS/Rust/src/runtime/async_generator.rs
+++ b/Libraries/LibJS/Rust/src/runtime/async_generator.rs
@@ -170,7 +170,7 @@ impl AsyncGenerator {
}
// 27.6.3.4 AsyncGeneratorEnqueue ( generator, completion, promiseCapability ), https://tc39.es/ecma262/#sec-asyncgeneratorenqueue
- pub fn async_generator_enqueue(&self, completion: Completion, promise_capability: Gc<PromiseCapability>) {
+ pub fn async_generator_enqueue(&self, vm: &Vm, completion: Completion, promise_capability: Gc<PromiseCapability>) {
// 1. Let request be AsyncGeneratorRequest { [[Completion]]: completion, [[Capability]]: promiseCapability }.
let request = AsyncGeneratorRequest {
completion,
@@ -178,7 +178,7 @@ impl AsyncGenerator {
};
// 2. Append request to generator.[[AsyncGeneratorQueue]].
- self.async_generator_queue.borrow_mut().push_back(request);
+ self.async_generator_queue.borrow_mut(vm).push_back(request);
// 3. Return unused.
}
@@ -578,7 +578,7 @@ impl AsyncGenerator {
// 3. Remove the first element from generator.[[AsyncGeneratorQueue]].
let next = self
.async_generator_queue
- .borrow_mut()
+ .borrow_mut(vm)
.pop_front()
.expect("the queue is not empty");
diff --git a/Libraries/LibJS/Rust/src/runtime/async_generator_prototype.rs b/Libraries/LibJS/Rust/src/runtime/async_generator_prototype.rs
index f433af24300..2fcf29f04d6 100644
--- a/Libraries/LibJS/Rust/src/runtime/async_generator_prototype.rs
+++ b/Libraries/LibJS/Rust/src/runtime/async_generator_prototype.rs
@@ -173,7 +173,7 @@ impl AsyncGeneratorPrototype {
let completion = Completion::normal(vm.argument(0));
// 8. Perform AsyncGeneratorEnqueue(generator, completion, promiseCapability).
- generator.async_generator_enqueue(completion, promise_capability);
+ generator.async_generator_enqueue(vm, completion, promise_capability);
// 9. If state is either suspendedStart or suspendedYield, then
if state == AsyncGeneratorState::SuspendedStart || state == AsyncGeneratorState::SuspendedYield {
@@ -213,7 +213,7 @@ impl AsyncGeneratorPrototype {
let completion = Completion::new(CompletionType::Return, vm.argument(0));
// 6. Perform AsyncGeneratorEnqueue(gen, completion, promiseCapability).
- generator.async_generator_enqueue(completion, promise_capability);
+ generator.async_generator_enqueue(vm, completion, promise_capability);
// 7. Let state be gen.[[AsyncGeneratorState]].
let state = generator.async_generator_state();
@@ -288,7 +288,7 @@ impl AsyncGeneratorPrototype {
let completion = Completion::new(CompletionType::Throw, exception);
// 9. Perform AsyncGeneratorEnqueue(generator, completion, promiseCapability).
- generator.async_generator_enqueue(completion, promise_capability);
+ generator.async_generator_enqueue(vm, completion, promise_capability);
// 10. If state is suspendedYield, then
if state == AsyncGeneratorState::SuspendedYield {
diff --git a/Libraries/LibJS/Rust/src/runtime/class_construction.rs b/Libraries/LibJS/Rust/src/runtime/class_construction.rs
index 2c55a9ed6ae..597ac058a91 100644
--- a/Libraries/LibJS/Rust/src/runtime/class_construction.rs
+++ b/Libraries/LibJS/Rust/src/runtime/class_construction.rs
@@ -401,11 +401,11 @@ pub fn construct_class(
}
for index in 0..instance_fields.len() {
- class_constructor.add_field(instance_fields.get(index).expect("the index is in bounds"));
+ class_constructor.add_field(vm, instance_fields.get(index).expect("the index is in bounds"));
}
for index in 0..instance_private_methods.len() {
- class_constructor.add_private_method(instance_private_methods.get(index).expect("the index is in bounds"));
+ class_constructor.add_private_method(vm, instance_private_methods.get(index).expect("the index is in bounds"));
}
for index in 0..static_private_methods.len() {
diff --git a/Libraries/LibJS/Rust/src/runtime/cyclic_module.rs b/Libraries/LibJS/Rust/src/runtime/cyclic_module.rs
index 461ff217004..1e22c0f9b76 100644
--- a/Libraries/LibJS/Rust/src/runtime/cyclic_module.rs
+++ b/Libraries/LibJS/Rust/src/runtime/cyclic_module.rs
@@ -572,7 +572,7 @@ impl CyclicModule {
// 2. Append module to requiredModule.[[AsyncParentModules]].
cyclic_module
.async_parent_modules
- .borrow_mut()
+ .borrow_mut(vm)
.push(self.as_cyclic_module_gc());
}
}
@@ -967,7 +967,7 @@ pub fn inner_module_loading(vm: &Vm, state: Gc<GraphLoadingState>, module: Gc<Mo
let cyclic_module = cyclic_module.as_cyclic_module_gc();
// a. Append module to state.[[Visited]].
- state.append_to_visited(cyclic_module);
+ state.append_to_visited(vm, cyclic_module);
// b. Let requestedModulesCount be the number of elements in module.[[RequestedModules]].
let requested_modules_count = cyclic_module.requested_modules().len();
diff --git a/Libraries/LibJS/Rust/src/runtime/descriptor_array.rs b/Libraries/LibJS/Rust/src/runtime/descriptor_array.rs
index 68a4153ab95..477cabcf8fd 100644
--- a/Libraries/LibJS/Rust/src/runtime/descriptor_array.rs
+++ b/Libraries/LibJS/Rust/src/runtime/descriptor_array.rs
@@ -170,9 +170,9 @@ impl DescriptorArray {
Some(entries[index].metadata())
}
- pub fn set(&self, property_key: &PropertyKey, metadata: PropertyMetadata, enum_index: u32) {
+ pub fn set(&self, vm: &Vm, property_key: &PropertyKey, metadata: PropertyMetadata, enum_index: u32) {
set_entry(
- &mut self.entries.borrow_mut(),
+ &mut self.entries.borrow_mut(vm),
&mut self.entry_indices_by_enum_index.borrow_mut(),
property_key,
metadata,
@@ -180,14 +180,20 @@ impl DescriptorArray {
);
}
- pub fn set_attributes(&self, property_key: &PropertyKey, attributes: PropertyAttributes, descriptor_count: u32) {
- let mut entries = self.entries.borrow_mut();
+ pub fn set_attributes(
+ &self,
+ vm: &Vm,
+ property_key: &PropertyKey,
+ attributes: PropertyAttributes,
+ descriptor_count: u32,
+ ) {
+ let mut entries = self.entries.borrow_mut(vm);
let index = find(&entries, property_key, descriptor_count).expect("the property has a descriptor");
entries[index].attributes = u16::from(attributes.bits());
}
- pub fn remove(&self, property_key: &PropertyKey, descriptor_count: u32) {
- let mut entries = self.entries.borrow_mut();
+ pub fn remove(&self, vm: &Vm, property_key: &PropertyKey, descriptor_count: u32) {
+ let mut entries = self.entries.borrow_mut(vm);
let mut entry_indices_by_enum_index = self.entry_indices_by_enum_index.borrow_mut();
let index = find(&entries, property_key, descriptor_count).expect("the property has a descriptor");
diff --git a/Libraries/LibJS/Rust/src/runtime/disposable_resource_stack.rs b/Libraries/LibJS/Rust/src/runtime/disposable_resource_stack.rs
index 67635d81cc1..ce2d47b556f 100644
--- a/Libraries/LibJS/Rust/src/runtime/disposable_resource_stack.rs
+++ b/Libraries/LibJS/Rust/src/runtime/disposable_resource_stack.rs
@@ -160,7 +160,7 @@ impl DisposableResourceStack {
}
self.dispose_capability
- .borrow_mut()
+ .borrow_mut(vm)
.disposable_resource_stack
.as_mut()
.expect("the stack has the resource")
@@ -211,7 +211,7 @@ impl DisposableResourceStack {
// 6. NOTE: At this point disposableResourceStack will never be used again. The contents of
// disposableResourceStack can be discarded in implementations, such as by garbage collection.
- self.dispose_capability.borrow_mut().disposable_resource_stack = None;
+ self.dispose_capability.borrow_mut(vm).disposable_resource_stack = None;
// 7. Return ? outputCompletion.
let output_completion_value = self.output_completion_value.get();
diff --git a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
index 442655b8988..d1304d9db08 100644
--- a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
@@ -717,8 +717,8 @@ impl EcmascriptFunctionObject {
self.name.get().unwrap_or_else(|| self.shared_data().name())
}
- fn ensure_class_data(&self) {
- let mut class_data = self.storage.class_data.borrow_mut();
+ fn ensure_class_data(&self, vm: &Vm) {
+ let mut class_data = self.storage.class_data.borrow_mut(vm);
if class_data.is_none() {
*class_data = Some(Box::default());
}
@@ -747,11 +747,11 @@ impl EcmascriptFunctionObject {
.clone()
}
- pub fn add_field(&self, field: ClassFieldDefinition) {
- self.ensure_class_data();
+ pub fn add_field(&self, vm: &Vm, field: ClassFieldDefinition) {
+ self.ensure_class_data(vm);
self.storage
.class_data
- .borrow_mut()
+ .borrow_mut(vm)
.as_mut()
.expect("the function has class data")
.fields
@@ -777,11 +777,11 @@ impl EcmascriptFunctionObject {
.clone()
}
- pub fn add_private_method(&self, method: PrivateElement) {
- self.ensure_class_data();
+ pub fn add_private_method(&self, vm: &Vm, method: PrivateElement) {
+ self.ensure_class_data(vm);
self.storage
.class_data
- .borrow_mut()
+ .borrow_mut(vm)
.as_mut()
.expect("the function has class data")
.private_methods
diff --git a/Libraries/LibJS/Rust/src/runtime/finalization_registry.rs b/Libraries/LibJS/Rust/src/runtime/finalization_registry.rs
index d78228b6e08..253452cfcdf 100644
--- a/Libraries/LibJS/Rust/src/runtime/finalization_registry.rs
+++ b/Libraries/LibJS/Rust/src/runtime/finalization_registry.rs
@@ -10,8 +10,8 @@ use libjs_runtime_macros::Trace;
use crate::gc::class::{Finalize, GcCell, define_cell};
use crate::gc::gc_ref_cell::GcRefCell;
-use crate::gc::visitor::{Trace, Visitor};
use crate::gc::sweep::Sweep;
+use crate::gc::visitor::{Trace, Visitor};
use crate::gc::weak_container::WeakContainer;
use crate::interpreter::vm::Vm;
use crate::layout::cell::{CellHeader, Gc};
@@ -112,12 +112,13 @@ impl FinalizationRegistry {
pub fn add_finalization_record(
&self,
+ vm: &Vm,
target: Gc<CellHeader>,
held_value: Value,
unregister_token: Option<Gc<CellHeader>>,
) {
assert!(!held_value.is_empty());
- self.records.borrow_mut().0.push(FinalizationRecord {
+ self.records.borrow_mut(vm).0.push(FinalizationRecord {
target: Some(target),
held_value,
unregister_token,
@@ -125,12 +126,12 @@ impl FinalizationRegistry {
}
// Extracted from FinalizationRegistry.prototype.unregister ( unregisterToken )
- pub fn remove_by_token(&self, unregister_token: Gc<CellHeader>) -> bool {
+ pub fn remove_by_token(&self, vm: &Vm, unregister_token: Gc<CellHeader>) -> bool {
// 4. Let removed be false.
let mut removed = false;
// 5. For each Record { [[WeakRefTarget]], [[HeldValue]], [[UnregisterToken]] } cell of finalizationRegistry.[[Cells]], do
- self.records.borrow_mut().0.retain(|record| {
+ self.records.borrow_mut(vm).0.retain(|record| {
// a. If cell.[[UnregisterToken]] is not empty and SameValue(cell.[[UnregisterToken]], unregisterToken) is true, then
if record.unregister_token == Some(unregister_token) {
// i. Remove cell from finalizationRegistry.[[Cells]].
@@ -155,7 +156,7 @@ impl FinalizationRegistry {
.downcast::<FinalizationRegistry>()
.expect("the weak container is a FinalizationRegistry");
let mut any_cells_were_removed = false;
- for record in &mut finalization_registry.records.borrow_mut().0 {
+ for record in &mut finalization_registry.records.borrow_mut_in_sweep(sweep).0 {
let Some(target) = record.target else {
continue;
};
@@ -185,7 +186,7 @@ impl FinalizationRegistry {
// a. Choose any such cell.
// b. Remove cell from finalizationRegistry.[[Cells]].
let held_value = {
- let mut records = self.records.borrow_mut();
+ let mut records = self.records.borrow_mut(vm);
let Some(index) = records.0.iter().position(|record| record.target.is_none()) else {
break;
};
diff --git a/Libraries/LibJS/Rust/src/runtime/finalization_registry_prototype.rs b/Libraries/LibJS/Rust/src/runtime/finalization_registry_prototype.rs
index b705f4be284..dee7900d0ca 100644
--- a/Libraries/LibJS/Rust/src/runtime/finalization_registry_prototype.rs
+++ b/Libraries/LibJS/Rust/src/runtime/finalization_registry_prototype.rs
@@ -129,6 +129,7 @@ impl FinalizationRegistryPrototype {
// 6. Let cell be the Record { [[WeakRefTarget]]: target, [[HeldValue]]: heldValue, [[UnregisterToken]]: unregisterToken }.
// 7. Append cell to finalizationRegistry.[[Cells]].
finalization_registry.add_finalization_record(
+ vm,
target.as_cell(),
held_value,
(!unregister_token.is_undefined()).then(|| unregister_token.as_cell()),
@@ -157,7 +158,7 @@ impl FinalizationRegistryPrototype {
// 4-6.
Ok(Value::from_bool(
- finalization_registry.remove_by_token(unregister_token.as_cell()),
+ finalization_registry.remove_by_token(vm, unregister_token.as_cell()),
))
}
}
diff --git a/Libraries/LibJS/Rust/src/runtime/iterator_constructor.rs b/Libraries/LibJS/Rust/src/runtime/iterator_constructor.rs
index 4b0d3f40c93..1f511770f56 100644
--- a/Libraries/LibJS/Rust/src/runtime/iterator_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/iterator_constructor.rs
@@ -146,7 +146,7 @@ impl IteratorConstructor {
};
// d. Append the Record { [[OpenMethod]]: method, [[Iterable]]: item } to iterables.
- iterables.append_iterable(method, item.as_object());
+ iterables.append_iterable(vm, method, item.as_object());
}
// 3. Let closure be a new Abstract Closure with no parameters that captures iterables and performs the following steps when called:
@@ -259,7 +259,7 @@ impl IteratorConstructor {
};
// iii. Append iter to iters.
- zip_iterator.append_iterator(iterator);
+ zip_iterator.append_iterator(vm, iterator);
}
// 13. Let iterCount be the number of elements in iters.
@@ -273,7 +273,7 @@ impl IteratorConstructor {
// i. Perform the following steps iterCount times:
for _ in 0..iterator_count {
// 1. Append undefined to padding.
- zip_iterator.append_padding(Value::UNDEFINED);
+ zip_iterator.append_padding(vm, Value::UNDEFINED);
}
}
// b. Else,
@@ -307,13 +307,13 @@ impl IteratorConstructor {
None => using_iterator = false,
// d. Else,
// i. Append next to padding.
- Some(next) => zip_iterator.append_padding(next),
+ Some(next) => zip_iterator.append_padding(vm, next),
}
}
// 2. If usingIterator is false, append undefined to padding.
if !using_iterator {
- zip_iterator.append_padding(Value::UNDEFINED);
+ zip_iterator.append_padding(vm, Value::UNDEFINED);
}
}
@@ -398,7 +398,7 @@ impl IteratorConstructor {
// iii. If value is not undefined, then
if !value.is_undefined() {
// 1. Append key to keys.
- zip_iterator.append_key(key);
+ zip_iterator.append_key(vm, key);
// 2. Let iter be Completion(GetIteratorFlattenable(value, REJECT-PRIMITIVES)).
// 3. IfAbruptCloseIterators(iter, iters).
@@ -409,7 +409,7 @@ impl IteratorConstructor {
);
// 4. Append iter to iters.
- zip_iterator.append_iterator(iterator);
+ zip_iterator.append_iterator(vm, iterator);
}
}
}
@@ -425,7 +425,7 @@ impl IteratorConstructor {
// i. Perform the following steps iterCount times:
for _ in 0..iterator_count {
// 1. Append undefined to padding.
- zip_iterator.append_padding(Value::UNDEFINED);
+ zip_iterator.append_padding(vm, Value::UNDEFINED);
}
}
// b. Else,
@@ -440,7 +440,7 @@ impl IteratorConstructor {
try_or_close_iterators!(vm, &zip_iterator.open_iterators(vm), padding_option.get(vm, &key));
// 3. Append value to padding.
- zip_iterator.append_padding(value);
+ zip_iterator.append_padding(vm, value);
}
}
}
@@ -491,9 +491,9 @@ impl ConcatIterator {
})
}
- fn append_iterable(&self, open_method: Gc<FunctionObject>, iterable: Gc<Object>) {
+ fn append_iterable(&self, vm: &Vm, open_method: Gc<FunctionObject>, iterable: Gc<Object>) {
self.iterables
- .borrow_mut()
+ .borrow_mut(vm)
.push(ConcatIterable { open_method, iterable });
}
@@ -665,7 +665,7 @@ impl ZipIterator {
let step_value = match step_value_result {
Err(throw) => {
// i. Remove iter from openIters.
- self.remove_iterator_from_open_iterators(iterator);
+ self.remove_iterator_from_open_iterators(vm, iterator);
// ii. Return ? IteratorCloseAll(openIters, result).
return self.close_all_open_iterators(vm, throw.into());
@@ -678,7 +678,7 @@ impl ZipIterator {
Some(step_value) => result = step_value,
None => {
// i. Remove iter from openIters.
- self.remove_iterator_from_open_iterators(iterator);
+ self.remove_iterator_from_open_iterators(vm, iterator);
match self.mode {
// ii. If mode is "shortest", then
@@ -714,7 +714,7 @@ impl ZipIterator {
let open = match step_result {
Err(throw) => {
// i. Remove iters[k] from openIters.
- self.remove_iterator_from_open_iterators(iterator_k);
+ self.remove_iterator_from_open_iterators(vm, iterator_k);
// ii. Return ? IteratorCloseAll(openIters, open).
return self.close_all_open_iterators(vm, throw.into());
@@ -725,7 +725,7 @@ impl ZipIterator {
// v. If open is DONE, then
if matches!(open, IterationResult::Done) {
// i. Remove iters[k] from openIters.
- self.remove_iterator_from_open_iterators(iterator_k);
+ self.remove_iterator_from_open_iterators(vm, iterator_k);
}
// vi. Else,
else {
@@ -752,7 +752,7 @@ impl ZipIterator {
}
// iii. Set iters[i] to null.
- self.iterators.borrow_mut()[i] = None;
+ self.iterators.borrow_mut(vm)[i] = None;
// iv. Set result to padding[i].
result = self.padding.borrow()[i];
@@ -805,21 +805,21 @@ impl ZipIterator {
self.finish_results.set(Some(finish_results));
}
- fn append_iterator(&self, iterator: Gc<IteratorRecord>) {
- self.iterators.borrow_mut().push(Some(iterator));
- self.open_iterators.borrow_mut().push(iterator);
+ fn append_iterator(&self, vm: &Vm, iterator: Gc<IteratorRecord>) {
+ self.iterators.borrow_mut(vm).push(Some(iterator));
+ self.open_iterators.borrow_mut(vm).push(iterator);
}
- fn append_key(&self, key: PropertyKey) {
- self.keys.borrow_mut().push(key);
+ fn append_key(&self, vm: &Vm, key: PropertyKey) {
+ self.keys.borrow_mut(vm).push(key);
}
- fn append_padding(&self, padding: Value) {
- self.padding.borrow_mut().push(padding);
+ fn append_padding(&self, vm: &Vm, padding: Value) {
+ self.padding.borrow_mut(vm).push(padding);
}
- fn remove_iterator_from_open_iterators(&self, iterator: Gc<IteratorRecord>) {
- let mut open_iterators = self.open_iterators.borrow_mut();
+ fn remove_iterator_from_open_iterators(&self, vm: &Vm, iterator: Gc<IteratorRecord>) {
+ let mut open_iterators = self.open_iterators.borrow_mut(vm);
if let Some(index) = open_iterators.iter().position(|candidate| *candidate == iterator) {
open_iterators.remove(index);
}
diff --git a/Libraries/LibJS/Rust/src/runtime/iterator_helper.rs b/Libraries/LibJS/Rust/src/runtime/iterator_helper.rs
index 88a0aa1a98a..aa9318ed144 100644
--- a/Libraries/LibJS/Rust/src/runtime/iterator_helper.rs
+++ b/Libraries/LibJS/Rust/src/runtime/iterator_helper.rs
@@ -156,7 +156,7 @@ impl IteratorHelper {
counter: Cell::new(0.0),
},
);
- *iterator.underlying_iterators.borrow_mut() = underlying_iterators.to_vec();
+ *iterator.underlying_iterators.borrow_mut(vm) = underlying_iterators.to_vec();
iterator
}
diff --git a/Libraries/LibJS/Rust/src/runtime/map.rs b/Libraries/LibJS/Rust/src/runtime/map.rs
index d483096e6d6..a13a8d86c51 100644
--- a/Libraries/LibJS/Rust/src/runtime/map.rs
+++ b/Libraries/LibJS/Rust/src/runtime/map.rs
@@ -150,7 +150,7 @@ impl Map {
// 24.1.3.1 Map.prototype.clear ( ), https://tc39.es/ecma262/#sec-map.prototype.clear
pub fn map_clear(&self, vm: &Vm) {
- let mut storage = self.storage.borrow_mut();
+ let mut storage = self.storage.borrow_mut(vm);
storage.entries = Vec::new();
storage.indices = HashMap::default();
storage.removed_entry_count = 0;
@@ -162,7 +162,7 @@ impl Map {
// 24.1.3.3 Map.prototype.delete ( key ), https://tc39.es/ecma262/#sec-map.prototype.delete
pub fn map_remove(&self, vm: &Vm, key: Value) -> bool {
- let mut storage = self.storage.borrow_mut();
+ let mut storage = self.storage.borrow_mut(vm);
let Some(index) = storage.indices.remove(&ValueTraitsKey(key)) else {
return false;
};
@@ -200,7 +200,7 @@ impl Map {
// 24.1.3.9 Map.prototype.set ( key, value ), https://tc39.es/ecma262/#sec-map.prototype.set
pub fn map_set(&self, vm: &Vm, key: Value, value: Value) {
- let mut storage = self.storage.borrow_mut();
+ let mut storage = self.storage.borrow_mut(vm);
let new_index = storage.entries.len();
let index = *storage.indices.entry(ValueTraitsKey(key)).or_insert(new_index);
if index != new_index {
diff --git a/Libraries/LibJS/Rust/src/runtime/module.rs b/Libraries/LibJS/Rust/src/runtime/module.rs
index 4f7b92ade88..4487c1d1e18 100644
--- a/Libraries/LibJS/Rust/src/runtime/module.rs
+++ b/Libraries/LibJS/Rust/src/runtime/module.rs
@@ -171,8 +171,8 @@ impl GraphLoadingState {
self.visited.borrow().contains(&module)
}
- pub fn append_to_visited(&self, module: Gc<CyclicModule>) {
- self.visited.borrow_mut().push(module);
+ pub fn append_to_visited(&self, vm: &Vm, module: Gc<CyclicModule>) {
+ self.visited.borrow_mut(vm).push(module);
}
/// The modules of [[Visited]], kept alive by the returned list.
@@ -490,7 +490,7 @@ pub fn finish_loading_imported_module(
// b. Else,
if !found_record {
// i. Append the LoadedModuleRequest Record { [[Specifier]]: moduleRequest.[[Specifier]], [[Attributes]]: moduleRequest.[[Attributes]], [[Module]]: result.[[Value]] } to referrer.[[LoadedModules]].
- loaded_modules.borrow_mut().push(LoadedModuleRequest {
+ loaded_modules.borrow_mut(vm).push(LoadedModuleRequest {
specifier: Utf16String::from(&module_request.module_specifier),
attributes: module_request.attributes.clone(),
module,
diff --git a/Libraries/LibJS/Rust/src/runtime/module_environment.rs b/Libraries/LibJS/Rust/src/runtime/module_environment.rs
index 64579c7e759..a2ea0fb5546 100644
--- a/Libraries/LibJS/Rust/src/runtime/module_environment.rs
+++ b/Libraries/LibJS/Rust/src/runtime/module_environment.rs
@@ -153,6 +153,7 @@ impl ModuleEnvironment {
// 9.1.1.5.5 CreateImportBinding ( N, M, N2 ), https://tc39.es/ecma262/#sec-createimportbinding
pub fn create_import_binding(
&self,
+ vm: &Vm,
name: Utf16FlyString,
module: Option<Gc<Module>>,
binding_name: Utf16FlyString,
@@ -165,7 +166,7 @@ impl ModuleEnvironment {
// 3. Create an immutable indirect binding in envRec for N that references M and N2 as its target binding and record that the binding is initialized.
// Note: We use the fact that the binding is in this map as it being initialized.
self.indirect_bindings
- .borrow_mut()
+ .borrow_mut(vm)
.0
.insert(name, IndirectBinding { module, binding_name });
diff --git a/Libraries/LibJS/Rust/src/runtime/object.rs b/Libraries/LibJS/Rust/src/runtime/object.rs
index f931ccb8809..54b5220b4d8 100644
--- a/Libraries/LibJS/Rust/src/runtime/object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/object.rs
@@ -1218,7 +1218,7 @@ impl Object {
target_shape = target_shape.create_configure_transition(vm, property_key, new_attributes);
}
}
- shape.set_cached_integrity_level_shape(level, target_shape);
+ shape.set_cached_integrity_level_shape(vm, level, target_shape);
target_shape
}
};
@@ -1458,10 +1458,13 @@ impl Object {
for property_key in &enumerable_keys {
copy_shape = copy_shape.create_put_transition(vm, property_key, DEFAULT_ATTRIBUTES);
}
- from_shape.set_cached_assign_copy(AssignCopy {
- prototype_validity,
- copy_shape,
- });
+ from_shape.set_cached_assign_copy(
+ vm,
+ AssignCopy {
+ prototype_validity,
+ copy_shape,
+ },
+ );
copy_shape
}
};
@@ -1694,7 +1697,7 @@ impl Object {
}
// 4. Append PrivateElement { [[Key]]: P, [[Kind]]: field, [[Value]]: value } to O.[[PrivateElements]].
- self.private_elements.ensure().borrow_mut().push(PrivateElement {
+ self.private_elements.ensure().borrow_mut(vm).push(PrivateElement {
key: name.clone(),
kind: PrivateElementKind::Field,
value,
@@ -1725,7 +1728,7 @@ impl Object {
}
// 5. Append method to O.[[PrivateElements]].
- self.private_elements.ensure().borrow_mut().push(element);
+ self.private_elements.ensure().borrow_mut(vm).push(element);
// 6. Return unused.
Ok(())
@@ -1792,7 +1795,7 @@ impl Object {
self.private_elements
.get()
.expect("the object has private elements")
- .borrow_mut()[entry_index]
+ .borrow_mut(vm)[entry_index]
.value = value;
return Ok(());
}
@@ -3985,7 +3988,7 @@ impl Object {
#[cold]
fn indexed_put_into_dictionary(&self, index: u32, value: Value, attributes: PropertyAttributes) {
let promote = {
- let mut dictionary = self.indexed_dictionary().borrow_mut();
+ let mut dictionary = self.indexed_dictionary().borrow_mut(self.vm());
let old_size = dictionary.size();
dictionary.put(index, value, attributes);
let length = dictionary.array_like_size();
@@ -4041,7 +4044,7 @@ impl Object {
}
fn indexed_put_dictionary_and_update_size(&self, index: u32, value: Value, attributes: PropertyAttributes) {
- let mut dictionary = self.indexed_dictionary().borrow_mut();
+ let mut dictionary = self.indexed_dictionary().borrow_mut(self.vm());
dictionary.put(index, value, attributes);
self.indexed_array_like_size.set(dictionary.array_like_size() as u32);
}
@@ -4156,7 +4159,7 @@ impl Object {
}
self.set_indexed_element(index, Value::EMPTY);
}
- IndexedStorageKind::Dictionary => self.indexed_dictionary().borrow_mut().remove(index),
+ IndexedStorageKind::Dictionary => self.indexed_dictionary().borrow_mut(self.vm()).remove(index),
}
}
@@ -4166,7 +4169,7 @@ impl Object {
}
if self.indexed_storage_kind() == IndexedStorageKind::Dictionary {
- let mut dictionary = self.indexed_dictionary().borrow_mut();
+ let mut dictionary = self.indexed_dictionary().borrow_mut(self.vm());
let result = dictionary.set_array_like_size(new_size);
self.indexed_array_like_size.set(dictionary.array_like_size() as u32);
return result;
@@ -4265,7 +4268,7 @@ impl Object {
pub fn indexed_take_first(&self) -> ValueAndAttributes {
if self.indexed_storage_kind() == IndexedStorageKind::Dictionary {
- let mut dictionary = self.indexed_dictionary().borrow_mut();
+ let mut dictionary = self.indexed_dictionary().borrow_mut(self.vm());
let result = dictionary.take_first();
self.indexed_array_like_size.set(dictionary.array_like_size() as u32);
return result;
@@ -4300,7 +4303,7 @@ impl Object {
pub fn indexed_take_last(&self) -> ValueAndAttributes {
if self.indexed_storage_kind() == IndexedStorageKind::Dictionary {
- let mut dictionary = self.indexed_dictionary().borrow_mut();
+ let mut dictionary = self.indexed_dictionary().borrow_mut(self.vm());
let result = dictionary.take_last();
self.indexed_array_like_size.set(dictionary.array_like_size() as u32);
return result;
diff --git a/Libraries/LibJS/Rust/src/runtime/promise.rs b/Libraries/LibJS/Rust/src/runtime/promise.rs
index b811e7628c3..22c67eef80e 100644
--- a/Libraries/LibJS/Rust/src/runtime/promise.rs
+++ b/Libraries/LibJS/Rust/src/runtime/promise.rs
@@ -458,11 +458,11 @@ impl Promise {
PromiseState::Pending => {
// a. Append fulfillReaction as the last element of the List that is promise.[[PromiseFulfillReactions]].
let fulfill_reaction = create_fulfill_reaction();
- self.fulfill_reactions.borrow_mut().push(fulfill_reaction);
+ self.fulfill_reactions.borrow_mut(vm).push(fulfill_reaction);
// b. Append rejectReaction as the last element of the List that is promise.[[PromiseRejectReactions]].
let reject_reaction = create_reject_reaction();
- self.reject_reactions.borrow_mut().push(reject_reaction);
+ self.reject_reactions.borrow_mut(vm).push(reject_reaction);
}
// 10. Else if promise.[[PromiseState]] is fulfilled, then
PromiseState::Fulfilled => {
diff --git a/Libraries/LibJS/Rust/src/runtime/promise_constructor.rs b/Libraries/LibJS/Rust/src/runtime/promise_constructor.rs
index 6c7b9d4b43c..a9d5f9d5a24 100644
--- a/Libraries/LibJS/Rust/src/runtime/promise_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/promise_constructor.rs
@@ -111,7 +111,7 @@ fn run_promise_all_resolve_element_job(
value: Value,
) -> ThrowCompletionOr<Value> {
// 5. Set values[thisIndex] to value.
- values.set(index, value);
+ values.set(vm, index, value);
// 6. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
// 7. If remainingElementsCount.[[Value]] = 0, then
@@ -296,7 +296,7 @@ fn perform_promise_common(
};
// c. Append undefined to values.
- values.append(Value::UNDEFINED);
+ values.append(vm, Value::UNDEFINED);
// d. Let nextPromise be ? Call(promiseResolve, constructor, « next »).
let next_promise = call(vm, promise_resolve, constructor, &[next])?;
diff --git a/Libraries/LibJS/Rust/src/runtime/promise_resolving_element_functions.rs b/Libraries/LibJS/Rust/src/runtime/promise_resolving_element_functions.rs
index 5cc2f80e242..b211b647fc9 100644
--- a/Libraries/LibJS/Rust/src/runtime/promise_resolving_element_functions.rs
+++ b/Libraries/LibJS/Rust/src/runtime/promise_resolving_element_functions.rs
@@ -87,16 +87,16 @@ impl PromiseValueList {
})
}
- pub fn append(&self, value: Value) {
- self.values.borrow_mut().push(value);
+ pub fn append(&self, vm: &Vm, value: Value) {
+ self.values.borrow_mut(vm).push(value);
}
pub fn get(&self, index: usize) -> Value {
self.values.borrow()[index]
}
- pub fn set(&self, index: usize, value: Value) {
- self.values.borrow_mut()[index] = value;
+ pub fn set(&self, vm: &Vm, index: usize, value: Value) {
+ self.values.borrow_mut(vm)[index] = value;
}
/// Array::create_from(realm, values.values()): CreateArrayFromList of the values.
@@ -274,7 +274,7 @@ fn promise_all_resolve_element(function: &PromiseResolvingElementFunction, vm: &
let realm = vm.current_realm().expect("there is a current realm");
// 8. Set values[index] to x.
- function.values().set(function.index(), vm.argument(0));
+ function.values().set(vm, function.index(), vm.argument(0));
// 9. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
// 10. If remainingElementsCount.[[Value]] is 0, then
@@ -333,7 +333,7 @@ fn promise_all_settled_resolve_element(
.must();
// 12. Set values[index] to obj.
- function.values().set(function.index(), Value::from_object(object));
+ function.values().set(vm, function.index(), Value::from_object(object));
// 13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
// 14. If remainingElementsCount.[[Value]] is 0, then
@@ -389,7 +389,7 @@ fn promise_all_settled_reject_element(function: &PromiseResolvingElementFunction
.must();
// 12. Set values[index] to obj.
- function.values().set(function.index(), Value::from_object(object));
+ function.values().set(vm, function.index(), Value::from_object(object));
// 13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
// 14. If remainingElementsCount.[[Value]] is 0, then
@@ -417,7 +417,7 @@ fn promise_any_reject_element(function: &PromiseResolvingElementFunction, vm: &V
let realm = vm.current_realm().expect("there is a current realm");
// 8. Set errors[index] to x.
- function.values().set(function.index(), vm.argument(0));
+ function.values().set(vm, function.index(), vm.argument(0));
// 9. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
// 10. If remainingElementsCount.[[Value]] is 0, then
diff --git a/Libraries/LibJS/Rust/src/runtime/shape.rs b/Libraries/LibJS/Rust/src/runtime/shape.rs
index c8a378616a9..6e318233f83 100644
--- a/Libraries/LibJS/Rust/src/runtime/shape.rs
+++ b/Libraries/LibJS/Rust/src/runtime/shape.rs
@@ -12,8 +12,8 @@ use indexmap::IndexMap;
use crate::gc::class::{GcCell, define_cell};
use crate::gc::gc_ref_cell::GcRefCell;
-use crate::gc::sweep::Sweep;
use crate::gc::root::MarkedVec;
+use crate::gc::sweep::Sweep;
use crate::gc::visitor::{Trace, Visitor};
use crate::gc::weak::GcWeak;
use crate::interpreter::vm::Vm;
@@ -370,12 +370,14 @@ impl Shape {
fn set_descriptors(&self, descriptors: Option<Gc<DescriptorArray>>) {
assert!(!self.is_dictionary());
- *self.storage.property_storage.borrow_mut() = PropertyStorage::Descriptors(descriptors);
+ self.storage
+ .property_storage
+ .replace(PropertyStorage::Descriptors(descriptors));
}
- fn with_property_table<R>(&self, callback: impl FnOnce(&mut PropertyTable) -> R) -> R {
+ fn with_property_table<R>(&self, vm: &Vm, callback: impl FnOnce(&mut PropertyTable) -> R) -> R {
assert!(self.is_dictionary());
- match &mut *self.storage.property_storage.borrow_mut() {
+ match &mut *self.storage.property_storage.borrow_mut(vm) {
PropertyStorage::PropertyTable(property_table) => callback(property_table),
PropertyStorage::Descriptors(_) => unreachable!("a dictionary shape has a property table"),
}
@@ -383,12 +385,14 @@ impl Shape {
fn become_dictionary_shape(&self) {
assert!(!self.is_dictionary());
- *self.storage.property_storage.borrow_mut() = PropertyStorage::PropertyTable(Box::default());
+ self.storage
+ .property_storage
+ .replace(PropertyStorage::PropertyTable(Box::default()));
self.flags.set(self.flags.get() | shape_flag::DICTIONARY);
}
- fn with_rare_data<R>(&self, callback: impl FnOnce(&mut RareData) -> R) -> R {
- let mut rare_data = self.storage.rare_data.borrow_mut();
+ fn with_rare_data<R>(&self, vm: &Vm, callback: impl FnOnce(&mut RareData) -> R) -> R {
+ let mut rare_data = self.storage.rare_data.borrow_mut(vm);
callback(rare_data.get_or_insert_with(Box::default))
}
@@ -401,7 +405,7 @@ impl Shape {
.set(new_shape.flags.get() | (self.flags.get() & shape_flag::HAS_PARAMETER_MAP));
new_shape.prototype.set(self.prototype());
self.invalidate_prototype_if_needed_for_new_prototype(vm, new_shape);
- self.copy_properties_to_dictionary_shape(&new_shape);
+ self.copy_properties_to_dictionary_shape(vm, &new_shape);
new_shape
}
@@ -441,11 +445,11 @@ impl Shape {
longest
}
- fn get_or_prune_cached_forward_transition(&self, key: &TransitionKey) -> Option<Gc<Shape>> {
+ fn get_or_prune_cached_forward_transition(&self, vm: &Vm, key: &TransitionKey) -> Option<Gc<Shape>> {
if self.is_prototype_shape() {
return None;
}
- let mut forward_transitions = self.storage.forward_transitions.borrow_mut();
+ let mut forward_transitions = self.storage.forward_transitions.borrow_mut(vm);
match &mut *forward_transitions {
ForwardTransitions::Empty => None,
ForwardTransitions::Single {
@@ -479,7 +483,7 @@ impl Shape {
assert!(!self.is_prototype_shape());
let target = GcWeak::new(vm.heap(), shape);
- let mut forward_transitions = self.storage.forward_transitions.borrow_mut();
+ let mut forward_transitions = self.storage.forward_transitions.borrow_mut(vm);
match core::mem::replace(&mut *forward_transitions, ForwardTransitions::Empty) {
ForwardTransitions::Empty => {
*forward_transitions = ForwardTransitions::Single {
@@ -527,11 +531,11 @@ impl Shape {
}
}
- fn get_or_prune_cached_delete_transition(&self, key: &PropertyKey) -> Option<Gc<Shape>> {
+ fn get_or_prune_cached_delete_transition(&self, vm: &Vm, key: &PropertyKey) -> Option<Gc<Shape>> {
if self.is_prototype_shape() {
return None;
}
- let mut rare_data = self.storage.rare_data.borrow_mut();
+ let mut rare_data = self.storage.rare_data.borrow_mut(vm);
let delete_transitions = &mut rare_data.as_mut()?.delete_transitions;
let target = delete_transitions.get(key)?;
let Some(shape) = target.get() else {
@@ -542,11 +546,11 @@ impl Shape {
Some(shape)
}
- fn get_or_prune_cached_prototype_transition(&self, prototype: Option<Gc<Object>>) -> Option<Gc<Shape>> {
+ fn get_or_prune_cached_prototype_transition(&self, vm: &Vm, prototype: Option<Gc<Object>>) -> Option<Gc<Shape>> {
if self.is_prototype_shape() {
return None;
}
- let mut rare_data = self.storage.rare_data.borrow_mut();
+ let mut rare_data = self.storage.rare_data.borrow_mut(vm);
let prototype_transitions = &mut rare_data.as_mut()?.prototype_transitions;
let key = prototype_address(prototype);
let target = prototype_transitions.get(&key)?;
@@ -569,7 +573,7 @@ impl Shape {
property_key: property_key.clone(),
attributes,
};
- if let Some(existing_shape) = self.get_or_prune_cached_forward_transition(&key) {
+ if let Some(existing_shape) = self.get_or_prune_cached_forward_transition(vm, &key) {
return existing_shape;
}
let new_shape = vm
@@ -583,13 +587,13 @@ impl Shape {
};
match self.descriptors() {
Some(descriptors) if descriptors.size() == property_count => {
- descriptors.set(property_key, metadata, property_count);
+ descriptors.set(vm, property_key, metadata, property_count);
new_shape.set_descriptors(Some(descriptors));
}
_ => {
let descriptors = self.copy_descriptors(vm);
new_shape.set_descriptors(Some(descriptors));
- descriptors.set(property_key, metadata, property_count);
+ descriptors.set(vm, property_key, metadata, property_count);
}
}
self.invalidate_prototype_if_needed_for_new_prototype(vm, new_shape);
@@ -610,7 +614,7 @@ impl Shape {
property_key: property_key.clone(),
attributes,
};
- if let Some(existing_shape) = self.get_or_prune_cached_forward_transition(&key) {
+ if let Some(existing_shape) = self.get_or_prune_cached_forward_transition(vm, &key) {
return existing_shape;
}
let new_shape = vm
@@ -618,7 +622,7 @@ impl Shape {
.allocate(Self::new_from_previous_shape(self, PropertyCountChange::Preserve));
let descriptors = self.copy_descriptors(vm);
new_shape.set_descriptors(Some(descriptors));
- descriptors.set_attributes(property_key, attributes, self.property_count());
+ descriptors.set_attributes(vm, property_key, attributes, self.property_count());
self.invalidate_prototype_if_needed_for_new_prototype(vm, new_shape);
if !self.is_prototype_shape() {
self.cache_forward_transition(vm, key, new_shape);
@@ -634,7 +638,7 @@ impl Shape {
if let Some(existing_shape) = cache.and_then(|cache| cache.get(self.as_gc(), prototype)) {
return existing_shape;
}
- if let Some(existing_shape) = self.get_or_prune_cached_prototype_transition(new_prototype) {
+ if let Some(existing_shape) = self.get_or_prune_cached_prototype_transition(vm, new_prototype) {
if let Some(cache) = cache {
cache.set(self.as_gc(), prototype, existing_shape);
}
@@ -643,7 +647,9 @@ impl Shape {
let new_shape = self.build_prototype_transition(vm, self.realm(), new_prototype);
if !self.is_prototype_shape() {
let target = GcWeak::new(vm.heap(), new_shape);
- self.with_rare_data(|rare_data| rare_data.prototype_transitions.insert(prototype, target));
+ self.with_rare_data(vm, |rare_data| {
+ rare_data.prototype_transitions.insert(prototype, target)
+ });
}
if let Some(cache) = cache {
cache.set(self.as_gc(), prototype, new_shape);
@@ -672,7 +678,7 @@ impl Shape {
.allocate(Self::new_from_previous_shape_with_prototype(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(&new_shape);
+ self.copy_properties_to_dictionary_shape(vm, &new_shape);
} else if self.is_dictionary() {
new_shape.set_descriptors(Some(self.copy_descriptors(vm)));
} else {
@@ -684,7 +690,7 @@ impl Shape {
pub fn create_delete_transition(&self, vm: &Vm, property_key: &PropertyKey) -> Gc<Shape> {
self.mark_unstable(vm);
- if let Some(existing_shape) = self.get_or_prune_cached_delete_transition(property_key) {
+ if let Some(existing_shape) = self.get_or_prune_cached_delete_transition(vm, property_key) {
return existing_shape;
}
let new_shape = vm
@@ -692,10 +698,12 @@ impl Shape {
.allocate(Self::new_from_previous_shape(self, PropertyCountChange::Decrement));
let descriptors = self.copy_descriptors(vm);
new_shape.set_descriptors(Some(descriptors));
- descriptors.remove(property_key, self.property_count());
+ descriptors.remove(vm, property_key, self.property_count());
self.invalidate_prototype_if_needed_for_new_prototype(vm, new_shape);
let target = GcWeak::new(vm.heap(), new_shape);
- self.with_rare_data(|rare_data| rare_data.delete_transitions.insert(property_key.clone(), target));
+ self.with_rare_data(vm, |rare_data| {
+ rare_data.delete_transitions.insert(property_key.clone(), target)
+ });
new_shape
}
@@ -717,15 +725,15 @@ impl Shape {
let descriptors = DescriptorArray::create(vm);
self.for_each_property_in_insertion_order(|property_key, metadata| {
- descriptors.set(property_key, metadata, descriptors.size());
+ descriptors.set(vm, property_key, metadata, descriptors.size());
ControlFlow::Continue(())
});
descriptors
}
- fn copy_properties_to_dictionary_shape(&self, shape: &Shape) {
+ fn copy_properties_to_dictionary_shape(&self, vm: &Vm, shape: &Shape) {
assert!(shape.is_dictionary());
- let property_count = shape.with_property_table(|property_table| {
+ let property_count = shape.with_property_table(vm, |property_table| {
self.for_each_property_in_insertion_order(|property_key, metadata| {
property_table.insert(property_key.clone(), metadata);
ControlFlow::Continue(())
@@ -745,8 +753,9 @@ impl Shape {
attributes,
};
if self.is_dictionary() {
- let inserted_new_entry = self
- .with_property_table(|property_table| property_table.insert(property_key.clone(), metadata).is_none());
+ let inserted_new_entry = self.with_property_table(vm, |property_table| {
+ property_table.insert(property_key.clone(), metadata).is_none()
+ });
if inserted_new_entry {
assert!(property_count < u32::MAX);
self.property_count.set(property_count + 1);
@@ -762,11 +771,11 @@ impl Shape {
let descriptors = self.descriptors().expect("the shape has a descriptor array");
if descriptors.lookup(property_key, property_count).is_none() {
assert!(property_count < u32::MAX);
- descriptors.set(property_key, metadata, property_count);
+ descriptors.set(vm, property_key, metadata, property_count);
self.property_count.set(property_count + 1);
return;
}
- descriptors.set(property_key, metadata, property_count);
+ descriptors.set(vm, property_key, metadata, property_count);
}
pub fn set_property_attributes_without_transition(
@@ -777,7 +786,7 @@ impl Shape {
) {
self.invalidate_prototype_if_needed_for_change_without_transition(vm);
assert!(self.is_dictionary());
- self.with_property_table(|property_table| {
+ self.with_property_table(vm, |property_table| {
property_table
.get_mut(property_key)
.expect("the dictionary has the property")
@@ -789,7 +798,7 @@ impl Shape {
pub fn remove_property_without_transition(&self, vm: &Vm, property_key: &PropertyKey, offset: u32) {
self.invalidate_prototype_if_needed_for_change_without_transition(vm);
assert!(self.is_dictionary());
- let removed = self.with_property_table(|property_table| {
+ let removed = self.with_property_table(vm, |property_table| {
let removed = property_table.shift_remove(property_key).is_some();
for metadata in property_table.values_mut() {
assert!(metadata.offset != offset);
@@ -829,7 +838,7 @@ impl Shape {
for (property_key, _) in &property_keys {
keys.push(property_key.to_value(vm));
}
- self.with_rare_data(|rare_data| {
+ self.with_rare_data(vm, |rare_data| {
rare_data.own_string_keys = Some(OwnStringKeys {
generation,
keys: keys.values().iter().copied().collect(),
@@ -854,9 +863,9 @@ impl Shape {
.and_then(|rare_data| rare_data.assign_copy)
}
- pub fn set_cached_assign_copy(&self, assign_copy: AssignCopy) {
+ pub fn set_cached_assign_copy(&self, vm: &Vm, assign_copy: AssignCopy) {
assert!(!self.is_dictionary());
- self.with_rare_data(|rare_data| rare_data.assign_copy = Some(assign_copy));
+ self.with_rare_data(vm, |rare_data| rare_data.assign_copy = Some(assign_copy));
}
/// The shape that SetIntegrityLevel with `level` gave objects of this shape that have no accessor properties, if
@@ -869,9 +878,11 @@ impl Shape {
.and_then(|rare_data| rare_data.integrity_level_shapes[level as usize])
}
- pub fn set_cached_integrity_level_shape(&self, level: IntegrityLevel, shape: Gc<Shape>) {
+ pub fn set_cached_integrity_level_shape(&self, vm: &Vm, level: IntegrityLevel, shape: Gc<Shape>) {
assert!(!self.is_dictionary() && !self.is_prototype_shape());
- self.with_rare_data(|rare_data| rare_data.integrity_level_shapes[level as usize] = Some(shape));
+ self.with_rare_data(vm, |rare_data| {
+ rare_data.integrity_level_shapes[level as usize] = Some(shape);
+ });
}
fn increment_dictionary_generation(&self) {
@@ -890,7 +901,7 @@ impl Shape {
new_shape.prototype.set(self.prototype());
if self.is_dictionary() && self.property_count() > MAX_DESCRIPTOR_COUNT {
new_shape.become_dictionary_shape();
- self.copy_properties_to_dictionary_shape(&new_shape);
+ self.copy_properties_to_dictionary_shape(vm, &new_shape);
} else if self.is_dictionary() {
new_shape.set_descriptors(Some(self.copy_descriptors(vm)));
new_shape.property_count.set(self.property_count());
@@ -922,7 +933,7 @@ impl Shape {
assert!(self.is_prototype_shape());
assert!(child.is_prototype_shape());
let child = GcWeak::new(vm.heap(), child);
- self.with_rare_data(|rare_data| rare_data.child_prototype_shapes.push(child));
+ self.with_rare_data(vm, |rare_data| rare_data.child_prototype_shapes.push(child));
}
fn invalidate_prototype_if_needed_for_new_prototype(&self, vm: &Vm, new_prototype_shape: Gc<Shape>) {
@@ -940,12 +951,14 @@ impl Shape {
let child_prototype_shapes = self
.storage
.rare_data
- .borrow_mut()
+ .borrow_mut(vm)
.as_mut()
.filter(|rare_data| !rare_data.child_prototype_shapes.is_empty())
.map(|rare_data| core::mem::take(&mut rare_data.child_prototype_shapes));
if let Some(child_prototype_shapes) = child_prototype_shapes {
- new_prototype_shape.with_rare_data(|rare_data| rare_data.child_prototype_shapes = child_prototype_shapes);
+ new_prototype_shape.with_rare_data(vm, |rare_data| {
+ rare_data.child_prototype_shapes = child_prototype_shapes;
+ });
}
}
@@ -981,7 +994,7 @@ impl Shape {
let shapes_to_invalidate = MarkedVec::new(vm);
let worklist = MarkedVec::new(vm);
let enqueue_children_of = |shape: &Shape, shapes_already_enqueued: &mut HashSet<usize>| {
- let mut rare_data = shape.storage.rare_data.borrow_mut();
+ let mut rare_data = shape.storage.rare_data.borrow_mut(vm);
let Some(rare_data) = rare_data.as_mut() else {
return;
};
@@ -1088,9 +1101,8 @@ impl Shape {
Some(WatchedSlot::Watched(watchpoint_set)) if watchpoint_set.is_valid() => return Some(*watchpoint_set),
_ => {}
}
- // NB: Allocating may collect garbage, which reads the rare data, so the set is made before borrowing it.
let watchpoint_set = WatchpointSet::create(vm);
- self.with_rare_data(|rare_data| {
+ self.with_rare_data(vm, |rare_data| {
rare_data
.watched_slots
.insert(offset, WatchedSlot::Watched(watchpoint_set))
@@ -1133,7 +1145,7 @@ impl Shape {
return;
}
let watchpoint_set = {
- let mut rare_data = self.storage.rare_data.borrow_mut();
+ let mut rare_data = self.storage.rare_data.borrow_mut(vm);
let Some(rare_data) = rare_data.as_mut() else {
return;
};
@@ -1158,8 +1170,9 @@ impl Shape {
if !self.is_prototype_shape() {
return;
}
- let watched_slot =
- self.with_rare_data(|rare_data| rare_data.watched_slots.insert(offset, WatchedSlot::WrittenByCaches));
+ let watched_slot = self.with_rare_data(vm, |rare_data| {
+ rare_data.watched_slots.insert(offset, WatchedSlot::WrittenByCaches)
+ });
if let Some(WatchedSlot::Watched(watchpoint_set)) = watched_slot {
watchpoint_set.fire(vm);
}
@@ -1174,7 +1187,7 @@ impl Shape {
}
self.flags.set(self.flags.get() & !shape_flag::HAS_WATCHED_SLOTS);
let watchpoint_sets = MarkedVec::new(vm);
- if let Some(rare_data) = self.storage.rare_data.borrow_mut().as_mut() {
+ if let Some(rare_data) = self.storage.rare_data.borrow_mut(vm).as_mut() {
rare_data.watched_slots.retain(|_, watched_slot| match watched_slot {
WatchedSlot::Watched(watchpoint_set) => {
watchpoint_sets.push(*watchpoint_set);
@@ -1213,7 +1226,10 @@ impl Shape {
return None;
}
if self.is_dictionary() {
- return self.with_property_table(|property_table| property_table.get(property_key).copied());
+ return match &*self.storage.property_storage.borrow() {
+ PropertyStorage::PropertyTable(property_table) => property_table.get(property_key).copied(),
+ PropertyStorage::Descriptors(_) => unreachable!("a dictionary shape has a property table"),
+ };
}
self.descriptors()?.lookup(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 b5f306ab049..c4a417314ab 100644
--- a/Libraries/LibJS/Rust/src/runtime/source_text_module.rs
+++ b/Libraries/LibJS/Rust/src/runtime/source_text_module.rs
@@ -794,7 +794,7 @@ impl SourceTextModule {
// NB: A link that fails resets the module to unlinked, so this can run more than once.
{
- let mut imported_bindings = self.imported_bindings.borrow_mut();
+ let mut imported_bindings = self.imported_bindings.borrow_mut(vm);
imported_bindings.clear();
imported_bindings.reserve(self.import_entries.len());
}
@@ -814,7 +814,7 @@ impl SourceTextModule {
// ii. Perform ! env.CreateImmutableBinding(in.[[LocalName]], true).
// iii. Perform ! env.InitializeBinding(in.[[LocalName]], namespace, normal).
// AD-HOC: Both steps are performed after step 24.
- self.imported_bindings.borrow_mut().push(ImportedBinding {
+ self.imported_bindings.borrow_mut(vm).push(ImportedBinding {
namespace: Some(namespace),
..ImportedBinding::default()
});
@@ -844,7 +844,7 @@ impl SourceTextModule {
// 2. Perform ! env.CreateImmutableBinding(in.[[LocalName]], true).
// 3. Perform ! env.InitializeBinding(in.[[LocalName]], namespace, normal).
// AD-HOC: Both steps are performed after step 24.
- self.imported_bindings.borrow_mut().push(ImportedBinding {
+ self.imported_bindings.borrow_mut(vm).push(ImportedBinding {
namespace: Some(namespace),
..ImportedBinding::default()
});
@@ -854,12 +854,13 @@ impl SourceTextModule {
// 1. Perform env.CreateImportBinding(in.[[LocalName]], resolution.[[Module]], resolution.[[BindingName]]).
environment
.create_import_binding(
+ vm,
import_entry.local_name.clone(),
Some(resolved_module),
resolution.export_name.clone(),
)
.must();
- self.imported_bindings.borrow_mut().push(ImportedBinding {
+ self.imported_bindings.borrow_mut(vm).push(ImportedBinding {
module: Some(resolved_module),
binding_name: resolution.export_name,
..ImportedBinding::default()
@@ -1039,7 +1040,7 @@ impl SourceTextModule {
let binding_index = u32::try_from(binding_index.expect("the target module binds the name directly"))
.expect("the binding index fits in u32");
{
- let mut imported_bindings = self.imported_bindings.borrow_mut();
+ let mut imported_bindings = self.imported_bindings.borrow_mut(vm);
imported_bindings[import_index].environment = Some(target_environment);
imported_bindings[import_index].binding_index = binding_index;
}
diff --git a/Libraries/LibJS/Rust/src/runtime/symbol.rs b/Libraries/LibJS/Rust/src/runtime/symbol.rs
index 6e0546a07bf..02c7de5a4a2 100644
--- a/Libraries/LibJS/Rust/src/runtime/symbol.rs
+++ b/Libraries/LibJS/Rust/src/runtime/symbol.rs
@@ -162,8 +162,8 @@ impl GlobalSymbolRegistry {
self.symbols.borrow().0.get(&key).copied()
}
- pub fn set(&self, key: &Utf16String, symbol: Gc<Symbol>) {
+ pub fn set(&self, vm: &Vm, key: &Utf16String, symbol: Gc<Symbol>) {
let key = Utf16View::of_string(key).code_units().collect();
- self.symbols.borrow_mut().0.insert(key, symbol);
+ self.symbols.borrow_mut(vm).0.insert(key, symbol);
}
}
diff --git a/Libraries/LibJS/Rust/src/runtime/symbol_constructor.rs b/Libraries/LibJS/Rust/src/runtime/symbol_constructor.rs
index 6d33908fe14..103072f9b5c 100644
--- a/Libraries/LibJS/Rust/src/runtime/symbol_constructor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/symbol_constructor.rs
@@ -152,7 +152,7 @@ impl SymbolConstructor {
let new_symbol = Symbol::create(vm, Some(string_key.clone()), Kind::Global);
// 5. Append the Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to the GlobalSymbolRegistry List.
- global_symbol_registry.set(&string_key, new_symbol);
+ global_symbol_registry.set(vm, &string_key, new_symbol);
// 6. Return newSymbol.
Ok(Value::from_symbol(new_symbol))
diff --git a/Libraries/LibJS/Rust/src/runtime/weak_map.rs b/Libraries/LibJS/Rust/src/runtime/weak_map.rs
index a4d7aa7bdc7..55ca999c6dc 100644
--- a/Libraries/LibJS/Rust/src/runtime/weak_map.rs
+++ b/Libraries/LibJS/Rust/src/runtime/weak_map.rs
@@ -11,8 +11,8 @@ use libjs_runtime_macros::Trace;
use crate::gc::class::{ExternalMemorySize, Finalize, GcCell, define_cell};
use crate::gc::gc_ref_cell::GcRefCell;
-use crate::gc::visitor::{Trace, Visitor};
use crate::gc::sweep::Sweep;
+use crate::gc::visitor::{Trace, Visitor};
use crate::gc::weak_container::WeakContainer;
use crate::interpreter::vm::Vm;
use crate::layout::cell::{CellHeader, Gc};
@@ -104,7 +104,7 @@ impl WeakMap {
}
pub fn weak_map_set(&self, vm: &Vm, key: Gc<CellHeader>, value: Value) {
- let mut values = self.values.borrow_mut();
+ let mut values = self.values.borrow_mut(vm);
let old_size = values.0.allocation_size();
values.0.insert(key, value);
let new_size = values.0.allocation_size();
@@ -112,8 +112,8 @@ impl WeakMap {
vm.heap().account_external_memory_change(old_size, new_size);
}
- pub fn weak_map_remove(&self, key: Gc<CellHeader>) -> bool {
- self.values.borrow_mut().0.remove(&key).is_some()
+ pub fn weak_map_remove(&self, vm: &Vm, key: Gc<CellHeader>) -> bool {
+ self.values.borrow_mut(vm).0.remove(&key).is_some()
}
pub fn weak_map_size(&self) -> usize {
@@ -125,6 +125,10 @@ impl WeakMap {
.as_gc()
.downcast::<WeakMap>()
.expect("the weak container is a WeakMap");
- weak_map.values.borrow_mut().0.retain(|&key, _| !sweep.is_dead(key));
+ weak_map
+ .values
+ .borrow_mut_in_sweep(sweep)
+ .0
+ .retain(|&key, _| !sweep.is_dead(key));
}
}
diff --git a/Libraries/LibJS/Rust/src/runtime/weak_map_prototype.rs b/Libraries/LibJS/Rust/src/runtime/weak_map_prototype.rs
index 800c68d3f82..345befce4af 100644
--- a/Libraries/LibJS/Rust/src/runtime/weak_map_prototype.rs
+++ b/Libraries/LibJS/Rust/src/runtime/weak_map_prototype.rs
@@ -101,7 +101,7 @@ impl WeakMapPrototype {
// ii. Set p.[[Value]] to empty.
// iii. Return true.
// 5. Return false.
- Ok(Value::from_bool(weak_map.weak_map_remove(key.as_cell())))
+ Ok(Value::from_bool(weak_map.weak_map_remove(vm, key.as_cell())))
}
// 24.3.3.3 WeakMap.prototype.get ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.get
diff --git a/Libraries/LibJS/Rust/src/runtime/weak_set.rs b/Libraries/LibJS/Rust/src/runtime/weak_set.rs
index a584dd3b9ab..f1b995c81b3 100644
--- a/Libraries/LibJS/Rust/src/runtime/weak_set.rs
+++ b/Libraries/LibJS/Rust/src/runtime/weak_set.rs
@@ -11,8 +11,8 @@ use libjs_runtime_macros::Trace;
use crate::gc::class::{ExternalMemorySize, Finalize, GcCell, define_cell};
use crate::gc::gc_ref_cell::GcRefCell;
-use crate::gc::visitor::{Trace, Visitor};
use crate::gc::sweep::Sweep;
+use crate::gc::visitor::{Trace, Visitor};
use crate::gc::weak_container::WeakContainer;
use crate::interpreter::vm::Vm;
use crate::layout::cell::{CellHeader, Gc};
@@ -95,7 +95,7 @@ impl WeakSet {
}
pub fn weak_set_add(&self, vm: &Vm, value: Gc<CellHeader>) {
- let mut values = self.values.borrow_mut();
+ let mut values = self.values.borrow_mut(vm);
let old_size = values.0.allocation_size();
values.0.insert(value);
let new_size = values.0.allocation_size();
@@ -103,8 +103,8 @@ impl WeakSet {
vm.heap().account_external_memory_change(old_size, new_size);
}
- pub fn weak_set_remove(&self, value: Gc<CellHeader>) -> bool {
- self.values.borrow_mut().0.remove(&value)
+ pub fn weak_set_remove(&self, vm: &Vm, value: Gc<CellHeader>) -> bool {
+ self.values.borrow_mut(vm).0.remove(&value)
}
pub fn weak_set_size(&self) -> usize {
@@ -116,6 +116,10 @@ impl WeakSet {
.as_gc()
.downcast::<WeakSet>()
.expect("the weak container is a WeakSet");
- weak_set.values.borrow_mut().0.retain(|&cell| !sweep.is_dead(cell));
+ weak_set
+ .values
+ .borrow_mut_in_sweep(sweep)
+ .0
+ .retain(|&cell| !sweep.is_dead(cell));
}
}
diff --git a/Libraries/LibJS/Rust/src/runtime/weak_set_prototype.rs b/Libraries/LibJS/Rust/src/runtime/weak_set_prototype.rs
index c531020ecec..d6dca0c7022 100644
--- a/Libraries/LibJS/Rust/src/runtime/weak_set_prototype.rs
+++ b/Libraries/LibJS/Rust/src/runtime/weak_set_prototype.rs
@@ -116,7 +116,7 @@ impl WeakSetPrototype {
// i. Replace the element of S.[[WeakSetData]] whose value is e with an element whose value is empty.
// ii. Return true.
// 5. Return false.
- Ok(Value::from_bool(weak_set.weak_set_remove(value.as_cell())))
+ Ok(Value::from_bool(weak_set.weak_set_remove(vm, value.as_cell())))
}
// 24.4.3.4 WeakSet.prototype.has ( value ), https://tc39.es/ecma262/#sec-weakset.prototype.has
diff --git a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs
index ccbe9611a27..3317495ab7a 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, Realm, Trace, Visitor, Vm};
+use libjs_rust::api::{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};
@@ -245,23 +245,23 @@ impl ContextState {
})
}
- /// The current drawing state, to change it. Nothing may run script or collect garbage while the borrow lasts.
- pub(crate) fn drawing_state_mut(&self) -> RefMut<'_, DrawingState> {
- RefMut::map(self.states.borrow_mut(), |states| {
+ /// The current drawing state, to change it. Nothing may run script while the borrow lasts.
+ pub(crate) fn drawing_state_mut<'a>(&'a self, vm: &'a Vm) -> GcRefMut<'a, DrawingState> {
+ GcRefMut::map(self.states.borrow_mut(vm), |states| {
states.last_mut().expect("a context has a current drawing state")
})
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-save
- pub(crate) fn push_drawing_state(&self) {
- let mut states = self.states.borrow_mut();
+ pub(crate) fn push_drawing_state(&self, vm: &Vm) {
+ let mut states = self.states.borrow_mut(vm);
let current = states.last().expect("a context has a current drawing state").clone();
states.push(current);
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-restore
- pub(crate) fn pop_drawing_state(&self) -> bool {
- let mut states = self.states.borrow_mut();
+ pub(crate) fn pop_drawing_state(&self, vm: &Vm) -> bool {
+ let mut states = self.states.borrow_mut(vm);
if states.len() == 1 {
return false;
}
@@ -626,10 +626,10 @@ impl ContextState {
}
/// Sets the font of the current drawing state, unless the value is not a CSS font.
- pub(crate) fn assign_font(&self, font: &Utf16String) {
+ pub(crate) fn assign_font(&self, vm: &Vm, font: &Utf16String) {
let font_selection = FontSelection::of(&self.drawing_state());
if let Some(font) = self.canvas.resolve_font(font, font_selection) {
- self.drawing_state_mut().font = Some(font);
+ self.drawing_state_mut(vm).font = Some(font);
}
}
@@ -653,10 +653,10 @@ impl ContextState {
/// Resolves the font of the current drawing state again, after a change to the text drawing styles that select
/// its fonts.
- pub(crate) fn font_selection_did_change(&self) {
+ pub(crate) fn font_selection_did_change(&self, vm: &Vm) {
let font = self.drawing_state().font.as_ref().map(|font| font.serialized.clone());
if let Some(font) = font {
- self.assign_font(&font);
+ self.assign_font(vm, &font);
}
}
@@ -673,10 +673,10 @@ impl ContextState {
/// The font of the current drawing state, which is resolved the first time the context needs one, and again when
/// the fonts that the canvas can use change.
- pub(crate) fn current_font(&self) -> ResolvedFont {
+ pub(crate) fn current_font(&self, vm: &Vm) -> ResolvedFont {
// When font style value is empty load default font
if self.drawing_state().font.is_none() {
- self.assign_font(&Utf16String::from_ascii(b"10px sans-serif"));
+ self.assign_font(vm, &Utf16String::from_ascii(b"10px sans-serif"));
}
// NB: Drawing states, including saved states, retain their cascades across font loads and font-display
@@ -688,7 +688,7 @@ impl ContextState {
.clone()
.expect("a context has a font once it is set");
if font.environment_generation != self.canvas.font_environment_generation() {
- self.assign_font(&font.serialized);
+ self.assign_font(vm, &font.serialized);
return self
.drawing_state()
.font
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_compositing.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_compositing.rs
index 513bda2d7e3..a20ea48b16c 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_compositing.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_compositing.rs
@@ -20,14 +20,14 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-globalalpha
- pub(crate) fn set_global_alpha(&self, _: &mut CallContext, alpha: f64) -> WebIdlResult<()> {
+ pub(crate) fn set_global_alpha(&self, cx: &mut CallContext, alpha: f64) -> WebIdlResult<()> {
let alpha = float(alpha);
// 1. If the given value is either infinite, NaN, or not in the range 0.0 to 1.0, then return.
if !alpha.is_finite() || !(0.0..=1.0).contains(&alpha) {
return Ok(());
}
// 2. Otherwise, set this's global alpha to the given value.
- self.drawing_state_mut().global_alpha = alpha;
+ self.drawing_state_mut(cx.vm()).global_alpha = alpha;
Ok(())
}
@@ -40,14 +40,15 @@ impl<K: CanvasKind> RenderingContext2D<K> {
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-globalcompositeoperation
pub(crate) fn set_global_composite_operation(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
global_composite_operation: Utf16String,
) -> WebIdlResult<()> {
// 1. If the given value is not identical to any of the values that the <blend-mode> or the <composite-mode>
// properties are defined to take, then return.
// 2. Otherwise, set this's current compositing and blending operator to the given value.
if let Some(operator) = composite_operation_named(&global_composite_operation) {
- self.drawing_state_mut().current_compositing_and_blending_operator = operator;
+ self.drawing_state_mut(cx.vm())
+ .current_compositing_and_blending_operator = operator;
}
Ok(())
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_fill_stroke_styles.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_fill_stroke_styles.rs
index 28971d9b258..9b9f8d6830b 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_fill_stroke_styles.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_fill_stroke_styles.rs
@@ -43,7 +43,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-strokestyle
pub(crate) fn set_stroke_style(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
style: DOMStringOrCanvasGradientOrCanvasPattern,
) -> WebIdlResult<()> {
let style = match style {
@@ -58,7 +58,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
};
// 4. Set this's stroke style to parsedValue.
- self.drawing_state_mut().stroke_style = FillOrStrokeStyle::Color(parsed_value);
+ self.drawing_state_mut(cx.vm()).stroke_style = FillOrStrokeStyle::Color(parsed_value);
// 5. Return.
return Ok(());
@@ -75,7 +75,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
};
// 3. Set this's stroke style to the given value.
- self.drawing_state_mut().stroke_style = style;
+ self.drawing_state_mut(cx.vm()).stroke_style = style;
Ok(())
}
@@ -87,7 +87,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fillstyle
pub(crate) fn set_fill_style(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
style: DOMStringOrCanvasGradientOrCanvasPattern,
) -> WebIdlResult<()> {
let style = match style {
@@ -102,7 +102,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
};
// 4. Set this's fill style to parsedValue.
- self.drawing_state_mut().fill_style = FillOrStrokeStyle::Color(parsed_value);
+ self.drawing_state_mut(cx.vm()).fill_style = FillOrStrokeStyle::Color(parsed_value);
// 5. Return.
return Ok(());
@@ -119,7 +119,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
};
// 3. Set this's fill style to the given value.
- self.drawing_state_mut().fill_style = style;
+ self.drawing_state_mut(cx.vm()).fill_style = style;
Ok(())
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_filters.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_filters.rs
index 8a51d680527..237b37751b9 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_filters.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_filters.rs
@@ -26,12 +26,12 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-filter
- pub(crate) fn set_filter(&self, _: &mut CallContext, filter: Utf16String) -> WebIdlResult<()> {
- self.drawing_state_mut().filter = None;
+ pub(crate) fn set_filter(&self, cx: &mut CallContext, filter: Utf16String) -> WebIdlResult<()> {
+ self.drawing_state_mut(cx.vm()).filter = None;
// 1. If the given value is "none", then set this's current filter to "none" and return.
if filter == Utf16String::from_ascii(b"none") {
- self.drawing_state_mut().filter_string = None;
+ self.drawing_state_mut(cx.vm()).filter_string = None;
return Ok(());
}
@@ -47,7 +47,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
// 4. Set this's current filter to the given value.
let graph = filter_functions_graph(functions.into_iter().map(Filter::from));
- let mut state = self.drawing_state_mut();
+ let mut state = self.drawing_state_mut(cx.vm());
state.filter = graph.map(|graph| Rc::from(graph.serialize()));
state.filter_string = Some(filter);
Ok(())
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_image_smoothing.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_image_smoothing.rs
index 97fcb1c1c09..e9bdeec192a 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_image_smoothing.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_image_smoothing.rs
@@ -16,8 +16,8 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(self.drawing_state().image_smoothing_enabled)
}
- pub(crate) fn set_image_smoothing_enabled(&self, _: &mut CallContext, enabled: bool) -> WebIdlResult<()> {
- self.drawing_state_mut().image_smoothing_enabled = enabled;
+ pub(crate) fn set_image_smoothing_enabled(&self, cx: &mut CallContext, enabled: bool) -> WebIdlResult<()> {
+ self.drawing_state_mut(cx.vm()).image_smoothing_enabled = enabled;
Ok(())
}
@@ -28,10 +28,10 @@ impl<K: CanvasKind> RenderingContext2D<K> {
pub(crate) fn set_image_smoothing_quality(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
quality: ImageSmoothingQuality,
) -> WebIdlResult<()> {
- self.drawing_state_mut().image_smoothing_quality = quality;
+ self.drawing_state_mut(cx.vm()).image_smoothing_quality = quality;
Ok(())
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path_drawing_styles.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path_drawing_styles.rs
index 49e58e2ce80..1e6cb594fd0 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path_drawing_styles.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path_drawing_styles.rs
@@ -18,14 +18,14 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(f64::from(self.drawing_state().line_width))
}
- pub(crate) fn set_line_width(&self, _: &mut CallContext, line_width: f64) -> WebIdlResult<()> {
+ pub(crate) fn set_line_width(&self, cx: &mut CallContext, line_width: f64) -> WebIdlResult<()> {
// On setting, zero, negative, infinite, and NaN values must be ignored, leaving the value unchanged;
let line_width = float(line_width);
if line_width <= 0.0 || !line_width.is_finite() {
return Ok(());
}
// other values must change the current value to the new value.
- self.drawing_state_mut().line_width = line_width;
+ self.drawing_state_mut(cx.vm()).line_width = line_width;
Ok(())
}
@@ -34,8 +34,8 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(self.drawing_state().line_cap)
}
- pub(crate) fn set_line_cap(&self, _: &mut CallContext, line_cap: CanvasLineCap) -> WebIdlResult<()> {
- self.drawing_state_mut().line_cap = line_cap;
+ pub(crate) fn set_line_cap(&self, cx: &mut CallContext, line_cap: CanvasLineCap) -> WebIdlResult<()> {
+ self.drawing_state_mut(cx.vm()).line_cap = line_cap;
Ok(())
}
@@ -44,8 +44,8 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(self.drawing_state().line_join)
}
- pub(crate) fn set_line_join(&self, _: &mut CallContext, line_join: CanvasLineJoin) -> WebIdlResult<()> {
- self.drawing_state_mut().line_join = line_join;
+ pub(crate) fn set_line_join(&self, cx: &mut CallContext, line_join: CanvasLineJoin) -> WebIdlResult<()> {
+ self.drawing_state_mut(cx.vm()).line_join = line_join;
Ok(())
}
@@ -54,19 +54,19 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(f64::from(self.drawing_state().miter_limit))
}
- pub(crate) fn set_miter_limit(&self, _: &mut CallContext, miter_limit: f64) -> WebIdlResult<()> {
+ pub(crate) fn set_miter_limit(&self, cx: &mut CallContext, miter_limit: f64) -> WebIdlResult<()> {
// On setting, zero, negative, infinite, and NaN values must be ignored, leaving the value unchanged;
let miter_limit = float(miter_limit);
if miter_limit <= 0.0 || !miter_limit.is_finite() {
return Ok(());
}
// other values must change the current value to the new value.
- self.drawing_state_mut().miter_limit = miter_limit;
+ self.drawing_state_mut(cx.vm()).miter_limit = miter_limit;
Ok(())
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-setlinedash
- pub(crate) fn set_line_dash(&self, _: &mut CallContext, mut segments: Vec<f64>) -> WebIdlResult<()> {
+ pub(crate) fn set_line_dash(&self, cx: &mut CallContext, mut segments: Vec<f64>) -> WebIdlResult<()> {
// 1. If any value in segments is not finite (e.g. an Infinity or a NaN value), or if any value is negative
// (less than zero), then return (without throwing an exception; user agents could show a message on a
// developer console, though, as that would be helpful for debugging).
@@ -81,7 +81,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
// 3. Set the object's dash list to segments.
- self.drawing_state_mut().dash_list = segments;
+ self.drawing_state_mut(cx.vm()).dash_list = segments;
Ok(())
}
@@ -97,14 +97,14 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(f64::from(self.drawing_state().line_dash_offset))
}
- pub(crate) fn set_line_dash_offset(&self, _: &mut CallContext, line_dash_offset: f64) -> WebIdlResult<()> {
+ pub(crate) fn set_line_dash_offset(&self, cx: &mut CallContext, line_dash_offset: f64) -> WebIdlResult<()> {
// On setting, infinite and NaN values must be ignored, leaving the value unchanged;
let line_dash_offset = float(line_dash_offset);
if !line_dash_offset.is_finite() {
return Ok(());
}
// other values must change the current value to the new value.
- self.drawing_state_mut().line_dash_offset = line_dash_offset;
+ self.drawing_state_mut(cx.vm()).line_dash_offset = line_dash_offset;
Ok(())
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_shadow_styles.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_shadow_styles.rs
index 6d2ac3bfe76..033b12567e8 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_shadow_styles.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_shadow_styles.rs
@@ -19,10 +19,10 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(f64::from(self.drawing_state().shadow_offset_x))
}
- pub(crate) fn set_shadow_offset_x(&self, _: &mut CallContext, offset_x: f64) -> WebIdlResult<()> {
+ pub(crate) fn set_shadow_offset_x(&self, cx: &mut CallContext, offset_x: f64) -> WebIdlResult<()> {
let offset_x = float(offset_x);
if offset_x.is_finite() {
- self.drawing_state_mut().shadow_offset_x = offset_x;
+ self.drawing_state_mut(cx.vm()).shadow_offset_x = offset_x;
}
Ok(())
}
@@ -32,10 +32,10 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(f64::from(self.drawing_state().shadow_offset_y))
}
- pub(crate) fn set_shadow_offset_y(&self, _: &mut CallContext, offset_y: f64) -> WebIdlResult<()> {
+ pub(crate) fn set_shadow_offset_y(&self, cx: &mut CallContext, offset_y: f64) -> WebIdlResult<()> {
let offset_y = float(offset_y);
if offset_y.is_finite() {
- self.drawing_state_mut().shadow_offset_y = offset_y;
+ self.drawing_state_mut(cx.vm()).shadow_offset_y = offset_y;
}
Ok(())
}
@@ -45,14 +45,14 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(f64::from(self.drawing_state().shadow_blur))
}
- pub(crate) fn set_shadow_blur(&self, _: &mut CallContext, blur_radius: f64) -> WebIdlResult<()> {
+ pub(crate) fn set_shadow_blur(&self, cx: &mut CallContext, blur_radius: f64) -> WebIdlResult<()> {
// On setting, the attribute must be set to the new value, except if the value is negative, infinite or NaN,
// in which case the new value must be ignored.
let blur_radius = float(blur_radius);
if blur_radius < 0.0 || !blur_radius.is_finite() {
return Ok(());
}
- self.drawing_state_mut().shadow_blur = blur_radius;
+ self.drawing_state_mut(cx.vm()).shadow_blur = blur_radius;
Ok(())
}
@@ -61,7 +61,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(serialize_color(self.drawing_state().shadow_color.srgb))
}
- pub(crate) fn set_shadow_color(&self, _: &mut CallContext, color: Utf16String) -> WebIdlResult<()> {
+ pub(crate) fn set_shadow_color(&self, cx: &mut CallContext, color: Utf16String) -> WebIdlResult<()> {
// 1. Let context be this's canvas attribute's value, if that is an element; otherwise null.
// 2. Let parsedValue be the result of parsing the given value with context if non-null.
@@ -71,7 +71,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
};
// 4. Set this's shadow color to parsedValue.
- self.drawing_state_mut().shadow_color = parsed_value;
+ self.drawing_state_mut(cx.vm()).shadow_color = parsed_value;
Ok(())
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_state.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_state.rs
index 3eebc323cc5..cef2998df98 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_state.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_state.rs
@@ -11,19 +11,19 @@ use crate::canvas_2d::context::{CanvasKind, CanvasRecorder, RenderingContext2D};
impl<K: CanvasKind> RenderingContext2D<K> {
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-save
- pub(crate) fn save(&self, _: &mut CallContext) -> WebIdlResult<()> {
+ pub(crate) fn save(&self, cx: &mut CallContext) -> WebIdlResult<()> {
// The save() method steps are to push a copy of the current drawing state onto the drawing state stack.
- self.push_drawing_state();
+ self.push_drawing_state(cx.vm());
self.record_if_ready(CanvasRecorder::save);
Ok(())
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-restore
- pub(crate) fn restore(&self, _: &mut CallContext) -> WebIdlResult<()> {
+ pub(crate) fn restore(&self, cx: &mut CallContext) -> WebIdlResult<()> {
// The restore() method steps are to pop the top entry in the drawing state stack, and reset the drawing state
// it describes. If there is no saved state, then the method must do nothing.
- if !self.pop_drawing_state() {
+ if !self.pop_drawing_state(cx.vm()) {
return Ok(());
}
// NB: The current default path is not part of the drawing state.
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text.rs
index d9e0d4ac78a..848ba698136 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text.rs
@@ -7,6 +7,7 @@
//! https://html.spec.whatwg.org/multipage/canvas.html#canvastext
use core::ptr::NonNull;
+use libjs_rust::api::Vm;
use ak::Utf16String;
use libcompositing_rust::display_list::commands::DisplayListGlyph;
@@ -27,12 +28,12 @@ use crate::html::canvas_rendering_context2d::CanvasTextBaseline;
impl ContextState {
/// The outlines of the glyphs of the text, drawn at the point.
- fn text_path(&self, text: &[u16], x: f32, y: f32, max_width: Option<f64>) -> Path {
+ fn text_path(&self, vm: &Vm, text: &[u16], x: f32, y: f32, max_width: Option<f64>) -> Path {
if max_width.is_some_and(|max_width| max_width <= 0.0) {
return Path::new();
}
- let font = self.current_font();
+ let font = self.current_font(vm);
let letter_spacing = self.resolved_letter_spacing();
let word_spacing = self.resolved_word_spacing();
let runs = shape_text(&font.cascade, text, FloatPoint { x, y }, letter_spacing, word_spacing);
@@ -60,7 +61,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-filltext
pub(crate) fn fill_text(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
text: Utf16String,
x: f64,
y: f64,
@@ -81,11 +82,11 @@ impl<K: CanvasKind> RenderingContext2D<K> {
state.shadow_blur != 0.0 || state.shadow_offset_x != 0.0 || state.shadow_offset_y != 0.0
};
if max_width.is_some() || has_shadow {
- self.fill_internal(&self.text_path(&text, x, y, max_width), WindingRule::Nonzero);
+ self.fill_internal(&self.text_path(cx.vm(), &text, x, y, max_width), WindingRule::Nonzero);
return Ok(());
}
- let font = self.current_font();
+ let font = self.current_font(cx.vm());
let letter_spacing = self.resolved_letter_spacing();
let word_spacing = self.resolved_word_spacing();
let runs = shape_text(
@@ -96,11 +97,11 @@ impl<K: CanvasKind> RenderingContext2D<K> {
word_spacing,
);
let [run] = runs.as_slice() else {
- self.fill_internal(&self.text_path(&text, x, y, max_width), WindingRule::Nonzero);
+ self.fill_internal(&self.text_path(cx.vm(), &text, x, y, max_width), WindingRule::Nonzero);
return Ok(());
};
if run.font.is_invisible() {
- self.fill_internal(&self.text_path(&text, x, y, max_width), WindingRule::Nonzero);
+ self.fill_internal(&self.text_path(cx.vm(), &text, x, y, max_width), WindingRule::Nonzero);
return Ok(());
}
@@ -147,7 +148,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-stroketext
pub(crate) fn stroke_text(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
text: Utf16String,
x: f64,
y: f64,
@@ -160,7 +161,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
// https://html.spec.whatwg.org/multipage/canvas.html#text-preparation-algorithm
// 2. Replace all ASCII whitespace in text with U+0020 SPACE characters.
let text = replace_ascii_whitespace(&text.to_utf16());
- self.stroke_internal(&self.text_path(&text, x, y, max_width));
+ self.stroke_internal(&self.text_path(cx.vm(), &text, x, y, max_width));
Ok(())
}
@@ -176,7 +177,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
let replaced_text = replace_ascii_whitespace(&text.to_utf16());
// 3. Let font be the current font of target, as given by that object's font attribute.
- let font = self.current_font();
+ let font = self.current_font(cx.vm());
let letter_spacing = self.resolved_letter_spacing();
let word_spacing = self.resolved_word_spacing();
let runs = shape_text(
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text_drawing_styles.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text_drawing_styles.rs
index c5c1789324f..95529c51cb5 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text_drawing_styles.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text_drawing_styles.rs
@@ -74,7 +74,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-font
- pub(crate) fn set_font(&self, _: &mut CallContext, font: Utf16String) -> WebIdlResult<()> {
+ pub(crate) fn set_font(&self, cx: &mut CallContext, font: Utf16String) -> WebIdlResult<()> {
// The font IDL attribute, on setting, must be parsed as a CSS <'font'> value (but without supporting
// property-independent style sheet syntax like 'inherit'), and the resulting font must be assigned to the
// context, with the 'line-height' component forced to 'normal', with the 'font-size' component converted to
@@ -82,7 +82,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
// If the new value is syntactically incorrect (including using property-independent style sheet syntax like
// 'inherit' or 'initial'), then it must be ignored, without assigning a new font value.
// NB: LibWeb's C++ parses the value and resolves it against the canvas.
- self.assign_font(&font);
+ self.assign_font(cx.vm(), &font);
Ok(())
}
@@ -91,8 +91,8 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(self.drawing_state().text_align)
}
- pub(crate) fn set_text_align(&self, _: &mut CallContext, text_align: CanvasTextAlign) -> WebIdlResult<()> {
- self.drawing_state_mut().text_align = text_align;
+ pub(crate) fn set_text_align(&self, cx: &mut CallContext, text_align: CanvasTextAlign) -> WebIdlResult<()> {
+ self.drawing_state_mut(cx.vm()).text_align = text_align;
Ok(())
}
@@ -101,8 +101,12 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(self.drawing_state().text_baseline)
}
- pub(crate) fn set_text_baseline(&self, _: &mut CallContext, text_baseline: CanvasTextBaseline) -> WebIdlResult<()> {
- self.drawing_state_mut().text_baseline = text_baseline;
+ pub(crate) fn set_text_baseline(
+ &self,
+ cx: &mut CallContext,
+ text_baseline: CanvasTextBaseline,
+ ) -> WebIdlResult<()> {
+ self.drawing_state_mut(cx.vm()).text_baseline = text_baseline;
Ok(())
}
@@ -111,8 +115,8 @@ impl<K: CanvasKind> RenderingContext2D<K> {
Ok(self.drawing_state().direction)
}
- pub(crate) fn set_direction(&self, _: &mut CallContext, direction: CanvasDirection) -> WebIdlResult<()> {
- self.drawing_state_mut().direction = direction;
+ pub(crate) fn set_direction(&self, cx: &mut CallContext, direction: CanvasDirection) -> WebIdlResult<()> {
+ self.drawing_state_mut(cx.vm()).direction = direction;
Ok(())
}
@@ -126,7 +130,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-letterspacing
- pub(crate) fn set_letter_spacing(&self, _: &mut CallContext, letter_spacing: Utf16String) -> WebIdlResult<()> {
+ pub(crate) fn set_letter_spacing(&self, cx: &mut CallContext, letter_spacing: Utf16String) -> WebIdlResult<()> {
// 1. Let parsed be the result of parsing the given value as a CSS <length>.
// 2. If parsed is failure, then return.
let Some((length, serialized)) = parse_length(&letter_spacing) else {
@@ -134,7 +138,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
};
// 3. Set this's letter spacing to parsed.
- self.drawing_state_mut().letter_spacing = Some(Spacing { length, serialized });
+ self.drawing_state_mut(cx.vm()).letter_spacing = Some(Spacing { length, serialized });
Ok(())
}
@@ -145,9 +149,9 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-lang
- pub(crate) fn set_lang(&self, _: &mut CallContext, lang: Utf16String) -> WebIdlResult<()> {
+ pub(crate) fn set_lang(&self, cx: &mut CallContext, lang: Utf16String) -> WebIdlResult<()> {
// The lang setter steps are to set this's language to the given value.
- self.drawing_state_mut().language = lang;
+ self.drawing_state_mut(cx.vm()).language = lang;
Ok(())
}
@@ -161,7 +165,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-wordspacing
- pub(crate) fn set_word_spacing(&self, _: &mut CallContext, word_spacing: Utf16String) -> WebIdlResult<()> {
+ pub(crate) fn set_word_spacing(&self, cx: &mut CallContext, word_spacing: Utf16String) -> WebIdlResult<()> {
// 1. Let parsed be the result of parsing the given value as a CSS <length>.
// 2. If parsed is failure, then return.
let Some((length, serialized)) = parse_length(&word_spacing) else {
@@ -169,7 +173,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
};
// 3. Set this's word spacing to parsed.
- self.drawing_state_mut().word_spacing = Some(Spacing { length, serialized });
+ self.drawing_state_mut(cx.vm()).word_spacing = Some(Spacing { length, serialized });
Ok(())
}
@@ -180,11 +184,11 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontkerning
- pub(crate) fn set_font_kerning(&self, _: &mut CallContext, font_kerning: CanvasFontKerning) -> WebIdlResult<()> {
+ pub(crate) fn set_font_kerning(&self, cx: &mut CallContext, font_kerning: CanvasFontKerning) -> WebIdlResult<()> {
// On setting, the current value must be changed to the new value.
if self.drawing_state().font_kerning != font_kerning {
- self.drawing_state_mut().font_kerning = font_kerning;
- self.font_selection_did_change();
+ self.drawing_state_mut(cx.vm()).font_kerning = font_kerning;
+ self.font_selection_did_change(cx.vm());
}
Ok(())
}
@@ -196,11 +200,11 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontstretch
- pub(crate) fn set_font_stretch(&self, _: &mut CallContext, font_stretch: CanvasFontStretch) -> WebIdlResult<()> {
+ pub(crate) fn set_font_stretch(&self, cx: &mut CallContext, font_stretch: CanvasFontStretch) -> WebIdlResult<()> {
// On setting, the current value must be changed to the new value.
if self.drawing_state().font_stretch != font_stretch {
- self.drawing_state_mut().font_stretch = font_stretch;
- self.font_selection_did_change();
+ self.drawing_state_mut(cx.vm()).font_stretch = font_stretch;
+ self.font_selection_did_change(cx.vm());
}
Ok(())
}
@@ -214,13 +218,13 @@ impl<K: CanvasKind> RenderingContext2D<K> {
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontvariantcaps
pub(crate) fn set_font_variant_caps(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
font_variant_caps: CanvasFontVariantCaps,
) -> WebIdlResult<()> {
// On setting, the current value must be changed to the new value.
if self.drawing_state().font_variant_caps != font_variant_caps {
- self.drawing_state_mut().font_variant_caps = font_variant_caps;
- self.font_selection_did_change();
+ self.drawing_state_mut(cx.vm()).font_variant_caps = font_variant_caps;
+ self.font_selection_did_change(cx.vm());
}
Ok(())
}
@@ -234,13 +238,13 @@ impl<K: CanvasKind> RenderingContext2D<K> {
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-textrendering
pub(crate) fn set_text_rendering(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
text_rendering: CanvasTextRendering,
) -> WebIdlResult<()> {
// On setting, the current value must be changed to the new value.
if self.drawing_state().text_rendering != text_rendering {
- self.drawing_state_mut().text_rendering = text_rendering;
- self.font_selection_did_change();
+ self.drawing_state_mut(cx.vm()).text_rendering = text_rendering;
+ self.font_selection_did_change(cx.vm());
}
Ok(())
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_transform.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_transform.rs
index ac0011ff203..a1006d9179f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_transform.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_transform.rs
@@ -10,6 +10,7 @@
//! changes the matrix transforms the path by the inverse of the change.
use libgfx_rust::AffineTransform;
+use libjs_rust::api::Vm;
use crate::bindings::interface::{Ref, allocate};
use crate::bindings::{CallContext, WebIdlResult};
@@ -25,13 +26,13 @@ fn all_finite(values: &[f64]) -> bool {
impl<K: CanvasKind> RenderingContext2D<K> {
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-scale
- pub(crate) fn scale(&self, _: &mut CallContext, x: f64, y: f64) -> WebIdlResult<()> {
+ pub(crate) fn scale(&self, cx: &mut CallContext, x: f64, y: f64) -> WebIdlResult<()> {
let (x, y) = (float(x), float(y));
if !x.is_finite() || !y.is_finite() {
return Ok(());
}
{
- let mut state = self.drawing_state_mut();
+ let mut state = self.drawing_state_mut(cx.vm());
state.transform = scaled(state.transform, x, y);
}
self.flush_transform();
@@ -47,13 +48,13 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-translate
- pub(crate) fn translate(&self, _: &mut CallContext, x: f64, y: f64) -> WebIdlResult<()> {
+ pub(crate) fn translate(&self, cx: &mut CallContext, x: f64, y: f64) -> WebIdlResult<()> {
let (x, y) = (float(x), float(y));
if !x.is_finite() || !y.is_finite() {
return Ok(());
}
{
- let mut state = self.drawing_state_mut();
+ let mut state = self.drawing_state_mut(cx.vm());
state.transform = translated(state.transform, x, y);
}
self.flush_transform();
@@ -62,13 +63,13 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-rotate
- pub(crate) fn rotate(&self, _: &mut CallContext, radians: f64) -> WebIdlResult<()> {
+ pub(crate) fn rotate(&self, cx: &mut CallContext, radians: f64) -> WebIdlResult<()> {
let radians = float(radians);
if !radians.is_finite() {
return Ok(());
}
{
- let mut state = self.drawing_state_mut();
+ let mut state = self.drawing_state_mut(cx.vm());
state.transform = rotated(state.transform, radians);
}
self.flush_transform();
@@ -80,7 +81,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
#[allow(clippy::too_many_arguments, reason = "the arguments of transform()")]
pub(crate) fn transform(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
a: f64,
b: f64,
c: f64,
@@ -88,11 +89,12 @@ impl<K: CanvasKind> RenderingContext2D<K> {
e: f64,
f: f64,
) -> WebIdlResult<()> {
- self.multiply_transform(a, b, c, d, e, f);
+ self.multiply_transform(cx.vm(), a, b, c, d, e, f);
Ok(())
}
- fn multiply_transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
+ #[allow(clippy::too_many_arguments, reason = "the arguments of transform()")]
+ fn multiply_transform(&self, vm: &Vm, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
// 1. If any of the arguments are infinite or NaN, then return.
if !all_finite(&[a, b, c, d, e, f]) {
return;
@@ -105,7 +107,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
// 0 0 1
let transform = AffineTransform::new(float(a), float(b), float(c), float(d), float(e), float(f));
{
- let mut state = self.drawing_state_mut();
+ let mut state = self.drawing_state_mut(vm);
state.transform = multiply_transforms(state.transform, transform);
}
@@ -149,7 +151,7 @@ impl<K: CanvasKind> RenderingContext2D<K> {
#[allow(clippy::too_many_arguments, reason = "the arguments of setTransform()")]
pub(crate) fn set_transform(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
a: f64,
b: f64,
c: f64,
@@ -166,19 +168,15 @@ impl<K: CanvasKind> RenderingContext2D<K> {
// a c e
// b d f
// 0 0 1
- self.set_current_transform(AffineTransform::new(
- float(a),
- float(b),
- float(c),
- float(d),
- float(e),
- float(f),
- ));
+ self.set_current_transform(
+ cx.vm(),
+ AffineTransform::new(float(a), float(b), float(c), float(d), float(e), float(f)),
+ );
Ok(())
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-settransform-matrix
- pub(crate) fn set_transform_to_matrix(&self, _: &mut CallContext, transform: DOMMatrix2DInit) -> WebIdlResult<()> {
+ pub(crate) fn set_transform_to_matrix(&self, cx: &mut CallContext, transform: DOMMatrix2DInit) -> WebIdlResult<()> {
// 1. Let matrix be the result of creating a DOMMatrix from the 2D dictionary transform.
let matrix = validate_and_fixup_2d(&transform)?;
@@ -189,22 +187,22 @@ impl<K: CanvasKind> RenderingContext2D<K> {
}
// 3. Reset the current transformation matrix to matrix.
- self.set_current_transform(matrix.to_affine_transform());
+ self.set_current_transform(cx.vm(), matrix.to_affine_transform());
Ok(())
}
/// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-resettransform
- pub(crate) fn reset_transform(&self, _: &mut CallContext) -> WebIdlResult<()> {
+ pub(crate) fn reset_transform(&self, cx: &mut CallContext) -> WebIdlResult<()> {
// The resetTransform() method, when invoked, must reset the current transformation matrix to the identity
// matrix.
- self.set_current_transform(AffineTransform::identity());
+ self.set_current_transform(cx.vm(), AffineTransform::identity());
Ok(())
}
/// Replaces the current transformation matrix, which leaves the current default path where it is on the output
/// bitmap.
- fn set_current_transform(&self, transform: AffineTransform) {
- self.drawing_state_mut().transform = transform;
+ fn set_current_transform(&self, vm: &Vm, transform: AffineTransform) {
+ self.drawing_state_mut(vm).transform = transform;
self.keep_path_in_place();
self.flush_transform();
}
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 b1468c005ac..4d15b78d72a 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/cross_realm_transform.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/cross_realm_transform.rs
@@ -508,7 +508,7 @@ pub(crate) fn set_up_cross_realm_transform_writable(
port: CrossRealmTransformPort,
) {
// 1. Perform ! InitializeWritableStream(stream).
- initialize_writable_stream(stream);
+ initialize_writable_stream(cx.vm(), stream);
// 2. Let controller be a new WritableStreamDefaultController.
let controller = allocate(cx.vm(), WritableStreamDefaultController::new());
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 ec95c9cf80f..4d46581efd9 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};
+use libjs_rust::api::{GcRefCell, Trace, Value, Vm};
use crate::bindings::{Exception, WebIdlResult};
use crate::streams::abstract_operations::is_non_negative_number;
@@ -53,14 +53,14 @@ impl QueueWithSizes {
}
// https://streams.spec.whatwg.org/#dequeue-value
- pub(crate) fn dequeue_value(&self) -> Value {
+ pub(crate) fn dequeue_value(&self, vm: &Vm) -> Value {
// 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots.
// 2. Assert: container.[[queue]] is not empty.
// 3. Let valueWithSize be container.[[queue]][0].
// 4. Remove valueWithSize from container.[[queue]].
let value_with_size = self
.queue
- .borrow_mut()
+ .borrow_mut(vm)
.pop_front()
.expect("a container dequeues from a queue that is not empty");
@@ -79,7 +79,7 @@ impl QueueWithSizes {
}
// https://streams.spec.whatwg.org/#enqueue-value-with-size
- pub(crate) fn enqueue_value_with_size(&self, value: Value, size: Value) -> WebIdlResult<()> {
+ pub(crate) fn enqueue_value_with_size(&self, vm: &Vm, value: Value, size: Value) -> WebIdlResult<()> {
// 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots.
// 2. If ! IsNonNegativeNumber(size) is false, throw a RangeError exception.
if !is_non_negative_number(size) {
@@ -93,7 +93,7 @@ impl QueueWithSizes {
}
// 4. Append a new value-with-size with value value and size size to container.[[queue]].
- self.queue.borrow_mut().push_back(ValueWithSize { value, size });
+ self.queue.borrow_mut(vm).push_back(ValueWithSize { value, size });
// 5. Set container.[[queueTotalSize]] to container.[[queueTotalSize]] + size.
self.queue_total_size.set(self.queue_total_size.get() + size);
@@ -114,10 +114,10 @@ impl QueueWithSizes {
}
// https://streams.spec.whatwg.org/#reset-queue
- pub(crate) fn reset_queue(&self) {
+ pub(crate) fn reset_queue(&self, vm: &Vm) {
// 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots.
// 2. Set container.[[queue]] to a new empty list.
- self.queue.borrow_mut().clear();
+ self.queue.borrow_mut(vm).clear();
// 3. Set container.[[queueTotalSize]] to 0.
self.queue_total_size.set(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 abe58e55ed1..370247c8c5e 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
@@ -172,11 +172,11 @@ impl ReadableByteStreamController {
}
// https://streams.spec.whatwg.org/#reset-queue
- fn reset_queue(&self) {
+ fn reset_queue(&self, vm: &Vm) {
// 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots.
// 2. Set container.[[queue]] to a new empty list.
- self.queue.borrow_mut().clear();
+ self.queue.borrow_mut(vm).clear();
// 3. Set container.[[queueTotalSize]] to 0.
self.queue_total_size.set(0.0);
@@ -253,10 +253,10 @@ impl ReadableByteStreamController {
// https://streams.spec.whatwg.org/#rbs-controller-private-cancel
pub(crate) fn cancel_steps(this: Ref<Self>, cx: &CallContext, reason: Value) -> WebIdlPromise {
// 1. Perform ! ReadableByteStreamControllerClearPendingPullIntos(this).
- readable_byte_stream_controller_clear_pending_pull_intos(this);
+ readable_byte_stream_controller_clear_pending_pull_intos(cx.vm(), this);
// 2. Perform ! ResetQueue(this).
- this.reset_queue();
+ this.reset_queue(cx.vm());
// 3. Let result be the result of performing this.[[cancelAlgorithm]], passing in reason.
let cancel_algorithm = this
@@ -342,18 +342,18 @@ impl ReadableByteStreamController {
);
// 4. Append pullIntoDescriptor to this.[[pendingPullIntos]].
- this.pending_pull_intos.borrow_mut().push_back(pull_into_descriptor);
+ this.pending_pull_intos.borrow_mut(vm).push_back(pull_into_descriptor);
}
// 6. Perform ! ReadableStreamAddReadRequest(stream, readRequest).
- readable_stream_add_read_request(stream, read_request);
+ readable_stream_add_read_request(vm, stream, read_request);
// 7. Perform ! ReadableByteStreamControllerCallPullIfNeeded(this).
readable_byte_stream_controller_call_pull_if_needed(cx, this);
}
// https://streams.spec.whatwg.org/#abstract-opdef-readablebytestreamcontroller-releasesteps
- pub(crate) fn release_steps(this: Ref<Self>) {
+ pub(crate) fn release_steps(vm: &Vm, this: Ref<Self>) {
// 1. If this.[[pendingPullIntos]] is not empty,
if let Some(first_pending_pull_into) = this.first_pending_pull_into() {
// 1. Let firstPendingPullInto be this.[[pendingPullIntos]][0].
@@ -362,7 +362,7 @@ impl ReadableByteStreamController {
first_pending_pull_into.reader_type.set(ReaderType::None);
// 3. Set this.[[pendingPullIntos]] to the list « firstPendingPullInto ».
- let mut pending_pull_intos = this.pending_pull_intos.borrow_mut();
+ let mut pending_pull_intos = this.pending_pull_intos.borrow_mut(vm);
pending_pull_intos.clear();
pending_pull_intos.push_back(first_pending_pull_into);
}
@@ -438,19 +438,22 @@ pub(crate) fn readable_byte_stream_controller_call_pull_if_needed(
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-clear-algorithms
pub(crate) fn readable_byte_stream_controller_clear_algorithms(controller: Ref<ReadableByteStreamController>) {
// 1. Set controller.[[pullAlgorithm]] to undefined.
- *controller.pull_algorithm.borrow_mut() = None;
+ controller.pull_algorithm.replace(None);
// 2. Set controller.[[cancelAlgorithm]] to undefined.
- *controller.cancel_algorithm.borrow_mut() = None;
+ controller.cancel_algorithm.replace(None);
}
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-clear-pending-pull-intos
-pub(crate) fn readable_byte_stream_controller_clear_pending_pull_intos(controller: Ref<ReadableByteStreamController>) {
+pub(crate) fn readable_byte_stream_controller_clear_pending_pull_intos(
+ vm: &Vm,
+ controller: Ref<ReadableByteStreamController>,
+) {
// 1. Perform ! ReadableByteStreamControllerInvalidateBYOBRequest(controller).
readable_byte_stream_controller_invalidate_byob_request(controller);
// 2. Set controller.[[pendingPullIntos]] to a new empty list.
- controller.pending_pull_intos.borrow_mut().clear();
+ controller.pending_pull_intos.borrow_mut(vm).clear();
}
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-close
@@ -644,6 +647,7 @@ fn readable_byte_stream_controller_enqueue_transferred_buffer(
// 2. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset,
// byteLength).
readable_byte_stream_controller_enqueue_chunk_to_queue(
+ vm,
controller,
transferred_buffer,
byte_offset,
@@ -661,7 +665,7 @@ fn readable_byte_stream_controller_enqueue_transferred_buffer(
assert!(first_pending_pull_into.reader_type.get() == ReaderType::Default);
// 2. Perform ! ReadableByteStreamControllerShiftPendingPullInto(controller).
- readable_byte_stream_controller_shift_pending_pull_into(controller);
+ readable_byte_stream_controller_shift_pending_pull_into(vm, controller);
}
// 3. Let transferredView be ! Construct(%Uint8Array%, « transferredBuffer, byteOffset, byteLength »).
@@ -686,6 +690,7 @@ fn readable_byte_stream_controller_enqueue_transferred_buffer(
// 1. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset,
// byteLength).
readable_byte_stream_controller_enqueue_chunk_to_queue(
+ vm,
controller,
transferred_buffer,
byte_offset,
@@ -712,6 +717,7 @@ fn readable_byte_stream_controller_enqueue_transferred_buffer(
// 2. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset,
// byteLength).
readable_byte_stream_controller_enqueue_chunk_to_queue(
+ vm,
controller,
transferred_buffer,
byte_offset,
@@ -795,6 +801,7 @@ pub(crate) fn readable_byte_stream_controller_enqueue_native_bytes(
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-enqueue-chunk-to-queue
pub(crate) fn readable_byte_stream_controller_enqueue_chunk_to_queue(
+ vm: &Vm,
controller: Ref<ReadableByteStreamController>,
buffer: Gc<ArrayBuffer>,
byte_offset: u64,
@@ -802,7 +809,7 @@ pub(crate) fn readable_byte_stream_controller_enqueue_chunk_to_queue(
) {
// 1. Append a new readable byte stream queue entry with buffer buffer, byte offset byteOffset, and byte length
// byteLength to controller.[[queue]].
- controller.queue.borrow_mut().push_back(ReadableByteStreamQueueEntry {
+ controller.queue.borrow_mut(vm).push_back(ReadableByteStreamQueueEntry {
buffer,
byte_offset,
byte_length,
@@ -838,7 +845,7 @@ pub(crate) fn readable_byte_stream_controller_enqueue_cloned_chunk_to_queue(
};
// 3. Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(controller, cloneResult.[[Value]], 0, byteLength).
- readable_byte_stream_controller_enqueue_chunk_to_queue(controller, clone_result, 0, byte_length);
+ readable_byte_stream_controller_enqueue_chunk_to_queue(cx.vm(), controller, clone_result, 0, byte_length);
Ok(())
}
@@ -865,7 +872,7 @@ pub(crate) fn readable_byte_stream_controller_enqueue_detached_pull_into_to_queu
}
// 3. Perform ! ReadableByteStreamControllerShiftPendingPullInto(controller).
- readable_byte_stream_controller_shift_pending_pull_into(controller);
+ readable_byte_stream_controller_shift_pending_pull_into(cx.vm(), controller);
Ok(())
}
@@ -884,10 +891,10 @@ pub(crate) fn readable_byte_stream_controller_error(
}
// 3. Perform ! ReadableByteStreamControllerClearPendingPullIntos(controller).
- readable_byte_stream_controller_clear_pending_pull_intos(controller);
+ readable_byte_stream_controller_clear_pending_pull_intos(cx.vm(), controller);
// 4. Perform ! ResetQueue(controller).
- controller.reset_queue();
+ controller.reset_queue(cx.vm());
// 5. Perform ! ReadableByteStreamControllerClearAlgorithms(controller).
readable_byte_stream_controller_clear_algorithms(controller);
@@ -921,6 +928,7 @@ pub(crate) fn readable_byte_stream_controller_fill_head_pull_into_descriptor(
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-fill-pull-into-descriptor-from-queue
pub(crate) fn readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(
+ vm: &Vm,
controller: Ref<ReadableByteStreamController>,
pull_into_descriptor: PullIntoDescriptorRef,
) -> bool {
@@ -1009,7 +1017,7 @@ pub(crate) fn readable_byte_stream_controller_fill_pull_into_descriptor_from_que
);
{
- let mut queue = queue.borrow_mut();
+ let mut queue = queue.borrow_mut(vm);
// 9. If headOfQueue’s byte length is bytesToCopy,
if head_of_queue.byte_length == bytes_to_copy {
@@ -1072,7 +1080,7 @@ pub(crate) fn readable_byte_stream_controller_fill_read_request_from_queue(
// 3. Remove entry from controller.[[queue]].
let entry = controller
.queue
- .borrow_mut()
+ .borrow_mut(vm)
.pop_front()
.expect("a controller with bytes in its queue has a queue entry");
@@ -1232,9 +1240,9 @@ pub(crate) fn readable_byte_stream_controller_process_pull_into_descriptors_usin
// 2. Let pullIntoDescriptor be controller.[[pendingPullIntos]][0].
// 3. If ! ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) is true,
- if readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(controller, pull_into_descriptor) {
+ if readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(vm, controller, pull_into_descriptor) {
// 1. Perform ! ReadableByteStreamControllerShiftPendingPullInto(controller).
- readable_byte_stream_controller_shift_pending_pull_into(controller);
+ readable_byte_stream_controller_shift_pending_pull_into(vm, controller);
// 2. Append pullIntoDescriptor to filledPullIntos.
filled_pull_intos.push(pull_into_descriptor);
@@ -1265,7 +1273,7 @@ pub(crate) fn readable_byte_stream_controller_process_read_requests_using_queue(
// 2. Let readRequest be reader.[[readRequests]][0].
// 3. Remove readRequest from reader.[[readRequests]].
- let read_request = reader.take_first_read_request();
+ let read_request = reader.take_first_read_request(cx.vm());
// 4. Perform ! ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest).
readable_byte_stream_controller_fill_read_request_from_queue(cx, controller, read_request);
@@ -1365,11 +1373,11 @@ pub(crate) fn readable_byte_stream_controller_pull_into(
// 1. Append pullIntoDescriptor to controller.[[pendingPullIntos]].
controller
.pending_pull_intos
- .borrow_mut()
+ .borrow_mut(vm)
.push_back(pull_into_descriptor);
// 2. Perform ! ReadableStreamAddReadIntoRequest(stream, readIntoRequest).
- readable_stream_add_read_into_request(stream, read_into_request);
+ readable_stream_add_read_into_request(vm, stream, read_into_request);
// 3. Return.
return;
@@ -1400,7 +1408,7 @@ pub(crate) fn readable_byte_stream_controller_pull_into(
// 16. If controller.[[queueTotalSize]] > 0,
if controller.queue_total_size.get() > 0.0 {
// 1. If ! ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) is true,
- if readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(controller, pull_into_descriptor) {
+ if readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(vm, controller, pull_into_descriptor) {
// 1. Let filledView be ! ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor).
let filled_view = readable_byte_stream_controller_convert_pull_into_descriptor(cx, pull_into_descriptor);
@@ -1433,11 +1441,11 @@ pub(crate) fn readable_byte_stream_controller_pull_into(
// 17. Append pullIntoDescriptor to controller.[[pendingPullIntos]].
controller
.pending_pull_intos
- .borrow_mut()
+ .borrow_mut(vm)
.push_back(pull_into_descriptor);
// 18. Perform ! ReadableStreamAddReadIntoRequest(stream, readIntoRequest).
- readable_stream_add_read_into_request(stream, read_into_request);
+ readable_stream_add_read_into_request(vm, stream, read_into_request);
// 19. Perform ! ReadableByteStreamControllerCallPullIfNeeded(controller).
readable_byte_stream_controller_call_pull_if_needed(cx, controller);
@@ -1512,7 +1520,7 @@ pub(crate) fn readable_byte_stream_controller_respond_in_closed_state(
// 2. If firstDescriptor’s reader type is "none", perform
// ! ReadableByteStreamControllerShiftPendingPullInto(controller).
if first_descriptor.reader_type.get() == ReaderType::None {
- readable_byte_stream_controller_shift_pending_pull_into(controller);
+ readable_byte_stream_controller_shift_pending_pull_into(cx.vm(), controller);
}
// 3. Let stream be controller.[[stream]].
@@ -1526,7 +1534,7 @@ pub(crate) fn readable_byte_stream_controller_respond_in_closed_state(
// 2. While filledPullIntos’s size < ! ReadableStreamGetNumReadIntoRequests(stream),
while filled_pull_intos.len() < readable_stream_get_num_read_into_requests(stream) {
// 1. Let pullIntoDescriptor be ! ReadableByteStreamControllerShiftPendingPullInto(controller).
- let pull_into_descriptor = readable_byte_stream_controller_shift_pending_pull_into(controller);
+ let pull_into_descriptor = readable_byte_stream_controller_shift_pending_pull_into(cx.vm(), controller);
// 2. Append pullIntoDescriptor to filledPullIntos.
filled_pull_intos.push(pull_into_descriptor);
@@ -1585,7 +1593,7 @@ pub(crate) fn readable_byte_stream_controller_respond_in_readable_state(
// the queue, so the underlying source can keep filling it.
// 5. Perform ! ReadableByteStreamControllerShiftPendingPullInto(controller).
- readable_byte_stream_controller_shift_pending_pull_into(controller);
+ readable_byte_stream_controller_shift_pending_pull_into(cx.vm(), controller);
// 6. Let remainderSize be the remainder after dividing pullIntoDescriptor’s bytes filled by pullIntoDescriptor’s
// element size.
@@ -1754,6 +1762,7 @@ pub(crate) fn readable_byte_stream_controller_respond_with_new_view(
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-shift-pending-pull-into
pub(crate) fn readable_byte_stream_controller_shift_pending_pull_into(
+ vm: &Vm,
controller: Ref<ReadableByteStreamController>,
) -> PullIntoDescriptorRef {
// 1. Assert: controller.[[byobRequest]] is null.
@@ -1764,7 +1773,7 @@ pub(crate) fn readable_byte_stream_controller_shift_pending_pull_into(
// 4. Return descriptor.
controller
.pending_pull_intos
- .borrow_mut()
+ .borrow_mut(vm)
.pop_front()
.expect("a controller shifts a pending pull-into it has")
}
@@ -1848,7 +1857,7 @@ pub(crate) fn set_up_readable_byte_stream_controller(
controller.byob_request.set(None);
// 6. Perform ! ResetQueue(controller).
- controller.reset_queue();
+ controller.reset_queue(cx.vm());
// 7. Set controller.[[closeRequested]] and controller.[[started]] to false.
controller.close_requested.set(false);
@@ -1858,16 +1867,16 @@ pub(crate) fn set_up_readable_byte_stream_controller(
controller.strategy_hwm.set(high_water_mark);
// 9. Set controller.[[pullAlgorithm]] to pullAlgorithm.
- *controller.pull_algorithm.borrow_mut() = Some(pull_algorithm);
+ controller.pull_algorithm.replace(Some(pull_algorithm));
// 10. Set controller.[[cancelAlgorithm]] to cancelAlgorithm.
- *controller.cancel_algorithm.borrow_mut() = Some(cancel_algorithm);
+ controller.cancel_algorithm.replace(Some(cancel_algorithm));
// 11. Set controller.[[autoAllocateChunkSize]] to autoAllocateChunkSize.
controller.auto_allocate_chunk_size.set(auto_allocate_chunk_size);
// 12. Set controller.[[pendingPullIntos]] to a new empty list.
- controller.pending_pull_intos.borrow_mut().clear();
+ controller.pending_pull_intos.borrow_mut(cx.vm()).clear();
// 13. Set stream.[[controller]] to controller.
stream.set_controller(Some(ReadableStreamController::ReadableByteStreamController(controller)));
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream.rs
index e6daa558ef7..68f0581774f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream.rs
@@ -1110,7 +1110,11 @@ pub(crate) fn readable_stream_from_iterable_cancel_algorithm(
}
// https://streams.spec.whatwg.org/#readable-stream-add-read-into-request
-pub(crate) fn readable_stream_add_read_into_request(stream: Ref<ReadableStream>, read_into_request: ReadIntoRequest) {
+pub(crate) fn readable_stream_add_read_into_request(
+ vm: &Vm,
+ stream: Ref<ReadableStream>,
+ read_into_request: ReadIntoRequest,
+) {
// 1. Assert: stream.[[reader]] implements ReadableStreamBYOBReader.
let Some(ReadableStreamReader::ReadableStreamBYOBReader(reader)) = stream.reader() else {
panic!("the stream is locked to a ReadableStreamBYOBReader");
@@ -1123,11 +1127,11 @@ pub(crate) fn readable_stream_add_read_into_request(stream: Ref<ReadableStream>,
));
// 3. Append readRequest to stream.[[reader]].[[readIntoRequests]].
- reader.append_read_into_request(read_into_request);
+ reader.append_read_into_request(vm, read_into_request);
}
// https://streams.spec.whatwg.org/#readable-stream-add-read-request
-pub(crate) fn readable_stream_add_read_request(stream: Ref<ReadableStream>, read_request: ReadRequest) {
+pub(crate) fn readable_stream_add_read_request(vm: &Vm, stream: Ref<ReadableStream>, read_request: ReadRequest) {
// 1. Assert: stream.[[reader]] implements ReadableStreamDefaultReader.
let Some(ReadableStreamReader::ReadableStreamDefaultReader(reader)) = stream.reader() else {
panic!("the stream is locked to a ReadableStreamDefaultReader");
@@ -1137,7 +1141,7 @@ pub(crate) fn readable_stream_add_read_request(stream: Ref<ReadableStream>, read
assert!(stream.state() == ReadableStreamState::Readable);
// 3. Append readRequest to stream.[[reader]].[[readRequests]].
- reader.append_read_request(read_request);
+ reader.append_read_request(vm, read_request);
}
// https://streams.spec.whatwg.org/#readable-stream-cancel
@@ -1293,7 +1297,7 @@ pub(crate) fn readable_stream_fulfill_read_into_request(
// 3. Assert: reader.[[readIntoRequests]] is not empty.
// 4. Let readIntoRequest be reader.[[readIntoRequests]][0].
// 5. Remove readIntoRequest from reader.[[readIntoRequests]].
- let read_into_request = reader.take_first_read_into_request();
+ let read_into_request = reader.take_first_read_into_request(vm);
// 6. If done is true, perform readIntoRequest’s close steps, given chunk.
if done {
@@ -1316,7 +1320,7 @@ pub(crate) fn readable_stream_fulfill_read_request(vm: &Vm, stream: Ref<Readable
// 3. Assert: reader.[[readRequests]] is not empty.
// 4. Let readRequest be reader.[[readRequests]][0].
// 5. Remove readRequest from reader.[[readRequests]].
- let read_request = reader.take_first_read_request();
+ let read_request = reader.take_first_read_request(vm);
// 6. If done is true, perform readRequest’s close steps.
if done {
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 a96484d7376..54e763fc2f4 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
@@ -55,8 +55,8 @@ impl ReadableStreamBYOBReader {
&self.generic
}
- pub(crate) fn append_read_into_request(&self, read_into_request: ReadIntoRequest) {
- self.read_into_requests.borrow_mut().push_back(read_into_request);
+ pub(crate) fn append_read_into_request(&self, vm: &Vm, read_into_request: ReadIntoRequest) {
+ self.read_into_requests.borrow_mut(vm).push_back(read_into_request);
}
/// Takes the reader's [[readIntoRequests]], leaving an empty list.
@@ -65,14 +65,14 @@ impl ReadableStreamBYOBReader {
for read_into_request in self.read_into_requests.borrow().iter() {
read_into_requests.push(read_into_request.clone());
}
- self.read_into_requests.borrow_mut().clear();
+ self.read_into_requests.borrow_mut(vm).clear();
read_into_requests
}
/// Removes the first of the reader's [[readIntoRequests]], which are not empty.
- pub(crate) fn take_first_read_into_request(&self) -> ReadIntoRequest {
+ pub(crate) fn take_first_read_into_request(&self, vm: &Vm) -> ReadIntoRequest {
self.read_into_requests
- .borrow_mut()
+ .borrow_mut(vm)
.pop_front()
.expect("the reader has a read-into request")
}
@@ -291,6 +291,6 @@ pub(crate) fn set_up_readable_stream_byob_reader(
readable_stream_reader_generic_initialize(cx, ReadableStreamReader::ReadableStreamBYOBReader(reader), stream);
// 4. Set reader.[[readIntoRequests]] to a new empty list.
- reader.read_into_requests.borrow_mut().clear();
+ reader.read_into_requests.borrow_mut(cx.vm()).clear();
Ok(())
}
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 aa410958b31..2353041e61a 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
@@ -133,7 +133,7 @@ impl ReadableStreamDefaultController {
// https://streams.spec.whatwg.org/#rs-default-controller-private-cancel
pub(crate) fn cancel_steps(this: Ref<Self>, cx: &CallContext, reason: Value) -> WebIdlPromise {
// 1. Perform ! ResetQueue(this).
- this.queue.reset_queue();
+ this.queue.reset_queue(cx.vm());
// 2. Let result be the result of performing this.[[cancelAlgorithm]], passing reason.
let cancel_algorithm = this
@@ -157,7 +157,7 @@ impl ReadableStreamDefaultController {
// 2. If this.[[queue]] is not empty,
if !this.queue.is_empty() {
// 1. Let chunk be ! DequeueValue(this).
- let chunk = this.queue.dequeue_value();
+ let chunk = this.queue.dequeue_value(vm);
// 2. If this.[[closeRequested]] is true and this.[[queue]] is empty,
if this.close_requested() && this.queue.is_empty() {
@@ -178,7 +178,7 @@ impl ReadableStreamDefaultController {
// 3. Otherwise,
else {
// 1. Perform ! ReadableStreamAddReadRequest(stream, readRequest).
- readable_stream_add_read_request(stream, read_request);
+ readable_stream_add_read_request(vm, stream, read_request);
// 2. Perform ! ReadableStreamDefaultControllerCallPullIfNeeded(this).
readable_stream_default_controller_call_pull_if_needed(cx, this);
@@ -294,13 +294,13 @@ pub(crate) fn readable_stream_default_controller_should_call_pull(
// https://streams.spec.whatwg.org/#readable-stream-default-controller-clear-algorithms
pub(crate) fn readable_stream_default_controller_clear_algorithms(controller: Ref<ReadableStreamDefaultController>) {
// 1. Set controller.[[pullAlgorithm]] to undefined.
- *controller.pull_algorithm.borrow_mut() = None;
+ controller.pull_algorithm.replace(None);
// 2. Set controller.[[cancelAlgorithm]] to undefined.
- *controller.cancel_algorithm.borrow_mut() = None;
+ controller.cancel_algorithm.replace(None);
// 3. Set controller.[[strategySizeAlgorithm]] to undefined.
- *controller.strategy_size_algorithm.borrow_mut() = None;
+ controller.strategy_size_algorithm.replace(None);
}
// https://streams.spec.whatwg.org/#readable-stream-default-controller-close
@@ -374,7 +374,7 @@ pub(crate) fn readable_stream_default_controller_enqueue(
};
// 4. Let enqueueResult be EnqueueValueWithSize(controller, chunk, chunkSize).
- let enqueue_result = controller.queue.enqueue_value_with_size(chunk, chunk_size);
+ let enqueue_result = controller.queue.enqueue_value_with_size(vm, chunk, chunk_size);
// 5. If enqueueResult is an abrupt completion,
if let Err(exception) = enqueue_result {
@@ -408,7 +408,7 @@ pub(crate) fn readable_stream_default_controller_error(
}
// 3. Perform ! ResetQueue(controller).
- controller.queue.reset_queue();
+ controller.queue.reset_queue(cx.vm());
// 4. Perform ! ReadableStreamDefaultControllerClearAlgorithms(controller).
readable_stream_default_controller_clear_algorithms(controller);
@@ -488,7 +488,7 @@ pub(crate) fn set_up_readable_stream_default_controller(
controller.stream.set(Some(stream));
// 3. Perform ! ResetQueue(controller).
- controller.queue.reset_queue();
+ controller.queue.reset_queue(vm);
// 4. Set controller.[[started]], controller.[[closeRequested]], controller.[[pullAgain]], and
// controller.[[pulling]] to false.
@@ -498,14 +498,14 @@ pub(crate) fn set_up_readable_stream_default_controller(
controller.pulling.set(false);
// 5. Set controller.[[strategySizeAlgorithm]] to sizeAlgorithm and controller.[[strategyHWM]] to highWaterMark.
- *controller.strategy_size_algorithm.borrow_mut() = Some(size_algorithm);
+ *controller.strategy_size_algorithm.borrow_mut(vm) = Some(size_algorithm);
controller.strategy_hwm.set(high_water_mark);
// 6. Set controller.[[pullAlgorithm]] to pullAlgorithm.
- *controller.pull_algorithm.borrow_mut() = Some(pull_algorithm);
+ *controller.pull_algorithm.borrow_mut(vm) = Some(pull_algorithm);
// 7. Set controller.[[cancelAlgorithm]] to cancelAlgorithm.
- *controller.cancel_algorithm.borrow_mut() = Some(cancel_algorithm);
+ *controller.cancel_algorithm.borrow_mut(vm) = Some(cancel_algorithm);
// 8. Set stream.[[controller]] to controller.
stream.set_controller(Some(ReadableStreamController::ReadableStreamDefaultController(
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 1ac2139480e..21bb061e20a 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
@@ -72,8 +72,8 @@ impl ReadableStreamDefaultReader {
&self.generic
}
- pub(crate) fn append_read_request(&self, read_request: ReadRequest) {
- self.read_requests.borrow_mut().push_back(read_request);
+ pub(crate) fn append_read_request(&self, vm: &Vm, read_request: ReadRequest) {
+ self.read_requests.borrow_mut(vm).push_back(read_request);
}
/// Takes the reader's [[readRequests]], leaving an empty list.
@@ -82,14 +82,14 @@ impl ReadableStreamDefaultReader {
for read_request in self.read_requests.borrow().iter() {
read_requests.push(read_request.clone());
}
- self.read_requests.borrow_mut().clear();
+ self.read_requests.borrow_mut(vm).clear();
read_requests
}
/// Removes the first of the reader's [[readRequests]], which are not empty.
- pub(crate) fn take_first_read_request(&self) -> ReadRequest {
+ pub(crate) fn take_first_read_request(&self, vm: &Vm) -> ReadRequest {
self.read_requests
- .borrow_mut()
+ .borrow_mut(vm)
.pop_front()
.expect("the reader has a read request")
}
@@ -350,6 +350,6 @@ pub(crate) fn set_up_readable_stream_default_reader(
readable_stream_reader_generic_initialize(cx, ReadableStreamReader::ReadableStreamDefaultReader(reader), stream);
// 3. Set reader.[[readRequests]] to a new empty list.
- reader.read_requests.borrow_mut().clear();
+ reader.read_requests.borrow_mut(cx.vm()).clear();
Ok(())
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_generic_reader.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_generic_reader.rs
index 98dedebee53..dabe94dee30 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_generic_reader.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_generic_reader.rs
@@ -184,7 +184,7 @@ pub(crate) fn readable_stream_reader_generic_release(vm: &Vm, reader: ReadableSt
ReadableStreamDefaultController::release_steps(controller);
}
ReadableStreamController::ReadableByteStreamController(controller) => {
- ReadableByteStreamController::release_steps(controller);
+ ReadableByteStreamController::release_steps(vm, controller);
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_pipe_to.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_pipe_to.rs
index f5e628b1e80..a5b46520002 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_pipe_to.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/readable_stream_pipe_to.rs
@@ -299,7 +299,7 @@ impl PipeTo {
// chunk steps, given chunk, of the read request of the pipe
pub(crate) fn read_request_chunk_steps(this: PipeToRef, vm: &Vm, chunk: Value) {
- this.unwritten_chunks.borrow_mut().push_back(chunk);
+ this.unwritten_chunks.borrow_mut(vm).push_back(chunk);
if Self::check_for_error_and_close_states(this, vm) {
return;
@@ -335,7 +335,7 @@ impl PipeTo {
}
// NB: Shutdown writes every unwritten chunk, which can run before the write that a read queued.
- let Some(chunk) = this.unwritten_chunks.borrow_mut().pop_front() else {
+ let Some(chunk) = this.unwritten_chunks.borrow_mut(vm).pop_front() else {
return;
};
let promise = writable_stream_default_writer_write(vm, this.writer, chunk);
@@ -616,7 +616,7 @@ pub(crate) fn readable_stream_pipe_to(
let signal_id = signal
.add_algorithm(abort_algorithm)
.expect("a signal that is not aborted takes algorithms");
- *this.signal.borrow_mut() = Some(signal);
+ *this.signal.borrow_mut(vm) = Some(signal);
this.signal_algorithm_id.set(Some(signal_id));
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/transform_stream_default_controller.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/transform_stream_default_controller.rs
index 1deabb7d030..e4d1811acfc 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/transform_stream_default_controller.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/transform_stream_default_controller.rs
@@ -77,7 +77,7 @@ impl TransformStreamDefaultController {
}
pub(crate) fn set_cancel_algorithm(&self, algorithm: Option<CancelAlgorithm>) {
- *self.cancel_algorithm.borrow_mut() = algorithm;
+ self.cancel_algorithm.replace(algorithm);
}
pub(crate) fn flush_algorithm(&self) -> Option<FlushAlgorithm> {
@@ -85,7 +85,7 @@ impl TransformStreamDefaultController {
}
pub(crate) fn set_flush_algorithm(&self, algorithm: Option<FlushAlgorithm>) {
- *self.flush_algorithm.borrow_mut() = algorithm;
+ self.flush_algorithm.replace(algorithm);
}
pub(crate) fn transform_algorithm(&self) -> Option<TransformAlgorithm> {
@@ -93,7 +93,7 @@ impl TransformStreamDefaultController {
}
pub(crate) fn set_transform_algorithm(&self, algorithm: Option<TransformAlgorithm>) {
- *self.transform_algorithm.borrow_mut() = algorithm;
+ self.transform_algorithm.replace(algorithm);
}
// https://streams.spec.whatwg.org/#ts-default-controller-desired-size
diff --git a/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream.rs b/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream.rs
index 8ae0f8a8c74..3ea61224364 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/streams/writable_stream.rs
@@ -158,7 +158,7 @@ impl WritableStream {
for write_request in self.write_requests.borrow().iter() {
write_requests.push(*write_request);
}
- self.write_requests.borrow_mut().clear();
+ self.write_requests.borrow_mut(vm).clear();
write_requests
}
@@ -341,7 +341,7 @@ pub(crate) fn create_writable_stream(
let stream = allocate(cx.vm(), WritableStream::new(cx.realm()));
// 3. Perform ! InitializeWritableStream(stream).
- initialize_writable_stream(stream);
+ initialize_writable_stream(cx.vm(), stream);
// 4. Let controller be a new WritableStreamDefaultController.
let controller = allocate(cx.vm(), WritableStreamDefaultController::new());
@@ -365,7 +365,7 @@ pub(crate) fn create_writable_stream(
}
// https://streams.spec.whatwg.org/#initialize-writable-stream
-pub(crate) fn initialize_writable_stream(stream: Ref<WritableStream>) {
+pub(crate) fn initialize_writable_stream(vm: &Vm, stream: Ref<WritableStream>) {
// 1. Set stream.[[state]] to "writable".
stream.state.set(WritableStreamState::Writable);
@@ -380,7 +380,7 @@ pub(crate) fn initialize_writable_stream(stream: Ref<WritableStream>) {
stream.pending_abort_request.set(None);
// 3. Set stream.[[writeRequests]] to a new empty list.
- stream.write_requests.borrow_mut().clear();
+ stream.write_requests.borrow_mut(vm).clear();
// 4. Set stream.[[backpressure]] to false.
stream.backpressure.set(false);
@@ -618,7 +618,7 @@ pub(crate) fn writable_stream_add_write_request(cx: &CallContext, stream: Ref<Wr
let promise = create_promise(cx.vm(), cx.realm());
// 4. Append promise to stream.[[writeRequests]].
- stream.write_requests.borrow_mut().push_back(promise);
+ stream.write_requests.borrow_mut(cx.vm()).push_back(promise);
// 5. Return promise.
promise
@@ -667,7 +667,7 @@ pub(crate) fn writable_stream_finish_erroring(cx: &CallContext, stream: Ref<Writ
// 4. Perform ! stream.[[controller]].[[ErrorSteps]]().
let controller = stream.controller().expect("a stream that is set up has a controller");
- WritableStreamDefaultController::error_steps(controller);
+ WritableStreamDefaultController::error_steps(vm, controller);
// 5. Let storedError be stream.[[storedError]].
let stored_error = stream.stored_error();
@@ -888,7 +888,7 @@ pub(crate) fn writable_stream_mark_close_request_in_flight(stream: Ref<WritableS
}
// https://streams.spec.whatwg.org/#writable-stream-mark-first-write-request-in-flight
-pub(crate) fn writable_stream_mark_first_write_request_in_flight(stream: Ref<WritableStream>) {
+pub(crate) fn writable_stream_mark_first_write_request_in_flight(vm: &Vm, stream: Ref<WritableStream>) {
// 1. Assert: stream.[[inFlightWriteRequest]] is undefined.
assert!(stream.in_flight_write_request.get().is_none());
@@ -897,7 +897,7 @@ pub(crate) fn writable_stream_mark_first_write_request_in_flight(stream: Ref<Wri
// 4. Remove writeRequest from stream.[[writeRequests]].
let write_request = stream
.write_requests
- .borrow_mut()
+ .borrow_mut(vm)
.pop_front()
.expect("a stream has a write request to mark in flight");
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 65efa7857db..c1e52ebecd1 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};
+use libjs_rust::api::{GcRefCell, Trace, Value, Vm};
use crate::bindings::conversions::CppInterface;
use crate::bindings::interface::{Ref, Wrappable, allocate, wrap};
@@ -157,9 +157,9 @@ impl WritableStreamDefaultController {
}
// https://streams.spec.whatwg.org/#ws-default-controller-private-error
- pub(crate) fn error_steps(this: Ref<Self>) {
+ pub(crate) fn error_steps(vm: &Vm, this: Ref<Self>) {
// 1. Perform ! ResetQueue(this).
- this.queue.reset_queue();
+ this.queue.reset_queue(vm);
}
}
@@ -190,29 +190,29 @@ pub(crate) fn set_up_writable_stream_default_controller(
stream.set_controller(Some(controller));
// 5. Perform ! ResetQueue(controller).
- controller.queue.reset_queue();
+ controller.queue.reset_queue(vm);
// 6. Set controller.[[abortController]] to a new AbortController.
let signal = AbortSignal::create();
- *controller.signal.borrow_mut() = Some(signal);
+ *controller.signal.borrow_mut(vm) = Some(signal);
// 7. Set controller.[[started]] to false.
controller.started.set(false);
// 8. Set controller.[[strategySizeAlgorithm]] to sizeAlgorithm.
- *controller.strategy_size_algorithm.borrow_mut() = Some(size_algorithm);
+ *controller.strategy_size_algorithm.borrow_mut(vm) = Some(size_algorithm);
// 9. Set controller.[[strategyHWM]] to highWaterMark.
controller.strategy_hwm.set(high_water_mark);
// 10. Set controller.[[writeAlgorithm]] to writeAlgorithm.
- *controller.write_algorithm.borrow_mut() = Some(write_algorithm);
+ *controller.write_algorithm.borrow_mut(vm) = Some(write_algorithm);
// 11. Set controller.[[closeAlgorithm]] to closeAlgorithm.
- *controller.close_algorithm.borrow_mut() = Some(close_algorithm);
+ *controller.close_algorithm.borrow_mut(vm) = Some(close_algorithm);
// 12. Set controller.[[abortAlgorithm]] to abortAlgorithm.
- *controller.abort_algorithm.borrow_mut() = Some(abort_algorithm);
+ *controller.abort_algorithm.borrow_mut(vm) = Some(abort_algorithm);
// 13. Let backpressure be ! WritableStreamDefaultControllerGetBackpressure(controller).
let backpressure = writable_stream_default_controller_get_backpressure(controller);
@@ -398,16 +398,16 @@ pub(crate) fn writable_stream_default_controller_advance_queue_if_needed(
// https://streams.spec.whatwg.org/#writable-stream-default-controller-clear-algorithms
pub(crate) fn writable_stream_default_controller_clear_algorithms(controller: Ref<WritableStreamDefaultController>) {
// 1. Set controller.[[writeAlgorithm]] to undefined.
- *controller.write_algorithm.borrow_mut() = None;
+ controller.write_algorithm.replace(None);
// 2. Set controller.[[closeAlgorithm]] to undefined.
- *controller.close_algorithm.borrow_mut() = None;
+ controller.close_algorithm.replace(None);
// 3. Set controller.[[abortAlgorithm]] to undefined.
- *controller.abort_algorithm.borrow_mut() = None;
+ controller.abort_algorithm.replace(None);
// 4. Set controller.[[strategySizeAlgorithm]] to undefined.
- *controller.strategy_size_algorithm.borrow_mut() = None;
+ controller.strategy_size_algorithm.replace(None);
}
// https://streams.spec.whatwg.org/#writable-stream-default-controller-close
@@ -418,7 +418,7 @@ pub(crate) fn writable_stream_default_controller_close(
// 1. Perform ! EnqueueValueWithSize(controller, close sentinel, 0).
controller
.queue
- .enqueue_value_with_size(create_close_sentinel(), Value::from_f64(0.0))
+ .enqueue_value_with_size(cx.vm(), create_close_sentinel(), Value::from_f64(0.0))
.must();
// 2. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller).
@@ -521,7 +521,7 @@ pub(crate) fn writable_stream_default_controller_process_close(
writable_stream_mark_close_request_in_flight(stream);
// 3. Perform ! DequeueValue(controller).
- controller.queue.dequeue_value();
+ controller.queue.dequeue_value(cx.vm());
// 4. Assert: controller.[[queue]] is empty.
assert!(controller.queue.is_empty());
@@ -566,7 +566,7 @@ pub(crate) fn writable_stream_default_controller_process_write(
let stream = controller.stream();
// 2. Perform ! WritableStreamMarkFirstWriteRequestInFlight(stream).
- writable_stream_mark_first_write_request_in_flight(stream);
+ writable_stream_mark_first_write_request_in_flight(cx.vm(), stream);
// 3. Let sinkWritePromise be the result of performing controller.[[writeAlgorithm]], passing in chunk.
let write_algorithm = controller
@@ -590,7 +590,7 @@ pub(crate) fn writable_stream_default_controller_process_write(
assert!(state == WritableStreamState::Writable || state == WritableStreamState::Erroring);
// 4. Perform ! DequeueValue(controller).
- controller.queue.dequeue_value();
+ controller.queue.dequeue_value(cx.vm());
// 5. If ! WritableStreamCloseQueuedOrInFlight(stream) is false and state is "writable",
if !writable_stream_close_queued_or_in_flight(stream) && state == WritableStreamState::Writable {
@@ -630,7 +630,7 @@ pub(crate) fn writable_stream_default_controller_write(
chunk_size: Value,
) {
// 1. Let enqueueResult be EnqueueValueWithSize(controller, chunk, chunkSize).
- let enqueue_result = controller.queue.enqueue_value_with_size(chunk, chunk_size);
+ let enqueue_result = controller.queue.enqueue_value_with_size(cx.vm(), chunk, chunk_size);
// 2. If enqueueResult is an abrupt completion,
if let Err(exception) = enqueue_result {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/extensions.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/extensions.rs
index 69f07b74849..157fa72bd07 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/extensions.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/extensions.rs
@@ -227,7 +227,7 @@ impl ContextState {
match extension.kind {
Kind::Interface(interface) => {
let object = interface.create(cx.vm(), self);
- self.enabled_extensions.borrow_mut().push(EnabledExtension {
+ self.enabled_extensions.borrow_mut(cx.vm()).push(EnabledExtension {
name: extension.name,
object,
});
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_framebuffer.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_framebuffer.rs
index 502ef3b5864..3be45628e5b 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_framebuffer.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_framebuffer.rs
@@ -65,13 +65,18 @@ impl WebGLFramebuffer {
.copied()
}
- fn set_attachment(&self, attachment: u32, new_attachment: Option<Attachment>) {
- let mut attachments = self.attachments.borrow_mut();
+ fn set_attachment(&self, vm: &Vm, attachment: u32, new_attachment: Option<Attachment>) {
+ let mut attachments = self.attachments.borrow_mut(vm);
attachments.retain(|existing| existing.attachment != attachment);
attachments.extend(new_attachment);
}
- pub(crate) fn set_renderbuffer_attachment(&self, attachment: u32, renderbuffer: Option<Ref<WebGLRenderbuffer>>) {
+ pub(crate) fn set_renderbuffer_attachment(
+ &self,
+ vm: &Vm,
+ attachment: u32,
+ renderbuffer: Option<Ref<WebGLRenderbuffer>>,
+ ) {
let new_attachment = renderbuffer.map(|renderbuffer| Attachment {
attachment,
texture: None,
@@ -79,11 +84,12 @@ impl WebGLFramebuffer {
texture_target: 0,
texture_level: 0,
});
- self.set_attachment(attachment, new_attachment);
+ self.set_attachment(vm, attachment, new_attachment);
}
pub(crate) fn set_texture_attachment(
&self,
+ vm: &Vm,
attachment: u32,
texture: Option<Ref<WebGLTexture>>,
texture_target: u32,
@@ -96,6 +102,6 @@ impl WebGLFramebuffer {
texture_target,
texture_level,
});
- self.set_attachment(attachment, new_attachment);
+ self.set_attachment(vm, attachment, new_attachment);
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_rendering_context_base.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_rendering_context_base.rs
index 1424101a97b..3548f590dab 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_rendering_context_base.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_rendering_context_base.rs
@@ -683,7 +683,7 @@ impl<V: Version> RenderingContext<V> {
pub(crate) fn framebuffer_renderbuffer(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
target: u32,
attachment: u32,
renderbuffertarget: u32,
@@ -718,13 +718,13 @@ impl<V: Version> RenderingContext<V> {
}
self.proxy
.framebuffer_renderbuffer(target, attachment, renderbuffertarget, renderbuffer_handle);
- bound_framebuffer.set_renderbuffer_attachment(attachment, renderbuffer);
+ bound_framebuffer.set_renderbuffer_attachment(cx.vm(), attachment, renderbuffer);
Ok(())
}
pub(crate) fn framebuffer_texture2d(
&self,
- _: &mut CallContext,
+ cx: &mut CallContext,
target: u32,
attachment: u32,
textarget: u32,
@@ -765,7 +765,7 @@ impl<V: Version> RenderingContext<V> {
}
self.proxy
.framebuffer_texture2d(target, attachment, textarget, texture_handle, level);
- bound_framebuffer.set_texture_attachment(attachment, texture, textarget, level);
+ bound_framebuffer.set_texture_attachment(cx.vm(), attachment, texture, textarget, level);
Ok(())
}