From dbff26bce05d404027ef5bbfd85fb5995e4726bc Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sun, 28 May 2023 22:43:55 -0400 Subject: Support arbitrary protos when wrapping DOM objects with constructors. --- components/script/dom/file.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'components/script/dom/file.rs') diff --git a/components/script/dom/file.rs b/components/script/dom/file.rs index cbbc16bd264..946677d5b35 100644 --- a/components/script/dom/file.rs +++ b/components/script/dom/file.rs @@ -7,13 +7,14 @@ use crate::dom::bindings::codegen::Bindings::FileBinding::FileMethods; use crate::dom::bindings::codegen::UnionTypes::ArrayBufferOrArrayBufferViewOrBlobOrString; use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::inheritance::Castable; -use crate::dom::bindings::reflector::reflect_dom_object; +use crate::dom::bindings::reflector::reflect_dom_object2; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::DOMString; use crate::dom::blob::{blob_parts_to_bytes, normalize_type_string, Blob}; use crate::dom::globalscope::GlobalScope; use crate::dom::window::Window; use dom_struct::dom_struct; +use js::rust::HandleObject; use net_traits::filemanager_thread::SelectedFile; use script_traits::serializable::BlobImpl; @@ -41,16 +42,27 @@ impl File { } } - #[allow(unrooted_must_root)] pub fn new( global: &GlobalScope, blob_impl: BlobImpl, name: DOMString, modified: Option, ) -> DomRoot { - let file = reflect_dom_object( + Self::new_with_proto(global, None, blob_impl, name, modified) + } + + #[allow(unrooted_must_root)] + fn new_with_proto( + global: &GlobalScope, + proto: Option, + blob_impl: BlobImpl, + name: DOMString, + modified: Option, + ) -> DomRoot { + let file = reflect_dom_object2( Box::new(File::new_inherited(&blob_impl, name, modified)), global, + proto, ); global.track_file(&file, blob_impl); file @@ -82,6 +94,7 @@ impl File { #[allow(non_snake_case)] pub fn Constructor( global: &GlobalScope, + proto: Option, fileBits: Vec, filename: DOMString, filePropertyBag: &FileBinding::FilePropertyBag, @@ -98,8 +111,9 @@ impl File { // see https://github.com/w3c/FileAPI/issues/41 let replaced_filename = DOMString::from_string(filename.replace("/", ":")); let type_string = normalize_type_string(&blobPropertyBag.type_.to_string()); - Ok(File::new( + Ok(File::new_with_proto( global, + proto, BlobImpl::new_from_bytes(bytes, type_string), replaced_filename, modified, -- cgit v1.2.3