diff --git a/components/script/dom/audiocontext.rs b/components/script/dom/audiocontext.rs index 14e71e1de94..62b574d10b7 100644 --- a/components/script/dom/audiocontext.rs +++ b/components/script/dom/audiocontext.rs @@ -292,10 +292,13 @@ impl AudioContextMethods for AudioContext { } /// - fn CreateMediaStreamDestination(&self) -> Fallible> { + fn CreateMediaStreamDestination( + &self, + can_gc: CanGc, + ) -> Fallible> { let global = self.global(); let window = global.as_window(); - MediaStreamAudioDestinationNode::new(window, self, &AudioNodeOptions::empty()) + MediaStreamAudioDestinationNode::new(window, self, &AudioNodeOptions::empty(), can_gc) } } diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index 3553583b53c..5ac224923b1 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -20,6 +20,7 @@ DOMInterfaces = { 'AudioContext': { 'inRealms': ['Close', 'Suspend'], + 'canGc':['CreateMediaStreamDestination'], }, 'BaseAudioContext': { @@ -28,6 +29,7 @@ DOMInterfaces = { 'Blob': { 'weakReferenceable': True, + 'canGc': ['Slice'], }, 'Bluetooth': { @@ -67,7 +69,7 @@ DOMInterfaces = { }, 'Document': { - 'canGc': ['Close', 'CreateElement', 'CreateElementNS', 'ImportNode', 'SetTitle', 'Write', 'Writeln'], + 'canGc': ['Close', 'CreateElement', 'CreateElementNS', 'ImportNode', 'SetTitle', 'Write', 'Writeln', 'CreateEvent', 'CreateRange', 'Open', 'Open_'], }, 'DynamicModuleOwner': { @@ -117,14 +119,23 @@ DOMInterfaces = { 'inRealms': ['Play'], }, +'HTMLCanvasElement': { + 'canGc': ['CaptureStream'], +}, + 'HTMLTemplateElement': { 'canGc': ['Content'], }, 'MediaDevices': { + 'canGc': ['GetUserMedia'], 'inRealms': ['GetUserMedia', 'GetClientRects', 'GetBoundingClientRect'], }, +'MediaStream': { + 'canGc': ['Clone'], +}, + 'MediaQueryList': { 'weakReferenceable': True, }, diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index 7f0307a5a2d..da62954effd 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -246,12 +246,13 @@ impl BlobMethods for Blob { start: Option, end: Option, content_type: Option, + can_gc: CanGc, ) -> DomRoot { let type_string = normalize_type_string(content_type.unwrap_or(DOMString::from("")).as_ref()); let rel_pos = RelativePos::from_opts(start, end); let blob_impl = BlobImpl::new_sliced(rel_pos, self.blob_id, type_string); - Blob::new(&self.global(), blob_impl, CanGc::note()) + Blob::new(&self.global(), blob_impl, can_gc) } // https://w3c.github.io/FileAPI/#text-method-algo diff --git a/components/script/dom/customevent.rs b/components/script/dom/customevent.rs index cecf28c29ae..cb99468e00e 100644 --- a/components/script/dom/customevent.rs +++ b/components/script/dom/customevent.rs @@ -36,8 +36,8 @@ impl CustomEvent { } } - pub fn new_uninitialized(global: &GlobalScope) -> DomRoot { - Self::new_uninitialized_with_proto(global, None, CanGc::note()) + pub fn new_uninitialized(global: &GlobalScope, can_gc: CanGc) -> DomRoot { + Self::new_uninitialized_with_proto(global, None, can_gc) } fn new_uninitialized_with_proto( diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index e9c268d5555..3412913d9d3 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -4581,7 +4581,7 @@ impl DocumentMethods for Document { } // https://dom.spec.whatwg.org/#dom-document-createevent - fn CreateEvent(&self, mut interface: DOMString) -> Fallible> { + fn CreateEvent(&self, mut interface: DOMString, can_gc: CanGc) -> Fallible> { interface.make_ascii_lowercase(); match &*interface { "beforeunloadevent" => Ok(DomRoot::upcast(BeforeUnloadEvent::new_uninitialized( @@ -4592,13 +4592,13 @@ impl DocumentMethods for Document { )), "customevent" => Ok(DomRoot::upcast(CustomEvent::new_uninitialized( self.window.upcast(), + can_gc, ))), // FIXME(#25136): devicemotionevent, deviceorientationevent // FIXME(#7529): dragevent - "events" | "event" | "htmlevents" | "svgevents" => Ok(Event::new_uninitialized( - self.window.upcast(), - CanGc::note(), - )), + "events" | "event" | "htmlevents" | "svgevents" => { + Ok(Event::new_uninitialized(self.window.upcast(), can_gc)) + }, "focusevent" => Ok(DomRoot::upcast(FocusEvent::new_uninitialized(&self.window))), "hashchangeevent" => Ok(DomRoot::upcast(HashChangeEvent::new_uninitialized( &self.window, @@ -4640,8 +4640,8 @@ impl DocumentMethods for Document { } // https://dom.spec.whatwg.org/#dom-document-createrange - fn CreateRange(&self) -> DomRoot { - Range::new_with_doc(self, None, CanGc::note()) + fn CreateRange(&self, can_gc: CanGc) -> DomRoot { + Range::new_with_doc(self, None, can_gc) } // https://dom.spec.whatwg.org/#dom-document-createnodeiteratorroot-whattoshow-filter @@ -5188,6 +5188,7 @@ impl DocumentMethods for Document { &self, _unused1: Option, _unused2: Option, + can_gc: CanGc, ) -> Fallible> { // Step 1 if !self.is_html_document() { @@ -5238,7 +5239,7 @@ impl DocumentMethods for Document { if self.has_browsing_context() { // spec says "stop document loading", // which is a process that does more than just abort - self.abort(CanGc::note()); + self.abort(can_gc); } // Step 9 @@ -5305,6 +5306,7 @@ impl DocumentMethods for Document { url: USVString, target: DOMString, features: DOMString, + can_gc: CanGc, ) -> Fallible>> { self.browsing_context() .ok_or(Error::InvalidAccess)? @@ -5341,7 +5343,7 @@ impl DocumentMethods for Document { return Ok(()); } // Step 5. - self.Open(None, None)?; + self.Open(None, None, can_gc)?; self.get_current_parser().unwrap() }, }; diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index b8fb33d07fc..98aa03f9451 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -48,7 +48,7 @@ use crate::dom::node::{window_from_node, Node}; use crate::dom::virtualmethods::VirtualMethods; use crate::dom::webgl2renderingcontext::WebGL2RenderingContext; use crate::dom::webglrenderingcontext::WebGLRenderingContext; -use crate::script_runtime::JSContext; +use crate::script_runtime::{CanGc, JSContext}; const DEFAULT_WIDTH: u32 = 300; const DEFAULT_HEIGHT: u32 = 150; @@ -424,9 +424,13 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement { } /// - fn CaptureStream(&self, _frame_request_rate: Option>) -> DomRoot { + fn CaptureStream( + &self, + _frame_request_rate: Option>, + can_gc: CanGc, + ) -> DomRoot { let global = self.global(); - let stream = MediaStream::new(&global); + let stream = MediaStream::new(&global, can_gc); let track = MediaStreamTrack::new(&global, MediaStreamId::new(), MediaStreamType::Video); stream.AddTrack(&track); stream diff --git a/components/script/dom/mediadevices.rs b/components/script/dom/mediadevices.rs index 1da57905dae..4207542d8c7 100644 --- a/components/script/dom/mediadevices.rs +++ b/components/script/dom/mediadevices.rs @@ -25,6 +25,7 @@ use crate::dom::mediastream::MediaStream; use crate::dom::mediastreamtrack::MediaStreamTrack; use crate::dom::promise::Promise; use crate::realms::{AlreadyInRealm, InRealm}; +use crate::script_runtime::CanGc; #[dom_struct] pub struct MediaDevices { @@ -46,10 +47,15 @@ impl MediaDevices { impl MediaDevicesMethods for MediaDevices { /// #[allow(unsafe_code)] - fn GetUserMedia(&self, constraints: &MediaStreamConstraints, comp: InRealm) -> Rc { + fn GetUserMedia( + &self, + constraints: &MediaStreamConstraints, + comp: InRealm, + can_gc: CanGc, + ) -> Rc { let p = Promise::new_in_current_realm(comp); let media = ServoMedia::get().unwrap(); - let stream = MediaStream::new(&self.global()); + let stream = MediaStream::new(&self.global(), can_gc); if let Some(constraints) = convert_constraints(&constraints.audio) { if let Some(audio) = media.create_audioinput_stream(constraints) { let track = MediaStreamTrack::new(&self.global(), audio, MediaStreamType::Audio); diff --git a/components/script/dom/mediastream.rs b/components/script/dom/mediastream.rs index 4834eed12b7..172bafe508c 100644 --- a/components/script/dom/mediastream.rs +++ b/components/script/dom/mediastream.rs @@ -33,8 +33,8 @@ impl MediaStream { } } - pub fn new(global: &GlobalScope) -> DomRoot { - Self::new_with_proto(global, None, CanGc::note()) + pub fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot { + Self::new_with_proto(global, None, can_gc) } fn new_with_proto( @@ -54,8 +54,9 @@ impl MediaStream { global: &GlobalScope, id: MediaStreamId, ty: MediaStreamType, + can_gc: CanGc, ) -> DomRoot { - let this = Self::new(global); + let this = Self::new(global, can_gc); let track = MediaStreamTrack::new(global, id, ty); this.AddTrack(&track); this @@ -160,8 +161,8 @@ impl MediaStreamMethods for MediaStream { } /// - fn Clone(&self) -> DomRoot { - self.clone_with_proto(None, CanGc::note()) + fn Clone(&self, can_gc: CanGc) -> DomRoot { + self.clone_with_proto(None, can_gc) } } diff --git a/components/script/dom/mediastreamaudiodestinationnode.rs b/components/script/dom/mediastreamaudiodestinationnode.rs index 5e8288c39a3..3c1004ab52c 100644 --- a/components/script/dom/mediastreamaudiodestinationnode.rs +++ b/components/script/dom/mediastreamaudiodestinationnode.rs @@ -33,10 +33,11 @@ impl MediaStreamAudioDestinationNode { pub fn new_inherited( context: &AudioContext, options: &AudioNodeOptions, + can_gc: CanGc, ) -> Fallible { let media = ServoMedia::get().unwrap(); let (socket, id) = media.create_stream_and_socket(MediaStreamType::Audio); - let stream = MediaStream::new_single(&context.global(), id, MediaStreamType::Audio); + let stream = MediaStream::new_single(&context.global(), id, MediaStreamType::Audio, can_gc); let node_options = options.unwrap_or( 2, ChannelCountMode::Explicit, @@ -59,8 +60,9 @@ impl MediaStreamAudioDestinationNode { window: &Window, context: &AudioContext, options: &AudioNodeOptions, + 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)] @@ -71,7 +73,7 @@ impl MediaStreamAudioDestinationNode { options: &AudioNodeOptions, can_gc: CanGc, ) -> Fallible> { - let node = MediaStreamAudioDestinationNode::new_inherited(context, options)?; + let node = MediaStreamAudioDestinationNode::new_inherited(context, options, can_gc)?; Ok(reflect_dom_object_with_proto( Box::new(node), window,