Commit Graph

2564 Commits

Author SHA1 Message Date
Alex Crichton
d75ae42d4f
Merge pull request #1425 from c410-f3r/rustfmt
Update CONTRIBUTING to inform about code formatting
2019-04-05 08:25:45 -05:00
Caio
a9ad9a96db Update CONTRIBUTING to inform about code formatting 2019-04-05 09:41:00 -03:00
Alex Crichton
aa0aff674c
Merge pull request #1424 from fitzgen/fix-imports
Don't put anything before ES module imports
2019-04-04 20:27:37 -05: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
863a8b9cea
Merge pull request #1423 from alexcrichton/fix
Fix imported usage of `wasm_bindgen` macro
2019-04-04 13:42:20 -05:00
Alex Crichton
f48fdec21e Fix imported usage of wasm_bindgen macro
Make sure it refers to `__wasm_bindgen_class_marker` via an absolute
path!

Closes #1422
2019-04-04 09:56:16 -07:00
Alex Crichton
76a03adfa6
Merge pull request #1419 from alexcrichton/init-is-hard
Fix instantiation with a `Module`
2019-04-02 16:41:34 -05: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
Alex Crichton
a1c457bd15
Merge pull request #1414 from RReverser/smaller-realloc
Optimise encodeInto reallocations
2019-04-02 10:26:03 -05:00
Nick Fitzgerald
f367a4247b
Merge pull request #1417 from alexcrichton/closure-ref
Support 1-reference argument closures
2019-04-01 16:21:54 -07:00
Caio
b6317e3f24 Add TS type for init fn 2019-04-01 19:45:53 -03:00
Alex Crichton
d48f4995e5 Support 1-reference argument closures
This is work towards #1399, although it's just for one-argument closures
where the first argument is a reference. No other closures with
references in argument position are supported yet
2019-04-01 14:31:21 -07: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
alexlapa
1dcf468c9d add wasm_bindgen(skip) attr to disable getters and setters exposure of pub fields 2019-03-30 05:09:02 +02:00
Alex Crichton
c5f18b6099
Merge pull request #1408 from samcday/impl-debug-on-closure
Implement Debug on Closures
2019-03-29 07:32:11 -05:00
Sam Day
1914bba0be Implement Debug on Closures
resolves #1387
2019-03-29 09:07:48 +01:00
Alex Crichton
1121393203
Merge pull request #1403 from RReverser/expose-constructor
Add `constructor` property to `Object`
2019-03-28 10:55:22 -03:00
Alex Crichton
30b258515d
Merge pull request #1401 from alexcrichton/fix-u32
Fix handling of `u32` between Rust and JS
2019-03-27 17:38:00 -03: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
db17e9d2a7 Add constructor property to Object 2019-03-27 14:25:55 +00:00
Alex Crichton
98e554c1fa
Merge pull request #1402 from samcday/patch-1
Quick typo fix in closure.rs
2019-03-27 08:08:04 -04: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
Sam
ea01043e9a
Quick type fix in closure.rs 2019-03-27 13:03:50 +01:00
Stephen Sherratt
3c12e13c04 Use rust template in mdbook test 2019-03-27 07:38:35 +00:00
Alex Crichton
e3aabcb27d
Merge pull request #1398 from RReverser/is-like-none
Consistently expose `is_like_none`
2019-03-26 14:29:46 -05: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
Nick Fitzgerald
5ae6de5e9e
Merge pull request #1395 from alexcrichton/e2018
Migrate all crates to the 2018 edition
2019-03-26 10:59:16 -07:00
Alex Crichton
778e497186 Generate r#async method names in web-sys
This is a new keyword in the 2018 edition!
2019-03-26 08:51:46 -07: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
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
e43963fd42
Merge pull request #1393 from RReverser/faster-try-iter
Remove string allocation from try_iter
2019-03-26 09:28:39 -05:00
Ingvar Stepanyan
11bb8f03c2 Remove string allocation from try_iter
This allows to significantly speed up iteration over small collections, where string encoding is the primary overhead.

Related to #1386, but works around only this partial case.
2019-03-26 12:22:54 +00: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
Alex Crichton
faf49c7d56 Reorganize the import_js example 2019-03-25 13:49:29 -07:00
Alex Crichton
433a8d8df9
Merge pull request #1391 from RReverser/node-pass-string
Add specialised passStringToWasm for Node.js
2019-03-25 13:17:38 -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
6522968fb6 Switch UI tests to beta toolchain
Should ideally help reduce breakage!
2019-03-22 07:27:49 -07:00
Alex Crichton
0631182b68 Enable the stable feature of compiletest_rs
Should fix CI!
2019-03-22 07:26:23 -07:00
Alex Crichton
7392df8a39
Merge pull request #1381 from alexcrichton/bump
Bump to 0.2.40
2019-03-21 19:09:16 -05: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
Ashley Williams
3e814a6824 feat(js): add check to no_modules gen js for cloudflare workers 2019-03-21 18:10:20 -05:00