Files
moli/moli-webapi/src/dom_parser_values.rs
T

41 lines
1.5 KiB
Rust

//! Parser construction keeps its creation realm witness in the V8 heap.
//! Parsing and native Document creation remain embedding operations.
use crate::interfaces;
use moli_v8_util::throw_type_error;
use moli_webapi_declare::WebApiObject;
pub const DOM_PARSER_CONSTRUCTION_REALM_SLOT: &str = "__moliDomParserConstructionRealm";
#[derive(WebApiObject)]
#[webapi(interface = interfaces::DOMParser)]
struct DomParserObjectDeclaration<'s> {
#[webapi(slot = DOM_PARSER_CONSTRUCTION_REALM_SLOT)]
creation_realm: v8::Local<'s, v8::Object>,
}
pub fn dom_parser_constructor_callback<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
if !args.is_construct_call() {
throw_type_error(scope, "DOMParser constructor must be called with new");
return;
}
initialize_dom_parser_object(scope, args.this());
rv.set(args.this().into());
}
pub fn initialize_dom_parser_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
parser: v8::Local<'s, v8::Object>,
) {
// The constructor's Window is independent of newTarget.prototype. Keep
// a V8-traced creation-Realm witness, not a native persistent Context root
// or a WindowProxy that can be rebound to another Window on navigation.
let realm = moli_v8_util::new_null_prototype_object(scope);
DomParserObjectDeclaration::new(realm)
.initialize(scope, parser)
.expect("DOMParser state should initialize");
}