Commit Graph

55 Commits

Author SHA1 Message Date
Alex Crichton
84bda02bbf
Merge pull request #923 from alexcrichton/extends-path
Parse `Path`s in `extends` attributes
2018-10-03 10:38:50 -07:00
Alex Crichton
5df8e20815 Parse Paths in extends attributes
Closes #916
2018-10-03 09:14:23 -07:00
Alex Crichton
32b62b4358 Fix exporting structs with BorrowMut in scope
Apparently the codegen wasn't precise enough such that a trait import
could cause method resolution to go awry!

Closes #919
2018-10-02 23:56:15 -07:00
Alex Crichton
9c085dc0f5
Merge pull request #914 from alexcrichton/rename-polyfill
Rename `polyfill` to `vendor_prefix`
2018-10-01 14:47:07 -07:00
Alex Crichton
f75349262a Rename polyfill to vendor_prefix
cc #906
2018-10-01 14:45:30 -07:00
Alex Crichton
a7e9da0a81
Merge pull request #879 from alexcrichton/closure-zst
Improve codegen for `Closure<T>`
2018-10-01 14:41:13 -07:00
Alex Crichton
8ba41cce6e Improve codegen for Closure<T>
This commit improves the codegen for `Closure<T>`, primarily for ZST
where the closure doesn't actually capture anything. Previously
`wasm-bindgen` would unconditionally allocate an `Rc` for a fat pointer,
meaning that it would always hit the allocator even when the `Box<T>`
didn't actually contain an allocation. Now the reference count for the
closure is stored on the JS object rather than in Rust.

Some more advanced tests were added along the way to ensure that
functionality didn't regress, and otherwise the calling convention for
`Closure` changed a good deal but should still be the same user-facing.
The primary change was that the reference count reaching zero may cause
JS to need to run the destructor. It simply returns this information in
`Drop for Closure` and otherwise when calling it now also retains a
function pointer that runs the destructor.

Closes #874
2018-09-29 07:00:53 -07:00
Alex Crichton
3c14f7a6eb Implement a polyfill attribute for imports
Allow using imported APIs under alternative names, such as prefixed
names, for web APIs when the exact API differs across browsers.
2018-09-28 13:43:00 -07:00
Alex Crichton
7ecf4aae87 cargo +nightly fmt --all
Rustfmt all the things!
2018-09-26 08:26:00 -07:00
Alex Crichton
7b495468f6 Implement support for Uint8ClampedArray
This commit implements support for binding APIs that take
`Uint8ClampedArray` in JS. This is pretty rare but comes up in a
`web-sys` binding or two, and we're now able to bind these APIs instead
of having to omit the bindings.

The `Uint8ClampedArray` type is bound by using the `Clamped` marker
struct in Rust. For example this is declaring a JS API that takes
`Uint8ClampedArray`:

    use wasm_bindgen::Clamped;

    #[wasm_bindgen]
    extern {
        fn takes_clamped(a: Clamped<&[u8]>);
    }

The `Clamped` type currently only works when wrapping the `&[u8]`, `&mut
[u8]`, and `Vec<u8>` types. Everything else will produce an error at
`wasm-bindgen` time.

Closes #421
2018-09-24 13:58:37 -07:00
Alex Crichton
9a1fa5a81b
Merge pull request #870 from alexcrichton/no-constructor-token
Remove the need for a `ConstructorToken`
2018-09-21 21:40:08 -07:00
Alex Crichton
75f005be23 Support #[wasm_bindgen(setter, js_name = ...)]
Previously we'd require the explicit `js_name` to *also* start with
`set_`, but when explicitly specified it shouldn't be mangled at all!

Closes #584
2018-09-21 17:54:26 -07:00
Alex Crichton
3f85d7db9f Remove the need for a ConstructorToken
This commit removes the need for an injected `ConstructorToken` type and
also cleans up the story we have for generating constructors a bit.
After this commit a `constructor()` is omitted entirely if we're in
non-debug mode and there's no actual listed constructor. Additionally we
don't deal with splat arguments and rerouting constructors, Nick was
kind enough to enlighten me about `Object.create` which is creating an
instance without running the constructor!

Instances of an exported type are now created through one of two
methods:

* If `#[wasm_bindgen(constructor)]` is present, then a `constructor` is
  generated with the appropriate signature. If a constructor is not
  present and we're in debug mode, a throwing constructor is generated.
  If we're in release mode and there's no constructor, no constructor is
  generated.

* Otherwise if a binding returns an instance of a type (or otherwise
  needs to manfuacture an instance, then it will cause an internal
  `__wrap` function to be generated. This function will use
  `Object.create` to create an instance without running the constructor.

This should ideally clean up our generated JS for classes quite a bit,
making it much more lean-and-mean!
2018-09-21 17:42:06 -07:00
Alex Crichton
ab3688d01a Only generate JS null checks in debug mode
In non-debug mode Rust is already checking these pointers, so let's only
generate the relevant code in debug mode.
2018-09-21 16:10:02 -07:00
Alex Crichton
7cf4213283 Allow returning Result from functions
This commit adds support for exporting a function defined in Rust that returns a
`Result`, translating the `Ok` variant to the actual return value and the `Err`
variant to an exception that's thrown in JS.

The support for return types and descriptors was rejiggered a bit to be a bit
more abstract and more well suited for this purpose. We no longer distinguish
between functions with a return value and those without a return value.
Additionally a new trait, `ReturnWasmAbi`, is used for converting return values.
This trait is an internal implementation detail, however, and shouldn't surface
itself to users much (if at all).

Closes #841
2018-09-18 13:13:59 -07:00
Richard Dodd
7d5d845608 Add docs and remove typecheck from variadic attribute 2018-09-01 13:55:35 +01:00
Richard Dodd
ce1cb84327 Merge branch 'master' into variadic_js_functions 2018-08-31 10:08:53 +01:00
Alex Crichton
e1474110d4 Add an accessor for wasm's own memory as a JS object
In addition to closing #495 this'll be useful eventually when instantiating
multiple wasm modules from Rust as you'd now be able to acquire a reference to
the current module in Rust itself.
2018-08-27 11:05:55 -07:00
Richard Dodd
8ff0da6f85 Add more tests then comment them out 2018-08-21 14:07:29 +01:00
Richard Dodd
b8c1f72dab Comment out failing code 2018-08-21 13:55:14 +01:00
Richard Dodd
e92536f300 Allow Vec as well as slice 2018-08-21 13:47:00 +01:00
Richard Dodd
385e805509 Work on review comments 2018-08-21 12:55:09 +01:00
Alex Crichton
86d1ab513b
Merge pull request #741 from alexcrichton/duplicate-statics
Support importing same-name statics from two modules
2018-08-20 11:37:21 -07:00
Alex Crichton
f8cf4ab732 Support importing same-name statics from two modules
Closes #714
2018-08-20 10:56:58 -07:00
Alex Crichton
4195af68e7 Fix the constructor and catch attributes combined
This commit fixes annotations that include both the `constructor` and `catch`
attributes on imported types, ensuring that we infer the right type being
returned after extracting the first type parameter of the `Result`.

Closes #735
2018-08-20 10:40:54 -07:00
Alex Crichton
4c1bf937f2 Move the unsize feature behind a nightly Cargo feature
This should fully stabilize the `wasm-bindgen` crate, preparing us for stable
Rust!
2018-08-19 14:45:59 -07:00
Alex Crichton
d4297ad2d3 Remove use_extern_macros features
This has now been stabilized!
2018-08-19 14:33:01 -07:00
Richard Dodd
a4835304eb Add codegen to make test work. 2018-08-19 13:39:16 +01:00
Richard Dodd
d9fd2147a0 [wip] support variadic javascript function parameters 2018-08-18 22:15:29 +01:00
Nick Fitzgerald
998d37a353 Use the JS name of an imported type for instanceof checks 2018-08-08 14:42:21 -07:00
Alex Crichton
bd15db40a0 Rebase fallout and review comments 2018-08-07 13:24:48 -07:00
Alex Crichton
37db88ebfa Implement #[wasm_bindgen(extends = ...)]
This commit implements the `extends` attribute for `#[wasm_bindgen]` to
statically draw the inheritance hierarchy in the generated bindings, generating
appropriate `AsRef`, `AsMut`, and `From` implementations.
2018-08-07 13:04:11 -07:00
Alex Crichton
11553a1af2 Implement JsCast for all imported types
This commit implements the `JsCast` trait automatically for all imported types
in `#[wasm_bindgen] extern { ... }` blocks. The main change here was to generate
an `instanceof` shim for all imported types in case it's needed.

All imported types now also implement `AsRef<JsValue>` and `AsMut<JsValue>`
2018-08-07 12:59:51 -07:00
Alex Crichton
c82c8e7acb Move comments test to wasm 2018-08-06 11:46:23 -07:00
Alex Crichton
d5b81595ec Remove support for the version attribute
First added in #161 this never ended up panning out, so let's remove the
experimental suport which isn't actually used by anything today and hold off on
any other changes until an RFC happens.
2018-08-06 13:30:28 -05:00
Alex Crichton
7f8d510f3d Move unused_imports_not_generated test to wasm 2018-08-06 11:28:08 -07:00
Alex Crichton
005f7eb9fa Migrate rest of dependencies test to wasm 2018-08-06 10:42:08 -07:00
Alex Crichton
28036db262 Move node test over to wasm 2018-08-06 10:06:45 -07:00
Alex Crichton
6edf063c94 Allow disabling --debug in wasm-bindgen-test-runner
Afterwards remove the `non_debug` test as we're running the entire test suite in
non-debug mode!
2018-08-06 09:57:41 -07:00
Alex Crichton
8513858973 Move $-renaming tests to wasm 2018-08-06 09:51:29 -07:00
Alex Crichton
0bdb31d41e Migrate the serde-serialize test to wasm 2018-08-06 09:43:55 -07:00
Alex Crichton
4661588171 Move most of the "simple" test to the wasm suite 2018-08-06 09:21:41 -07:00
Alex Crichton
b4601295d0 Migrate most import tests to wasm 2018-08-05 12:35:47 -05:00
Alex Crichton
66d51f13ee Migrate the import_class to wasm 2018-08-05 12:35:47 -05:00
Anton Danilkin
654bb9b683 Port tests that use only basic features 2018-08-04 22:25:29 -05:00
Alex Crichton
57fd1dedd6 Migrate wasm-bindgen classes test to wasm 2018-08-04 15:09:43 -05:00
Alex Crichton
df7bcc4e03 Migrate wasm-bindgen char test to wasm 2018-08-04 15:09:43 -05:00
Anton Danilkin
61b3d52dc9 Rename the test 2018-08-03 15:59:27 -05:00
Anton Danilkin
afaf94a428 Add support for optional chars 2018-08-03 15:59:27 -05:00
Anton Danilkin
4a0c69ffed Add support for optional bools 2018-08-03 15:59:27 -05:00