Commit Graph

63 Commits

Author SHA1 Message Date
4054ce8a2c More fixes for iterating example 2018-12-13 10:40:07 -08:00
53d6e00b70 Fix compilation of example in docs
Stray `match` keyword!

Closes #1109
2018-12-12 08:20:35 -08:00
a2aa28e4d3 Add a #[wasm_bindgen(start)] attribute
This commit adds a new attribute to `#[wasm_bindgen]`: `start`. The
`start` attribute can be used to indicate that a function should be
executed when the module is loaded, configuring the `start` function of
the wasm executable. While this doesn't necessarily literally configure
the `start` section, it does its best!

Only one crate in a crate graph may indicate `#[wasm_bindgen(start)]`,
so it's not recommended to be used in libraries but only end-user
applications. Currently this still must be used with the `crate-type =
["cdylib"]` annotation in `Cargo.toml`.

The implementation here is somewhat tricky because of the circular
dependency between our generated JS and the wasm file that we emit. This
circular dependency makes running initialization routines (like the
`start` shim) particularly fraught with complications because one may
need to run before the other but bundlers may not necessarily respect
it. Workarounds have been implemented for various emission strategies,
for example calling the start function directly after exports are wired
up with `--no-modules` and otherwise working around what appears to be
a Webpack bug with initializers running in a different order than we'd
like. In any case, this in theory doesn't show up to the end user!

Closes #74
2018-11-28 22:11:15 -08:00
151ed58b69 Consistently use extern "C"
This is what rustfmt favors, so let's favor it too!

Closes #1042
2018-11-27 12:27:00 -08:00
90193eab51 Adds support for #[wasm_bindgen(typescript_custom_section)]. 2018-11-24 00:49:28 -05:00
4c44f7d2db Fix typo: wasm-bindgn -> wasm-bindgen 2018-11-22 10:34:31 -05:00
cb246e38fb Rename host_binding to final 2018-11-09 08:00:41 -08:00
2c9084d0e2 Update web-sys test to only test compilation 2018-11-09 07:56:48 -08:00
4c42aba007 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
2018-11-08 13:52:18 -08:00
ac6a230d83 Merge pull request #1012 from alexcrichton/rename-exported-type
Implement support for `js_class` on exported types
2018-11-05 17:44:21 -06:00
16d5243362 Implement support for js_class on exported types
Allow defining types which have different names in Rust than they have
in JS! (just like can be done with imported types)

Closes #1010
2018-11-05 12:29:14 -08:00
9478a65e3c Add a note about renaming types and js_class
When a type is renamed in Rust via `js_name` then all method imports
will also need a `js_class` annotation to hook them up correctly.
2018-11-05 11:10:09 -08:00
34b75c35b2 Allow passing a WebAssembly.Module in --no-modules
I've noticed this in a few cases where it's sometimes easy to have a
`WebAssembly.Module` on-hand for the `--no-modules` mode where you don't
want to necessarily `fetch`. This commit changes the exported
initialization function in `--no-modules` mode to support both!
2018-10-16 10:48:07 -07:00
5957289ef2 Add caveat for BigInt and u64 in browser support
Closes #948
2018-10-10 10:30:32 -07:00
32fd1227e4 Merge pull request #910 from alexcrichton/fix-text-encoder-edge
Fix polyfill of `TextEncoder` and `TextDecoder`
2018-10-03 00:07:30 -07:00
f75349262a Rename polyfill to vendor_prefix
cc #906
2018-10-01 14:45:30 -07:00
717cfa303d Fix polyfill of TextEncoder and TextDecoder
This commit does a few things, including:

* Fixing the generated JS of `wasm-bindgen` to allow polyfills to work.
  (a minor tweak of the generated JS)

* All examples are updated to include a Webpack-specific polyfill for
  these two types to get examples working in Edge.

* A new page has been added to the guide about supported browsers. This
  mentions known caveats like IE 11 requiring `wasm2js` as well as
  documenting some `TextEncoder` and `TextDecoder` workarounds for Edge.

Closes #895
2018-09-30 10:16:20 -07:00
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
114176f8b8 Add documentation about supported targets
* Main target is wasm32-unknown-unknown
* All other targets work ok, but imports panic
* Emscripten explicitly not supported at this time

Closes #892
2018-09-27 13:39:23 -07:00
a920656e09 guide: Update untyped JS values section to handle fallibility of Reflect::* APIs 2018-09-25 14:30:26 -07:00
dfd0f534f9 guide: Add section about iterating over JS values 2018-09-25 14:30:26 -07:00
0ba7e8107c Add some blurbs about optimizing for size
The main thing we mention is to explicitly not measure the output of the
compiler, but only the ouput of `wasm-bindgen` itself.

Closes #826
2018-09-24 11:28:02 -07:00
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
1872e84a8a guide: Add section on working with duck-typed interfaces 2018-09-11 16:40:32 -07:00
27a7008764 guide: Add section on accessing properties of untyped values
Part of #616
2018-09-11 15:26:51 -07:00
3f92607be2 Merge pull request #810 from Tarnadas/doc/js-sys-function
doc: Add number suffix hint for JS function calls
2018-09-11 10:04:20 -07:00
84a477d78d doc: Add number suffix hint for JS function calls 2018-09-11 07:25:08 +02:00
e6fe9cf353 doc: Add nightly feature hint for closures
resolves #767
2018-09-11 07:06:21 +02:00
7d5d845608 Add docs and remove typecheck from variadic attribute 2018-09-01 13:55:35 +01:00
a5a8fd747d guide: Split supported types section up into many sub sections 2018-08-14 18:01:17 -07:00
b1e3101fd4 guide: Add examples for number slices 2018-08-14 17:42:47 -07:00
fea41b4a87 guide: also allow Option<bool> 2018-08-14 17:34:16 -07:00
9c9e53485a guide: Add examples of boxed number slices 2018-08-14 17:15:01 -07:00
8043baac69 guide: Add examples for working with numbers to types section 2018-08-14 15:45:25 -07:00
602b63c1b0 guide: Add working with pointers example to types section 2018-08-14 15:24:43 -07:00
46f1719524 Merge pull request #696 from fitzgen/more-examples-for-guide
More examples for guide
2018-08-13 18:34:26 -06:00
d1b2299340 guide: Add Box<[JsValue]> example to supported types section 2018-08-13 17:08:18 -07:00
60307e81f9 guide: Add JsValue example to supported types section 2018-08-13 16:57:29 -07:00
fedd1a5440 guide: Add bool example to supported types section 2018-08-13 16:55:05 -07:00
975a122d6d guide: Add a char example to the supported types section 2018-08-13 16:24:39 -07:00
74dc8874e1 guide: add String example usage to supported types 2018-08-13 16:20:25 -07:00
fa72afe286 guide: Add str examples to supported types section 2018-08-13 16:12:58 -07:00
8e19645006 guide: Add exported rust type examples to reference 2018-08-13 16:03:02 -07:00
485d377594 guide: Add a reference section for Promises and Futures 2018-08-13 15:44:28 -07:00
e87498e939 guide: Start adding example usage to "supported types" section 2018-08-10 16:56:40 -07:00
cc76963bad guide: typo in arbitrary data with serde 2018-08-09 17:46:38 +02:00
5b935526ff Merge pull request #640 from alexcrichton/jscast
Implement RFC #2 - casting hierarchy between JS values
2018-08-07 17:26:37 -05:00
43636977ae Merge pull request #664 from fitzgen/guide-serde-arbitrary-data
Guide serde arbitrary data
2018-08-07 14:48:45 -07:00
1d92784e07 guide: add indexing_{getter,setter,deleter} attribute page 2018-08-07 14:42:13 -07:00
2e7620e014 guide: Polish Serializing + Deserializing into/from JsValue with Serde section 2018-08-07 14:25:30 -07:00