Commit Graph

395 Commits

Author SHA1 Message Date
ibaryshnikov
805738608d expose forget to wasm 2019-05-19 14:42:53 +03:00
Nick Fitzgerald
d422436487 Update dependencies and use new walrus custom sections APIs 2019-05-17 14:58:50 -07:00
Alex Crichton
773c6ff430 Bump to 0.2.44 2019-05-16 07:47:23 -07:00
Alex Crichton
827810fa1b
Merge pull request #1483 from dbrgn/typescript-optional-args
Fix optional arguments in TypeScript
2019-05-14 12:39:35 -05:00
Ingvar Stepanyan
716ed0d891 Hotfix for double encodeInto call
This was a regression introduced in the last commit of https://github.com/rustwasm/wasm-bindgen/pull/1470, which might make Unicode strings 2x slower to pass.
2019-05-14 14:14:34 +01:00
Alex Crichton
15defcfd3a Add a debug assert and more tests 2019-05-13 08:12:32 -07:00
Ingvar Stepanyan
0c681ee2ba Fix offset to arg comparison 2019-05-10 15:31:59 +01:00
Ingvar Stepanyan
7418cec613 Reduce reallocation sizes 2019-05-10 14:44:49 +01:00
Ingvar Stepanyan
57b1a57c5e Speed up passing ASCII-only strings to WASM
Some speed up numbers from my string-heavy WASM benchmarks:
 - Firefox + encodeInto: +45%
 - Chrome + encodeInto: +80%
 - Firefox + encode: +29%
 - Chrome + encode: +62%

Note that this helps specifically with case of lots of small ASCII strings, in case of large strings there is no measurable difference in either direction.
2019-05-10 14:40:59 +01:00
Nick Fitzgerald
befefe0da6
Merge pull request #1521 from fitzgen/anyref-heap-live-count
Utility for counting the number of live JsValues in the wasm-bindgen heap
2019-05-09 16:22:06 -07:00
Nick Fitzgerald
450c9234ad Add the anyref_heap_live_count function
This is useful for debugging and writing tests that assert various operations do
not leak `JsValue`s.
2019-05-09 15:57:21 -07:00
Chris Trevino
2850cfc78e update init function export 2019-05-09 11:01:45 -07:00
Danilo Bargen
d9c559f2ca fixup! Fix optional arguments in TypeScript
Apply feedback about omittable and non-omittable arguments. Thanks
@rhysd!
2019-05-09 18:22:47 +02:00
Danilo Bargen
2384af21c1 Fix optional arguments in TypeScript 2019-05-09 18:09:29 +02:00
Alex Crichton
a7b85362ce
Merge pull request #1506 from alexcrichton/fix-same-name
Fix importing and exporting the same name
2019-05-03 11:29:44 -05:00
Alex Crichton
3d43d6e5e8 Fix importing and exporting the same name
Run exports through the same identifier generation as imports to ensure
that everything gets a unique identifier and then just make sure all the
appropriate wires are hooked up when dealing with exports and imports.

Closes #1496
2019-05-03 07:15:20 -07:00
Alex Crichton
5a017c1e22 Update walrus dependency 2019-05-03 07:12:28 -07:00
Alex Crichton
358ee18ab2
Merge pull request #1466 from fitzgen/log-stacks
Log stacks of imported JS functions that throw but aren't marked `catch`
2019-05-01 16:51:50 -05:00
Alex Crichton
22eb34d9ab Fix direct imports in --target web
Currently the import object constructed for the `--target web` output
only ever includes the current module as an one of the modules included.
With `wasm-bindgen`'s optimization to import directly from modules,
however, it's possible to have more modules imported from in the
generated wasm file. This commit ensures that the imports are hooked up
in the `--target web` es6 emulation mode, ensuring there aren't
extraneous errors about import objects.
2019-05-01 13:53:59 -07:00
Alex Crichton
578d59ebc0
Merge pull request #1440 from c410-f3r/getters
Getters/Setters for fields
2019-04-30 12:07:34 -05:00
Caio
470eea9fb0 Getters/Setters for fields 2019-04-30 10:26:03 -03:00
Alex Crichton
f2429be07f Bump to 0.2.43 2019-04-29 08:28:41 -07:00
Alex Crichton
21205eccf2 Add missing expose_wasm_vector_len
Found through some testing I did awhile back!
2019-04-25 19:21:13 -07:00
Alex Crichton
7decb133f0
Merge pull request #1472 from c410-f3r/ts-methods
TS: Add docs for methods
2019-04-18 09:07:33 -07:00
Caio
59fd11b31c TS: Add docs for methods 2019-04-17 18:41:20 -03:00
Nick Fitzgerald
805aaa2273 Log stacks of imported JS functions that throw but are not marked catch
Particularly useful in our tests, where we don't have the regular console
logging with post-facto object inspection, and instead need to provide all this
info up front.
2019-04-17 13:16:48 -07:00
Alex Crichton
ff1addbbaa Run cargo fmt 2019-04-16 10:52:27 -07:00
Alex Crichton
df6e15e3ab Bump to 0.2.42 2019-04-11 07:39:45 -07:00
Alex Crichton
3906e4066d Fix a bug using encodeInto truncating strings
The last write accidentally wasn't accounted for in the returned length
of the string and we unfortunately don't have any test coverage of
`encodeInto` since it requires Firefox nightly right now (and doesn't
work in Node yet).

Closes #1436
2019-04-11 07:25:27 -07:00
Alex Crichton
02394724ea Bump to 0.2.41 2019-04-10 10:53:32 -07:00
Alex Crichton
7e5e401076 Add an accessor for the function table
This commit adds an intrinsics to the `wasm_bindgen` crate which
accesses the `WebAssembly.Table` which is the function table of the
module. Eventually the thinking is that a module would import its own
function table via native wasm functionality (via `anyref` and such),
but until that's implemented let's add a binding for it ourselves!

Closes #1427
2019-04-08 10:40:46 -07:00
Nick Fitzgerald
dff9b9b1e3 Don't put anything before ES module imports
Because of some incorrect use of `js.push_str(..)`, we could sometimes emit code
before the ES modules imports, which is syntactically invalid:

    const __exports = {};
    import { Thing } from '...'; // Syntax error!

This has been fixed by making sure that the correct `imports` or `imports_post`
string is built up. We now also assert that the `js` string is empty at the
location where we add imports if we're using ES modules.
2019-04-04 15:53:43 -07:00
Alex Crichton
e3473f5e9e Fix instantiation with a Module
This commit fixes the `init` function when passed a
`WebAssembly.Module`. Upon closer reading of the [spec] we see there's
two possible return values from `WebAssembly.instantiate`. If passed a
`Module`, it will return only the `Instance`. If passed a buffer source,
though, it'll return an object with the module/instance.

The fix here is to check the result value is an `Instance`, and if so
assume the input must have been a module so it's paired up in the
output.

Closes #1418

[spec]: http://webassembly.github.io/spec/js-api/index.html#webassembly-namespace
2019-04-02 14:19:24 -07:00
Alex Crichton
fa674df109
Merge pull request #1412 from c410-f3r/init-ts
Add TS type for init fn
2019-04-02 15:46:34 -05:00
Caio
b6317e3f24 Add TS type for init fn 2019-04-01 19:45:53 -03:00
Ingvar Stepanyan
2f28b8b80e Optimise encodeInto reallocations
Instead of doubling the size on each iteration, use precise upper limit (3 * JS length) if the string turned out not to be ASCII-only. This results in maximum of 1 reallocation instead of O(log N).

Some dummy examples of what this would change:
 - 1000 of ASCII chars: no change, allocates 1000 bytes and bails out.
 - 1000 ASCII chars + 1 '😃': before allocated 1000 bytes and reallocated to 2000; now allocates 1000 bytes and reallocates to 1006.
 - 1000 of '😃' chars: before allocated 1000 bytes, reallocated to 2000, finally reallocated again to 4000; now allocates 1000 bytes and reallocates to 4000 right away.

Related issue: #1313
2019-04-01 13:08:08 +01:00
Alex Crichton
0160f6af45 Fix handling of u32 between Rust and JS
All numbers in WebAssembly are signed and then each operation on them
may optionally have an unsigned version. This means that when we pass
large signed numbers to JS they actually show up as large negative
numbers even though JS numbers can faithfully represent the type.

This is fixed by adding `>>>0` in a few locations in the generated
bindings to coerce the JS value into an unsigned value.

Closes #1388
2019-03-27 13:37:14 -07:00
Ingvar Stepanyan
a5f5c7a9e8 Consistently expose is_like_none
Aside from visual deduplication, this actually fixes a bug in js2rust.rs where it didn't call `expose_is_like_none` but used `isLikeNone` inside of `arg.get_64()` branch.
2019-03-26 18:53:55 +00:00
Alex Crichton
72672ff42a
Merge pull request #1397 from RReverser/option-char-abi
Simplify ABI for Option<char>
2019-03-26 13:50:59 -05:00
Ingvar Stepanyan
5f742ca4c4 Simplify ABI for Option<char>
Flatten None to a special u32 value instead of using an intermediate pointer.
2019-03-26 18:12:24 +00:00
Alex Crichton
a6fe0cefa8 Migrate all crates to the 2018 edition
Most of the CLI crates were already in the 2018 edition, and it turns
out that one of the macro crates was already in the 2018 edition so we
may as well move everything to the 2018 edition!

Always nice to remove those `extern crate` statements nowadays!

This commit also does a `cargo fmt --all` to make sure we're conforming
with style again.
2019-03-26 08:10:53 -07:00
Alex Crichton
b4b3926bb8
Merge pull request #1305 from alexcrichton/npm-dependencies
Implement transitive support for NPM dependencies
2019-03-25 16:03:02 -05:00
Ingvar Stepanyan
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
Alex Crichton
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
Alex Crichton
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
Alex Crichton
6803c619bb Bump to 0.2.40 2019-03-21 17:08:48 -07:00
Alex Crichton
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
Nick Fitzgerald
6c62d54ad9
Update crates/cli-support/src/js/closures.rs
Co-Authored-By: alexcrichton <alex@alexcrichton.com>
2019-03-21 19:05:15 -05:00
Nick Fitzgerald
407bc5dfbb
Update crates/cli-support/src/js/closures.rs
Co-Authored-By: alexcrichton <alex@alexcrichton.com>
2019-03-21 19:05:10 -05:00
Alex Crichton
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