Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor(webapi): replace legacy brands with generated receiver checks

ldm0967a0d03d80b
diff --git a/moli-renderer-v8/src/blob.rs b/moli-renderer-v8/src/blob.rs
index d71dcb029..6da24d293 100644
--- a/moli-renderer-v8/src/blob.rs
+++ b/moli-renderer-v8/src/blob.rs
@@ -315,7 +315,7 @@ pub(super) fn is_blob_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- blob_id_from_object(scope, object).is_some()
+ moli_webapi_declare::implements_interface(scope, object, "Blob")
}
pub(super) fn blob_mime_type_from_object<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap.rs b/moli-renderer-v8/src/context_bootstrap.rs
index 7df5b7c03..8fd68e1d7 100644
--- a/moli-renderer-v8/src/context_bootstrap.rs
+++ b/moli-renderer-v8/src/context_bootstrap.rs
@@ -436,7 +436,6 @@ pub(crate) use self::trusted_types::{
trusted_script_url_string_or_throw, trusted_types_code_generation_check,
trusted_types_code_generation_check_callback,
};
-pub(crate) use self::url_form::object_prototype_matches;
pub(crate) use self::url_search_params_runtime::url_search_params_request_body;
pub(crate) use self::web_storage::install_storage_aliases_for_window;
pub use self::web_storage::{
diff --git a/moli-renderer-v8/src/context_bootstrap/animation_runtime.rs b/moli-renderer-v8/src/context_bootstrap/animation_runtime.rs
index f4aac606f..2e56aeeb9 100644
--- a/moli-renderer-v8/src/context_bootstrap/animation_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/animation_runtime.rs
@@ -274,7 +274,7 @@ fn require_animation_receiver<'s>(
receiver: v8::Local<'s, v8::Object>,
member: &str,
) -> bool {
- if get_private_value(scope, receiver, ANIMATION_PLAY_STATE_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, "Animation") {
return true;
}
throw_type_error(
diff --git a/moli-renderer-v8/src/context_bootstrap/broadcast_channel.rs b/moli-renderer-v8/src/context_bootstrap/broadcast_channel.rs
index a7c0c9383..d5a2e90e4 100644
--- a/moli-renderer-v8/src/context_bootstrap/broadcast_channel.rs
+++ b/moli-renderer-v8/src/context_bootstrap/broadcast_channel.rs
@@ -19,7 +19,6 @@ use crate::{
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
const BROADCAST_CHANNEL_ID_SLOT: &str = "__lmBroadcastChannelId";
-const BROADCAST_CHANNEL_BRAND_SLOT: &str = "__lmBroadcastChannelBrand";
const BROADCAST_CHANNEL_NAME_SLOT: &str = "__lmBroadcastChannelName";
const BROADCAST_CHANNEL_CLOSED_SLOT: &str = "__lmBroadcastChannelClosed";
const BROADCAST_CHANNEL_LISTENERS_SLOT: &str = "__lmBroadcastChannelListeners";
@@ -29,9 +28,6 @@ const BROADCAST_CHANNEL_ONMESSAGEERROR_SLOT: &str = "__lmBroadcastChannelOnmessa
#[derive(WebApiObject)]
#[webapi(interface = "BroadcastChannel")]
struct BroadcastChannelObjectDeclaration<'scope> {
- #[webapi(slot = BROADCAST_CHANNEL_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = BROADCAST_CHANNEL_ID_SLOT)]
channel_id: v8::Local<'scope, v8::Value>,
@@ -348,8 +344,7 @@ fn broadcast_channel_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, BROADCAST_CHANNEL_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "BroadcastChannel")
}
fn broadcast_channel_event_target_add_event_listener_callback<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/canvas.rs b/moli-renderer-v8/src/context_bootstrap/canvas.rs
index 80fa5ee79..b55ad2594 100644
--- a/moli-renderer-v8/src/context_bootstrap/canvas.rs
+++ b/moli-renderer-v8/src/context_bootstrap/canvas.rs
@@ -119,7 +119,7 @@ const WEBGL_SUPPORTED_EXTENSIONS: &[&str] = &[
];
#[derive(WebApiFunctionTemplate)]
-#[webapi(name = "HTMLCanvasElement", receiver = crate::native_bridge::receivers::html_canvas_element)]
+#[webapi(name = "HTMLCanvasElement", receiver = "HTMLCanvasElement")]
struct HtmlCanvasElementPrototypeAccessorsDeclaration {
#[webapi(
accessor_property,
diff --git a/moli-renderer-v8/src/context_bootstrap/canvas/context2d.rs b/moli-renderer-v8/src/context_bootstrap/canvas/context2d.rs
index 3e5ccca4b..8566352b4 100644
--- a/moli-renderer-v8/src/context_bootstrap/canvas/context2d.rs
+++ b/moli-renderer-v8/src/context_bootstrap/canvas/context2d.rs
@@ -307,7 +307,13 @@ fn require_canvas_context_receiver<'s>(
receiver: v8::Local<'s, v8::Object>,
member: &str,
) -> bool {
- if get_private_value(scope, receiver, CANVAS_CONTEXT_FILL_STYLE_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, "CanvasRenderingContext2D")
+ || moli_webapi_declare::implements_interface(
+ scope,
+ receiver,
+ "OffscreenCanvasRenderingContext2D",
+ )
+ {
return true;
}
throw_type_error(
diff --git a/moli-renderer-v8/src/context_bootstrap/canvas/image_bitmap.rs b/moli-renderer-v8/src/context_bootstrap/canvas/image_bitmap.rs
index adfc4de35..9d1539b4b 100644
--- a/moli-renderer-v8/src/context_bootstrap/canvas/image_bitmap.rs
+++ b/moli-renderer-v8/src/context_bootstrap/canvas/image_bitmap.rs
@@ -7,7 +7,6 @@ use crate::util::{
};
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
-const IMAGE_BITMAP_BRAND_SLOT: &str = "__moliImageBitmapBrand";
const IMAGE_BITMAP_WIDTH_SLOT: &str = "__moliImageBitmapWidth";
const IMAGE_BITMAP_HEIGHT_SLOT: &str = "__moliImageBitmapHeight";
@@ -16,8 +15,6 @@ const IMAGE_BITMAP_DIMENSION_SLOTS: &[&str] = &[IMAGE_BITMAP_WIDTH_SLOT, IMAGE_B
#[derive(WebApiObject)]
#[webapi(interface = "ImageBitmap")]
struct ImageBitmapObjectDeclaration {
- #[webapi(slot = IMAGE_BITMAP_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = IMAGE_BITMAP_WIDTH_SLOT)]
width: f64,
#[webapi(slot = IMAGE_BITMAP_HEIGHT_SLOT)]
@@ -183,6 +180,5 @@ fn image_bitmap_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, IMAGE_BITMAP_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "ImageBitmap")
}
diff --git a/moli-renderer-v8/src/context_bootstrap/canvas/offscreen.rs b/moli-renderer-v8/src/context_bootstrap/canvas/offscreen.rs
index fed9164f3..fb8f168dd 100644
--- a/moli-renderer-v8/src/context_bootstrap/canvas/offscreen.rs
+++ b/moli-renderer-v8/src/context_bootstrap/canvas/offscreen.rs
@@ -9,16 +9,12 @@ use crate::util::{
use crate::webidl;
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
-const OFFSCREEN_CANVAS_BRAND_SLOT: &str = "__moliOffscreenCanvasBrand";
const OFFSCREEN_CANVAS_CONTEXT_SLOT: &str = "__moliOffscreenCanvasContext";
const OFFSCREEN_CANVAS_CONTEXT_KIND_SLOT: &str = "__moliOffscreenCanvasContextKind";
#[derive(WebApiObject)]
#[webapi(interface = "OffscreenCanvas")]
struct OffscreenCanvasObjectDeclaration {
- #[webapi(slot = OFFSCREEN_CANVAS_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = OFFSCREEN_CANVAS_WIDTH_SLOT)]
width: f64,
#[webapi(slot = OFFSCREEN_CANVAS_HEIGHT_SLOT)]
@@ -232,6 +228,5 @@ pub(super) fn offscreen_canvas_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, OFFSCREEN_CANVAS_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "OffscreenCanvas")
}
diff --git a/moli-renderer-v8/src/context_bootstrap/canvas/webgl.rs b/moli-renderer-v8/src/context_bootstrap/canvas/webgl.rs
index edf430596..ab185f2d1 100644
--- a/moli-renderer-v8/src/context_bootstrap/canvas/webgl.rs
+++ b/moli-renderer-v8/src/context_bootstrap/canvas/webgl.rs
@@ -6,13 +6,11 @@ use crate::{
};
use moli_webapi_declare::{WebApiObject, WebApiValue};
-const WEBGL_HANDLE_KIND_SLOT: &str = "__moliWebGlHandleKind";
const WEBGL_VIEWPORT_SLOT: &str = "__moliWebGlViewport";
const WEBGL_ERROR_SLOT: &str = "__moliWebGlError";
const WEBGL_VIEWPORT: u32 = 0x0BA2;
const WEBGL_INVALID_VALUE: u32 = 0x0501;
const WEBGL_MAX_VIEWPORT_DIMS: [i32; 2] = [8192, 8192];
-const WEBGL2_CONTEXT_BRAND_SLOT: &str = "__moliWebGl2ContextBrand";
const WEBGL2_DRAWING_BUFFER_COLOR_SPACE_SLOT: &str = "__moliWebGl2DrawingBufferColorSpace";
const WEBGL2_UNPACK_COLOR_SPACE_SLOT: &str = "__moliWebGl2UnpackColorSpace";
const WEBGL2_COLOR_SPACE_SLOTS: &[&str] = &[
@@ -90,61 +88,56 @@ struct WebGl2GetInternalformatParameterArgs {
}
#[derive(WebApiObject)]
-#[webapi(interface = "WebGLBuffer", fallback_to_string_tag = "WebGLBuffer")]
-struct WebGlBufferHandleDeclaration {
- #[webapi(slot = WEBGL_HANDLE_KIND_SLOT)]
- kind: &'static str,
-}
+#[webapi(
+ allow_empty,
+ interface = "WebGLBuffer",
+ fallback_to_string_tag = "WebGLBuffer"
+)]
+struct WebGlBufferHandleDeclaration {}
#[derive(WebApiObject)]
-#[webapi(interface = "WebGLProgram", fallback_to_string_tag = "WebGLProgram")]
-struct WebGlProgramHandleDeclaration {
- #[webapi(slot = WEBGL_HANDLE_KIND_SLOT)]
- kind: &'static str,
-}
+#[webapi(
+ allow_empty,
+ interface = "WebGLProgram",
+ fallback_to_string_tag = "WebGLProgram"
+)]
+struct WebGlProgramHandleDeclaration {}
#[derive(WebApiObject)]
-#[webapi(interface = "WebGLShader", fallback_to_string_tag = "WebGLShader")]
-struct WebGlShaderHandleDeclaration {
- #[webapi(slot = WEBGL_HANDLE_KIND_SLOT)]
- kind: &'static str,
-}
+#[webapi(
+ allow_empty,
+ interface = "WebGLShader",
+ fallback_to_string_tag = "WebGLShader"
+)]
+struct WebGlShaderHandleDeclaration {}
#[derive(WebApiObject)]
#[webapi(
+ allow_empty,
interface = "WebGLUniformLocation",
fallback_to_string_tag = "WebGLUniformLocation"
)]
-struct WebGlUniformLocationHandleDeclaration {
- #[webapi(slot = WEBGL_HANDLE_KIND_SLOT)]
- kind: &'static str,
-}
+struct WebGlUniformLocationHandleDeclaration {}
#[derive(WebApiObject)]
#[webapi(
+ allow_empty,
interface = "WebGLFramebuffer",
fallback_to_string_tag = "WebGLFramebuffer"
)]
-struct WebGlFramebufferHandleDeclaration {
- #[webapi(slot = WEBGL_HANDLE_KIND_SLOT)]
- kind: &'static str,
-}
+struct WebGlFramebufferHandleDeclaration {}
#[derive(WebApiObject)]
#[webapi(
+ allow_empty,
interface = "WebGLRenderbuffer",
fallback_to_string_tag = "WebGLRenderbuffer"
)]
-struct WebGlRenderbufferHandleDeclaration {
- #[webapi(slot = WEBGL_HANDLE_KIND_SLOT)]
- kind: &'static str,
-}
+struct WebGlRenderbufferHandleDeclaration {}
#[derive(WebApiObject)]
#[webapi(interface = "WebGL2RenderingContext")]
struct WebGl2ContextObjectDeclaration {
- #[webapi(slot = WEBGL2_CONTEXT_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = WEBGL2_DRAWING_BUFFER_COLOR_SPACE_SLOT)]
drawing_buffer_color_space: String,
#[webapi(slot = WEBGL2_UNPACK_COLOR_SPACE_SLOT)]
@@ -512,7 +505,7 @@ pub(crate) fn webgl_create_buffer_callback(
_args: v8::FunctionCallbackArguments<'_>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- let value = WebGlBufferHandleDeclaration { kind: "buffer" }
+ let value = WebGlBufferHandleDeclaration::new()
.bind(scope)
.expect("WebGLBuffer handle declaration should bind");
rv.set(value.into());
@@ -523,11 +516,9 @@ pub(crate) fn webgl_create_framebuffer_callback(
_args: v8::FunctionCallbackArguments<'_>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- let value = WebGlFramebufferHandleDeclaration {
- kind: "framebuffer",
- }
- .bind(scope)
- .expect("WebGLFramebuffer handle declaration should bind");
+ let value = WebGlFramebufferHandleDeclaration::new()
+ .bind(scope)
+ .expect("WebGLFramebuffer handle declaration should bind");
rv.set(value.into());
}
@@ -536,11 +527,9 @@ pub(crate) fn webgl_create_renderbuffer_callback(
_args: v8::FunctionCallbackArguments<'_>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- let value = WebGlRenderbufferHandleDeclaration {
- kind: "renderbuffer",
- }
- .bind(scope)
- .expect("WebGLRenderbuffer handle declaration should bind");
+ let value = WebGlRenderbufferHandleDeclaration::new()
+ .bind(scope)
+ .expect("WebGLRenderbuffer handle declaration should bind");
rv.set(value.into());
}
@@ -557,7 +546,7 @@ pub(crate) fn webgl_create_program_callback(
_args: v8::FunctionCallbackArguments<'_>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- let value = WebGlProgramHandleDeclaration { kind: "program" }
+ let value = WebGlProgramHandleDeclaration::new()
.bind(scope)
.expect("WebGLProgram handle declaration should bind");
rv.set(value.into());
@@ -568,7 +557,7 @@ pub(crate) fn webgl_create_shader_callback(
_args: v8::FunctionCallbackArguments<'_>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- let value = WebGlShaderHandleDeclaration { kind: "shader" }
+ let value = WebGlShaderHandleDeclaration::new()
.bind(scope)
.expect("WebGLShader handle declaration should bind");
rv.set(value.into());
@@ -579,11 +568,9 @@ pub(crate) fn webgl_uniform_location_callback(
_args: v8::FunctionCallbackArguments<'_>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- let value = WebGlUniformLocationHandleDeclaration {
- kind: "uniformLocation",
- }
- .bind(scope)
- .expect("WebGLUniformLocation handle declaration should bind");
+ let value = WebGlUniformLocationHandleDeclaration::new()
+ .bind(scope)
+ .expect("WebGLUniformLocation handle declaration should bind");
rv.set(value.into());
}
@@ -841,8 +828,7 @@ fn is_webgl2_context<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, object, WEBGL2_CONTEXT_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, object, "WebGL2RenderingContext")
}
pub(crate) fn webgl2_color_space_getter_callback<'s>(
@@ -850,7 +836,7 @@ pub(crate) fn webgl2_color_space_getter_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- if get_private_value(scope, args.this(), WEBGL2_CONTEXT_BRAND_SLOT).is_none() {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "WebGL2RenderingContext") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -879,7 +865,7 @@ pub(crate) fn webgl2_color_space_setter_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- if get_private_value(scope, args.this(), WEBGL2_CONTEXT_BRAND_SLOT).is_none() {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "WebGL2RenderingContext") {
throw_type_error(scope, "Illegal invocation");
return;
}
diff --git a/moli-renderer-v8/src/context_bootstrap/constructors/dom_exception.rs b/moli-renderer-v8/src/context_bootstrap/constructors/dom_exception.rs
index 80dc62d44..6c7030574 100644
--- a/moli-renderer-v8/src/context_bootstrap/constructors/dom_exception.rs
+++ b/moli-renderer-v8/src/context_bootstrap/constructors/dom_exception.rs
@@ -3,17 +3,13 @@ use crate::{util::get_private_value, webidl};
use moli_web_errors::{DOM_EXCEPTION_CONSTANTS, dom_exception_legacy_code};
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject, WebApiTemplateValue};
-const DOM_EXCEPTION_BRAND_SLOT: &str = "__lmDomExceptionBrand";
const DOM_EXCEPTION_MESSAGE_SLOT: &str = "__lmDomExceptionMessage";
const DOM_EXCEPTION_NAME_SLOT: &str = "__lmDomExceptionName";
const DOM_EXCEPTION_CODE_SLOT: &str = "__lmDomExceptionCode";
-const DOM_ERROR_BRAND_SLOT: &str = "__lmDomErrorBrand";
const DOM_ERROR_MESSAGE_SLOT: &str = "__lmDomErrorMessage";
const DOM_ERROR_NAME_SLOT: &str = "__lmDomErrorName";
-const QUOTA_EXCEEDED_ERROR_BRAND_SLOT: &str = "__lmQuotaExceededErrorBrand";
const QUOTA_EXCEEDED_ERROR_QUOTA_SLOT: &str = "__lmQuotaExceededErrorQuota";
const QUOTA_EXCEEDED_ERROR_REQUESTED_SLOT: &str = "__lmQuotaExceededErrorRequested";
-const WEBSOCKET_ERROR_BRAND_SLOT: &str = "__lmWebSocketErrorBrand";
const WEBSOCKET_ERROR_CLOSE_CODE_SLOT: &str = "__lmWebSocketErrorCloseCode";
const WEBSOCKET_ERROR_REASON_SLOT: &str = "__lmWebSocketErrorReason";
@@ -61,8 +57,6 @@ struct QuotaExceededErrorConstructorArgs {
#[derive(WebApiObject)]
#[webapi(interface = "DOMException")]
struct DomExceptionObjectDeclaration<'scope> {
- #[webapi(slot = DOM_EXCEPTION_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = DOM_EXCEPTION_MESSAGE_SLOT)]
message: Option<v8::Local<'scope, v8::String>>,
#[webapi(slot = DOM_EXCEPTION_NAME_SLOT)]
@@ -74,8 +68,6 @@ struct DomExceptionObjectDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "DOMError", fallback_to_string_tag = "DOMError")]
struct DomErrorObjectDeclaration<'scope> {
- #[webapi(slot = DOM_ERROR_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = DOM_ERROR_NAME_SLOT)]
name: Option<v8::Local<'scope, v8::String>>,
#[webapi(slot = DOM_ERROR_MESSAGE_SLOT)]
@@ -108,16 +100,12 @@ struct DomErrorPrototypeAccessorsDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "QuotaExceededError")]
struct QuotaExceededErrorObjectDeclaration<'scope> {
- #[webapi(slot = DOM_EXCEPTION_BRAND_SLOT, init = true)]
- dom_exception_brand: (),
#[webapi(slot = DOM_EXCEPTION_MESSAGE_SLOT)]
message: Option<v8::Local<'scope, v8::String>>,
#[webapi(slot = DOM_EXCEPTION_NAME_SLOT, init = string("QuotaExceededError"))]
name: (),
#[webapi(slot = DOM_EXCEPTION_CODE_SLOT, value = f64::from(dom_exception_legacy_code("QuotaExceededError")))]
code: (),
- #[webapi(slot = QUOTA_EXCEEDED_ERROR_BRAND_SLOT, init = true)]
- quota_exceeded_error_brand: (),
#[webapi(slot = QUOTA_EXCEEDED_ERROR_QUOTA_SLOT)]
quota: v8::Local<'scope, v8::Value>,
#[webapi(slot = QUOTA_EXCEEDED_ERROR_REQUESTED_SLOT)]
@@ -140,16 +128,12 @@ struct QuotaExceededErrorPrototypeAccessorsDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "WebSocketError")]
struct WebSocketErrorObjectDeclaration<'scope> {
- #[webapi(slot = DOM_EXCEPTION_BRAND_SLOT, init = true)]
- dom_exception_brand: (),
#[webapi(slot = DOM_EXCEPTION_MESSAGE_SLOT)]
message: Option<v8::Local<'scope, v8::String>>,
#[webapi(slot = DOM_EXCEPTION_NAME_SLOT, init = string("WebSocketError"))]
name: (),
#[webapi(slot = DOM_EXCEPTION_CODE_SLOT, value = f64::from(dom_exception_legacy_code("WebSocketError")))]
code: (),
- #[webapi(slot = WEBSOCKET_ERROR_BRAND_SLOT, init = true)]
- websocket_error_brand: (),
#[webapi(slot = WEBSOCKET_ERROR_CLOSE_CODE_SLOT)]
close_code: v8::Local<'scope, v8::Value>,
#[webapi(slot = WEBSOCKET_ERROR_REASON_SLOT)]
@@ -226,7 +210,7 @@ fn dom_exception_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> Option<v8::Local<'s, v8::Object>> {
- if get_private_value(scope, receiver, DOM_EXCEPTION_BRAND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, "DOMException") {
Some(receiver)
} else {
throw_type_error(
@@ -241,7 +225,7 @@ fn dom_error_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> Option<v8::Local<'s, v8::Object>> {
- if get_private_value(scope, receiver, DOM_ERROR_BRAND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, "DOMError") {
Some(receiver)
} else {
throw_type_error(scope, "DOMError getter called on incompatible receiver.");
@@ -253,7 +237,7 @@ pub(crate) fn dom_exception_clone_fields<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> Option<(String, String)> {
- get_private_value(scope, object, DOM_EXCEPTION_BRAND_SLOT)?;
+ moli_webapi_declare::implements_interface(scope, object, "DOMException").then_some(())?;
let message = get_private_value(scope, object, DOM_EXCEPTION_MESSAGE_SLOT)
.and_then(|value| value.to_string(scope))
.map(|value| value.to_rust_string_lossy(scope))
@@ -269,7 +253,7 @@ pub(crate) fn quota_exceeded_error_clone_fields<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> Option<(String, Option<f64>, Option<f64>)> {
- get_private_value(scope, object, QUOTA_EXCEEDED_ERROR_BRAND_SLOT)?;
+ moli_webapi_declare::implements_interface(scope, object, "QuotaExceededError").then_some(())?;
let (message, _) = dom_exception_clone_fields(scope, object)?;
let quota = nullable_double_clone_slot(scope, object, QUOTA_EXCEEDED_ERROR_QUOTA_SLOT)?;
let requested = nullable_double_clone_slot(scope, object, QUOTA_EXCEEDED_ERROR_REQUESTED_SLOT)?;
@@ -383,33 +367,22 @@ fn quota_exceeded_error_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> Option<v8::Local<'s, v8::Object>> {
- dom_exception_subclass_receiver(
- scope,
- receiver,
- QUOTA_EXCEEDED_ERROR_BRAND_SLOT,
- "QuotaExceededError",
- )
+ dom_exception_subclass_receiver(scope, receiver, "QuotaExceededError")
}
fn websocket_error_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> Option<v8::Local<'s, v8::Object>> {
- dom_exception_subclass_receiver(
- scope,
- receiver,
- WEBSOCKET_ERROR_BRAND_SLOT,
- "WebSocketError",
- )
+ dom_exception_subclass_receiver(scope, receiver, "WebSocketError")
}
fn dom_exception_subclass_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
- brand_slot: &'static str,
interface_name: &'static str,
) -> Option<v8::Local<'s, v8::Object>> {
- if get_private_value(scope, receiver, brand_slot).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, interface_name) {
Some(receiver)
} else {
throw_type_error(
@@ -748,7 +721,7 @@ pub(crate) fn websocket_error_close_info<'s>(
value: v8::Local<'s, v8::Value>,
) -> Option<(Option<u16>, String)> {
let object = v8::Local::<v8::Object>::try_from(value).ok()?;
- get_private_value(scope, object, WEBSOCKET_ERROR_BRAND_SLOT)?;
+ moli_webapi_declare::implements_interface(scope, object, "WebSocketError").then_some(())?;
let close_code_value = get_private_value(scope, object, WEBSOCKET_ERROR_CLOSE_CODE_SLOT)?;
let reason_value = get_private_value(scope, object, WEBSOCKET_ERROR_REASON_SLOT)?;
let close_code = if close_code_value.is_null_or_undefined() {
diff --git a/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs b/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs
index 91ff06e51..3420cbc70 100644
--- a/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs
+++ b/moli-renderer-v8/src/context_bootstrap/constructors/text_codecs.rs
@@ -7,11 +7,9 @@ use crate::{
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
const TEXT_ENCODER_ENCODING_SLOT: &str = "__lmTextEncoderEncoding";
-const TEXT_ENCODER_BRAND_SLOT: &str = "__lmTextEncoderBrand";
const TEXT_DECODER_ENCODING_SLOT: &str = "__lmTextDecoderEncoding";
const TEXT_DECODER_FATAL_SLOT: &str = "__lmTextDecoderFatal";
const TEXT_DECODER_IGNORE_BOM_SLOT: &str = "__lmTextDecoderIgnoreBOM";
-const TEXT_DECODER_BRAND_SLOT: &str = "__lmTextDecoderBrand";
const TEXT_ENCODER_ENCODING_SLOT_INDEX: usize = 0;
const TEXT_DECODER_ENCODING_SLOT_INDEX: usize = 1;
const TEXT_DECODER_FATAL_SLOT_INDEX: usize = 2;
@@ -20,9 +18,6 @@ const TEXT_DECODER_IGNORE_BOM_SLOT_INDEX: usize = 3;
#[derive(WebApiObject)]
#[webapi(interface = "TextEncoder")]
struct TextEncoderObjectDeclaration {
- #[webapi(slot = TEXT_ENCODER_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = TEXT_ENCODER_ENCODING_SLOT)]
encoding: &'static str,
}
@@ -46,9 +41,6 @@ struct TextEncoderPrototypeDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "TextDecoder")]
struct TextDecoderObjectDeclaration {
- #[webapi(slot = TEXT_DECODER_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = TEXT_DECODER_ENCODING_SLOT)]
encoding: String,
#[webapi(slot = TEXT_DECODER_FATAL_SLOT)]
@@ -429,16 +421,14 @@ fn text_encoder_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, TEXT_ENCODER_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "TextEncoder")
}
fn text_decoder_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, TEXT_DECODER_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "TextDecoder")
}
fn init_text_decoder_state(
diff --git a/moli-renderer-v8/src/context_bootstrap/crypto.rs b/moli-renderer-v8/src/context_bootstrap/crypto.rs
index 79f9fdbfc..1f8abaead 100644
--- a/moli-renderer-v8/src/context_bootstrap/crypto.rs
+++ b/moli-renderer-v8/src/context_bootstrap/crypto.rs
@@ -6,9 +6,6 @@ mod keys;
mod random;
mod subtle;
-const CRYPTO_BRAND_SLOT: &str = "__moliCryptoBrand";
-const CRYPTO_SUBTLE_BRAND_SLOT: &str = "__moliCryptoSubtleBrand";
-
pub(crate) use helpers::WebCryptoRejection;
pub(in crate::context_bootstrap) use install::{
build_window_crypto_for_receiver, ensure_worker_crypto_for_global,
diff --git a/moli-renderer-v8/src/context_bootstrap/crypto/install.rs b/moli-renderer-v8/src/context_bootstrap/crypto/install.rs
index 9007a1be7..8b44d9b3b 100644
--- a/moli-renderer-v8/src/context_bootstrap/crypto/install.rs
+++ b/moli-renderer-v8/src/context_bootstrap/crypto/install.rs
@@ -20,18 +20,12 @@ const CRYPTO_SUBTLE_AVAILABLE_SLOT: &str = "__moliCryptoSubtleAvailable";
const WINDOW_CRYPTO_SUBTLE_AVAILABLE_SLOT: &str = "__moliWindowCryptoSubtleAvailable";
#[derive(Default, WebApiObject)]
-#[webapi(interface = "Crypto")]
-struct CryptoObjectDeclaration {
- #[webapi(slot = CRYPTO_BRAND_SLOT, init = true)]
- brand: (),
-}
+#[webapi(allow_empty, interface = "Crypto")]
+struct CryptoObjectDeclaration {}
#[derive(Default, WebApiObject)]
-#[webapi(interface = "SubtleCrypto")]
-struct SubtleCryptoObjectDeclaration {
- #[webapi(slot = CRYPTO_SUBTLE_BRAND_SLOT, init = true)]
- brand: (),
-}
+#[webapi(allow_empty, interface = "SubtleCrypto")]
+struct SubtleCryptoObjectDeclaration {}
#[derive(Default, WebApiObject)]
#[webapi(unbranded, interface = "Crypto")]
@@ -239,7 +233,7 @@ fn crypto_attribute_getter_callback<'s>(
rv.set_undefined();
return;
};
- if get_private_value(scope, args.this(), CRYPTO_BRAND_SLOT).is_none() {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "Crypto") {
throw_type_error(scope, "Illegal invocation");
return;
}
diff --git a/moli-renderer-v8/src/context_bootstrap/crypto/keys.rs b/moli-renderer-v8/src/context_bootstrap/crypto/keys.rs
index cfa71faf8..39ca91071 100644
--- a/moli-renderer-v8/src/context_bootstrap/crypto/keys.rs
+++ b/moli-renderer-v8/src/context_bootstrap/crypto/keys.rs
@@ -274,7 +274,7 @@ pub(crate) fn is_crypto_key_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
key: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, key, CRYPTO_KEY_KIND_SLOT).is_some()
+ moli_webapi_declare::implements_interface(scope, key, "CryptoKey")
}
pub(crate) fn crypto_key_clone_payload_from_object<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/crypto/random.rs b/moli-renderer-v8/src/context_bootstrap/crypto/random.rs
index c9fd23237..6487b48ff 100644
--- a/moli-renderer-v8/src/context_bootstrap/crypto/random.rs
+++ b/moli-renderer-v8/src/context_bootstrap/crypto/random.rs
@@ -4,7 +4,6 @@ use moli_crypto::fill_secure_random;
use uuid::Builder as UuidBuilder;
use crate::native_bridge::throw_dom_exception;
-use crate::util::get_private_value;
use super::helpers::is_crypto_integer_typed_array;
use super::*;
@@ -14,7 +13,7 @@ pub(super) fn crypto_get_random_values_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- if get_private_value(scope, args.this(), CRYPTO_BRAND_SLOT).is_none() {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "Crypto") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -88,7 +87,7 @@ pub(super) fn crypto_random_uuid_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- if get_private_value(scope, args.this(), CRYPTO_BRAND_SLOT).is_none() {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "Crypto") {
throw_type_error(scope, "Illegal invocation");
return;
}
diff --git a/moli-renderer-v8/src/context_bootstrap/crypto/subtle/mod.rs b/moli-renderer-v8/src/context_bootstrap/crypto/subtle/mod.rs
index 648dc7334..4ef2b92b1 100644
--- a/moli-renderer-v8/src/context_bootstrap/crypto/subtle/mod.rs
+++ b/moli-renderer-v8/src/context_bootstrap/crypto/subtle/mod.rs
@@ -32,9 +32,7 @@ use moli_webcrypto::{
};
use crate::{
- context_bootstrap::WebCryptoTaskResult,
- util::{context_host_ptr_from_global_bridge, get_private_value},
- webidl,
+ context_bootstrap::WebCryptoTaskResult, util::context_host_ptr_from_global_bridge, webidl,
};
use super::helpers::{
diff --git a/moli-renderer-v8/src/context_bootstrap/crypto/subtle/params.rs b/moli-renderer-v8/src/context_bootstrap/crypto/subtle/params.rs
index 06fc9b39d..ca56248c8 100644
--- a/moli-renderer-v8/src/context_bootstrap/crypto/subtle/params.rs
+++ b/moli-renderer-v8/src/context_bootstrap/crypto/subtle/params.rs
@@ -5,7 +5,7 @@ pub(crate) fn subtle_crypto_receiver_is_valid<'s>(
args: &v8::FunctionCallbackArguments<'s>,
rv: &mut v8::ReturnValue<'_, v8::Value>,
) -> bool {
- if get_private_value(scope, args.this(), CRYPTO_SUBTLE_BRAND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, args.this(), "SubtleCrypto") {
true
} else {
set_rejected_webcrypto_promise(scope, rv, WebCryptoRejection::Type);
diff --git a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime.rs b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime.rs
index 849fc3edd..f981336ef 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime.rs
@@ -41,7 +41,6 @@ pub(in crate::context_bootstrap) use events::{
};
pub(super) use font_face::{
font_face_constructor_callback, font_face_load_callback, install_font_face_template_accessors,
- is_font_face,
};
pub(super) use font_face_set::{
font_face_set_add_callback, font_face_set_add_event_listener_callback,
diff --git a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face.rs b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face.rs
index 25fea937c..31abb66a9 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/font_face.rs
@@ -37,7 +37,7 @@ struct FontFaceObjectDeclaration<'s> {
}
#[derive(WebApiFunctionTemplate)]
-#[webapi(name = "FontFace", receiver = is_font_face)]
+#[webapi(name = "FontFace", receiver = "FontFace")]
struct FontFacePrototypeAccessorsDeclaration {
#[webapi(
accessor_property,
@@ -345,13 +345,6 @@ pub(in crate::context_bootstrap) fn font_face_load_callback<'s>(
}
}
-pub(in crate::context_bootstrap) fn is_font_face<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
-) -> bool {
- get_private_value(scope, receiver, FONT_FACE_STATUS_SLOT).is_some()
-}
-
fn descriptor_string_property(
scope: &mut v8::PinScope<'_, '_>,
object: Option<v8::Local<'_, v8::Object>>,
diff --git a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/storage.rs b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/storage.rs
index 772b3e664..bc2164a2c 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/storage.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_fontface_runtime/storage.rs
@@ -300,22 +300,14 @@ pub(super) fn set_font_face_set_status<'s>(
set_font_face_set_slot_value(scope, object, FONT_FACE_SET_STATUS_SLOT, value.into());
}
-pub(super) fn is_font_face_value(
- scope: &mut v8::PinScope<'_, '_>,
- value: v8::Local<'_, v8::Value>,
+pub(super) fn is_font_face_value<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ value: v8::Local<'s, v8::Value>,
) -> bool {
let Ok(object) = v8::Local::<v8::Object>::try_from(value) else {
return false;
};
- if global_constructor_prototype(scope, "FontFace").is_some_and(|prototype| {
- object
- .get_prototype(scope)
- .is_some_and(|candidate| candidate.strict_equals(prototype.into()))
- }) {
- return true;
- }
- object_has_string_property(scope, object, "family")
- && object_has_string_property(scope, object, "status")
+ moli_webapi_declare::implements_interface(scope, object, "FontFace")
}
pub(super) fn array_contains_value(
@@ -334,21 +326,6 @@ pub(super) fn array_contains_value(
false
}
-fn object_has_string_property(
- scope: &mut v8::PinScope<'_, '_>,
- object: v8::Local<'_, v8::Object>,
- key: &str,
-) -> bool {
- object
- .get(
- scope,
- v8_string(scope, key)
- .map(Into::into)
- .unwrap_or_else(|| v8::String::empty(scope).into()),
- )
- .is_some_and(|value| value.is_string())
-}
-
fn sync_font_face_set_size<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
diff --git a/moli-renderer-v8/src/context_bootstrap/css_runtime/typed_om/values.rs b/moli-renderer-v8/src/context_bootstrap/css_runtime/typed_om/values.rs
index a26e0a6a7..841ec20e6 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_runtime/typed_om/values.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_runtime/typed_om/values.rs
@@ -1,7 +1,6 @@
use super::*;
const CSS_STYLE_VALUE_TEXT_SLOT: &str = "__moliCssStyleValueText";
-const CSS_STYLE_VALUE_BRAND_SLOT: &str = "__moliCssStyleValueBrand";
const CSS_KEYWORD_VALUE_VALUE_SLOT: &str = "__moliCssKeywordValueValue";
const CSS_UNIT_VALUE_VALUE_SLOT: &str = "__moliCssUnitValueValue";
const CSS_UNIT_VALUE_UNIT_SLOT: &str = "__moliCssUnitValueUnit";
@@ -15,8 +14,6 @@ const VALID_UNIT_NAMES: &[&str] = &[
#[derive(WebApiObject)]
#[webapi(interface = "CSSStyleValue")]
struct CssStyleValueObjectDeclaration {
- #[webapi(slot = CSS_STYLE_VALUE_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = CSS_STYLE_VALUE_TEXT_SLOT)]
text: String,
}
@@ -24,8 +21,6 @@ struct CssStyleValueObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "CSSKeywordValue")]
struct CssKeywordValueObjectDeclaration {
- #[webapi(slot = CSS_STYLE_VALUE_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = CSS_KEYWORD_VALUE_VALUE_SLOT)]
value: String,
}
@@ -33,8 +28,6 @@ struct CssKeywordValueObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "CSSUnitValue")]
struct CssUnitValueObjectDeclaration {
- #[webapi(slot = CSS_STYLE_VALUE_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = CSS_UNIT_VALUE_VALUE_SLOT)]
value: f64,
#[webapi(slot = CSS_UNIT_VALUE_UNIT_SLOT)]
@@ -363,8 +356,7 @@ fn css_style_value_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, CSS_STYLE_VALUE_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "CSSStyleValue")
}
fn css_unit_value_number<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/install.rs b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/install.rs
index b0d916fe3..8c1a4c337 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/install.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/install.rs
@@ -185,7 +185,6 @@ pub(crate) fn install_css_rule_list_surface<'s>(
list: v8::Local<'s, v8::Object>,
) {
CssRuleListDeclaration {
- brand: (),
length: css_rule_list_length(scope, list),
}
.bind_into(scope, list)
diff --git a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/media_list.rs b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/media_list.rs
index 53242b233..87ce9a655 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/media_list.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/media_list.rs
@@ -5,7 +5,7 @@ pub(crate) fn ensure_media_list_object<'s>(
object: v8::Local<'s, v8::Object>,
member: &'static str,
) -> bool {
- if get_private_value(scope, object, CSS_MEDIA_LIST_LENGTH_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, object, "MediaList") {
return true;
}
throw_type_error(
diff --git a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/rule_callbacks.rs b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/rule_callbacks.rs
index ddc686ac5..48dcbff01 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/rule_callbacks.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/rule_callbacks.rs
@@ -247,7 +247,6 @@ pub(crate) fn build_css_generic_at_rule_object_from_stylo_rule_type<'s>(
let prototype_name = css_at_rule_prototype_name_for_stylo_rule_type(stylo_rule_type);
let rule_type = css_rule_type_from_stylo_rule_type(stylo_rule_type);
let declaration = CssAtRuleDeclaration {
- brand: true,
css_text,
rule_type,
parent_rule,
@@ -258,6 +257,8 @@ pub(crate) fn build_css_generic_at_rule_object_from_stylo_rule_type<'s>(
declaration,
stylo_rule_type == CssRuleType::Keyframes,
);
+ moli_webapi_declare::initialize_web_api_object(scope, object, prototype_name)
+ .expect("CSS rule interface identity should initialize");
if let Some(prototype) = global_constructor_prototype(scope, prototype_name) {
let _ = object.set_prototype(scope, prototype.into());
}
@@ -438,7 +439,7 @@ pub(crate) fn ensure_css_rule_object<'s>(
interface: &'static str,
member: &'static str,
) -> bool {
- if get_private_value(scope, object, CSS_RULE_BRAND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, object, "CSSRule") {
return true;
}
throw_type_error(
@@ -455,7 +456,7 @@ pub(crate) fn ensure_css_rule_type_object<'s>(
member: &str,
expected_type: u32,
) -> bool {
- if get_private_value(scope, object, CSS_RULE_BRAND_SLOT).is_some()
+ if moli_webapi_declare::implements_interface(scope, object, "CSSRule")
&& css_rule_type_from_object(scope, object) == Some(expected_type)
{
return true;
@@ -543,7 +544,6 @@ pub(crate) fn build_css_rule_object_with_rule_context<'s>(
.filter(|rule_type| *rule_type != CSS_RULE_UNKNOWN_RULE_TYPE)
.unwrap_or_else(|| css_at_rule_type(rule_kind));
let declaration = CssAtRuleDeclaration {
- brand: true,
css_text,
rule_type,
parent_rule,
@@ -551,6 +551,8 @@ pub(crate) fn build_css_rule_object_with_rule_context<'s>(
};
let object =
bind_css_at_rule_declaration(scope, declaration, rule_kind == CssAtRuleKind::Keyframes);
+ moli_webapi_declare::initialize_web_api_object(scope, object, prototype_name)
+ .expect("CSS rule interface identity should initialize");
if let Some(prototype) = global_constructor_prototype(scope, prototype_name) {
let _ = object.set_prototype(scope, prototype.into());
}
@@ -731,7 +733,7 @@ pub(crate) fn css_rule_type_from_object<'s>(
return Some(css_rule_type);
}
}
- get_private_value(scope, object, CSS_RULE_BRAND_SLOT)?;
+ moli_webapi_declare::implements_interface(scope, object, "CSSRule").then_some(())?;
Some(private_u32(scope, object, CSS_AT_RULE_TYPE_SLOT).unwrap_or(CSS_RULE_UNKNOWN_RULE_TYPE))
}
diff --git a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/rule_list.rs b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/rule_list.rs
index aaaf1055a..e1e55f523 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/rule_list.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/rule_list.rs
@@ -103,12 +103,9 @@ pub(crate) fn new_css_rule_list_object<'s>(
let list = template
.new_instance(scope)
.expect("CSSRuleList object template should instantiate");
- CssRuleListDeclaration {
- brand: (),
- length: 0,
- }
- .bind_into(scope, list)
- .expect("CSSRuleList declaration should bind into list");
+ CssRuleListDeclaration { length: 0 }
+ .bind_into(scope, list)
+ .expect("CSSRuleList declaration should bind into list");
reset_css_rule_list_materialized_items(scope, list);
list
}
@@ -418,7 +415,7 @@ pub(crate) fn ensure_css_rule_list_object<'s>(
object: v8::Local<'s, v8::Object>,
member: &'static str,
) -> bool {
- if get_private_value(scope, object, CSS_RULE_LIST_BRAND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, object, "CSSRuleList") {
return true;
}
throw_type_error(
diff --git a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/specific_rules.rs b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/specific_rules.rs
index e4b932208..430ad77de 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/specific_rules.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/specific_rules.rs
@@ -278,7 +278,6 @@ pub(crate) fn build_css_margin_rule_object_from_stylo_view<'s>(
parent_rule: Option<v8::Local<'s, v8::Object>>,
) -> v8::Local<'s, v8::Object> {
CssMarginRuleDeclaration {
- brand: true,
css_text: view.css_text,
name: view.name,
style_text: view.style_text,
@@ -296,7 +295,6 @@ pub(crate) fn build_css_font_face_rule_object_from_stylo_view<'s>(
parent_rule: Option<v8::Local<'s, v8::Object>>,
) -> v8::Local<'s, v8::Object> {
let object = CssAtRuleDeclaration {
- brand: true,
css_text: view.css_text,
rule_type: CSS_RULE_FONT_FACE_RULE_TYPE,
parent_rule,
@@ -304,6 +302,8 @@ pub(crate) fn build_css_font_face_rule_object_from_stylo_view<'s>(
}
.bind(scope)
.expect("CSSFontFaceRule declaration should bind");
+ moli_webapi_declare::initialize_web_api_object(scope, object, "CSSFontFaceRule")
+ .expect("CSS rule interface identity should initialize");
if let Some(prototype) = global_constructor_prototype(scope, "CSSFontFaceRule") {
let _ = object.set_prototype(scope, prototype.into());
}
@@ -318,7 +318,6 @@ pub(crate) fn build_css_keyframe_rule_object<'s>(
) -> v8::Local<'s, v8::Object> {
let style_text = parsed.style_text.clone();
let rule = CssKeyframeRuleDeclaration {
- brand: true,
css_text: parsed.css_text,
key_text: parsed.selector_text,
style_text: parsed.style_text,
@@ -343,7 +342,6 @@ pub(crate) fn build_css_font_feature_values_rule_object_from_stylo_view<'s>(
parent_rule: Option<v8::Local<'s, v8::Object>>,
) -> v8::Local<'s, v8::Object> {
let object = CssFontFeatureValuesRuleDeclaration {
- brand: true,
css_text: view.css_text,
font_family: view.font_family,
parent_rule,
@@ -419,7 +417,6 @@ pub(crate) fn bind_css_property_rule_object<'s>(
parent_rule: Option<v8::Local<'s, v8::Object>>,
) -> v8::Local<'s, v8::Object> {
CssPropertyRuleDeclaration {
- brand: true,
css_text,
rule_type: CSS_RULE_UNKNOWN_RULE_TYPE,
name,
@@ -556,7 +553,6 @@ fn bind_css_style_rule_object<'s>(
parent_rule: Option<v8::Local<'s, v8::Object>>,
) -> v8::Local<'s, v8::Object> {
CssStyleRuleDeclaration {
- brand: true,
css_text: parsed.css_text,
selector_text: parsed.selector_text,
style_text: parsed.style_text,
@@ -574,7 +570,6 @@ pub(crate) fn build_css_nested_declarations_rule_object<'s>(
parent_rule: v8::Local<'s, v8::Object>,
) -> v8::Local<'s, v8::Object> {
let rule = CssNestedDeclarationsRuleDeclaration {
- brand: true,
css_text: style_text.to_owned(),
style_text: style_text.to_owned(),
parent_rule,
diff --git a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/style_sheet.rs b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/style_sheet.rs
index a6e44c7e3..d85ff1b9a 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/style_sheet.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/style_sheet.rs
@@ -273,7 +273,8 @@ pub(crate) fn adopted_style_sheet_objects_from_array_object<'s>(
(0..length)
.filter_map(|index| {
let object = array.get_index(scope, index)?.try_into().ok()?;
- get_private_value(scope, object, CSS_STYLE_SHEET_BRAND_SLOT).map(|_| object)
+ moli_webapi_declare::implements_interface(scope, object, "CSSStyleSheet")
+ .then_some(object)
})
.collect()
}
@@ -946,7 +947,7 @@ pub(crate) fn css_style_sheet_replace_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if get_private_value(scope, args.this(), CSS_STYLE_SHEET_BRAND_SLOT).is_none() {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "CSSStyleSheet") {
let promise = rejected_type_error_promise(
scope,
"Failed to execute 'replace' on 'CSSStyleSheet': Illegal invocation.",
@@ -1033,7 +1034,7 @@ pub(crate) fn ensure_css_style_sheet_object<'s>(
interface: &'static str,
member: &'static str,
) -> bool {
- if get_private_value(scope, object, CSS_STYLE_SHEET_BRAND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, object, "CSSStyleSheet") {
return true;
}
throw_type_error(
@@ -1094,7 +1095,7 @@ pub(crate) fn ensure_style_sheet_list_object<'s>(
object: v8::Local<'s, v8::Object>,
member: &'static str,
) -> bool {
- if get_private_value(scope, object, STYLE_SHEET_LIST_BRAND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, object, "StyleSheetList") {
return true;
}
throw_type_error(
@@ -1114,12 +1115,9 @@ pub(crate) fn style_sheet_list_length<'s>(
pub(crate) fn new_style_sheet_list_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
) -> v8::Local<'s, v8::Object> {
- StyleSheetListDeclaration {
- brand: (),
- length: (),
- }
- .bind(scope)
- .expect("StyleSheetList declaration should bind")
+ StyleSheetListDeclaration { length: () }
+ .bind(scope)
+ .expect("StyleSheetList declaration should bind")
}
pub(crate) fn set_style_sheet_list_contents<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/types.rs b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/types.rs
index a0c619171..c88a9f4ab 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/types.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_stylesheet_runtime/types.rs
@@ -22,14 +22,10 @@ pub const CSS_STYLE_SHEET_ADOPTED_OWNER_KEYS_SLOT: &str = "__moliCssStyleSheetAd
pub const CSS_STYLE_SHEET_ADOPTED_OWNER_ARRAYS_SLOT: &str = "__moliCssStyleSheetAdoptedOwnerArrays";
-pub const CSS_STYLE_SHEET_BRAND_SLOT: &str = "__moliCssStyleSheetBrand";
-
pub const CSS_STYLE_SHEET_ID_SLOT: &str = "__moliCssStyleSheetId";
pub const CSS_STYLE_SHEET_WRAPPER_LEASE_ID_SLOT: &str = "__moliCssStyleSheetWrapperLeaseId";
-pub const CSS_RULE_BRAND_SLOT: &str = "__moliCssRuleBrand";
-
pub const CSS_RULE_DETACHED_SNAPSHOT_TEXT_SLOT: &str = "__moliCssRuleDetachedSnapshotText";
pub const CSS_RULE_DETACHED_CHILD_SNAPSHOTS_SLOT: &str = "__moliCssRuleDetachedChildSnapshots";
@@ -129,12 +125,8 @@ pub const CSS_MEDIA_LIST_OWNER_KIND_SLOT: &str = "__moliCssMediaListOwnerKind";
pub const CSS_MEDIA_LIST_LENGTH_SLOT: &str = "__moliCssMediaListLength";
-pub const STYLE_SHEET_LIST_BRAND_SLOT: &str = "__moliStyleSheetListBrand";
-
pub const STYLE_SHEET_LIST_LENGTH_SLOT: &str = "__moliStyleSheetListLength";
-pub const CSS_RULE_LIST_BRAND_SLOT: &str = "__moliCssRuleListBrand";
-
pub const CSS_RULE_LIST_LENGTH_SLOT: &str = "__moliCssRuleListLength";
pub const CSS_RULE_LIST_MATERIALIZED_ITEMS_SLOT: &str = "__moliCssRuleListMaterializedItems";
@@ -287,8 +279,6 @@ pub struct CssRuleConstantsDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "CSSStyleSheet")]
pub struct CssStyleSheetDeclaration<'scope> {
- #[webapi(slot = CSS_STYLE_SHEET_BRAND_SLOT, init = true)]
- pub brand: (),
#[webapi(slot = CSS_STYLE_SHEET_RULES_SLOT)]
pub rules: v8::Local<'scope, v8::Value>,
}
@@ -296,8 +286,6 @@ pub struct CssStyleSheetDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "StyleSheetList")]
pub struct StyleSheetListDeclaration {
- #[webapi(slot = STYLE_SHEET_LIST_BRAND_SLOT, init = true)]
- pub brand: (),
#[webapi(slot = STYLE_SHEET_LIST_LENGTH_SLOT, init = 0)]
pub length: (),
}
@@ -305,8 +293,6 @@ pub struct StyleSheetListDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "CSSRuleList")]
pub struct CssRuleListDeclaration {
- #[webapi(slot = CSS_RULE_LIST_BRAND_SLOT, init = true)]
- pub brand: (),
#[webapi(slot = CSS_RULE_LIST_LENGTH_SLOT)]
pub length: u32,
}
@@ -314,8 +300,6 @@ pub struct CssRuleListDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "CSSRule")]
pub struct CssAtRuleDeclaration<'scope> {
- #[webapi(slot = CSS_RULE_BRAND_SLOT)]
- pub brand: bool,
#[webapi(slot = CSS_RULE_DETACHED_SNAPSHOT_TEXT_SLOT)]
pub css_text: String,
#[webapi(slot = CSS_AT_RULE_TYPE_SLOT)]
@@ -329,8 +313,6 @@ pub struct CssAtRuleDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "CSSMarginRule")]
pub struct CssMarginRuleDeclaration<'scope> {
- #[webapi(slot = CSS_RULE_BRAND_SLOT)]
- pub brand: bool,
#[webapi(slot = CSS_RULE_DETACHED_SNAPSHOT_TEXT_SLOT)]
pub css_text: String,
#[webapi(slot = CSS_MARGIN_RULE_NAME_SLOT)]
@@ -346,8 +328,6 @@ pub struct CssMarginRuleDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "CSSKeyframeRule")]
pub struct CssKeyframeRuleDeclaration<'scope> {
- #[webapi(slot = CSS_RULE_BRAND_SLOT)]
- pub brand: bool,
#[webapi(slot = CSS_RULE_DETACHED_SNAPSHOT_TEXT_SLOT)]
pub css_text: String,
#[webapi(slot = CSS_KEYFRAME_RULE_KEY_TEXT_SLOT)]
@@ -363,8 +343,6 @@ pub struct CssKeyframeRuleDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "CSSFontFeatureValuesRule")]
pub struct CssFontFeatureValuesRuleDeclaration<'scope> {
- #[webapi(slot = CSS_RULE_BRAND_SLOT)]
- pub brand: bool,
#[webapi(slot = CSS_RULE_DETACHED_SNAPSHOT_TEXT_SLOT)]
pub css_text: String,
#[webapi(slot = CSS_FONT_FEATURE_VALUES_RULE_FONT_FAMILY_SLOT)]
@@ -378,8 +356,6 @@ pub struct CssFontFeatureValuesRuleDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "CSSPropertyRule")]
pub struct CssPropertyRuleDeclaration<'scope> {
- #[webapi(slot = CSS_RULE_BRAND_SLOT)]
- pub brand: bool,
#[webapi(slot = CSS_RULE_DETACHED_SNAPSHOT_TEXT_SLOT)]
pub css_text: String,
#[webapi(slot = CSS_AT_RULE_TYPE_SLOT)]
@@ -401,8 +377,6 @@ pub struct CssPropertyRuleDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "CSSStyleRule")]
pub struct CssStyleRuleDeclaration<'scope> {
- #[webapi(slot = CSS_RULE_BRAND_SLOT)]
- pub brand: bool,
#[webapi(slot = CSS_RULE_DETACHED_SNAPSHOT_TEXT_SLOT)]
pub css_text: String,
#[webapi(slot = CSS_STYLE_RULE_SELECTOR_TEXT_SLOT)]
@@ -418,8 +392,6 @@ pub struct CssStyleRuleDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "CSSNestedDeclarations")]
pub struct CssNestedDeclarationsRuleDeclaration<'scope> {
- #[webapi(slot = CSS_RULE_BRAND_SLOT)]
- pub brand: bool,
#[webapi(slot = CSS_RULE_DETACHED_SNAPSHOT_TEXT_SLOT)]
pub css_text: String,
#[webapi(slot = CSS_NESTED_DECLARATIONS_STYLE_TEXT_SLOT)]
diff --git a/moli-renderer-v8/src/context_bootstrap/dom_rect.rs b/moli-renderer-v8/src/context_bootstrap/dom_rect.rs
index c9457d8aa..730bea00e 100644
--- a/moli-renderer-v8/src/context_bootstrap/dom_rect.rs
+++ b/moli-renderer-v8/src/context_bootstrap/dom_rect.rs
@@ -7,14 +7,10 @@ const DOM_RECT_X_SLOT: &str = "__moliDomRectX";
const DOM_RECT_Y_SLOT: &str = "__moliDomRectY";
const DOM_RECT_WIDTH_SLOT: &str = "__moliDomRectWidth";
const DOM_RECT_HEIGHT_SLOT: &str = "__moliDomRectHeight";
-const DOM_RECT_BRAND_SLOT: &str = "__moliDomRectBrand";
#[derive(WebApiObject)]
#[webapi(interface = "DOMRect")]
struct DomRectObjectDeclaration {
- #[webapi(slot = DOM_RECT_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = DOM_RECT_X_SLOT)]
x: f64,
#[webapi(slot = DOM_RECT_Y_SLOT)]
@@ -28,9 +24,6 @@ struct DomRectObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "DOMRectReadOnly")]
struct DomRectReadOnlyObjectDeclaration {
- #[webapi(slot = DOM_RECT_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = DOM_RECT_X_SLOT)]
x: f64,
#[webapi(slot = DOM_RECT_Y_SLOT)]
@@ -564,8 +557,7 @@ fn dom_rect_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, DOM_RECT_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "DOMRectReadOnly")
}
const DOM_RECT_WRITABLE_ATTRIBUTE_SLOTS: &[&str] = &[
diff --git a/moli-renderer-v8/src/context_bootstrap/event_template.rs b/moli-renderer-v8/src/context_bootstrap/event_template.rs
index 045f0fbf9..2d83bb0bf 100644
--- a/moli-renderer-v8/src/context_bootstrap/event_template.rs
+++ b/moli-renderer-v8/src/context_bootstrap/event_template.rs
@@ -26,31 +26,13 @@ use super::{
specs::{ConstructorKind, ConstructorSpec},
};
use crate::{native_bridge::document, window_host};
-use moli_webapi_declare::{EVENT_TARGET_INTERFACE_BRAND_SLOT, WebApiFunctionTemplate};
+use moli_webapi_declare::WebApiFunctionTemplate;
pub(in crate::context_bootstrap) fn object_is_event_target<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- if crate::util::get_private_value(scope, object, EVENT_TARGET_INTERFACE_BRAND_SLOT)
- .is_some_and(|value| value.is_true())
- {
- return true;
- }
- super::exposed_interfaces::object_is_intrinsic_interface_instance(scope, "EventTarget", object)
- || crate::native_bridge::object_is_native_event_target_wrapper_or_detached(scope, object)
-}
-
-pub(in crate::context_bootstrap) fn mark_event_target_interface_prototype<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- prototype: v8::Local<'s, v8::Object>,
-) {
- crate::util::set_private_value(
- scope,
- prototype,
- EVENT_TARGET_INTERFACE_BRAND_SLOT,
- v8::Boolean::new(scope, true).into(),
- );
+ moli_webapi_declare::implements_interface(scope, object, "EventTarget")
}
#[derive(WebApiFunctionTemplate)]
diff --git a/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/finalize.rs b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/finalize.rs
index 248f47d6c..f869a6b60 100644
--- a/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/finalize.rs
+++ b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/finalize.rs
@@ -7,7 +7,6 @@ use super::materialize::{
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum RealmDependentFinalizer {
NodeMixinUnscopables,
- EventTargetBrand,
DomExceptionPrototypeCache,
CryptoSecureContextSurface,
BlobPrototypeCache,
@@ -36,7 +35,6 @@ const REALM_DEPENDENT_FINALIZER_ALLOWLIST: &[(&str, RealmDependentFinalizer)] =
),
// These entries install private realm state, context-conditional surface,
// or constructor data whose JavaScript identity must be realm-local.
- ("EventTarget", RealmDependentFinalizer::EventTargetBrand),
(
"DOMException",
RealmDependentFinalizer::DomExceptionPrototypeCache,
@@ -89,11 +87,6 @@ pub(super) fn finalize_materialized_interface(
RealmDependentFinalizer::NodeMixinUnscopables => {
finalize_node_mixin_unscopables(scope, prototype);
}
- RealmDependentFinalizer::EventTargetBrand => {
- crate::context_bootstrap::event_template::mark_event_target_interface_prototype(
- scope, prototype,
- );
- }
RealmDependentFinalizer::DomExceptionPrototypeCache => {
crate::context_bootstrap::constructors::finalize_dom_exception_realm_bindings(
scope, prototype,
@@ -162,7 +155,6 @@ mod tests {
"Element",
"DocumentType",
"CharacterData",
- "EventTarget",
"DOMException",
"Crypto",
"Blob",
@@ -173,6 +165,7 @@ mod tests {
]
);
for static_owner in [
+ "EventTarget",
"Node",
"HTMLAnchorElement",
"HTMLAreaElement",
diff --git a/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/materialize.rs b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/materialize.rs
index 2b5b44dfc..1d7f37dd3 100644
--- a/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/materialize.rs
+++ b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/materialize.rs
@@ -176,22 +176,6 @@ pub(crate) fn ensure_intrinsic_interface_prototype<'s>(
.ok_or_else(|| anyhow!("intrinsic prototype `{name}` is missing after materialization"))
}
-pub(crate) fn object_is_intrinsic_interface_instance<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- name: &str,
- object: v8::Local<'s, v8::Object>,
-) -> bool {
- let Some(registry) = ExposedInterfaceTemplateRegistry::current(scope) else {
- return false;
- };
- let Some(id) = registry.id_by_name(name) else {
- return false;
- };
- registry
- .ready_template(scope, id)
- .is_some_and(|template| template.has_instance(object.into()))
-}
-
fn materialize_uninitialized_interface<'s>(
scope: &mut v8::PinScope<'s, '_>,
registry: &Rc<ExposedInterfaceTemplateRegistry>,
diff --git a/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/mod.rs b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/mod.rs
index 6155abb6c..edc261971 100644
--- a/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/mod.rs
+++ b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/mod.rs
@@ -21,7 +21,7 @@ pub(crate) use install::{
};
pub(crate) use materialize::{
build_intrinsic_interface_instance, ensure_intrinsic_interface_constructor,
- ensure_intrinsic_interface_prototype, object_is_intrinsic_interface_instance,
+ ensure_intrinsic_interface_prototype,
};
pub(crate) use metadata::RealmKind;
pub(in crate::context_bootstrap) use metadata::TemplateBuildProfile;
diff --git a/moli-renderer-v8/src/context_bootstrap/file_api/data_transfer.rs b/moli-renderer-v8/src/context_bootstrap/file_api/data_transfer.rs
index 696e6de33..1468ebd2a 100644
--- a/moli-renderer-v8/src/context_bootstrap/file_api/data_transfer.rs
+++ b/moli-renderer-v8/src/context_bootstrap/file_api/data_transfer.rs
@@ -13,7 +13,6 @@ use moli_file_api::data_transfer::{
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
const DATA_TRANSFER_FILES_SLOT: &str = "__lmDataTransferFiles";
-const DATA_TRANSFER_BRAND_SLOT: &str = "__lmDataTransferBrand";
const DATA_TRANSFER_ITEMS_SLOT: &str = "__lmDataTransferItems";
const DATA_TRANSFER_TYPES_SLOT: &str = "__lmDataTransferTypes";
const DATA_TRANSFER_DROP_EFFECT_SLOT: &str = "__lmDataTransferDropEffect";
@@ -46,8 +45,6 @@ pub(super) const FILE_SYSTEM_DIRECTORY_READER_ERROR_SLOT: &str =
#[derive(WebApiObject)]
#[webapi(interface = "DataTransfer", require_prototype)]
struct DataTransferObjectDeclaration<'s> {
- #[webapi(slot = DATA_TRANSFER_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = DATA_TRANSFER_FILES_SLOT)]
files: v8::Local<'s, v8::Object>,
#[webapi(slot = DATA_TRANSFER_ITEMS_SLOT)]
@@ -66,8 +63,7 @@ pub(crate) fn is_branded_data_transfer_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, object, DATA_TRANSFER_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, object, "DataTransfer")
}
#[derive(Default, WebApiObject)]
diff --git a/moli-renderer-v8/src/context_bootstrap/form_data_runtime.rs b/moli-renderer-v8/src/context_bootstrap/form_data_runtime.rs
index 958cdd3d9..e43fba0a4 100644
--- a/moli-renderer-v8/src/context_bootstrap/form_data_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/form_data_runtime.rs
@@ -1,4 +1,4 @@
-use super::url_form::{callback_value_string, object_prototype_matches};
+use super::url_form::callback_value_string;
use super::*;
mod callbacks;
diff --git a/moli-renderer-v8/src/context_bootstrap/form_data_runtime/storage.rs b/moli-renderer-v8/src/context_bootstrap/form_data_runtime/storage.rs
index 906d2ee86..6dad02c40 100644
--- a/moli-renderer-v8/src/context_bootstrap/form_data_runtime/storage.rs
+++ b/moli-renderer-v8/src/context_bootstrap/form_data_runtime/storage.rs
@@ -10,11 +10,11 @@ struct FormDataObjectDeclaration<'scope> {
entries: v8::Local<'scope, v8::Array>,
}
-pub(in crate::context_bootstrap) fn form_data_is_object(
- scope: &mut v8::PinScope<'_, '_>,
- object: v8::Local<'_, v8::Object>,
+pub(in crate::context_bootstrap) fn form_data_is_object<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ object: v8::Local<'s, v8::Object>,
) -> bool {
- object_prototype_matches(scope, object, "FormData")
+ moli_webapi_declare::implements_interface(scope, object, "FormData")
}
pub(in crate::context_bootstrap) fn form_data_entries<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/geometry_runtime.rs b/moli-renderer-v8/src/context_bootstrap/geometry_runtime.rs
index 1ff871212..fb6b6450d 100644
--- a/moli-renderer-v8/src/context_bootstrap/geometry_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/geometry_runtime.rs
@@ -12,7 +12,6 @@ const DOM_POINT_X_SLOT: &str = "__moliDomPointX";
const DOM_POINT_Y_SLOT: &str = "__moliDomPointY";
const DOM_POINT_Z_SLOT: &str = "__moliDomPointZ";
const DOM_POINT_W_SLOT: &str = "__moliDomPointW";
-const DOM_POINT_BRAND_SLOT: &str = "__moliDomPointBrand";
const DOM_MATRIX_M11_SLOT: &str = "__moliDomMatrixM11";
const DOM_MATRIX_M12_SLOT: &str = "__moliDomMatrixM12";
@@ -30,16 +29,11 @@ const DOM_MATRIX_M41_SLOT: &str = "__moliDomMatrixM41";
const DOM_MATRIX_M42_SLOT: &str = "__moliDomMatrixM42";
const DOM_MATRIX_M43_SLOT: &str = "__moliDomMatrixM43";
const DOM_MATRIX_M44_SLOT: &str = "__moliDomMatrixM44";
-const DOM_MATRIX_READONLY_BRAND_SLOT: &str = "__moliDomMatrixReadOnlyBrand";
-const DOM_MATRIX_MUTABLE_BRAND_SLOT: &str = "__moliDomMatrixMutableBrand";
const DOM_MATRIX_TYPED_ARRAY_LENGTH: usize = DOM_MATRIX_COMPONENT_COUNT;
#[derive(WebApiObject)]
#[webapi(interface = "DOMPoint", fallback_to_string_tag = "DOMPoint")]
struct DomPointObjectDeclaration {
- #[webapi(slot = DOM_POINT_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = DOM_POINT_X_SLOT)]
x: f64,
#[webapi(slot = DOM_POINT_Y_SLOT)]
@@ -51,32 +45,10 @@ struct DomPointObjectDeclaration {
}
macro_rules! dom_matrix_object_declaration {
- ($name:ident, $interface:literal, mutable) => {
- dom_matrix_object_declaration!(
- @body
- $name,
- $interface,
- {
- #[webapi(slot = DOM_MATRIX_MUTABLE_BRAND_SLOT, init = true)]
- mutable_brand: (),
- },
- {
- mutable_brand: (),
- }
- );
- };
- ($name:ident, $interface:literal, readonly) => {
- dom_matrix_object_declaration!(@body $name, $interface, {}, {});
- };
- (@body $name:ident, $interface:literal, {$($extra_field:tt)*}, {$($extra_init:tt)*}) => {
+ ($name:ident, $interface:literal) => {
#[derive(WebApiObject)]
#[webapi(interface = $interface, fallback_to_string_tag = $interface)]
struct $name {
- #[webapi(slot = DOM_MATRIX_READONLY_BRAND_SLOT, init = true)]
- readonly_brand: (),
-
- $($extra_field)*
-
#[webapi(slot = DOM_MATRIX_M11_SLOT)]
m11: f64,
#[webapi(slot = DOM_MATRIX_M12_SLOT)]
@@ -114,8 +86,6 @@ macro_rules! dom_matrix_object_declaration {
impl $name {
fn from_components(components: DomMatrixComponents) -> Self {
Self {
- readonly_brand: (),
- $($extra_init)*
m11: components.m11,
m12: components.m12,
m13: components.m13,
@@ -142,12 +112,8 @@ macro_rules! dom_matrix_object_declaration {
};
}
-dom_matrix_object_declaration!(DomMatrixObjectDeclaration, "DOMMatrix", mutable);
-dom_matrix_object_declaration!(
- DomMatrixReadOnlyObjectDeclaration,
- "DOMMatrixReadOnly",
- readonly
-);
+dom_matrix_object_declaration!(DomMatrixObjectDeclaration, "DOMMatrix");
+dom_matrix_object_declaration!(DomMatrixReadOnlyObjectDeclaration, "DOMMatrixReadOnly");
#[derive(WebApiObject)]
#[webapi(interface = "Object", data_properties, enumerable)]
@@ -892,15 +858,14 @@ fn dom_point_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, DOM_POINT_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "DOMPoint")
}
fn dom_matrix_require_readonly_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- if dom_matrix_receiver_branded(scope, receiver, DOM_MATRIX_READONLY_BRAND_SLOT) {
+ if moli_webapi_declare::implements_interface(scope, receiver, "DOMMatrixReadOnly") {
return true;
}
throw_type_error(scope, "Illegal invocation");
@@ -911,21 +876,13 @@ fn dom_matrix_require_mutable_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- if dom_matrix_receiver_branded(scope, receiver, DOM_MATRIX_MUTABLE_BRAND_SLOT) {
+ if moli_webapi_declare::implements_interface(scope, receiver, "DOMMatrix") {
return true;
}
throw_type_error(scope, "Illegal invocation");
false
}
-fn dom_matrix_receiver_branded<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
- brand: &'static str,
-) -> bool {
- get_private_value(scope, receiver, brand).is_some_and(|value| value.boolean_value(scope))
-}
-
fn dom_matrix_to_json_callback<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
diff --git a/moli-renderer-v8/src/context_bootstrap/idle_detection.rs b/moli-renderer-v8/src/context_bootstrap/idle_detection.rs
index c39ded79d..d2d92af40 100644
--- a/moli-renderer-v8/src/context_bootstrap/idle_detection.rs
+++ b/moli-renderer-v8/src/context_bootstrap/idle_detection.rs
@@ -11,7 +11,6 @@ use crate::{
};
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
-const IDLE_DETECTOR_BRAND_SLOT: &str = "__lmIdleDetectorBrand";
const IDLE_DETECTOR_STARTED_SLOT: &str = "__lmIdleDetectorStarted";
const IDLE_DETECTOR_USER_ACTIVE_SLOT: &str = "__lmIdleDetectorUserActive";
const IDLE_DETECTOR_SCREEN_UNLOCKED_SLOT: &str = "__lmIdleDetectorScreenUnlocked";
@@ -27,9 +26,6 @@ const ACTUAL_IDLE_STATE: crate::protocol_types::EmulatedIdleOverride =
#[derive(WebApiObject)]
#[webapi(interface = "IdleDetector")]
struct IdleDetectorObjectDeclaration {
- #[webapi(slot = IDLE_DETECTOR_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = IDLE_DETECTOR_STARTED_SLOT)]
started: bool,
@@ -115,9 +111,7 @@ fn idle_detector_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> Option<v8::Local<'s, v8::Object>> {
- if get_private_value(scope, receiver, IDLE_DETECTOR_BRAND_SLOT)
- .is_some_and(|value| value.is_true())
- {
+ if moli_webapi_declare::implements_interface(scope, receiver, "IdleDetector") {
return Some(receiver);
}
throw_type_error(scope, "Illegal invocation");
diff --git a/moli-renderer-v8/src/context_bootstrap/image_data.rs b/moli-renderer-v8/src/context_bootstrap/image_data.rs
index 38a4e2d62..c36fa2f1f 100644
--- a/moli-renderer-v8/src/context_bootstrap/image_data.rs
+++ b/moli-renderer-v8/src/context_bootstrap/image_data.rs
@@ -10,14 +10,10 @@ const IMAGE_DATA_HEIGHT_SLOT: &str = "__moliImageDataHeight";
const IMAGE_DATA_COLOR_SPACE_SLOT: &str = "__moliImageDataColorSpace";
const IMAGE_DATA_PIXEL_FORMAT_SLOT: &str = "__moliImageDataPixelFormat";
const IMAGE_DATA_DATA_SLOT: &str = "__moliImageDataData";
-const IMAGE_DATA_BRAND_SLOT: &str = "__moliImageDataBrand";
#[derive(WebApiObject)]
#[webapi(interface = "ImageData")]
struct ImageDataObjectDeclaration<'s> {
- #[webapi(slot = IMAGE_DATA_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = IMAGE_DATA_WIDTH_SLOT)]
width: u32,
#[webapi(slot = IMAGE_DATA_HEIGHT_SLOT)]
@@ -171,8 +167,7 @@ fn image_data_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, IMAGE_DATA_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "ImageData")
}
fn image_data_constructor_parts<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/media_cues.rs b/moli-renderer-v8/src/context_bootstrap/media_cues.rs
index a678c3d54..085691851 100644
--- a/moli-renderer-v8/src/context_bootstrap/media_cues.rs
+++ b/moli-renderer-v8/src/context_bootstrap/media_cues.rs
@@ -323,7 +323,7 @@ fn text_track_cue_receiver<'s>(
args: &v8::FunctionCallbackArguments<'s>,
) -> Option<v8::Local<'s, v8::Object>> {
let receiver = args.this();
- if get_private_value(scope, receiver, TEXT_TRACK_CUE_START_TIME_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, "TextTrackCue") {
return Some(receiver);
}
throw_type_error(scope, "Illegal invocation");
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime.rs
index 7e2745d59..9b48b04e7 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime.rs
@@ -17,10 +17,10 @@ pub(crate) use self::navigator::build_lightweight_popup_window_navigator_object;
pub(super) use self::navigator::install_navigator_template_bindings;
pub(crate) use self::navigator::install_worker_navigator_runtime_state;
pub(in crate::context_bootstrap) use self::navigator::{
- SERVICE_WORKER_OWNER_TOKEN_SLOT, STORAGE_BUCKET_MANAGER_BRAND_SLOT,
- STORAGE_BUCKET_MANAGER_CHILD_HANDLE_SLOT, STORAGE_BUCKET_MANAGER_POPUP_ID_SLOT,
- STORAGE_MANAGER_BRAND_SLOT, STORAGE_MANAGER_CHILD_HANDLE_SLOT, STORAGE_MANAGER_POPUP_ID_SLOT,
- build_storage_manager_worker_template, current_protocol_user_gesture_activation,
+ SERVICE_WORKER_OWNER_TOKEN_SLOT, STORAGE_BUCKET_MANAGER_CHILD_HANDLE_SLOT,
+ STORAGE_BUCKET_MANAGER_POPUP_ID_SLOT, STORAGE_MANAGER_CHILD_HANDLE_SLOT,
+ STORAGE_MANAGER_POPUP_ID_SLOT, build_storage_manager_worker_template,
+ current_protocol_user_gesture_activation,
install_storage_manager_constructor_template_bindings, navigator_identity_profile,
navigator_receiver_branded, service_worker_owner_token_value, set_navigator_identity_profile,
};
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/clipboard.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/clipboard.rs
index 97aea80a7..a4ea66e72 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/clipboard.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/clipboard.rs
@@ -7,12 +7,10 @@ use crate::{
use anyhow::{Result, anyhow};
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
-const CLIPBOARD_BRAND_SLOT: &str = "__moliClipboardBrand";
const CLIPBOARD_ITEMS_SLOT: &str = "__moliClipboardItems";
const CLIPBOARD_TEXT_SLOT: &str = "__moliClipboardText";
const CLIPBOARD_EVENT_LISTENERS_SLOT: &str = "__moliClipboardEventListeners";
-const CLIPBOARD_ITEM_BRAND_SLOT: &str = "__moliClipboardItemBrand";
const CLIPBOARD_ITEM_DATA_SLOT: &str = "__moliClipboardItemData";
const CLIPBOARD_ITEM_RAW_DATA_SLOT: &str = "__moliClipboardItemRawData";
const CLIPBOARD_ITEM_TYPES_SLOT: &str = "__moliClipboardItemTypes";
@@ -21,9 +19,6 @@ const CLIPBOARD_ITEM_PRESENTATION_STYLE_SLOT: &str = "__moliClipboardItemPresent
#[derive(Default, WebApiObject)]
#[webapi(interface = "Clipboard")]
struct ClipboardObjectDeclaration {
- #[webapi(slot = CLIPBOARD_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = SIMPLE_EVENT_TARGET_SLOT, value = CLIPBOARD_EVENT_LISTENERS_SLOT)]
event_target_slot: (),
@@ -56,9 +51,6 @@ struct ClipboardPrototypeDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "ClipboardItem")]
struct ClipboardItemObjectDeclaration<'scope> {
- #[webapi(slot = CLIPBOARD_ITEM_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = CLIPBOARD_ITEM_DATA_SLOT)]
data: v8::Local<'scope, v8::Object>,
@@ -416,16 +408,14 @@ fn clipboard_item_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, CLIPBOARD_ITEM_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "ClipboardItem")
}
fn clipboard_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, CLIPBOARD_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "Clipboard")
}
fn clipboard_item_presentation_style_getter<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/collections.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/collections.rs
index c64583185..379436889 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/collections.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/collections.rs
@@ -32,9 +32,6 @@ const PDF_MIME_TYPES: &[(&str, &str, &str)] = &[
("text/pdf", "pdf", "Portable Document Format"),
];
-const PLUGIN_ARRAY_BRAND_SLOT: &str = "__moliPluginArrayBrand";
-const MIME_TYPE_ARRAY_BRAND_SLOT: &str = "__moliMimeTypeArrayBrand";
-const PLUGIN_BRAND_SLOT: &str = "__moliPluginBrand";
const COLLECTION_LENGTH_SLOT: &str = "__moliNavigatorCollectionLength";
#[derive(WebApiObject)]
@@ -56,9 +53,6 @@ struct MimeTypeObjectDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "MimeTypeArray")]
struct MimeTypeArrayObjectDeclaration {
- #[webapi(slot = MIME_TYPE_ARRAY_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = COLLECTION_LENGTH_SLOT)]
length: u32,
}
@@ -66,9 +60,6 @@ struct MimeTypeArrayObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "PluginArray")]
struct PluginArrayObjectDeclaration {
- #[webapi(slot = PLUGIN_ARRAY_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = COLLECTION_LENGTH_SLOT)]
length: u32,
}
@@ -76,9 +67,6 @@ struct PluginArrayObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "Plugin")]
struct PluginObjectDeclaration<'scope> {
- #[webapi(slot = PLUGIN_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = COLLECTION_LENGTH_SLOT)]
length: u32,
@@ -175,7 +163,7 @@ fn plugin_array_length_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- collection_length_getter_for(scope, args, rv, PLUGIN_ARRAY_BRAND_SLOT);
+ collection_length_getter_for(scope, args, rv, "PluginArray");
}
fn mime_type_array_length_getter<'s>(
@@ -183,7 +171,7 @@ fn mime_type_array_length_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- collection_length_getter_for(scope, args, rv, MIME_TYPE_ARRAY_BRAND_SLOT);
+ collection_length_getter_for(scope, args, rv, "MimeTypeArray");
}
fn plugin_length_getter<'s>(
@@ -191,16 +179,16 @@ fn plugin_length_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- collection_length_getter_for(scope, args, rv, PLUGIN_BRAND_SLOT);
+ collection_length_getter_for(scope, args, rv, "Plugin");
}
fn collection_length_getter_for<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
- brand_slot: &'static str,
+ interface: &'static str,
) {
- if !receiver_has_brand(scope, args.this(), brand_slot) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), interface) {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -214,7 +202,7 @@ fn plugin_array_item_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- collection_item_callback_for(scope, args, rv, PLUGIN_ARRAY_BRAND_SLOT);
+ collection_item_callback_for(scope, args, rv, "PluginArray");
}
fn plugin_array_named_item_callback<'s>(
@@ -222,7 +210,7 @@ fn plugin_array_named_item_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- collection_named_item_callback_for(scope, args, rv, PLUGIN_ARRAY_BRAND_SLOT);
+ collection_named_item_callback_for(scope, args, rv, "PluginArray");
}
fn mime_type_array_item_callback<'s>(
@@ -230,7 +218,7 @@ fn mime_type_array_item_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- collection_item_callback_for(scope, args, rv, MIME_TYPE_ARRAY_BRAND_SLOT);
+ collection_item_callback_for(scope, args, rv, "MimeTypeArray");
}
fn mime_type_array_named_item_callback<'s>(
@@ -238,7 +226,7 @@ fn mime_type_array_named_item_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- collection_named_item_callback_for(scope, args, rv, MIME_TYPE_ARRAY_BRAND_SLOT);
+ collection_named_item_callback_for(scope, args, rv, "MimeTypeArray");
}
fn plugin_item_callback<'s>(
@@ -246,7 +234,7 @@ fn plugin_item_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- collection_item_callback_for(scope, args, rv, PLUGIN_BRAND_SLOT);
+ collection_item_callback_for(scope, args, rv, "Plugin");
}
fn plugin_named_item_callback<'s>(
@@ -254,20 +242,20 @@ fn plugin_named_item_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- collection_named_item_callback_for(scope, args, rv, PLUGIN_BRAND_SLOT);
+ collection_named_item_callback_for(scope, args, rv, "Plugin");
}
fn collection_item_callback_for<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
- brand_slot: &'static str,
+ interface: &'static str,
) {
let Some(this_obj) = args.this().to_object(scope) else {
throw_type_error(scope, "Illegal invocation");
return;
};
- if !receiver_has_brand(scope, this_obj, brand_slot) {
+ if !moli_webapi_declare::implements_interface(scope, this_obj, interface) {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -284,13 +272,13 @@ fn collection_named_item_callback_for<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
- brand_slot: &'static str,
+ interface: &'static str,
) {
let Some(this_obj) = args.this().to_object(scope) else {
throw_type_error(scope, "Illegal invocation");
return;
};
- if !receiver_has_brand(scope, this_obj, brand_slot) {
+ if !moli_webapi_declare::implements_interface(scope, this_obj, interface) {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -313,19 +301,11 @@ fn plugin_array_refresh_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
_rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), PLUGIN_ARRAY_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "PluginArray") {
throw_type_error(scope, "Illegal invocation");
}
}
-fn receiver_has_brand<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
- slot: &'static str,
-) -> bool {
- get_private_value(scope, receiver, slot).is_some_and(|value| value.boolean_value(scope))
-}
-
fn build_mime_type<'s>(
scope: &mut v8::PinScope<'s, '_>,
type_name: &str,
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs
index ad7442089..bd92653fd 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/geolocation.rs
@@ -12,11 +12,9 @@ use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
mod position;
mod watches;
-const GEOLOCATION_BRAND_SLOT: &str = "__moliGeolocationBrand";
const GEOLOCATION_SECURE_CONTEXT_SLOT: &str = "__moliGeolocationSecureContext";
const GEOLOCATION_NEXT_WATCH_ID_SLOT: &str = "__moliGeolocationNextWatchId";
const GEOLOCATION_CHILD_HANDLE_SLOT: &str = "__moliGeolocationChildHandle";
-const GEOLOCATION_POSITION_ERROR_BRAND_SLOT: &str = "__moliGeolocationPositionErrorBrand";
const GEOLOCATION_POSITION_ERROR_CODE_SLOT: &str = "__moliGeolocationPositionErrorCode";
const GEOLOCATION_POSITION_ERROR_MESSAGE_SLOT: &str = "__moliGeolocationPositionErrorMessage";
@@ -27,9 +25,6 @@ const TIMEOUT: u16 = 3;
#[derive(WebApiObject)]
#[webapi(interface = "Geolocation")]
struct GeolocationObjectDeclaration {
- #[webapi(slot = GEOLOCATION_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = GEOLOCATION_SECURE_CONTEXT_SLOT)]
secure_context: bool,
@@ -53,9 +48,6 @@ struct GeolocationPrototypeMethodsDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "GeolocationPositionError")]
struct GeolocationPositionErrorObjectDeclaration {
- #[webapi(slot = GEOLOCATION_POSITION_ERROR_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = GEOLOCATION_POSITION_ERROR_CODE_SLOT)]
code: u16,
@@ -308,8 +300,7 @@ fn geolocation_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, GEOLOCATION_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "Geolocation")
}
fn take_next_watch_id<'s>(
@@ -447,9 +438,7 @@ fn geolocation_position_error_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> Option<v8::Local<'s, v8::Object>> {
- if get_private_value(scope, receiver, GEOLOCATION_POSITION_ERROR_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
- {
+ if moli_webapi_declare::implements_interface(scope, receiver, "GeolocationPositionError") {
Some(receiver)
} else {
throw_type_error(scope, "Illegal invocation");
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_capabilities.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_capabilities.rs
index 83c4f6143..978ea2f9d 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_capabilities.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_capabilities.rs
@@ -2,16 +2,12 @@ use super::super::*;
use crate::{util::get_private_value, webidl};
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
-const MEDIA_CAPABILITIES_BRAND_SLOT: &str = "__moliMediaCapabilitiesBrand";
const MEDIA_CAPABILITIES_SECURE_CONTEXT_SLOT: &str = "__moliMediaCapabilitiesSecureContext";
const MEDIA_CAPABILITIES_WORKER_SLOT: &str = "__moliMediaCapabilitiesWorker";
#[derive(WebApiObject)]
#[webapi(interface = "MediaCapabilities")]
struct MediaCapabilitiesObjectDeclaration {
- #[webapi(slot = MEDIA_CAPABILITIES_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = MEDIA_CAPABILITIES_SECURE_CONTEXT_SLOT)]
secure_context: bool,
@@ -478,8 +474,7 @@ fn media_capabilities_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, MEDIA_CAPABILITIES_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "MediaCapabilities")
}
fn media_capabilities_is_secure_context<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_devices.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_devices.rs
index 189a1f2be..3d9a00365 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_devices.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/media_devices.rs
@@ -1,6 +1,4 @@
-use super::super::window_runtime::{
- MEDIA_DEVICES_BRAND_SLOT, navigator_media_devices_get_user_media_callback,
-};
+use super::super::window_runtime::navigator_media_devices_get_user_media_callback;
use super::super::*;
use crate::util::{get_private_value, set_private_value, throw_type_error};
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
@@ -11,9 +9,6 @@ const MEDIA_DEVICES_ONDEVICECHANGE_SLOT: &str = "__moliMediaDevicesOndevicechang
#[derive(Default, WebApiObject)]
#[webapi(interface = "MediaDevices")]
struct MediaDevicesObjectDeclaration {
- #[webapi(slot = MEDIA_DEVICES_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = SIMPLE_EVENT_TARGET_SLOT, value = MEDIA_DEVICES_LISTENERS_SLOT)]
event_target_slot: (),
@@ -55,8 +50,7 @@ fn receiver_is_media_devices<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, MEDIA_DEVICES_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "MediaDevices")
}
fn enumerate_devices_callback<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs
index e03215114..8c01fed54 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/navigator.rs
@@ -1,5 +1,5 @@
use super::super::window_runtime::{
- PERMISSIONS_BRAND_SLOT, build_legacy_storage_quota_object, build_navigator_ua_data_object,
+ build_legacy_storage_quota_object, build_navigator_ua_data_object,
install_initial_service_worker_ready_promise, navigator_get_battery_callback,
navigator_java_enabled_callback, navigator_permissions_query_callback,
navigator_send_beacon_callback, navigator_service_worker_controller_getter_callback,
@@ -82,20 +82,15 @@ const WORKER_NAVIGATOR_USER_AGENT_SEED_SLOT: &str = "__moliWorkerNavigatorUserAg
const WORKER_NAVIGATOR_ACCEPT_LANGUAGE_SEED_SLOT: &str = "__moliWorkerNavigatorAcceptLanguageSeed";
const WORKER_NAVIGATOR_BACKING_SLOT: &str = "__moliWorkerNavigatorBacking";
-const NAVIGATOR_BRAND_SLOT: &str = "__moliNavigatorBrand";
const NAVIGATOR_STORAGE_OWNER_CHILD_HANDLE_SLOT: &str = "__moliNavigatorStorageOwnerChildHandle";
const NAVIGATOR_STORAGE_OWNER_POPUP_ID_SLOT: &str = "__moliNavigatorStorageOwnerPopupId";
const NAVIGATOR_ACCEPT_LANGUAGE_SLOT: &str = "__moliNavigatorAcceptLanguage";
pub(in crate::context_bootstrap) const NAVIGATOR_IDENTITY_PROFILE_SLOT: &str =
"__moliNavigatorIdentityProfile";
-pub(in crate::context_bootstrap) const STORAGE_MANAGER_BRAND_SLOT: &str =
- "__moliStorageManagerBrand";
pub(in crate::context_bootstrap) const STORAGE_MANAGER_CHILD_HANDLE_SLOT: &str =
"__moliStorageManagerChildHandle";
pub(in crate::context_bootstrap) const STORAGE_MANAGER_POPUP_ID_SLOT: &str =
"__moliStorageManagerPopupId";
-pub(in crate::context_bootstrap) const STORAGE_BUCKET_MANAGER_BRAND_SLOT: &str =
- "__moliStorageBucketManagerBrand";
pub(in crate::context_bootstrap) const STORAGE_BUCKET_MANAGER_CHILD_HANDLE_SLOT: &str =
"__moliStorageBucketManagerChildHandle";
pub(in crate::context_bootstrap) const STORAGE_BUCKET_MANAGER_POPUP_ID_SLOT: &str =
@@ -109,15 +104,10 @@ const SERVICE_WORKER_CONTAINER_ONCONTROLLERCHANGE_SLOT: &str =
const SERVICE_WORKER_CONTAINER_CONTROLLER_SLOT: &str = "__moliServiceWorkerContainerController";
pub(in crate::context_bootstrap) const SERVICE_WORKER_OWNER_TOKEN_SLOT: &str =
"__moliServiceWorkerOwner";
-const USER_ACTIVATION_BRAND_SLOT: &str = "__moliUserActivationBrand";
-const NAVIGATOR_CONNECTION_BRAND_SLOT: &str = "__moliNavigatorConnectionBrand";
#[derive(Default, WebApiObject)]
#[webapi(interface = "Permissions", allow_empty)]
-struct PermissionsObjectDeclaration {
- #[webapi(slot = PERMISSIONS_BRAND_SLOT, init = true)]
- brand: (),
-}
+struct PermissionsObjectDeclaration {}
#[derive(Default, WebApiFunctionTemplate)]
#[webapi(name = "Permissions", enumerable)]
@@ -129,9 +119,6 @@ struct PermissionsPrototypeMethodsDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "Navigator")]
struct NavigatorObjectDeclaration<'scope> {
- #[webapi(slot = NAVIGATOR_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = NAVIGATOR_RUNTIME_DATA_SLOT)]
runtime_data: v8::Local<'scope, v8::Object>,
}
@@ -297,9 +284,6 @@ struct PermissionStatusPrototypeDeclaration {
prototype = "Object"
)]
struct NavigatorConnectionDeclaration {
- #[webapi(slot = NAVIGATOR_CONNECTION_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(data_property, name = "type", enumerable, value = DEFAULT_CONNECTION_TYPE)]
connection_type: (),
@@ -339,11 +323,8 @@ struct NavigatorConnectionDeclaration {
}
#[derive(WebApiObject)]
-#[webapi(interface = "StorageManager")]
-struct StorageManagerObjectDeclaration {
- #[webapi(slot, name = STORAGE_MANAGER_BRAND_SLOT, constructor_default = true)]
- brand: bool,
-}
+#[webapi(allow_empty, interface = "StorageManager")]
+struct StorageManagerObjectDeclaration {}
#[derive(WebApiFunctionTemplate)]
#[webapi(name = "StorageManager", enumerable)]
@@ -396,15 +377,8 @@ pub(in crate::context_bootstrap) fn install_storage_manager_constructor_template
}
#[derive(WebApiObject)]
-#[webapi(interface = "StorageBucketManager")]
-struct StorageBucketManagerObjectDeclaration {
- #[webapi(
- slot,
- name = STORAGE_BUCKET_MANAGER_BRAND_SLOT,
- constructor_default = true
- )]
- brand: bool,
-}
+#[webapi(allow_empty, interface = "StorageBucketManager")]
+struct StorageBucketManagerObjectDeclaration {}
#[derive(Default, WebApiFunctionTemplate)]
#[webapi(name = "NavigatorUAData", enumerable)]
@@ -486,9 +460,6 @@ struct ServiceWorkerContainerDeclaration {
#[derive(Default, WebApiObject)]
#[webapi(interface = "UserActivation")]
struct UserActivationObjectDeclaration {
- #[webapi(slot = USER_ACTIVATION_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(accessor_property, getter = navigator_user_activation_state_getter_callback, enumerable)]
is_active: (),
@@ -723,8 +694,7 @@ pub(in crate::context_bootstrap) fn navigator_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
navigator: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, navigator, NAVIGATOR_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, navigator, "Navigator")
}
pub(crate) fn current_protocol_user_gesture_activation(scope: &mut v8::PinScope<'_, '_>) -> bool {
@@ -737,9 +707,7 @@ fn navigator_user_activation_state_getter_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if get_private_value(scope, args.this(), USER_ACTIVATION_BRAND_SLOT)
- .is_none_or(|value| !value.boolean_value(scope))
- {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "UserActivation") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -814,8 +782,7 @@ fn navigator_connection_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, NAVIGATOR_CONNECTION_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "NetworkInformation")
}
pub(in crate::context_bootstrap) fn install_navigator_template_bindings<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/screen.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/screen.rs
index 819c6921a..6201a27f4 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/screen.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/screen.rs
@@ -11,7 +11,6 @@ use crate::util::{
use crate::webidl;
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
-const SCREEN_BRAND_SLOT: &str = "__moliScreenBrand";
const SCREEN_WIDTH_SLOT: &str = "__moliScreenWidth";
const SCREEN_HEIGHT_SLOT: &str = "__moliScreenHeight";
const SCREEN_AVAIL_WIDTH_SLOT: &str = "__moliScreenAvailWidth";
@@ -22,7 +21,6 @@ const SCREEN_COLOR_DEPTH_SLOT: &str = "__moliScreenColorDepth";
const SCREEN_PIXEL_DEPTH_SLOT: &str = "__moliScreenPixelDepth";
const SCREEN_ORIENTATION_SLOT: &str = "__moliScreenOrientation";
-const SCREEN_ORIENTATION_BRAND_SLOT: &str = "__moliScreenOrientationBrand";
const SCREEN_ORIENTATION_TYPE_SLOT: &str = "__moliScreenOrientationType";
const SCREEN_ORIENTATION_ANGLE_SLOT: &str = "__moliScreenOrientationAngle";
const SCREEN_ORIENTATION_ONCHANGE_SLOT: &str = "__moliScreenOrientationOnchange";
@@ -50,9 +48,6 @@ struct ScreenOrientationLockArgs {
#[derive(WebApiObject)]
#[webapi(interface = "Screen")]
struct ScreenObjectDeclaration {
- #[webapi(slot = SCREEN_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = SCREEN_WIDTH_SLOT)]
width: f64,
#[webapi(slot = SCREEN_HEIGHT_SLOT)]
@@ -97,9 +92,6 @@ struct ScreenPrototypeAccessorsDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "ScreenOrientation")]
struct ScreenOrientationObjectDeclaration {
- #[webapi(slot = SCREEN_ORIENTATION_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = SCREEN_ORIENTATION_TYPE_SLOT)]
orientation_type: &'static str,
#[webapi(slot = SCREEN_ORIENTATION_ANGLE_SLOT)]
@@ -197,7 +189,7 @@ fn screen_orientation_lock_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_ORIENTATION_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "ScreenOrientation") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -228,7 +220,7 @@ fn screen_orientation_unlock_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_ORIENTATION_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "ScreenOrientation") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -240,7 +232,7 @@ fn screen_event_target_add_event_listener_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "Screen") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -252,7 +244,7 @@ fn screen_event_target_remove_event_listener_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "Screen") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -264,7 +256,7 @@ fn screen_event_target_dispatch_event_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "Screen") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -276,7 +268,7 @@ fn screen_orientation_event_target_add_event_listener_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_ORIENTATION_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "ScreenOrientation") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -288,7 +280,7 @@ fn screen_orientation_event_target_remove_event_listener_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_ORIENTATION_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "ScreenOrientation") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -300,7 +292,7 @@ fn screen_orientation_event_target_dispatch_event_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_ORIENTATION_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "ScreenOrientation") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -338,7 +330,6 @@ pub(in crate::context_bootstrap) fn build_window_screen<'s>(
) -> Result<v8::Local<'s, v8::Object>> {
let profile = &DEFAULT_WINDOW_SURFACE_PROFILE;
let screen = ScreenObjectDeclaration {
- brand: (),
width: profile.screen_width,
height: profile.screen_height,
avail_width: profile.screen_avail_width,
@@ -373,7 +364,7 @@ fn screen_attribute_getter_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "Screen") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -455,7 +446,7 @@ fn screen_orientation_attribute_getter_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_ORIENTATION_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "ScreenOrientation") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -493,7 +484,7 @@ fn screen_orientation_onchange_getter_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_ORIENTATION_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "ScreenOrientation") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -508,7 +499,7 @@ fn screen_orientation_onchange_setter_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !receiver_has_brand(scope, args.this(), SCREEN_ORIENTATION_BRAND_SLOT) {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "ScreenOrientation") {
throw_type_error(scope, "Illegal invocation");
return;
}
@@ -520,11 +511,3 @@ fn screen_orientation_onchange_setter_callback<'s>(
);
rv.set_undefined();
}
-
-fn receiver_has_brand<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
- slot: &'static str,
-) -> bool {
- get_private_value(scope, receiver, slot).is_some_and(|value| value.boolean_value(scope))
-}
diff --git a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/visual_viewport.rs b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/visual_viewport.rs
index 209995da8..1275d1c5c 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigator_runtime/visual_viewport.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigator_runtime/visual_viewport.rs
@@ -4,7 +4,6 @@ use crate::util::{
};
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
-const VISUAL_VIEWPORT_BRAND_SLOT: &str = "__moliVisualViewportBrand";
const VISUAL_VIEWPORT_OFFSET_LEFT_SLOT: &str = "__moliVisualViewportOffsetLeft";
const VISUAL_VIEWPORT_OFFSET_TOP_SLOT: &str = "__moliVisualViewportOffsetTop";
const VISUAL_VIEWPORT_PAGE_LEFT_SLOT: &str = "__moliVisualViewportPageLeft";
@@ -16,9 +15,6 @@ const VISUAL_VIEWPORT_SCALE_SLOT: &str = "__moliVisualViewportScale";
#[derive(WebApiObject)]
#[webapi(interface = "VisualViewport")]
struct VisualViewportObjectDeclaration {
- #[webapi(slot = VISUAL_VIEWPORT_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = VISUAL_VIEWPORT_OFFSET_LEFT_SLOT)]
offset_left: f64,
#[webapi(slot = VISUAL_VIEWPORT_OFFSET_TOP_SLOT)]
@@ -73,7 +69,6 @@ pub(in crate::context_bootstrap) fn build_window_visual_viewport<'s>(
) -> Result<v8::Local<'s, v8::Object>> {
let profile = &DEFAULT_WINDOW_SURFACE_PROFILE;
Ok(VisualViewportObjectDeclaration {
- brand: (),
offset_left: 0.0,
offset_top: 0.0,
page_left: 0.0,
@@ -107,9 +102,7 @@ fn visual_viewport_attribute_getter_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- if get_private_value(scope, args.this(), VISUAL_VIEWPORT_BRAND_SLOT)
- .is_none_or(|value| !value.boolean_value(scope))
- {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "VisualViewport") {
throw_type_error(scope, "Illegal invocation");
return;
}
diff --git a/moli-renderer-v8/src/context_bootstrap/notification_runtime.rs b/moli-renderer-v8/src/context_bootstrap/notification_runtime.rs
index 4c3f867c8..c1e878a64 100644
--- a/moli-renderer-v8/src/context_bootstrap/notification_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/notification_runtime.rs
@@ -37,7 +37,6 @@ const NOTIFICATION_ACTIONS_SLOT: &str = "__lmNotificationActions";
const NOTIFICATION_RECORD_ID_SLOT: &str = "__lmNotificationRecordId";
const NOTIFICATION_RECORD_REGISTRATION_ID_SLOT: &str = "__lmNotificationRecordRegistrationId";
const NOTIFICATION_LISTENERS_SLOT: &str = "__lmNotificationListeners";
-const NOTIFICATION_BRAND_SLOT: &str = "__lmNotificationBrand";
const NOTIFICATION_MAX_ACTIONS: usize = 2;
pub(crate) struct NotificationOptionsPayload {
@@ -50,9 +49,6 @@ pub(crate) struct NotificationOptionsPayload {
#[derive(WebApiObject)]
#[webapi(interface = "Notification")]
struct NotificationObjectDeclaration<'scope> {
- #[webapi(slot = NOTIFICATION_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = NOTIFICATION_TITLE_SLOT)]
title: String,
@@ -914,7 +910,6 @@ fn initialize_notification_object<'s>(
.map(|silent| v8::Boolean::new(scope, silent).into())
.unwrap_or_else(|| v8::null(scope).into());
NotificationObjectDeclaration {
- brand: (),
title,
data,
tag,
@@ -1305,8 +1300,7 @@ fn notification_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, NOTIFICATION_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "Notification")
}
fn notification_event_target_add_event_listener_callback<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/opfs.rs b/moli-renderer-v8/src/context_bootstrap/opfs.rs
index eae3c2bfc..e8acaea91 100644
--- a/moli-renderer-v8/src/context_bootstrap/opfs.rs
+++ b/moli-renderer-v8/src/context_bootstrap/opfs.rs
@@ -36,18 +36,13 @@ use crate::{
webidl,
};
-const FILE_SYSTEM_HANDLE_BRAND_SLOT: &str = "__moliFileSystemHandleBrand";
const FILE_SYSTEM_HANDLE_STATE_SLOT: &str = "__moliFileSystemHandleState";
const FILE_SYSTEM_HANDLE_ID_SLOT: &str = "__moliFileSystemHandleId";
-const FILE_SYSTEM_ITERATOR_BRAND_SLOT: &str = "__moliFileSystemIteratorBrand";
const FILE_SYSTEM_ITERATOR_ID_SLOT: &str = "__moliFileSystemIteratorId";
const FILE_SYSTEM_ITERATOR_PROTOTYPE_SLOT: &str = "__moliFileSystemIteratorPrototype";
-const FILE_SYSTEM_WRITABLE_BRAND_SLOT: &str = "__moliFileSystemWritableBrand";
const FILE_SYSTEM_WRITABLE_MODE_SLOT: &str = "__moliFileSystemWritableMode";
const FILE_SYSTEM_WRITABLE_SINK_STATE_SLOT: &str = "__moliFileSystemWritableSinkState";
-const FILE_SYSTEM_WRITABLE_SINK_BRAND_SLOT: &str = "__moliFileSystemWritableSinkBrand";
const FILE_SYSTEM_FILE_SNAPSHOT_STATE_SLOT: &str = "__moliFileSystemFileSnapshotState";
-const FILE_SYSTEM_SYNC_ACCESS_BRAND_SLOT: &str = "__moliFileSystemSyncAccessBrand";
const FILE_SYSTEM_SYNC_ACCESS_STATE_SLOT: &str = "__moliFileSystemSyncAccessState";
const FILE_SYSTEM_SYNC_ACCESS_CLOSED_SLOT: &str = "__moliFileSystemSyncAccessClosed";
const MAX_SYNC_ACCESS_FILE_OFFSET: u64 = i64::MAX as u64;
@@ -708,8 +703,6 @@ fn dispatch_opfs_quota_mutation_task<'s, T, Operation, Wrap>(
#[derive(WebApiObject)]
#[webapi(interface = "FileSystemDirectoryHandle", require_prototype)]
struct FileSystemDirectoryHandleObjectDeclaration {
- #[webapi(slot, name = FILE_SYSTEM_HANDLE_BRAND_SLOT, constructor_default = true)]
- brand: bool,
#[webapi(slot = FILE_SYSTEM_HANDLE_STATE_SLOT)]
state_json: String,
#[webapi(slot = FILE_SYSTEM_HANDLE_ID_SLOT)]
@@ -719,8 +712,6 @@ struct FileSystemDirectoryHandleObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "FileSystemFileHandle", require_prototype)]
struct FileSystemFileHandleObjectDeclaration {
- #[webapi(slot, name = FILE_SYSTEM_HANDLE_BRAND_SLOT, constructor_default = true)]
- brand: bool,
#[webapi(slot = FILE_SYSTEM_HANDLE_STATE_SLOT)]
state_json: String,
#[webapi(slot = FILE_SYSTEM_HANDLE_ID_SLOT)]
@@ -794,8 +785,6 @@ struct FileSystemFileHandleSyncPrototypeDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "FileSystemWritableFileStream", require_prototype)]
struct FileSystemWritableFileStreamObjectDeclaration {
- #[webapi(slot, name = FILE_SYSTEM_WRITABLE_BRAND_SLOT, constructor_default = true)]
- brand: bool,
#[webapi(slot = FILE_SYSTEM_WRITABLE_MODE_SLOT)]
mode: String,
}
@@ -816,8 +805,6 @@ struct FileSystemWritableFileStreamPrototypeDeclaration {
#[derive(WebApiObject)]
#[webapi(prototype = "Object", interface = "FileSystemWritableSink")]
struct FileSystemWritableSinkObjectDeclaration {
- #[webapi(slot, name = FILE_SYSTEM_WRITABLE_SINK_BRAND_SLOT, constructor_default = true)]
- brand: bool,
#[webapi(slot = FILE_SYSTEM_WRITABLE_SINK_STATE_SLOT)]
state_json: String,
#[webapi(method, length = 1, callback = file_system_writable_sink_write_callback)]
@@ -831,8 +818,6 @@ struct FileSystemWritableSinkObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "FileSystemSyncAccessHandle", require_prototype)]
struct FileSystemSyncAccessHandleObjectDeclaration {
- #[webapi(slot, name = FILE_SYSTEM_SYNC_ACCESS_BRAND_SLOT, constructor_default = true)]
- brand: bool,
#[webapi(slot = FILE_SYSTEM_SYNC_ACCESS_STATE_SLOT)]
state_json: String,
#[webapi(slot, name = FILE_SYSTEM_SYNC_ACCESS_CLOSED_SLOT, constructor_default = false)]
@@ -864,8 +849,6 @@ struct FileSystemSyncAccessHandlePrototypeDeclaration {
interface = "FileSystemDirectoryHandle AsyncIterator"
)]
struct FileSystemDirectoryIteratorObjectDeclaration {
- #[webapi(slot = FILE_SYSTEM_ITERATOR_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = FILE_SYSTEM_ITERATOR_ID_SLOT)]
iterator_id: f64,
}
@@ -1240,8 +1223,7 @@ fn handle_state<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> Option<FileSystemHandleState> {
- let branded = get_private_value(scope, object, FILE_SYSTEM_HANDLE_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope));
+ let branded = moli_webapi_declare::implements_interface(scope, object, "FileSystemHandle");
if !branded {
return None;
}
@@ -2196,9 +2178,11 @@ fn file_system_directory_iterator_next_callback<'s>(
return;
};
rv.set(resolver.get_promise(scope).into());
- if !get_private_value(scope, args.this(), FILE_SYSTEM_ITERATOR_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
- {
+ if !moli_webapi_declare::implements_interface(
+ scope,
+ args.this(),
+ "FileSystemDirectoryHandle AsyncIterator",
+ ) {
reject_type_error(scope, resolver, "Illegal invocation");
return;
}
@@ -2565,9 +2549,7 @@ fn sync_access_state<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> Option<FileSystemSyncAccessHandleState> {
- if !get_private_value(scope, object, FILE_SYSTEM_SYNC_ACCESS_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
- {
+ if !moli_webapi_declare::implements_interface(scope, object, "FileSystemSyncAccessHandle") {
return None;
}
let json = get_private_value(scope, object, FILE_SYSTEM_SYNC_ACCESS_STATE_SLOT)?
@@ -3091,8 +3073,7 @@ fn writable_stream_is_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
stream: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, stream, FILE_SYSTEM_WRITABLE_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, stream, "FileSystemWritableFileStream")
}
fn file_system_writable_mode_getter_callback<'s>(
@@ -3187,9 +3168,7 @@ fn writable_sink_state<'s>(
scope: &mut v8::PinScope<'s, '_>,
sink: v8::Local<'s, v8::Object>,
) -> Option<FileSystemWritableSinkState> {
- if !get_private_value(scope, sink, FILE_SYSTEM_WRITABLE_SINK_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
- {
+ if !moli_webapi_declare::implements_interface(scope, sink, "FileSystemWritableSink") {
return None;
}
let json = get_private_value(scope, sink, FILE_SYSTEM_WRITABLE_SINK_STATE_SLOT)?
diff --git a/moli-renderer-v8/src/context_bootstrap/performance_runtime/entries.rs b/moli-renderer-v8/src/context_bootstrap/performance_runtime/entries.rs
index d6efd989a..7571791fa 100644
--- a/moli-renderer-v8/src/context_bootstrap/performance_runtime/entries.rs
+++ b/moli-renderer-v8/src/context_bootstrap/performance_runtime/entries.rs
@@ -208,7 +208,7 @@ impl PerformanceResourceTimingJsonSnapshotDeclaration {
}
#[derive(WebApiFunctionTemplate)]
-#[webapi(name = "PerformanceEntry")]
+#[webapi(name = "PerformanceEntry", receiver = "PerformanceEntry")]
struct PerformanceEntryPrototypeAccessorsDeclaration {
#[webapi(
accessor_property,
@@ -241,7 +241,7 @@ struct PerformanceEntryPrototypeAccessorsDeclaration {
}
#[derive(WebApiFunctionTemplate)]
-#[webapi(name = "PerformanceEntry", enumerable)]
+#[webapi(name = "PerformanceEntry", enumerable, receiver = "PerformanceEntry")]
struct PerformanceEntryPrototypeMethodsDeclaration {
#[webapi(
method,
@@ -265,7 +265,10 @@ struct PerformanceEntryDetailPrototypeAccessorsDeclaration {
}
#[derive(WebApiFunctionTemplate)]
-#[webapi(name = "PerformanceResourceTiming")]
+#[webapi(
+ name = "PerformanceResourceTiming",
+ receiver = "PerformanceResourceTiming"
+)]
struct PerformanceResourceTimingPrototypeAccessorsDeclaration {
#[webapi(
accessor_property,
@@ -410,7 +413,11 @@ struct PerformanceResourceTimingPrototypeAccessorsDeclaration {
}
#[derive(WebApiFunctionTemplate)]
-#[webapi(name = "PerformanceResourceTiming", enumerable)]
+#[webapi(
+ name = "PerformanceResourceTiming",
+ enumerable,
+ receiver = "PerformanceResourceTiming"
+)]
struct PerformanceResourceTimingPrototypeMethodsDeclaration {
#[webapi(
method,
diff --git a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
index 3c93c55c9..12cd4d96e 100644
--- a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
+++ b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
@@ -468,7 +468,12 @@ struct WebAssemblyNamespaceDeclaration {
#[cfg(feature = "wpt-extensions")]
#[derive(WebApiObject)]
-#[webapi(interface = "Object", prototype = "WebDriver", require_prototype)]
+#[webapi(
+ allow_empty,
+ interface = "Object",
+ prototype = "WebDriver",
+ require_prototype
+)]
struct WebDriverObjectDeclaration {}
#[cfg(feature = "wpt-extensions")]
diff --git a/moli-renderer-v8/src/context_bootstrap/speech_synthesis.rs b/moli-renderer-v8/src/context_bootstrap/speech_synthesis.rs
index 5043df195..01d3dace1 100644
--- a/moli-renderer-v8/src/context_bootstrap/speech_synthesis.rs
+++ b/moli-renderer-v8/src/context_bootstrap/speech_synthesis.rs
@@ -9,14 +9,12 @@ use crate::util::{
use anyhow::Result;
use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject, v8};
-const SPEECH_SYNTHESIS_BRAND_SLOT: &str = "__lmSpeechSynthesisBrand";
const SPEECH_SYNTHESIS_PENDING_SLOT: &str = "__lmSpeechSynthesisPending";
const SPEECH_SYNTHESIS_SPEAKING_SLOT: &str = "__lmSpeechSynthesisSpeaking";
const SPEECH_SYNTHESIS_PAUSED_SLOT: &str = "__lmSpeechSynthesisPaused";
const SPEECH_SYNTHESIS_LISTENERS_SLOT: &str = "__lmSpeechSynthesisListeners";
const SPEECH_SYNTHESIS_ONVOICESCHANGED_SLOT: &str = "__lmSpeechSynthesisOnvoiceschanged";
-const SPEECH_UTTERANCE_BRAND_SLOT: &str = "__lmSpeechSynthesisUtteranceBrand";
const SPEECH_UTTERANCE_TEXT_SLOT: &str = "__lmSpeechSynthesisUtteranceText";
const SPEECH_UTTERANCE_LANG_SLOT: &str = "__lmSpeechSynthesisUtteranceLang";
const SPEECH_UTTERANCE_VOICE_SLOT: &str = "__lmSpeechSynthesisUtteranceVoice";
@@ -32,7 +30,6 @@ const SPEECH_UTTERANCE_ONRESUME_SLOT: &str = "__lmSpeechSynthesisUtteranceOnresu
const SPEECH_UTTERANCE_ONMARK_SLOT: &str = "__lmSpeechSynthesisUtteranceOnmark";
const SPEECH_UTTERANCE_ONBOUNDARY_SLOT: &str = "__lmSpeechSynthesisUtteranceOnboundary";
-const SPEECH_VOICE_BRAND_SLOT: &str = "__lmSpeechSynthesisVoiceBrand";
const SPEECH_VOICE_URI_SLOT: &str = "__lmSpeechSynthesisVoiceUri";
const SPEECH_VOICE_NAME_SLOT: &str = "__lmSpeechSynthesisVoiceName";
const SPEECH_VOICE_LANG_SLOT: &str = "__lmSpeechSynthesisVoiceLang";
@@ -42,9 +39,6 @@ const SPEECH_VOICE_DEFAULT_SLOT: &str = "__lmSpeechSynthesisVoiceDefault";
#[derive(Default, WebApiObject)]
#[webapi(interface = "SpeechSynthesis")]
struct SpeechSynthesisObjectDeclaration {
- #[webapi(slot = SPEECH_SYNTHESIS_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = SPEECH_SYNTHESIS_PENDING_SLOT, init = false)]
pending: (),
@@ -114,9 +108,6 @@ struct SpeechSynthesisPrototypeDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "SpeechSynthesisUtterance")]
struct SpeechSynthesisUtteranceObjectDeclaration<'scope> {
- #[webapi(slot = SPEECH_UTTERANCE_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = SPEECH_UTTERANCE_TEXT_SLOT)]
text: v8::Local<'scope, v8::String>,
@@ -392,7 +383,6 @@ pub(in crate::context_bootstrap) fn speech_synthesis_utterance_constructor_callb
let lang = v8::String::empty(scope);
let utterance = args.this();
let declaration = SpeechSynthesisUtteranceObjectDeclaration {
- brand: (),
text,
lang,
voice: (),
@@ -421,7 +411,7 @@ fn speech_synthesis_state_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_SYNTHESIS_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesis") {
return;
}
let Some(slot) = callback_data_item(
@@ -443,7 +433,7 @@ fn speech_synthesis_speak_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_SYNTHESIS_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesis") {
return;
}
if args.length() == 0 {
@@ -456,7 +446,9 @@ fn speech_synthesis_speak_callback<'s>(
let utterance = args.get(0);
let branded = v8::Local::<v8::Object>::try_from(utterance)
.ok()
- .is_some_and(|object| has_brand(scope, object, SPEECH_UTTERANCE_BRAND_SLOT));
+ .is_some_and(|object| {
+ moli_webapi_declare::implements_interface(scope, object, "SpeechSynthesisUtterance")
+ });
if !branded {
throw_type_error(
scope,
@@ -477,7 +469,7 @@ fn speech_synthesis_cancel_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_SYNTHESIS_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesis") {
return;
}
rv.set_undefined();
@@ -488,7 +480,7 @@ fn speech_synthesis_pause_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_SYNTHESIS_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesis") {
return;
}
rv.set_undefined();
@@ -499,7 +491,7 @@ fn speech_synthesis_resume_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_SYNTHESIS_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesis") {
return;
}
rv.set_undefined();
@@ -510,7 +502,7 @@ fn speech_synthesis_get_voices_callback<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_SYNTHESIS_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesis") {
return;
}
rv.set(v8::Array::new(scope, 0).into());
@@ -521,7 +513,7 @@ fn speech_synthesis_onvoiceschanged_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_SYNTHESIS_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesis") {
return;
}
rv.set(
@@ -535,7 +527,7 @@ fn speech_synthesis_onvoiceschanged_setter<'s>(
args: v8::FunctionCallbackArguments<'s>,
_rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_SYNTHESIS_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesis") {
return;
}
set_event_handler(
@@ -553,7 +545,7 @@ fn speech_utterance_string_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_UTTERANCE_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesisUtterance") {
return;
}
let Some(slot) = callback_data_item(
@@ -576,7 +568,7 @@ fn speech_utterance_string_setter<'s>(
args: v8::FunctionCallbackArguments<'s>,
_rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_UTTERANCE_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesisUtterance") {
return;
}
let Some(slot) = callback_data_item(
@@ -598,7 +590,7 @@ fn speech_utterance_voice_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_UTTERANCE_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesisUtterance") {
return;
}
rv.set(
@@ -612,7 +604,7 @@ fn speech_utterance_voice_setter<'s>(
args: v8::FunctionCallbackArguments<'s>,
_rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_UTTERANCE_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesisUtterance") {
return;
}
let value = args.get(0);
@@ -627,7 +619,9 @@ fn speech_utterance_voice_setter<'s>(
}
let valid = v8::Local::<v8::Object>::try_from(value)
.ok()
- .is_some_and(|object| has_brand(scope, object, SPEECH_VOICE_BRAND_SLOT));
+ .is_some_and(|object| {
+ moli_webapi_declare::implements_interface(scope, object, "SpeechSynthesisVoice")
+ });
if !valid {
throw_type_error(
scope,
@@ -643,7 +637,7 @@ fn speech_utterance_float_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_UTTERANCE_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesisUtterance") {
return;
}
let Some(attribute) = callback_data_item(
@@ -666,7 +660,7 @@ fn speech_utterance_float_setter<'s>(
args: v8::FunctionCallbackArguments<'s>,
_rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_UTTERANCE_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesisUtterance") {
return;
}
let Some(attribute) = callback_data_item(
@@ -701,7 +695,7 @@ fn speech_utterance_event_handler_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_UTTERANCE_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesisUtterance") {
return;
}
let Some(handler) = callback_data_item(
@@ -724,7 +718,7 @@ fn speech_utterance_event_handler_setter<'s>(
args: v8::FunctionCallbackArguments<'s>,
_rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_UTTERANCE_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesisUtterance") {
return;
}
let Some(handler) = callback_data_item(
@@ -750,7 +744,7 @@ fn speech_voice_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'s, v8::Value>,
) {
- if !require_brand(scope, args.this(), SPEECH_VOICE_BRAND_SLOT) {
+ if !require_brand(scope, args.this(), "SpeechSynthesisVoice") {
return;
}
let Some(slot) = callback_data_item(
@@ -799,17 +793,9 @@ fn require_brand<'s>(
receiver: v8::Local<'s, v8::Object>,
slot: &'static str,
) -> bool {
- if has_brand(scope, receiver, slot) {
+ if moli_webapi_declare::implements_interface(scope, receiver, slot) {
return true;
}
throw_type_error(scope, "Illegal invocation");
false
}
-
-fn has_brand<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
- slot: &'static str,
-) -> bool {
- get_private_value(scope, receiver, slot).is_some_and(|value| value.is_true())
-}
diff --git a/moli-renderer-v8/src/context_bootstrap/storage_access.rs b/moli-renderer-v8/src/context_bootstrap/storage_access.rs
index 753c7e4f8..0a5bbe7be 100644
--- a/moli-renderer-v8/src/context_bootstrap/storage_access.rs
+++ b/moli-renderer-v8/src/context_bootstrap/storage_access.rs
@@ -7,7 +7,6 @@ use crate::opfs_owner_tasks::OpfsHandleAccessContext;
use crate::util::{context_host_ptr_from_global_bridge, get_private_value, v8_string};
use crate::webidl;
-const STORAGE_ACCESS_HANDLE_BRAND_SLOT: &str = "__moliStorageAccessHandleBrand";
const STORAGE_ACCESS_HANDLE_GET_DIRECTORY_SLOT: &str = "__moliStorageAccessHandleGetDirectory";
const STORAGE_ACCESS_HANDLE_STORAGE_KEY_SLOT: &str = "__moliStorageAccessHandleStorageKey";
@@ -112,12 +111,6 @@ impl StorageAccessTypes {
#[derive(WebApiObject)]
#[webapi(interface = "StorageAccessHandle", require_prototype)]
struct StorageAccessHandleObjectDeclaration {
- #[webapi(
- slot,
- name = STORAGE_ACCESS_HANDLE_BRAND_SLOT,
- constructor_default = true
- )]
- brand: bool,
#[webapi(slot = STORAGE_ACCESS_HANDLE_GET_DIRECTORY_SLOT)]
get_directory: bool,
#[webapi(slot = STORAGE_ACCESS_HANDLE_STORAGE_KEY_SLOT)]
@@ -277,9 +270,7 @@ fn storage_access_handle_get_directory_callback<'s>(
return;
};
rv.set(resolver.get_promise(scope).into());
- if !get_private_value(scope, args.this(), STORAGE_ACCESS_HANDLE_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
- {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), "StorageAccessHandle") {
reject_type_error(scope, resolver, "Illegal invocation");
return;
}
diff --git a/moli-renderer-v8/src/context_bootstrap/stream_objects/readable_reader.rs b/moli-renderer-v8/src/context_bootstrap/stream_objects/readable_reader.rs
index 8c7e3a869..66f2cfd8e 100644
--- a/moli-renderer-v8/src/context_bootstrap/stream_objects/readable_reader.rs
+++ b/moli-renderer-v8/src/context_bootstrap/stream_objects/readable_reader.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::util::{get_private_value, v8str};
+use crate::util::v8str;
use crate::webidl;
use moli_streams::readable::{
AcquireReaderPlan, ReadableKind, ReaderKind, ReaderReleaseSnapshot, ReleaseReaderPlan,
@@ -8,13 +8,10 @@ use moli_streams::readable::{
use moli_webapi_declare::WebApiObject;
const READER_LOCK_RELEASED_MESSAGE: &str = "ReadableStreamDefaultReader lock released";
-const READABLE_STREAM_READER_BRAND_SLOT: &str = "__moliReadableStreamReaderBrand";
#[derive(WebApiObject)]
#[webapi(interface = "ReadableStreamDefaultReader")]
struct ReadableStreamReaderObjectDeclaration<'scope> {
- #[webapi(slot = READABLE_STREAM_READER_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = READABLE_STREAM_READER_STREAM_SLOT)]
stream: v8::Local<'scope, v8::Object>,
}
@@ -22,8 +19,6 @@ struct ReadableStreamReaderObjectDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "ReadableStreamBYOBReader")]
struct ReadableStreamByobReaderObjectDeclaration<'scope> {
- #[webapi(slot = READABLE_STREAM_READER_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = READABLE_STREAM_READER_STREAM_SLOT)]
stream: v8::Local<'scope, v8::Object>,
}
@@ -520,6 +515,6 @@ fn readable_stream_reader_is_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
reader: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, reader, READABLE_STREAM_READER_BRAND_SLOT)
- .is_some_and(|value| value.is_true())
+ moli_webapi_declare::implements_interface(scope, reader, "ReadableStreamDefaultReader")
+ || moli_webapi_declare::implements_interface(scope, reader, "ReadableStreamBYOBReader")
}
diff --git a/moli-renderer-v8/src/context_bootstrap/stream_objects/writable_writer.rs b/moli-renderer-v8/src/context_bootstrap/stream_objects/writable_writer.rs
index 9187e781f..c8573e6eb 100644
--- a/moli-renderer-v8/src/context_bootstrap/stream_objects/writable_writer.rs
+++ b/moli-renderer-v8/src/context_bootstrap/stream_objects/writable_writer.rs
@@ -1,17 +1,14 @@
use super::*;
-use crate::util::{get_private_value, v8str};
+use crate::util::v8str;
use crate::webidl;
use moli_streams::writable::{AcquireWriterPlan, DesiredSizePlan, WriterWriteEntryPlan};
use moli_webapi_declare::WebApiObject;
const WRITER_LOCK_RELEASED_MESSAGE: &str = "WritableStreamDefaultWriter lock released";
-const WRITABLE_STREAM_WRITER_BRAND_SLOT: &str = "__moliWritableStreamWriterBrand";
#[derive(WebApiObject)]
#[webapi(interface = "WritableStreamDefaultWriter")]
struct WritableStreamWriterObjectDeclaration<'scope> {
- #[webapi(slot = WRITABLE_STREAM_WRITER_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = WRITABLE_STREAM_WRITER_STREAM_SLOT)]
stream: v8::Local<'scope, v8::Object>,
#[webapi(slot = WRITABLE_STREAM_WRITER_READY_PROMISE_SLOT, init = "undefined")]
@@ -282,6 +279,5 @@ fn writable_stream_writer_is_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
writer: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, writer, WRITABLE_STREAM_WRITER_BRAND_SLOT)
- .is_some_and(|value| value.is_true())
+ moli_webapi_declare::implements_interface(scope, writer, "WritableStreamDefaultWriter")
}
diff --git a/moli-renderer-v8/src/context_bootstrap/streams/compression.rs b/moli-renderer-v8/src/context_bootstrap/streams/compression.rs
index 6abcb994b..07bcbbf01 100644
--- a/moli-renderer-v8/src/context_bootstrap/streams/compression.rs
+++ b/moli-renderer-v8/src/context_bootstrap/streams/compression.rs
@@ -6,16 +6,12 @@ use super::super::stream_adapter::{
EnqueueChunkError, maybe_pull_stream, value_buffer_source_bytes,
};
use super::*;
-use crate::{
- util::{get_private_value, set_private_value},
- webidl,
-};
+use crate::{util::set_private_value, webidl};
use moli_v8_util::set_static_property;
mod codec;
mod state;
-const BRAND_SLOT: &str = "__moliCompressionStreamBrand";
const TRANSFORM_SLOT: &str = "__moliCompressionTransform";
#[derive(webidl::WebIdlArgs)]
@@ -79,12 +75,6 @@ pub(in crate::context_bootstrap) fn compression_stream_constructor_callback<
};
moli_webapi_declare::initialize_web_api_object(scope, args.this(), interface)
.expect("compression stream identity should initialize");
- set_private_value(
- scope,
- args.this(),
- BRAND_SLOT,
- v8::Boolean::new(scope, DECOMPRESS).into(),
- );
rv.set(args.this().into());
}
@@ -183,11 +173,12 @@ fn endpoint_getter<'s, const DECOMPRESS: bool, const READABLE: bool>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- if get_private_value(scope, args.this(), BRAND_SLOT)
- .filter(|value| value.is_boolean())
- .map(|value| value.boolean_value(scope))
- != Some(DECOMPRESS)
- {
+ let interface = if DECOMPRESS {
+ "DecompressionStream"
+ } else {
+ "CompressionStream"
+ };
+ if !moli_webapi_declare::implements_interface(scope, args.this(), interface) {
throw_type_error(scope, "Illegal invocation");
return;
}
diff --git a/moli-renderer-v8/src/context_bootstrap/style_font_template.rs b/moli-renderer-v8/src/context_bootstrap/style_font_template.rs
index 5473235c9..2cf8692b7 100644
--- a/moli-renderer-v8/src/context_bootstrap/style_font_template.rs
+++ b/moli-renderer-v8/src/context_bootstrap/style_font_template.rs
@@ -9,14 +9,13 @@ use super::{
font_face_set_values_callback, install_font_face_set_event_handler_accessors,
install_font_face_set_load_event_template_accessors,
install_font_face_set_template_accessors, install_font_face_template_accessors,
- is_font_face,
},
specs::ConstructorSpec,
};
use moli_webapi_declare::WebApiFunctionTemplate;
#[derive(WebApiFunctionTemplate)]
-#[webapi(name = "FontFace", enumerable, receiver = is_font_face)]
+#[webapi(name = "FontFace", enumerable, receiver = "FontFace")]
struct FontFaceTemplateMethodsDeclaration {
#[webapi(method, length = 0, callback = font_face_load_callback, returns_promise)]
load: (),
diff --git a/moli-renderer-v8/src/context_bootstrap/svg_runtime/callbacks.rs b/moli-renderer-v8/src/context_bootstrap/svg_runtime/callbacks.rs
index cf5eeab47..d845e4060 100644
--- a/moli-renderer-v8/src/context_bootstrap/svg_runtime/callbacks.rs
+++ b/moli-renderer-v8/src/context_bootstrap/svg_runtime/callbacks.rs
@@ -32,11 +32,10 @@ const SVG_TEXT_POSITIONING_LIST_ATTRIBUTES: &[(&str, &str, SvgListKind)] = &[
fn require_svg_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
- brand_slot: &'static str,
interface: &str,
member: &str,
) -> bool {
- if get_private_value(scope, receiver, brand_slot).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, interface) {
return true;
}
webidl::throw_type_error(
@@ -299,7 +298,6 @@ pub(super) fn svg_animated_length_getter<'s>(
if !require_svg_receiver(
scope,
args.this(),
- SVG_ANIMATED_LENGTH_BASE_VAL_SLOT,
"SVGAnimatedLength",
&format!("{name} getter"),
) {
@@ -335,7 +333,6 @@ pub(super) fn svg_animated_length_list_getter<'s>(
if !require_svg_receiver(
scope,
args.this(),
- SVG_ANIMATED_LENGTH_LIST_BASE_VAL_SLOT,
"SVGAnimatedLengthList",
&format!("{name} getter"),
) {
@@ -368,13 +365,7 @@ pub(super) fn svg_length_getter<'s>(
rv.set_undefined();
return;
};
- if !require_svg_receiver(
- scope,
- args.this(),
- SVG_LENGTH_UNIT_TYPE_SLOT,
- "SVGLength",
- &format!("{name} getter"),
- ) {
+ if !require_svg_receiver(scope, args.this(), "SVGLength", &format!("{name} getter")) {
return;
}
match name {
@@ -411,13 +402,7 @@ pub(super) fn svg_length_setter<'s>(
) else {
return;
};
- if !require_svg_receiver(
- scope,
- args.this(),
- SVG_LENGTH_UNIT_TYPE_SLOT,
- "SVGLength",
- &format!("{name} setter"),
- ) {
+ if !require_svg_receiver(scope, args.this(), "SVGLength", &format!("{name} setter")) {
return;
}
match name {
@@ -463,13 +448,7 @@ pub(super) fn svg_number_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- if !require_svg_receiver(
- scope,
- args.this(),
- SVG_NUMBER_VALUE_SLOT,
- "SVGNumber",
- "value getter",
- ) {
+ if !require_svg_receiver(scope, args.this(), "SVGNumber", "value getter") {
return;
}
let value = svg_number_slot(scope, args.this(), SVG_NUMBER_VALUE_SLOT).unwrap_or(0.0);
@@ -481,13 +460,7 @@ pub(super) fn svg_number_setter<'s>(
args: v8::FunctionCallbackArguments<'s>,
_rv: v8::ReturnValue<'_, v8::Value>,
) {
- if !require_svg_receiver(
- scope,
- args.this(),
- SVG_NUMBER_VALUE_SLOT,
- "SVGNumber",
- "value setter",
- ) {
+ if !require_svg_receiver(scope, args.this(), "SVGNumber", "value setter") {
return;
}
let value = match webidl::convert::<webidl::UnrestrictedDouble>(
@@ -527,7 +500,6 @@ pub(super) fn svg_animated_number_getter<'s>(
if !require_svg_receiver(
scope,
args.this(),
- SVG_ANIMATED_NUMBER_BASE_VAL_SLOT,
"SVGAnimatedNumber",
&format!("{name} getter"),
) {
@@ -562,7 +534,6 @@ pub(super) fn svg_animated_number_list_getter<'s>(
if !require_svg_receiver(
scope,
args.this(),
- SVG_ANIMATED_NUMBER_LIST_BASE_VAL_SLOT,
"SVGAnimatedNumberList",
&format!("{name} getter"),
) {
@@ -598,7 +569,6 @@ pub(super) fn svg_animated_enumeration_getter<'s>(
if !require_svg_receiver(
scope,
args.this(),
- SVG_ANIMATED_ENUMERATION_BASE_VAL_SLOT,
"SVGAnimatedEnumeration",
&format!("{name} getter"),
) {
@@ -633,7 +603,6 @@ pub(super) fn svg_animated_enumeration_setter<'s>(
if !require_svg_receiver(
scope,
args.this(),
- SVG_ANIMATED_ENUMERATION_BASE_VAL_SLOT,
"SVGAnimatedEnumeration",
&format!("{name} setter"),
) || name != "baseVal"
@@ -682,7 +651,6 @@ pub(super) fn svg_animated_number_setter<'s>(
if !require_svg_receiver(
scope,
args.this(),
- SVG_ANIMATED_NUMBER_BASE_VAL_SLOT,
"SVGAnimatedNumber",
&format!("{name} setter"),
) || name != "baseVal"
@@ -732,7 +700,6 @@ pub(super) fn svg_animated_transform_list_getter<'s>(
if !require_svg_receiver(
scope,
args.this(),
- SVG_ANIMATED_TRANSFORM_LIST_BASE_VAL_SLOT,
"SVGAnimatedTransformList",
&format!("{name} getter"),
) {
@@ -756,14 +723,7 @@ pub(super) fn svg_length_list_length_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'_, v8::Value>,
) {
- svg_value_list_length_getter(
- scope,
- args,
- rv,
- SvgListKind::Length,
- SVG_LENGTH_LIST_ITEMS_SLOT,
- "SVGLengthList",
- );
+ svg_value_list_length_getter(scope, args, rv, SvgListKind::Length, "SVGLengthList");
}
pub(super) fn svg_number_list_length_getter<'s>(
@@ -771,14 +731,7 @@ pub(super) fn svg_number_list_length_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
rv: v8::ReturnValue<'_, v8::Value>,
) {
- svg_value_list_length_getter(
- scope,
- args,
- rv,
- SvgListKind::Number,
- SVG_NUMBER_LIST_ITEMS_SLOT,
- "SVGNumberList",
- );
+ svg_value_list_length_getter(scope, args, rv, SvgListKind::Number, "SVGNumberList");
}
pub(super) fn svg_value_list_length_getter<'s>(
@@ -786,10 +739,9 @@ pub(super) fn svg_value_list_length_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
kind: SvgListKind,
- brand_slot: &'static str,
interface: &'static str,
) {
- if !require_svg_receiver(scope, args.this(), brand_slot, interface, "length getter") {
+ if !require_svg_receiver(scope, args.this(), interface, "length getter") {
return;
}
let length = svg_value_list_items(scope, args.this(), kind).length();
@@ -1072,13 +1024,7 @@ pub(super) fn svg_transform_list_length_getter<'s>(
args: v8::FunctionCallbackArguments<'s>,
mut rv: v8::ReturnValue<'_, v8::Value>,
) {
- if !require_svg_receiver(
- scope,
- args.this(),
- SVG_TRANSFORM_LIST_ITEMS_SLOT,
- "SVGTransformList",
- "length getter",
- ) {
+ if !require_svg_receiver(scope, args.this(), "SVGTransformList", "length getter") {
return;
}
let length = svg_transform_list_items(scope, args.this()).length();
@@ -1299,7 +1245,6 @@ pub(super) fn svg_transform_getter<'s>(
if !require_svg_receiver(
scope,
args.this(),
- SVG_TRANSFORM_TYPE_SLOT,
"SVGTransform",
&format!("{name} getter"),
) {
@@ -1465,13 +1410,7 @@ pub(super) fn svg_matrix_getter<'s>(
rv.set_undefined();
return;
};
- if !require_svg_receiver(
- scope,
- args.this(),
- SVG_MATRIX_A_SLOT,
- "SVGMatrix",
- &format!("{name} getter"),
- ) {
+ if !require_svg_receiver(scope, args.this(), "SVGMatrix", &format!("{name} getter")) {
return;
}
let slot = svg_matrix_slot(name).expect("SVGMatrix callback data must name a component");
@@ -1492,13 +1431,7 @@ pub(super) fn svg_matrix_setter<'s>(
) else {
return;
};
- if !require_svg_receiver(
- scope,
- args.this(),
- SVG_MATRIX_A_SLOT,
- "SVGMatrix",
- &format!("{name} setter"),
- ) {
+ if !require_svg_receiver(scope, args.this(), "SVGMatrix", &format!("{name} setter")) {
return;
}
let slot = svg_matrix_slot(name).expect("SVGMatrix callback data must name a component");
diff --git a/moli-renderer-v8/src/context_bootstrap/trusted_types.rs b/moli-renderer-v8/src/context_bootstrap/trusted_types.rs
index 7317e4f0a..36a3dea94 100644
--- a/moli-renderer-v8/src/context_bootstrap/trusted_types.rs
+++ b/moli-renderer-v8/src/context_bootstrap/trusted_types.rs
@@ -14,7 +14,6 @@ use policy_callbacks::{
#[cfg(test)]
pub(crate) use realm_state::trusted_types_lazy_state_materialized;
-const TRUSTED_TYPE_KIND_SLOT: &str = "__moliTrustedTypeKind";
const TRUSTED_TYPE_VALUE_SLOT: &str = "__moliTrustedTypeValue";
const TRUSTED_SCRIPT_CODE_LIKE_CONSTRUCTOR_SLOT: &str = "__moliTrustedScriptCodeLikeConstructor";
const TRUSTED_TYPE_HTML_PROTOTYPE_SLOT: &str = "__moliTrustedHTMLPrototype";
@@ -44,8 +43,6 @@ struct TrustedTypesFactoryDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "Object")]
struct TrustedTypeObjectDeclaration<'scope> {
- #[webapi(slot = TRUSTED_TYPE_KIND_SLOT)]
- kind: v8::Local<'scope, v8::String>,
#[webapi(slot = TRUSTED_TYPE_VALUE_SLOT)]
value: v8::Local<'scope, v8::String>,
}
@@ -143,14 +140,6 @@ impl TrustedTypeKind {
}
}
- fn as_slot_value(self) -> &'static str {
- match self {
- Self::Html => "html",
- Self::Script => "script",
- Self::ScriptUrl => "script-url",
- }
- }
-
fn from_callback_index(index: usize) -> Option<Self> {
match index {
0 => Some(Self::Html),
@@ -578,9 +567,7 @@ fn trusted_type_string<'s>(
kind: TrustedTypeKind,
) -> Option<String> {
let object = v8::Local::<v8::Object>::try_from(value).ok()?;
- let kind_value = get_private_value(scope, object, TRUSTED_TYPE_KIND_SLOT)?;
- let kind_string = kind_value.to_string(scope)?.to_rust_string_lossy(scope);
- if kind_string != kind.as_slot_value() {
+ if !moli_webapi_declare::implements_interface(scope, object, kind.constructor_name()) {
return None;
}
let value = get_private_value(scope, object, TRUSTED_TYPE_VALUE_SLOT)?;
@@ -672,7 +659,7 @@ fn build_trusted_type_object<'s>(
} else {
v8::Object::new(scope)
};
- TrustedTypeObjectDeclaration::new(v8str(scope, kind.as_slot_value()), value)
+ TrustedTypeObjectDeclaration::new(value)
.initialize(scope, object)
.expect("TrustedType object declaration should initialize");
moli_webapi_declare::initialize_web_api_object(scope, object, kind.constructor_name()).ok()?;
diff --git a/moli-renderer-v8/src/context_bootstrap/url_form.rs b/moli-renderer-v8/src/context_bootstrap/url_form.rs
index 7640d47fd..c9fb922a7 100644
--- a/moli-renderer-v8/src/context_bootstrap/url_form.rs
+++ b/moli-renderer-v8/src/context_bootstrap/url_form.rs
@@ -6,7 +6,6 @@ mod callbacks;
mod helpers;
mod template;
-pub(crate) use helpers::object_prototype_matches;
pub(super) use helpers::{
apply_url_update, callback_arg_url_like_string, callback_value_string, url_href_slot,
url_object_value,
diff --git a/moli-renderer-v8/src/context_bootstrap/url_form/helpers.rs b/moli-renderer-v8/src/context_bootstrap/url_form/helpers.rs
index 6a429075c..c4cef6919 100644
--- a/moli-renderer-v8/src/context_bootstrap/url_form/helpers.rs
+++ b/moli-renderer-v8/src/context_bootstrap/url_form/helpers.rs
@@ -1,18 +1,6 @@
use super::*;
use crate::util::{get_private_value, set_private_value};
-pub(crate) fn object_prototype_matches(
- scope: &mut v8::PinScope<'_, '_>,
- object: v8::Local<'_, v8::Object>,
- ctor_name: &str,
-) -> bool {
- global_constructor_prototype(scope, ctor_name).is_some_and(|prototype| {
- object
- .get_prototype(scope)
- .is_some_and(|candidate| candidate.strict_equals(prototype.into()))
- })
-}
-
pub(in crate::context_bootstrap) fn callback_value_string(
scope: &mut v8::PinScope<'_, '_>,
value: v8::Local<'_, v8::Value>,
@@ -71,7 +59,7 @@ pub(in crate::context_bootstrap) fn require_url_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> Option<v8::Local<'s, v8::Object>> {
- if get_private_value(scope, object, URL_HREF_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, object, "URL") {
return Some(object);
}
throw_type_error(scope, "Illegal invocation");
diff --git a/moli-renderer-v8/src/context_bootstrap/url_search_params_runtime/storage.rs b/moli-renderer-v8/src/context_bootstrap/url_search_params_runtime/storage.rs
index bb3bebbb3..00f4ae551 100644
--- a/moli-renderer-v8/src/context_bootstrap/url_search_params_runtime/storage.rs
+++ b/moli-renderer-v8/src/context_bootstrap/url_search_params_runtime/storage.rs
@@ -102,9 +102,7 @@ pub(super) fn url_search_params_is_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- // The internal slot is the WebIDL brand. A constructed subclass has this
- // slot even though its direct prototype is not URLSearchParams.prototype.
- url_search_params_pairs_array(scope, object).is_some()
+ moli_webapi_declare::implements_interface(scope, object, "URLSearchParams")
}
pub(crate) fn url_search_params_request_body<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/lifecycle.rs b/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/lifecycle.rs
index 76d760d9b..0e99f8dcc 100644
--- a/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/lifecycle.rs
+++ b/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/lifecycle.rs
@@ -242,7 +242,7 @@ fn require_view_transition_receiver<'s>(
receiver: v8::Local<'s, v8::Object>,
member: &str,
) -> bool {
- if get_private_value(scope, receiver, VIEW_TRANSITION_CALLBACK_STATE_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, "ViewTransition") {
return true;
}
throw_type_error(
diff --git a/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/type_set.rs b/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/type_set.rs
index 119bb36c2..6f4d10aae 100644
--- a/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/type_set.rs
+++ b/moli-renderer-v8/src/context_bootstrap/view_transition_runtime/type_set.rs
@@ -8,7 +8,6 @@ use crate::{
},
};
-const VIEW_TRANSITION_TYPE_SET_BRAND_SLOT: &str = "__lmViewTransitionTypeSetBrand";
const VIEW_TRANSITION_TYPE_SET_BACKING_SLOT: &str = "__lmViewTransitionTypeSetBacking";
pub(super) fn new_view_transition_type_set<'s>(
@@ -25,12 +24,7 @@ pub(super) fn new_view_transition_type_set<'s>(
if object.set_prototype(scope, prototype.into()) != Some(true) {
return None;
}
- set_private_value(
- scope,
- object,
- VIEW_TRANSITION_TYPE_SET_BRAND_SLOT,
- v8::Boolean::new(scope, true).into(),
- );
+ moli_webapi_declare::initialize_web_api_object(scope, object, "ViewTransitionTypeSet").ok()?;
set_private_value(
scope,
object,
@@ -45,8 +39,8 @@ fn require_view_transition_type_set_receiver<'s>(
receiver: v8::Local<'s, v8::Object>,
member: &str,
) -> Option<v8::Local<'s, v8::Set>> {
- let branded = get_private_value(scope, receiver, VIEW_TRANSITION_TYPE_SET_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope));
+ let branded =
+ moli_webapi_declare::implements_interface(scope, receiver, "ViewTransitionTypeSet");
let backing = get_private_value(scope, receiver, VIEW_TRANSITION_TYPE_SET_BACKING_SLOT)
.and_then(|value| v8::Local::<v8::Set>::try_from(value).ok());
if branded && backing.is_some() {
diff --git a/moli-renderer-v8/src/context_bootstrap/web_audio_runtime.rs b/moli-renderer-v8/src/context_bootstrap/web_audio_runtime.rs
index e70a5cbc0..3d1514c67 100644
--- a/moli-renderer-v8/src/context_bootstrap/web_audio_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/web_audio_runtime.rs
@@ -549,7 +549,7 @@ pub(in crate::context_bootstrap) fn is_audio_context_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, object, AUDIO_CONTEXT_MODULES_SLOT).is_some()
+ moli_webapi_declare::implements_interface(scope, object, "AudioContext")
}
fn audio_context_close_callback<'s>(
@@ -1310,9 +1310,7 @@ fn require_base_audio_context<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- if is_audio_context_object(scope, object)
- || get_private_value(scope, object, OFFLINE_AUDIO_LENGTH_SLOT).is_some()
- {
+ if moli_webapi_declare::implements_interface(scope, object, "BaseAudioContext") {
return true;
}
throw_type_error(scope, "Illegal invocation: expected a BaseAudioContext.");
diff --git a/moli-renderer-v8/src/context_bootstrap/webrtc.rs b/moli-renderer-v8/src/context_bootstrap/webrtc.rs
index 9300c4549..a0107ac5b 100644
--- a/moli-renderer-v8/src/context_bootstrap/webrtc.rs
+++ b/moli-renderer-v8/src/context_bootstrap/webrtc.rs
@@ -10,7 +10,6 @@ mod session_description;
pub(in crate::context_bootstrap) use ice_candidate::rtc_ice_candidate_constructor_callback;
pub(in crate::context_bootstrap) use session_description::rtc_session_description_constructor_callback;
-const RTC_PEER_CONNECTION_BRAND_SLOT: &str = "__moliRtcPeerConnectionBrand";
const RTC_PEER_CONNECTION_CONFIGURATION_SLOT: &str = "__moliRtcPeerConnectionConfiguration";
const RTC_PEER_CONNECTION_SIGNALING_STATE_SLOT: &str = "__moliRtcPeerConnectionSignalingState";
const RTC_PEER_CONNECTION_ICE_GATHERING_STATE_SLOT: &str =
@@ -26,7 +25,6 @@ const RTC_PEER_CONNECTION_PENDING_LOCAL_DESCRIPTION_SLOT: &str =
const RTC_PEER_CONNECTION_HAS_DATA_CHANNEL_SLOT: &str = "__moliRtcPeerConnectionHasDataChannel";
const RTC_PEER_CONNECTION_LISTENERS_SLOT: &str = "__moliRtcPeerConnectionListeners";
-const RTC_DATA_CHANNEL_BRAND_SLOT: &str = "__moliRtcDataChannelBrand";
const RTC_DATA_CHANNEL_LABEL_SLOT: &str = "__moliRtcDataChannelLabel";
const RTC_DATA_CHANNEL_ORDERED_SLOT: &str = "__moliRtcDataChannelOrdered";
const RTC_DATA_CHANNEL_MAX_PACKET_LIFETIME_SLOT: &str = "__moliRtcDataChannelMaxPacketLifetime";
@@ -68,8 +66,6 @@ const RTC_DATA_CHANNEL_VALUE_SLOTS: &[&str] = &[
#[derive(WebApiObject)]
#[webapi(interface = "RTCPeerConnection")]
struct RtcPeerConnectionObjectDeclaration<'scope> {
- #[webapi(slot = RTC_PEER_CONNECTION_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = RTC_PEER_CONNECTION_CONFIGURATION_SLOT)]
configuration: v8::Local<'scope, v8::Object>,
#[webapi(slot = RTC_PEER_CONNECTION_SIGNALING_STATE_SLOT)]
@@ -97,8 +93,6 @@ struct RtcPeerConnectionObjectDeclaration<'scope> {
#[derive(WebApiObject)]
#[webapi(interface = "RTCDataChannel")]
struct RtcDataChannelObjectDeclaration<'scope> {
- #[webapi(slot = RTC_DATA_CHANNEL_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = RTC_DATA_CHANNEL_LABEL_SLOT)]
label: v8::Local<'scope, v8::String>,
#[webapi(slot = RTC_DATA_CHANNEL_ORDERED_SLOT, init = true)]
@@ -251,7 +245,6 @@ pub(in crate::context_bootstrap) fn rtc_peer_connection_constructor_callback<'s>
return;
};
let declaration = RtcPeerConnectionObjectDeclaration {
- brand: (),
configuration,
signaling_state: v8str(scope, "stable"),
ice_gathering_state: v8str(scope, "new"),
@@ -590,16 +583,14 @@ fn rtc_peer_connection_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, RTC_PEER_CONNECTION_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "RTCPeerConnection")
}
fn rtc_data_channel_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, RTC_DATA_CHANNEL_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "RTCDataChannel")
}
fn build_signaling_only_offer(audio: bool, video: bool, data: bool) -> String {
diff --git a/moli-renderer-v8/src/context_bootstrap/websocket/stream.rs b/moli-renderer-v8/src/context_bootstrap/websocket/stream.rs
index 84803d1b0..07638a82a 100644
--- a/moli-renderer-v8/src/context_bootstrap/websocket/stream.rs
+++ b/moli-renderer-v8/src/context_bootstrap/websocket/stream.rs
@@ -651,7 +651,7 @@ pub(super) fn is_websocket_stream_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- websocket_value_slot(scope, object, WEBSOCKET_STREAM_URL_SLOT).is_some()
+ moli_webapi_declare::implements_interface(scope, object, "WebSocketStream")
}
fn call_websocket_stream_function_slot<'s>(
diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime.rs
index b541723af..d934ebdee 100644
--- a/moli-renderer-v8/src/context_bootstrap/window_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime.rs
@@ -29,22 +29,21 @@ pub(crate) use navigator::{
LegacyStorageQuotaCallbackTaskEffect,
};
pub(super) use navigator::{
- MEDIA_DEVICES_BRAND_SLOT, PERMISSIONS_BRAND_SLOT, build_legacy_storage_info_object,
- build_legacy_storage_quota_object, build_navigator_ua_data_object,
- global_caches_getter_callback, navigator_get_battery_callback, navigator_java_enabled_callback,
- navigator_media_devices_get_user_media_callback, navigator_permissions_query_callback,
- navigator_send_beacon_callback, navigator_storage_estimate_callback,
- navigator_storage_get_directory_callback, navigator_storage_persist_callback,
- navigator_storage_persisted_callback, navigator_ua_data_get_high_entropy_values_callback,
- navigator_ua_data_to_json_callback, navigator_vibrate_callback,
- permission_status_name_getter_callback, permission_status_state_getter_callback,
- storage_bucket_caches_getter_callback, storage_bucket_durability_callback,
- storage_bucket_estimate_callback, storage_bucket_expires_callback,
- storage_bucket_get_directory_callback, storage_bucket_indexed_db_getter_callback,
- storage_bucket_manager_delete_callback, storage_bucket_manager_keys_callback,
- storage_bucket_manager_open_callback, storage_bucket_name_getter_callback,
- storage_bucket_persist_callback, storage_bucket_persisted_callback,
- storage_bucket_set_expires_callback,
+ build_legacy_storage_info_object, build_legacy_storage_quota_object,
+ build_navigator_ua_data_object, global_caches_getter_callback, navigator_get_battery_callback,
+ navigator_java_enabled_callback, navigator_media_devices_get_user_media_callback,
+ navigator_permissions_query_callback, navigator_send_beacon_callback,
+ navigator_storage_estimate_callback, navigator_storage_get_directory_callback,
+ navigator_storage_persist_callback, navigator_storage_persisted_callback,
+ navigator_ua_data_get_high_entropy_values_callback, navigator_ua_data_to_json_callback,
+ navigator_vibrate_callback, permission_status_name_getter_callback,
+ permission_status_state_getter_callback, storage_bucket_caches_getter_callback,
+ storage_bucket_durability_callback, storage_bucket_estimate_callback,
+ storage_bucket_expires_callback, storage_bucket_get_directory_callback,
+ storage_bucket_indexed_db_getter_callback, storage_bucket_manager_delete_callback,
+ storage_bucket_manager_keys_callback, storage_bucket_manager_open_callback,
+ storage_bucket_name_getter_callback, storage_bucket_persist_callback,
+ storage_bucket_persisted_callback, storage_bucket_set_expires_callback,
};
pub(super) use obsolete::window_obsolete_noop_callback;
pub(super) use performance::performance_now_callback;
diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs
index 98a2cb572..abc5d7ba6 100644
--- a/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs
+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime/navigator.rs
@@ -3,8 +3,7 @@ use moli_browser_profile::BrowserIdentityProfile;
use moli_webapi_declare::{ObjectLiteralDeclaration, WebApiObject};
use crate::context_bootstrap::navigator_runtime::{
- STORAGE_BUCKET_MANAGER_BRAND_SLOT, STORAGE_BUCKET_MANAGER_CHILD_HANDLE_SLOT,
- STORAGE_BUCKET_MANAGER_POPUP_ID_SLOT, STORAGE_MANAGER_BRAND_SLOT,
+ STORAGE_BUCKET_MANAGER_CHILD_HANDLE_SLOT, STORAGE_BUCKET_MANAGER_POPUP_ID_SLOT,
STORAGE_MANAGER_CHILD_HANDLE_SLOT, STORAGE_MANAGER_POPUP_ID_SLOT,
current_protocol_user_gesture_activation, navigator_identity_profile,
navigator_receiver_branded, set_navigator_identity_profile,
@@ -33,19 +32,15 @@ pub(in crate::context_bootstrap) use legacy_storage_quota::{
const PERMISSION_STATUS_NAME_SLOT: &str = "__moliPermissionStatusName";
const PERMISSION_STATUS_STATE_SLOT: &str = "__moliPermissionStatusState";
-const PERMISSION_STATUS_BRAND_SLOT: &str = "__moliPermissionStatusBrand";
const VIBRATION_PATTERN_LENGTH_MAX: usize = 99;
const VIBRATION_DURATION_MS_MAX: u32 = 10_000;
-const STORAGE_BUCKET_BRAND_SLOT: &str = "__moliStorageBucketBrand";
const STORAGE_BUCKET_CACHES_OBJECT_SLOT: &str = "__moliStorageBucketCachesObject";
const STORAGE_BUCKET_ID_SLOT: &str = "__moliStorageBucketId";
const STORAGE_BUCKET_NAME_SLOT: &str = "__moliStorageBucketName";
const STORAGE_BUCKET_ORIGIN_SLOT: &str = "__moliStorageBucketOrigin";
const STORAGE_BUCKET_STORAGE_KEY_SLOT: &str = "__moliStorageBucketStorageKey";
-const STORAGE_BUCKET_CACHE_BRAND_SLOT: &str = "__moliStorageBucketCacheBrand";
const STORAGE_BUCKET_CACHE_NAME_SLOT: &str = "__moliStorageBucketCacheName";
const STORAGE_BUCKET_CACHE_ID_SLOT: &str = "__moliStorageBucketCacheId";
-const STORAGE_BUCKET_CACHE_STORAGE_BRAND_SLOT: &str = "__moliStorageBucketCacheStorageBrand";
const GLOBAL_CACHE_STORAGE_SLOT: &str = "__moliGlobalCacheStorage";
const STORAGE_BUCKET_CACHE_PUT_RESOLVER_SLOT: &str = "__moliStorageBucketCachePutResolver";
const STORAGE_BUCKET_CACHE_PUT_BUCKET_ORIGIN_SLOT: &str = "__moliStorageBucketCachePutBucketOrigin";
@@ -70,12 +65,7 @@ const STORAGE_BUCKET_CACHE_PUT_RESPONSE_STATUS_TEXT_SLOT: &str =
"__moliStorageBucketCachePutResponseStatusText";
const STORAGE_BUCKET_CACHE_PUT_RESPONSE_HEADERS_SLOT: &str =
"__moliStorageBucketCachePutResponseHeaders";
-pub(in crate::context_bootstrap) const NAVIGATOR_UA_DATA_BRAND_SLOT: &str =
- "__moliNavigatorUADataBrand";
const NAVIGATOR_UA_DATA_USER_AGENT_SLOT: &str = "__moliNavigatorUADataUserAgent";
-pub(in crate::context_bootstrap) const MEDIA_DEVICES_BRAND_SLOT: &str = "__moliMediaDevicesBrand";
-pub(in crate::context_bootstrap) const PERMISSIONS_BRAND_SLOT: &str = "__moliPermissionsBrand";
-const NAVIGATOR_BATTERY_STATUS_BRAND_SLOT: &str = "__moliBatteryStatusBrand";
#[derive(Default, WebApiObject)]
#[webapi(
@@ -84,8 +74,6 @@ const NAVIGATOR_BATTERY_STATUS_BRAND_SLOT: &str = "__moliBatteryStatusBrand";
own_to_string_tag = "CacheStorage"
)]
struct StorageBucketCacheStorageObjectDeclaration {
- #[webapi(slot = STORAGE_BUCKET_CACHE_STORAGE_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(
method,
callback = storage_bucket_cache_storage_match_callback,
@@ -121,8 +109,6 @@ struct StorageBucketCacheStorageObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(prototype = "Object", interface = "Cache", own_to_string_tag = "Cache")]
struct StorageBucketCacheObjectDeclaration {
- #[webapi(slot = STORAGE_BUCKET_CACHE_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = STORAGE_BUCKET_CACHE_NAME_SLOT)]
cache_name: String,
#[webapi(slot = STORAGE_BUCKET_CACHE_ID_SLOT)]
@@ -142,9 +128,6 @@ struct StorageBucketCacheObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "PermissionStatus")]
struct PermissionStatusObjectDeclaration {
- #[webapi(slot = PERMISSION_STATUS_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = PERMISSION_STATUS_NAME_SLOT)]
name: String,
@@ -185,9 +168,6 @@ struct NavigatorUaBrandEntryDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "NavigatorUAData")]
struct NavigatorUaDataObjectDeclaration {
- #[webapi(slot = NAVIGATOR_UA_DATA_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = NAVIGATOR_UA_DATA_USER_AGENT_SLOT)]
user_agent: String,
@@ -278,9 +258,6 @@ struct StorageUsageDetailsObjectDeclaration {
#[derive(WebApiObject)]
#[webapi(prototype = "Object", interface = "BatteryManager", data_properties)]
struct NavigatorBatteryStatusObjectDeclaration {
- #[webapi(slot = NAVIGATOR_BATTERY_STATUS_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(data_property, enumerable)]
charging: bool,
#[webapi(data_property, enumerable)]
@@ -313,11 +290,8 @@ struct NavigatorBatteryStatusObjectDeclaration {
}
#[derive(WebApiObject)]
-#[webapi(interface = "StorageBucket")]
-struct StorageBucketObjectDeclaration {
- #[webapi(slot, name = STORAGE_BUCKET_BRAND_SLOT, constructor_default = true)]
- brand: bool,
-}
+#[webapi(allow_empty, interface = "StorageBucket")]
+struct StorageBucketObjectDeclaration {}
#[derive(Debug)]
struct StorageBucketHandle {
@@ -577,8 +551,7 @@ fn battery_status_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, NAVIGATOR_BATTERY_STATUS_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "BatteryManager")
}
pub(in crate::context_bootstrap) fn navigator_permissions_query_callback<'s>(
@@ -640,8 +613,7 @@ fn permissions_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, PERMISSIONS_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "Permissions")
}
fn build_permission_status_object<'s>(
@@ -761,14 +733,7 @@ fn storage_manager_promise_resolver<'s>(
rv: &mut v8::ReturnValue<'_, v8::Value>,
method: &'static str,
) -> Option<v8::Local<'s, v8::PromiseResolver>> {
- branded_promise_resolver(
- scope,
- args,
- rv,
- "StorageManager",
- method,
- STORAGE_MANAGER_BRAND_SLOT,
- )
+ branded_promise_resolver(scope, args, rv, "StorageManager", method)
}
fn storage_manager_context_or_reject<'s>(
@@ -1111,14 +1076,7 @@ fn storage_bucket_manager_resolver<'s>(
rv: &mut v8::ReturnValue<'_, v8::Value>,
method: &'static str,
) -> Option<v8::Local<'s, v8::PromiseResolver>> {
- let resolver = branded_promise_resolver(
- scope,
- args,
- rv,
- "StorageBucketManager",
- method,
- STORAGE_BUCKET_MANAGER_BRAND_SLOT,
- )?;
+ let resolver = branded_promise_resolver(scope, args, rv, "StorageBucketManager", method)?;
if !storage_bucket_manager_owner_is_live(scope, args.this()) {
reject_illegal_invocation(scope, resolver, "StorageBucketManager", method);
return None;
@@ -2449,14 +2407,7 @@ fn storage_bucket_resolver<'s>(
rv: &mut v8::ReturnValue<'_, v8::Value>,
method: &'static str,
) -> Option<v8::Local<'s, v8::PromiseResolver>> {
- let resolver = branded_promise_resolver(
- scope,
- args,
- rv,
- "StorageBucket",
- method,
- STORAGE_BUCKET_BRAND_SLOT,
- )?;
+ let resolver = branded_promise_resolver(scope, args, rv, "StorageBucket", method)?;
if !storage_bucket_receiver_execution_context_is_live(scope, args.this()) {
reject_storage_bucket_invalid_state(scope, resolver, method);
return None;
@@ -2468,8 +2419,7 @@ fn storage_bucket_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, STORAGE_BUCKET_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "StorageBucket")
}
fn build_storage_bucket_object<'s>(
@@ -2566,14 +2516,7 @@ fn storage_bucket_cache_storage_resolver<'s>(
rv: &mut v8::ReturnValue<'_, v8::Value>,
method: &'static str,
) -> Option<v8::Local<'s, v8::PromiseResolver>> {
- let resolver = branded_promise_resolver(
- scope,
- args,
- rv,
- "CacheStorage",
- method,
- STORAGE_BUCKET_CACHE_STORAGE_BRAND_SLOT,
- )?;
+ let resolver = branded_promise_resolver(scope, args, rv, "CacheStorage", method)?;
if !storage_bucket_receiver_execution_context_is_live(scope, args.this()) {
reject_storage_bucket_invalid_state(scope, resolver, method);
return None;
@@ -2587,14 +2530,7 @@ fn storage_bucket_cache_resolver<'s>(
rv: &mut v8::ReturnValue<'_, v8::Value>,
method: &'static str,
) -> Option<v8::Local<'s, v8::PromiseResolver>> {
- let resolver = branded_promise_resolver(
- scope,
- args,
- rv,
- "Cache",
- method,
- STORAGE_BUCKET_CACHE_BRAND_SLOT,
- )?;
+ let resolver = branded_promise_resolver(scope, args, rv, "Cache", method)?;
if !storage_bucket_receiver_execution_context_is_live(scope, args.this()) {
reject_storage_bucket_invalid_state(scope, resolver, method);
return None;
@@ -2625,13 +2561,10 @@ fn branded_promise_resolver<'s>(
rv: &mut v8::ReturnValue<'_, v8::Value>,
interface: &'static str,
method: &'static str,
- brand_slot: &'static str,
) -> Option<v8::Local<'s, v8::PromiseResolver>> {
let resolver = v8::PromiseResolver::new(scope)?;
rv.set(resolver.get_promise(scope).into());
- if !get_private_value(scope, args.this(), brand_slot)
- .is_some_and(|value| value.boolean_value(scope))
- {
+ if !moli_webapi_declare::implements_interface(scope, args.this(), interface) {
reject_illegal_invocation(scope, resolver, interface, method);
return None;
}
@@ -3444,8 +3377,7 @@ fn navigator_ua_data_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, NAVIGATOR_UA_DATA_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "NavigatorUAData")
}
pub(in crate::context_bootstrap) fn build_navigator_ua_data_object<'s>(
@@ -3592,6 +3524,5 @@ fn media_devices_receiver_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, receiver, MEDIA_DEVICES_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, receiver, "MediaDevices")
}
diff --git a/moli-renderer-v8/src/native_bridge/collections.rs b/moli-renderer-v8/src/native_bridge/collections.rs
index ab20be437..ab3f90f53 100644
--- a/moli-renderer-v8/src/native_bridge/collections.rs
+++ b/moli-renderer-v8/src/native_bridge/collections.rs
@@ -24,8 +24,6 @@ use super::{
runtime_ptr_from_object, set_wrapped_handle_array,
};
-const COLLECTION_KIND_BRAND_SLOT: &str = "__lmCollectionKindBrand";
-
mod bridge_callbacks;
mod builders;
mod iteration;
@@ -66,82 +64,35 @@ pub(super) use templates::{
build_static_handle_node_list_wrapper_template,
};
-pub(crate) fn blob_parts_platform_collection_kind(
- scope: &mut v8::PinScope<'_, '_>,
- object: v8::Local<'_, v8::Object>,
+pub(crate) fn blob_parts_platform_collection_kind<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ object: v8::Local<'s, v8::Object>,
) -> Option<&'static str> {
- if let Some(kind) = static_collection_kind_from_object(scope, object) {
- return collection_kind_blob_parts_name(kind);
- }
- let (_, descriptor) = live_collection_descriptor_from_object(scope, object).ok()?;
- collection_kind_blob_parts_name(descriptor.collection_kind)
-}
-
-fn static_collection_kind_from_object(
- scope: &mut v8::PinScope<'_, '_>,
- object: v8::Local<'_, v8::Object>,
-) -> Option<CollectionKind> {
- let value = object.get_internal_field(scope, 1)?;
- let value = v8::Local::<v8::Value>::try_from(value).ok()?;
- let tag = value.number_value(scope)?;
- if !tag.is_finite() || tag.fract() != 0.0 || tag >= 0.0 {
- return None;
- }
- match tag as i32 {
- -2 => Some(CollectionKind::NodeList),
- -3 => Some(CollectionKind::HtmlCollection),
- -4 => Some(CollectionKind::FormControlsCollection),
- -5 => Some(CollectionKind::OptionsCollection),
- -6 => Some(CollectionKind::RadioNodeList),
- _ => None,
- }
+ collection_kind_from_object(scope, object).map(collection_interface_name)
}
pub(in crate::native_bridge::collections) fn collection_kind_from_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> Option<CollectionKind> {
- static_collection_kind_from_object(scope, object)
- .or_else(|| {
- live_collection_descriptor_from_object(scope, object)
- .ok()
- .map(|(_, descriptor)| descriptor.collection_kind)
- })
- .or_else(|| {
- get_private_value(scope, object, COLLECTION_KIND_BRAND_SLOT)
- .and_then(|value| value.int32_value(scope))
- .and_then(collection_kind_from_brand)
- })
+ match moli_webapi_declare::web_api_object_type(scope, object)?.name() {
+ "NodeList" => Some(CollectionKind::NodeList),
+ "HTMLCollection" => Some(CollectionKind::HtmlCollection),
+ "HTMLFormControlsCollection" => Some(CollectionKind::FormControlsCollection),
+ "HTMLOptionsCollection" => Some(CollectionKind::OptionsCollection),
+ "RadioNodeList" => Some(CollectionKind::RadioNodeList),
+ _ => None,
+ }
}
-pub(in crate::native_bridge) fn mark_collection_kind<'s>(
+pub(in crate::native_bridge) fn initialize_collection_identity<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
kind: CollectionKind,
) {
- let brand = v8::Integer::new(scope, collection_kind_brand(kind));
- set_private_value(scope, object, COLLECTION_KIND_BRAND_SLOT, brand.into());
-}
-
-fn collection_kind_brand(kind: CollectionKind) -> i32 {
- match kind {
- CollectionKind::NodeList => 1,
- CollectionKind::HtmlCollection => 2,
- CollectionKind::FormControlsCollection => 3,
- CollectionKind::OptionsCollection => 4,
- CollectionKind::RadioNodeList => 5,
- }
-}
-
-fn collection_kind_from_brand(brand: i32) -> Option<CollectionKind> {
- match brand {
- 1 => Some(CollectionKind::NodeList),
- 2 => Some(CollectionKind::HtmlCollection),
- 3 => Some(CollectionKind::FormControlsCollection),
- 4 => Some(CollectionKind::OptionsCollection),
- 5 => Some(CollectionKind::RadioNodeList),
- _ => None,
- }
+ let interface = collection_interface_name(kind);
+ moli_webapi_declare::initialize_web_api_object(scope, object, interface)
+ .expect("native collection identity should initialize");
}
pub(in crate::native_bridge::collections) fn is_node_list_kind(kind: CollectionKind) -> bool {
@@ -160,12 +111,12 @@ pub(in crate::native_bridge::collections) fn is_html_collection_kind(kind: Colle
)
}
-fn collection_kind_blob_parts_name(kind: CollectionKind) -> Option<&'static str> {
+fn collection_interface_name(kind: CollectionKind) -> &'static str {
match kind {
- CollectionKind::NodeList => Some("NodeList"),
- CollectionKind::HtmlCollection => Some("HTMLCollection"),
- CollectionKind::FormControlsCollection => Some("HTMLFormControlsCollection"),
- CollectionKind::OptionsCollection => Some("HTMLOptionsCollection"),
- CollectionKind::RadioNodeList => Some("RadioNodeList"),
+ CollectionKind::NodeList => "NodeList",
+ CollectionKind::HtmlCollection => "HTMLCollection",
+ CollectionKind::FormControlsCollection => "HTMLFormControlsCollection",
+ CollectionKind::OptionsCollection => "HTMLOptionsCollection",
+ CollectionKind::RadioNodeList => "RadioNodeList",
}
}
diff --git a/moli-renderer-v8/src/native_bridge/collections/builders.rs b/moli-renderer-v8/src/native_bridge/collections/builders.rs
index f7ec577ab..2129a475f 100644
--- a/moli-renderer-v8/src/native_bridge/collections/builders.rs
+++ b/moli-renderer-v8/src/native_bridge/collections/builders.rs
@@ -482,18 +482,13 @@ fn define_html_collection_named_properties(
}
}
-fn set_collection_prototype(
- scope: &mut v8::PinScope<'_, '_>,
- wrapper: v8::Local<'_, v8::Object>,
+fn set_collection_prototype<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ wrapper: v8::Local<'s, v8::Object>,
kind: CollectionKind,
) {
- let prototype_name = match kind {
- CollectionKind::NodeList => "NodeList",
- CollectionKind::HtmlCollection => "HTMLCollection",
- CollectionKind::FormControlsCollection => "HTMLFormControlsCollection",
- CollectionKind::OptionsCollection => "HTMLOptionsCollection",
- CollectionKind::RadioNodeList => "RadioNodeList",
- };
+ initialize_collection_identity(scope, wrapper, kind);
+ let prototype_name = collection_interface_name(kind);
set_named_constructor_prototype(scope, wrapper, prototype_name);
}
diff --git a/moli-renderer-v8/src/native_bridge/document.rs b/moli-renderer-v8/src/native_bridge/document.rs
index 1d2df0378..627369f2f 100644
--- a/moli-renderer-v8/src/native_bridge/document.rs
+++ b/moli-renderer-v8/src/native_bridge/document.rs
@@ -324,7 +324,7 @@ struct DocumentMetadataPrototypeDeclaration {
getter = document_last_modified_getter_function
)]
last_modified: (),
- #[webapi(accessor_property, getter = document_referrer_getter_function, receiver = super::receivers::document)]
+ #[webapi(accessor_property, getter = document_referrer_getter_function, receiver = "Document")]
referrer: (),
}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_objects/collections.rs b/moli-renderer-v8/src/native_bridge/document/detached_objects/collections.rs
index ca71b055b..6a593e4fc 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_objects/collections.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_objects/collections.rs
@@ -1,4 +1,6 @@
-use crate::native_bridge::collections::{STATIC_COLLECTION_LENGTH_SLOT, mark_collection_kind};
+use crate::native_bridge::collections::{
+ STATIC_COLLECTION_LENGTH_SLOT, initialize_collection_identity,
+};
use crate::native_bridge::document::DETACHED_NATIVE_NODE_LIST_HANDLES_SLOT;
use crate::native_bridge::identity::CollectionKind;
use crate::native_bridge::named_access::{
@@ -400,7 +402,7 @@ fn install_detached_collection_state<'s>(
kind: CollectionKind,
length: usize,
) {
- mark_collection_kind(scope, wrapper, kind);
+ initialize_collection_identity(scope, wrapper, kind);
set_private_value(
scope,
wrapper,
diff --git a/moli-renderer-v8/src/native_bridge/element.rs b/moli-renderer-v8/src/native_bridge/element.rs
index 5e1c92ec2..05c92ac4f 100644
--- a/moli-renderer-v8/src/native_bridge/element.rs
+++ b/moli-renderer-v8/src/native_bridge/element.rs
@@ -1002,14 +1002,14 @@ struct HtmlElementGeometryPrototypeDeclaration {
#[webapi(
accessor_property = "offsetWidth",
enumerable,
- receiver = super::receivers::html_element,
+ receiver = "HTMLElement",
getter = node_offset_width_getter_function
)]
offset_width: (),
#[webapi(
accessor_property = "offsetHeight",
enumerable,
- receiver = super::receivers::html_element,
+ receiver = "HTMLElement",
getter = node_offset_height_getter_function
)]
offset_height: (),
@@ -4040,13 +4040,13 @@ struct HtmlIFrameElementPrototypeDeclaration {
#[webapi(
accessor_property,
getter = frame_owner_content_document_getter_function,
- receiver = super::receivers::html_iframe_element
+ receiver = "HTMLIFrameElement"
)]
content_document: (),
#[webapi(
accessor_property,
getter = frame_owner_content_window_getter_function,
- receiver = super::receivers::html_iframe_element
+ receiver = "HTMLIFrameElement"
)]
content_window: (),
}
diff --git a/moli-renderer-v8/src/native_bridge/element/media/text_tracks.rs b/moli-renderer-v8/src/native_bridge/element/media/text_tracks.rs
index 04fa6b60a..b4f7e2c33 100644
--- a/moli-renderer-v8/src/native_bridge/element/media/text_tracks.rs
+++ b/moli-renderer-v8/src/native_bridge/element/media/text_tracks.rs
@@ -37,8 +37,6 @@ const TEXT_TRACK_ACTIVE_CUES_SLOT: &str = "__moliTextTrackActiveCues";
const TEXT_TRACK_INSERTION_COUNTER_SLOT: &str = "__moliTextTrackInsertionCounter";
const TEXT_TRACK_CUE_ORDER_SLOT: &str = "__moliTextTrackCueOrder";
const TEXT_TRACK_LIST_ITEMS_SLOT: &str = "__moliTextTrackListItems";
-const TEXT_TRACK_LIST_BRAND_SLOT: &str = "__moliTextTrackListBrand";
-const TEXT_TRACK_CUE_LIST_BRAND_SLOT: &str = "__moliTextTrackCueListBrand";
const TEXT_TRACK_ONCUECHANGE_SLOT: &str = "__moliTextTrackOnCueChange";
const TEXT_TRACK_LIST_ONADDTRACK_SLOT: &str = "__moliTextTrackListOnAddTrack";
const TEXT_TRACK_LIST_ONREMOVETRACK_SLOT: &str = "__moliTextTrackListOnRemoveTrack";
@@ -54,9 +52,6 @@ const TRACK_READY_STATE_ERROR: u32 = 3;
struct TextTrackCueListObjectDeclaration<'scope> {
#[webapi(slot = TEXT_TRACK_LIST_ITEMS_SLOT)]
items: Vec<v8::Local<'scope, v8::Value>>,
-
- #[webapi(slot = TEXT_TRACK_CUE_LIST_BRAND_SLOT, constructor_default = true)]
- _brand: bool,
}
#[derive(WebApiFunctionTemplate)]
@@ -86,9 +81,6 @@ struct TextTrackListObjectDeclaration<'scope> {
#[webapi(slot = TEXT_TRACK_LIST_ITEMS_SLOT)]
items: Vec<v8::Local<'scope, v8::Value>>,
- #[webapi(slot = TEXT_TRACK_LIST_BRAND_SLOT, constructor_default = true)]
- _brand: bool,
-
#[webapi(slot = TEXT_TRACK_LIST_ONADDTRACK_SLOT, init = "null")]
_onaddtrack: (),
@@ -232,7 +224,7 @@ fn text_track_receiver<'s>(
args: &v8::FunctionCallbackArguments<'s>,
) -> Option<v8::Local<'s, v8::Object>> {
let receiver = args.this();
- if get_private_value(scope, receiver, TEXT_TRACK_KIND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, "TextTrack") {
return Some(receiver);
}
throw_type_error(scope, "Illegal invocation");
@@ -244,7 +236,7 @@ fn text_track_list_receiver<'s>(
args: &v8::FunctionCallbackArguments<'s>,
) -> Option<v8::Local<'s, v8::Object>> {
let receiver = args.this();
- if get_private_value(scope, receiver, TEXT_TRACK_LIST_BRAND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, "TextTrackList") {
return Some(receiver);
}
throw_type_error(scope, "Illegal invocation");
@@ -256,7 +248,7 @@ fn text_track_cue_list_receiver<'s>(
args: &v8::FunctionCallbackArguments<'s>,
) -> Option<v8::Local<'s, v8::Object>> {
let receiver = args.this();
- if get_private_value(scope, receiver, TEXT_TRACK_CUE_LIST_BRAND_SLOT).is_some() {
+ if moli_webapi_declare::implements_interface(scope, receiver, "TextTrackCueList") {
return Some(receiver);
}
throw_type_error(scope, "Illegal invocation");
diff --git a/moli-renderer-v8/src/native_bridge/mod.rs b/moli-renderer-v8/src/native_bridge/mod.rs
index a5fa6434a..71c9a54af 100644
--- a/moli-renderer-v8/src/native_bridge/mod.rs
+++ b/moli-renderer-v8/src/native_bridge/mod.rs
@@ -21,7 +21,6 @@ pub(super) mod identity;
pub(crate) mod named_access;
mod node;
pub(crate) mod pointer_lock;
-pub(crate) mod receivers;
mod traversal;
mod window;
@@ -84,14 +83,4 @@ pub(crate) use node::{
};
pub(crate) use node::{install_character_data_template_bindings, install_node_template_bindings};
-pub(crate) fn object_is_native_event_target_wrapper_or_detached<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- object: v8::Local<'s, v8::Object>,
-) -> bool {
- if node::receiver_has_detached_state(scope, object) {
- return true;
- }
- bridge_handle_from_object(scope, object)
- .is_ok_and(|(_, handle)| matches!(handle, BridgeHandle::Node(_) | BridgeHandle::Window))
-}
pub(crate) use traversal::install_traversal_template_bindings;
diff --git a/moli-renderer-v8/src/native_bridge/receivers.rs b/moli-renderer-v8/src/native_bridge/receivers.rs
deleted file mode 100644
index a45a91075..000000000
--- a/moli-renderer-v8/src/native_bridge/receivers.rs
+++ /dev/null
@@ -1,56 +0,0 @@
-//! Native DOM brand predicates for declarative bindings. Do not consult public
-//! constructors or prototype chains: those are mutable, realm-specific JS state.
-
-use super::node::{node_is_document, node_runtime_and_handle_from_object_or_detached};
-
-pub(crate) fn document<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
-) -> bool {
- node_runtime_and_handle_from_object_or_detached(scope, receiver)
- .ok()
- .is_some_and(|(runtime, handle)| node_is_document(unsafe { &*runtime }, handle))
-}
-
-pub(crate) fn html_element<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
-) -> bool {
- node_runtime_and_handle_from_object_or_detached(scope, receiver)
- .ok()
- .is_some_and(|(runtime, handle)| {
- unsafe { &*runtime }
- .dom_host()
- .node(handle)
- .and_then(|node| node.as_element())
- .is_some_and(|element| element.namespace() == super::document::XHTML_NS)
- })
-}
-
-pub(crate) fn html_canvas_element<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
-) -> bool {
- html_element_named(scope, receiver, "canvas")
-}
-
-pub(crate) fn html_iframe_element<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
-) -> bool {
- html_element_named(scope, receiver, "iframe")
-}
-
-fn html_element_named<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
- local_name: &str,
-) -> bool {
- node_runtime_and_handle_from_object_or_detached(scope, receiver)
- .ok()
- .is_some_and(|(runtime, handle)| {
- unsafe { &*runtime }
- .dom_host()
- .is_html_element_named(handle, local_name)
- })
-}
diff --git a/moli-renderer-v8/src/network_host/beacon.rs b/moli-renderer-v8/src/network_host/beacon.rs
index dd21e6ae8..bfd93cab3 100644
--- a/moli-renderer-v8/src/network_host/beacon.rs
+++ b/moli-renderer-v8/src/network_host/beacon.rs
@@ -337,7 +337,7 @@ fn navigator_beacon_body<'s>(
}
let data = args.get(1);
if let Ok(object) = v8::Local::<v8::Object>::try_from(data)
- && crate::context_bootstrap::object_prototype_matches(scope, object, "ReadableStream")
+ && moli_webapi_declare::implements_interface(scope, object, "ReadableStream")
{
crate::util::throw_type_error(scope, "sendBeacon cannot have a ReadableStream body.");
return None;
diff --git a/moli-renderer-v8/src/network_host/body.rs b/moli-renderer-v8/src/network_host/body.rs
index 01643c0d1..0aa13f43f 100644
--- a/moli-renderer-v8/src/network_host/body.rs
+++ b/moli-renderer-v8/src/network_host/body.rs
@@ -46,7 +46,7 @@ pub(in crate::network_host) fn body_init<'s>(
let content_type = (!mime_type.is_empty()).then_some(mime_type);
return Ok(Some(PreparedBodyInit::new(bytes, content_type)));
}
- if crate::context_bootstrap::object_prototype_matches(scope, object, "ReadableStream") {
+ if moli_webapi_declare::implements_interface(scope, object, "ReadableStream") {
return Ok(Some(PreparedBodyInit::new(Vec::new(), None)));
}
}
diff --git a/moli-renderer-v8/src/network_host/body_source.rs b/moli-renderer-v8/src/network_host/body_source.rs
index a80422e93..64664e27b 100644
--- a/moli-renderer-v8/src/network_host/body_source.rs
+++ b/moli-renderer-v8/src/network_host/body_source.rs
@@ -1403,7 +1403,7 @@ fn readable_body_stream_from_value<'s>(
let Ok(stream) = v8::Local::<v8::Object>::try_from(value) else {
return None;
};
- if crate::context_bootstrap::object_prototype_matches(scope, stream, "ReadableStream") {
+ if moli_webapi_declare::implements_interface(scope, stream, "ReadableStream") {
return Some(stream);
}
None
diff --git a/moli-renderer-v8/src/network_host/event_source.rs b/moli-renderer-v8/src/network_host/event_source.rs
index ab02b9e2e..0a5065287 100644
--- a/moli-renderer-v8/src/network_host/event_source.rs
+++ b/moli-renderer-v8/src/network_host/event_source.rs
@@ -22,7 +22,6 @@ pub(crate) use bindings::{
pub(crate) use parser::{EventSourceMessage, EventSourceParser};
pub(crate) use request::event_source_constructor_callback;
-const EVENT_SOURCE_BRAND_SLOT: &str = "__lmEventSourceBrand";
const EVENT_SOURCE_URL_SLOT: &str = "__lmEventSourceUrl";
const EVENT_SOURCE_WITH_CREDENTIALS_SLOT: &str = "__lmEventSourceWithCredentials";
const EVENT_SOURCE_READY_STATE_SLOT: &str = "__lmEventSourceReadyState";
diff --git a/moli-renderer-v8/src/network_host/event_source/bindings.rs b/moli-renderer-v8/src/network_host/event_source/bindings.rs
index ced487444..19ca5d3cc 100644
--- a/moli-renderer-v8/src/network_host/event_source/bindings.rs
+++ b/moli-renderer-v8/src/network_host/event_source/bindings.rs
@@ -5,9 +5,6 @@ use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};
#[derive(WebApiObject)]
#[webapi(interface = "EventSource")]
struct EventSourceObjectDeclaration<'scope> {
- #[webapi(slot = EVENT_SOURCE_BRAND_SLOT, init = true)]
- brand: (),
-
#[webapi(slot = EVENT_SOURCE_URL_SLOT)]
url: v8::Local<'scope, v8::String>,
@@ -610,8 +607,7 @@ fn event_source_is_branded<'s>(
scope: &mut v8::PinScope<'s, '_>,
event_source: v8::Local<'s, v8::Object>,
) -> bool {
- get_private_value(scope, event_source, EVENT_SOURCE_BRAND_SLOT)
- .is_some_and(|value| value.boolean_value(scope))
+ moli_webapi_declare::implements_interface(scope, event_source, "EventSource")
}
fn event_source_string_slot<'s>(
diff --git a/moli-renderer-v8/src/network_host/fetch_surface.rs b/moli-renderer-v8/src/network_host/fetch_surface.rs
index 659697f88..04fc2e17a 100644
--- a/moli-renderer-v8/src/network_host/fetch_surface.rs
+++ b/moli-renderer-v8/src/network_host/fetch_surface.rs
@@ -31,7 +31,6 @@ pub(in crate::network_host) const REQUEST_IS_RELOAD_NAVIGATION_SLOT: &str =
"__lmRequestIsReloadNavigation";
pub(in crate::network_host) const REQUEST_BODY_SLOT: &str = "__lmRequestBody";
pub(in crate::network_host) const REQUEST_BODY_USED_SLOT: &str = "__lmRequestBodyUsed";
-const REQUEST_BRAND_SLOT: &str = "__lmRequestBrand";
pub(crate) const RESPONSE_TYPE_SLOT: &str = "__lmResponseType";
pub(crate) const RESPONSE_URL_SLOT: &str = "__lmResponseUrl";
pub(crate) const RESPONSE_INTERNAL_URL_SLOT: &str = "__lmResponseInternalUrl";
@@ -45,21 +44,6 @@ pub(crate) const RESPONSE_STATUS_TEXT_SLOT: &str = "__lmResponseStatusText";
pub(crate) const RESPONSE_HEADERS_SLOT: &str = "__lmResponseHeadersObject";
pub(crate) const RESPONSE_BODY_SLOT: &str = "__lmResponseBody";
pub(crate) const RESPONSE_BODY_USED_SLOT: &str = "__lmResponseBodyUsed";
-const RESPONSE_BRAND_SLOT: &str = "__lmResponseBrand";
-
-#[derive(Default, WebApiObject)]
-#[webapi(prototype = "Object", interface = "Request")]
-struct RequestBrandDeclaration {
- #[webapi(slot = REQUEST_BRAND_SLOT, init = true)]
- brand: (),
-}
-
-#[derive(Default, WebApiObject)]
-#[webapi(prototype = "Object", interface = "Response")]
-struct ResponseBrandDeclaration {
- #[webapi(slot = RESPONSE_BRAND_SLOT, init = true)]
- brand: (),
-}
#[derive(WebApiObject)]
#[webapi(interface = "Response", prototype = "Response")]
@@ -184,8 +168,7 @@ pub(in crate::network_host) fn mark_request_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) {
- RequestBrandDeclaration::default()
- .initialize(scope, object)
+ moli_webapi_declare::initialize_web_api_object(scope, object, "Request")
.expect("Request brand declaration should initialize");
}
@@ -193,10 +176,7 @@ pub(crate) fn is_branded_request_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- let Some(value) = get_private_value(scope, object, REQUEST_BRAND_SLOT) else {
- return false;
- };
- value.boolean_value(scope)
+ moli_webapi_declare::implements_interface(scope, object, "Request")
}
pub(crate) fn request_headers_entries<'s>(
@@ -313,8 +293,7 @@ pub(in crate::network_host) fn mark_response_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) {
- ResponseBrandDeclaration::default()
- .initialize(scope, object)
+ moli_webapi_declare::initialize_web_api_object(scope, object, "Response")
.expect("Response brand declaration should initialize");
}
@@ -322,10 +301,7 @@ pub(crate) fn is_branded_response_object<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
) -> bool {
- let Some(value) = get_private_value(scope, object, RESPONSE_BRAND_SLOT) else {
- return false;
- };
- value.boolean_value(scope)
+ moli_webapi_declare::implements_interface(scope, object, "Response")
}
fn require_response_receiver<'s>(
@@ -949,7 +925,7 @@ fn clone_response_readable_stream_body<'s>(
let Ok(stream) = v8::Local::<v8::Object>::try_from(value) else {
return Ok(None);
};
- if !crate::context_bootstrap::object_prototype_matches(scope, stream, "ReadableStream") {
+ if !moli_webapi_declare::implements_interface(scope, stream, "ReadableStream") {
return Ok(None);
}
if readable_stream_locked(scope, stream) {
diff --git a/moli-renderer-v8/src/network_host/headers/methods.rs b/moli-renderer-v8/src/network_host/headers/methods.rs
index d90de397c..1f9746eaf 100644
--- a/moli-renderer-v8/src/network_host/headers/methods.rs
+++ b/moli-renderer-v8/src/network_host/headers/methods.rs
@@ -2,7 +2,6 @@ mod access;
mod iteration;
mod mutation;
-use super::store::headers_entries_slot_present;
use super::*;
pub(super) use self::access::{
@@ -21,7 +20,7 @@ pub(super) fn require_headers_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> Option<v8::Local<'s, v8::Object>> {
- if headers_entries_slot_present(scope, receiver) {
+ if moli_webapi_declare::implements_interface(scope, receiver, "Headers") {
return Some(receiver);
}
throw_type_error(scope, "Illegal invocation");
diff --git a/moli-renderer-v8/src/network_host/headers/store.rs b/moli-renderer-v8/src/network_host/headers/store.rs
index a9e09bbb9..ab08f172f 100644
--- a/moli-renderer-v8/src/network_host/headers/store.rs
+++ b/moli-renderer-v8/src/network_host/headers/store.rs
@@ -4,7 +4,7 @@ mod projection;
pub(crate) use self::entries::{HeadersGuard, filter_headers_for_guard, headers_entries};
pub(in crate::network_host::headers) use self::entries::{
- header_allowed_by_guard, headers_are_immutable, headers_entries_slot_present, headers_guard,
+ header_allowed_by_guard, headers_are_immutable, headers_guard,
};
pub(in crate::network_host) use self::entries::{mark_headers_immutable, set_headers_entries};
pub(in crate::network_host::headers) use self::entries::{
diff --git a/moli-renderer-v8/src/network_host/headers/store/entries.rs b/moli-renderer-v8/src/network_host/headers/store/entries.rs
index cb3e966c8..4118101ed 100644
--- a/moli-renderer-v8/src/network_host/headers/store/entries.rs
+++ b/moli-renderer-v8/src/network_host/headers/store/entries.rs
@@ -213,13 +213,6 @@ pub(in crate::network_host) fn headers_entries_if_present<'s>(
.and_then(|json| serde_json::from_str::<Vec<(String, String)>>(&json).ok())
}
-pub(in crate::network_host::headers) fn headers_entries_slot_present<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- obj: v8::Local<'s, v8::Object>,
-) -> bool {
- get_private_value(scope, obj, HEADERS_ENTRIES_SLOT).is_some()
-}
-
fn private_string_value<'s>(
scope: &mut v8::PinScope<'s, '_>,
obj: v8::Local<'s, v8::Object>,
diff --git a/moli-renderer-v8/src/network_host/request/bindings/init.rs b/moli-renderer-v8/src/network_host/request/bindings/init.rs
index 0b09fb655..b4ccaf57f 100644
--- a/moli-renderer-v8/src/network_host/request/bindings/init.rs
+++ b/moli-renderer-v8/src/network_host/request/bindings/init.rs
@@ -148,7 +148,7 @@ pub(super) fn apply_request_init_overrides<'s>(
let init_body_is_readable_stream = init_body_value
.and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())
.is_some_and(|object| {
- crate::context_bootstrap::object_prototype_matches(scope, object, "ReadableStream")
+ moli_webapi_declare::implements_interface(scope, object, "ReadableStream")
});
let body_from_init = init_body_value
.map(|value| body_init(scope, value, webidl::Context::member("RequestInit", "body")))
diff --git a/moli-renderer-v8/src/network_host/request/input.rs b/moli-renderer-v8/src/network_host/request/input.rs
index f0c91ad28..78ffdba68 100644
--- a/moli-renderer-v8/src/network_host/request/input.rs
+++ b/moli-renderer-v8/src/network_host/request/input.rs
@@ -265,7 +265,7 @@ fn request_body_stream_locked<'s>(
let Ok(stream) = v8::Local::<v8::Object>::try_from(body) else {
return false;
};
- if !crate::context_bootstrap::object_prototype_matches(scope, stream, "ReadableStream") {
+ if !moli_webapi_declare::implements_interface(scope, stream, "ReadableStream") {
return false;
}
stream
diff --git a/moli-renderer-v8/src/network_host/response/bindings.rs b/moli-renderer-v8/src/network_host/response/bindings.rs
index 0ec053b54..3d3945ad9 100644
--- a/moli-renderer-v8/src/network_host/response/bindings.rs
+++ b/moli-renderer-v8/src/network_host/response/bindings.rs
@@ -121,8 +121,7 @@ fn readable_stream_body_arg<'s>(
return None;
}
let object = v8::Local::<v8::Object>::try_from(value).ok()?;
- crate::context_bootstrap::object_prototype_matches(scope, object, "ReadableStream")
- .then_some(object)
+ moli_webapi_declare::implements_interface(scope, object, "ReadableStream").then_some(object)
}
fn readable_stream_body_locked(
diff --git a/moli-renderer-v8/src/network_host/response/materialize.rs b/moli-renderer-v8/src/network_host/response/materialize.rs
index c2eb41fc0..a713340a5 100644
--- a/moli-renderer-v8/src/network_host/response/materialize.rs
+++ b/moli-renderer-v8/src/network_host/response/materialize.rs
@@ -673,7 +673,7 @@ fn response_body_locked<'s>(
let Ok(stream) = v8::Local::<v8::Object>::try_from(body) else {
return false;
};
- if !crate::context_bootstrap::object_prototype_matches(scope, stream, "ReadableStream") {
+ if !moli_webapi_declare::implements_interface(scope, stream, "ReadableStream") {
return false;
}
stream
diff --git a/moli-renderer-v8/src/observer_runtime/mod.rs b/moli-renderer-v8/src/observer_runtime/mod.rs
index f691dc6a2..caecd3d65 100644
--- a/moli-renderer-v8/src/observer_runtime/mod.rs
+++ b/moli-renderer-v8/src/observer_runtime/mod.rs
@@ -135,7 +135,11 @@ struct IntersectionObserverPrototypeAccessorsDeclaration {
}
#[derive(WebApiFunctionTemplate)]
-#[webapi(name = "IntersectionObserverEntry", enumerable, receiver = is_intersection_observer_entry)]
+#[webapi(
+ name = "IntersectionObserverEntry",
+ enumerable,
+ receiver = "IntersectionObserverEntry"
+)]
struct IntersectionObserverEntryPrototypeAccessorsDeclaration {
#[webapi(accessor_property, getter = intersection_observer_entry_attribute_getter_callback, data = callback_data_index_value(scope, 0))]
time: (),
@@ -2513,13 +2517,6 @@ fn intersection_observer_attribute_getter_callback(
);
}
-fn is_intersection_observer_entry<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- receiver: v8::Local<'s, v8::Object>,
-) -> bool {
- get_private_value(scope, receiver, "__moliIntersectionEntryTime").is_some()
-}
-
fn intersection_observer_entry_attribute_getter_callback<'s>(
scope: &mut v8::PinScope<'s, '_>,
args: v8::FunctionCallbackArguments<'s>,
diff --git a/moli-renderer-v8/src/window_host.rs b/moli-renderer-v8/src/window_host.rs
index 379931096..d0d42c13a 100644
--- a/moli-renderer-v8/src/window_host.rs
+++ b/moli-renderer-v8/src/window_host.rs
@@ -56,7 +56,6 @@ const WINDOW_SCROLL_Y_SLOT: &str = "__moliWindowScrollY";
const WINDOW_PENDING_ANIMATION_FRAME_TIMESTAMP_SLOT: &str =
"__moliWindowPendingAnimationFrameTimestamp";
const IDLE_CALLBACK_BUDGET_MS: f64 = 50.0;
-const IDLE_DEADLINE_BRAND_SLOT: &str = "__moliIdleDeadlineBrand";
const IDLE_DEADLINE_DID_TIMEOUT_SLOT: &str = "__moliIdleDeadlineDidTimeout";
const IDLE_DEADLINE_MS_SLOT: &str = "__moliIdleDeadlineMs";
const IDLE_OPPORTUNITY_DELAY_MS: u32 = 1;
@@ -82,8 +81,6 @@ struct WindowDocumentEventInitDeclaration {
#[derive(WebApiObject)]
#[webapi(interface = "IdleDeadline")]
struct IdleDeadlineDeclaration {
- #[webapi(slot = IDLE_DEADLINE_BRAND_SLOT, init = true)]
- brand: (),
#[webapi(slot = IDLE_DEADLINE_MS_SLOT)]
deadline_ms: f64,
#[webapi(slot = IDLE_DEADLINE_DID_TIMEOUT_SLOT)]
@@ -1984,9 +1981,7 @@ fn idle_deadline_receiver<'s>(
scope: &mut v8::PinScope<'s, '_>,
receiver: v8::Local<'s, v8::Object>,
) -> Option<v8::Local<'s, v8::Object>> {
- if get_private_value(scope, receiver, IDLE_DEADLINE_BRAND_SLOT)
- .is_some_and(|value| value.is_true())
- {
+ if moli_webapi_declare::implements_interface(scope, receiver, "IdleDeadline") {
return Some(receiver);
}
throw_type_error(scope, "Illegal invocation");
diff --git a/moli-webapi-declare-derive/src/attrs.rs b/moli-webapi-declare-derive/src/attrs.rs
index 747d725a7..bd7f0af70 100644
--- a/moli-webapi-declare-derive/src/attrs.rs
+++ b/moli-webapi-declare-derive/src/attrs.rs
@@ -1,9 +1,32 @@
use syn::spanned::Spanned;
use syn::{Error, Expr, ExprLit, Field, Lit, LitInt, LitStr, Path, Token};
+#[derive(Clone)]
+pub(crate) enum ReceiverAttr {
+ Predicate(Path),
+ Interface(LitStr),
+}
+
+impl syn::parse::Parse for ReceiverAttr {
+ fn parse(input: syn::parse::ParseStream<'_>) -> Result<Self, Error> {
+ if input.peek(LitStr) {
+ let name: LitStr = input.parse()?;
+ if name.value().is_empty() || name.value() == "Object" {
+ return Err(Error::new(
+ name.span(),
+ "receiver requires a Web IDL interface name",
+ ));
+ }
+ Ok(Self::Interface(name))
+ } else {
+ input.parse().map(Self::Predicate)
+ }
+ }
+}
+
#[derive(Default)]
pub(crate) struct InterfaceAttrs {
- pub(crate) receiver: Option<Path>,
+ pub(crate) receiver: Option<ReceiverAttr>,
pub(crate) name: Option<LitStr>,
pub(crate) parent: Option<LitStr>,
pub(crate) constructor: Option<ConstructorAttr>,
@@ -46,7 +69,7 @@ pub(crate) enum RenameRule {
#[derive(Default)]
pub(crate) struct ObjectAttrs {
- pub(crate) receiver: Option<Path>,
+ pub(crate) receiver: Option<ReceiverAttr>,
pub(crate) interface: Option<LitStr>,
pub(crate) parent: Option<LitStr>,
pub(crate) prototype: Option<LitStr>,
@@ -65,7 +88,7 @@ pub(crate) struct ObjectAttrs {
#[derive(Default)]
pub(crate) struct FunctionTemplateAttrs {
- pub(crate) receiver: Option<Path>,
+ pub(crate) receiver: Option<ReceiverAttr>,
pub(crate) name: Option<LitStr>,
pub(crate) constructor: Option<ConstructorAttr>,
pub(crate) constructor_length: Option<i32>,
@@ -78,7 +101,7 @@ pub(crate) struct FunctionTemplateAttrs {
#[derive(Clone, Default)]
pub(crate) struct FieldAttrs {
- pub(crate) receiver: Option<Path>,
+ pub(crate) receiver: Option<ReceiverAttr>,
pub(crate) returns_promise: bool,
pub(crate) method: bool,
pub(crate) static_method: bool,
@@ -111,7 +134,10 @@ pub(crate) struct FieldAttrs {
}
impl FieldAttrs {
- pub(crate) fn inherit_receiver(&mut self, receiver: Option<&Path>) -> Result<(), Error> {
+ pub(crate) fn inherit_receiver(
+ &mut self,
+ receiver: Option<&ReceiverAttr>,
+ ) -> Result<(), Error> {
if self.method || self.accessor_property {
self.receiver = self.receiver.take().or_else(|| receiver.cloned());
}
diff --git a/moli-webapi-declare-derive/src/expand.rs b/moli-webapi-declare-derive/src/expand.rs
index 8144222fe..d0305699d 100644
--- a/moli-webapi-declare-derive/src/expand.rs
+++ b/moli-webapi-declare-derive/src/expand.rs
@@ -1099,7 +1099,7 @@ fn expand_function_template_alias_field(
fn expand_interface_field(
field: &Field,
rename_all: RenameRule,
- receiver: Option<&syn::Path>,
+ receiver: Option<&crate::attrs::ReceiverAttr>,
) -> Option<Result<proc_macro2::TokenStream, Error>> {
let mut attrs = match parse_field_attrs(field) {
Ok(attrs) => attrs,
@@ -1770,8 +1770,16 @@ fn expand_callback(
return quote!(#callback);
}
let receiver_check = attrs.receiver.as_ref().map(|receiver| {
+ let check = match receiver {
+ crate::attrs::ReceiverAttr::Predicate(predicate) => {
+ quote!(#predicate(scope, args.this()))
+ }
+ crate::attrs::ReceiverAttr::Interface(interface) => quote!(
+ ::moli_webapi_declare::implements_interface(scope, args.this(), #interface)
+ ),
+ };
quote! {
- if !#receiver(scope, args.this()) {
+ if !#check {
::moli_webapi_declare::__private::throw_illegal_invocation(scope);
return;
}
diff --git a/moli-webapi-declare/src/lib.rs b/moli-webapi-declare/src/lib.rs
index 4e4c586b6..21f1b781a 100644
--- a/moli-webapi-declare/src/lib.rs
+++ b/moli-webapi-declare/src/lib.rs
@@ -228,10 +228,9 @@ pub use property::{
illegal_constructor_callback, webidl_constant_property_attributes,
};
pub use prototype::{
- EVENT_TARGET_INTERFACE_BRAND_SLOT, define_declared_to_string_tag,
- define_declared_to_string_tag_with_attributes, define_interface_constructor_property,
- define_interface_prototype_property, define_to_string_tag,
- define_to_string_tag_with_attributes, set_declared_prototype, set_interface_prototype,
- set_required_interface_prototype,
+ define_declared_to_string_tag, define_declared_to_string_tag_with_attributes,
+ define_interface_constructor_property, define_interface_prototype_property,
+ define_to_string_tag, define_to_string_tag_with_attributes, set_declared_prototype,
+ set_interface_prototype, set_required_interface_prototype,
};
pub use value::{WebApiTemplateValue, WebApiValue, define_array_data_property};
diff --git a/moli-webapi-declare/src/prototype.rs b/moli-webapi-declare/src/prototype.rs
index fdebc2387..f825870a8 100644
--- a/moli-webapi-declare/src/prototype.rs
+++ b/moli-webapi-declare/src/prototype.rs
@@ -1,14 +1,7 @@
-use moli_v8_util::{
- define_static_symbol_to_string_tag, get_private_value, global_constructor_prototype,
- set_private_value,
-};
+use moli_v8_util::{define_static_symbol_to_string_tag, global_constructor_prototype};
use crate::{__private, BindError, WebApiValue, v8};
-/// Native-only marker copied from `EventTarget.prototype` to Web API objects
-/// while their declared interface prototype is installed.
-pub const EVENT_TARGET_INTERFACE_BRAND_SLOT: &str = "__moliEventTargetInterfaceBrand";
-
pub fn set_interface_prototype<'s>(
scope: &mut v8::PinScope<'s, '_>,
object: v8::Local<'s, v8::Object>,
@@ -18,13 +11,9 @@ pub fn set_interface_prototype<'s>(
return true;
}
if let Some(prototype) = global_constructor_prototype(scope, interface) {
- let installed = object
+ object
.set_prototype(scope, prototype.into())
- .unwrap_or(false);
- if installed {
- copy_event_target_interface_brand(scope, object, prototype);
- }
- installed
+ .unwrap_or(false)
} else {
false
}
@@ -48,41 +37,9 @@ pub fn set_required_interface_prototype<'s>(
"failed to set `{interface}` prototype"
)));
}
- copy_event_target_interface_brand(scope, object, prototype);
Ok(())
}
-fn copy_event_target_interface_brand<'s>(
- scope: &mut v8::PinScope<'s, '_>,
- object: v8::Local<'s, v8::Object>,
- prototype: v8::Local<'s, v8::Object>,
-) {
- let mut current = Some(prototype);
- for _ in 0..64 {
- let Some(candidate) = current else {
- return;
- };
- if get_private_value(scope, candidate, EVENT_TARGET_INTERFACE_BRAND_SLOT)
- .is_some_and(|value| value.is_true())
- {
- set_private_value(
- scope,
- object,
- EVENT_TARGET_INTERFACE_BRAND_SLOT,
- v8::Boolean::new(scope, true).into(),
- );
- return;
- }
- let Some(parent) = candidate.get_prototype(scope) else {
- return;
- };
- if parent.is_null_or_undefined() {
- return;
- }
- current = v8::Local::<v8::Object>::try_from(parent).ok();
- }
-}
-
pub fn define_to_string_tag(
scope: &mut v8::PinScope<'_, '_>,
object: v8::Local<'_, v8::Object>,
@@ -119,7 +76,6 @@ where
if !installed {
return Err(BindError::new("failed to set declared prototype"));
}
- copy_event_target_interface_brand(scope, object, prototype);
Ok(())
}
diff --git a/moli-webapi-declare/tests/brand.rs b/moli-webapi-declare/tests/brand.rs
index d313c2bfc..66cc3f616 100644
--- a/moli-webapi-declare/tests/brand.rs
+++ b/moli-webapi-declare/tests/brand.rs
@@ -11,7 +11,7 @@ use moli_webapi_declare::{
struct Base {}
#[derive(WebApiObject)]
-#[webapi(interface = "TestDerived", allow_empty)]
+#[webapi(interface = "TestDerived", parent = "TestBase", allow_empty)]
struct Derived {}
#[derive(WebApiObject)]
@@ -218,3 +218,77 @@ fn only_explicitly_registered_native_proxies_share_target_identity() {
native.revoke();
assert_eq!(web_api_object_type(scope, native_object), None);
}
+
+#[derive(moli_webapi_declare::WebApiFunctionTemplate)]
+#[webapi(name = "TestBase", receiver = "TestBase")]
+struct CheckedBaseTemplate {
+ #[webapi(method, callback = convert_argument)]
+ convert: (),
+ #[webapi(method, callback = convert_argument, returns_promise)]
+ convert_async: (),
+}
+
+fn convert_argument<'s>(
+ scope: &mut v8::PinScope<'s, '_>,
+ args: v8::FunctionCallbackArguments<'s>,
+ mut rv: v8::ReturnValue<'s>,
+) {
+ if let Some(value) = args.get(0).to_string(scope) {
+ rv.set(value.into());
+ }
+}
+
+#[test]
+fn generated_interface_receivers_accept_subtypes_and_reject_forgery_before_conversion() {
+ ensure_v8();
+ let mut isolate = v8::Isolate::new(Default::default());
+ let scope = pin!(v8::HandleScope::new(&mut isolate));
+ let scope = &mut scope.init();
+ let template = CheckedBaseTemplate::build(scope);
+ let context = v8::Context::new(scope, Default::default());
+ let other = v8::Context::new(scope, Default::default());
+ let object = {
+ let scope = &mut v8::ContextScope::new(scope, other);
+ register_web_api_interfaces(scope, [("TestDerived", Some("TestBase"))]).unwrap();
+ Derived::new().bind(scope).unwrap()
+ };
+ let scope = &mut v8::ContextScope::new(scope, context);
+ let constructor = template.get_function(scope).unwrap();
+ let global = context.global(scope);
+ let constructor_key = v8::String::new(scope, "TestBase").unwrap();
+ let object_key = v8::String::new(scope, "real").unwrap();
+ global.set(scope, constructor_key.into(), constructor.into());
+ global.set(scope, object_key.into(), object.into());
+ assert!(eval(scope, r#"
+ (() => {
+ let conversions = 0;
+ const input = {toString() { conversions++; return 'converted'; }};
+ const method = TestBase.prototype.convert;
+ Object.setPrototypeOf(real, null);
+ if (method.call(real, input) !== 'converted') return false;
+ for (const fake of [{}, Object.create(TestBase.prototype), Object.create(real), new Proxy(real, {})]) {
+ try { method.call(fake, input); return false; }
+ catch (error) { if (!(error instanceof TypeError)) return false; }
+ }
+ return conversions === 1;
+ })()
+ "#).is_true());
+ let promise = eval(
+ scope,
+ "TestBase.prototype.convertAsync.call({}, {toString() { throw Error('must not convert'); }})",
+ );
+ let promise = v8::Local::<v8::Promise>::try_from(promise).unwrap();
+ assert_eq!(promise.state(), v8::PromiseState::Rejected);
+ let reason = promise.result(scope);
+ let reason = v8::Local::<v8::Object>::try_from(reason).unwrap();
+ let name = v8::String::new(scope, "name").unwrap();
+ assert_eq!(
+ reason
+ .get(scope, name.into())
+ .unwrap()
+ .to_string(scope)
+ .unwrap()
+ .to_rust_string_lossy(scope),
+ "TypeError"
+ );
+}