Skip to content

Commit 79261ec

Browse files
committed
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.
1 parent 1ee5790 commit 79261ec

File tree

9 files changed

+10
-74
lines changed

9 files changed

+10
-74
lines changed

crates/backend/src/ast.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ pub enum ImportFunctionKind {
100100
ty: syn::Type,
101101
kind: MethodKind,
102102
},
103-
ScopedMethod {
104-
ty: syn::Type,
105-
operation: Operation,
106-
},
107103
Normal,
108104
}
109105

@@ -448,16 +444,10 @@ impl ImportFunction {
448444
}
449445
};
450446
Some(shared::MethodData {
451-
class: Some(class.clone()),
447+
class: class.clone(),
452448
kind,
453449
})
454450
}
455-
ImportFunctionKind::ScopedMethod { ref operation, .. } => {
456-
Some(shared::MethodData {
457-
class: None,
458-
kind: shared::MethodKind::Operation(shared_operation(operation)),
459-
})
460-
}
461451
ImportFunctionKind::Normal => None,
462452
};
463453

crates/backend/src/codegen.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,6 @@ impl TryToTokens for ast::ImportFunction {
784784
}
785785
class_ty = Some(ty);
786786
}
787-
ast::ImportFunctionKind::ScopedMethod { ref ty, .. } => {
788-
class_ty = Some(ty);
789-
}
790787
ast::ImportFunctionKind::Normal => {}
791788
}
792789
let vis = &self.function.rust_vis;

crates/backend/src/defined.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ impl ImportedTypes for ast::ImportFunctionKind {
256256
{
257257
match self {
258258
ast::ImportFunctionKind::Method { ty, .. } => ty.imported_types(f),
259-
ast::ImportFunctionKind::ScopedMethod { ty, .. } => ty.imported_types(f),
260259
ast::ImportFunctionKind::Normal => {}
261260
}
262261
}

crates/cli-support/src/js/mod.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,30 +2001,7 @@ impl<'a, 'b> SubContext<'a, 'b> {
20012001
}
20022002
};
20032003

2004-
let class = match &method_data.class {
2005-
Some(class) => self.import_name(info, class)?,
2006-
None => {
2007-
let op = match &method_data.kind {
2008-
shared::MethodKind::Operation(op) => op,
2009-
shared::MethodKind::Constructor => {
2010-
bail!("\"no class\" methods cannot be constructors")
2011-
}
2012-
};
2013-
match &op.kind {
2014-
shared::OperationKind::Regular => {
2015-
return Ok(import.function.name.to_string())
2016-
}
2017-
shared::OperationKind::Getter(g) => {
2018-
return Ok(format!("(() => {})", g));
2019-
}
2020-
shared::OperationKind::Setter(g) => {
2021-
return Ok(format!("(v => {} = v)", g));
2022-
}
2023-
_ => bail!("\"no class\" methods must be regular/getter/setter"),
2024-
}
2025-
2026-
}
2027-
};
2004+
let class = self.import_name(info, &method_data.class)?;
20282005
let op = match &method_data.kind {
20292006
shared::MethodKind::Constructor => return Ok(format!("new {}", class)),
20302007
shared::MethodKind::Operation(op) => op,

crates/macro-support/src/parser.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
510510

511511
let shim = {
512512
let ns = match kind {
513-
ast::ImportFunctionKind::ScopedMethod { .. } |
514513
ast::ImportFunctionKind::Normal => (0, "n"),
515514
ast::ImportFunctionKind::Method { ref class, .. } => (1, &class[..]),
516515
};

crates/shared/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct ImportFunction {
5151

5252
#[derive(Deserialize, Serialize)]
5353
pub struct MethodData {
54-
pub class: Option<String>,
54+
pub class: String,
5555
pub kind: MethodKind,
5656
}
5757

crates/webidl/src/first_pass.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub(crate) struct FirstPassRecord<'src> {
4444
pub(crate) struct InterfaceData<'src> {
4545
/// Whether only partial interfaces were encountered
4646
pub(crate) partial: bool,
47-
pub(crate) global: bool,
4847
pub(crate) attributes: Vec<&'src AttributeInterfaceMember<'src>>,
4948
pub(crate) consts: Vec<&'src ConstMember<'src>>,
5049
pub(crate) operations: BTreeMap<OperationId<'src>, OperationData<'src>>,
@@ -373,12 +372,6 @@ fn process_interface_attribute<'src>(
373372
false,
374373
);
375374
}
376-
ExtendedAttribute::Ident(id) if id.lhs_identifier.0 == "Global" => {
377-
record.interfaces.get_mut(self_name).unwrap().global = true;
378-
}
379-
ExtendedAttribute::IdentList(id) if id.identifier.0 == "Global" => {
380-
record.interfaces.get_mut(self_name).unwrap().global = true;
381-
}
382375
_ => {}
383376
}
384377
}

crates/webidl/src/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -525,18 +525,11 @@ impl<'src> FirstPassRecord<'src> {
525525
None => false,
526526
};
527527

528-
let global = self
529-
.interfaces
530-
.get(self_name)
531-
.map(|interface_data| interface_data.global)
532-
.unwrap_or(false);
533-
534528
for mut import_function in self.create_getter(
535529
identifier,
536530
&type_.type_,
537531
self_name,
538532
is_static,
539-
global,
540533
attrs,
541534
container_attrs,
542535
) {
@@ -552,7 +545,6 @@ impl<'src> FirstPassRecord<'src> {
552545
&type_.type_,
553546
self_name,
554547
is_static,
555-
global,
556548
attrs,
557549
container_attrs,
558550
) {
@@ -573,7 +565,7 @@ impl<'src> FirstPassRecord<'src> {
573565
op_data: &OperationData<'src>,
574566
) {
575567
let import_function_kind = |opkind| {
576-
self.import_function_kind(self_name, data.global, op_data.is_static, opkind)
568+
self.import_function_kind(self_name, op_data.is_static, opkind)
577569
};
578570
let kind = match id {
579571
OperationId::Constructor(ctor_name) => {

crates/webidl/src/util.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ impl<'src> FirstPassRecord<'src> {
316316
structural,
317317
shim: {
318318
let ns = match kind {
319-
backend::ast::ImportFunctionKind::ScopedMethod { .. } |
320319
backend::ast::ImportFunctionKind::Normal => "",
321320
backend::ast::ImportFunctionKind::Method { ref class, .. } => class,
322321
};
@@ -334,12 +333,11 @@ impl<'src> FirstPassRecord<'src> {
334333
ty: &weedle::types::Type<'src>,
335334
self_name: &str,
336335
is_static: bool,
337-
global: bool,
338336
attrs: &Option<ExtendedAttributeList>,
339337
container_attrs: Option<&ExtendedAttributeList>,
340338
) -> Option<backend::ast::ImportFunction> {
341339
let kind = backend::ast::OperationKind::Getter(Some(raw_ident(name)));
342-
let kind = self.import_function_kind(self_name, global, is_static, kind);
340+
let kind = self.import_function_kind(self_name, is_static, kind);
343341
let ret = ty.to_idl_type(self)?;
344342
self.create_one_function(
345343
&name,
@@ -361,12 +359,11 @@ impl<'src> FirstPassRecord<'src> {
361359
field_ty: &weedle::types::Type<'src>,
362360
self_name: &str,
363361
is_static: bool,
364-
global: bool,
365362
attrs: &Option<ExtendedAttributeList>,
366363
container_attrs: Option<&ExtendedAttributeList>,
367364
) -> Option<backend::ast::ImportFunction> {
368365
let kind = backend::ast::OperationKind::Setter(Some(raw_ident(name)));
369-
let kind = self.import_function_kind(self_name, global, is_static, kind);
366+
let kind = self.import_function_kind(self_name, is_static, kind);
370367
let field_ty = field_ty.to_idl_type(self)?;
371368
self.create_one_function(
372369
&name,
@@ -384,7 +381,6 @@ impl<'src> FirstPassRecord<'src> {
384381
pub fn import_function_kind(
385382
&self,
386383
self_name: &str,
387-
global: bool,
388384
is_static: bool,
389385
operation_kind: backend::ast::OperationKind,
390386
) -> backend::ast::ImportFunctionKind {
@@ -393,17 +389,10 @@ impl<'src> FirstPassRecord<'src> {
393389
kind: operation_kind,
394390
};
395391
let ty = ident_ty(rust_ident(camel_case_ident(&self_name).as_str()));
396-
if global {
397-
backend::ast::ImportFunctionKind::ScopedMethod {
398-
ty,
399-
operation,
400-
}
401-
} else {
402-
backend::ast::ImportFunctionKind::Method {
403-
class: self_name.to_string(),
404-
ty,
405-
kind: backend::ast::MethodKind::Operation(operation),
406-
}
392+
backend::ast::ImportFunctionKind::Method {
393+
class: self_name.to_string(),
394+
ty,
395+
kind: backend::ast::MethodKind::Operation(operation),
407396
}
408397
}
409398

0 commit comments

Comments
 (0)