CanGc fixes in components/script/dom (#33891)

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
This commit is contained in:
tanishka 2024-10-18 04:06:04 +05:30 committed by GitHub
parent 9c893c7f4d
commit f826698d6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 49 additions and 25 deletions

View file

@ -89,7 +89,7 @@ pub trait WorkerEventLoopMethods {
type ControlMsg; type ControlMsg;
type Event; type Event;
fn task_queue(&self) -> &TaskQueue<Self::WorkerMsg>; fn task_queue(&self) -> &TaskQueue<Self::WorkerMsg>;
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<AutoWorkerReset>; fn handle_worker_post_event(&self, worker: &TrustedWorkerAddress) -> Option<AutoWorkerReset>;
fn from_control_msg(msg: Self::ControlMsg) -> Self::Event; fn from_control_msg(msg: Self::ControlMsg) -> Self::Event;
fn from_worker_msg(msg: Self::WorkerMsg) -> Self::Event; fn from_worker_msg(msg: Self::WorkerMsg) -> Self::Event;
@ -143,7 +143,7 @@ pub fn run_worker_event_loop<T, WorkerMsg, Event>(
// Step 3 // Step 3
for event in sequential { for event in sequential {
let _realm = enter_realm(worker_scope); let _realm = enter_realm(worker_scope);
if !worker_scope.handle_event(event) { if !worker_scope.handle_event(event, can_gc) {
// Shutdown // Shutdown
return; return;
} }

View file

@ -367,8 +367,13 @@ impl BaseAudioContextMethods for BaseAudioContext {
} }
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createpanner> /// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createpanner>
fn CreatePanner(&self) -> Fallible<DomRoot<PannerNode>> { fn CreatePanner(&self, can_gc: CanGc) -> Fallible<DomRoot<PannerNode>> {
PannerNode::new(self.global().as_window(), self, &PannerOptions::empty()) PannerNode::new(
self.global().as_window(),
self,
&PannerOptions::empty(),
can_gc,
)
} }
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createanalyser> /// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createanalyser>
@ -411,10 +416,14 @@ impl BaseAudioContextMethods for BaseAudioContext {
} }
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelmerger> /// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelmerger>
fn CreateChannelMerger(&self, count: u32) -> Fallible<DomRoot<ChannelMergerNode>> { fn CreateChannelMerger(
&self,
count: u32,
can_gc: CanGc,
) -> Fallible<DomRoot<ChannelMergerNode>> {
let mut opts = ChannelMergerOptions::empty(); let mut opts = ChannelMergerOptions::empty();
opts.numberOfInputs = count; opts.numberOfInputs = count;
ChannelMergerNode::new(self.global().as_window(), self, &opts) ChannelMergerNode::new(self.global().as_window(), self, &opts, can_gc)
} }
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelsplitter> /// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelsplitter>

View file

@ -25,7 +25,7 @@ DOMInterfaces = {
'BaseAudioContext': { 'BaseAudioContext': {
'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'], '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': { 'Blob': {

View file

@ -61,8 +61,9 @@ impl ChannelMergerNode {
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &ChannelMergerOptions, options: &ChannelMergerOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<ChannelMergerNode>> { ) -> Fallible<DomRoot<ChannelMergerNode>> {
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)] #[allow(crown::unrooted_must_root)]

View file

@ -212,7 +212,7 @@ impl WorkerEventLoopMethods for DedicatedWorkerGlobalScope {
&self.task_queue &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) self.handle_mixed_message(event)
} }

View file

@ -75,6 +75,7 @@ impl ExtendableMessageEvent {
origin: DOMString, origin: DOMString,
lastEventId: DOMString, lastEventId: DOMString,
ports: Vec<DomRoot<MessagePort>>, ports: Vec<DomRoot<MessagePort>>,
can_gc: CanGc,
) -> DomRoot<ExtendableMessageEvent> { ) -> DomRoot<ExtendableMessageEvent> {
Self::new_with_proto( Self::new_with_proto(
global, global,
@ -86,7 +87,7 @@ impl ExtendableMessageEvent {
origin, origin,
lastEventId, lastEventId,
ports, ports,
CanGc::note(), can_gc,
) )
} }
@ -126,6 +127,7 @@ impl ExtendableMessageEvent {
scope: &GlobalScope, scope: &GlobalScope,
message: HandleValue, message: HandleValue,
ports: Vec<DomRoot<MessagePort>>, ports: Vec<DomRoot<MessagePort>>,
can_gc: CanGc,
) { ) {
let Extendablemessageevent = ExtendableMessageEvent::new( let Extendablemessageevent = ExtendableMessageEvent::new(
scope, scope,
@ -136,11 +138,12 @@ impl ExtendableMessageEvent {
DOMString::new(), DOMString::new(),
DOMString::new(), DOMString::new(),
ports, ports,
can_gc,
); );
Extendablemessageevent.upcast::<Event>().fire(target); Extendablemessageevent.upcast::<Event>().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 init = ExtendableMessageEventBinding::ExtendableMessageEventInit::empty();
let ExtendableMsgEvent = ExtendableMessageEvent::new( let ExtendableMsgEvent = ExtendableMessageEvent::new(
scope, scope,
@ -151,6 +154,7 @@ impl ExtendableMessageEvent {
init.origin.clone(), init.origin.clone(),
init.lastEventId.clone(), init.lastEventId.clone(),
init.ports.clone(), init.ports.clone(),
can_gc,
); );
ExtendableMsgEvent.upcast::<Event>().fire(target); ExtendableMsgEvent.upcast::<Event>().fire(target);
} }

View file

@ -143,7 +143,7 @@ impl GPUMethods for GPU {
} }
impl AsyncWGPUListener for GPU { impl AsyncWGPUListener for GPU {
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>, _can_gc: CanGc) { fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>, can_gc: CanGc) {
match response { match response {
WebGPUResponse::Adapter(Ok(adapter)) => { WebGPUResponse::Adapter(Ok(adapter)) => {
let adapter = GPUAdapter::new( let adapter = GPUAdapter::new(
@ -158,6 +158,7 @@ impl AsyncWGPUListener for GPU {
adapter.limits, adapter.limits,
adapter.adapter_info, adapter.adapter_info,
adapter.adapter_id, adapter.adapter_id,
can_gc,
); );
promise.resolve_native(&adapter); promise.resolve_native(&adapter);
}, },

View file

@ -77,8 +77,9 @@ impl GPUAdapter {
limits: wgt::Limits, limits: wgt::Limits,
info: wgt::AdapterInfo, info: wgt::AdapterInfo,
adapter: WebGPUAdapter, adapter: WebGPUAdapter,
can_gc: CanGc,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
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 limits = GPUSupportedLimits::new(global, limits);
let info = GPUAdapterInfo::new(global, info); let info = GPUAdapterInfo::new(global, info);
reflect_dom_object( reflect_dom_object(
@ -195,7 +196,7 @@ impl GPUAdapterMethods for GPUAdapter {
} }
impl AsyncWGPUListener for GPUAdapter { impl AsyncWGPUListener for GPUAdapter {
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>, _can_gc: CanGc) { fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>, can_gc: CanGc) {
match response { match response {
WebGPUResponse::Device((device_id, queue_id, Ok(descriptor))) => { WebGPUResponse::Device((device_id, queue_id, Ok(descriptor))) => {
let device = GPUDevice::new( let device = GPUDevice::new(
@ -208,6 +209,7 @@ impl AsyncWGPUListener for GPUAdapter {
device_id, device_id,
queue_id, queue_id,
descriptor.label.unwrap_or_default(), descriptor.label.unwrap_or_default(),
can_gc,
); );
self.global().add_gpu_device(&device); self.global().add_gpu_device(&device);
promise.resolve_native(&device); promise.resolve_native(&device);
@ -231,6 +233,7 @@ impl AsyncWGPUListener for GPUAdapter {
device_id, device_id,
queue_id, queue_id,
String::new(), String::new(),
can_gc,
); );
device.lose(GPUDeviceLostReason::Unknown, e.to_string()); device.lose(GPUDeviceLostReason::Unknown, e.to_string());
promise.resolve_native(&device); promise.resolve_native(&device);

View file

@ -148,10 +148,11 @@ impl GPUDevice {
device: webgpu::WebGPUDevice, device: webgpu::WebGPUDevice,
queue: webgpu::WebGPUQueue, queue: webgpu::WebGPUQueue,
label: String, label: String,
can_gc: CanGc,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
let queue = GPUQueue::new(global, channel.clone(), queue); let queue = GPUQueue::new(global, channel.clone(), queue);
let limits = GPUSupportedLimits::new(global, limits); 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 lost_promise = Promise::new(global);
let device = reflect_dom_object( let device = reflect_dom_object(
Box::new(GPUDevice::new_inherited( Box::new(GPUDevice::new_inherited(

View file

@ -50,6 +50,7 @@ impl GPUSupportedFeatures {
global: &GlobalScope, global: &GlobalScope,
proto: Option<HandleObject>, proto: Option<HandleObject>,
features: Features, features: Features,
can_gc: CanGc,
) -> DomRoot<GPUSupportedFeatures> { ) -> DomRoot<GPUSupportedFeatures> {
let mut set = IndexSet::new(); let mut set = IndexSet::new();
if features.contains(Features::DEPTH_CLIP_CONTROL) { if features.contains(Features::DEPTH_CLIP_CONTROL) {
@ -103,7 +104,7 @@ impl GPUSupportedFeatures {
}), }),
global, global,
proto, proto,
CanGc::note(), can_gc,
) )
} }
@ -112,8 +113,9 @@ impl GPUSupportedFeatures {
global: &GlobalScope, global: &GlobalScope,
proto: Option<HandleObject>, proto: Option<HandleObject>,
features: Features, features: Features,
can_gc: CanGc,
) -> Fallible<DomRoot<GPUSupportedFeatures>> { ) -> Fallible<DomRoot<GPUSupportedFeatures>> {
Ok(GPUSupportedFeatures::new(global, proto, features)) Ok(GPUSupportedFeatures::new(global, proto, features, can_gc))
} }
} }

View file

@ -184,8 +184,9 @@ impl PannerNode {
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &PannerOptions, options: &PannerOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<PannerNode>> { ) -> Fallible<DomRoot<PannerNode>> {
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)] #[allow(crown::unrooted_must_root)]

View file

@ -70,8 +70,9 @@ impl PerformanceObserver {
global: &GlobalScope, global: &GlobalScope,
callback: Rc<PerformanceObserverCallback>, callback: Rc<PerformanceObserverCallback>,
entries: DOMPerformanceEntryList, entries: DOMPerformanceEntryList,
can_gc: CanGc,
) -> DomRoot<PerformanceObserver> { ) -> DomRoot<PerformanceObserver> {
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)] #[allow(crown::unrooted_must_root)]

View file

@ -191,8 +191,8 @@ impl WorkerEventLoopMethods for ServiceWorkerGlobalScope {
&self.task_queue &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) self.handle_mixed_message(event, can_gc)
} }
fn handle_worker_post_event(&self, _worker: &TrustedWorkerAddress) -> Option<AutoWorkerReset> { fn handle_worker_post_event(&self, _worker: &TrustedWorkerAddress) -> Option<AutoWorkerReset> {
@ -411,7 +411,7 @@ impl ServiceWorkerGlobalScope {
.expect("Thread spawning failed") .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 { match msg {
MixedMessage::Devtools(msg) => match msg { MixedMessage::Devtools(msg) => match msg {
DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) => { DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) => {
@ -423,7 +423,7 @@ impl ServiceWorkerGlobalScope {
_ => debug!("got an unusable devtools control message inside the worker!"), _ => debug!("got an unusable devtools control message inside the worker!"),
}, },
MixedMessage::ServiceWorker(msg) => { MixedMessage::ServiceWorker(msg) => {
self.handle_script_event(msg); self.handle_script_event(msg, can_gc);
}, },
MixedMessage::Control(ServiceWorkerControlMsg::Exit) => { MixedMessage::Control(ServiceWorkerControlMsg::Exit) => {
return false; return false;
@ -437,7 +437,7 @@ impl ServiceWorkerGlobalScope {
false false
} }
fn handle_script_event(&self, msg: ServiceWorkerScriptMsg) { fn handle_script_event(&self, msg: ServiceWorkerScriptMsg, can_gc: CanGc) {
use self::ServiceWorkerScriptMsg::*; use self::ServiceWorkerScriptMsg::*;
match msg { match msg {
@ -453,9 +453,10 @@ impl ServiceWorkerGlobalScope {
scope.upcast(), scope.upcast(),
message.handle(), message.handle(),
ports, ports,
can_gc,
); );
} else { } else {
ExtendableMessageEvent::dispatch_error(target, scope.upcast()); ExtendableMessageEvent::dispatch_error(target, scope.upcast(), can_gc);
} }
}, },
CommonWorker(WorkerScriptMsg::Common(msg)) => { CommonWorker(WorkerScriptMsg::Common(msg)) => {