Commit Graph

2777 Commits

Author SHA1 Message Date
433a8d8df9 Merge pull request #1391 from RReverser/node-pass-string
Add specialised passStringToWasm for Node.js
2019-03-25 13:17:38 -05:00
12011f4537 Add specialised passStringToWasm for Node.js
Node.js doesn't currently implement `TextEncoder::encodeInto`. I've raised an upstream issue to add it - https://github.com/nodejs/node/issues/26904 - but it's likely to take some time and will be available only in new releases.

In the meanwhile, it's worth noting that Node.js already has `Buffer::write` which has pretty similar semantics, but doesn't require creating an intermediate view using `.subarray` and instead accepts pointer and length directly.

Also, Node.js has `Buffer::byteLength` helper which allows to efficiently retrieve an encoded byte length of a string upfront, and so allows us to avoid a loop with reallocations.

This change takes leverage of these methods by generating an additional Buffer-based view into the WASM memory and using it for string operations.

I'm seeing up to 35% increase in performance in string-heavy library benchmarks.
2019-03-25 17:42:16 +00:00
362777fc75 Start implementing a test suite for the CLI
We have very few tests today so this starts to add the basics of a test
suite which compiles Cargo projects on-the-fly which will hopefully help
us bolster the amount of assertions we can make about the output.
2019-03-22 11:32:03 -07:00
6edb40a807 Implement transitive support for NPM dependencies
This commit implements [RFC 8], which enables transitive and transparent
dependencies on NPM. The `module` attribute, when seen and not part of a
local JS snippet, triggers detection of a `package.json` next to
`Cargo.toml`. If found it will cause the `wasm-bindgen` CLI tool to load
and parse the `package.json` within each crate and then create a merged
`package.json` at the end.

[RFC 8]: https://github.com/rustwasm/rfcs/pull/8
2019-03-22 09:42:40 -07:00
6522968fb6 Switch UI tests to beta toolchain
Should ideally help reduce breakage!
2019-03-22 07:27:49 -07:00
0631182b68 Enable the stable feature of compiletest_rs
Should fix CI!
2019-03-22 07:26:23 -07:00
7392df8a39 Merge pull request #1381 from alexcrichton/bump
Bump to 0.2.40
0.2.40
2019-03-21 19:09:16 -05:00
6803c619bb Bump to 0.2.40 2019-03-21 17:08:48 -07:00
a8c5fa4a2a Merge pull request #1385 from alexcrichton/fix-uaf
Fix use-after-free with closures in JS bindings
2019-03-21 19:05:24 -05:00
6c62d54ad9 Update crates/cli-support/src/js/closures.rs
Co-Authored-By: alexcrichton <alex@alexcrichton.com>
2019-03-21 19:05:15 -05:00
407bc5dfbb Update crates/cli-support/src/js/closures.rs
Co-Authored-By: alexcrichton <alex@alexcrichton.com>
2019-03-21 19:05:10 -05:00
1a7b3d56bd Merge pull request #1384 from rustwasm/cloudflare-workers
feat(js): add check to no_modules gen js for cloudflare workers
2019-03-21 19:04:53 -05:00
3e814a6824 feat(js): add check to no_modules gen js for cloudflare workers 2019-03-21 18:10:20 -05:00
2ff2e2505a Fix use-after-free with closures in JS bindings
This commit fixes an erroneous use-after-free which can happen in
erroneous situations in JS. It's intended that if you invoke a closure
after its environment has been destroyed that you'll immediately get an
error from Rust saying so. The JS binding generation for mutable
closures, however, accidentally did not protect against this.

Each closure has an internal reference count which is incremented while
being invoked and decremented when the invocation finishes and also when
the `Closure` in Rust is dropped. That means there's two branches where
the reference count reaches zero and the internal pointer stored in JS
needs to be set to zero. Only one, however, actually set the pointer to
zero!

This means that if a closure was destroyed while it was being invoked it
would not correctly set its internal pointer to zero. A further
invocation of the closure would then pass as seemingly valid pointer
into Rust, causing a use-after-free.

A test isn't included here specifically for this because our CI has
started failing left-and-right over this test, so this commit will
hopefully just make our CI green!
2019-03-21 15:57:08 -07:00
b8e9a20d8f Merge pull request #1377 from alexcrichton/fix-dupe
Move `links` annotation to `wasm-bindgen-shared`
2019-03-21 16:58:53 -05:00
c9a972ac55 Merge pull request #1376 from alexcrichton/more-debugging
Add some logging useful in debugging #1373
2019-03-21 16:55:04 -05:00
a4736682d5 Merge pull request #1383 from alexcrichton/deterministic
Fix a nondeterministic bug in the JS wrapper emitted
2019-03-21 16:54:53 -05:00
80899abf84 Merge pull request #1378 from alexcrichton/doc-tweaks
Clarify some introductory docs
2019-03-21 16:54:45 -05:00
a5a600192a Fix a nondeterministic bug in the JS wrapper emitted
We've always wanted this to be the deterministic, but usage of `HashMap`
for example can accidentally lead to non-determinism. Looks like one was
forgotten and the bindings were nondeterministic by accident as a
result!
2019-03-21 14:37:44 -07:00
629a19b8de Bring back accidentally deleted raytrace build script 2019-03-21 14:32:27 -07:00
0e864a4855 Merge pull request #1369 from alexcrichton/targets
Replace target flags with `--target`
2019-03-21 16:06:42 -05:00
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
93cab3d755 Merge pull request #1382 from fitzgen/wasm-pack-web-target
Use `wasm-pack build --target web` for without-a-bundler example
2019-03-21 15:57:12 -05:00
1e98f6b0dd Use wasm-pack build --target web for without-a-bundler example 2019-03-21 13:55:25 -07:00
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
7b6731fd3b Move links annotation to wasm-bindgen-shared
This commit moves our `links` annotation in the `wasm-bindgen` crate to
the `wasm-bindgen-shared` crate. The `links` annotation is used to
ensure that there's only one version of `wasm-bindgen` in a crate graph
because if there are multiple versions then a CLI surely cannot actually
process the wasm binary (as the multiple versions likely have different
formats in their custom sections).

Discovered in #1373 it looks like the usage in `wasm-bindgen` isn't
quite sufficient to cause this deduplication. It turns out that
`wasm-bindgen-shared`, a very core dependency, is actually the most
critical to be deduplicated since its the one that defines the format of
the custom section. In #1373 a case came up where `wasm-bindgen` was
deduplciated but there were two versions of `wasm-bindgen-shared` in the
crate graph, meaning that a `[patch]` for only `wasm-bindgen` wasn't
sufficient, but rather `web-sys` and/or `js-sys` also needed a `[patch]`
annotation to ensure everyone used the right dependencies.

This commit won't actually fix #1373 to the point where it "just works",
but what it does do is present a better error message than an internal
panic of `wasm-bindgen`. The hope is that by moving the `links`
annotation we can catch more errors of this crate graph duplication,
leading to more `[patch]` annotations locally.

Closes #1373
2019-03-21 08:35:27 -07:00
12355ce81c Add some logging useful in debugging #1373
Ended up helping diagnose the problem in the end!
2019-03-21 08:30:30 -07:00
d49d8c9e1b Merge pull request #1372 from RReverser/fix-dataview-docs
Fix docs for DataView::get*int32*
2019-03-20 13:47:10 -05:00
3f86c9429f Merge pull request #1371 from RReverser/merge-typed-arrays
Merge TypedArray definitions into a macro
2019-03-20 13:46:12 -05:00
4e806bab70 Fix docs for DataView::get*int32* 2019-03-20 18:32:34 +00:00
c5260f29aa Merge TypedArray definitions into a macro 2019-03-20 17:25:35 +00:00
42c1cdd8bf Merge branch 'master' into reexporting_in_2018 2019-03-18 21:38:18 +01:00
2177dee9e4 Merge pull request #1353 from alexcrichton/raw-module
Add a `raw_module` attribute to `#[wasm_bindgen]`
2019-03-18 12:48:14 -05:00
ae47665b4d Merge pull request #1356 from c410-f3r/ts-tests
Improve TS tests
2019-03-18 10:10:21 -05:00
b89fefde29 Merge pull request #1346 from rustwasm/dependabot/npm_and_yarn/@wasm-tool/wasm-pack-plugin-0.2.7
Update @wasm-tool/wasm-pack-plugin requirement from 0.2.5 to 0.2.7
2019-03-18 10:09:12 -05:00
8cc9374904 Merge pull request #1350 from alexlapa/enable-rtc-rtp-transceiver
Enable OptionIntoWasmAbi and OptionFromWasmAbi for ast::ImportEnum, RTCRtpTransceiver.webidl
2019-03-18 10:08:59 -05:00
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
47f3247a0e Installing and running the linkcheck mdbook backend 2019-03-16 17:42:15 +00:00
dc50a5ab58 Improve TS tests 2019-03-15 22:15:04 -03:00
4e32b5e430 add read_optional_enum_attribute to webidl-tests/enums 2019-03-15 14:27:18 -06:00
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
9e74085f4b Merge pull request #1351 from konradsz/number_slices_guide
Import correct functions
2019-03-15 09:34:57 -05:00
185c2b66fa Import correct functions 2019-03-14 23:28:18 +01:00
1014bdb5df Merge remote-tracking branch 'upstream/master' into enable-rtc-rtp-transceiver 2019-03-14 13:24:24 -06:00
e6c42d4155 fix 2019-03-14 12:50:50 -06:00
d5a9208b49 Merge pull request #1344 from c410-f3r/arg-names
Preserve argument names
2019-03-14 13:45:52 -05:00
bf273a2035 fix 2019-03-14 12:30:08 -06:00
9178231b60 impl OptionFromWasmAbi and OptionIntoWasmAbi for ImportEnum, enable RTCRtpTransceiver.webidl, add add rtc_rtp_transceiver_direction test 2019-03-14 12:15:02 -06:00
91ea972c03 Take &str instead of String in argument fn 2019-03-14 12:21:41 -03:00
59c1b2a565 Merge branch 'master' into arg-names 2019-03-14 09:30:14 -03:00