From f826698d6e5483f18d13a9f104e0645ee31bb8d9 Mon Sep 17 00:00:00 2001 From: tanishka <109246904+taniishkaaa@users.noreply.github.com> Date: Fri, 18 Oct 2024 04:06:04 +0530 Subject: [PATCH] CanGc fixes in components/script/dom (#33891) Signed-off-by: taniishkaaa --- .../script/dom/abstractworkerglobalscope.rs | 4 ++-- components/script/dom/baseaudiocontext.rs | 17 +++++++++++++---- .../script/dom/bindings/codegen/Bindings.conf | 2 +- components/script/dom/channelmergernode.rs | 3 ++- .../script/dom/dedicatedworkerglobalscope.rs | 2 +- components/script/dom/extendablemessageevent.rs | 8 ++++++-- components/script/dom/gpu.rs | 3 ++- components/script/dom/gpuadapter.rs | 7 +++++-- components/script/dom/gpudevice.rs | 3 ++- components/script/dom/gpusupportedfeatures.rs | 6 ++++-- components/script/dom/pannernode.rs | 3 ++- components/script/dom/performanceobserver.rs | 3 ++- .../script/dom/serviceworkerglobalscope.rs | 13 +++++++------ 13 files changed, 49 insertions(+), 25 deletions(-) diff --git a/components/script/dom/abstractworkerglobalscope.rs b/components/script/dom/abstractworkerglobalscope.rs index 2309c08d41d..15277175075 100644 --- a/components/script/dom/abstractworkerglobalscope.rs +++ b/components/script/dom/abstractworkerglobalscope.rs @@ -89,7 +89,7 @@ pub trait WorkerEventLoopMethods { type ControlMsg; type Event; fn task_queue(&self) -> &TaskQueue; - fn handle_event(&self, event: Self::Event) -> bool; + fn handle_event(&self, event: Self::Event, can_gc: CanGc) -> bool; fn handle_worker_post_event(&self, worker: &TrustedWorkerAddress) -> Option; fn from_control_msg(msg: Self::ControlMsg) -> Self::Event; fn from_worker_msg(msg: Self::WorkerMsg) -> Self::Event; @@ -143,7 +143,7 @@ pub fn run_worker_event_loop( // Step 3 for event in sequential { let _realm = enter_realm(worker_scope); - if !worker_scope.handle_event(event) { + if !worker_scope.handle_event(event, can_gc) { // Shutdown return; } diff --git a/components/script/dom/baseaudiocontext.rs b/components/script/dom/baseaudiocontext.rs index cdb8320d75d..a4cac0fb69f 100644 --- a/components/script/dom/baseaudiocontext.rs +++ b/components/script/dom/baseaudiocontext.rs @@ -367,8 +367,13 @@ impl BaseAudioContextMethods for BaseAudioContext { } /// - fn CreatePanner(&self) -> Fallible> { - PannerNode::new(self.global().as_window(), self, &PannerOptions::empty()) + fn CreatePanner(&self, can_gc: CanGc) -> Fallible> { + PannerNode::new( + self.global().as_window(), + self, + &PannerOptions::empty(), + can_gc, + ) } /// @@ -411,10 +416,14 @@ impl BaseAudioContextMethods for BaseAudioContext { } /// - fn CreateChannelMerger(&self, count: u32) -> Fallible> { + fn CreateChannelMerger( + &self, + count: u32, + can_gc: CanGc, + ) -> Fallible> { let mut opts = ChannelMergerOptions::empty(); opts.numberOfInputs = count; - ChannelMergerNode::new(self.global().as_window(), self, &opts) + ChannelMergerNode::new(self.global().as_window(), self, &opts, can_gc) } /// diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index 99ac357781e..e3c0116f631 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -25,7 +25,7 @@ DOMInterfaces = { 'BaseAudioContext': { 'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'], - 'canGc': ['CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser'], + 'canGc': ['CreateChannelMerger', 'CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser', 'CreatePanner'], }, 'Blob': { diff --git a/components/script/dom/channelmergernode.rs b/components/script/dom/channelmergernode.rs index e40197c8853..47d1e1600f3 100644 --- a/components/script/dom/channelmergernode.rs +++ b/components/script/dom/channelmergernode.rs @@ -61,8 +61,9 @@ impl ChannelMergerNode { window: &Window, context: &BaseAudioContext, options: &ChannelMergerOptions, + can_gc: CanGc, ) -> Fallible> { - Self::new_with_proto(window, None, context, options, CanGc::note()) + Self::new_with_proto(window, None, context, options, can_gc) } #[allow(crown::unrooted_must_root)] diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 4b0b064bb35..f25fa281638 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -212,7 +212,7 @@ impl WorkerEventLoopMethods for DedicatedWorkerGlobalScope { &self.task_queue } - fn handle_event(&self, event: MixedMessage) -> bool { + fn handle_event(&self, event: MixedMessage, _can_gc: CanGc) -> bool { self.handle_mixed_message(event) } diff --git a/components/script/dom/extendablemessageevent.rs b/components/script/dom/extendablemessageevent.rs index 3c92bce544a..2d8321fbe46 100644 --- a/components/script/dom/extendablemessageevent.rs +++ b/components/script/dom/extendablemessageevent.rs @@ -75,6 +75,7 @@ impl ExtendableMessageEvent { origin: DOMString, lastEventId: DOMString, ports: Vec>, + can_gc: CanGc, ) -> DomRoot { Self::new_with_proto( global, @@ -86,7 +87,7 @@ impl ExtendableMessageEvent { origin, lastEventId, ports, - CanGc::note(), + can_gc, ) } @@ -126,6 +127,7 @@ impl ExtendableMessageEvent { scope: &GlobalScope, message: HandleValue, ports: Vec>, + can_gc: CanGc, ) { let Extendablemessageevent = ExtendableMessageEvent::new( scope, @@ -136,11 +138,12 @@ impl ExtendableMessageEvent { DOMString::new(), DOMString::new(), ports, + can_gc, ); Extendablemessageevent.upcast::().fire(target); } - pub fn dispatch_error(target: &EventTarget, scope: &GlobalScope) { + pub fn dispatch_error(target: &EventTarget, scope: &GlobalScope, can_gc: CanGc) { let init = ExtendableMessageEventBinding::ExtendableMessageEventInit::empty(); let ExtendableMsgEvent = ExtendableMessageEvent::new( scope, @@ -151,6 +154,7 @@ impl ExtendableMessageEvent { init.origin.clone(), init.lastEventId.clone(), init.ports.clone(), + can_gc, ); ExtendableMsgEvent.upcast::().fire(target); } diff --git a/components/script/dom/gpu.rs b/components/script/dom/gpu.rs index 02c8179e520..84e1a2fd481 100644 --- a/components/script/dom/gpu.rs +++ b/components/script/dom/gpu.rs @@ -143,7 +143,7 @@ impl GPUMethods for GPU { } impl AsyncWGPUListener for GPU { - fn handle_response(&self, response: WebGPUResponse, promise: &Rc, _can_gc: CanGc) { + fn handle_response(&self, response: WebGPUResponse, promise: &Rc, can_gc: CanGc) { match response { WebGPUResponse::Adapter(Ok(adapter)) => { let adapter = GPUAdapter::new( @@ -158,6 +158,7 @@ impl AsyncWGPUListener for GPU { adapter.limits, adapter.adapter_info, adapter.adapter_id, + can_gc, ); promise.resolve_native(&adapter); }, diff --git a/components/script/dom/gpuadapter.rs b/components/script/dom/gpuadapter.rs index 1643820f972..9a8ad998280 100644 --- a/components/script/dom/gpuadapter.rs +++ b/components/script/dom/gpuadapter.rs @@ -77,8 +77,9 @@ impl GPUAdapter { limits: wgt::Limits, info: wgt::AdapterInfo, adapter: WebGPUAdapter, + can_gc: CanGc, ) -> DomRoot { - let features = GPUSupportedFeatures::Constructor(global, None, features).unwrap(); + let features = GPUSupportedFeatures::Constructor(global, None, features, can_gc).unwrap(); let limits = GPUSupportedLimits::new(global, limits); let info = GPUAdapterInfo::new(global, info); reflect_dom_object( @@ -195,7 +196,7 @@ impl GPUAdapterMethods for GPUAdapter { } impl AsyncWGPUListener for GPUAdapter { - fn handle_response(&self, response: WebGPUResponse, promise: &Rc, _can_gc: CanGc) { + fn handle_response(&self, response: WebGPUResponse, promise: &Rc, can_gc: CanGc) { match response { WebGPUResponse::Device((device_id, queue_id, Ok(descriptor))) => { let device = GPUDevice::new( @@ -208,6 +209,7 @@ impl AsyncWGPUListener for GPUAdapter { device_id, queue_id, descriptor.label.unwrap_or_default(), + can_gc, ); self.global().add_gpu_device(&device); promise.resolve_native(&device); @@ -231,6 +233,7 @@ impl AsyncWGPUListener for GPUAdapter { device_id, queue_id, String::new(), + can_gc, ); device.lose(GPUDeviceLostReason::Unknown, e.to_string()); promise.resolve_native(&device); diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs index 29e2231b99b..b3aae263d4e 100644 --- a/components/script/dom/gpudevice.rs +++ b/components/script/dom/gpudevice.rs @@ -148,10 +148,11 @@ impl GPUDevice { device: webgpu::WebGPUDevice, queue: webgpu::WebGPUQueue, label: String, + can_gc: CanGc, ) -> DomRoot { let queue = GPUQueue::new(global, channel.clone(), queue); let limits = GPUSupportedLimits::new(global, limits); - let features = GPUSupportedFeatures::Constructor(global, None, features).unwrap(); + let features = GPUSupportedFeatures::Constructor(global, None, features, can_gc).unwrap(); let lost_promise = Promise::new(global); let device = reflect_dom_object( Box::new(GPUDevice::new_inherited( diff --git a/components/script/dom/gpusupportedfeatures.rs b/components/script/dom/gpusupportedfeatures.rs index cff007fa7d1..cafa8d87908 100644 --- a/components/script/dom/gpusupportedfeatures.rs +++ b/components/script/dom/gpusupportedfeatures.rs @@ -50,6 +50,7 @@ impl GPUSupportedFeatures { global: &GlobalScope, proto: Option, features: Features, + can_gc: CanGc, ) -> DomRoot { let mut set = IndexSet::new(); if features.contains(Features::DEPTH_CLIP_CONTROL) { @@ -103,7 +104,7 @@ impl GPUSupportedFeatures { }), global, proto, - CanGc::note(), + can_gc, ) } @@ -112,8 +113,9 @@ impl GPUSupportedFeatures { global: &GlobalScope, proto: Option, features: Features, + can_gc: CanGc, ) -> Fallible> { - Ok(GPUSupportedFeatures::new(global, proto, features)) + Ok(GPUSupportedFeatures::new(global, proto, features, can_gc)) } } diff --git a/components/script/dom/pannernode.rs b/components/script/dom/pannernode.rs index d82f14b8be6..7954f4c4940 100644 --- a/components/script/dom/pannernode.rs +++ b/components/script/dom/pannernode.rs @@ -184,8 +184,9 @@ impl PannerNode { window: &Window, context: &BaseAudioContext, options: &PannerOptions, + can_gc: CanGc, ) -> Fallible> { - Self::new_with_proto(window, None, context, options, CanGc::note()) + Self::new_with_proto(window, None, context, options, can_gc) } #[allow(crown::unrooted_must_root)] diff --git a/components/script/dom/performanceobserver.rs b/components/script/dom/performanceobserver.rs index 167a997287d..339941ffbf6 100644 --- a/components/script/dom/performanceobserver.rs +++ b/components/script/dom/performanceobserver.rs @@ -70,8 +70,9 @@ impl PerformanceObserver { global: &GlobalScope, callback: Rc, entries: DOMPerformanceEntryList, + can_gc: CanGc, ) -> DomRoot { - Self::new_with_proto(global, None, callback, entries, CanGc::note()) + Self::new_with_proto(global, None, callback, entries, can_gc) } #[allow(crown::unrooted_must_root)] diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs index ee6a8da13c2..e4ce55ec3d5 100644 --- a/components/script/dom/serviceworkerglobalscope.rs +++ b/components/script/dom/serviceworkerglobalscope.rs @@ -191,8 +191,8 @@ impl WorkerEventLoopMethods for ServiceWorkerGlobalScope { &self.task_queue } - fn handle_event(&self, event: MixedMessage) -> bool { - self.handle_mixed_message(event) + fn handle_event(&self, event: MixedMessage, can_gc: CanGc) -> bool { + self.handle_mixed_message(event, can_gc) } fn handle_worker_post_event(&self, _worker: &TrustedWorkerAddress) -> Option { @@ -411,7 +411,7 @@ impl ServiceWorkerGlobalScope { .expect("Thread spawning failed") } - fn handle_mixed_message(&self, msg: MixedMessage) -> bool { + fn handle_mixed_message(&self, msg: MixedMessage, can_gc: CanGc) -> bool { match msg { MixedMessage::Devtools(msg) => match msg { DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) => { @@ -423,7 +423,7 @@ impl ServiceWorkerGlobalScope { _ => debug!("got an unusable devtools control message inside the worker!"), }, MixedMessage::ServiceWorker(msg) => { - self.handle_script_event(msg); + self.handle_script_event(msg, can_gc); }, MixedMessage::Control(ServiceWorkerControlMsg::Exit) => { return false; @@ -437,7 +437,7 @@ impl ServiceWorkerGlobalScope { false } - fn handle_script_event(&self, msg: ServiceWorkerScriptMsg) { + fn handle_script_event(&self, msg: ServiceWorkerScriptMsg, can_gc: CanGc) { use self::ServiceWorkerScriptMsg::*; match msg { @@ -453,9 +453,10 @@ impl ServiceWorkerGlobalScope { scope.upcast(), message.handle(), ports, + can_gc, ); } else { - ExtendableMessageEvent::dispatch_error(target, scope.upcast()); + ExtendableMessageEvent::dispatch_error(target, scope.upcast(), can_gc); } }, CommonWorker(WorkerScriptMsg::Common(msg)) => {