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

@ -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,