Commit Graph

46 Commits

Author SHA1 Message Date
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
Anton Danilkin
3d9401aca6 Fix JS style 2018-08-03 15:59:27 -05:00
Anton Danilkin
81cbb2e26d Migrate the test 2018-08-03 15:59:27 -05:00
Alex Crichton
88db12669f Add support for Option<&T> in imported argument lists
Closes #619
2018-08-02 22:40:42 -07:00
Alex Crichton
fe51cf9857 Add tests for by-value options 2018-08-02 22:23:11 -07:00
Alex Crichton
4181afea45
Start migrating wasm_bindgen tests to wasm_bindgen_test (#602)
This commit starts migrating the `wasm_bindgen` tests to the `wasm_bindgen_test`
framework, starting to assemble the coffin for
`wasm-bindgen-test-project-builder`. Over time all of the tests in
`tests/all/*.rs` should be migrated to `wasm_bindgen_test`, although they may
not all want to go into a monolithic test suite so we can continue to test for
some more subtle situations with `#[wasm_bindgen]`.

In the meantime those, the `tests/all/api.rs` tests can certainly migrate!
2018-08-01 14:19:19 -05:00