mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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,
|
||||
message: Option<DOMString>,
|
||||
anchor: Option<&HTMLElement>,
|
||||
can_gc: CanGc,
|
||||
) -> ErrorResult {
|
||||
// Steps 1-2: Check form-associated custom element
|
||||
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
|
||||
// `flag` to `value`.
|
||||
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
|
||||
// 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>
|
||||
fn GetLabels(&self) -> Fallible<DomRoot<NodeList>> {
|
||||
fn GetLabels(&self, can_gc: CanGc) -> Fallible<DomRoot<NodeList>> {
|
||||
if !self.is_target_form_associated() {
|
||||
return Err(Error::NotSupported);
|
||||
}
|
||||
|
@ -317,7 +318,7 @@ impl ElementInternalsMethods<crate::DomTypeHolder> for ElementInternals {
|
|||
NodeList::new_labels_list(
|
||||
self.target_element.upcast::<Node>().owner_doc().window(),
|
||||
&self.target_element,
|
||||
CanGc::note(),
|
||||
can_gc,
|
||||
)
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -2126,8 +2126,8 @@ impl GlobalScope {
|
|||
unsafe { SafeJSContext::from_ptr(cx) }
|
||||
}
|
||||
|
||||
pub(crate) fn crypto(&self) -> DomRoot<Crypto> {
|
||||
self.crypto.or_init(|| Crypto::new(self, CanGc::note()))
|
||||
pub(crate) fn crypto(&self, can_gc: CanGc) -> DomRoot<Crypto> {
|
||||
self.crypto.or_init(|| Crypto::new(self, can_gc))
|
||||
}
|
||||
|
||||
pub(crate) fn live_devtools_updates(&self) -> bool {
|
||||
|
@ -2994,6 +2994,7 @@ impl GlobalScope {
|
|||
device: WebGPUDevice,
|
||||
reason: DeviceLostReason,
|
||||
msg: String,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
let reason = match reason {
|
||||
DeviceLostReason::Unknown => GPUDeviceLostReason::Unknown,
|
||||
|
@ -3007,7 +3008,7 @@ impl GlobalScope {
|
|||
.expect("GPUDevice should still be in devices hashmap")
|
||||
.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
|
||||
fn RelList(&self) -> DomRoot<DOMTokenList> {
|
||||
fn RelList(&self, can_gc: CanGc) -> DomRoot<DOMTokenList> {
|
||||
self.rel_list.or_init(|| {
|
||||
DOMTokenList::new(
|
||||
self.upcast(),
|
||||
|
@ -155,7 +155,7 @@ impl HTMLAnchorElementMethods<crate::DomTypeHolder> for HTMLAnchorElement {
|
|||
Atom::from("noreferrer"),
|
||||
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>
|
||||
fn RelList(&self) -> DomRoot<DOMTokenList> {
|
||||
fn RelList(&self, can_gc: CanGc) -> DomRoot<DOMTokenList> {
|
||||
self.rel_list.or_init(|| {
|
||||
DOMTokenList::new(
|
||||
self.upcast(),
|
||||
|
@ -372,7 +372,7 @@ impl HTMLAreaElementMethods<crate::DomTypeHolder> for HTMLAreaElement {
|
|||
Atom::from("noreferrer"),
|
||||
Atom::from("opener"),
|
||||
]),
|
||||
CanGc::note(),
|
||||
can_gc,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -261,7 +261,7 @@ impl VirtualMethods for HTMLButtonElement {
|
|||
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()
|
||||
.perform_validation_and_update(ValidationFlags::all(), can_gc);
|
||||
},
|
||||
|
|
|
@ -323,7 +323,7 @@ impl HTMLCanvasElement {
|
|||
}
|
||||
|
||||
#[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() {
|
||||
return match *ctx {
|
||||
CanvasContext::WebGPU(ref ctx) => Some(DomRoot::from_ref(ctx)),
|
||||
|
@ -339,7 +339,7 @@ impl HTMLCanvasElement {
|
|||
.recv()
|
||||
.expect("Failed to get WebGPU 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)));
|
||||
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
|
||||
// is set to placeholder, the user agent must throw an "InvalidStateError" DOMException and leave the
|
||||
// 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() {
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
|||
value
|
||||
};
|
||||
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(())
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
|||
make_uint_getter!(Height, "height", DEFAULT_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() {
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
|||
value
|
||||
};
|
||||
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(())
|
||||
}
|
||||
|
||||
|
@ -536,7 +536,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
|||
.map(RenderingContext::WebGL2RenderingContext),
|
||||
#[cfg(feature = "webgpu")]
|
||||
"webgpu" => self
|
||||
.get_or_init_webgpu_context()
|
||||
.get_or_init_webgpu_context(can_gc)
|
||||
.map(RenderingContext::GPUCanvasContext),
|
||||
_ => None,
|
||||
})
|
||||
|
@ -647,7 +647,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
|||
}
|
||||
|
||||
/// <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() {
|
||||
// Step 1.
|
||||
// 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.Height().into(),
|
||||
Some(&Dom::from_ref(self)),
|
||||
CanGc::note(),
|
||||
can_gc,
|
||||
);
|
||||
// Step 4. Set this canvas element's context mode to placeholder.
|
||||
*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
|
||||
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
|
||||
|
|
|
@ -351,7 +351,7 @@ impl WorkerGlobalScopeMethods<crate::DomTypeHolder> for WorkerGlobalScope {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dfn-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
|
||||
|
|
|
@ -1948,7 +1948,7 @@ impl ScriptThread {
|
|||
msg,
|
||||
} => {
|
||||
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 {
|
||||
device,
|
||||
|
|
|
@ -226,7 +226,7 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
'ElementInternals': {
|
||||
'canGc': ['CheckValidity', 'ReportValidity'],
|
||||
'canGc': ['CheckValidity', 'GetLabels', 'SetValidity', 'ReportValidity'],
|
||||
},
|
||||
|
||||
'EventSource': {
|
||||
|
@ -319,11 +319,11 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
"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": {
|
||||
"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": {
|
||||
|
@ -335,7 +335,7 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
'HTMLCanvasElement': {
|
||||
'canGc': ['CaptureStream', 'GetContext'],
|
||||
'canGc': ['CaptureStream', 'GetContext', 'SetHeight', 'SetWidth', 'TransferControlToOffscreen'],
|
||||
},
|
||||
|
||||
'HTMLDialogElement': {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue