mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 12:31:22 +00:00
Support [NoInterfaceObject] in web-sys
This commit enables `[NoInterfaceObject]` annotated interfaces in `web-sys`. The `NoInterfaceObject` attribute means that there's not actually a JS class for the object, but all of its properties and such can still be accessed structually and invoked. This should help provide more bindings for some more common types on the web! Note that this builds on recent features to ensure that `dyn_into` and friends always fail for `NoInterfaceObject` objects because they don't actually have a class. Closes #893 Closes #1257 Closes #1315
This commit is contained in:
@ -45,6 +45,7 @@ pub(crate) struct FirstPassRecord<'src> {
|
||||
pub(crate) struct InterfaceData<'src> {
|
||||
/// Whether only partial interfaces were encountered
|
||||
pub(crate) partial: bool,
|
||||
pub(crate) has_interface: bool,
|
||||
pub(crate) deprecated: Option<String>,
|
||||
pub(crate) attributes: Vec<&'src AttributeInterfaceMember<'src>>,
|
||||
pub(crate) consts: Vec<&'src ConstMember<'src>>,
|
||||
@ -303,22 +304,14 @@ impl<'src> FirstPass<'src, ()> for weedle::InterfaceDefinition<'src> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if util::is_no_interface_object(&self.attributes) {
|
||||
log::info!(
|
||||
"Skipping because of `NoInterfaceObject` attribute: {:?}",
|
||||
self.identifier.0
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
{
|
||||
let interface_data = record.interfaces.entry(self.identifier.0).or_default();
|
||||
interface_data.partial = false;
|
||||
interface_data.superclass = self.inheritance.map(|s| s.identifier.0);
|
||||
interface_data.definition_attributes = self.attributes.as_ref();
|
||||
interface_data.deprecated =
|
||||
util::get_rust_deprecated(&self.attributes).map(|s| s.to_string());
|
||||
}
|
||||
let interface_data = record.interfaces.entry(self.identifier.0).or_default();
|
||||
interface_data.partial = false;
|
||||
interface_data.superclass = self.inheritance.map(|s| s.identifier.0);
|
||||
interface_data.definition_attributes = self.attributes.as_ref();
|
||||
interface_data.deprecated =
|
||||
util::get_rust_deprecated(&self.attributes).map(|s| s.to_string());
|
||||
interface_data.has_interface =
|
||||
!util::is_no_interface_object(&self.attributes);
|
||||
if let Some(attrs) = &self.attributes {
|
||||
for attr in attrs.body.list.iter() {
|
||||
process_interface_attribute(record, self.identifier.0, attr);
|
||||
|
@ -514,7 +514,11 @@ impl<'src> FirstPassRecord<'src> {
|
||||
attrs,
|
||||
doc_comment: None,
|
||||
instanceof_shim: format!("__widl_instanceof_{}", name),
|
||||
is_type_of: None,
|
||||
is_type_of: if data.has_interface {
|
||||
None
|
||||
} else {
|
||||
Some(syn::parse_quote!{ |_| false })
|
||||
},
|
||||
extends: Vec::new(),
|
||||
vendor_prefixes: Vec::new(),
|
||||
};
|
||||
|
Reference in New Issue
Block a user