mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
add CanGc as argument to methods in ElementInternals, GlobalScope, HTMLAnchorElement, HTMLAreaElement, HTMLCanvasElement (#36492)
add CanGc as argument to methods in ElementInternals, GlobalScope, HTMLAnchorElement, HTMLAreaElement, HTMLCanvasElement Testing: These changes do not require tests because they are a refactor. Addresses part of https://github.com/servo/servo/issues/34573. Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
This commit is contained in:
parent
dcc88b53aa
commit
70c0faa0e9
10 changed files with 29 additions and 27 deletions
|
@ -234,6 +234,7 @@ impl ElementInternalsMethods<crate::DomTypeHolder> for ElementInternals {
|
||||||
flags: &ValidityStateFlags,
|
flags: &ValidityStateFlags,
|
||||||
message: Option<DOMString>,
|
message: Option<DOMString>,
|
||||||
anchor: Option<&HTMLElement>,
|
anchor: Option<&HTMLElement>,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> ErrorResult {
|
) -> ErrorResult {
|
||||||
// Steps 1-2: Check form-associated custom element
|
// Steps 1-2: Check form-associated custom element
|
||||||
if !self.is_target_form_associated() {
|
if !self.is_target_form_associated() {
|
||||||
|
@ -253,7 +254,7 @@ impl ElementInternalsMethods<crate::DomTypeHolder> for ElementInternals {
|
||||||
// Step 4: For each entry `flag` → `value` of `flags`, set element's validity flag with the name
|
// Step 4: For each entry `flag` → `value` of `flags`, set element's validity flag with the name
|
||||||
// `flag` to `value`.
|
// `flag` to `value`.
|
||||||
self.validity_state().update_invalid_flags(bits);
|
self.validity_state().update_invalid_flags(bits);
|
||||||
self.validity_state().update_pseudo_classes(CanGc::note());
|
self.validity_state().update_pseudo_classes(can_gc);
|
||||||
|
|
||||||
// Step 5: Set element's validation message to the empty string if message is not given
|
// Step 5: Set element's validation message to the empty string if message is not given
|
||||||
// or all of element's validity flags are false, or to message otherwise.
|
// or all of element's validity flags are false, or to message otherwise.
|
||||||
|
@ -309,7 +310,7 @@ impl ElementInternalsMethods<crate::DomTypeHolder> for ElementInternals {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://html.spec.whatwg.org/multipage#dom-elementinternals-labels>
|
/// <https://html.spec.whatwg.org/multipage#dom-elementinternals-labels>
|
||||||
fn GetLabels(&self) -> Fallible<DomRoot<NodeList>> {
|
fn GetLabels(&self, can_gc: CanGc) -> Fallible<DomRoot<NodeList>> {
|
||||||
if !self.is_target_form_associated() {
|
if !self.is_target_form_associated() {
|
||||||
return Err(Error::NotSupported);
|
return Err(Error::NotSupported);
|
||||||
}
|
}
|
||||||
|
@ -317,7 +318,7 @@ impl ElementInternalsMethods<crate::DomTypeHolder> for ElementInternals {
|
||||||
NodeList::new_labels_list(
|
NodeList::new_labels_list(
|
||||||
self.target_element.upcast::<Node>().owner_doc().window(),
|
self.target_element.upcast::<Node>().owner_doc().window(),
|
||||||
&self.target_element,
|
&self.target_element,
|
||||||
CanGc::note(),
|
can_gc,
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2126,8 +2126,8 @@ impl GlobalScope {
|
||||||
unsafe { SafeJSContext::from_ptr(cx) }
|
unsafe { SafeJSContext::from_ptr(cx) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn crypto(&self) -> DomRoot<Crypto> {
|
pub(crate) fn crypto(&self, can_gc: CanGc) -> DomRoot<Crypto> {
|
||||||
self.crypto.or_init(|| Crypto::new(self, CanGc::note()))
|
self.crypto.or_init(|| Crypto::new(self, can_gc))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn live_devtools_updates(&self) -> bool {
|
pub(crate) fn live_devtools_updates(&self) -> bool {
|
||||||
|
@ -2994,6 +2994,7 @@ impl GlobalScope {
|
||||||
device: WebGPUDevice,
|
device: WebGPUDevice,
|
||||||
reason: DeviceLostReason,
|
reason: DeviceLostReason,
|
||||||
msg: String,
|
msg: String,
|
||||||
|
can_gc: CanGc,
|
||||||
) {
|
) {
|
||||||
let reason = match reason {
|
let reason = match reason {
|
||||||
DeviceLostReason::Unknown => GPUDeviceLostReason::Unknown,
|
DeviceLostReason::Unknown => GPUDeviceLostReason::Unknown,
|
||||||
|
@ -3007,7 +3008,7 @@ impl GlobalScope {
|
||||||
.expect("GPUDevice should still be in devices hashmap")
|
.expect("GPUDevice should still be in devices hashmap")
|
||||||
.root()
|
.root()
|
||||||
{
|
{
|
||||||
device.lose(reason, msg, CanGc::note());
|
device.lose(reason, msg, can_gc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ impl HTMLAnchorElementMethods<crate::DomTypeHolder> for HTMLAnchorElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-a-rellist
|
// https://html.spec.whatwg.org/multipage/#dom-a-rellist
|
||||||
fn RelList(&self) -> DomRoot<DOMTokenList> {
|
fn RelList(&self, can_gc: CanGc) -> DomRoot<DOMTokenList> {
|
||||||
self.rel_list.or_init(|| {
|
self.rel_list.or_init(|| {
|
||||||
DOMTokenList::new(
|
DOMTokenList::new(
|
||||||
self.upcast(),
|
self.upcast(),
|
||||||
|
@ -155,7 +155,7 @@ impl HTMLAnchorElementMethods<crate::DomTypeHolder> for HTMLAnchorElement {
|
||||||
Atom::from("noreferrer"),
|
Atom::from("noreferrer"),
|
||||||
Atom::from("opener"),
|
Atom::from("opener"),
|
||||||
]),
|
]),
|
||||||
CanGc::note(),
|
can_gc,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,7 +362,7 @@ impl HTMLAreaElementMethods<crate::DomTypeHolder> for HTMLAreaElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://html.spec.whatwg.org/multipage/#dom-area-rellist>
|
/// <https://html.spec.whatwg.org/multipage/#dom-area-rellist>
|
||||||
fn RelList(&self) -> DomRoot<DOMTokenList> {
|
fn RelList(&self, can_gc: CanGc) -> DomRoot<DOMTokenList> {
|
||||||
self.rel_list.or_init(|| {
|
self.rel_list.or_init(|| {
|
||||||
DOMTokenList::new(
|
DOMTokenList::new(
|
||||||
self.upcast(),
|
self.upcast(),
|
||||||
|
@ -372,7 +372,7 @@ impl HTMLAreaElementMethods<crate::DomTypeHolder> for HTMLAreaElement {
|
||||||
Atom::from("noreferrer"),
|
Atom::from("noreferrer"),
|
||||||
Atom::from("opener"),
|
Atom::from("opener"),
|
||||||
]),
|
]),
|
||||||
CanGc::note(),
|
can_gc,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,7 @@ impl VirtualMethods for HTMLButtonElement {
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
el.update_sequentially_focusable_status(CanGc::note());
|
el.update_sequentially_focusable_status(can_gc);
|
||||||
self.validity_state()
|
self.validity_state()
|
||||||
.perform_validation_and_update(ValidationFlags::all(), can_gc);
|
.perform_validation_and_update(ValidationFlags::all(), can_gc);
|
||||||
},
|
},
|
||||||
|
|
|
@ -323,7 +323,7 @@ impl HTMLCanvasElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "webgpu")]
|
#[cfg(feature = "webgpu")]
|
||||||
fn get_or_init_webgpu_context(&self) -> Option<DomRoot<GPUCanvasContext>> {
|
fn get_or_init_webgpu_context(&self, can_gc: CanGc) -> Option<DomRoot<GPUCanvasContext>> {
|
||||||
if let Some(ctx) = self.context() {
|
if let Some(ctx) = self.context() {
|
||||||
return match *ctx {
|
return match *ctx {
|
||||||
CanvasContext::WebGPU(ref ctx) => Some(DomRoot::from_ref(ctx)),
|
CanvasContext::WebGPU(ref ctx) => Some(DomRoot::from_ref(ctx)),
|
||||||
|
@ -339,7 +339,7 @@ impl HTMLCanvasElement {
|
||||||
.recv()
|
.recv()
|
||||||
.expect("Failed to get WebGPU channel")
|
.expect("Failed to get WebGPU channel")
|
||||||
.map(|channel| {
|
.map(|channel| {
|
||||||
let context = GPUCanvasContext::new(&global_scope, self, channel, CanGc::note());
|
let context = GPUCanvasContext::new(&global_scope, self, channel, can_gc);
|
||||||
*self.context.borrow_mut() = Some(CanvasContext::WebGPU(Dom::from_ref(&*context)));
|
*self.context.borrow_mut() = Some(CanvasContext::WebGPU(Dom::from_ref(&*context)));
|
||||||
context
|
context
|
||||||
})
|
})
|
||||||
|
@ -477,7 +477,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
||||||
// When setting the value of the width or height attribute, if the context mode of the canvas element
|
// When setting the value of the width or height attribute, if the context mode of the canvas element
|
||||||
// is set to placeholder, the user agent must throw an "InvalidStateError" DOMException and leave the
|
// is set to placeholder, the user agent must throw an "InvalidStateError" DOMException and leave the
|
||||||
// attribute's value unchanged.
|
// attribute's value unchanged.
|
||||||
fn SetWidth(&self, value: u32) -> Fallible<()> {
|
fn SetWidth(&self, value: u32, can_gc: CanGc) -> Fallible<()> {
|
||||||
if let Some(CanvasContext::Placeholder(_)) = *self.context.borrow() {
|
if let Some(CanvasContext::Placeholder(_)) = *self.context.borrow() {
|
||||||
return Err(Error::InvalidState);
|
return Err(Error::InvalidState);
|
||||||
}
|
}
|
||||||
|
@ -488,7 +488,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
let element = self.upcast::<Element>();
|
let element = self.upcast::<Element>();
|
||||||
element.set_uint_attribute(&html5ever::local_name!("width"), value, CanGc::note());
|
element.set_uint_attribute(&html5ever::local_name!("width"), value, can_gc);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
||||||
make_uint_getter!(Height, "height", DEFAULT_HEIGHT);
|
make_uint_getter!(Height, "height", DEFAULT_HEIGHT);
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-height
|
// https://html.spec.whatwg.org/multipage/#dom-canvas-height
|
||||||
fn SetHeight(&self, value: u32) -> Fallible<()> {
|
fn SetHeight(&self, value: u32, can_gc: CanGc) -> Fallible<()> {
|
||||||
if let Some(CanvasContext::Placeholder(_)) = *self.context.borrow() {
|
if let Some(CanvasContext::Placeholder(_)) = *self.context.borrow() {
|
||||||
return Err(Error::InvalidState);
|
return Err(Error::InvalidState);
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
let element = self.upcast::<Element>();
|
let element = self.upcast::<Element>();
|
||||||
element.set_uint_attribute(&html5ever::local_name!("height"), value, CanGc::note());
|
element.set_uint_attribute(&html5ever::local_name!("height"), value, can_gc);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
||||||
.map(RenderingContext::WebGL2RenderingContext),
|
.map(RenderingContext::WebGL2RenderingContext),
|
||||||
#[cfg(feature = "webgpu")]
|
#[cfg(feature = "webgpu")]
|
||||||
"webgpu" => self
|
"webgpu" => self
|
||||||
.get_or_init_webgpu_context()
|
.get_or_init_webgpu_context(can_gc)
|
||||||
.map(RenderingContext::GPUCanvasContext),
|
.map(RenderingContext::GPUCanvasContext),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
|
@ -647,7 +647,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://html.spec.whatwg.org/multipage/#dom-canvas-transfercontroltooffscreen>
|
/// <https://html.spec.whatwg.org/multipage/#dom-canvas-transfercontroltooffscreen>
|
||||||
fn TransferControlToOffscreen(&self) -> Fallible<DomRoot<OffscreenCanvas>> {
|
fn TransferControlToOffscreen(&self, can_gc: CanGc) -> Fallible<DomRoot<OffscreenCanvas>> {
|
||||||
if self.context.borrow().is_some() {
|
if self.context.borrow().is_some() {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
// If this canvas element's context mode is not set to none, throw an "InvalidStateError" DOMException.
|
// If this canvas element's context mode is not set to none, throw an "InvalidStateError" DOMException.
|
||||||
|
@ -665,7 +665,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
||||||
self.Width().into(),
|
self.Width().into(),
|
||||||
self.Height().into(),
|
self.Height().into(),
|
||||||
Some(&Dom::from_ref(self)),
|
Some(&Dom::from_ref(self)),
|
||||||
CanGc::note(),
|
can_gc,
|
||||||
);
|
);
|
||||||
// Step 4. Set this canvas element's context mode to placeholder.
|
// Step 4. Set this canvas element's context mode to placeholder.
|
||||||
*self.context.borrow_mut() = Some(CanvasContext::Placeholder(offscreen_canvas.as_traced()));
|
*self.context.borrow_mut() = Some(CanvasContext::Placeholder(offscreen_canvas.as_traced()));
|
||||||
|
|
|
@ -954,7 +954,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
|
||||||
|
|
||||||
// https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#dfn-GlobalCrypto
|
// https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#dfn-GlobalCrypto
|
||||||
fn Crypto(&self) -> DomRoot<Crypto> {
|
fn Crypto(&self) -> DomRoot<Crypto> {
|
||||||
self.as_global_scope().crypto()
|
self.as_global_scope().crypto(CanGc::note())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-frameelement
|
// https://html.spec.whatwg.org/multipage/#dom-frameelement
|
||||||
|
|
|
@ -351,7 +351,7 @@ impl WorkerGlobalScopeMethods<crate::DomTypeHolder> for WorkerGlobalScope {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dfn-Crypto
|
// https://html.spec.whatwg.org/multipage/#dfn-Crypto
|
||||||
fn Crypto(&self) -> DomRoot<Crypto> {
|
fn Crypto(&self) -> DomRoot<Crypto> {
|
||||||
self.upcast::<GlobalScope>().crypto()
|
self.upcast::<GlobalScope>().crypto(CanGc::note())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-windowbase64-btoa
|
// https://html.spec.whatwg.org/multipage/#dom-windowbase64-btoa
|
||||||
|
|
|
@ -1948,7 +1948,7 @@ impl ScriptThread {
|
||||||
msg,
|
msg,
|
||||||
} => {
|
} => {
|
||||||
let global = self.documents.borrow().find_global(pipeline_id).unwrap();
|
let global = self.documents.borrow().find_global(pipeline_id).unwrap();
|
||||||
global.gpu_device_lost(device, reason, msg);
|
global.gpu_device_lost(device, reason, msg, can_gc);
|
||||||
},
|
},
|
||||||
WebGPUMsg::UncapturedError {
|
WebGPUMsg::UncapturedError {
|
||||||
device,
|
device,
|
||||||
|
|
|
@ -226,7 +226,7 @@ DOMInterfaces = {
|
||||||
},
|
},
|
||||||
|
|
||||||
'ElementInternals': {
|
'ElementInternals': {
|
||||||
'canGc': ['CheckValidity', 'ReportValidity'],
|
'canGc': ['CheckValidity', 'GetLabels', 'SetValidity', 'ReportValidity'],
|
||||||
},
|
},
|
||||||
|
|
||||||
'EventSource': {
|
'EventSource': {
|
||||||
|
@ -319,11 +319,11 @@ DOMInterfaces = {
|
||||||
},
|
},
|
||||||
|
|
||||||
"HTMLAnchorElement": {
|
"HTMLAnchorElement": {
|
||||||
"canGc": ["SetText","SetRel","SetHref", 'SetHash', 'SetHost', 'SetHostname', 'SetPassword', 'SetPathname', 'SetPort', 'SetProtocol', 'SetSearch', 'SetUsername']
|
"canGc": ["SetText","SetRel","SetHref", 'SetHash', 'SetHost', 'SetHostname', 'SetPassword', 'SetPathname', 'SetPort', 'SetProtocol', 'SetSearch', 'SetUsername', 'RelList']
|
||||||
},
|
},
|
||||||
|
|
||||||
"HTMLAreaElement": {
|
"HTMLAreaElement": {
|
||||||
"canGc": ['SetText', 'SetRel', 'SetHref', 'SetHash', 'SetHost', 'SetHostname', 'SetPassword', 'SetPathname', 'SetPort', 'SetProtocol', 'SetSearch', 'SetUsername']
|
"canGc": ['SetText', 'SetRel', 'SetHref', 'SetHash', 'SetHost', 'SetHostname', 'SetPassword', 'SetPathname', 'SetPort', 'SetProtocol', 'SetSearch', 'SetUsername', 'RelList']
|
||||||
},
|
},
|
||||||
|
|
||||||
"HTMLBodyElement": {
|
"HTMLBodyElement": {
|
||||||
|
@ -335,7 +335,7 @@ DOMInterfaces = {
|
||||||
},
|
},
|
||||||
|
|
||||||
'HTMLCanvasElement': {
|
'HTMLCanvasElement': {
|
||||||
'canGc': ['CaptureStream', 'GetContext'],
|
'canGc': ['CaptureStream', 'GetContext', 'SetHeight', 'SetWidth', 'TransferControlToOffscreen'],
|
||||||
},
|
},
|
||||||
|
|
||||||
'HTMLDialogElement': {
|
'HTMLDialogElement': {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue