CanGc fixes from constantsourcenode.rs & window.rs (#33931)

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
This commit is contained in:
tanishka 2024-10-21 01:24:02 +05:30 committed by GitHub
parent c75f6627ba
commit 4d11b2dc84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 216 additions and 156 deletions

View file

@ -486,9 +486,9 @@ pub fn handle_request_animation_frame(documents: &Documents, id: PipelineId, act
}
}
pub fn handle_reload(documents: &Documents, id: PipelineId) {
pub fn handle_reload(documents: &Documents, id: PipelineId, can_gc: CanGc) {
if let Some(win) = documents.find_window(id) {
win.Location().reload_without_origin_check();
win.Location().reload_without_origin_check(can_gc);
}
}

View file

@ -407,11 +407,12 @@ impl BaseAudioContextMethods for BaseAudioContext {
}
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createconstantsource>
fn CreateConstantSource(&self) -> Fallible<DomRoot<ConstantSourceNode>> {
fn CreateConstantSource(&self, can_gc: CanGc) -> Fallible<DomRoot<ConstantSourceNode>> {
ConstantSourceNode::new(
self.global().as_window(),
self,
&ConstantSourceOptions::empty(),
can_gc,
)
}

View file

@ -25,7 +25,7 @@ DOMInterfaces = {
'BaseAudioContext': {
'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'],
'canGc': ['CreateChannelMerger', 'CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser', 'CreatePanner', 'CreateChannelSplitter', 'CreateBuffer'],
'canGc': ['CreateChannelMerger', 'CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser', 'CreatePanner', 'CreateChannelSplitter', 'CreateBuffer', 'CreateConstantSource'],
},
'Blob': {
@ -143,6 +143,10 @@ DOMInterfaces = {
'inRealms': ['PlayEffect', 'Reset']
},
'History': {
'canGc': ['Go'],
},
'HTMLButtonElement': {
'canGc': ['ReportValidity'],
},
@ -192,6 +196,10 @@ DOMInterfaces = {
'canGc': ['ReportValidity'],
},
'Location': {
'canGc': ['Assign', 'Reload', 'Replace', 'SetHash', 'SetHost', 'SetHostname', 'SetHref', 'SetPathname', 'SetPort', 'SetProtocol', 'SetSearch'],
},
'MediaDevices': {
'canGc': ['GetUserMedia'],
'inRealms': ['GetUserMedia', 'GetClientRects', 'GetBoundingClientRect'],
@ -293,7 +301,7 @@ DOMInterfaces = {
},
'Window': {
'canGc': ['Stop', 'Fetch'],
'canGc': ['Stop', 'Fetch', 'Open'],
'inRealms': ['Fetch', 'GetOpener'],
},

View file

@ -67,8 +67,9 @@ impl ConstantSourceNode {
window: &Window,
context: &BaseAudioContext,
options: &ConstantSourceOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<ConstantSourceNode>> {
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

@ -756,7 +756,7 @@ impl Document {
);
let event = event.upcast::<Event>();
event.set_trusted(true);
window.dispatch_event_with_target_override(event);
window.dispatch_event_with_target_override(event, CanGc::note());
}),
self.window.upcast(),
)
@ -1297,6 +1297,7 @@ impl Document {
}
#[allow(unsafe_code)]
#[allow(clippy::too_many_arguments)]
pub unsafe fn handle_mouse_button_event(
&self,
button: MouseButton,
@ -1465,6 +1466,7 @@ impl Document {
*self.last_click_info.borrow_mut() = Some((now, click_pos));
}
#[allow(clippy::too_many_arguments)]
pub fn fire_mouse_event(
&self,
client_point: Point2D<f32>,
@ -2271,7 +2273,7 @@ impl Document {
}
// https://html.spec.whatwg.org/multipage/#prompt-to-unload-a-document
pub fn prompt_to_unload(&self, recursive_flag: bool) -> bool {
pub fn prompt_to_unload(&self, recursive_flag: bool, can_gc: CanGc) -> bool {
// TODO: Step 1, increase the event loop's termination nesting level by 1.
// Step 2
self.incr_ignore_opens_during_unload_counter();
@ -2286,7 +2288,8 @@ impl Document {
event.set_trusted(true);
let event_target = self.window.upcast::<EventTarget>();
let has_listeners = event_target.has_listeners_for(&atom!("beforeunload"));
self.window.dispatch_event_with_target_override(event);
self.window
.dispatch_event_with_target_override(event, can_gc);
// TODO: Step 6, decrease the event loop's termination nesting level by 1.
// Step 7
if has_listeners {
@ -2311,7 +2314,7 @@ impl Document {
for iframe in self.iter_iframes() {
// TODO: handle the case of cross origin iframes.
let document = document_from_node(&*iframe);
can_unload = document.prompt_to_unload(true);
can_unload = document.prompt_to_unload(true, can_gc);
if !document.salvageable() {
self.salvageable.set(false);
}
@ -2346,7 +2349,9 @@ impl Document {
);
let event = event.upcast::<Event>();
event.set_trusted(true);
let _ = self.window.dispatch_event_with_target_override(event);
let _ = self
.window
.dispatch_event_with_target_override(event, can_gc);
// Step 6 Update the visibility state of oldDocument to "hidden".
self.update_visibility_state(DocumentVisibilityState::Hidden);
}
@ -2362,7 +2367,9 @@ impl Document {
event.set_trusted(true);
let event_target = self.window.upcast::<EventTarget>();
let has_listeners = event_target.has_listeners_for(&atom!("unload"));
let _ = self.window.dispatch_event_with_target_override(&event);
let _ = self
.window
.dispatch_event_with_target_override(&event, can_gc);
self.fired_unload.set(true);
// Step 9
if has_listeners {
@ -2458,7 +2465,7 @@ impl Document {
update_with_current_instant(&document.load_event_start);
debug!("About to dispatch load for {:?}", document.url());
window.dispatch_event_with_target_override(&event);
window.dispatch_event_with_target_override(&event, CanGc::note());
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventEnd
update_with_current_instant(&document.load_event_end);
@ -2498,7 +2505,7 @@ impl Document {
let event = event.upcast::<Event>();
event.set_trusted(true);
window.dispatch_event_with_target_override(event);
window.dispatch_event_with_target_override(event, CanGc::note());
}),
self.window.upcast(),
)
@ -5415,11 +5422,11 @@ impl DocumentMethods for Document {
url: USVString,
target: DOMString,
features: DOMString,
_can_gc: CanGc,
can_gc: CanGc,
) -> Fallible<Option<DomRoot<WindowProxy>>> {
self.browsing_context()
.ok_or(Error::InvalidAccess)?
.open(url, target, features)
.open(url, target, features, can_gc)
}
// https://html.spec.whatwg.org/multipage/#dom-document-write

View file

@ -47,6 +47,7 @@ impl FocusEvent {
reflect_dom_object_with_proto(Box::new(FocusEvent::new_inherited()), window, proto, can_gc)
}
#[allow(clippy::too_many_arguments)]
pub fn new(
window: &Window,
type_: DOMString,

View file

@ -313,11 +313,11 @@ impl HistoryMethods for History {
}
/// <https://html.spec.whatwg.org/multipage/#dom-history-go>
fn Go(&self, delta: i32) -> ErrorResult {
fn Go(&self, delta: i32, can_gc: CanGc) -> ErrorResult {
let direction = match delta.cmp(&0) {
Ordering::Greater => TraversalDirection::Forward(delta as usize),
Ordering::Less => TraversalDirection::Back(-delta as usize),
Ordering::Equal => return self.window.Location().Reload(),
Ordering::Equal => return self.window.Location().Reload(can_gc),
};
self.traverse_history(direction)

View file

@ -1016,6 +1016,7 @@ impl HTMLFormElement {
HistoryEntryReplacement::Disabled,
false,
load_data,
CanGc::note(),
);
});

View file

@ -30,6 +30,7 @@ use crate::dom::location::NavigationType;
use crate::dom::node::{document_from_node, window_from_node, BindContext, Node, UnbindContext};
use crate::dom::virtualmethods::VirtualMethods;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
use crate::timers::OneshotTimerCallback;
#[dom_struct]
@ -45,11 +46,12 @@ pub struct RefreshRedirectDue {
pub window: DomRoot<Window>,
}
impl RefreshRedirectDue {
pub fn invoke(self) {
pub fn invoke(self, can_gc: CanGc) {
self.window.Location().navigate(
self.url.clone(),
HistoryEntryReplacement::Enabled,
NavigationType::DeclarativeRefresh,
can_gc,
);
}
}

View file

@ -17,6 +17,7 @@ use crate::dom::document::Document;
use crate::dom::globalscope::GlobalScope;
use crate::dom::urlhelper::UrlHelper;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
#[derive(PartialEq)]
pub enum NavigationType {
@ -66,6 +67,7 @@ impl Location {
url: ServoUrl,
replacement_flag: HistoryEntryReplacement,
navigation_type: NavigationType,
can_gc: CanGc,
) {
fn incumbent_window() -> DomRoot<Window> {
let incumbent_global = GlobalScope::incumbent().expect("no incumbent global object");
@ -125,7 +127,7 @@ impl Location {
None, // Top navigation doesn't inherit secure context
);
self.window
.load_url(replacement_flag, reload_triggered, load_data);
.load_url(replacement_flag, reload_triggered, load_data, can_gc);
}
/// Get if this `Location`'s [relevant `Document`][1] is non-null.
@ -210,7 +212,11 @@ impl Location {
/// The common algorithm for `Location`'s setters and `Location::Assign`.
#[inline]
fn setter_common(&self, f: impl FnOnce(ServoUrl) -> Fallible<Option<ServoUrl>>) -> ErrorResult {
fn setter_common(
&self,
f: impl FnOnce(ServoUrl) -> Fallible<Option<ServoUrl>>,
can_gc: CanGc,
) -> ErrorResult {
// Step 1: If this Location object's relevant Document is null, then return.
// Step 2: If this Location object's relevant Document's origin is not
// same origin-domain with the entry settings object's origin, then
@ -225,6 +231,7 @@ impl Location {
copy_url,
HistoryEntryReplacement::Disabled,
NavigationType::Normal,
can_gc,
);
}
}
@ -235,7 +242,7 @@ impl Location {
/// [`reload()`][1]).
///
/// [1]: https://html.spec.whatwg.org/multipage/#dom-location-reload
pub fn reload_without_origin_check(&self) {
pub fn reload_without_origin_check(&self, can_gc: CanGc) {
// > When a user requests that the active document of a browsing context
// > be reloaded through a user interface element, the user agent should
// > navigate the browsing context to the same resource as that
@ -245,6 +252,7 @@ impl Location {
url,
HistoryEntryReplacement::Enabled,
NavigationType::ReloadByConstellation,
can_gc,
);
}
@ -256,33 +264,37 @@ impl Location {
impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-assign
fn Assign(&self, url: USVString) -> ErrorResult {
self.setter_common(|_copy_url| {
// Step 3: Parse url relative to the entry settings object. If that failed,
// throw a "SyntaxError" DOMException.
let base_url = self.entry_settings_object().api_base_url();
let url = match base_url.join(&url.0) {
Ok(url) => url,
Err(_) => return Err(Error::Syntax),
};
fn Assign(&self, url: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(
|_copy_url| {
// Step 3: Parse url relative to the entry settings object. If that failed,
// throw a "SyntaxError" DOMException.
let base_url = self.entry_settings_object().api_base_url();
let url = match base_url.join(&url.0) {
Ok(url) => url,
Err(_) => return Err(Error::Syntax),
};
Ok(Some(url))
})
Ok(Some(url))
},
can_gc,
)
}
// https://html.spec.whatwg.org/multipage/#dom-location-reload
fn Reload(&self) -> ErrorResult {
fn Reload(&self, can_gc: CanGc) -> ErrorResult {
let url = self.get_url_if_same_origin()?;
self.navigate(
url,
HistoryEntryReplacement::Enabled,
NavigationType::ReloadByScript,
can_gc,
);
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-location-replace
fn Replace(&self, url: USVString) -> ErrorResult {
fn Replace(&self, url: USVString, can_gc: CanGc) -> ErrorResult {
// Step 1: If this Location object's relevant Document is null, then return.
if self.has_document() {
// Step 2: Parse url relative to the entry settings object. If that failed,
@ -298,6 +310,7 @@ impl LocationMethods for Location {
url,
HistoryEntryReplacement::Enabled,
NavigationType::Normal,
can_gc,
);
}
Ok(())
@ -309,26 +322,29 @@ impl LocationMethods for Location {
}
// https://html.spec.whatwg.org/multipage/#dom-location-hash
fn SetHash(&self, value: USVString) -> ErrorResult {
self.setter_common(|mut copy_url| {
// Step 4: Let input be the given value with a single leading "#" removed, if any.
// Step 5: Set copyURL's fragment to the empty string.
// Step 6: Basic URL parse input, with copyURL as url and fragment state as
// state override.
let new_fragment = if value.0.starts_with('#') {
Some(&value.0[1..])
} else {
Some(value.0.as_str())
};
// Step 7: If copyURL's fragment is this's url's fragment, then return.
if copy_url.fragment() == new_fragment {
Ok(None)
} else {
copy_url.as_mut_url().set_fragment(new_fragment);
fn SetHash(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(
|mut copy_url| {
// Step 4: Let input be the given value with a single leading "#" removed, if any.
// Step 5: Set copyURL's fragment to the empty string.
// Step 6: Basic URL parse input, with copyURL as url and fragment state as
// state override.
let new_fragment = if value.0.starts_with('#') {
Some(&value.0[1..])
} else {
Some(value.0.as_str())
};
// Step 7: If copyURL's fragment is this's url's fragment, then return.
if copy_url.fragment() == new_fragment {
Ok(None)
} else {
copy_url.as_mut_url().set_fragment(new_fragment);
Ok(Some(copy_url))
}
})
Ok(Some(copy_url))
}
},
can_gc,
)
}
// https://html.spec.whatwg.org/multipage/#dom-location-host
@ -337,19 +353,22 @@ impl LocationMethods for Location {
}
// https://html.spec.whatwg.org/multipage/#dom-location-host
fn SetHost(&self, value: USVString) -> ErrorResult {
self.setter_common(|mut copy_url| {
// Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if copy_url.cannot_be_a_base() {
return Ok(None);
}
fn SetHost(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(
|mut copy_url| {
// Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if copy_url.cannot_be_a_base() {
return Ok(None);
}
// Step 5: Basic URL parse the given value, with copyURL as url and host state
// as state override.
let _ = copy_url.as_mut_url().set_host(Some(&value.0));
// Step 5: Basic URL parse the given value, with copyURL as url and host state
// as state override.
let _ = copy_url.as_mut_url().set_host(Some(&value.0));
Ok(Some(copy_url))
})
Ok(Some(copy_url))
},
can_gc,
)
}
// https://html.spec.whatwg.org/multipage/#dom-location-origin
@ -363,19 +382,22 @@ impl LocationMethods for Location {
}
// https://html.spec.whatwg.org/multipage/#dom-location-hostname
fn SetHostname(&self, value: USVString) -> ErrorResult {
self.setter_common(|mut copy_url| {
// Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if copy_url.cannot_be_a_base() {
return Ok(None);
}
fn SetHostname(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(
|mut copy_url| {
// Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if copy_url.cannot_be_a_base() {
return Ok(None);
}
// Step 5: Basic URL parse the given value, with copyURL as url and hostname
// state as state override.
let _ = copy_url.as_mut_url().set_host(Some(&value.0));
// Step 5: Basic URL parse the given value, with copyURL as url and hostname
// state as state override.
let _ = copy_url.as_mut_url().set_host(Some(&value.0));
Ok(Some(copy_url))
})
Ok(Some(copy_url))
},
can_gc,
)
}
// https://html.spec.whatwg.org/multipage/#dom-location-href
@ -384,7 +406,7 @@ impl LocationMethods for Location {
}
// https://html.spec.whatwg.org/multipage/#dom-location-href
fn SetHref(&self, value: USVString) -> ErrorResult {
fn SetHref(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
// Step 1: If this Location object's relevant Document is null, then return.
if self.has_document() {
// Note: no call to self.check_same_origin_domain()
@ -400,6 +422,7 @@ impl LocationMethods for Location {
url,
HistoryEntryReplacement::Disabled,
NavigationType::Normal,
can_gc,
);
}
Ok(())
@ -411,20 +434,23 @@ impl LocationMethods for Location {
}
// https://html.spec.whatwg.org/multipage/#dom-location-pathname
fn SetPathname(&self, value: USVString) -> ErrorResult {
self.setter_common(|mut copy_url| {
// Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if copy_url.cannot_be_a_base() {
return Ok(None);
}
fn SetPathname(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(
|mut copy_url| {
// Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if copy_url.cannot_be_a_base() {
return Ok(None);
}
// Step 5: Set copyURL's path to the empty list.
// Step 6: Basic URL parse the given value, with copyURL as url and path
// start state as state override.
copy_url.as_mut_url().set_path(&value.0);
// Step 5: Set copyURL's path to the empty list.
// Step 6: Basic URL parse the given value, with copyURL as url and path
// start state as state override.
copy_url.as_mut_url().set_path(&value.0);
Ok(Some(copy_url))
})
Ok(Some(copy_url))
},
can_gc,
)
}
// https://html.spec.whatwg.org/multipage/#dom-location-port
@ -433,25 +459,28 @@ impl LocationMethods for Location {
}
// https://html.spec.whatwg.org/multipage/#dom-location-port
fn SetPort(&self, value: USVString) -> ErrorResult {
self.setter_common(|mut copy_url| {
// Step 4: If copyURL cannot have a username/password/port, then return.
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
if copy_url.host().is_none() ||
copy_url.cannot_be_a_base() ||
copy_url.scheme() == "file"
{
return Ok(None);
}
fn SetPort(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(
|mut copy_url| {
// Step 4: If copyURL cannot have a username/password/port, then return.
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
if copy_url.host().is_none() ||
copy_url.cannot_be_a_base() ||
copy_url.scheme() == "file"
{
return Ok(None);
}
// Step 5: If the given value is the empty string, then set copyURL's
// port to null.
// Step 6: Otherwise, basic URL parse the given value, with copyURL as url
// and port state as state override.
let _ = url::quirks::set_port(copy_url.as_mut_url(), &value.0);
// Step 5: If the given value is the empty string, then set copyURL's
// port to null.
// Step 6: Otherwise, basic URL parse the given value, with copyURL as url
// and port state as state override.
let _ = url::quirks::set_port(copy_url.as_mut_url(), &value.0);
Ok(Some(copy_url))
})
Ok(Some(copy_url))
},
can_gc,
)
}
// https://html.spec.whatwg.org/multipage/#dom-location-protocol
@ -460,30 +489,33 @@ impl LocationMethods for Location {
}
// https://html.spec.whatwg.org/multipage/#dom-location-protocol
fn SetProtocol(&self, value: USVString) -> ErrorResult {
self.setter_common(|mut copy_url| {
// Step 4: Let possibleFailure be the result of basic URL parsing the given
// value, followed by ":", with copyURL as url and scheme start state as
// state override.
let scheme = match value.0.find(':') {
Some(position) => &value.0[..position],
None => &value.0,
};
fn SetProtocol(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(
|mut copy_url| {
// Step 4: Let possibleFailure be the result of basic URL parsing the given
// value, followed by ":", with copyURL as url and scheme start state as
// state override.
let scheme = match value.0.find(':') {
Some(position) => &value.0[..position],
None => &value.0,
};
if copy_url.as_mut_url().set_scheme(scheme).is_err() {
// Step 5: If possibleFailure is failure, then throw a "SyntaxError" DOMException.
return Err(Error::Syntax);
}
if copy_url.as_mut_url().set_scheme(scheme).is_err() {
// Step 5: If possibleFailure is failure, then throw a "SyntaxError" DOMException.
return Err(Error::Syntax);
}
// Step 6: If copyURL's scheme is not an HTTP(S) scheme, then terminate these steps.
if !copy_url.scheme().eq_ignore_ascii_case("http") &&
!copy_url.scheme().eq_ignore_ascii_case("https")
{
return Ok(None);
}
// Step 6: If copyURL's scheme is not an HTTP(S) scheme, then terminate these steps.
if !copy_url.scheme().eq_ignore_ascii_case("http") &&
!copy_url.scheme().eq_ignore_ascii_case("https")
{
return Ok(None);
}
Ok(Some(copy_url))
})
Ok(Some(copy_url))
},
can_gc,
)
}
// https://html.spec.whatwg.org/multipage/#dom-location-search
@ -492,22 +524,25 @@ impl LocationMethods for Location {
}
// https://html.spec.whatwg.org/multipage/#dom-location-search
fn SetSearch(&self, value: USVString) -> ErrorResult {
self.setter_common(|mut copy_url| {
// Step 4: If the given value is the empty string, set copyURL's query to null.
// Step 5: Otherwise, run these substeps:
// 1. Let input be the given value with a single leading "?" removed, if any.
// 2. Set copyURL's query to the empty string.
// 3. Basic URL parse input, with copyURL as url and query state as state
// override, and the relevant Document's document's character encoding as
// encoding override.
copy_url.as_mut_url().set_query(match value.0.as_str() {
"" => None,
_ if value.0.starts_with('?') => Some(&value.0[1..]),
_ => Some(&value.0),
});
fn SetSearch(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(
|mut copy_url| {
// Step 4: If the given value is the empty string, set copyURL's query to null.
// Step 5: Otherwise, run these substeps:
// 1. Let input be the given value with a single leading "?" removed, if any.
// 2. Set copyURL's query to the empty string.
// 3. Basic URL parse input, with copyURL as url and query state as state
// override, and the relevant Document's document's character encoding as
// encoding override.
copy_url.as_mut_url().set_query(match value.0.as_str() {
"" => None,
_ if value.0.starts_with('?') => Some(&value.0[1..]),
_ => Some(&value.0),
});
Ok(Some(copy_url))
})
Ok(Some(copy_url))
},
can_gc,
)
}
}

View file

@ -547,8 +547,8 @@ impl Window {
}
// see note at https://dom.spec.whatwg.org/#concept-event-dispatch step 2
pub fn dispatch_event_with_target_override(&self, event: &Event) -> EventStatus {
event.dispatch(self.upcast(), true, CanGc::note())
pub fn dispatch_event_with_target_override(&self, event: &Event, can_gc: CanGc) -> EventStatus {
event.dispatch(self.upcast(), true, can_gc)
}
}
@ -688,8 +688,9 @@ impl WindowMethods for Window {
url: USVString,
target: DOMString,
features: DOMString,
can_gc: CanGc,
) -> Fallible<Option<DomRoot<WindowProxy>>> {
self.window_proxy().open(url, target, features)
self.window_proxy().open(url, target, features, can_gc)
}
// https://html.spec.whatwg.org/multipage/#dom-opener
@ -781,7 +782,7 @@ impl WindowMethods for Window {
// Steps 2 and 3, prompt to unload for all inclusive descendant navigables.
// TODO: We should be prompting for all inclusive descendant navigables,
// but we pass false here, which suggests we are not doing that. Why?
if document.prompt_to_unload(false) {
if document.prompt_to_unload(false, CanGc::note()) {
// Step 4, unload.
document.unload(false, CanGc::note());
@ -2236,6 +2237,7 @@ impl Window {
replace: HistoryEntryReplacement,
force_reload: bool,
load_data: LoadData,
can_gc: CanGc,
) {
let doc = self.Document();
// TODO: Important re security. See https://github.com/servo/servo/issues/23373
@ -2293,7 +2295,7 @@ impl Window {
}
// Step 8
if doc.prompt_to_unload(false) {
if doc.prompt_to_unload(false, can_gc) {
let window_proxy = self.window_proxy();
if window_proxy.parent().is_some() {
// Step 10

View file

@ -54,7 +54,7 @@ use crate::dom::element::Element;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
use crate::script_runtime::JSContext as SafeJSContext;
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
use crate::script_thread::ScriptThread;
#[dom_struct]
@ -465,6 +465,7 @@ impl WindowProxy {
url: USVString,
target: DOMString,
features: DOMString,
can_gc: CanGc,
) -> Fallible<Option<DomRoot<WindowProxy>>> {
// Step 4.
let non_empty_target = match target.as_ref() {
@ -527,7 +528,7 @@ impl WindowProxy {
} else {
HistoryEntryReplacement::Disabled
};
target_window.load_url(replacement_flag, false, load_data);
target_window.load_url(replacement_flag, false, load_data, can_gc);
}
if noopener {
// Step 15 (Dis-owning has been done in create_auxiliary_browsing_context).

View file

@ -21,6 +21,7 @@ use crate::dom::htmlformelement::HTMLFormElement;
use crate::dom::htmllinkelement::HTMLLinkElement;
use crate::dom::node::document_from_node;
use crate::dom::types::{Element, GlobalScope};
use crate::script_runtime::CanGc;
use crate::task_source::TaskSource;
bitflags::bitflags! {
@ -432,7 +433,7 @@ pub fn follow_hyperlink(
let target = Trusted::new(target_window);
let task = task!(navigate_follow_hyperlink: move || {
debug!("following hyperlink to {}", load_data.url);
target.root().load_url(replace, false, load_data);
target.root().load_url(replace, false, load_data, CanGc::note());
});
target_window
.task_manager()

View file

@ -2409,7 +2409,7 @@ impl ScriptThread {
ConstellationControlMsg::ReportCSSError(pipeline_id, filename, line, column, msg) => {
self.handle_css_error_reporting(pipeline_id, filename, line, column, msg)
},
ConstellationControlMsg::Reload(pipeline_id) => self.handle_reload(pipeline_id),
ConstellationControlMsg::Reload(pipeline_id) => self.handle_reload(pipeline_id, can_gc),
ConstellationControlMsg::ExitPipeline(pipeline_id, discard_browsing_context) => {
self.handle_exit_pipeline_msg(pipeline_id, discard_browsing_context, can_gc)
},
@ -2629,7 +2629,7 @@ impl ScriptThread {
DevtoolScriptControlMsg::RequestAnimationFrame(id, name) => {
devtools::handle_request_animation_frame(&documents, id, name)
},
DevtoolScriptControlMsg::Reload(id) => devtools::handle_reload(&documents, id),
DevtoolScriptControlMsg::Reload(id) => devtools::handle_reload(&documents, id, can_gc),
DevtoolScriptControlMsg::GetCssDatabase(reply) => {
devtools::handle_get_css_database(reply)
},
@ -4259,10 +4259,10 @@ impl ScriptThread {
}
}
fn handle_reload(&self, pipeline_id: PipelineId) {
fn handle_reload(&self, pipeline_id: PipelineId, can_gc: CanGc) {
let window = self.documents.borrow().find_window(pipeline_id);
if let Some(window) = window {
window.Location().reload_without_origin_check();
window.Location().reload_without_origin_check(can_gc);
}
}

View file

@ -96,7 +96,7 @@ impl OneshotTimerCallback {
OneshotTimerCallback::JsTimer(task) => task.invoke(this, js_timers),
OneshotTimerCallback::TestBindingCallback(callback) => callback.invoke(),
OneshotTimerCallback::FakeRequestAnimationFrame(callback) => callback.invoke(),
OneshotTimerCallback::RefreshRedirectDue(callback) => callback.invoke(),
OneshotTimerCallback::RefreshRedirectDue(callback) => callback.invoke(can_gc),
}
}
}