Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(webapi): retire unused interface object derive
ldm0c35acc033d59
diff --git a/moli-webapi-declare-derive/src/attrs.rs b/moli-webapi-declare-derive/src/attrs.rsindex bd7f0af70..8b74ea6d6 100644--- a/moli-webapi-declare-derive/src/attrs.rs+++ b/moli-webapi-declare-derive/src/attrs.rs@@ -24,16 +24,6 @@ impl syn::parse::Parse for ReceiverAttr {}}-#[derive(Default)]-pub(crate) struct InterfaceAttrs {- pub(crate) receiver: Option<ReceiverAttr>,- pub(crate) name: Option<LitStr>,- pub(crate) parent: Option<LitStr>,- pub(crate) constructor: Option<ConstructorAttr>,- pub(crate) constructor_length: Option<i32>,- pub(crate) rename_all: RenameRule,-}-#[derive(Clone)]pub(crate) enum ConstructorAttr {Illegal,@@ -189,50 +179,6 @@ impl FieldAttrs {}}-pub(crate) fn parse_interface_attrs(attrs: &[syn::Attribute]) -> Result<InterfaceAttrs, Error> {- let mut parsed = InterfaceAttrs::default();- for attr in attrs.iter().filter(|attr| attr.path().is_ident("webapi")) {- attr.parse_nested_meta(|meta| {- if meta.path.is_ident("receiver") {- parsed.receiver = Some(meta.value()?.parse()?);- return Ok(());- }- if meta.path.is_ident("name") {- parsed.name = Some(meta.value()?.parse()?);- return Ok(());- }- if meta.path.is_ident("parent") {- parsed.parent = Some(meta.value()?.parse()?);- return Ok(());- }- if meta.path.is_ident("constructor") {- let value: LitStr = meta.value()?.parse()?;- parsed.constructor = Some(match value.value().as_str() {- "illegal" => ConstructorAttr::Illegal,- _ => return Err(Error::new(value.span(), "unsupported constructor kind")),- });- return Ok(());- }- if meta.path.is_ident("constructor_callback") {- parsed.constructor = Some(ConstructorAttr::Callback(meta.value()?.parse()?));- return Ok(());- }- if meta.path.is_ident("constructor_length") {- let length: LitInt = meta.value()?.parse()?;- parsed.constructor_length = Some(length.base10_parse()?);- return Ok(());- }- if meta.path.is_ident("rename_all") {- let value: LitStr = meta.value()?.parse()?;- parsed.rename_all = parse_rename_rule(&value)?;- return Ok(());- }- Err(meta.error("unsupported #[webapi(...)] interface attribute"))- })?;- }- Ok(parsed)-}-pub(crate) fn parse_object_attrs(attrs: &[syn::Attribute]) -> Result<ObjectAttrs, Error> {let mut parsed = ObjectAttrs::default();for attr in attrs.iter().filter(|attr| attr.path().is_ident("webapi")) {diff --git a/moli-webapi-declare-derive/src/expand.rs b/moli-webapi-declare-derive/src/expand.rsindex d0305699d..81be91a16 100644--- a/moli-webapi-declare-derive/src/expand.rs+++ b/moli-webapi-declare-derive/src/expand.rs@@ -6,8 +6,7 @@ use syn::{Data, DeriveInput, Error, Field, Fields, GenericParam, Ident, Lit, Lituse crate::attrs::{ConstructorAttr, ConstructorDefaultAttr, FunctionTemplateAttrs, ObjectAttrs, RenameRule,- ValueInitAttr, parse_field_attrs, parse_function_template_attrs, parse_interface_attrs,- parse_object_attrs,+ ValueInitAttr, parse_field_attrs, parse_function_template_attrs, parse_object_attrs,};struct WebApiFieldKey {@@ -18,127 +17,6 @@ struct WebApiFieldKey {shared_template_method_name: Option<proc_macro2::TokenStream>,}-pub(crate) fn expand_webapi_interface(- input: DeriveInput,-) -> Result<proc_macro2::TokenStream, Error> {- let struct_name = input.ident;- let generics = input.generics;- let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();- let attrs = parse_interface_attrs(&input.attrs)?;- let interface_name = attrs- .name- .unwrap_or_else(|| LitStr::new(&struct_name.to_string(), struct_name.span()));- let parent = match attrs.parent {- Some(parent) => quote!(::std::option::Option::Some(#parent)),- None => quote!(::std::option::Option::None),- };- let constructor_callback = match attrs- .constructor- .clone()- .unwrap_or(ConstructorAttr::Illegal)- {- ConstructorAttr::Illegal => {- quote!(::moli_webapi_declare::illegal_constructor_callback)- }- ConstructorAttr::Callback(callback) => {- quote!(::moli_webapi_declare::web_api_constructor!(#interface_name, #callback))- }- };- let constructor_length = attrs.constructor_length.unwrap_or(0);- let fields = named_fields(&input.data)?;- let methods = fields- .iter()- .filter_map(|field| {- expand_interface_field(field, attrs.rename_all, attrs.receiver.as_ref())- })- .collect::<Result<Vec<_>, _>>()?;-- let body = quote! {- const INTERFACE_NAME: &'static str = #interface_name;- const PARENT_INTERFACE: ::std::option::Option<&'static str> = #parent;-- ::moli_webapi_declare::register_web_api_interfaces(- scope, [(INTERFACE_NAME, PARENT_INTERFACE)],- )?;-- let prototype = ::moli_webapi_declare::v8::Object::new(scope);- if let ::std::option::Option::Some(parent) = PARENT_INTERFACE {- if let ::std::option::Option::Some(parent_prototype) =- ::moli_webapi_declare::__private::global_constructor_prototype(scope, parent)- {- let _ = prototype.set_prototype(scope, parent_prototype.into());- }- }- #(#methods)*- let constructor = ::moli_webapi_declare::v8::Function::builder(#constructor_callback)- .length(#constructor_length)- .build(scope)- .ok_or_else(|| {- ::moli_webapi_declare::BindError::new(- ::std::format!("failed to build `{}` constructor", INTERFACE_NAME)- )- })?;- constructor.set_name(::moli_webapi_declare::__private::v8str(scope, INTERFACE_NAME));- ::moli_webapi_declare::define_interface_prototype_property(- scope,- constructor,- prototype,- )?;- ::moli_webapi_declare::define_interface_constructor_property(- scope,- prototype,- constructor,- )?;- ::moli_webapi_declare::define_to_string_tag(scope, prototype, INTERFACE_NAME);- global- .define_own_property(- scope,- ::moli_webapi_declare::__private::v8str(scope, INTERFACE_NAME).into(),- constructor.into(),- ::moli_webapi_declare::v8::PropertyAttribute::DONT_ENUM,- )- .unwrap_or(false)- .then_some(())- .ok_or_else(|| {- ::moli_webapi_declare::BindError::new(- ::std::format!("failed to define `{}` constructor", INTERFACE_NAME)- )- })?;- ::std::result::Result::Ok(constructor)- };-- Ok(quote! {- impl #impl_generics #struct_name #ty_generics #where_clause {- pub fn bind<'s>(- &self,- scope: &mut ::moli_webapi_declare::v8::PinScope<'s, '_>,- global: ::moli_webapi_declare::v8::Local<'s, ::moli_webapi_declare::v8::Object>,- ) -> ::std::result::Result<- ::moli_webapi_declare::v8::Local<'s, ::moli_webapi_declare::v8::Function>,- ::moli_webapi_declare::BindError,- > {- #body- }- }-- impl #impl_generics ::moli_webapi_declare::WebApiInterfaceDeclaration for #struct_name #ty_generics #where_clause {- const NAME: &'static str = #interface_name;- const PARENT: ::std::option::Option<&'static str> = #parent;-- fn bind<'s>(- &self,- scope: &mut ::moli_webapi_declare::v8::PinScope<'s, '_>,- global: ::moli_webapi_declare::v8::Local<'s, ::moli_webapi_declare::v8::Object>,- ) -> ::std::result::Result<- ::moli_webapi_declare::v8::Local<'s, ::moli_webapi_declare::v8::Function>,- ::moli_webapi_declare::BindError,- > {- self.bind(scope, global)- }- }- })-}-pub(crate) fn expand_webapi_function_template(input: DeriveInput,) -> Result<proc_macro2::TokenStream, Error> {@@ -1096,97 +974,6 @@ fn expand_function_template_alias_field(})}-fn expand_interface_field(- field: &Field,- rename_all: RenameRule,- receiver: Option<&crate::attrs::ReceiverAttr>,-) -> Option<Result<proc_macro2::TokenStream, Error>> {- let mut attrs = match parse_field_attrs(field) {- Ok(attrs) => attrs,- Err(error) => return Some(Err(error)),- };- if let Err(error) = attrs.inherit_receiver(receiver) {- return Some(Err(error));- }- if !attrs.method && !attrs.accessor_property {- if attrs.has_installation_kind() || attrs.has_installation_attribute() {- return Some(Err(Error::new(- field.span(),- "interface fields with #[webapi(...)] attributes must declare #[webapi(method)] or #[webapi(accessor_property)]",- )));- }- return None;- }- if attrs.method {- let key = match webapi_field_key(field, &attrs, rename_all) {- Ok(key) => key,- Err(error) => return Some(Err(error)),- };- let name = key.display_name;- let property_key = key.property_key;- let set_function_name = key.function_name.map(|function_name| {- quote! {- function.set_name(#function_name);- }- });- let Some(callback) = attrs.callback.as_ref() else {- return Some(Err(Error::new(- field.span(),- "method field requires #[webapi(callback = path)]",- )));- };- let length = attrs.length.unwrap_or(0);- let enumerable = attrs.enumerable;- let writable = !attrs.readonly;- let configurable = !attrs.dont_delete;- let callback = expand_callback(callback, &attrs, false);- let build_function =- expand_method_function_builder(&callback, length, attrs.data.as_ref(), &name);- let field_read = field- .ident- .as_ref()- .map(|ident| quote!(let _ = &self.#ident;));- return Some(Ok(quote! {- #field_read- let function = #build_function.ok_or_else(|| {- ::moli_webapi_declare::BindError::new(- ::std::format!("failed to build `{}.{}` function", INTERFACE_NAME, #name)- )- })?;- #set_function_name- let mut descriptor =- ::moli_webapi_declare::v8::PropertyDescriptor::new_from_value_writable(- function.into(),- #writable,- );- descriptor.set_configurable(#configurable);- descriptor.set_enumerable(#enumerable);- prototype- .define_property(- scope,- #property_key,- &descriptor,- )- .unwrap_or(false)- .then_some(())- .ok_or_else(|| {- ::moli_webapi_declare::BindError::new(- ::std::format!("failed to define `{}.{}` function", INTERFACE_NAME, #name)- )- })?;- }));- }- if attrs.accessor_property {- return Some(expand_accessor_property_field(- field,- &attrs,- rename_all,- quote!(prototype),- ));- }- None-}-fn single_lifetime_param(generics: &syn::Generics) -> Option<syn::Lifetime> {// Most object declarations carry exactly one lifetime, and that lifetime is// the V8 scope lifetime used by `v8::Local<'scope, T>` fields. In that common@@ -2316,7 +2103,7 @@ fn named_fields(data: &Data) -> Result<Vec<Field>, Error> {#[cfg(test)]mod tests {- use super::{expand_webapi_function_template, expand_webapi_interface, expand_webapi_object};+ use super::{expand_webapi_function_template, expand_webapi_object};#[test]fn callback_policies_reject_fields_that_cannot_apply_them() {@@ -2482,49 +2269,6 @@ mod tests {assert!(!tokens.contains("pub fn new"));}- #[test]- fn interface_fields_with_ignored_attributes_are_rejected() {- let input = syn::parse_quote! {- #[webapi(name = "Sample")]- struct BadInterface {- #[webapi(enumerable)]- ignored: (),- }- };- let error = match expand_webapi_interface(input) {- Ok(_) => panic!("ignored interface field attributes should be rejected"),- Err(error) => error,- };- assert_eq!(- error.to_string(),- "interface fields with #[webapi(...)] attributes must declare #[webapi(method)] or #[webapi(accessor_property)]"- );- }-- #[test]- fn interface_fields_with_unsupported_installation_kinds_are_rejected() {- for kind in ["data_property", "slot", "hidden"] {- let input = syn::parse_str(&format!(- r#"- #[webapi(name = "Sample")]- struct BadInterface {{- #[webapi({kind})]- ignored: (),- }}- "#- ))- .expect("parse interface");- let error = match expand_webapi_interface(input) {- Ok(_) => panic!("unsupported interface field kind should be rejected"),- Err(error) => error,- };- assert_eq!(- error.to_string(),- "interface fields with #[webapi(...)] attributes must declare #[webapi(method)] or #[webapi(accessor_property)]"- );- }- }-#[test]fn function_template_fields_with_unsupported_installation_kinds_are_rejected() {for kind in [diff --git a/moli-webapi-declare-derive/src/lib.rs b/moli-webapi-declare-derive/src/lib.rsindex ccffbb70d..fccb31505 100644--- a/moli-webapi-declare-derive/src/lib.rs+++ b/moli-webapi-declare-derive/src/lib.rs@@ -4,21 +4,6 @@ mod expand;use proc_macro::TokenStream;use syn::{DeriveInput, parse_macro_input};-/// Derives a Web API interface constructor/prototype binder.-///-/// The generated implementation creates a prototype object, links the declared-/// parent prototype when present, installs declared prototype methods, creates-/// the constructor function, and publishes the constructor on the supplied-/// global object. The derive is intended for renderer bootstrap code and future-/// WebIDL codegen, not for parsing or converting WebIDL argument lists.-#[proc_macro_derive(WebApiInterface, attributes(webapi))]-pub fn derive_webapi_interface(input: TokenStream) -> TokenStream {- match expand::expand_webapi_interface(parse_macro_input!(input as DeriveInput)) {- Ok(tokens) => tokens.into(),- Err(error) => error.to_compile_error().into(),- }-}-/// Derives a Web API function-template declaration binder.////// The generated implementation creates a V8 `FunctionTemplate`, sets its classdiff --git a/moli-webapi-declare/src/declaration.rs b/moli-webapi-declare/src/declaration.rsindex 40821106a..918ee96d5 100644--- a/moli-webapi-declare/src/declaration.rs+++ b/moli-webapi-declare/src/declaration.rs@@ -2,23 +2,6 @@ use crate::{__private, BindError, WebApiObject, define_to_string_tag, set_interface_prototype, v8,};-/// Binds a Web API constructor/prototype pair onto a V8 global object.-///-/// Implementations are generated by `#[derive(WebApiInterface)]`. The generated-/// binding creates the prototype object, links the optional parent prototype,-/// installs declared prototype methods, creates the constructor function, and-/// publishes it on the provided global object.-pub trait WebApiInterfaceDeclaration {- const NAME: &'static str;- const PARENT: Option<&'static str>;-- fn bind<'s>(- &self,- scope: &mut v8::PinScope<'s, '_>,- global: v8::Local<'s, v8::Object>,- ) -> Result<v8::Local<'s, v8::Function>, BindError>;-}-/// Binds a constructor-backed Web API V8 function template.////// Implementations are generated by `#[derive(WebApiFunctionTemplate)]`. Thediff --git a/moli-webapi-declare/src/lib.rs b/moli-webapi-declare/src/lib.rsindex 0320c062d..00e1d4862 100644--- a/moli-webapi-declare/src/lib.rs+++ b/moli-webapi-declare/src/lib.rs@@ -102,8 +102,7 @@//! make them pass structured clone.//!//! Register inheritance with `register_web_api_interfaces` using the same-//! interface metadata that drives constructor installation. `WebApiInterface`-//! registers its own name and parent automatically. Identity is independent of+//! interface metadata that drives constructor installation. Identity is independent of//! realm exposure and mutable JavaScript prototypes. Use `web_api_object_type`//! for the primary interface and `implements_interface` for inherited receiver//! checks. Native factories can call `initialize_web_api_object` directly.@@ -117,7 +116,7 @@//! Factories using that registry should not repeat `parent`: deleting a public//! constructor or taking a fallback path does not remove registered inheritance.//!-//! `WebApiInterface` and `WebApiFunctionTemplate` adapt native constructor+//! `WebApiFunctionTemplate` adapts native constructor//! callbacks automatically. Hand-written templates can use//! `web_api_constructor!("Interface", callback)` when construction does not//! already go through a named object declaration. Only successful construction@@ -166,7 +165,7 @@//! change. Forged prototypes, public properties, and author Proxies cannot pass.//!//! Struct-level `receiver` supplies the default for instance methods and-//! accessor properties in all three derives; a field can override it. Static+//! accessor properties in both derives; a field can override it. Static//! methods, data properties, and holder-based native data properties do not//! inherit this policy. Already-built `getter_value` functions cannot use it.//!@@ -235,7 +234,7 @@ mod value;pub mod __private;-pub use moli_webapi_declare_derive::{WebApiFunctionTemplate, WebApiInterface, WebApiObject};+pub use moli_webapi_declare_derive::{WebApiFunctionTemplate, WebApiObject};pub use v8;/// Adapts a manual native constructor to the same identity initialization used@@ -262,7 +261,7 @@ pub use brand::{pub use declaration::{DataPropertyDescriptorDeclaration, ObjectLiteralDeclaration, WebApiFunctionTemplateDeclaration,- WebApiInterfaceDeclaration, WebApiObjectDeclaration,+ WebApiObjectDeclaration,};pub use error::BindError;pub use property::{@@ -277,7 +276,6 @@ pub use property::{};pub use 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,};diff --git a/moli-webapi-declare/src/prototype.rs b/moli-webapi-declare/src/prototype.rsindex f825870a8..c1ac56c28 100644--- a/moli-webapi-declare/src/prototype.rs+++ b/moli-webapi-declare/src/prototype.rs@@ -1,6 +1,6 @@use moli_v8_util::{define_static_symbol_to_string_tag, global_constructor_prototype};-use crate::{__private, BindError, WebApiValue, v8};+use crate::{BindError, WebApiValue, v8};pub fn set_interface_prototype<'s>(scope: &mut v8::PinScope<'s, '_>,@@ -121,41 +121,3 @@ where.then_some(()).ok_or_else(|| BindError::new("failed to define declared toStringTag"))}--pub fn define_interface_prototype_property(- scope: &mut v8::PinScope<'_, '_>,- constructor: v8::Local<'_, v8::Function>,- prototype: v8::Local<'_, v8::Object>,-) -> Result<(), BindError> {- let mut descriptor = v8::PropertyDescriptor::new_from_value_writable(prototype.into(), false);- descriptor.set_configurable(false);- descriptor.set_enumerable(false);- constructor- .define_property(- scope,- __private::v8str(scope, "prototype").into(),- &descriptor,- )- .unwrap_or(false)- .then_some(())- .ok_or_else(|| BindError::new("failed to define interface prototype property"))-}--pub fn define_interface_constructor_property(- scope: &mut v8::PinScope<'_, '_>,- prototype: v8::Local<'_, v8::Object>,- constructor: v8::Local<'_, v8::Function>,-) -> Result<(), BindError> {- let mut descriptor = v8::PropertyDescriptor::new_from_value_writable(constructor.into(), true);- descriptor.set_configurable(true);- descriptor.set_enumerable(false);- prototype- .define_property(- scope,- __private::v8str(scope, "constructor").into(),- &descriptor,- )- .unwrap_or(false)- .then_some(())- .ok_or_else(|| BindError::new("failed to define interface constructor property"))-}diff --git a/moli-webapi-declare/tests/declare.rs b/moli-webapi-declare/tests/declare.rsindex 53b3d7707..f34c7a772 100644--- a/moli-webapi-declare/tests/declare.rs+++ b/moli-webapi-declare/tests/declare.rs@@ -2,10 +2,28 @@ use std::pin::pin;use moli_v8_test_util::ensure_v8;use moli_webapi_declare::{- ObjectLiteralDeclaration, WebApiFunctionTemplate, WebApiInterface, WebApiObject, WebApiValue,- define_array_data_property,+ ObjectLiteralDeclaration, WebApiFunctionTemplate, WebApiFunctionTemplateDeclaration,+ WebApiObject, WebApiValue, define_array_data_property,};+fn install_template<'s, D: WebApiFunctionTemplateDeclaration>(+ scope: &mut v8::PinScope<'s, '_>,+ global: v8::Local<'s, v8::Object>,+) -> v8::Local<'s, v8::Function> {+ let constructor = D::build(scope)+ .get_function(scope)+ .expect("build constructor");+ global+ .define_own_property(+ scope,+ v8::String::new(scope, D::NAME).unwrap().into(),+ constructor.into(),+ v8::PropertyAttribute::DONT_ENUM,+ )+ .expect("publish constructor");+ constructor+}+fn run_script<'s>(scope: &mut v8::PinScope<'s, '_>, source: &str) -> v8::Local<'s, v8::Value> {let source = v8::String::new(scope, source).expect("test source should allocate");v8::Script::compile(scope, source, None)@@ -129,8 +147,13 @@ const SAMPLE_HIDDEN_SLOT: &str = "__lmSampleHidden";const SAMPLE_LOCKED_HIDDEN_SLOT: &str = "__lmSampleLockedHidden";const SAMPLE_LOCAL_OBJECT_SLOT: &str = "__lmSampleLocalObject";-#[derive(WebApiInterface)]-#[webapi(name = "SamplePerformance", constructor = "illegal")]+#[derive(WebApiFunctionTemplate)]+#[webapi(+ name = "SamplePerformance",+ constructor = "illegal",+ readonly_prototype,+ prototype_to_string_tag = "SamplePerformance"+)]struct SamplePerformanceInterface {#[webapi(method, length = 0, callback = sample_now_callback)]now: (),@@ -141,7 +164,7 @@ struct SamplePerformanceInterface {current_time: (),}-#[derive(WebApiInterface)]+#[derive(WebApiFunctionTemplate)]#[webapi(name = "ConstructibleSample",constructor_callback = sample_constructor_callback,@@ -149,7 +172,7 @@ struct SamplePerformanceInterface {)]struct ConstructibleSampleInterface {}-#[derive(WebApiInterface)]+#[derive(WebApiFunctionTemplate)]#[webapi(name = "InterfaceDescriptorSample", constructor = "illegal")]struct InterfaceDescriptorSample {#[webapi(method, enumerable, readonly, dont_delete, callback = sample_now_callback)]@@ -568,7 +591,7 @@ struct PrototypeBackedFallbackTagObject {}struct MissingPrototypeFallbackTagObject {}#[test]-fn declared_interface_and_object_have_expected_surface() {+fn declared_template_and_object_have_expected_surface() {ensure_v8();let mut isolate = v8::Isolate::new(v8::CreateParams::default());let scope = pin!(v8::HandleScope::new(&mut isolate));@@ -577,12 +600,7 @@ fn declared_interface_and_object_have_expected_surface() {let scope = &mut v8::ContextScope::new(scope, context);let global = context.global(scope);- let interface = SamplePerformanceInterface {- now: (),- sample_now: (),- current_time: (),- };- interface.bind(scope, global).expect("bind interface");+ install_template::<SamplePerformanceInterface>(scope, global);let declaration = SamplePerformanceObject {time_origin: 12.0,public_time_origin: 12.0,@@ -1704,9 +1722,7 @@ fn declared_constructor_callback_uses_configured_length() {let scope = &mut v8::ContextScope::new(scope, context);let global = context.global(scope);- let constructor = ConstructibleSampleInterface {}- .bind(scope, global)- .expect("bind interface");+ let constructor = install_template::<ConstructibleSampleInterface>(scope, global);let length = constructor.get(scope, v8::String::new(scope, "length").unwrap().into()).and_then(|value| value.number_value(scope));@@ -1739,7 +1755,7 @@ fn declared_native_data_property_uses_native_holder() {}#[test]-fn declared_interface_method_descriptor_attributes_are_applied() {+fn declared_template_method_descriptor_attributes_are_applied() {ensure_v8();let mut isolate = v8::Isolate::new(v8::CreateParams::default());let scope = pin!(v8::HandleScope::new(&mut isolate));@@ -1748,9 +1764,7 @@ fn declared_interface_method_descriptor_attributes_are_applied() {let scope = &mut v8::ContextScope::new(scope, context);let global = context.global(scope);- let constructor = InterfaceDescriptorSample { locked_visible: () }- .bind(scope, global)- .expect("bind descriptor sample");+ let constructor = install_template::<InterfaceDescriptorSample>(scope, global);let prototype = constructor.get(scope, v8::String::new(scope, "prototype").unwrap().into()).and_then(|value| v8::Local::<v8::Object>::try_from(value).ok())@@ -2159,13 +2173,7 @@ fn declared_enumerable_properties_bypass_prototype_assignment_semantics() {let scope = &mut v8::ContextScope::new(scope, context);let global = context.global(scope);- SamplePerformanceInterface {- now: (),- sample_now: (),- current_time: (),- }- .bind(scope, global)- .expect("bind SamplePerformance");+ install_template::<SamplePerformanceInterface>(scope, global);let constructor = global.get(scope,diff --git a/moli-webapi-declare/tests/receivers.rs b/moli-webapi-declare/tests/receivers.rsindex c17b59941..8c01fd8d4 100644--- a/moli-webapi-declare/tests/receivers.rs+++ b/moli-webapi-declare/tests/receivers.rs@@ -2,7 +2,7 @@ use std::pin::pin;use moli_v8_test_util::ensure_v8;use moli_v8_util::{get_private_value, set_private_value, v8str};-use moli_webapi_declare::{WebApiFunctionTemplate, WebApiInterface, WebApiObject};+use moli_webapi_declare::{WebApiFunctionTemplate, WebApiObject};const BRAND: &str = "__receiverTestBrand";const OTHER_BRAND: &str = "__receiverTestOtherBrand";@@ -76,7 +76,7 @@ struct NativeSample {static_promise: (),}-#[derive(WebApiInterface)]+#[derive(WebApiFunctionTemplate)]#[webapi(name = "PlainInterface", receiver = has_brand)]struct PlainInterface {#[webapi(method, callback = callback, data = 7)]@@ -242,7 +242,7 @@ fn promise_members_reject_all_synchronous_errors_and_preserve_success_identity()}#[test]-fn object_and_interface_declarations_use_the_same_receiver_policy() {+fn object_and_template_declarations_use_the_same_receiver_policy() {ensure_v8();let mut isolate = v8::Isolate::new(Default::default());let scope = pin!(v8::HandleScope::new(&mut isolate));@@ -250,13 +250,15 @@ fn object_and_interface_declarations_use_the_same_receiver_policy() {let context = v8::Context::new(scope, Default::default());let scope = &mut v8::ContextScope::new(scope, context);let global = context.global(scope);- PlainInterface {- method: (),- value: (),- ready: (),- }- .bind(scope, global)- .unwrap();+ let constructor = PlainInterface::build(scope).get_function(scope).unwrap();+ global+ .define_own_property(+ scope,+ v8str(scope, "PlainInterface").into(),+ constructor.into(),+ v8::PropertyAttribute::DONT_ENUM,+ )+ .unwrap();let object = PlainObject::new(true).bind(scope).unwrap();global.set(scope, v8str(scope, "object").into(), object.into())