Commit Graph

198 Commits

Author SHA1 Message Date
noelyoo
f3ec734310 docs: update docs link 2019-05-26 16:43:00 +09:00
Nick Fitzgerald
2a896dbeb3 Also mention that serde-wasm-bindgen supports more types than JSON does 2019-05-23 14:14:21 -07:00
Nick Fitzgerald
90f1866ddd Add note to the guide about serde-wasm-bindgen 2019-05-22 09:39:08 -07:00
lzubiaur
c043a952a2 Fix closure example compilation errors 2019-05-20 16:40:22 +09:00
Delet0r
cb691100f1
corretected unit of UTF-16 from byte to bit 2019-05-08 15:03:34 +02:00
Alex Crichton
3031c15bf6 Rewrite docs for getters/setters 2019-04-30 10:06:38 -07:00
Caio
470eea9fb0 Getters/Setters for fields 2019-04-30 10:26:03 -03:00
Dimitrii Nemkov
735b1a1aa8
guide: fixed typo in js-objects-in.rust.md 2019-04-21 09:44:24 +05:00
alexlapa
8b6dabcb5c add wasm_bindgen(skip) to reference 2019-04-14 23:49:24 +03:00
Alex Crichton
16745edf3f
Merge pull request #1416 from alexcrichton/js-string-valid-utf16
Add warnings about UTF-16 vs UTF-8 strings
2019-04-05 10:12:32 -05:00
Alex Crichton
44738e049a Add warnings about UTF-16 vs UTF-8 strings
This commit aims to address #1348 via a number of strategies:

* Documentation is updated to warn about UTF-16 vs UTF-8 problems
  between JS and Rust. Notably documenting that `as_string` and handling
  of arguments is lossy when there are lone surrogates.

* A `JsString::is_valid_utf16` method was added to test whether
  `as_string` is lossless or not.

The intention is that most default behavior of `wasm-bindgen` will
remain, but where necessary bindings will use `JsString` instead of
`str`/`String` and will manually check for `is_valid_utf16` as
necessary. It's also hypothesized that this is relatively rare and not
too performance critical, so an optimized intrinsic for `is_valid_utf16`
is not yet provided.

Closes #1348
2019-04-05 08:11:50 -07:00
Caio
a9ad9a96db Update CONTRIBUTING to inform about code formatting 2019-04-05 09:41:00 -03:00
Alex Crichton
05fbbb2b92
Merge pull request #1358 from stevebob/book-linkcheck-pr
Installing and running the linkcheck mdbook backend
2019-03-27 08:04:49 -04:00
Alex Crichton
c5d2b2d1fb
Merge pull request #1359 from konstin/reexporting_in_2018
Allow reexporting proc macro output in the 2018 edition
2019-03-26 10:08:46 -05:00
Alex Crichton
faf49c7d56 Reorganize the import_js example 2019-03-25 13:49:29 -07:00
Alex Crichton
80899abf84
Merge pull request #1378 from alexcrichton/doc-tweaks
Clarify some introductory docs
2019-03-21 16:54:45 -05:00
Alex Crichton
995be7c027 Replace target flags with --target
This commit deprecates the `--web`, `--no-modules`, and `--nodejs` flags
in favor of one `--target` flag. The motivation for this commit is to be
consistent between `wasm-bindgen` and `wasm-pack` so documentation for
one is applicable for the other (so we don't have to document everywhere
what the translation is between flags). Additionally this should make it
a bit easier to add new targets (if necessary) in the future as it won't
add to the proliferation of flags.

For now the old flags (like `--web`) continue to be accepted, but
they'll be removed during the next set of breaking changes for
`wasm-bindgen`.
2019-03-21 14:00:33 -07:00
Nick Fitzgerald
1e98f6b0dd Use wasm-pack build --target web for without-a-bundler example 2019-03-21 13:55:25 -07:00
Alex Crichton
e39b5c1121 Clarify some introductory docs
* Note that after the game of life tutorial there's also wasm-pack tutorials
* Ensure that the hello world example is clear that webpack isn't
  required inline in addition to the text on other pages.
2019-03-21 08:44:53 -07:00
konstin
42c1cdd8bf
Merge branch 'master' into reexporting_in_2018 2019-03-18 21:38:18 +01:00
konstin
69bbf597af Allow reexporting proc macro output in the 2018 edition
Trying to use a proc macro from a 2018 edition crate in a 2018 edition crate that reexports wasm bindgen's output failed before this commit with "could not find `wasm_bindgen` in `{{root}}`".

This commit was made with 

rg " ::wasm_bindgen::" --files-with-matches | xargs sed -i 's/::wasm_bindgen::/wasm_bindgen::/g'
2019-03-18 10:43:48 +01:00
Stephen Sherratt
47f3247a0e Installing and running the linkcheck mdbook backend 2019-03-16 17:42:15 +00:00
Alex Crichton
0d592fffb0 Add a raw_module attribute to #[wasm_bindgen]
This allows subverting the checks and resolution performed by the
`module` attribute added as part of [RFC 6] and has been discussed in #1343.

Closes #1343

[RFC 6]: https://github.com/rustwasm/rfcs/pull/6
2019-03-15 08:08:09 -07:00
Alex Crichton
8db85dddde Update a few links here and there with doc restructuring 2019-03-08 05:58:22 -08:00
Alex Crichton
a7e7f8b5e1
Merge pull request #1328 from alexcrichton/switch-to-web
Switch the `--browser` argument to `--web`
2019-03-07 15:25:26 -06:00
Nick Fitzgerald
fcafd03dcd
Update guide/src/contributing/index.md
Co-Authored-By: alexcrichton <alex@alexcrichton.com>
2019-03-07 15:17:17 -06:00
Alex Crichton
cd3781cb73 Switch the --browser argument to --web
This commit reverts part of the implementation of [RFC 6]. That RFC
specified that the `--browser` flag was going to be repurposed for the
new "natively loadable as ES module output", but unfortunately the
breakage is far broader than initially expected. It turns out that
`wasm-pack` passes `--browser` by default which means that a change to
break `--browser` would break all historical versions of `wasm-pack`
which is a bit much for now.

To solve this the `--browser` flag is going back to what it represents
on the current released version of `wasm-bindgen` (optimize away some
node.js checks in a few places for bundler-style output) and a new
`--web` flag is being introduced as the new deployment strategy.

[RFC 6]: https://github.com/rustwasm/rfcs/pull/6

Closes #1318
2019-03-07 08:26:36 -08:00
Alex Crichton
96f4c8aa63 Add a "nightly only" warning to documentation
Official documentation is now available at
https://rustwasm.github.io/docs/wasm-bindgen/, so let's leave this git
repository's documentation purely for our own previewing purposes.
2019-03-07 07:48:26 -08:00
Alex Crichton
b762948456 Implement the local JS snippets RFC
This commit is an implementation of [RFC 6] which enables crates to
inline local JS snippets into the final output artifact of
`wasm-bindgen`. This is accompanied with a few minor breaking changes
which are intended to be relatively minor in practice:

* The `module` attribute disallows paths starting with `./` and `../`.
  It requires paths starting with `/` to actually exist on the filesystem.
* The `--browser` flag no longer emits bundler-compatible code, but
  rather emits an ES module that can be natively loaded into a browser.

Otherwise be sure to check out [the RFC][RFC 6] for more details, and
otherwise this should implement at least the MVP version of the RFC!
Notably at this time JS snippets with `--nodejs` or `--no-modules` are
not supported and will unconditionally generate an error.

[RFC 6]: https://github.com/rustwasm/rfcs/pull/6

Closes #1311
2019-03-05 08:00:47 -08:00
Tyler Anton
c40f4d05b5 Fix typo in Js Objects in Rust 2019-02-24 17:13:24 -08:00
limira
de3c852c21
[guide] Minor fix 2019-02-23 15:06:16 +07:00
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