Commit Graph

167 Commits

Author SHA1 Message Date
Alex Crichton
b71f3374c5 Tweak introductory and deployment documentation.
This commit rejiggers some documentation of `wasm-bindgen` in a few
significant ways:

* The main landing page now has text and links to the Game of Life
  tutorial and `wasm-pack`.
* The "whirlwind tour" was deleted as it wasn't really serving any
  purpose that the Game of Life plus the later references weren't already
  serving.
* The "no modules" example was renamed to "without a bundler"
* A dedicated section on "Deployment" was added which replaces the
  previous "No ES Modules" page. This is hopefully more descriptive and
  also prominently mentions the various options for deployment.
2019-02-22 07:50:32 -08:00
Camille TJHOA
eda7541e45 Fix missing link on todomvc example 2019-02-17 16:19:23 +00:00
Stephen Sherratt
f774d52ed5 Fix broken links 2019-02-10 14:54:18 +00:00
Carlos Diaz-Padron
11db255e47
Fix version number in travis instruction 2019-01-31 18:00:49 -08:00
Ivo Georgiev
b3e97a7e45
browser-support: warn about the performance hit of using the polyfill~ 2019-01-28 20:55:11 +01:00
Alex Crichton
32c611d16d Convert all examples to using wasm-pack
This commit migrates all our examples to using `wasm-pack build` to
compile their code and run `wasm-bindgen`. This should make it a bit
easier to understand the examples as there's less to follow during the
build step.

Webpack projects are all using `@wasm-tool/wasm-pack-plugin` as well so
the build step is simple `npm run serve`. Other examples which retain
`build.sh` are just using `wasm-pack build` now
2019-01-17 08:37:32 -08:00
Andrew Mackenzie
4139fc10f7
Remove separators that cause numbering jumps
I have removed the "--------------------" separators as they cause a section number to be skipped and hence incorrect section numbering in the left panel TOC.

Take a look at https://rustwasm.github.io/wasm-bindgen/web-sys/index.html left panel, towards the bottom, and you will see that it's jumps from section 3, to 5, to 7 to 9 - which I am assuming is NOT what you wanted.
2019-01-01 17:38:45 +01:00
Khải
af06c6fc3d
Fix typo 2018-12-22 16:15:12 +07:00
Alex Crichton
4054ce8a2c More fixes for iterating example 2018-12-13 10:40:07 -08:00
Roberto Vidal
08680276ae Fixes outdated links 2018-12-13 15:25:15 +01:00
Alex Crichton
53d6e00b70 Fix compilation of example in docs
Stray `match` keyword!

Closes #1109
2018-12-12 08:20:35 -08:00
Nick Fitzgerald
77ddf5ebcd examples: Add a requestAnimationFrame loop example 2018-12-10 12:50:19 -08:00
Alex Crichton
49d835a7bc Switch from heap/stack to just a heap
This commit switches strategies for storing `JsValue` from a heap/stack
to just one heap. This mirrors the new strategy for `JsValue` storage
in #1002 and should make multiplexing those strategies at
`wasm-bindgen`-time much easier.

Instead of having one array which acts as a stack for borrowed values
and one array for a heap of borrowed values, only one JS array is used
for storage of JS values now. This makes `getObject` far simpler by
simply being an array access, but it means that cloning an object now
reserves a new slot instead of reference counting it. If the old
reference counting behavior is needed it's thought that `Rc<JsValue>`
can be used in Rust.

The new "heap" has an initial stack pointer which grows downwards, and a
heap which grows upwards. The heap is a singly-linked-list which is
allocated/deallocated from. The stack grows downwards to zero and
presumably starts generating errors once it underflows. An initial stack
size of 32 is chosen as that should encompass all use cases today, but
we can eventually probably add configuration for this!

Note that the heap is initialized to all `null` for the stack and then
the initial JS values (`undefined`, `null`, `true`, `false`) are pushed
onto the heap in reserved locations.
2018-11-30 12:07:16 -08:00
Danilo Bargen
fdf201a8f1
Fix typo in wasm-bindgen-test usage docs 2018-11-29 17:47:07 +01:00
Alex Crichton
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
Alex Crichton
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
Tim Ryan
90193eab51 Adds support for #[wasm_bindgen(typescript_custom_section)]. 2018-11-24 00:49:28 -05:00
Markus Stange
4c44f7d2db
Fix typo: wasm-bindgn -> wasm-bindgen 2018-11-22 10:34:31 -05:00
Garrett Steffen
92ce73d197
Revert js-sys link change, added web-sys link
Correction to Pull Request #1035

limira is correct, that particular paragraph is referencing another crate. Considering the wasm-bindgen tutorial links here for the web-sys crate I added another link to the correct cargo link.

Sorry for the mistake.
2018-11-17 09:57:43 -06:00
Garrett Steffen
0452fbc639
Fixed link to the wrong crate 2018-11-16 19:22:19 -06:00
Alex Crichton
cb246e38fb Rename host_binding to final 2018-11-09 08:00:41 -08:00
Alex Crichton
2c9084d0e2 Update web-sys test to only test compilation 2018-11-09 07:56:48 -08:00
Alex Crichton
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
Alex Crichton
5b76a6291e Implement Deref for all imported JS types
This commit implements the first half of [RFC #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 #5]: https://github.com/rustwasm/rfcs/blob/master/text/005-structural-and-deref.md
2018-11-08 11:01:34 -08:00
Alex Crichton
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
Alex Crichton
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
Alex Crichton
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
Jonathan Kingston
b322f46303 Adding in TODO MVC example using web-sys 2018-10-23 14:15:42 +01:00
Alex Crichton
25b26f41e7 Implement support for WebAssembly threads
... and add a parallel raytracing demo!

This commit adds enough support to `wasm-bindgen` to produce a workable
wasm binary *today* with the experimental WebAssembly threads support
implemented in Firefox Nightly. I've tried to comment what's going on in
the commits and such, but at a high level the changes made here are:

* A new transformation, living in a new `wasm-bindgen-threads-xform`
  crate, prepares a wasm module for parallel execution. This performs a
  number of mundane tasks which I hope to detail in a blog post later on.
* The `--no-modules` output is enhanced with more support for when
  shared memory is enabled, allowing passing in the module/memory to
  initialize the wasm instance on multiple threads (sharing both module
  and memory).
* The `wasm-bindgen` crate now offers the ability, in `--no-modules`
  mode, to get a handle on the `WebAssembly.Module` instance.
* The example itself requires Xargo to recompile the standard library
  with atomics and an experimental feature enabled. Afterwards it
  experimentally also enables threading support in wasm-bindgen.

I've also added hopefully enough CI support to compile this example in a
builder so we can upload it and poke around live online. I hope to
detail more about the technical details here in a blog post soon as
well!
2018-10-23 01:20:18 -07:00
Alex Crichton
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
Alex Crichton
5957289ef2 Add caveat for BigInt and u64 in browser support
Closes #948
2018-10-10 10:30:32 -07:00
Nick Fitzgerald
8d195d07ee guide: clarify testing docs; prefer wasm-pack-based workflows 2018-10-09 09:31:01 -07:00
Daniele Esposti
882c6ef0ed Update installation of toolchain in Basic Usage page 2018-10-05 17:15:22 +01:00
Alex Crichton
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
Alex Crichton
f75349262a Rename polyfill to vendor_prefix
cc #906
2018-10-01 14:45:30 -07:00
Alex Crichton
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
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
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
Alex Crichton
a3e160744e Update Window example in web-sys 2018-09-26 08:14:14 -07:00
Alex Crichton
7a2f55d2d1 Update another git url 2018-09-26 08:11:55 -07:00
Alex Crichton
3b2448cce1 Update web-sys docs now that it's published 2018-09-26 08:10:18 -07:00
Cameron Taggart
052b41b84c update to "webpack-cli": "^3.1.1" 2018-09-25 18:50:27 -07:00
Nick Fitzgerald
a920656e09 guide: Update untyped JS values section to handle fallibility of Reflect::* APIs 2018-09-25 14:30:26 -07:00
Nick Fitzgerald
dfd0f534f9 guide: Add section about iterating over JS values 2018-09-25 14:30:26 -07:00
Nick Fitzgerald
8a2b2cb6e1
Merge pull request #876 from alexcrichton/contrib-js-sys
Update contributing docs for js-sys
2018-09-24 17:35:28 -07:00
Nick Fitzgerald
f9f8d2c214
Merge pull request #877 from alexcrichton/opt-tests
Add some blurbs about optimizing for size
2018-09-24 17:30:41 -07:00
Alex Crichton
b256b98e38 Improve link_mem_intrinsics hack
Previously the `link_mem_intrinsics` hack actually had a runtime
overhead by storing a value into a global location, but it turns out we
can actually use a non-inlined function call as part of the *descriptor*
which requires this to be in the final binary, but we'll end up snip'ing
the value at the end.

All in all this should mean that it's not a zero-overhead solution for
linking these intrinsics! The `#[wasm_bindgen]` attribute already has
other problems if the descriptors don't show up, so that's the least of
our issues!
2018-09-24 15:43:04 -07:00
Alex Crichton
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
Alex Crichton
752ad99cbd Update contributing docs for js-sys
Tweak a few links here and there and otherwise mention that we should be
complete and stage 4 proposals can be added in the future

Closes #859
2018-09-24 10:51:05 -07:00
Alex Crichton
d10ca579e4 Yarn is no longer needed for tests 2018-09-24 10:44:14 -07:00