mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
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:
parent
bd8006afc5
commit
a55f9a37ec
9 changed files with 58 additions and 28 deletions
|
@ -292,10 +292,13 @@ impl AudioContextMethods for AudioContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://webaudio.github.io/web-audio-api/#dom-audiocontext-createmediastreamdestination>
|
/// <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 global = self.global();
|
||||||
let window = global.as_window();
|
let window = global.as_window();
|
||||||
MediaStreamAudioDestinationNode::new(window, self, &AudioNodeOptions::empty())
|
MediaStreamAudioDestinationNode::new(window, self, &AudioNodeOptions::empty(), can_gc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ DOMInterfaces = {
|
||||||
|
|
||||||
'AudioContext': {
|
'AudioContext': {
|
||||||
'inRealms': ['Close', 'Suspend'],
|
'inRealms': ['Close', 'Suspend'],
|
||||||
|
'canGc':['CreateMediaStreamDestination'],
|
||||||
},
|
},
|
||||||
|
|
||||||
'BaseAudioContext': {
|
'BaseAudioContext': {
|
||||||
|
@ -28,6 +29,7 @@ DOMInterfaces = {
|
||||||
|
|
||||||
'Blob': {
|
'Blob': {
|
||||||
'weakReferenceable': True,
|
'weakReferenceable': True,
|
||||||
|
'canGc': ['Slice'],
|
||||||
},
|
},
|
||||||
|
|
||||||
'Bluetooth': {
|
'Bluetooth': {
|
||||||
|
@ -67,7 +69,7 @@ DOMInterfaces = {
|
||||||
},
|
},
|
||||||
|
|
||||||
'Document': {
|
'Document': {
|
||||||
'canGc': ['Close', 'CreateElement', 'CreateElementNS', 'ImportNode', 'SetTitle', 'Write', 'Writeln'],
|
'canGc': ['Close', 'CreateElement', 'CreateElementNS', 'ImportNode', 'SetTitle', 'Write', 'Writeln', 'CreateEvent', 'CreateRange', 'Open', 'Open_'],
|
||||||
},
|
},
|
||||||
|
|
||||||
'DynamicModuleOwner': {
|
'DynamicModuleOwner': {
|
||||||
|
@ -117,14 +119,23 @@ DOMInterfaces = {
|
||||||
'inRealms': ['Play'],
|
'inRealms': ['Play'],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'HTMLCanvasElement': {
|
||||||
|
'canGc': ['CaptureStream'],
|
||||||
|
},
|
||||||
|
|
||||||
'HTMLTemplateElement': {
|
'HTMLTemplateElement': {
|
||||||
'canGc': ['Content'],
|
'canGc': ['Content'],
|
||||||
},
|
},
|
||||||
|
|
||||||
'MediaDevices': {
|
'MediaDevices': {
|
||||||
|
'canGc': ['GetUserMedia'],
|
||||||
'inRealms': ['GetUserMedia', 'GetClientRects', 'GetBoundingClientRect'],
|
'inRealms': ['GetUserMedia', 'GetClientRects', 'GetBoundingClientRect'],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'MediaStream': {
|
||||||
|
'canGc': ['Clone'],
|
||||||
|
},
|
||||||
|
|
||||||
'MediaQueryList': {
|
'MediaQueryList': {
|
||||||
'weakReferenceable': True,
|
'weakReferenceable': True,
|
||||||
},
|
},
|
||||||
|
|
|
@ -246,12 +246,13 @@ impl BlobMethods for Blob {
|
||||||
start: Option<i64>,
|
start: Option<i64>,
|
||||||
end: Option<i64>,
|
end: Option<i64>,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> DomRoot<Blob> {
|
) -> DomRoot<Blob> {
|
||||||
let type_string =
|
let type_string =
|
||||||
normalize_type_string(content_type.unwrap_or(DOMString::from("")).as_ref());
|
normalize_type_string(content_type.unwrap_or(DOMString::from("")).as_ref());
|
||||||
let rel_pos = RelativePos::from_opts(start, end);
|
let rel_pos = RelativePos::from_opts(start, end);
|
||||||
let blob_impl = BlobImpl::new_sliced(rel_pos, self.blob_id, type_string);
|
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
|
// https://w3c.github.io/FileAPI/#text-method-algo
|
||||||
|
|
|
@ -36,8 +36,8 @@ impl CustomEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_uninitialized(global: &GlobalScope) -> DomRoot<CustomEvent> {
|
pub fn new_uninitialized(global: &GlobalScope, can_gc: CanGc) -> DomRoot<CustomEvent> {
|
||||||
Self::new_uninitialized_with_proto(global, None, CanGc::note())
|
Self::new_uninitialized_with_proto(global, None, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_uninitialized_with_proto(
|
fn new_uninitialized_with_proto(
|
||||||
|
|
|
@ -4581,7 +4581,7 @@ impl DocumentMethods for Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-createevent
|
// 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();
|
interface.make_ascii_lowercase();
|
||||||
match &*interface {
|
match &*interface {
|
||||||
"beforeunloadevent" => Ok(DomRoot::upcast(BeforeUnloadEvent::new_uninitialized(
|
"beforeunloadevent" => Ok(DomRoot::upcast(BeforeUnloadEvent::new_uninitialized(
|
||||||
|
@ -4592,13 +4592,13 @@ impl DocumentMethods for Document {
|
||||||
)),
|
)),
|
||||||
"customevent" => Ok(DomRoot::upcast(CustomEvent::new_uninitialized(
|
"customevent" => Ok(DomRoot::upcast(CustomEvent::new_uninitialized(
|
||||||
self.window.upcast(),
|
self.window.upcast(),
|
||||||
|
can_gc,
|
||||||
))),
|
))),
|
||||||
// FIXME(#25136): devicemotionevent, deviceorientationevent
|
// FIXME(#25136): devicemotionevent, deviceorientationevent
|
||||||
// FIXME(#7529): dragevent
|
// FIXME(#7529): dragevent
|
||||||
"events" | "event" | "htmlevents" | "svgevents" => Ok(Event::new_uninitialized(
|
"events" | "event" | "htmlevents" | "svgevents" => {
|
||||||
self.window.upcast(),
|
Ok(Event::new_uninitialized(self.window.upcast(), can_gc))
|
||||||
CanGc::note(),
|
},
|
||||||
)),
|
|
||||||
"focusevent" => Ok(DomRoot::upcast(FocusEvent::new_uninitialized(&self.window))),
|
"focusevent" => Ok(DomRoot::upcast(FocusEvent::new_uninitialized(&self.window))),
|
||||||
"hashchangeevent" => Ok(DomRoot::upcast(HashChangeEvent::new_uninitialized(
|
"hashchangeevent" => Ok(DomRoot::upcast(HashChangeEvent::new_uninitialized(
|
||||||
&self.window,
|
&self.window,
|
||||||
|
@ -4640,8 +4640,8 @@ impl DocumentMethods for Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-createrange
|
// https://dom.spec.whatwg.org/#dom-document-createrange
|
||||||
fn CreateRange(&self) -> DomRoot<Range> {
|
fn CreateRange(&self, can_gc: CanGc) -> DomRoot<Range> {
|
||||||
Range::new_with_doc(self, None, CanGc::note())
|
Range::new_with_doc(self, None, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-createnodeiteratorroot-whattoshow-filter
|
// https://dom.spec.whatwg.org/#dom-document-createnodeiteratorroot-whattoshow-filter
|
||||||
|
@ -5188,6 +5188,7 @@ impl DocumentMethods for Document {
|
||||||
&self,
|
&self,
|
||||||
_unused1: Option<DOMString>,
|
_unused1: Option<DOMString>,
|
||||||
_unused2: Option<DOMString>,
|
_unused2: Option<DOMString>,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> Fallible<DomRoot<Document>> {
|
) -> Fallible<DomRoot<Document>> {
|
||||||
// Step 1
|
// Step 1
|
||||||
if !self.is_html_document() {
|
if !self.is_html_document() {
|
||||||
|
@ -5238,7 +5239,7 @@ impl DocumentMethods for Document {
|
||||||
if self.has_browsing_context() {
|
if self.has_browsing_context() {
|
||||||
// spec says "stop document loading",
|
// spec says "stop document loading",
|
||||||
// which is a process that does more than just abort
|
// which is a process that does more than just abort
|
||||||
self.abort(CanGc::note());
|
self.abort(can_gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 9
|
// Step 9
|
||||||
|
@ -5305,6 +5306,7 @@ impl DocumentMethods for Document {
|
||||||
url: USVString,
|
url: USVString,
|
||||||
target: DOMString,
|
target: DOMString,
|
||||||
features: DOMString,
|
features: DOMString,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> Fallible<Option<DomRoot<WindowProxy>>> {
|
) -> Fallible<Option<DomRoot<WindowProxy>>> {
|
||||||
self.browsing_context()
|
self.browsing_context()
|
||||||
.ok_or(Error::InvalidAccess)?
|
.ok_or(Error::InvalidAccess)?
|
||||||
|
@ -5341,7 +5343,7 @@ impl DocumentMethods for Document {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
// Step 5.
|
// Step 5.
|
||||||
self.Open(None, None)?;
|
self.Open(None, None, can_gc)?;
|
||||||
self.get_current_parser().unwrap()
|
self.get_current_parser().unwrap()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,7 +48,7 @@ use crate::dom::node::{window_from_node, Node};
|
||||||
use crate::dom::virtualmethods::VirtualMethods;
|
use crate::dom::virtualmethods::VirtualMethods;
|
||||||
use crate::dom::webgl2renderingcontext::WebGL2RenderingContext;
|
use crate::dom::webgl2renderingcontext::WebGL2RenderingContext;
|
||||||
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
|
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
|
||||||
use crate::script_runtime::JSContext;
|
use crate::script_runtime::{CanGc, JSContext};
|
||||||
|
|
||||||
const DEFAULT_WIDTH: u32 = 300;
|
const DEFAULT_WIDTH: u32 = 300;
|
||||||
const DEFAULT_HEIGHT: u32 = 150;
|
const DEFAULT_HEIGHT: u32 = 150;
|
||||||
|
@ -424,9 +424,13 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://w3c.github.io/mediacapture-fromelement/#dom-htmlcanvaselement-capturestream>
|
/// <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 global = self.global();
|
||||||
let stream = MediaStream::new(&global);
|
let stream = MediaStream::new(&global, can_gc);
|
||||||
let track = MediaStreamTrack::new(&global, MediaStreamId::new(), MediaStreamType::Video);
|
let track = MediaStreamTrack::new(&global, MediaStreamId::new(), MediaStreamType::Video);
|
||||||
stream.AddTrack(&track);
|
stream.AddTrack(&track);
|
||||||
stream
|
stream
|
||||||
|
|
|
@ -25,6 +25,7 @@ use crate::dom::mediastream::MediaStream;
|
||||||
use crate::dom::mediastreamtrack::MediaStreamTrack;
|
use crate::dom::mediastreamtrack::MediaStreamTrack;
|
||||||
use crate::dom::promise::Promise;
|
use crate::dom::promise::Promise;
|
||||||
use crate::realms::{AlreadyInRealm, InRealm};
|
use crate::realms::{AlreadyInRealm, InRealm};
|
||||||
|
use crate::script_runtime::CanGc;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct MediaDevices {
|
pub struct MediaDevices {
|
||||||
|
@ -46,10 +47,15 @@ impl MediaDevices {
|
||||||
impl MediaDevicesMethods for MediaDevices {
|
impl MediaDevicesMethods for MediaDevices {
|
||||||
/// <https://w3c.github.io/mediacapture-main/#dom-mediadevices-getusermedia>
|
/// <https://w3c.github.io/mediacapture-main/#dom-mediadevices-getusermedia>
|
||||||
#[allow(unsafe_code)]
|
#[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 p = Promise::new_in_current_realm(comp);
|
||||||
let media = ServoMedia::get().unwrap();
|
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(constraints) = convert_constraints(&constraints.audio) {
|
||||||
if let Some(audio) = media.create_audioinput_stream(constraints) {
|
if let Some(audio) = media.create_audioinput_stream(constraints) {
|
||||||
let track = MediaStreamTrack::new(&self.global(), audio, MediaStreamType::Audio);
|
let track = MediaStreamTrack::new(&self.global(), audio, MediaStreamType::Audio);
|
||||||
|
|
|
@ -33,8 +33,8 @@ impl MediaStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(global: &GlobalScope) -> DomRoot<MediaStream> {
|
pub fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot<MediaStream> {
|
||||||
Self::new_with_proto(global, None, CanGc::note())
|
Self::new_with_proto(global, None, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_with_proto(
|
fn new_with_proto(
|
||||||
|
@ -54,8 +54,9 @@ impl MediaStream {
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
id: MediaStreamId,
|
id: MediaStreamId,
|
||||||
ty: MediaStreamType,
|
ty: MediaStreamType,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> DomRoot<MediaStream> {
|
) -> DomRoot<MediaStream> {
|
||||||
let this = Self::new(global);
|
let this = Self::new(global, can_gc);
|
||||||
let track = MediaStreamTrack::new(global, id, ty);
|
let track = MediaStreamTrack::new(global, id, ty);
|
||||||
this.AddTrack(&track);
|
this.AddTrack(&track);
|
||||||
this
|
this
|
||||||
|
@ -160,8 +161,8 @@ impl MediaStreamMethods for MediaStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://w3c.github.io/mediacapture-main/#dom-mediastream-clone>
|
/// <https://w3c.github.io/mediacapture-main/#dom-mediastream-clone>
|
||||||
fn Clone(&self) -> DomRoot<MediaStream> {
|
fn Clone(&self, can_gc: CanGc) -> DomRoot<MediaStream> {
|
||||||
self.clone_with_proto(None, CanGc::note())
|
self.clone_with_proto(None, can_gc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,11 @@ impl MediaStreamAudioDestinationNode {
|
||||||
pub fn new_inherited(
|
pub fn new_inherited(
|
||||||
context: &AudioContext,
|
context: &AudioContext,
|
||||||
options: &AudioNodeOptions,
|
options: &AudioNodeOptions,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> Fallible<MediaStreamAudioDestinationNode> {
|
) -> Fallible<MediaStreamAudioDestinationNode> {
|
||||||
let media = ServoMedia::get().unwrap();
|
let media = ServoMedia::get().unwrap();
|
||||||
let (socket, id) = media.create_stream_and_socket(MediaStreamType::Audio);
|
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(
|
let node_options = options.unwrap_or(
|
||||||
2,
|
2,
|
||||||
ChannelCountMode::Explicit,
|
ChannelCountMode::Explicit,
|
||||||
|
@ -59,8 +60,9 @@ impl MediaStreamAudioDestinationNode {
|
||||||
window: &Window,
|
window: &Window,
|
||||||
context: &AudioContext,
|
context: &AudioContext,
|
||||||
options: &AudioNodeOptions,
|
options: &AudioNodeOptions,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> Fallible<DomRoot<MediaStreamAudioDestinationNode>> {
|
) -> 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)]
|
#[allow(crown::unrooted_must_root)]
|
||||||
|
@ -71,7 +73,7 @@ impl MediaStreamAudioDestinationNode {
|
||||||
options: &AudioNodeOptions,
|
options: &AudioNodeOptions,
|
||||||
can_gc: CanGc,
|
can_gc: CanGc,
|
||||||
) -> Fallible<DomRoot<MediaStreamAudioDestinationNode>> {
|
) -> 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(
|
Ok(reflect_dom_object_with_proto(
|
||||||
Box::new(node),
|
Box::new(node),
|
||||||
window,
|
window,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue