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

@ -8,13 +8,14 @@ use crate::dom::bindings::codegen::Bindings::StorageEventBinding;
use crate::dom::bindings::codegen::Bindings::StorageEventBinding::StorageEventMethods;
use crate::dom::bindings::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, MutNullableDom};
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::storage::Storage;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use js::rust::HandleObject;
use servo_atoms::Atom;
#[dom_struct]
@ -47,9 +48,14 @@ impl StorageEvent {
}
pub fn new_uninitialized(window: &Window, url: DOMString) -> DomRoot<StorageEvent> {
reflect_dom_object(
Self::new_uninitialized_with_proto(window, None, url)
}
fn new_uninitialized_with_proto(window: &Window, proto: Option<HandleObject>, url: DOMString) -> DomRoot<StorageEvent> {
reflect_dom_object2(
Box::new(StorageEvent::new_inherited(None, None, None, url, None)),
window,
proto,
)
}
@ -64,7 +70,33 @@ impl StorageEvent {
url: DOMString,
storageArea: Option<&Storage>,
) -> DomRoot<StorageEvent> {
let ev = reflect_dom_object(
Self::new_with_proto(
global,
None,
type_,
bubbles,
cancelable,
key,
oldValue,
newValue,
url,
storageArea,
)
}
fn new_with_proto(
global: &Window,
proto: Option<HandleObject>,
type_: Atom,
bubbles: EventBubbles,
cancelable: EventCancelable,
key: Option<DOMString>,
oldValue: Option<DOMString>,
newValue: Option<DOMString>,
url: DOMString,
storageArea: Option<&Storage>,
) -> DomRoot<StorageEvent> {
let ev = reflect_dom_object2(
Box::new(StorageEvent::new_inherited(
key,
oldValue,
@ -73,6 +105,7 @@ impl StorageEvent {
storageArea,
)),
global,
proto,
);
{
let event = ev.upcast::<Event>();
@ -83,6 +116,7 @@ impl StorageEvent {
pub fn Constructor(
global: &Window,
proto: Option<HandleObject>,
type_: DOMString,
init: &StorageEventBinding::StorageEventInit,
) -> Fallible<DomRoot<StorageEvent>> {
@ -93,8 +127,9 @@ impl StorageEvent {
let storageArea = init.storageArea.as_deref();
let bubbles = EventBubbles::from(init.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.cancelable);
let event = StorageEvent::new(
let event = StorageEvent::new_with_proto(
global,
proto,
Atom::from(type_),
bubbles,
cancelable,