Commit Graph

1444 Commits

Author SHA1 Message Date
Alex Crichton
18746ecf4a
Merge pull request #1461 from alexcrichton/rustfmt-web-sys
Format web-sys bindings by default
2019-04-15 12:36:28 -05:00
Alex Crichton
3ab9bb192a
Merge pull request #1449 from alexcrichton/no-interface-objects
Support [NoInterfaceObject] in `web-sys`
2019-04-15 12:36:14 -05:00
Alex Crichton
01a52233d3 Support [NoInterfaceObject] in web-sys
This commit enables `[NoInterfaceObject]` annotated interfaces in
`web-sys`. The `NoInterfaceObject` attribute means that there's not
actually a JS class for the object, but all of its properties and such
can still be accessed structually and invoked. This should help provide
more bindings for some more common types on the web!

Note that this builds on recent features to ensure that `dyn_into` and
friends always fail for `NoInterfaceObject` objects because they don't
actually have a class.

Closes #893
Closes #1257
Closes #1315
2019-04-15 10:36:01 -07:00
Alex Crichton
fd4f0b6508 Format web-sys bindings by default
This commit switches to executing `rustfmt` by default on
`web-sys`-generated bindings. This improves situations like "view
source" in Rustdoc as well as the IDE interactive debugging experience.

This was initially disabled by default because `rustfmt` took so long to
execute, but nowadays `web-sys` is by default much smaller so there's
much less need to avoid running `rustfmt` in fear of it taking too
long.

Closes #1457
2019-04-15 08:33:02 -07:00
Alex Crichton
526b253b47
Merge pull request #1451 from RReverser/more-static-namespaces
Transform Math, Reflect and JSON into static namespaces
2019-04-15 09:41:40 -05:00
Alex Crichton
7ee4906661
Merge pull request #1410 from alexlapa/add-wasm-bindgen-skip-attr
Add wasm_bindgen(skip) attribute
2019-04-15 09:31:01 -05:00
Ingvar Stepanyan
ed45ca72da Fix more DataView documentation mistakes
I fixed few copy-paste mistakes in https://github.com/rustwasm/wasm-bindgen/pull/1372, but haven't noticed that they go even deeper :(
2019-04-15 14:31:23 +01:00
alexlapa
00c4dd9b6f Merge branch 'master' into add-wasm-bindgen-skip-attr 2019-04-14 23:43:21 +03:00
Ingvar Stepanyan
62b7d3e3c4 Transform JSON into a namespace 2019-04-13 02:22:19 +01:00
Ingvar Stepanyan
75c2971ab9 Transform Reflect into a namespace 2019-04-13 02:21:33 +01:00
Ingvar Stepanyan
fe939bc911 Transform Math into a namespace 2019-04-13 02:20:24 +01:00
Ingvar Stepanyan
2f524ee494 Leverage new is_type_of for iterator protocol
Treats any object of shape `{ next: function }` as an iterator via new `is_type_of` method. This is consistent with JavaScript iteration protocol which we already respect.

Also fixes a minor issue that `is_function` was unnecessarily called twice (once explicitly and once as part of `dyn_into` which now does the same check).
2019-04-12 20:30:41 +01:00
Alex Crichton
c4776becbb Touch up descriptions of has_type 2019-04-12 10:54:36 -07:00
Ingvar Stepanyan
cb880bdbff Add customisable is_type_of 2019-04-12 17:23:42 +01:00
Alex Crichton
ba1f67d854 Remove some unnecessary unsafe in js-sys 2019-04-12 09:02:39 -07:00
Alex Crichton
df8da56a6c Add PartialEq/Eq to many js-sys types
This commit adds `#[derive(PartialEq, Eq)]` to many types throughout
`js-sys`. These types are basically all based on `Object`, which means
that `Object.is` can be used for `PartialEq` and the `Eq` requirements
are upheld.

The macro has also been updated to internally store the deref target
instead of unconditionally storing `JsValue`, allowing `#[derive]` to
work a bit better in these situations.
2019-04-12 09:02:33 -07:00
Alex Crichton
018b9b4e09 Fix compile of js-sys 2019-04-12 08:54:23 -07:00
Alex Crichton
ba88ae8b64 Improve Boolean/Number/JsString consistency
* Ensure `PartialEq` is implemented from these types to native Rust types
* Implement `From` between these type and native Rust types
* Deprecated `Number::new` and `Boolean::new` to discourage use of the
  object forms, recommending the `from` constructors instead.

Closes #1446
2019-04-12 08:50:29 -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
Alex Crichton
e4400ac8b4 Improve error message for non-copy struct fields
Make sure the error message points to the type in question instead of to
the `#[wasm_bindgen]` macro which can be overly confusing!
2019-04-08 07:35:14 -07: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
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
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
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
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
1121393203
Merge pull request #1403 from RReverser/expose-constructor
Add `constructor` property to `Object`
2019-03-28 10:55:22 -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
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
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
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
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
0631182b68 Enable the stable feature of compiletest_rs
Should fix CI!
2019-03-22 07:26:23 -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
Ashley Williams
3e814a6824 feat(js): add check to no_modules gen js for cloudflare workers 2019-03-21 18:10:20 -05:00
Alex Crichton
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
Alex Crichton
b8e9a20d8f
Merge pull request #1377 from alexcrichton/fix-dupe
Move `links` annotation to `wasm-bindgen-shared`
2019-03-21 16:58:53 -05:00
Alex Crichton
c9a972ac55
Merge pull request #1376 from alexcrichton/more-debugging
Add some logging useful in debugging #1373
2019-03-21 16:55:04 -05:00
Alex Crichton
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
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
Alex Crichton
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
Alex Crichton
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
Alex Crichton
d49d8c9e1b
Merge pull request #1372 from RReverser/fix-dataview-docs
Fix docs for DataView::get*int32*
2019-03-20 13:47:10 -05:00
Ingvar Stepanyan
4e806bab70 Fix docs for DataView::get*int32* 2019-03-20 18:32:34 +00:00
Ingvar Stepanyan
c5260f29aa Merge TypedArray definitions into a macro 2019-03-20 17:25:35 +00:00
konstin
42c1cdd8bf
Merge branch 'master' into reexporting_in_2018 2019-03-18 21:38:18 +01:00
Alex Crichton
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
Alex Crichton
ae47665b4d
Merge pull request #1356 from c410-f3r/ts-tests
Improve TS tests
2019-03-18 10:10:21 -05: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
Caio
dc50a5ab58 Improve TS tests 2019-03-15 22:15:04 -03:00
alexlapa
4e32b5e430 add read_optional_enum_attribute to webidl-tests/enums 2019-03-15 14:27:18 -06: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
alexlapa
1014bdb5df Merge remote-tracking branch 'upstream/master' into enable-rtc-rtp-transceiver 2019-03-14 13:24:24 -06:00
alexlapa
e6c42d4155 fix 2019-03-14 12:50:50 -06:00
alexlapa
bf273a2035 fix 2019-03-14 12:30:08 -06:00
alexlapa
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
Caio
91ea972c03 Take &str instead of String in argument fn 2019-03-14 12:21:41 -03:00
Caio
59c1b2a565 Merge branch 'master' into arg-names 2019-03-14 09:30:14 -03:00
Caio
70f5373348 Preserve argument names 2019-03-14 08:46:42 -03:00
Alex Crichton
228f58dca3 Bump to 0.2.39 2019-03-13 11:02:27 -07:00
Alex Crichton
5192b95bf3 Workaround an upstream nom bug
This commit works around Geal/nom#843 where the API of the `nom` crate
changes based on feature selection, meaning we need to be compatible
even if another crate in the crate graph enables a feature.

Ideally this'd be fixed in upstream `nom`, and it looks like it will in
the next major version! For now a local catch-all directive should help
out.
2019-03-12 12:22:24 -07:00
Nathan Stoddard
03fa00d201 Make the slice argument of texImage2D and related functions immutable
This also adds immutable slice whitelisting for Uint8Array, ArrayBufferView, and BufferSource, and removes Uint8ArrayMut.
2019-03-08 15:25:52 -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
e5ec474896
Update crates/cli-support/src/js/mod.rs
Co-Authored-By: alexcrichton <alex@alexcrichton.com>
2019-03-07 15:25:20 -06:00
Alex Crichton
0b7fab4474
Merge pull request #1331 from c410-f3r/span-impls
Remove PartialEq and Eq from Function
2019-03-07 13:32:42 -06:00
Alex Crichton
f00c74aeb0
Merge pull request #1330 from Vlad-Shcherbina/mkdir_pkg
Create --out_dir (usually "pkg") if it does not exist
2019-03-07 12:08:37 -06:00
Caio
ded4fdf52d Remove PartialEq and Eq from Function 2019-03-07 15:00:55 -03:00
Vlad Shcherbina
2a2581188a Create out_dir (usually "pkg") if it does not exist 2019-03-07 19:56:57 +03: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
17bd1969b6
Merge pull request #1323 from alexcrichton/bump-walrus
Update walrus to 0.5.0
2019-03-06 22:34:28 -06:00
Alex Crichton
795bf7c6b1 Update walrus to 0.5.0 2019-03-06 15:09:20 -08:00
ibaryshnikov
fa0a3610af issue-1317-typed-array-typo-fixed 2019-03-06 22:12:48 +03:00
Alex Crichton
9f6c2a6125
Merge pull request #1314 from alexcrichton/typescript-tests
Start testing TypeScript output on CI
2019-03-05 17:20:00 -06:00
Alex Crichton
d6e3770350 Scope snippets within a crate
Use the same crate identifier for manually included snippets as well as
inline snippets to help with debugging.
2019-03-05 14:53:14 -08:00
Alex Crichton
c463cc96df Clean up the super long finalize function 2019-03-05 14:40:05 -08:00
Alex Crichton
f3f3ebee3a Remove unsafe usage in backend/src/encode.rs
Using `unsafe` was just a little too eager there so let's use an
off-the-shelf solution for solving the actual problem we have, which is
to allocate strings with a lifetime of `Interner` rather than
deduplicating strings.
2019-03-05 12:28:14 -08:00
Alex Crichton
93a1301c9f Don't explicitly hide _INCLUDED_FILES
It's already hidden from docs!
2019-03-05 12:17:42 -08:00
Alex Crichton
bdcfcb49b1 Log webdriver command we execute 2019-03-05 09:33:22 -08:00
Alex Crichton
235bc7c889 Start testing TypeScript output on CI
This commit starts to add some simple tests for our TypeScript output of
the wasm-bindgen CLI, currently just running `tsc` to make sure syntax
looks good and types are emitted as expected. This'll hopefully be able
to get expanded over time with bug reports as they come in as well as
ensure that we don't regress anything in egregious manners!

Closes #922
2019-03-05 08:57:52 -08:00
Alex Crichton
20f1e503d3 Fix the webidl-tests crate 2019-03-05 08:00:47 -08:00
Alex Crichton
5de3189411 Fix js-sys and web-sys tests 2019-03-05 08:00:47 -08:00
Alex Crichton
7e62aff1ce Fix a case where snippet is specified twice
When importing a file across multiple locations in a module make sure it
doesn't trip an assert and it works as expected.
2019-03-05 08:00:47 -08:00
Alex Crichton
6283169a30 Paths are relative to CARGO_MANIFEST_DIR
The cwd is different for workspaces, so use the manifest env var
instead.
2019-03-05 08:00:47 -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
Alex Crichton
a659f27c07 Bump to 0.2.38 2019-03-04 09:11:23 -08:00
Dan Robertson
7ad5426714
Update tests after nightly fix 2019-03-04 02:14:57 +00:00
Alex Crichton
1299a2086f
Merge pull request #1307 from alexcrichton/fix-name
Fix name of "current thread ID" intrinsic
2019-03-01 12:48:53 -06:00
Alex Crichton
dad0de4f8b Work around a nightly regression 2019-03-01 10:48:03 -08:00
Alex Crichton
1031d9dea6 Work around rust-lang/rust#58853 2019-03-01 10:47:27 -08:00
Alex Crichton
9ac8a974a9 Fix name of "current thread ID" intrinsic
This was accidentally renamed in the transition to `walrus`, but
upstream rust-lang/rust still uses the old name so let's switch back to
that.
2019-03-01 09:22:30 -08:00
Alex Crichton
233525d7d6 Fix passStringToWasm with shared memory
Looks like `TextEncoder#encodeInto` isn't compatible when the buffer
passed in is backed by a `SharedArrayBuffer`, so if the module has a
shared thread skip the `encodeInto` optimization entirely.
2019-02-28 14:58:10 -08:00
Alex Crichton
c62f6529d8
Merge pull request #1304 from alexcrichton/fix-init
Fix a `__wbindgen_placeholder__` module leaking through
2019-02-28 13:39:56 -06:00
Alex Crichton
da168dc7f5
Merge pull request #1302 from tyleranton/export-comments-ts
Add doc comments export for typescript
2019-02-28 09:34:11 -06:00
Alex Crichton
c4c0fea05e Fix a __wbindgen_placeholder__ module leaking through
With #1267 now fixed looks like we had an accidental regression sneak
through in the meantime!
2019-02-28 07:32:30 -08:00
Tyler Anton
59825c6d01 Add doc comments export for typescript 2019-02-27 20:09:28 +00:00
Alex Crichton
cb432be5df
Merge pull request #1296 from rustwasm/dependabot/cargo/scoped-tls-1.0
Update scoped-tls requirement from 0.1 to 1.0
2019-02-27 10:45:01 -06:00
Alex Crichton
46955735d9
Merge pull request #1298 from LegNeato/fix_high_sierra
Fix headless test runner on macOS High Sierra
2019-02-27 09:32:42 -06:00
Christian Legnitto
e80b0ccdc2 Fix headless test runner on macOS High Sierra 2019-02-26 21:06:45 -07:00
Alex Crichton
860612485d
Merge pull request #1279 from alexcrichton/encode-into
Add support for `TextEncoder#encodeInto`
2019-02-26 12:29:56 -06:00
Alex Crichton
745b16e3d2 Add support for TextEncoder#encodeInto
This commit adds support for the recently implemented standard of
[`TextEncoder#encodeInto`][standard]. This new function is a "bring your
own buffer" style function where we can avoid an intermediate allocation
and copy by encoding strings directly into wasm's memory.

Currently we feature-detect whether `encodeInto` exists as it is only
implemented in recent browsers and not in all browsers. Additionally
this commit emits the binding using `encodeInto` by default, but this
requires `realloc` functionality to be exposed by the wasm module.
Measured locally an empty binary which takes `&str` previously took
7.6k, but after this commit takes 8.7k due to the extra code needed for
`realloc`.

[standard]: https://encoding.spec.whatwg.org/#dom-textencoder-encodeinto

Closes #1172
2019-02-26 10:29:39 -08:00
dependabot[bot]
7eb11a7faa
Update scoped-tls requirement from 0.1 to 1.0
Updates the requirements on [scoped-tls](https://github.com/alexcrichton/scoped-tls) to permit the latest version.
- [Release notes](https://github.com/alexcrichton/scoped-tls/releases)
- [Commits](https://github.com/alexcrichton/scoped-tls/compare/0.1.0...1.0.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>
2019-02-26 08:15:14 +00:00
Alex Crichton
7fbe0210dc Rename test Context in JS
This will hopefully help avoid symbol collisions with other projects
that have a struct named `Context`
2019-02-20 09:23:00 -08:00
Alex Crichton
4181fb311a Add experimental support for the anyref type
This commit adds experimental support to `wasm-bindgen` to emit and
leverage the `anyref` native wasm type. This native type is still in a
proposal status (the reference-types proposal). The intention of
`anyref` is to be able to directly hold JS values in wasm and pass the
to imported functions, namely to empower eventual host bindings (now
renamed WebIDL bindings) integration where we can skip JS shims
altogether for many imports.

This commit doesn't actually affect wasm-bindgen's behavior at all
as-is, but rather this support requires an opt-in env var to be
configured. Once the support is stable in browsers it's intended that
this will add a CLI switch for turning on this support, eventually
defaulting it to `true` in the far future.

The basic strategy here is to take the `stack` and `slab` globals in the
generated JS glue and move them into wasm using a table. This new table
in wasm is managed at the fringes via injected shims. At
`wasm-bindgen`-time the CLI will rewrite exports and imports with shims
that actually use `anyref` if needed, performing loads/stores inside the
wasm module instead of externally in the wasm module.

This should provide a boost over what we have today, but it's not a
fantastic strategy long term. We have a more grand vision for `anyref`
being a first-class type in the language, but that's on a much longer
horizon and this is currently thought to be the best we can do in terms
of integration in the near future.

The stack/heap JS tables are combined into one wasm table. The stack
starts at the end of the table and grows down with a stack pointer (also
injected). The heap starts at the end and grows up (state managed in
linear memory). The anyref transformation here will hook up various
intrinsics in wasm-bindgen to the runtime functionality if the anyref
supoprt is enabled.

The main tricky treatment here was applied to closures, where we need JS
to use a different function pointer than the one Rust gives it to use a
JS function pointer empowered with anyref. This works by switching up a
bit how descriptors work, embedding the shims to call inside descriptors
rather than communicated at runtime. This means that we're accessing
constant values in the generated JS and we can just update the constant
value accessed.
2019-02-20 07:28:54 -08:00
Alex Crichton
8fb705a1ef Upgrade to walrus 0.4
Also be sure to have an explicit GC pass!
2019-02-19 14:14:01 -08:00
Nick Fitzgerald
5b0cfd7cea
Merge pull request #1274 from alexcrichton/delete-once
Fix an assert while deleting table elements
2019-02-19 10:21:25 -08:00
Alex Crichton
f831711f5d Support Option<RustStruct> in arguments/returns
Add all the necessary support in a few locations and we should be good
to go!

Closes #1252
2019-02-19 09:08:37 -08:00
Alex Crichton
9bab9d4af1 Fix an assert while deleting table elements
LLVM's mergefunc pass may mean that the same descriptor function is used
for different closure invocation sites even when the closure itself is
different. This typically only happens with LTO but in theory could
happen at any time!

The assert was tripping when we tried to delete the same function table
entry twice, so instead of a `Vec<usize>` of entries to delete this
commit switches to a `HashSet<usize>` which should do the deduplication
for us and enusre that we delete each descriptor only once.

Closes #1264
2019-02-19 08:17:14 -08:00
Alex Crichton
a3c03b5265 Revert "Temporarily unconditionally remove producers section"
This reverts commit f0cd51a566.
2019-02-15 11:22:46 -08:00
Alex Crichton
e9f423d57e Bump to 0.2.37 2019-02-15 08:16:24 -08:00
Alex Crichton
f0cd51a566 Temporarily unconditionally remove producers section
We've had a lot of bug reports with upstream webpack currently and while
webpack has a fix it may take a moment to deploy. Let's try and fix
wasm-bindgen in the meantime!

Once webpack is updated we can go back to emitting a producers section
by default and publish a new version of wasm-bindgen.
2019-02-15 07:39:42 -08:00
Alex Crichton
632a2b2979
Merge pull request #1259 from ctjhoa/master
Fix warning on ATOMIC_USIZE_INIT & ATOMIC_BOOL_INIT
2019-02-15 08:59:24 -06:00
Camille TJHOA
768b654b58 Fix warning on ATOMIC_USIZE_INIT & ATOMIC_BOOL_INIT 2019-02-15 11:58:48 +00:00
Alex Crichton
5e3cedfaf2 Add a flag to remove producers section
This should help handle instances like the recent Webpack bug and is
also a useful flag in its own right. For now it's set to `false`, but if
the Webpack bug persists through to tomorrow we likely want to publish a
version of `wasm-bindgen` with it default set to `true`.
2019-02-14 10:08:24 -08:00
Nick Fitzgerald
17dc79e4c5 Configure walrus to generate DWARF/names at the right times
Fixes ##1254
2019-02-14 07:20:43 -08:00
Alex Crichton
c49b87b2d8
Merge pull request #1225 from Pauan/get_index
Adding in Reflect::get_f64, Reflect::get_u32, Reflect::set_f64, and Reflect::set_u32
2019-02-13 13:10:40 -06:00
Alex Crichton
8ead8a1b62
Merge pull request #1248 from selaux/add-srcObject-to-HTMLMediaElement
[HTMLMediaElement] Reintroduce srcObject
2019-02-13 13:00:57 -06:00
Nick Fitzgerald
802cfedcbd Bump to 0.2.36 2019-02-12 13:19:02 -08:00
Nick Fitzgerald
f20afebdd1 Don't need the old wasm-bindgen-gc crate's Cargo.toml either 2019-02-12 13:16:17 -08:00
Nick Fitzgerald
6f00d9563f interpreter: handle closure descriptors with less than two parameters
This might happen because of LTO.

Fixes #1244
2019-02-12 12:57:22 -08:00
Nick Fitzgerald
d9cf9b3735 Bump to version 0.2.35 2019-02-12 11:36:19 -08:00
Alex Crichton
db4c3bf77b
Merge pull request #1243 from fitzgen/instantiateStreaming-fallback-round-2
Apply the `instantiateStreaming` incorrect MIME type recovery for no-modules
2019-02-12 12:45:46 -06:00
Nick Fitzgerald
b858875d49 Apply the instantiateStreaming incorrect MIME type recovery for no-modules
It was incorrectly only enabled for the multithreading glue previously.
2019-02-12 10:41:53 -08:00
Alex Crichton
894b479213 Migrate wasm-bindgen to using walrus
This commit moves `wasm-bindgen` the CLI tool from internally using
`parity-wasm` for wasm parsing/serialization to instead use `walrus`.
The `walrus` crate is something we've been working on recently with an
aim to replace the usage of `parity-wasm` in `wasm-bindgen` to make the
current CLI tool more maintainable as well as more future-proof.

The `walrus` crate provides a much nicer AST to work with as well as a
structured `Module`, whereas `parity-wasm` provides a very raw interface
to the wasm module which isn't really appropriate for our use case. The
many transformations and tweaks that wasm-bindgen does have a huge
amount of ad-hoc index management to carefully craft a final wasm
binary, but this is all entirely taken care for us with the `walrus`
crate.

Additionally, `wasm-bindgen` will ingest and rewrite the wasm file,
often changing the binary offsets of functions. Eventually with DWARF
debug information we'll need to be sure to preserve the debug
information throughout the transformations that `wasm-bindgen` does
today. This is practically impossible to do with the `parity-wasm`
architecture, but `walrus` was designed from the get-go to solve this
problem transparently in the `walrus` crate itself. (it doesn't today,
but this is planned work)

It is the intention that this does not end up regressing any
`wasm-bindgen` use cases, neither in functionality or in speed. As a
large change and refactoring, however, it's likely that at least
something will arise! We'll want to continue to remain vigilant to any
issues that come up with this commit.

Note that the `gc` crate has been deleted as part of this change, as the
`gc` crate is no longer necessary since `walrus` does it automatically.
Additionally the `gc` crate was one of the main problems with preserving
debug information as it often deletes wasm items!

Finally, this also starts moving crates to the 2018 edition where
necessary since `walrus` requires the 2018 edition, and in general it's
more pleasant to work within the 2018 edition!
2019-02-12 07:25:53 -08:00
Nick Fitzgerald
078257943d Bump to 0.2.34 2019-02-11 18:58:54 -08:00
Nick Fitzgerald
4975ca2954 Don't give up when servers don't set the application/wasm MIME type
It is quite annoying when using `python -m SimpleHTTPServer` or equivalent.
2019-02-10 13:59:39 -05:00
Nick Fitzgerald
c8ad85dd0b Use unwrap_throw instead of normal unwrap for JsString -> String conversion
Should have less code size.
2019-02-10 13:59:39 -05:00
T5uku5hi
5c0da8878d add #[allow(clippy::all)] in top-level items. 2019-02-09 20:20:10 +09:00
T5uku5hi
916789336c add #[allow(clippy::drop_ref)] 2019-02-09 03:47:25 +09:00
T5uku5hi
1b764103f6 Merge remote-tracking branch 'upstream/master' into add-allow-clippy 2019-02-09 03:13:16 +09:00
Nick Fitzgerald
11eeeb8fc8 Use textContent instead of innerHTML for extracting logs from headless browser tests
Easier to maintain fidelity and less likely to be sabotaged by XSS and
`<script>` tags.

Fixes #1232
2019-02-08 10:35:19 +01:00
Alex Crichton
9d27bc2e8b
Merge pull request #1199 from chinedufn/ref-slice
Whitelist for slice args that do not need to be mutable
2019-02-07 13:40:36 +01:00
Chinedu Francis Nwafili
acd69e97ee
Remove RefCell 2019-02-07 07:14:33 -05:00
Chinedu Francis Nwafili
ed28ce9db2
Clean up 2019-02-05 13:47:46 -05:00
Alex Crichton
74cd3c08f6
Merge pull request #1228 from rustwasm/dependabot/cargo/parity-wasm-0.36
Update parity-wasm requirement from 0.35 to 0.36
2019-02-05 08:28:53 +01:00
Alex Crichton
3de5253554 Remove passive segment tests for now 2019-02-04 22:24:08 -08:00
Alex Crichton
ef37986541 Update more parity-wasm 2019-02-04 22:06:10 -08:00
Nick Fitzgerald
e20c4067dc futures: Add a test for creating multiple futures from the same promise 2019-02-04 16:38:21 +01:00
dependabot[bot]
4a50d7b71c
Update parity-wasm requirement from 0.35 to 0.36
Updates the requirements on [parity-wasm](https://github.com/paritytech/parity-wasm) to permit the latest version.
- [Release notes](https://github.com/paritytech/parity-wasm/releases)
- [Commits](https://github.com/paritytech/parity-wasm/commits)

Signed-off-by: dependabot[bot] <support@dependabot.com>
2019-02-04 08:30:40 +00:00
Pauan
e4294babeb Simplifying the error handling code 2019-02-04 02:08:08 +01:00
Pauan
8b6e951e34 Adding in Reflect::get_f64, Reflect::get_u32, Reflect::set_f64, and Reflect::set_u32 2019-02-04 01:32:43 +01:00
T5uku5hi
fb8e158c9b remove unnecessary changes 2019-02-03 22:44:27 +09:00
T5uku5hi
51f7756e83 add #[allow(clippy::*)] to 901 line 2019-02-03 22:40:24 +09:00
T5uku5hi
d3a523439e comment out the all #[allow(clippy::*)] lines 2019-02-03 13:55:57 +09:00
T5uku5hi
223054811d fixed conflict 2019-02-03 13:49:42 +09:00
Alex Crichton
2e80313aa3
Merge pull request #1221 from rhysd/format-dts-file
Format .d.ts file
2019-02-01 09:24:49 -06:00
rhysd
6e2f10440e give 2 space indentations to each enum variant 2019-02-01 16:25:25 +09:00
rhysd
a1995cafd4 remove unnecessary blank lines in .d.ts file 2019-02-01 16:07:31 +09:00
rhysd
23ccd3b5c1 remove unnecessary space before function name in .d.ts file 2019-02-01 16:07:12 +09:00
rhysd
019a0863c4 give class members 2 spaces indentation in .d.ts files 2019-02-01 15:45:01 +09:00
Chinedu Francis Nwafili
965bd8c9fa
Clean up 2019-01-31 07:32:12 -05:00
Alex Crichton
9224455077 Support Option with custom enums in JS
Find a hole automatically to use a sentinel value for `None`, and then
just wire everything up!

Closes #1198
2019-01-28 14:27:57 -08:00
Alex Crichton
c35d6f4b0a Fix conditional #[wasm_bindgen] in impls
Reported in #1191 the fix requires us to get a bit creative I think. The
general gist is that a block like this:

    #[wasm_bindgen]
    impl Foo {
        pub fn foo() {}
    }

was previously expanded all in one go. Now, however, it's expanded into:

    impl Foo {
        #[__wasm_bindgen_class_marker(Foo = "Foo")]
        pub fn foo() {}
    }

    // goop generated by orginal #[wasm_bindgen]

This method of expansion takes advantage of rustc's recursive expansion
feature. It also allows us to expand `impl` blocks and allow inner items
to not be fully expanded yet, such as still having `#[cfg]` attributes
(like in the original bug report).

We use theinternal `__wasm_bindgen_class_marker` to indicate that we're
parsing an `ImplItemMethod` unconditionally, and then generation
proceeds as usual. The only final catch is that when we're expanding in
an `impl` block we have to generate tokens for the `Program`
(wasm-bindgen injected goop like the custom section) inside the body
of the function itself instead of next to it. Otherwise we'd get syntax
errors inside of impl blocks!

Closes #1191
2019-01-28 12:29:01 -08:00
Chinedu Francis Nwafili
fa1d51fe44
Comment out WebGl tests 2019-01-26 12:19:28 -05:00
Chinedu Francis Nwafili
2e6880c43c
Whitelist WebGlRenderingContext float slices 2019-01-26 12:10:08 -05:00
T5uku5hi
e19306c6a9 add #[allow(clippy::*)] in the top-level items 2019-01-25 14:44:10 +09:00
Henry
2a6d2004e1
minor typo in js-sys lib.rs 2019-01-24 15:35:21 -08:00
rhysd
3300301b3f add '| undefined' to optional types in generated .d.ts 2019-01-23 20:49:52 +09:00
Chinedu Francis Nwafili
048a22bc77 Fix idl_type swap 2019-01-22 21:35:22 -05:00
Chinedu Francis Nwafili
48b64f4cfe
Remove test file 2019-01-21 19:24:37 -05:00
Chinedu Francis Nwafili
1738f0772c
Add immutable field to IdlType::Float32Array 2019-01-21 19:18:35 -05:00
Chinedu Francis Nwafili
216b4e36ff
Rename immutable slices test 2019-01-21 16:59:02 -05:00
Chinedu Francis Nwafili
e6971cee34
Add failing immutable slice test 2019-01-21 16:59:02 -05:00
Chinedu Francis Nwafili
459639137c
Add maybe adjust function 2019-01-21 16:59:01 -05:00
Alex Crichton
78c4075e40 Bump to 0.2.33 2019-01-18 15:32:17 -08:00
Alex Crichton
ba732a8a72
Merge pull request #1161 from derekdreery/debug_output
Better output from `impl Debug for JsValue`.
2019-01-17 16:52:13 -08:00
Richard Dodd (dodj)
867b13b65e
remove array check 2019-01-17 21:07:23 +00:00
Nick Fitzgerald
d79ca22234
Merge pull request #1190 from sagan-software/issue-1186
js-sys: JSON::stringify_with_replacer[_and_space]
2019-01-16 16:38:59 -08:00
Liam Curry
6226e6959f js-sys: JSON::stringify_with_replacer[_and_space]
This commit adds two new externs for `JSON.stringify`:
`JSON::stringify_with_replacer` and
`JSON::stringify_with_replacer_and_space`.

Fixes #1186
2019-01-16 18:03:03 -05:00
Nick Fitzgerald
31fdede9fc Bump to 0.2.32 2019-01-16 13:11:13 -08:00
Richard Dodd
b0906fddba Better recognition of error type. 2019-01-16 15:36:13 +00:00
Richard Dodd
5f2ba3f98e Add better support for errors. 2019-01-16 10:46:26 +00:00
Richard Dodd
5bffc28631 Add a proper test.
And fix loads of bugs.
2019-01-16 10:16:29 +00:00
Richard Dodd
b60d82a531 Implement suggestings from @fitzgen. 2019-01-16 10:16:29 +00:00
Richard Dodd
72765757ef Fix tests again. 2019-01-16 10:16:29 +00:00
Richard Dodd
126efd5a95 Redo as js function + fix tests 2019-01-16 10:16:29 +00:00
Richard Dodd
5b51d279b4 Use toString where JSON.stringify didn't work 2019-01-16 10:16:29 +00:00
Richard Dodd
34bab511e5 Use JSON serialization to get better debug printouts. 2019-01-16 10:16:29 +00:00
Nick Fitzgerald
41eefa7425 wasm-bindgen-test: Capture more console logging methods' output
Fixes #1183
2019-01-15 14:05:22 -08:00
rhysd
8d6839878e fix missing semicolons to struct fields in .d.ts
TypeScript class property requires semicolon at the end:
    https://www.typescriptlang.org/docs/handbook/classes.html
2019-01-15 17:45:11 +09:00
Alex Crichton
715b4f4ced
Merge pull request #1179 from alexcrichton/catch-all-errors
In debug mode log all imported uncaught exceptions
2019-01-14 17:28:15 -08:00
Alex Crichton
f2f11a01a2 In debug mode log all imported uncaught exceptions
This commit updates the `--debug` output of `wasm-bindgen` from the CLI
to catch all JS exceptions from imported functions, log such, and then
rethrow. It's hoped that this can be used when necessary to learn more
information about thrown exceptions and where an uncaught exception
could be causing issues with Rust code.

Closes #1176
2019-01-14 15:59:31 -08:00
Alex Crichton
5c04427382
Merge pull request #1175 from alexcrichton/internal-consistency
Fix an issue where closure rewriting required class internals
2019-01-14 15:53:40 -08:00
Alex Crichton
20e871f676 Fix an issue where closure rewriting required class internals
Surfaced through previous sanity-checking commits, this reorders some
internal operations to...

Closes #1174
2019-01-14 15:53:29 -08:00
Alex Crichton
b21489368c Ensure internal exported_classes map is consistent
Throw it in an `Option` and then `take()` it when we consume it to
ensure that future calls to insert data into it panic instead of
producing inconsistent JS.
2019-01-14 15:53:29 -08:00
Nick Fitzgerald
f2cbbb83f3 wasm-bindgen-test: ignore example code that is not intended to compile
This was making `cargo test --all` fail.
2019-01-14 14:53:46 -08:00
Nick Fitzgerald
56c4385f42 wasm-bindgen-test: Rename console_*_redirect to on_console_*
Since we are no longer redirecting all console logs, and are instead just
observing them.
2019-01-14 14:51:28 -08:00
Nick Fitzgerald
a94f3f4403 wasm-bindgen-test: Have the test runner JS call the original console.log
This makes control flow a little easier to follow and avoids wasm->js->wasm
re-entrancy.
2019-01-14 14:51:28 -08:00
Nick Fitzgerald
51ef19b85f wasm-bindgen-test: Use spread array arguments instead of arguments objects
Our testing runtime tries to call `Array.prototype.forEach` on this object, so
it had damn well better be a proper array!

Fixes #1167
2019-01-14 14:51:28 -08:00
Alex Crichton
c0ddabcca1 Sanity check exposed_globals map
Make sure that we don't actually try to expose something when they've
already been written, causing an internal tool panic rather than wrong
JS.
2019-01-14 13:09:05 -08:00
lcnr/Bastian Kauschke
6e08f579a6 add temporary test 2019-01-14 21:04:29 +01:00
lcnr/Bastian Kauschke
4e611c318e fix spawn_local 2019-01-12 17:42:05 +01:00
Alex Crichton
12893183b6
Merge pull request #1164 from alexcrichton/fix-tests
Fix and execute wasm-bindgen-wasm-interpreter tests
2019-01-11 18:45:47 -08:00
Alex Crichton
61a6fcfced Fix and execute wasm-bindgen-wasm-interpreter tests 2019-01-11 13:20:08 -08:00
Richard Dodd
cb8bf9390d Implement webidl sequences. 2019-01-11 19:14:07 +00:00
Ryan Levick
c056235530 Simply remove the web-sys bindings 'tested' list 2019-01-10 19:06:11 +01:00
Alex Crichton
b04f60cf2b Bump to 0.2.31 2019-01-09 09:17:50 -08:00
Alex Crichton
f404182c47 Fix a typo 2019-01-07 11:00:15 -08:00
Alex Crichton
9dced1d99b
Merge pull request #1147 from alexcrichton/more-slicing
Add conversions between typed arrays and Rust
2019-01-07 12:59:38 -06:00
Alex Crichton
8b0416a0e5
Merge pull request #1155 from derekdreery/fix_dictionaries
Make dictionaries use their original text in js
2019-01-07 12:45:15 -06:00
Richard Dodd
8bc9fad103 Fix error 2019-01-07 17:40:42 +00:00
Richard Dodd
3d2efb0dff Add test to check case of field. 2019-01-07 17:09:10 +00:00
Alex Crichton
194a169c24
Merge pull request #1148 from derekdreery/spawn_local
Spawn local
2019-01-07 10:27:44 -06:00
Alex Crichton
fbf000a508 Bump to 0.2.30 2019-01-07 07:47:07 -08:00
Richard Dodd
687fc278a7 Revert previous change. 2019-01-07 14:23:10 +00:00
Richard Dodd
46d4330637 Make dictionaries use their original text in js 2019-01-07 14:15:00 +00:00
Stefan Lau
0427ede5e9 [HTMLMediaElement] Reintroduce srcObject
This was removed when mozilla specific extensions were removed. It is not
mozilla specific though and currently the only way to show webcam data in
a video element that I am aware of.
2019-01-06 17:07:43 +01:00
Richard Dodd
73913c99f2 Relax bound on Future 2019-01-05 18:10:14 +00:00
Richard Dodd
25ac4549a0 Docs 2019-01-05 14:37:39 +00:00
Richard Dodd
c849ef3cf4 Add naive spawn_local implementation + tests
This is just a naive implementation. It seems it can be improved using a
custom task queue, but that can be in a separate PR.
2019-01-05 14:34:50 +00:00
Alex Crichton
2d7f601696 Add conversions between typed arrays and Rust
For all typed arrays, this commit adds:

* `TypedArray::view(src: &[Type])`
* `TypedArray::copy_to(&self, dst: &mut [Type])`

The `view` function is unsafe because it doesn't provide any guarantees
about lifetimes or mutability. The `copy_to` function is, however, safe.

Closes #811
2019-01-04 10:42:14 -08:00
Alex Crichton
b4f172899c Fix order of export/gc
We might gc a table away so if we need to export it be sure to do so
before we gc! Additionally remove an extraneous gc that snuck in at some
point, no need to do more than one.

Closes #1130
2019-01-03 11:38:28 -08:00
Alex Crichton
47c4347955 Update UI tests 2019-01-02 08:35:05 -08:00
Daniel Barney
3858fe773f
fixing a small spelling error
I realize that this is just fixing spelling on some comments and a fairly minor correction at that.
2018-12-29 22:26:51 -07:00
Alex Crichton
9db0addb63 Update wat syntax with upstream changes 2018-12-19 15:49:05 -08:00
Alex Crichton
9237d4cf2c Flag all web-sys methods as structural
This was an intended change from #1019, but we forgot to apply it!

Closes #1095
2018-12-17 10:43:48 -08:00
Alex Crichton
ae49dd8697 Uncomment a webidl method we now support
First commented out in #568 when we didn't support this we now do!

Closes #1111
2018-12-14 13:25:35 -08:00
Alex Crichton
c6b74ffb43
Merge pull request #1106 from mvlabat/default-support
Add support for importing default exports
2018-12-11 15:48:10 -06:00
mvlabat
371e864509 Add support for importing default exports 2018-12-11 21:00:00 +02:00
dependabot[bot]
1610d199e3
Update rouille requirement from 2.1.0 to 3.0.0
Updates the requirements on [rouille](https://github.com/tomaka/rouille) to permit the latest version.
- [Release notes](https://github.com/tomaka/rouille/releases)
- [Changelog](https://github.com/tomaka/rouille/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tomaka/rouille/commits)

Signed-off-by: dependabot[bot] <support@dependabot.com>
2018-12-10 08:16:06 +00:00
DavidOConnor
a4bc5049c6 Added an --out-name param to the CLI, to allow custom output file names 2018-12-04 21:35:05 -05:00
Alex Crichton
63e3ba722d Bump to 0.2.29 2018-12-04 06:04:47 -08:00
Alex Crichton
a83c3af4bf Ensure our JS heap is a dense array
Turns out `heap.fill(undefined)` is required to ensure it's a dense
array, otherwise we'll accidentally be a sparse array and much slower
than necessary!
2018-11-30 13:23:41 -08:00
Alex Crichton
29531c0abf Run rustfmt 2018-11-30 13:04:27 -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
Alex Crichton
07b148789d Defer exposing methods until they're needed
Previously `catch` and `variadic` would exopse methods in our JS shims,
but they did so earlier than necessary. Turns out `variadic` didn't
actually need to expose anything and `catch` could do so much later!
2018-11-29 17:50:13 -08:00
Sendil Kumar N
fbad34a4cb
Merge pull request #1064 from alexcrichton/wasm2es6js-imports
wasm2es6js: Fix handling of exported imports
2018-11-30 01:01:45 +01:00
Alex Crichton
91e9495805
Merge pull request #1065 from alexcrichton/describe-closures
Move closure shims into the descriptor
2018-11-29 17:30:58 -06:00
Alex Crichton
5f966c5a8f
Merge pull request #1063 from alexcrichton/wasm2es6js-start
wasm2es6js: Fix handling of start function
2018-11-29 17:30:24 -06:00
Alex Crichton
2bd9c0eafb
Merge pull request #1067 from alexcrichton/minor-tweaks
A few minor CLI tweaks during work on #1002
2018-11-29 15:16:14 -06:00
Alex Crichton
42053ddd4e Move closure shims into the descriptor
Currently closure shims are communicated to JS at runtime, although at
runtime the same constant value is always passed to JS! More pressing,
however, work in #1002 requires knowledge of closure descriptor indices
at `wasm-bindgen` time which is not currently known.

Since the closure descriptor shims and such are already constant values,
this commit moves the descriptor function indices into the *descriptor*
for a closure/function pointer. This way we can learn about these values
at `wasm-bindgen` time instead of only knowing them at runtime.

This should have no semantic change on users of `wasm-bindgen`, although
some closure invocations may be slightly speedier because there's less
arguments being transferred over the boundary. Overall though this will
help #1002 as the closure shims that the Rust compiler generates may not
be the exact ones we hand out to JS, but rather wrappers around them
which do `anyref` business things.
2018-11-29 12:42:44 -08:00
Alex Crichton
430fce7a8b Enable env_logger for the wasm-bindgen CLI tool
This was intended earlier, but fogotten! Found during work on #1002
2018-11-29 12:25:24 -08:00
Alex Crichton
82bfbf9d20 Add more context to a wasm-bindgen-test-runner error
Minor cleanup I found during #1002
2018-11-29 12:25:10 -08:00