Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement rustwasm/rfcs#5, implement Deref for imports and structural by default #1019

Merged
merged 10 commits into from
Nov 12, 2018

Commits on Nov 8, 2018

  1. Implement Deref for all imported JS types

    This commit implements the first half of [RFC rustwasm#5] where the `Deref`
    trait is implemented for all imported types. The target of `Deref` is
    either the first entry of the list of `extends` attribute or `JsValue`.
    
    All examples using `.as_ref()` with various `web-sys` types have been
    updated to the more ergonomic deref casts now. Additionally the
    `web-sys` generation of the `extends` array has been fixed slightly to
    explicitly list implementatoins in the hierarchy order to ensure the
    correct target for `Deref` is chosen.
    
    [RFC rustwasm#5]: https://github.com/rustwasm/rfcs/blob/master/text/005-structural-and-deref.md
    alexcrichton committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    5b76a62 View commit details
    Browse the repository at this point in the history
  2. Use splat instead of arguments in tests

    Previously `arguments` was used to pass around an array of arguments,
    but this wasn't actually a `js_sys::Array` but rather a somewhat
    esoteric internal object. When switching over `Array` methods to be
    `structural` this caused issues because the inherent methods on an
    `arguments` object were different than that of `js_sys::Array`.
    alexcrichton committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    b013ec6 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    64a6241 View commit details
    Browse the repository at this point in the history
  4. Fix a test to actually test the right property

    This was a copy/paste typo!
    alexcrichton committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    58c3a99 View commit details
    Browse the repository at this point in the history
  5. 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 rustwasm#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
    alexcrichton committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    a16b4dd View commit details
    Browse the repository at this point in the history
  6. Don't convert boolean arguments going to wasm

    The wasm spec defines boolean conversion when crossing to the wasm type
    i32 as 1 for `true` and 0 for `false`, so no need for us to do it
    ourselves!
    alexcrichton committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    6093fd2 View commit details
    Browse the repository at this point in the history
  7. Switch all imports to structural by default

    This commit switches all imports of JS methods to `structural` by
    default. Proposed in [RFC 5] this should increase the performance of
    bindings today while also providing future-proofing for possible
    confusion with the recent addition of the `Deref` trait for all imported
    types by default as well.
    
    A new attribute, `host_binding`, is introduced in this PR as well to
    recover the old behavior of binding directly to an imported function
    which will one day be the precise function on the prototype. Eventually
    `web-sys` will switcsh over entirely to being driven via `host_binding`
    methods, but for now it's been measured to be not quite as fast so we're
    not making that switch yet.
    
    Note that `host_binding` differs from the proposed name of `final` due
    to the controversy, and its hoped that `host_binding` is a good
    middle-ground!
    
    [RFC 5]: https://rustwasm.github.io/rfcs/005-structural-and-deref.html
    alexcrichton committed Nov 8, 2018
    Configuration menu
    Copy the full SHA
    4c42aba View commit details
    Browse the repository at this point in the history

Commits on Nov 9, 2018

  1. Configuration menu
    Copy the full SHA
    8ba467e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2c9084d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    cb246e3 View commit details
    Browse the repository at this point in the history