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

@ -26,7 +26,7 @@ use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::{Castable, CharacterDataTypeId, ElementTypeId};
use crate::dom::bindings::inheritance::{EventTargetTypeId, HTMLElementTypeId, NodeTypeId};
use crate::dom::bindings::inheritance::{SVGElementTypeId, SVGGraphicsElementTypeId, TextTypeId};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, DomObjectWrap};
use crate::dom::bindings::reflector::{reflect_dom_object2, DomObject, DomObjectWrap};
use crate::dom::bindings::root::{Dom, DomRoot, DomSlice, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::bindings::xmlname::namespace_from_domstring;
@ -70,6 +70,7 @@ use dom_struct::dom_struct;
use euclid::default::{Point2D, Rect, Size2D, Vector2D};
use html5ever::{Namespace, Prefix, QualName};
use js::jsapi::JSObject;
use js::rust::HandleObject;
use libc::{self, c_void, uintptr_t};
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use msg::constellation_msg::{BrowsingContextId, PipelineId};
@ -1753,11 +1754,18 @@ fn as_uintptr<T>(t: &T) -> uintptr_t {
impl Node {
pub fn reflect_node<N>(node: Box<N>, document: &Document) -> DomRoot<N>
where
N: DerivedFrom<Node> + DomObject + DomObjectWrap,
{
Self::reflect_node_with_proto(node, document, None)
}
pub fn reflect_node_with_proto<N>(node: Box<N>, document: &Document, proto: Option<HandleObject>) -> DomRoot<N>
where
N: DerivedFrom<Node> + DomObject + DomObjectWrap,
{
let window = document.window();
reflect_dom_object(node, window)
reflect_dom_object2(node, window, proto)
}
pub fn new_inherited(doc: &Document) -> Node {
@ -2290,6 +2298,7 @@ impl Node {
&document,
ElementCreator::ScriptCreated,
CustomElementCreationMode::Asynchronous,
None,
);
DomRoot::upcast::<Node>(element)
},