aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/file.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2023-05-28 22:43:55 -0400
committerJosh Matthews <josh@joshmatthews.net>2023-05-28 23:23:12 -0400
commitdbff26bce05d404027ef5bbfd85fb5995e4726bc (patch)
tree6ebb631eef396c2f387fe8269b0d59bde0dccae2 /components/script/dom/file.rs
parentd9600ff50f3c1bdd8c44e2dfc15a18416d80cb82 (diff)
downloadservo-dbff26bce05d404027ef5bbfd85fb5995e4726bc.tar.gz
servo-dbff26bce05d404027ef5bbfd85fb5995e4726bc.zip
Support arbitrary protos when wrapping DOM objects with constructors.
Diffstat (limited to 'components/script/dom/file.rs')
-rw-r--r--components/script/dom/file.rs22
1 files changed, 18 insertions, 4 deletions
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<i64>,
) -> DomRoot<File> {
- 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<HandleObject>,
+ blob_impl: BlobImpl,
+ name: DOMString,
+ modified: Option<i64>,
+ ) -> DomRoot<File> {
+ 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<HandleObject>,
fileBits: Vec<ArrayBufferOrArrayBufferViewOrBlobOrString>,
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,