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) { 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> /// <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( ConstantSourceNode::new(
self.global().as_window(), self.global().as_window(),
self, self,
&ConstantSourceOptions::empty(), &ConstantSourceOptions::empty(),
can_gc,
) )
} }

View file

@ -25,7 +25,7 @@ DOMInterfaces = {
'BaseAudioContext': { 'BaseAudioContext': {
'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'], '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': { 'Blob': {
@ -143,6 +143,10 @@ DOMInterfaces = {
'inRealms': ['PlayEffect', 'Reset'] 'inRealms': ['PlayEffect', 'Reset']
}, },
'History': {
'canGc': ['Go'],
},
'HTMLButtonElement': { 'HTMLButtonElement': {
'canGc': ['ReportValidity'], 'canGc': ['ReportValidity'],
}, },
@ -192,6 +196,10 @@ DOMInterfaces = {
'canGc': ['ReportValidity'], 'canGc': ['ReportValidity'],
}, },
'Location': {
'canGc': ['Assign', 'Reload', 'Replace', 'SetHash', 'SetHost', 'SetHostname', 'SetHref', 'SetPathname', 'SetPort', 'SetProtocol', 'SetSearch'],
},
'MediaDevices': { 'MediaDevices': {
'canGc': ['GetUserMedia'], 'canGc': ['GetUserMedia'],
'inRealms': ['GetUserMedia', 'GetClientRects', 'GetBoundingClientRect'], 'inRealms': ['GetUserMedia', 'GetClientRects', 'GetBoundingClientRect'],
@ -293,7 +301,7 @@ DOMInterfaces = {
}, },
'Window': { 'Window': {
'canGc': ['Stop', 'Fetch'], 'canGc': ['Stop', 'Fetch', 'Open'],
'inRealms': ['Fetch', 'GetOpener'], 'inRealms': ['Fetch', 'GetOpener'],
}, },

View file

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

View file

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

View file

@ -313,11 +313,11 @@ impl HistoryMethods for History {
} }
/// <https://html.spec.whatwg.org/multipage/#dom-history-go> /// <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) { let direction = match delta.cmp(&0) {
Ordering::Greater => TraversalDirection::Forward(delta as usize), Ordering::Greater => TraversalDirection::Forward(delta as usize),
Ordering::Less => TraversalDirection::Back(-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) self.traverse_history(direction)

View file

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

View file

@ -17,6 +17,7 @@ use crate::dom::document::Document;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::urlhelper::UrlHelper; use crate::dom::urlhelper::UrlHelper;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc;
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum NavigationType { pub enum NavigationType {
@ -66,6 +67,7 @@ impl Location {
url: ServoUrl, url: ServoUrl,
replacement_flag: HistoryEntryReplacement, replacement_flag: HistoryEntryReplacement,
navigation_type: NavigationType, navigation_type: NavigationType,
can_gc: CanGc,
) { ) {
fn incumbent_window() -> DomRoot<Window> { fn incumbent_window() -> DomRoot<Window> {
let incumbent_global = GlobalScope::incumbent().expect("no incumbent global object"); let incumbent_global = GlobalScope::incumbent().expect("no incumbent global object");
@ -125,7 +127,7 @@ impl Location {
None, // Top navigation doesn't inherit secure context None, // Top navigation doesn't inherit secure context
); );
self.window 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. /// 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`. /// The common algorithm for `Location`'s setters and `Location::Assign`.
#[inline] #[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 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 // Step 2: If this Location object's relevant Document's origin is not
// same origin-domain with the entry settings object's origin, then // same origin-domain with the entry settings object's origin, then
@ -225,6 +231,7 @@ impl Location {
copy_url, copy_url,
HistoryEntryReplacement::Disabled, HistoryEntryReplacement::Disabled,
NavigationType::Normal, NavigationType::Normal,
can_gc,
); );
} }
} }
@ -235,7 +242,7 @@ impl Location {
/// [`reload()`][1]). /// [`reload()`][1]).
/// ///
/// [1]: https://html.spec.whatwg.org/multipage/#dom-location-reload /// [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 // > When a user requests that the active document of a browsing context
// > be reloaded through a user interface element, the user agent should // > be reloaded through a user interface element, the user agent should
// > navigate the browsing context to the same resource as that // > navigate the browsing context to the same resource as that
@ -245,6 +252,7 @@ impl Location {
url, url,
HistoryEntryReplacement::Enabled, HistoryEntryReplacement::Enabled,
NavigationType::ReloadByConstellation, NavigationType::ReloadByConstellation,
can_gc,
); );
} }
@ -256,8 +264,9 @@ impl Location {
impl LocationMethods for Location { impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-assign // https://html.spec.whatwg.org/multipage/#dom-location-assign
fn Assign(&self, url: USVString) -> ErrorResult { fn Assign(&self, url: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(|_copy_url| { self.setter_common(
|_copy_url| {
// Step 3: Parse url relative to the entry settings object. If that failed, // Step 3: Parse url relative to the entry settings object. If that failed,
// throw a "SyntaxError" DOMException. // throw a "SyntaxError" DOMException.
let base_url = self.entry_settings_object().api_base_url(); let base_url = self.entry_settings_object().api_base_url();
@ -267,22 +276,25 @@ impl LocationMethods for Location {
}; };
Ok(Some(url)) Ok(Some(url))
}) },
can_gc,
)
} }
// https://html.spec.whatwg.org/multipage/#dom-location-reload // 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()?; let url = self.get_url_if_same_origin()?;
self.navigate( self.navigate(
url, url,
HistoryEntryReplacement::Enabled, HistoryEntryReplacement::Enabled,
NavigationType::ReloadByScript, NavigationType::ReloadByScript,
can_gc,
); );
Ok(()) Ok(())
} }
// https://html.spec.whatwg.org/multipage/#dom-location-replace // 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. // Step 1: If this Location object's relevant Document is null, then return.
if self.has_document() { if self.has_document() {
// Step 2: Parse url relative to the entry settings object. If that failed, // Step 2: Parse url relative to the entry settings object. If that failed,
@ -298,6 +310,7 @@ impl LocationMethods for Location {
url, url,
HistoryEntryReplacement::Enabled, HistoryEntryReplacement::Enabled,
NavigationType::Normal, NavigationType::Normal,
can_gc,
); );
} }
Ok(()) Ok(())
@ -309,8 +322,9 @@ impl LocationMethods for Location {
} }
// https://html.spec.whatwg.org/multipage/#dom-location-hash // https://html.spec.whatwg.org/multipage/#dom-location-hash
fn SetHash(&self, value: USVString) -> ErrorResult { fn SetHash(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(|mut copy_url| { self.setter_common(
|mut copy_url| {
// Step 4: Let input be the given value with a single leading "#" removed, if any. // 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 5: Set copyURL's fragment to the empty string.
// Step 6: Basic URL parse input, with copyURL as url and fragment state as // Step 6: Basic URL parse input, with copyURL as url and fragment state as
@ -328,7 +342,9 @@ impl LocationMethods for Location {
Ok(Some(copy_url)) Ok(Some(copy_url))
} }
}) },
can_gc,
)
} }
// https://html.spec.whatwg.org/multipage/#dom-location-host // https://html.spec.whatwg.org/multipage/#dom-location-host
@ -337,8 +353,9 @@ impl LocationMethods for Location {
} }
// https://html.spec.whatwg.org/multipage/#dom-location-host // https://html.spec.whatwg.org/multipage/#dom-location-host
fn SetHost(&self, value: USVString) -> ErrorResult { fn SetHost(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(|mut copy_url| { self.setter_common(
|mut copy_url| {
// Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps. // Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if copy_url.cannot_be_a_base() { if copy_url.cannot_be_a_base() {
return Ok(None); return Ok(None);
@ -349,7 +366,9 @@ impl LocationMethods for Location {
let _ = copy_url.as_mut_url().set_host(Some(&value.0)); 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 // https://html.spec.whatwg.org/multipage/#dom-location-origin
@ -363,8 +382,9 @@ impl LocationMethods for Location {
} }
// https://html.spec.whatwg.org/multipage/#dom-location-hostname // https://html.spec.whatwg.org/multipage/#dom-location-hostname
fn SetHostname(&self, value: USVString) -> ErrorResult { fn SetHostname(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(|mut copy_url| { self.setter_common(
|mut copy_url| {
// Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps. // Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if copy_url.cannot_be_a_base() { if copy_url.cannot_be_a_base() {
return Ok(None); return Ok(None);
@ -375,7 +395,9 @@ impl LocationMethods for Location {
let _ = copy_url.as_mut_url().set_host(Some(&value.0)); 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 // 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 // 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. // Step 1: If this Location object's relevant Document is null, then return.
if self.has_document() { if self.has_document() {
// Note: no call to self.check_same_origin_domain() // Note: no call to self.check_same_origin_domain()
@ -400,6 +422,7 @@ impl LocationMethods for Location {
url, url,
HistoryEntryReplacement::Disabled, HistoryEntryReplacement::Disabled,
NavigationType::Normal, NavigationType::Normal,
can_gc,
); );
} }
Ok(()) Ok(())
@ -411,8 +434,9 @@ impl LocationMethods for Location {
} }
// https://html.spec.whatwg.org/multipage/#dom-location-pathname // https://html.spec.whatwg.org/multipage/#dom-location-pathname
fn SetPathname(&self, value: USVString) -> ErrorResult { fn SetPathname(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(|mut copy_url| { self.setter_common(
|mut copy_url| {
// Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps. // Step 4: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if copy_url.cannot_be_a_base() { if copy_url.cannot_be_a_base() {
return Ok(None); return Ok(None);
@ -424,7 +448,9 @@ impl LocationMethods for Location {
copy_url.as_mut_url().set_path(&value.0); 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 // https://html.spec.whatwg.org/multipage/#dom-location-port
@ -433,8 +459,9 @@ impl LocationMethods for Location {
} }
// https://html.spec.whatwg.org/multipage/#dom-location-port // https://html.spec.whatwg.org/multipage/#dom-location-port
fn SetPort(&self, value: USVString) -> ErrorResult { fn SetPort(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(|mut copy_url| { self.setter_common(
|mut copy_url| {
// Step 4: If copyURL cannot have a username/password/port, then return. // Step 4: If copyURL cannot have a username/password/port, then return.
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port // https://url.spec.whatwg.org/#cannot-have-a-username-password-port
if copy_url.host().is_none() || if copy_url.host().is_none() ||
@ -451,7 +478,9 @@ impl LocationMethods for Location {
let _ = url::quirks::set_port(copy_url.as_mut_url(), &value.0); 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 // https://html.spec.whatwg.org/multipage/#dom-location-protocol
@ -460,8 +489,9 @@ impl LocationMethods for Location {
} }
// https://html.spec.whatwg.org/multipage/#dom-location-protocol // https://html.spec.whatwg.org/multipage/#dom-location-protocol
fn SetProtocol(&self, value: USVString) -> ErrorResult { fn SetProtocol(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(|mut copy_url| { self.setter_common(
|mut copy_url| {
// Step 4: Let possibleFailure be the result of basic URL parsing the given // 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 // value, followed by ":", with copyURL as url and scheme start state as
// state override. // state override.
@ -483,7 +513,9 @@ impl LocationMethods for Location {
} }
Ok(Some(copy_url)) Ok(Some(copy_url))
}) },
can_gc,
)
} }
// https://html.spec.whatwg.org/multipage/#dom-location-search // https://html.spec.whatwg.org/multipage/#dom-location-search
@ -492,8 +524,9 @@ impl LocationMethods for Location {
} }
// https://html.spec.whatwg.org/multipage/#dom-location-search // https://html.spec.whatwg.org/multipage/#dom-location-search
fn SetSearch(&self, value: USVString) -> ErrorResult { fn SetSearch(&self, value: USVString, can_gc: CanGc) -> ErrorResult {
self.setter_common(|mut copy_url| { self.setter_common(
|mut copy_url| {
// Step 4: If the given value is the empty string, set copyURL's query to null. // Step 4: If the given value is the empty string, set copyURL's query to null.
// Step 5: Otherwise, run these substeps: // Step 5: Otherwise, run these substeps:
// 1. Let input be the given value with a single leading "?" removed, if any. // 1. Let input be the given value with a single leading "?" removed, if any.
@ -508,6 +541,8 @@ impl LocationMethods for Location {
}); });
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 // see note at https://dom.spec.whatwg.org/#concept-event-dispatch step 2
pub fn dispatch_event_with_target_override(&self, event: &Event) -> EventStatus { pub fn dispatch_event_with_target_override(&self, event: &Event, can_gc: CanGc) -> EventStatus {
event.dispatch(self.upcast(), true, CanGc::note()) event.dispatch(self.upcast(), true, can_gc)
} }
} }
@ -688,8 +688,9 @@ impl WindowMethods for Window {
url: USVString, url: USVString,
target: DOMString, target: DOMString,
features: DOMString, features: DOMString,
can_gc: CanGc,
) -> Fallible<Option<DomRoot<WindowProxy>>> { ) -> 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 // 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. // Steps 2 and 3, prompt to unload for all inclusive descendant navigables.
// TODO: We should be prompting 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? // 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. // Step 4, unload.
document.unload(false, CanGc::note()); document.unload(false, CanGc::note());
@ -2236,6 +2237,7 @@ impl Window {
replace: HistoryEntryReplacement, replace: HistoryEntryReplacement,
force_reload: bool, force_reload: bool,
load_data: LoadData, load_data: LoadData,
can_gc: CanGc,
) { ) {
let doc = self.Document(); let doc = self.Document();
// TODO: Important re security. See https://github.com/servo/servo/issues/23373 // TODO: Important re security. See https://github.com/servo/servo/issues/23373
@ -2293,7 +2295,7 @@ impl Window {
} }
// Step 8 // Step 8
if doc.prompt_to_unload(false) { if doc.prompt_to_unload(false, can_gc) {
let window_proxy = self.window_proxy(); let window_proxy = self.window_proxy();
if window_proxy.parent().is_some() { if window_proxy.parent().is_some() {
// Step 10 // Step 10

View file

@ -54,7 +54,7 @@ use crate::dom::element::Element;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::realms::{enter_realm, AlreadyInRealm, InRealm}; 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; use crate::script_thread::ScriptThread;
#[dom_struct] #[dom_struct]
@ -465,6 +465,7 @@ impl WindowProxy {
url: USVString, url: USVString,
target: DOMString, target: DOMString,
features: DOMString, features: DOMString,
can_gc: CanGc,
) -> Fallible<Option<DomRoot<WindowProxy>>> { ) -> Fallible<Option<DomRoot<WindowProxy>>> {
// Step 4. // Step 4.
let non_empty_target = match target.as_ref() { let non_empty_target = match target.as_ref() {
@ -527,7 +528,7 @@ impl WindowProxy {
} else { } else {
HistoryEntryReplacement::Disabled HistoryEntryReplacement::Disabled
}; };
target_window.load_url(replacement_flag, false, load_data); target_window.load_url(replacement_flag, false, load_data, can_gc);
} }
if noopener { if noopener {
// Step 15 (Dis-owning has been done in create_auxiliary_browsing_context). // 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::htmllinkelement::HTMLLinkElement;
use crate::dom::node::document_from_node; use crate::dom::node::document_from_node;
use crate::dom::types::{Element, GlobalScope}; use crate::dom::types::{Element, GlobalScope};
use crate::script_runtime::CanGc;
use crate::task_source::TaskSource; use crate::task_source::TaskSource;
bitflags::bitflags! { bitflags::bitflags! {
@ -432,7 +433,7 @@ pub fn follow_hyperlink(
let target = Trusted::new(target_window); let target = Trusted::new(target_window);
let task = task!(navigate_follow_hyperlink: move || { let task = task!(navigate_follow_hyperlink: move || {
debug!("following hyperlink to {}", load_data.url); 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 target_window
.task_manager() .task_manager()

View file

@ -2409,7 +2409,7 @@ impl ScriptThread {
ConstellationControlMsg::ReportCSSError(pipeline_id, filename, line, column, msg) => { ConstellationControlMsg::ReportCSSError(pipeline_id, filename, line, column, msg) => {
self.handle_css_error_reporting(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) => { ConstellationControlMsg::ExitPipeline(pipeline_id, discard_browsing_context) => {
self.handle_exit_pipeline_msg(pipeline_id, discard_browsing_context, can_gc) self.handle_exit_pipeline_msg(pipeline_id, discard_browsing_context, can_gc)
}, },
@ -2629,7 +2629,7 @@ impl ScriptThread {
DevtoolScriptControlMsg::RequestAnimationFrame(id, name) => { DevtoolScriptControlMsg::RequestAnimationFrame(id, name) => {
devtools::handle_request_animation_frame(&documents, 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) => { DevtoolScriptControlMsg::GetCssDatabase(reply) => {
devtools::handle_get_css_database(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); let window = self.documents.borrow().find_window(pipeline_id);
if let Some(window) = window { 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::JsTimer(task) => task.invoke(this, js_timers),
OneshotTimerCallback::TestBindingCallback(callback) => callback.invoke(), OneshotTimerCallback::TestBindingCallback(callback) => callback.invoke(),
OneshotTimerCallback::FakeRequestAnimationFrame(callback) => callback.invoke(), OneshotTimerCallback::FakeRequestAnimationFrame(callback) => callback.invoke(),
OneshotTimerCallback::RefreshRedirectDue(callback) => callback.invoke(), OneshotTimerCallback::RefreshRedirectDue(callback) => callback.invoke(can_gc),
} }
} }
} }