Optimize shim generation for structural items

This commit removes shims, where possible, for `structural` items.
Instead of generating code that looks like:

    const target = function() { this.foo(); };
    exports.__wbg_thing = function(a) { target.call(getObject(a)); };

we now instead generate:

    exports.__wbg_thing = function(a) { getObject(a).foo(); };

Note that this only applies to `structural` bindings, all default
bindings (as of this commit) are still using imported targets to ensure
that their binding can't change after instantiation.

This change was [detailed in RFC #5][link] as an important optimization
for `structural` bindings to ensure they've got performance parity with
today's non-`structural` default bindings.

[link]: https://rustwasm.github.io/rfcs/005-structural-and-deref.html#why-is-it-ok-to-make-structural-the-default
This commit is contained in:
Alex Crichton
2018-11-08 12:31:39 -08:00
parent 58c3a99f94
commit a16b4dd9a4
4 changed files with 167 additions and 136 deletions

View File

@ -129,7 +129,7 @@ fn get_own_property_descriptor() {
let desc = Object::get_own_property_descriptor(&foo, &"foo".into());
assert_eq!(PropertyDescriptor::from(desc).value(), 42);
let desc = Object::get_own_property_descriptor(&foo, &"bar".into());
assert!(PropertyDescriptor::from(desc).value().is_undefined());
assert!(desc.is_undefined());
}
#[wasm_bindgen_test]

View File

@ -114,7 +114,7 @@ fn get_own_property_descriptor() {
let desc = Reflect::get_own_property_descriptor(&obj, &"x".into()).unwrap();
assert_eq!(PropertyDescriptor::from(desc).value(), 10);
let desc = Reflect::get_own_property_descriptor(&obj, &"foo".into()).unwrap();
assert!(PropertyDescriptor::from(desc).value().is_undefined());
assert!(desc.is_undefined());
}
#[wasm_bindgen_test]