Various CanGc fixes in 8 files (#33893)

* Various CanGc fixes in 8 files

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* fixed merge conflicts and formatting

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

---------

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-10-18 17:24:32 +05:30 committed by GitHub
parent 6b87ecc291
commit fde8d72aca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 77 additions and 58 deletions

View file

@ -715,7 +715,11 @@ impl Callback for ConsumeBodyPromiseHandler {
// https://fetch.spec.whatwg.org/#concept-body-consume-body // https://fetch.spec.whatwg.org/#concept-body-consume-body
#[allow(crown::unrooted_must_root)] #[allow(crown::unrooted_must_root)]
pub fn consume_body<T: BodyMixin + DomObject>(object: &T, body_type: BodyType) -> Rc<Promise> { pub fn consume_body<T: BodyMixin + DomObject>(
object: &T,
body_type: BodyType,
can_gc: CanGc,
) -> Rc<Promise> {
let in_realm_proof = AlreadyInRealm::assert(); let in_realm_proof = AlreadyInRealm::assert();
let promise = Promise::new_in_current_realm(InRealm::Already(&in_realm_proof)); let promise = Promise::new_in_current_realm(InRealm::Already(&in_realm_proof));
@ -732,6 +736,7 @@ pub fn consume_body<T: BodyMixin + DomObject>(object: &T, body_type: BodyType) -
body_type, body_type,
promise.clone(), promise.clone(),
InRealm::Already(&in_realm_proof), InRealm::Already(&in_realm_proof),
can_gc,
); );
promise promise
@ -744,6 +749,7 @@ fn consume_body_with_promise<T: BodyMixin + DomObject>(
body_type: BodyType, body_type: BodyType,
promise: Rc<Promise>, promise: Rc<Promise>,
comp: InRealm, comp: InRealm,
can_gc: CanGc,
) { ) {
let global = object.global(); let global = object.global();
@ -771,7 +777,7 @@ fn consume_body_with_promise<T: BodyMixin + DomObject>(
result_promise: promise.clone(), result_promise: promise.clone(),
stream: Some(stream), stream: Some(stream),
body_type: DomRefCell::new(Some(body_type)), body_type: DomRefCell::new(Some(body_type)),
mime_type: DomRefCell::new(Some(object.get_mime_type())), mime_type: DomRefCell::new(Some(object.get_mime_type(can_gc))),
// Step 2. // Step 2.
bytes: DomRefCell::new(Some(vec![])), bytes: DomRefCell::new(Some(vec![])),
}); });
@ -913,5 +919,5 @@ pub trait BodyMixin {
/// <https://fetch.spec.whatwg.org/#concept-body-locked> /// <https://fetch.spec.whatwg.org/#concept-body-locked>
fn is_locked(&self) -> bool; fn is_locked(&self) -> bool;
/// <https://fetch.spec.whatwg.org/#concept-body-mime-type> /// <https://fetch.spec.whatwg.org/#concept-body-mime-type>
fn get_mime_type(&self) -> Vec<u8>; fn get_mime_type(&self, can_gc: CanGc) -> Vec<u8>;
} }

View file

@ -328,6 +328,7 @@ pub fn handle_get_layout(
pipeline: PipelineId, pipeline: PipelineId,
node_id: String, node_id: String,
reply: IpcSender<Option<ComputedNodeLayout>>, reply: IpcSender<Option<ComputedNodeLayout>>,
can_gc: CanGc,
) { ) {
let node = match find_node_by_unique_id(documents, pipeline, &node_id) { let node = match find_node_by_unique_id(documents, pipeline, &node_id) {
None => return reply.send(None).unwrap(), None => return reply.send(None).unwrap(),
@ -337,7 +338,7 @@ pub fn handle_get_layout(
let elem = node let elem = node
.downcast::<Element>() .downcast::<Element>()
.expect("should be getting layout of element"); .expect("should be getting layout of element");
let rect = elem.GetBoundingClientRect(CanGc::note()); let rect = elem.GetBoundingClientRect(can_gc);
let width = rect.Width() as f32; let width = rect.Width() as f32;
let height = rect.Height() as f32; let height = rect.Height() as f32;

View file

@ -427,10 +427,14 @@ impl BaseAudioContextMethods for BaseAudioContext {
} }
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelsplitter> /// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelsplitter>
fn CreateChannelSplitter(&self, count: u32) -> Fallible<DomRoot<ChannelSplitterNode>> { fn CreateChannelSplitter(
&self,
count: u32,
can_gc: CanGc,
) -> Fallible<DomRoot<ChannelSplitterNode>> {
let mut opts = ChannelSplitterOptions::empty(); let mut opts = ChannelSplitterOptions::empty();
opts.numberOfOutputs = count; opts.numberOfOutputs = count;
ChannelSplitterNode::new(self.global().as_window(), self, &opts) ChannelSplitterNode::new(self.global().as_window(), self, &opts, can_gc)
} }
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer> /// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer>

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'], 'canGc': ['CreateChannelMerger', 'CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser', 'CreatePanner', 'CreateChannelSplitter'],
}, },
'Blob': { 'Blob': {
@ -213,9 +213,12 @@ DOMInterfaces = {
}, },
'Response': { 'Response': {
'canGc': ['Error', 'Redirect', 'Clone'], 'canGc': ['Error', 'Redirect', 'Clone', 'Text', 'Blob', 'FormData', 'Json', 'ArrayBuffer'],
}, },
'Request': {
'canGc': ['Headers', 'Text', 'Blob', 'FormData', 'Json', 'ArrayBuffer', 'Clone'],
},
'Selection': { 'Selection': {
'canGc': ['Collapse', 'CollapseToEnd', 'CollapseToStart', 'Extend', 'SelectAllChildren', 'SetBaseAndExtent', 'SetPosition'], 'canGc': ['Collapse', 'CollapseToEnd', 'CollapseToStart', 'Extend', 'SelectAllChildren', 'SetBaseAndExtent', 'SetPosition'],
@ -261,6 +264,7 @@ DOMInterfaces = {
'WorkerGlobalScope': { 'WorkerGlobalScope': {
'inRealms': ['Fetch'], 'inRealms': ['Fetch'],
'canGc': ['Fetch'],
}, },
'Worklet': { 'Worklet': {

View file

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

@ -33,15 +33,10 @@ impl FormDataEvent {
can_bubble: EventBubbles, can_bubble: EventBubbles,
cancelable: EventCancelable, cancelable: EventCancelable,
form_data: &FormData, form_data: &FormData,
can_gc: CanGc,
) -> DomRoot<FormDataEvent> { ) -> DomRoot<FormDataEvent> {
Self::new_with_proto( Self::new_with_proto(
global, global, None, type_, can_bubble, cancelable, form_data, can_gc,
None,
type_,
can_bubble,
cancelable,
form_data,
CanGc::note(),
) )
} }

View file

@ -1214,6 +1214,7 @@ impl HTMLFormElement {
EventBubbles::Bubbles, EventBubbles::Bubbles,
EventCancelable::NotCancelable, EventCancelable::NotCancelable,
&form_data, &form_data,
can_gc,
); );
event.upcast::<Event>().fire(self.upcast::<EventTarget>()); event.upcast::<Event>().fire(self.upcast::<EventTarget>());

View file

@ -88,7 +88,7 @@ impl Request {
fn clone_from(r: &Request, can_gc: CanGc) -> Fallible<DomRoot<Request>> { fn clone_from(r: &Request, can_gc: CanGc) -> Fallible<DomRoot<Request>> {
let req = r.request.borrow(); let req = r.request.borrow();
let url = req.url(); let url = req.url();
let headers_guard = r.Headers().get_guard(); let headers_guard = r.Headers(can_gc).get_guard();
let r_clone = Request::new(&r.global(), None, url, can_gc); let r_clone = Request::new(&r.global(), None, url, can_gc);
r_clone.request.borrow_mut().pipeline_id = req.pipeline_id; r_clone.request.borrow_mut().pipeline_id = req.pipeline_id;
{ {
@ -96,8 +96,10 @@ impl Request {
borrowed_r_request.origin = req.origin.clone(); borrowed_r_request.origin = req.origin.clone();
} }
*r_clone.request.borrow_mut() = req.clone(); *r_clone.request.borrow_mut() = req.clone();
r_clone.Headers().copy_from_headers(r.Headers())?; r_clone
r_clone.Headers().set_guard(headers_guard); .Headers(can_gc)
.copy_from_headers(r.Headers(can_gc))?;
r_clone.Headers(can_gc).set_guard(headers_guard);
Ok(r_clone) Ok(r_clone)
} }
@ -384,7 +386,7 @@ impl RequestMethods for Request {
// "or_init" looks unclear here, but it always enters the block since r // "or_init" looks unclear here, but it always enters the block since r
// hasn't had any other way to initialize its headers // hasn't had any other way to initialize its headers
r.headers r.headers
.or_init(|| Headers::for_request(&r.global(), CanGc::note())); .or_init(|| Headers::for_request(&r.global(), can_gc));
// Step 33 - but spec says this should only be when non-empty init? // Step 33 - but spec says this should only be when non-empty init?
let headers_copy = init let headers_copy = init
@ -419,7 +421,7 @@ impl RequestMethods for Request {
)); ));
} }
// Step 32.2 // Step 32.2
r.Headers().set_guard(Guard::RequestNoCors); r.Headers(can_gc).set_guard(Guard::RequestNoCors);
} }
// Step 33.5 // Step 33.5
@ -430,15 +432,16 @@ impl RequestMethods for Request {
// but an input with headers is given, set request's // but an input with headers is given, set request's
// headers as the input's Headers. // headers as the input's Headers.
if let RequestInfo::Request(ref input_request) = input { if let RequestInfo::Request(ref input_request) = input {
r.Headers().copy_from_headers(input_request.Headers())?; r.Headers(can_gc)
.copy_from_headers(input_request.Headers(can_gc))?;
} }
}, },
Some(headers_copy) => r.Headers().fill(Some(headers_copy))?, Some(headers_copy) => r.Headers(can_gc).fill(Some(headers_copy))?,
} }
// Step 33.5 depending on how we got here // Step 33.5 depending on how we got here
// Copy the headers list onto the headers of net_traits::Request // Copy the headers list onto the headers of net_traits::Request
r.request.borrow_mut().headers = r.Headers().get_headers_list(); r.request.borrow_mut().headers = r.Headers(can_gc).get_headers_list();
// Step 34 // Step 34
let mut input_body = if let RequestInfo::Request(ref mut input_request) = input { let mut input_body = if let RequestInfo::Request(ref mut input_request) = input {
@ -480,12 +483,12 @@ impl RequestMethods for Request {
if let Some(contents) = extracted_body.content_type.take() { if let Some(contents) = extracted_body.content_type.take() {
let ct_header_name = b"Content-Type"; let ct_header_name = b"Content-Type";
if !r if !r
.Headers() .Headers(can_gc)
.Has(ByteString::new(ct_header_name.to_vec())) .Has(ByteString::new(ct_header_name.to_vec()))
.unwrap() .unwrap()
{ {
let ct_header_val = contents.as_bytes(); let ct_header_val = contents.as_bytes();
r.Headers().Append( r.Headers(can_gc).Append(
ByteString::new(ct_header_name.to_vec()), ByteString::new(ct_header_name.to_vec()),
ByteString::new(ct_header_val.to_vec()), ByteString::new(ct_header_val.to_vec()),
)?; )?;
@ -536,9 +539,9 @@ impl RequestMethods for Request {
} }
// https://fetch.spec.whatwg.org/#dom-request-headers // https://fetch.spec.whatwg.org/#dom-request-headers
fn Headers(&self) -> DomRoot<Headers> { fn Headers(&self, can_gc: CanGc) -> DomRoot<Headers> {
self.headers self.headers
.or_init(|| Headers::new(&self.global(), CanGc::note())) .or_init(|| Headers::new(&self.global(), can_gc))
} }
// https://fetch.spec.whatwg.org/#dom-request-destination // https://fetch.spec.whatwg.org/#dom-request-destination
@ -608,7 +611,7 @@ impl RequestMethods for Request {
} }
// https://fetch.spec.whatwg.org/#dom-request-clone // https://fetch.spec.whatwg.org/#dom-request-clone
fn Clone(&self) -> Fallible<DomRoot<Request>> { fn Clone(&self, can_gc: CanGc) -> Fallible<DomRoot<Request>> {
// Step 1 // Step 1
if request_is_locked(self) { if request_is_locked(self) {
return Err(Error::Type("Request is locked".to_string())); return Err(Error::Type("Request is locked".to_string()));
@ -618,32 +621,32 @@ impl RequestMethods for Request {
} }
// Step 2 // Step 2
Request::clone_from(self, CanGc::note()) Request::clone_from(self, can_gc)
} }
// https://fetch.spec.whatwg.org/#dom-body-text // https://fetch.spec.whatwg.org/#dom-body-text
fn Text(&self) -> Rc<Promise> { fn Text(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::Text) consume_body(self, BodyType::Text, can_gc)
} }
// https://fetch.spec.whatwg.org/#dom-body-blob // https://fetch.spec.whatwg.org/#dom-body-blob
fn Blob(&self) -> Rc<Promise> { fn Blob(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::Blob) consume_body(self, BodyType::Blob, can_gc)
} }
// https://fetch.spec.whatwg.org/#dom-body-formdata // https://fetch.spec.whatwg.org/#dom-body-formdata
fn FormData(&self) -> Rc<Promise> { fn FormData(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::FormData) consume_body(self, BodyType::FormData, can_gc)
} }
// https://fetch.spec.whatwg.org/#dom-body-json // https://fetch.spec.whatwg.org/#dom-body-json
fn Json(&self) -> Rc<Promise> { fn Json(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::Json) consume_body(self, BodyType::Json, can_gc)
} }
// https://fetch.spec.whatwg.org/#dom-body-arraybuffer // https://fetch.spec.whatwg.org/#dom-body-arraybuffer
fn ArrayBuffer(&self) -> Rc<Promise> { fn ArrayBuffer(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::ArrayBuffer) consume_body(self, BodyType::ArrayBuffer, can_gc)
} }
} }
@ -664,8 +667,8 @@ impl BodyMixin for Request {
self.body_stream.get() self.body_stream.get()
} }
fn get_mime_type(&self) -> Vec<u8> { fn get_mime_type(&self, can_gc: CanGc) -> Vec<u8> {
let headers = self.Headers(); let headers = self.Headers(can_gc);
headers.extract_mime_type() headers.extract_mime_type()
} }
} }

View file

@ -113,7 +113,7 @@ impl BodyMixin for Response {
self.body_stream.get() self.body_stream.get()
} }
fn get_mime_type(&self) -> Vec<u8> { fn get_mime_type(&self, _can_gc: CanGc) -> Vec<u8> {
let headers = self.Headers(); let headers = self.Headers();
headers.extract_mime_type() headers.extract_mime_type()
} }
@ -358,28 +358,28 @@ impl ResponseMethods for Response {
} }
// https://fetch.spec.whatwg.org/#dom-body-text // https://fetch.spec.whatwg.org/#dom-body-text
fn Text(&self) -> Rc<Promise> { fn Text(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::Text) consume_body(self, BodyType::Text, can_gc)
} }
// https://fetch.spec.whatwg.org/#dom-body-blob // https://fetch.spec.whatwg.org/#dom-body-blob
fn Blob(&self) -> Rc<Promise> { fn Blob(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::Blob) consume_body(self, BodyType::Blob, can_gc)
} }
// https://fetch.spec.whatwg.org/#dom-body-formdata // https://fetch.spec.whatwg.org/#dom-body-formdata
fn FormData(&self) -> Rc<Promise> { fn FormData(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::FormData) consume_body(self, BodyType::FormData, can_gc)
} }
// https://fetch.spec.whatwg.org/#dom-body-json // https://fetch.spec.whatwg.org/#dom-body-json
fn Json(&self) -> Rc<Promise> { fn Json(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::Json) consume_body(self, BodyType::Json, can_gc)
} }
// https://fetch.spec.whatwg.org/#dom-body-arraybuffer // https://fetch.spec.whatwg.org/#dom-body-arraybuffer
fn ArrayBuffer(&self) -> Rc<Promise> { fn ArrayBuffer(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::ArrayBuffer) consume_body(self, BodyType::ArrayBuffer, can_gc)
} }
} }

View file

@ -20,6 +20,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::storageevent::StorageEvent; use crate::dom::storageevent::StorageEvent;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::CanGc;
use crate::task_source::TaskSource; use crate::task_source::TaskSource;
#[dom_struct] #[dom_struct]
@ -222,6 +223,7 @@ impl Storage {
new_value.map(DOMString::from), new_value.map(DOMString::from),
DOMString::from(url.into_string()), DOMString::from(url.into_string()),
Some(&this), Some(&this),
CanGc::note()
); );
event.upcast::<Event>().fire(global.upcast()); event.upcast::<Event>().fire(global.upcast());
}), }),

View file

@ -82,6 +82,7 @@ impl StorageEvent {
newValue: Option<DOMString>, newValue: Option<DOMString>,
url: DOMString, url: DOMString,
storageArea: Option<&Storage>, storageArea: Option<&Storage>,
can_gc: CanGc,
) -> DomRoot<StorageEvent> { ) -> DomRoot<StorageEvent> {
Self::new_with_proto( Self::new_with_proto(
global, global,
@ -94,7 +95,7 @@ impl StorageEvent {
newValue, newValue,
url, url,
storageArea, storageArea,
CanGc::note(), can_gc,
) )
} }

View file

@ -403,8 +403,9 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
input: RequestOrUSVString, input: RequestOrUSVString,
init: RootedTraceableBox<RequestInit>, init: RootedTraceableBox<RequestInit>,
comp: InRealm, comp: InRealm,
can_gc: CanGc,
) -> Rc<Promise> { ) -> Rc<Promise> {
fetch::Fetch(self.upcast(), input, init, comp, CanGc::note()) fetch::Fetch(self.upcast(), input, init, comp, can_gc)
} }
// https://w3c.github.io/hr-time/#the-performance-attribute // https://w3c.github.io/hr-time/#the-performance-attribute

View file

@ -2010,7 +2010,7 @@ impl ScriptThread {
self.handle_msg_from_constellation(inner_msg, can_gc) self.handle_msg_from_constellation(inner_msg, can_gc)
}, },
FromScript(inner_msg) => self.handle_msg_from_script(inner_msg), FromScript(inner_msg) => self.handle_msg_from_script(inner_msg),
FromDevtools(inner_msg) => self.handle_msg_from_devtools(inner_msg), FromDevtools(inner_msg) => self.handle_msg_from_devtools(inner_msg, can_gc),
FromImageCache(inner_msg) => self.handle_msg_from_image_cache(inner_msg), FromImageCache(inner_msg) => self.handle_msg_from_image_cache(inner_msg),
FromWebGPUServer(inner_msg) => { FromWebGPUServer(inner_msg) => {
self.handle_msg_from_webgpu_server(inner_msg, can_gc) self.handle_msg_from_webgpu_server(inner_msg, can_gc)
@ -2563,7 +2563,7 @@ impl ScriptThread {
} }
} }
fn handle_msg_from_devtools(&self, msg: DevtoolScriptControlMsg) { fn handle_msg_from_devtools(&self, msg: DevtoolScriptControlMsg, can_gc: CanGc) {
let documents = self.documents.borrow(); let documents = self.documents.borrow();
match msg { match msg {
DevtoolScriptControlMsg::EvaluateJS(id, s, reply) => match documents.find_window(id) { DevtoolScriptControlMsg::EvaluateJS(id, s, reply) => match documents.find_window(id) {
@ -2602,7 +2602,7 @@ impl ScriptThread {
devtools::handle_get_computed_style(&documents, id, node_id, reply) devtools::handle_get_computed_style(&documents, id, node_id, reply)
}, },
DevtoolScriptControlMsg::GetLayout(id, node_id, reply) => { DevtoolScriptControlMsg::GetLayout(id, node_id, reply) => {
devtools::handle_get_layout(&documents, id, node_id, reply) devtools::handle_get_layout(&documents, id, node_id, reply, can_gc)
}, },
DevtoolScriptControlMsg::ModifyAttribute(id, node_id, modifications) => { DevtoolScriptControlMsg::ModifyAttribute(id, node_id, modifications) => {
devtools::handle_modify_attribute(&documents, id, node_id, modifications) devtools::handle_modify_attribute(&documents, id, node_id, modifications)