mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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:
parent
6b87ecc291
commit
fde8d72aca
13 changed files with 77 additions and 58 deletions
|
@ -715,7 +715,11 @@ impl Callback for ConsumeBodyPromiseHandler {
|
|||
|
||||
// https://fetch.spec.whatwg.org/#concept-body-consume-body
|
||||
#[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 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,
|
||||
promise.clone(),
|
||||
InRealm::Already(&in_realm_proof),
|
||||
can_gc,
|
||||
);
|
||||
|
||||
promise
|
||||
|
@ -744,6 +749,7 @@ fn consume_body_with_promise<T: BodyMixin + DomObject>(
|
|||
body_type: BodyType,
|
||||
promise: Rc<Promise>,
|
||||
comp: InRealm,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
let global = object.global();
|
||||
|
||||
|
@ -771,7 +777,7 @@ fn consume_body_with_promise<T: BodyMixin + DomObject>(
|
|||
result_promise: promise.clone(),
|
||||
stream: Some(stream),
|
||||
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.
|
||||
bytes: DomRefCell::new(Some(vec![])),
|
||||
});
|
||||
|
@ -913,5 +919,5 @@ pub trait BodyMixin {
|
|||
/// <https://fetch.spec.whatwg.org/#concept-body-locked>
|
||||
fn is_locked(&self) -> bool;
|
||||
/// <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>;
|
||||
}
|
||||
|
|
|
@ -328,6 +328,7 @@ pub fn handle_get_layout(
|
|||
pipeline: PipelineId,
|
||||
node_id: String,
|
||||
reply: IpcSender<Option<ComputedNodeLayout>>,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
let node = match find_node_by_unique_id(documents, pipeline, &node_id) {
|
||||
None => return reply.send(None).unwrap(),
|
||||
|
@ -337,7 +338,7 @@ pub fn handle_get_layout(
|
|||
let elem = node
|
||||
.downcast::<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 height = rect.Height() as f32;
|
||||
|
||||
|
|
|
@ -427,10 +427,14 @@ impl BaseAudioContextMethods for BaseAudioContext {
|
|||
}
|
||||
|
||||
/// <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();
|
||||
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>
|
||||
|
|
|
@ -25,7 +25,7 @@ DOMInterfaces = {
|
|||
|
||||
'BaseAudioContext': {
|
||||
'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': {
|
||||
|
@ -213,9 +213,12 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
'Response': {
|
||||
'canGc': ['Error', 'Redirect', 'Clone'],
|
||||
'canGc': ['Error', 'Redirect', 'Clone', 'Text', 'Blob', 'FormData', 'Json', 'ArrayBuffer'],
|
||||
},
|
||||
|
||||
'Request': {
|
||||
'canGc': ['Headers', 'Text', 'Blob', 'FormData', 'Json', 'ArrayBuffer', 'Clone'],
|
||||
},
|
||||
|
||||
'Selection': {
|
||||
'canGc': ['Collapse', 'CollapseToEnd', 'CollapseToStart', 'Extend', 'SelectAllChildren', 'SetBaseAndExtent', 'SetPosition'],
|
||||
|
@ -261,6 +264,7 @@ DOMInterfaces = {
|
|||
|
||||
'WorkerGlobalScope': {
|
||||
'inRealms': ['Fetch'],
|
||||
'canGc': ['Fetch'],
|
||||
},
|
||||
|
||||
'Worklet': {
|
||||
|
|
|
@ -63,8 +63,9 @@ impl ChannelSplitterNode {
|
|||
window: &Window,
|
||||
context: &BaseAudioContext,
|
||||
options: &ChannelSplitterOptions,
|
||||
can_gc: CanGc,
|
||||
) -> 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)]
|
||||
|
|
|
@ -33,15 +33,10 @@ impl FormDataEvent {
|
|||
can_bubble: EventBubbles,
|
||||
cancelable: EventCancelable,
|
||||
form_data: &FormData,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<FormDataEvent> {
|
||||
Self::new_with_proto(
|
||||
global,
|
||||
None,
|
||||
type_,
|
||||
can_bubble,
|
||||
cancelable,
|
||||
form_data,
|
||||
CanGc::note(),
|
||||
global, None, type_, can_bubble, cancelable, form_data, can_gc,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1214,6 +1214,7 @@ impl HTMLFormElement {
|
|||
EventBubbles::Bubbles,
|
||||
EventCancelable::NotCancelable,
|
||||
&form_data,
|
||||
can_gc,
|
||||
);
|
||||
|
||||
event.upcast::<Event>().fire(self.upcast::<EventTarget>());
|
||||
|
|
|
@ -88,7 +88,7 @@ impl Request {
|
|||
fn clone_from(r: &Request, can_gc: CanGc) -> Fallible<DomRoot<Request>> {
|
||||
let req = r.request.borrow();
|
||||
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);
|
||||
r_clone.request.borrow_mut().pipeline_id = req.pipeline_id;
|
||||
{
|
||||
|
@ -96,8 +96,10 @@ impl Request {
|
|||
borrowed_r_request.origin = req.origin.clone();
|
||||
}
|
||||
*r_clone.request.borrow_mut() = req.clone();
|
||||
r_clone.Headers().copy_from_headers(r.Headers())?;
|
||||
r_clone.Headers().set_guard(headers_guard);
|
||||
r_clone
|
||||
.Headers(can_gc)
|
||||
.copy_from_headers(r.Headers(can_gc))?;
|
||||
r_clone.Headers(can_gc).set_guard(headers_guard);
|
||||
Ok(r_clone)
|
||||
}
|
||||
|
||||
|
@ -384,7 +386,7 @@ impl RequestMethods for Request {
|
|||
// "or_init" looks unclear here, but it always enters the block since r
|
||||
// hasn't had any other way to initialize its 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?
|
||||
let headers_copy = init
|
||||
|
@ -419,7 +421,7 @@ impl RequestMethods for Request {
|
|||
));
|
||||
}
|
||||
// Step 32.2
|
||||
r.Headers().set_guard(Guard::RequestNoCors);
|
||||
r.Headers(can_gc).set_guard(Guard::RequestNoCors);
|
||||
}
|
||||
|
||||
// Step 33.5
|
||||
|
@ -430,15 +432,16 @@ impl RequestMethods for Request {
|
|||
// but an input with headers is given, set request's
|
||||
// headers as the input's Headers.
|
||||
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
|
||||
// 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
|
||||
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() {
|
||||
let ct_header_name = b"Content-Type";
|
||||
if !r
|
||||
.Headers()
|
||||
.Headers(can_gc)
|
||||
.Has(ByteString::new(ct_header_name.to_vec()))
|
||||
.unwrap()
|
||||
{
|
||||
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_val.to_vec()),
|
||||
)?;
|
||||
|
@ -536,9 +539,9 @@ impl RequestMethods for Request {
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-request-headers
|
||||
fn Headers(&self) -> DomRoot<Headers> {
|
||||
fn Headers(&self, can_gc: CanGc) -> DomRoot<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
|
||||
|
@ -608,7 +611,7 @@ impl RequestMethods for Request {
|
|||
}
|
||||
|
||||
// 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
|
||||
if request_is_locked(self) {
|
||||
return Err(Error::Type("Request is locked".to_string()));
|
||||
|
@ -618,32 +621,32 @@ impl RequestMethods for Request {
|
|||
}
|
||||
|
||||
// Step 2
|
||||
Request::clone_from(self, CanGc::note())
|
||||
Request::clone_from(self, can_gc)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-text
|
||||
fn Text(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Text)
|
||||
fn Text(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Text, can_gc)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-blob
|
||||
fn Blob(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Blob)
|
||||
fn Blob(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Blob, can_gc)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-formdata
|
||||
fn FormData(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::FormData)
|
||||
fn FormData(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::FormData, can_gc)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-json
|
||||
fn Json(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Json)
|
||||
fn Json(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Json, can_gc)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-arraybuffer
|
||||
fn ArrayBuffer(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::ArrayBuffer)
|
||||
fn ArrayBuffer(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::ArrayBuffer, can_gc)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -664,8 +667,8 @@ impl BodyMixin for Request {
|
|||
self.body_stream.get()
|
||||
}
|
||||
|
||||
fn get_mime_type(&self) -> Vec<u8> {
|
||||
let headers = self.Headers();
|
||||
fn get_mime_type(&self, can_gc: CanGc) -> Vec<u8> {
|
||||
let headers = self.Headers(can_gc);
|
||||
headers.extract_mime_type()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ impl BodyMixin for Response {
|
|||
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();
|
||||
headers.extract_mime_type()
|
||||
}
|
||||
|
@ -358,28 +358,28 @@ impl ResponseMethods for Response {
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-text
|
||||
fn Text(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Text)
|
||||
fn Text(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Text, can_gc)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-blob
|
||||
fn Blob(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Blob)
|
||||
fn Blob(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Blob, can_gc)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-formdata
|
||||
fn FormData(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::FormData)
|
||||
fn FormData(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::FormData, can_gc)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-json
|
||||
fn Json(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Json)
|
||||
fn Json(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::Json, can_gc)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#dom-body-arraybuffer
|
||||
fn ArrayBuffer(&self) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::ArrayBuffer)
|
||||
fn ArrayBuffer(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
consume_body(self, BodyType::ArrayBuffer, can_gc)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ use crate::dom::bindings::str::DOMString;
|
|||
use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use crate::dom::storageevent::StorageEvent;
|
||||
use crate::dom::window::Window;
|
||||
use crate::script_runtime::CanGc;
|
||||
use crate::task_source::TaskSource;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -222,6 +223,7 @@ impl Storage {
|
|||
new_value.map(DOMString::from),
|
||||
DOMString::from(url.into_string()),
|
||||
Some(&this),
|
||||
CanGc::note()
|
||||
);
|
||||
event.upcast::<Event>().fire(global.upcast());
|
||||
}),
|
||||
|
|
|
@ -82,6 +82,7 @@ impl StorageEvent {
|
|||
newValue: Option<DOMString>,
|
||||
url: DOMString,
|
||||
storageArea: Option<&Storage>,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<StorageEvent> {
|
||||
Self::new_with_proto(
|
||||
global,
|
||||
|
@ -94,7 +95,7 @@ impl StorageEvent {
|
|||
newValue,
|
||||
url,
|
||||
storageArea,
|
||||
CanGc::note(),
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -403,8 +403,9 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
|||
input: RequestOrUSVString,
|
||||
init: RootedTraceableBox<RequestInit>,
|
||||
comp: InRealm,
|
||||
can_gc: CanGc,
|
||||
) -> 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
|
||||
|
|
|
@ -2010,7 +2010,7 @@ impl ScriptThread {
|
|||
self.handle_msg_from_constellation(inner_msg, can_gc)
|
||||
},
|
||||
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),
|
||||
FromWebGPUServer(inner_msg) => {
|
||||
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();
|
||||
match msg {
|
||||
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)
|
||||
},
|
||||
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) => {
|
||||
devtools::handle_modify_attribute(&documents, id, node_id, modifications)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue