More CanGc fixes (#33888)

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-10-18 01:06:42 +05:30 committed by GitHub
parent 720d632170
commit 9c893c7f4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 102 additions and 58 deletions

View file

@ -96,8 +96,9 @@ impl AnalyserNode {
window: &Window,
context: &BaseAudioContext,
options: &AnalyserOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<AnalyserNode>> {
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)]

View file

@ -100,8 +100,9 @@ impl AudioBufferSourceNode {
window: &Window,
context: &BaseAudioContext,
options: &AudioBufferSourceOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<AudioBufferSourceNode>> {
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)]

View file

@ -372,16 +372,22 @@ impl BaseAudioContextMethods for BaseAudioContext {
}
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createanalyser>
fn CreateAnalyser(&self) -> Fallible<DomRoot<AnalyserNode>> {
AnalyserNode::new(self.global().as_window(), self, &AnalyserOptions::empty())
fn CreateAnalyser(&self, can_gc: CanGc) -> Fallible<DomRoot<AnalyserNode>> {
AnalyserNode::new(
self.global().as_window(),
self,
&AnalyserOptions::empty(),
can_gc,
)
}
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbiquadfilter>
fn CreateBiquadFilter(&self) -> Fallible<DomRoot<BiquadFilterNode>> {
fn CreateBiquadFilter(&self, can_gc: CanGc) -> Fallible<DomRoot<BiquadFilterNode>> {
BiquadFilterNode::new(
self.global().as_window(),
self,
&BiquadFilterOptions::empty(),
can_gc,
)
}
@ -442,11 +448,12 @@ impl BaseAudioContextMethods for BaseAudioContext {
}
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffersource
fn CreateBufferSource(&self) -> Fallible<DomRoot<AudioBufferSourceNode>> {
fn CreateBufferSource(&self, can_gc: CanGc) -> Fallible<DomRoot<AudioBufferSourceNode>> {
AudioBufferSourceNode::new(
self.global().as_window(),
self,
&AudioBufferSourceOptions::empty(),
can_gc,
)
}

View file

@ -25,7 +25,7 @@ DOMInterfaces = {
'BaseAudioContext': {
'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'],
'canGc': ['CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter'],
'canGc': ['CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser'],
},
'Blob': {
@ -74,13 +74,16 @@ DOMInterfaces = {
},
'DOMQuad': {
'canGc': ['FromRect', 'FromQuad'],
'canGc': ['FromRect', 'FromQuad', 'GetBounds'],
},
'DOMPoint': {
'canGc': ['FromPoint'],
},
'DOMPointReadOnly': {
'canGc': ['FromPoint'],
},
'DOMMatrixReadOnly': {
'canGc': ['Multiply', 'Inverse', 'Scale', 'Translate', 'Rotate', 'RotateFromVector','FlipY', 'ScaleNonUniform', 'Scale3d', 'RotateAxisAngle', 'SkewX', 'SkewY', 'FlipX', 'TransformPoint', 'FromFloat32Array', 'FromFloat64Array','FromMatrix'],
@ -247,7 +250,7 @@ DOMInterfaces = {
},
'Window': {
'canGc': ['Stop'],
'canGc': ['Stop', 'Fetch'],
'inRealms': ['Fetch', 'GetOpener'],
},
@ -277,6 +280,18 @@ DOMInterfaces = {
'inRealms': ['RequestSession', 'SupportsSessionMode'],
},
'XRBoundedReferenceSpace': {
'canGc': ['BoundsGeometry'],
},
'XRRay': {
'canGc': ['Origin', 'Direction'],
},
'XRRigidTransform': {
'canGc': ['Position', 'Orientation'],
},
'SubtleCrypto': {
'inRealms': ['GenerateKey', 'ExportKey']
}

View file

@ -117,8 +117,9 @@ impl BiquadFilterNode {
window: &Window,
context: &BaseAudioContext,
options: &BiquadFilterOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<BiquadFilterNode>> {
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)]

View file

@ -45,17 +45,10 @@ impl CloseEvent {
wasClean: bool,
code: u16,
reason: DOMString,
can_gc: CanGc,
) -> DomRoot<CloseEvent> {
Self::new_with_proto(
global,
None,
type_,
bubbles,
cancelable,
wasClean,
code,
reason,
CanGc::note(),
global, None, type_, bubbles, cancelable, wasClean, code, reason, can_gc,
)
}

View file

@ -43,17 +43,10 @@ impl CompositionEvent {
view: Option<&Window>,
detail: i32,
data: DOMString,
can_gc: CanGc,
) -> DomRoot<CompositionEvent> {
Self::new_with_proto(
window,
None,
type_,
can_bubble,
cancelable,
view,
detail,
data,
CanGc::note(),
window, None, type_, can_bubble, cancelable, view, detail, data, can_gc,
)
}

View file

@ -1905,6 +1905,7 @@ impl Document {
pub fn dispatch_composition_event(
&self,
composition_event: ::keyboard_types::CompositionEvent,
can_gc: CanGc,
) {
// spec: https://w3c.github.io/uievents/#compositionstart
// spec: https://w3c.github.io/uievents/#compositionupdate
@ -1928,6 +1929,7 @@ impl Document {
Some(&self.window),
0,
DOMString::from(composition_event.data),
can_gc,
);
let event = compositionevent.upcast::<Event>();
event.fire(target);

View file

@ -37,8 +37,15 @@ impl DOMPointReadOnly {
}
}
pub fn new(global: &GlobalScope, x: f64, y: f64, z: f64, w: f64) -> DomRoot<DOMPointReadOnly> {
Self::new_with_proto(global, None, x, y, z, w, CanGc::note())
pub fn new(
global: &GlobalScope,
x: f64,
y: f64,
z: f64,
w: f64,
can_gc: CanGc,
) -> DomRoot<DOMPointReadOnly> {
Self::new_with_proto(global, None, x, y, z, w, can_gc)
}
fn new_with_proto(
@ -77,8 +84,8 @@ impl DOMPointReadOnlyMethods for DOMPointReadOnly {
}
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
fn FromPoint(global: &GlobalScope, init: &DOMPointInit) -> DomRoot<Self> {
Self::new(global, init.x, init.y, init.z, init.w)
fn FromPoint(global: &GlobalScope, init: &DOMPointInit, can_gc: CanGc) -> DomRoot<Self> {
Self::new(global, init.x, init.y, init.z, init.w, can_gc)
}
// https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-x

View file

@ -43,8 +43,9 @@ impl DOMQuad {
p2: &DOMPoint,
p3: &DOMPoint,
p4: &DOMPoint,
can_gc: CanGc,
) -> DomRoot<DOMQuad> {
Self::new_with_proto(global, None, p1, p2, p3, p4, CanGc::note())
Self::new_with_proto(global, None, p1, p2, p3, p4, can_gc)
}
fn new_with_proto(
@ -102,6 +103,7 @@ impl DOMQuadMethods for DOMQuad {
can_gc,
),
&DOMPoint::new(global, other.x, other.y + other.height, 0f64, 1f64, can_gc),
can_gc,
)
}
@ -113,6 +115,7 @@ impl DOMQuadMethods for DOMQuad {
&DOMPoint::new_from_init(global, &other.p2, can_gc),
&DOMPoint::new_from_init(global, &other.p3, can_gc),
&DOMPoint::new_from_init(global, &other.p4, can_gc),
can_gc,
)
}
@ -137,7 +140,7 @@ impl DOMQuadMethods for DOMQuad {
}
// https://drafts.fxtf.org/geometry/#dom-domquad-getbounds
fn GetBounds(&self) -> DomRoot<DOMRect> {
fn GetBounds(&self, can_gc: CanGc) -> DomRoot<DOMRect> {
// https://drafts.fxtf.org/geometry/#nan-safe-minimum
let nan_safe_minimum = |a: f64, b: f64| {
if a.is_nan() || b.is_nan() {
@ -196,7 +199,7 @@ impl DOMQuadMethods for DOMQuad {
top,
right - left,
bottom - top,
CanGc::note(),
can_gc,
)
}
}

View file

@ -203,6 +203,7 @@ impl GPUDevice {
error,
parent: EventInit::empty(),
},
can_gc,
);
let _ = self.eventtarget.DispatchEvent(ev.event());
}

View file

@ -37,8 +37,9 @@ impl GPUUncapturedErrorEvent {
global: &GlobalScope,
type_: DOMString,
init: &GPUUncapturedErrorEventInit,
can_gc: CanGc,
) -> DomRoot<Self> {
Self::new_with_proto(global, None, type_, init, CanGc::note())
Self::new_with_proto(global, None, type_, init, can_gc)
}
fn new_with_proto(

View file

@ -321,7 +321,7 @@ fn finish_fetching_a_classic_script(
},
}
document.finish_load(LoadType::Script(url), CanGc::note());
document.finish_load(LoadType::Script(url), can_gc);
}
pub type ScriptResult = Result<ScriptOrigin, NoTrace<NetworkError>>;

View file

@ -40,6 +40,7 @@ impl OfflineAudioCompletionEvent {
bubbles: EventBubbles,
cancelable: EventCancelable,
rendered_buffer: &AudioBuffer,
can_gc: CanGc,
) -> DomRoot<OfflineAudioCompletionEvent> {
Self::new_with_proto(
window,
@ -48,7 +49,7 @@ impl OfflineAudioCompletionEvent {
bubbles,
cancelable,
rendered_buffer,
CanGc::note(),
can_gc,
)
}

View file

@ -205,7 +205,7 @@ impl OfflineAudioContextMethods for OfflineAudioContext {
atom!("complete"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
&buffer);
&buffer, CanGc::note());
event.upcast::<Event>().fire(this.upcast());
}),
&canceller,

View file

@ -127,6 +127,7 @@ impl ResizeObserver {
&[],
&[&*observer_size],
&[],
can_gc,
);
entries.push(entry);

View file

@ -65,6 +65,7 @@ impl ResizeObserverEntry {
border_box_size: &[&ResizeObserverSize],
content_box_size: &[&ResizeObserverSize],
device_pixel_content_box_size: &[&ResizeObserverSize],
can_gc: CanGc,
) -> DomRoot<ResizeObserverEntry> {
let entry = Box::new(ResizeObserverEntry::new_inherited(
target,
@ -73,7 +74,7 @@ impl ResizeObserverEntry {
content_box_size,
device_pixel_content_box_size,
));
reflect_dom_object_with_proto(entry, window, None, CanGc::note())
reflect_dom_object_with_proto(entry, window, None, can_gc)
}
}

View file

@ -539,6 +539,7 @@ impl TaskOnce for CloseTask {
clean_close,
code,
reason,
CanGc::note(),
);
close_event.upcast::<Event>().fire(ws.upcast());
}

View file

@ -1341,8 +1341,9 @@ impl WindowMethods for Window {
input: RequestOrUSVString,
init: RootedTraceableBox<RequestInit>,
comp: InRealm,
can_gc: CanGc,
) -> Rc<Promise> {
fetch::Fetch(self.upcast(), input, init, comp, CanGc::note())
fetch::Fetch(self.upcast(), input, init, comp, can_gc)
}
fn TestRunner(&self) -> DomRoot<TestRunner> {

View file

@ -15,7 +15,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::XRSession;
use crate::script_runtime::JSContext;
use crate::script_runtime::{CanGc, JSContext};
#[dom_struct]
pub struct XRBoundedReferenceSpace {
@ -63,12 +63,19 @@ impl XRBoundedReferenceSpace {
impl XRBoundedReferenceSpaceMethods for XRBoundedReferenceSpace {
/// <https://www.w3.org/TR/webxr/#dom-xrboundedreferencespace-boundsgeometry>
fn BoundsGeometry(&self, cx: JSContext) -> JSVal {
fn BoundsGeometry(&self, cx: JSContext, can_gc: CanGc) -> JSVal {
if let Some(bounds) = self.reference_space.get_bounds() {
let points: Vec<DomRoot<DOMPointReadOnly>> = bounds
.into_iter()
.map(|point| {
DOMPointReadOnly::new(&self.global(), point.x.into(), 0.0, point.y.into(), 1.0)
DOMPointReadOnly::new(
&self.global(),
point.x.into(),
0.0,
point.y.into(),
1.0,
can_gc,
)
})
.collect();

View file

@ -46,16 +46,10 @@ impl XRInputSourceEvent {
cancelable: bool,
frame: &XRFrame,
source: &XRInputSource,
can_gc: CanGc,
) -> DomRoot<XRInputSourceEvent> {
Self::new_with_proto(
global,
None,
type_,
bubbles,
cancelable,
frame,
source,
CanGc::note(),
global, None, type_, bubbles, cancelable, frame, source, can_gc,
)
}

View file

@ -112,24 +112,26 @@ impl XRRayMethods for XRRay {
}
/// <https://immersive-web.github.io/hit-test/#dom-xrray-origin>
fn Origin(&self) -> DomRoot<DOMPointReadOnly> {
fn Origin(&self, can_gc: CanGc) -> DomRoot<DOMPointReadOnly> {
DOMPointReadOnly::new(
&self.global(),
self.ray.origin.x as f64,
self.ray.origin.y as f64,
self.ray.origin.z as f64,
1.,
can_gc,
)
}
/// <https://immersive-web.github.io/hit-test/#dom-xrray-direction>
fn Direction(&self) -> DomRoot<DOMPointReadOnly> {
fn Direction(&self, can_gc: CanGc) -> DomRoot<DOMPointReadOnly> {
DOMPointReadOnly::new(
&self.global(),
self.ray.direction.x as f64,
self.ray.direction.y as f64,
self.ray.direction.z as f64,
0.,
can_gc,
)
}

View file

@ -127,14 +127,21 @@ impl XRRigidTransformMethods for XRRigidTransform {
}
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-position
fn Position(&self) -> DomRoot<DOMPointReadOnly> {
fn Position(&self, can_gc: CanGc) -> DomRoot<DOMPointReadOnly> {
self.position.or_init(|| {
let t = &self.transform.translation;
DOMPointReadOnly::new(&self.global(), t.x.into(), t.y.into(), t.z.into(), 1.0)
DOMPointReadOnly::new(
&self.global(),
t.x.into(),
t.y.into(),
t.z.into(),
1.0,
can_gc,
)
})
}
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-orientation
fn Orientation(&self) -> DomRoot<DOMPointReadOnly> {
fn Orientation(&self, can_gc: CanGc) -> DomRoot<DOMPointReadOnly> {
self.orientation.or_init(|| {
let r = &self.transform.rotation;
DOMPointReadOnly::new(
@ -143,6 +150,7 @@ impl XRRigidTransformMethods for XRRigidTransform {
r.j.into(),
r.k.into(),
r.r.into(),
can_gc,
)
})
}

View file

@ -321,6 +321,7 @@ impl XRSession {
false,
&frame,
&source,
can_gc,
);
event.upcast::<Event>().fire(self.upcast());
} else {
@ -332,6 +333,7 @@ impl XRSession {
false,
&frame,
&source,
can_gc,
);
event.upcast::<Event>().fire(self.upcast());
}
@ -342,6 +344,7 @@ impl XRSession {
false,
&frame,
&source,
can_gc,
);
event.upcast::<Event>().fire(self.upcast());
}

View file

@ -1632,7 +1632,7 @@ impl ScriptThread {
},
CompositorEvent::CompositionEvent(composition_event) => {
document.dispatch_composition_event(composition_event);
document.dispatch_composition_event(composition_event, can_gc);
},
CompositorEvent::GamepadEvent(gamepad_event) => {