Commit Graph

576 Commits

Author SHA1 Message Date
Alex Crichton
31c2d6fbe5
Bump to 0.2.64 (#2219) 2020-06-29 09:48:25 -05:00
skim
41409d2b86
trims trailing space in doc comments (#2210) 2020-06-18 13:18:57 -05:00
Alex Crichton
9c5a6dfff6
Merge pull request #2176 from jakobhellermann/deno-target
add deno target
2020-06-03 16:20:30 -05:00
Jakob Hellermann
addb0824d1 fix deno import logic to include non-placeholder-module imports 2020-06-03 22:33:15 +02:00
Jakob Hellermann
84c7cf01ce address pr comments 2020-06-03 22:31:05 +02:00
Alex Crichton
8edcda4095
Update threads-xform for current nightly (#2183)
This commit updates the threads transformation for LLVM 10 where LLD has
has breaking changes from LLVM 9. While previously the support here
attempted to straddle multiple LLVM styles this is now removed in favor
of simply supporting LLVM 10's style of output. This means that
wasm-bindgen will only be compatible with recent nightlies and forward.

The major change here is that the `__wasm_init_memory` function is
automatically called by the `start` function. We handle that by placing
the previous `start` function first, before stack/tls allocation. Other
changes are to delete all the old code from pre-llvm-9.

Closes #2175
2020-06-03 11:39:10 -05:00
Jakob Hellermann
79f96af262 add deno target 2020-06-01 16:07:19 +02:00
Alex Crichton
cc36bdc00d
Fix codegen of consuming setters/getters (#2172)
Make sure they reset their internal pointer to null after we call Rust
since it invalidates the Rust pointer after being called!

Closes #2168
2020-05-29 15:28:52 -05:00
Hajime Fukuda
87663c6d2a
Enable nested namespace (#951) (#2105)
* Enable nested namespace (#951)

* Specify the namespace as array (#951)

* added an example to the document

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2020-05-27 10:36:20 -05:00
Alex Crichton
df809df9a5
Bump to 0.2.63 (#2163)
* Update `syn` version requirement

Require latest version to fix issues with nightly.

* Bump to 0.2.63
2020-05-27 10:07:18 -05:00
Alex Crichton
996e92f3ae
Mass rename anyref to externref (#2142)
Updates a mess of dependencies and tracks the most recent version of the
reference types specification.
2020-05-18 09:36:30 -05:00
Alex Crichton
61e8fc0d38 Update tests for new anyref syntax 2020-05-18 05:02:31 -07:00
Alex Crichton
8e3d6fe619
Update the walrus dependency (#2125)
This commit updates the `walrus` crate used in `wasm-bindgen`. The major
change here is how `walrus` handles element segments, exposing segments
rather than trying to keep a contiugous array of all the elements and
doing the splitting itself. That means that we need to do mroe logic
here in `wasm-bindgen` to juggle indices, segments, etc.
2020-05-06 12:57:02 -05:00
Alex Crichton
d896446edc
Bump to 0.2.62 (#2119) 2020-05-01 10:34:36 -05:00
Pauan
7bee6a8c19
Fixing require to be ignored by Webpack (#2115)
* Fixing require to be ignored by Webpack

* Making the module.require even more dynamic, to trick Webpack
2020-04-29 13:59:49 -05:00
Alex Crichton
6d61cd8b76
Bump to 0.2.61 (#2113) 2020-04-29 11:22:35 -05:00
Pauan
e16f7e41bf
Adding in wrapper file to fix circular dependency with Webpack 5 (#2110)
* Adding in wrapper file to fix circular dependency with Webpack 5

* Running rustfmt

* Fixing unit tests
2020-04-29 10:55:28 -05:00
Pauan
541e8f5359
No longer error for npm dependencies with web (#2103)
* No longer error for npm dependencies with web

* Fixing build error
2020-04-27 10:14:05 -05:00
Pauan
7bc9147258
Improving the code generation for catch (#2098)
* Improving the code generation for catch

* Fixing newlines

* Running rustfmt

* Updating unit tests

* Fixing build error
2020-04-22 09:14:00 -05:00
a1trl9
3c40492fa3
exhausively match JSImportName (#2090) 2020-04-20 09:10:33 -05:00
a1trl9
ad85de50c6
try to fix global / modulaized import ns conflict (#2057)
* use global import map for rename

* fix same ns import

* cargo fmt

* add basic test

* move generate_identifier, add comments, add tests

* remove leading &mut

* remove unnecessary bail

* use import_name for global and some refine

* Add back in error handling, clean up instruction iteration

* Remove unnecessary patch statements

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2020-04-15 08:28:29 -05:00
0xd4d
826538922f
Copy more doc comments to JS/TS files, unescape comments (#2070)
* Copy more doc comments to JS/TS files, unescape comments

* Move unescape code to macro-support
2020-04-13 13:51:32 -05:00
Alex Crichton
a19c8a3fe0
Bump to 0.2.60 (#2051)
* Bump to 0.2.60

* Try to fix CI

* Fix CI syntax
2020-03-25 16:33:36 -05:00
daxpedda
5534253280
Fix undefined error in worker. (#2038) 2020-03-10 09:13:50 -05:00
Pauan
b99ab10696 Running rustfmt 2020-03-04 06:20:58 +01:00
Pauan
d193b2db8f Improving the TypeScript types for the init function 2020-03-04 05:23:05 +01:00
Alex Crichton
db8d3e4412
Bump to 0.2.59 (#2026)
Wow this is a big release!
2020-03-03 10:55:51 -06:00
Joey Watts
7ffb5ed70c
Add skip_typescript attribute to prevent .d.ts emit (#2016)
* Add skip_typescript attribute to prevent .d.ts emit

* Add guide page for typescript attribute
2020-03-03 09:34:28 -06:00
Pauan
3f4acc453b
Dramatically improving the build time of web-sys (#2012)
* Pre-generating web-sys

* Fixing build errors

* Minor refactor for the unit tests

* Changing to generate #[wasm_bindgen} annotations

* Fixing code generation

* Adding in main bin to wasm-bindgen-webidl

* Fixing more problems

* Adding in support for unstable APIs

* Fixing bug with code generation

* More code generation fixes

* Improving the webidl program

* Removing unnecessary cfg from the generated code

* Splitting doc comments onto separate lines

* Improving the generation for unstable features

* Adding in support for string values in enums

* Now runs rustfmt on the mod.rs file

* Fixing codegen for constructors

* Fixing webidl-tests

* Fixing build errors

* Another fix for build errors

* Renaming typescript_name to typescript_type

* Adding in docs for typescript_type

* Adding in CI script to verify that web-sys is up to date

* Fixing CI script

* Fixing CI script

* Don't suppress git diff output

* Remove duplicate definitions of `Location`

Looks to be a preexisting bug in wasm-bindgen?

* Regenerate webidl

* Try to get the git diff command right

* Handle named constructors in WebIDL

* Remove stray rustfmt.toml

* Add back NamedConstructorBar definition in tests

* Run stable rustfmt over everything

* Don't run Cargo in a build script

Instead refactor things so webidl-tests can use the Rust-code-generation
as a library in a build script. Also fixes `cargo fmt` in the
repository.

* Fixup generated code

* Running web-sys checks on stable

* Improving the code generation a little

* Running rustfmt

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2020-03-02 17:39:36 -06:00
Alex Crichton
381660c49b
Run rustfmt and keep it running on CI (#2023)
Thought we did this awhile back, but looks like we forgot to do so!
2020-03-02 11:44:14 -06:00
Ingvar Stepanyan
d26068dc6c
Propagate missing memory argument (#2011)
Fixes #2010.
2020-02-20 11:33:40 -06:00
Bennett Hardwick
ec1b9453c9
Allow web-sys to emit correct typescript declarations from webidl (#1998)
* Update to emit typescript names

* Update to use NamedAnyref

* Update incoming / outgoing

* Remove added space

* Remove comment

* Add basic typescript tests for web-sys
2020-02-19 09:14:32 -06:00
clearloop
b6190700c9
Reflect optional struct fields in typescript (#1990)
* reflect option struct fields in typescript

* optional fields: move type checker to getter

* infer optional fields from ts_args
2020-02-18 09:15:37 -06:00
Pauan
156e1cb47f
Removing duplicate closure wrappers in the JS glue (#2002)
* Removing duplicate closure wrappers in the JS glue

* Fixing build error

* Adding in explanatory comment
2020-02-18 08:37:40 -06:00
Darin Morrison
673e9b7830
Add electron support via --omit-imports (#1958) 2020-02-12 09:52:59 -08:00
Pauan
ca742a84c4
Improving wasm loading logic (#1996)
* Improving wasm loading logic

* Adding in note to the book about the new loading functionality
2020-02-11 08:58:42 -08:00
Pauan
91f0dbdb28
Removing self from no-modules target (#1995) 2020-02-10 16:18:55 -06:00
Timothy McCallum
0f3c53b5a5
Create JavaScript array without using new keyword. (#1987)
* Create JavaScript array without using `new` keyword.

At present [this line of code](https://github.com/rustwasm/wasm-bindgen/blob/master/crates/cli-support/src/js/mod.rs#L747) creates the heap using JavaScript's new keyword.
```
//Line 747
self.global(&format!("const heap = new Array({});", INITIAL_HEAP_OFFSET));
self.global("heap.fill(undefined);");
```
Assuming that the `INITIAL_HEAP_OFFSET` is always 32 (because it is set as a constant in the Rust code), below is the equivalent of what this code will produce; an Array Object with 32 items which are all undefined.
```
const heap = new Array(32);
//(32) [empty × 32]
//Where
var zero_element = heap[0];
//undefined
var one_element = heap[1];
//undefined
```
I believe that this is the desired outcome for the program. All good.

### Suggestion to consider

I am always reminded **not** to use the `new` keyword. Mainly by reading or listening to JavaScript ["The Good Parts"](https://youtu.be/XFTOG895C7c?t=1654). 

For example if the `INITIAL_HEAP_OFFSET` was ever anything but one number, the heap would be created in a different way. For example if two numbers are passed in, then an array of size 2 would be created; where both items in the array are individual numbers.
```
const heap = new Array(32, 32);
var zero_element = heap[0];
var one_element = heap[1];
//32
//32
```
I know that this is highly unlikely, due to the fact that the `INITIAL_HEAP_OFFSET` is set as a `const` in the Rust. But thought that I would put out the following suggestion for consideration anyway. This comes from a place of just wanting to contribute in a way that could make this already awesome program a little better. :)

### Suggested update
The heap array could be created using the following code
```
const heap = [];
heap.length = INITIAL_HEAP_OFFSET;
heap[0]
heap[1]
//undefined
//undefined
```
This would create a JavaScript Array of length `INITIAL_HEAP_OFFSET`, where are items are `undefined`

The new code generates (in raw JavaScript)
```
const heap = [];
heap.length = 32;
```
Which produces
```
(32) [empty × 32]
```
In the same way that the original code does.

* Add closing parenthesis to close out self.global

* Adding files which were altered by the BLESS=1 system variable. Essentially updating generated files that are used for testing.

* Adding code generated wat file, by way of running tests using BLESS=1

* Adding table.wat that was generated by running the  tests with BLESS=1 set

* Update code that creates heap array line 747 mod.rs

* Updating files that are automatically generated when using BLESS=1
2020-02-06 19:00:15 -06:00
Mario Reder
34eb8a8516 fix: ignore non dependency keys in package json (#1969)
resolves #1921
2020-01-21 13:04:40 -06:00
Alex Crichton
c5c7acc766
Preserve the function table explicitly (#1970)
The main gc pass of unused items in wasm-bindgen was accidentally
removing the function table because we weren't properly rooting it in
the auxiliary section which has a few ways that imports can reference
the function table via intrinsics and closures.

Closes #1967
2020-01-21 13:02:13 -06:00
Alex Crichton
2902ceb26f
Bump to 0.2.58 (#1946) 2020-01-07 13:48:25 -06:00
Alex Crichton
f66d83ff70
Store richer adapter types, don't use instructions for TypeScript (#1945)
This commit updates how TypeScript signature are generated from adapters
in wasm-bindgen. A richer set of `AdapterType` types are now stored
which record information about optional types and such. These direct
`AdapterType` values are then used to calculate the TypeScript
signature, rather than following the instructions in an adapter function
(which only works anyway for wasm-bindgen generated adapters).

This should be more robust since it reads the actual true signature of
the adapter to generate the TypeScript signature, rather than attempting
to ad-hoc-ly infer it from the various instructions, which was already
broken.

A number of refactorings were involved here, but the main pieces are:

* The `AdapterType` type is a bit more rich now to describe more
  Rust-like types.
* The `TypescriptArg` structure is now gone and instead return values
  are directly inferred from type signatures of adapters.
* The `typescript_{required,optional}` methods are no longer needed.
* The return of `JsBuilder::process` was enhanced to return more values,
  rather than storing some return values on the structure itself.

Closes #1926
2020-01-07 11:34:02 -06:00
daxpedda
93fedf85bf Add default module to init for no-modules output mode. (#1938)
* Add default module to `init` for `no-modules` output mode.

* Add semicolons.
2020-01-06 14:55:45 -06:00
Alex Crichton
56e4d7de1d
Bump to 0.2.57 (#1943) 2020-01-06 13:17:28 -06:00
Paul Butler
620212dff8 bool -> boolean in generated TypeScript code (#1933)
* bool -> boolean in generated TypeScript code

* Add a test for booleans

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2020-01-06 13:17:19 -06:00
Alex Crichton
1548953364
Handle duplicate imports of the same item. (#1942)
The wasm-bindgen nightly test suite started failing recently and a
bisection shows that rust-lang/rust#67363 is the cause of this issue.
The problem happening here is that after that Rust PR duplicate imports
from the same name/module in different parts of a Rust program may now
show up as duplicate imports rather than being coalesced into one
import. This was tripping up `wasm-bindgen` which, when translating from
the wasm module to wasm-bindgen's IR, is unfortunately very
string-based.

The fix here was to detect these duplicate imports and map them all to
the same item, removing the duplicate imports.

Closes #1929
2020-01-06 11:44:52 -06:00
Pauan
580daab1d3 Release 0.2.56 (#1922) 2019-12-20 10:31:17 -06:00
Linda_pp
090109dea7 disable eslint in generated type definition file (#1908) 2019-12-11 10:24:49 -08:00
Alex Crichton
057c9157b3
Add test for consuming interface types inputs (#1900)
This commit adds a test suite for consuming interface types modules as
input and producing a JS polyfill output. The tests are relatively
simple today and don't exercise a ton of functionality, but they should
hopefully cover the breadth of at least some basics of what wasm
interface types supports today.

A few small fixes were applied along the way, such as:

* Don't require modules to have a stack pointer

* Allow passing `*.wat`, `*.wit`, or `*.wasm` files as input to
  `wasm-bindgen` instead of always requiring `*.wasm`.
2019-12-04 22:39:57 -06:00
Alex Crichton
203d86f343
Add tests for the interface types output of wasm-bindgen (#1898)
* Add tests for the interface types output of wasm-bindgen

This commit expands the test suite with assertions about the output of
the interface types pass in wasm-bindgen. The goal here is to actually
assert that we produce the right output and have a suite of reference
files to show how the interface types output is changing over time.

The `reference` test suite added in the previous PR has been updated to
work for interface types as well, generating `*.wit` file assertions
which are printed via the `wit-printer` crate on crates.io.

Along the way a number of bugs were fixed with the interface types
output, such as:

* Non-determinism in output caused by iteration of a `HashMap`

* Avoiding JS generation entirely in interface types mode, ensuring that
  we don't export extraneous intrinsics that aren't otherwise needed.

* Fixing location of the stack pointer for modules where it's GC'd out.
  It's now rooted in the aux section of wasm-bindgen so it's available
  to later passes, like the multi-value pass.

* Interface types emission now works in debug mode, meaning the
  `--release` flag is no longer required. This previously did not work
  because the `__wbindgen_throw` intrinsic was required in debug mode.
  This comes about because of the `malloc_failure` and `internal_error`
  functions in the anyref pass. The purpose of these functions is to
  signal fatal runtime errors, if any, in a way that's usable to the
  user. For wasm interface types though we can replace calls to these
  functions with `unreachable` to avoid needing to import the
  intrinsic. This has the accidental side effect of making
  `wasm_bindgen::throw_str` "just work" with wasm interface types by
  aborting the program, but that's not actually entirely intended. It's
  hoped that a split of a `wasm-bindgen-core` crate would solve this
  issue for the future.

* Run the wasm interface types validator in tests

* Add more gc roots for adapter gc

* Improve stack pointer detection

The stack pointer is never initialized to zero, but some other mutable
globals are (TLS, thread ID, etc), so let's filter those out.
2019-12-04 15:19:48 -06:00