CanGc fixes starting from blob.rs, mediastream.rs, custom_event.rs (#33820)

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-10-12 22:47:47 +05:30 committed by GitHub
parent bd8006afc5
commit a55f9a37ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 58 additions and 28 deletions

View file

@ -292,10 +292,13 @@ impl AudioContextMethods for AudioContext {
}
/// <https://webaudio.github.io/web-audio-api/#dom-audiocontext-createmediastreamdestination>
fn CreateMediaStreamDestination(&self) -> Fallible<DomRoot<MediaStreamAudioDestinationNode>> {
fn CreateMediaStreamDestination(
&self,
can_gc: CanGc,
) -> Fallible<DomRoot<MediaStreamAudioDestinationNode>> {
let global = self.global();
let window = global.as_window();
MediaStreamAudioDestinationNode::new(window, self, &AudioNodeOptions::empty())
MediaStreamAudioDestinationNode::new(window, self, &AudioNodeOptions::empty(), can_gc)
}
}

View file

@ -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,
},

View file

@ -246,12 +246,13 @@ impl BlobMethods for Blob {
start: Option<i64>,
end: Option<i64>,
content_type: Option<DOMString>,
can_gc: CanGc,
) -> DomRoot<Blob> {
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

View file

@ -36,8 +36,8 @@ impl CustomEvent {
}
}
pub fn new_uninitialized(global: &GlobalScope) -> DomRoot<CustomEvent> {
Self::new_uninitialized_with_proto(global, None, CanGc::note())
pub fn new_uninitialized(global: &GlobalScope, can_gc: CanGc) -> DomRoot<CustomEvent> {
Self::new_uninitialized_with_proto(global, None, can_gc)
}
fn new_uninitialized_with_proto(

View file

@ -4581,7 +4581,7 @@ impl DocumentMethods for Document {
}
// https://dom.spec.whatwg.org/#dom-document-createevent
fn CreateEvent(&self, mut interface: DOMString) -> Fallible<DomRoot<Event>> {
fn CreateEvent(&self, mut interface: DOMString, can_gc: CanGc) -> Fallible<DomRoot<Event>> {
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> {
Range::new_with_doc(self, None, CanGc::note())
fn CreateRange(&self, can_gc: CanGc) -> DomRoot<Range> {
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<DOMString>,
_unused2: Option<DOMString>,
can_gc: CanGc,
) -> Fallible<DomRoot<Document>> {
// 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<Option<DomRoot<WindowProxy>>> {
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()
},
};

View file

@ -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 {
}
/// <https://w3c.github.io/mediacapture-fromelement/#dom-htmlcanvaselement-capturestream>
fn CaptureStream(&self, _frame_request_rate: Option<Finite<f64>>) -> DomRoot<MediaStream> {
fn CaptureStream(
&self,
_frame_request_rate: Option<Finite<f64>>,
can_gc: CanGc,
) -> DomRoot<MediaStream> {
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

View file

@ -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 {
/// <https://w3c.github.io/mediacapture-main/#dom-mediadevices-getusermedia>
#[allow(unsafe_code)]
fn GetUserMedia(&self, constraints: &MediaStreamConstraints, comp: InRealm) -> Rc<Promise> {
fn GetUserMedia(
&self,
constraints: &MediaStreamConstraints,
comp: InRealm,
can_gc: CanGc,
) -> Rc<Promise> {
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);

View file

@ -33,8 +33,8 @@ impl MediaStream {
}
}
pub fn new(global: &GlobalScope) -> DomRoot<MediaStream> {
Self::new_with_proto(global, None, CanGc::note())
pub fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot<MediaStream> {
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<MediaStream> {
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 {
}
/// <https://w3c.github.io/mediacapture-main/#dom-mediastream-clone>
fn Clone(&self) -> DomRoot<MediaStream> {
self.clone_with_proto(None, CanGc::note())
fn Clone(&self, can_gc: CanGc) -> DomRoot<MediaStream> {
self.clone_with_proto(None, can_gc)
}
}

View file

@ -33,10 +33,11 @@ impl MediaStreamAudioDestinationNode {
pub fn new_inherited(
context: &AudioContext,
options: &AudioNodeOptions,
can_gc: CanGc,
) -> Fallible<MediaStreamAudioDestinationNode> {
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<DomRoot<MediaStreamAudioDestinationNode>> {
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<DomRoot<MediaStreamAudioDestinationNode>> {
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,