mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 12:31:22 +00:00
Guarantee static_method_of
uses the right this
(#1795)
This came up during #1760 where `Promise.resolve` must be invoked with `this` as the `Promise` object, but we were erroneously importing it in such a way that it didn't have a shim and `this` was `undefined`.
This commit is contained in:
@ -2269,6 +2269,11 @@ impl<'a> Context<'a> {
|
||||
}
|
||||
},
|
||||
|
||||
AuxImport::ValueWithThis(class, name) => {
|
||||
let class = self.import_name(class)?;
|
||||
Ok(format!("{}.{}({})", class, name, variadic_args(&args)?))
|
||||
}
|
||||
|
||||
AuxImport::Instanceof(js) => {
|
||||
assert!(webidl_ty.kind == ast::WebidlFunctionKind::Static);
|
||||
assert!(!variadic);
|
||||
|
@ -278,6 +278,10 @@ pub enum AuxImport {
|
||||
/// imported
|
||||
Value(AuxValue),
|
||||
|
||||
/// A static method on a class is being imported, and the `this` of the
|
||||
/// function call is expected to always be the class.
|
||||
ValueWithThis(JsImport, String),
|
||||
|
||||
/// This import is expected to be a function that takes an `anyref` and
|
||||
/// returns a `bool`. It's expected that it tests if the argument is an
|
||||
/// instance of (using `instanceof`) the name specified.
|
||||
@ -950,8 +954,7 @@ impl<'a> Context<'a> {
|
||||
match op.kind {
|
||||
decode::OperationKind::Regular => {
|
||||
if op.is_static {
|
||||
class.fields.push(function.name.to_string());
|
||||
Ok((AuxImport::Value(AuxValue::Bare(class)), false))
|
||||
Ok((AuxImport::ValueWithThis(class, function.name.to_string()), false))
|
||||
} else if structural {
|
||||
Ok((
|
||||
AuxImport::StructuralMethod(function.name.to_string()),
|
||||
|
@ -574,6 +574,9 @@ fn check_standard_import(import: &AuxImport) -> Result<(), Error> {
|
||||
| AuxImport::Value(AuxValue::ClassSetter(js, name)) => {
|
||||
format!("field access of `{}` for {}", name, desc_js(js))
|
||||
}
|
||||
AuxImport::ValueWithThis(js, method) => {
|
||||
format!("method `{}.{}`", desc_js(js), method)
|
||||
}
|
||||
AuxImport::Instanceof(js) => format!("instance of check of {}", desc_js(js)),
|
||||
AuxImport::Static(js) => format!("static js value {}", desc_js(js)),
|
||||
AuxImport::StructuralMethod(name) => format!("structural method `{}`", name),
|
||||
|
Reference in New Issue
Block a user