mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-28 20:43:23 +03:00
Remove support for scoped static methods
This is intended to address #834 where we don't actually want methods scoped like this! Instead we'll provide one unique accessor for the `window` object itself.
This commit is contained in:
parent
a7cda70253
commit
c67582a315
@ -98,10 +98,6 @@ pub enum ImportFunctionKind {
|
||||
ty: syn::Type,
|
||||
kind: MethodKind,
|
||||
},
|
||||
ScopedMethod {
|
||||
ty: syn::Type,
|
||||
operation: Operation,
|
||||
},
|
||||
Normal,
|
||||
}
|
||||
|
||||
@ -432,16 +428,10 @@ impl ImportFunction {
|
||||
}
|
||||
};
|
||||
Some(shared::MethodData {
|
||||
class: Some(class.clone()),
|
||||
class: class.clone(),
|
||||
kind,
|
||||
})
|
||||
}
|
||||
ImportFunctionKind::ScopedMethod { ref operation, .. } => {
|
||||
Some(shared::MethodData {
|
||||
class: None,
|
||||
kind: shared::MethodKind::Operation(shared_operation(operation)),
|
||||
})
|
||||
}
|
||||
ImportFunctionKind::Normal => None,
|
||||
};
|
||||
|
||||
|
@ -779,9 +779,6 @@ impl TryToTokens for ast::ImportFunction {
|
||||
}
|
||||
class_ty = Some(ty);
|
||||
}
|
||||
ast::ImportFunctionKind::ScopedMethod { ref ty, .. } => {
|
||||
class_ty = Some(ty);
|
||||
}
|
||||
ast::ImportFunctionKind::Normal => {}
|
||||
}
|
||||
let vis = &self.function.rust_vis;
|
||||
|
@ -256,7 +256,6 @@ impl ImportedTypes for ast::ImportFunctionKind {
|
||||
{
|
||||
match self {
|
||||
ast::ImportFunctionKind::Method { ty, .. } => ty.imported_types(f),
|
||||
ast::ImportFunctionKind::ScopedMethod { ty, .. } => ty.imported_types(f),
|
||||
ast::ImportFunctionKind::Normal => {}
|
||||
}
|
||||
}
|
||||
|
@ -2001,30 +2001,7 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
||||
}
|
||||
};
|
||||
|
||||
let class = match &method_data.class {
|
||||
Some(class) => self.import_name(info, class)?,
|
||||
None => {
|
||||
let op = match &method_data.kind {
|
||||
shared::MethodKind::Operation(op) => op,
|
||||
shared::MethodKind::Constructor => {
|
||||
bail!("\"no class\" methods cannot be constructors")
|
||||
}
|
||||
};
|
||||
match &op.kind {
|
||||
shared::OperationKind::Regular => {
|
||||
return Ok(import.function.name.to_string())
|
||||
}
|
||||
shared::OperationKind::Getter(g) => {
|
||||
return Ok(format!("(() => {})", g));
|
||||
}
|
||||
shared::OperationKind::Setter(g) => {
|
||||
return Ok(format!("(v => {} = v)", g));
|
||||
}
|
||||
_ => bail!("\"no class\" methods must be regular/getter/setter"),
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
let class = self.import_name(info, &method_data.class)?;
|
||||
let op = match &method_data.kind {
|
||||
shared::MethodKind::Constructor => return Ok(format!("new {}", class)),
|
||||
shared::MethodKind::Operation(op) => op,
|
||||
|
@ -510,7 +510,6 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
|
||||
|
||||
let shim = {
|
||||
let ns = match kind {
|
||||
ast::ImportFunctionKind::ScopedMethod { .. } |
|
||||
ast::ImportFunctionKind::Normal => (0, "n"),
|
||||
ast::ImportFunctionKind::Method { ref class, .. } => (1, &class[..]),
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ pub struct ImportFunction {
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct MethodData {
|
||||
pub class: Option<String>,
|
||||
pub class: String,
|
||||
pub kind: MethodKind,
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,6 @@ pub(crate) struct FirstPassRecord<'src> {
|
||||
pub(crate) struct InterfaceData<'src> {
|
||||
/// Whether only partial interfaces were encountered
|
||||
pub(crate) partial: bool,
|
||||
pub(crate) global: bool,
|
||||
pub(crate) attributes: Vec<&'src AttributeInterfaceMember<'src>>,
|
||||
pub(crate) consts: Vec<&'src ConstMember<'src>>,
|
||||
pub(crate) operations: BTreeMap<OperationId<'src>, OperationData<'src>>,
|
||||
@ -373,12 +372,6 @@ fn process_interface_attribute<'src>(
|
||||
false,
|
||||
);
|
||||
}
|
||||
ExtendedAttribute::Ident(id) if id.lhs_identifier.0 == "Global" => {
|
||||
record.interfaces.get_mut(self_name).unwrap().global = true;
|
||||
}
|
||||
ExtendedAttribute::IdentList(id) if id.identifier.0 == "Global" => {
|
||||
record.interfaces.get_mut(self_name).unwrap().global = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -554,18 +554,11 @@ impl<'src> FirstPassRecord<'src> {
|
||||
None => false,
|
||||
};
|
||||
|
||||
let global = self
|
||||
.interfaces
|
||||
.get(self_name)
|
||||
.map(|interface_data| interface_data.global)
|
||||
.unwrap_or(false);
|
||||
|
||||
for mut import_function in self.create_getter(
|
||||
identifier,
|
||||
&type_.type_,
|
||||
self_name,
|
||||
is_static,
|
||||
global,
|
||||
attrs,
|
||||
container_attrs,
|
||||
) {
|
||||
@ -581,7 +574,6 @@ impl<'src> FirstPassRecord<'src> {
|
||||
&type_.type_,
|
||||
self_name,
|
||||
is_static,
|
||||
global,
|
||||
attrs,
|
||||
container_attrs,
|
||||
) {
|
||||
@ -602,7 +594,7 @@ impl<'src> FirstPassRecord<'src> {
|
||||
op_data: &OperationData<'src>,
|
||||
) {
|
||||
let import_function_kind = |opkind| {
|
||||
self.import_function_kind(self_name, data.global, op_data.is_static, opkind)
|
||||
self.import_function_kind(self_name, op_data.is_static, opkind)
|
||||
};
|
||||
let kind = match id {
|
||||
OperationId::Constructor(ctor_name) => {
|
||||
|
@ -316,7 +316,6 @@ impl<'src> FirstPassRecord<'src> {
|
||||
structural,
|
||||
shim: {
|
||||
let ns = match kind {
|
||||
backend::ast::ImportFunctionKind::ScopedMethod { .. } |
|
||||
backend::ast::ImportFunctionKind::Normal => "",
|
||||
backend::ast::ImportFunctionKind::Method { ref class, .. } => class,
|
||||
};
|
||||
@ -334,12 +333,11 @@ impl<'src> FirstPassRecord<'src> {
|
||||
ty: &weedle::types::Type<'src>,
|
||||
self_name: &str,
|
||||
is_static: bool,
|
||||
global: bool,
|
||||
attrs: &Option<ExtendedAttributeList>,
|
||||
container_attrs: Option<&ExtendedAttributeList>,
|
||||
) -> Option<backend::ast::ImportFunction> {
|
||||
let kind = backend::ast::OperationKind::Getter(Some(raw_ident(name)));
|
||||
let kind = self.import_function_kind(self_name, global, is_static, kind);
|
||||
let kind = self.import_function_kind(self_name, is_static, kind);
|
||||
let ret = ty.to_idl_type(self)?;
|
||||
self.create_one_function(
|
||||
&name,
|
||||
@ -361,12 +359,11 @@ impl<'src> FirstPassRecord<'src> {
|
||||
field_ty: &weedle::types::Type<'src>,
|
||||
self_name: &str,
|
||||
is_static: bool,
|
||||
global: bool,
|
||||
attrs: &Option<ExtendedAttributeList>,
|
||||
container_attrs: Option<&ExtendedAttributeList>,
|
||||
) -> Option<backend::ast::ImportFunction> {
|
||||
let kind = backend::ast::OperationKind::Setter(Some(raw_ident(name)));
|
||||
let kind = self.import_function_kind(self_name, global, is_static, kind);
|
||||
let kind = self.import_function_kind(self_name, is_static, kind);
|
||||
let field_ty = field_ty.to_idl_type(self)?;
|
||||
self.create_one_function(
|
||||
&name,
|
||||
@ -384,7 +381,6 @@ impl<'src> FirstPassRecord<'src> {
|
||||
pub fn import_function_kind(
|
||||
&self,
|
||||
self_name: &str,
|
||||
global: bool,
|
||||
is_static: bool,
|
||||
operation_kind: backend::ast::OperationKind,
|
||||
) -> backend::ast::ImportFunctionKind {
|
||||
@ -393,17 +389,10 @@ impl<'src> FirstPassRecord<'src> {
|
||||
kind: operation_kind,
|
||||
};
|
||||
let ty = ident_ty(rust_ident(camel_case_ident(&self_name).as_str()));
|
||||
if global {
|
||||
backend::ast::ImportFunctionKind::ScopedMethod {
|
||||
ty,
|
||||
operation,
|
||||
}
|
||||
} else {
|
||||
backend::ast::ImportFunctionKind::Method {
|
||||
class: self_name.to_string(),
|
||||
ty,
|
||||
kind: backend::ast::MethodKind::Operation(operation),
|
||||
}
|
||||
backend::ast::ImportFunctionKind::Method {
|
||||
class: self_name.to_string(),
|
||||
ty,
|
||||
kind: backend::ast::MethodKind::Operation(operation),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user