Support arbitrary protos when wrapping DOM objects with constructors.

This commit is contained in:
Josh Matthews 2023-05-28 22:43:55 -04:00
parent d9600ff50f
commit dbff26bce0
197 changed files with 2028 additions and 586 deletions

View file

@ -5,7 +5,7 @@
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::URLBinding::URLMethods;
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::reflector::{reflect_dom_object2, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::blob::Blob;
@ -13,6 +13,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::urlhelper::UrlHelper;
use crate::dom::urlsearchparams::URLSearchParams;
use dom_struct::dom_struct;
use js::rust::HandleObject;
use net_traits::blob_url_store::{get_blob_origin, parse_blob_url};
use net_traits::filemanager_thread::FileManagerThreadMsg;
use net_traits::{CoreResourceMsg, IpcSend};
@ -42,8 +43,8 @@ impl URL {
}
}
pub fn new(global: &GlobalScope, url: ServoUrl) -> DomRoot<URL> {
reflect_dom_object(Box::new(URL::new_inherited(url)), global)
fn new(global: &GlobalScope, proto: Option<HandleObject>, url: ServoUrl) -> DomRoot<URL> {
reflect_dom_object2(Box::new(URL::new_inherited(url)), global, proto)
}
pub fn query_pairs(&self) -> Vec<(String, String)> {
@ -74,6 +75,7 @@ impl URL {
// https://url.spec.whatwg.org/#constructors
pub fn Constructor(
global: &GlobalScope,
proto: Option<HandleObject>,
url: USVString,
base: Option<USVString>,
) -> Fallible<DomRoot<URL>> {
@ -108,7 +110,7 @@ impl URL {
// Step 7. Set thiss query objects URL object to this.
// Step 4. Set thiss URL to parsedURL.
Ok(URL::new(global, parsed_url))
Ok(URL::new(global, proto, parsed_url))
}
// https://url.spec.whatwg.org/#dom-url-canparse