Commit Graph

499 Commits

Author SHA1 Message Date
Alex Crichton
791e69a5c0
Generate normal Rust functions for imported bindings (#410)
* Generate normal Rust functions for imported bindings

No need to use the C ABI, it just mixes up the documentation!

* Update expected webidl output
2018-07-07 12:20:42 -05:00
R. Andrew Ohana
2d50d5209b Backend refactor (#411)
* remove BindgenAttrs from other backend::ast structs

This is primarily a tool for use with the macro crate. Most of
these attributes were ignored in the actual codegen, but a few
were still being used. This is confusing when trying to add
other sources for codegen (such as webidl and typescript).

* move parsing logic to macro crate

This makes the backend crate solely concerned with having an ast
for which we can generate code.
2018-07-07 12:20:31 -05:00
dependabot[bot]
37bb15baf6
Merge pull request #404 from rustwasm/dependabot/cargo/docopt-1.0 2018-07-06 19:43:25 +00:00
dependabot[bot]
ded378b92f
Update docopt requirement to 1.0
Updates the requirements on [docopt](https://github.com/docopt/docopt.rs) to permit the latest version.
- [Release notes](https://github.com/docopt/docopt.rs/releases)
- [Commits](https://github.com/docopt/docopt.rs/commits/1.0.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>
2018-07-06 16:55:11 +00:00
dependabot[bot]
178375a51b
Update wasmi requirement to 0.3
Updates the requirements on [wasmi](https://github.com/paritytech/wasmi) to permit the latest version.
- [Release notes](https://github.com/paritytech/wasmi/releases)
- [Commits](https://github.com/paritytech/wasmi/commits)

Signed-off-by: dependabot[bot] <support@dependabot.com>
2018-07-06 16:54:52 +00:00
Sendil Kumar N
142d7377e2
Merge pull request #400 from alexcrichton/derive-import
Forward attributes on `type` declaration to definition
2018-07-06 09:21:01 +02:00
Satoshi Amemiya
e6b2a0d98c Add support getter and setter for static props 2018-07-06 14:57:17 +09:00
Alex Crichton
f4b49226b6 Fix webidl crate 2018-07-05 21:25:40 -07:00
Alex Crichton
5a776c16b2 Forward attributes on type declaration to definition
This'll allow things like `#[derive(Clone)]` or `#[derive(Debug)]` to control
traits for these types.
2018-07-05 20:28:52 -07:00
Nick Fitzgerald
549e5a9be9 tests: Pull the project() builder out into its own crate
The WebIDL-based -sys crate will also use this, but I want its tests to be a
separate suite that we can run separately and in parallel in CI. Therefore, this
testing infrastructure code needs to be share-able between them :)
2018-07-05 14:27:26 -07:00
Alex Crichton
efa4a2b8fa
Speed up Travis by running Webpack in fewer tests (#381)
* Reorganize Travis configuration

* Add a `JOB` env var descriptor to all matrix entries. Not used anywhere but is
  useful when viewing the whole build on Travis's web interface.
* Reorganize where builds are located, moving slow builds first and fast ones
  last.
* Change checking the CLI builds from `cargo build` to `cargo check`
* Use YAML references to reduce some duplication

* Print some more timing statistics for each test

* Extract `Project` helper in tests to a module

This'll help make it a bit more extensible over time. At the same time the
methods are also slightly reorganized to read more clearly from top to bottom.

* Migrate all tests away from Webpack

Wepback can take a significant amount of time to execute and when it's
multiplied by hundreds of tests that adds up really quickly! After investigating
Node's `--experimental-modules` option it looks like it's suitable for our use
so this switches all tests to using JS files (moving away from TypeScript as
well) with `--experimental-modules` with Node.

Tests will be selectively re-enabled with webpack and node.js specific output
(that doesn't require `--experimental-modules`), coming in later commits.

* Restore the node test for node.js output

Ensures it's workable as-is

* Only generate typescript with webpack

* Only read wasm files for webpack

* Skip package.json/node_modules for now

* Only generate webpack config if needed

* Start a dedicated test module for typescript

Will hopefully verify the generated Typescript compiles OK.

* Remove unneeded `node` method

* Fixup some rebase conflicts

* Don't run asmjs example on travis

* Fixup generator tests

* Attempt to fix windows

* Comment windows fix

* More test fixes

* More exclusions

* More test fixes

* Relax eslint regex

Catch mjs modules as well

* Fix eslint

* Speed up travis on examples slightly
2018-07-04 22:37:09 -05:00
Alex Crichton
247ea628fb Don't import wasm in generated JS if it's not used
Mostly just an edge case
2018-07-04 08:50:48 -07:00
Alex Crichton
000970ee2c Remove extraneous exposure of uint64 memory
No longer needed!
2018-07-04 08:34:19 -07:00
Alex Crichton
67b9ce58aa Fix getArrayJsValueFromWasm exposing wrong function
This needs `getUint32Memory`, not `getArrayU32FromWasm`.
2018-07-04 08:30:18 -07:00
Alex Crichton
3510b20595 Fix a stray unused variable
Travis tests show hundreds of warning for `'y' is defined but never used` and
when investigating it looks like a mistake was introduced in 0938858aa
during #272, so hopefully this'll be an easy fix!
2018-07-04 08:16:09 -07:00
teovoinea
7cd3ca02a2 Update with masters and fix PR changes 2018-07-02 20:35:05 -07:00
Alex Crichton
4ceaf3e0f4
Some small cleanups (#366)
* No need for version deps in dev-deps

These are all internal so we can drop the version

* Remove wasm-bindgen-cli's parity-wasm dep

No longer needed

* Tweak file hierarchy in webidl tests

Use Cargo's conventions to avoid the need to define `[[test]]` sections

* Remove unused imports
2018-07-02 11:57:39 -05:00
Alex Crichton
e06255fba5 Don't generate JS bindings for unused imports
If a JS import's shim isn't actually imported that means that somewhere along
the way it was optimized out or it was never used in the first place! In that
case we can skip generation of the JS bindings for it as it's not needed.
2018-06-29 15:56:12 -07:00
Alex Crichton
e55af85edc
Support by-value self methods (#348)
Refactor slightly to use the same internal support that the other reference
conversions are using.

Closes #329
2018-06-28 20:09:11 -05:00
Alex Crichton
9a3ff77ea9
Support returning custom types in imports (#350)
Closes #320
2018-06-28 20:08:02 -05:00
Alex Crichton
4138583dff
Support wildcard arguments in foreign functions (#351)
No real reason to not support them!

Closes #346
2018-06-28 20:06:35 -05:00
R. Andrew Ohana
7626b55d00 fix up some strings that looked funky after rustfmt 2018-06-27 22:45:33 -07:00
R. Andrew Ohana
9127a0419f rustfmt all the things 2018-06-27 22:42:34 -07:00
xeqlol
2028efa76f Fix typo in backend crate 2018-06-26 13:17:40 +05:00
Nick Fitzgerald
5adda0d591
Merge pull request #313 from jamen/support-rollup
Make JS use a '.wasm' extension when importing the binary
2018-06-25 15:34:58 -07:00
Jamen Marz
a596dc4129
Make JS use a '.wasm' extension when importing the binary 2018-06-25 15:26:30 -06:00
Nick Fitzgerald
8fbf478058 Move some utility functions from the webidl crate into the backend crate 2018-06-25 10:45:53 -07:00
Nick Fitzgerald
21fa3beabd backend: Add some trailing commas that rustfmt prefers 2018-06-25 10:45:53 -07:00
Nick Fitzgerald
911a32c0d5 Add the #[wasm_bindgen(static_method_of = Class)] attribute
This is similar to `js_namespace` but translates into a static method on `Class`
rather than a free function. This allows us to have bindings to things like
`Object.keys` as `Object::keys`.
2018-06-25 10:45:53 -07:00
R. Andrew Ohana
d79f982a01
Merge pull request #295 from kzvi/js-class-attr
add js_class attribute for defining what class an imported method is for
2018-06-22 21:38:14 -07:00
kzvi
2cfffc65d7 add js_class attribute for defining what class an imported method is for 2018-06-22 12:12:43 -07:00
Nick Fitzgerald
3bce3fb7a5 backend: Tidy up whitespace
* Remove trailing space on line.
* Ensure that there is a newline at the end of the file.
2018-06-22 11:14:33 -07:00
Nick Fitzgerald
24f72c9680 backend: Remove unused import from ast module 2018-06-22 11:14:16 -07:00
Nick Fitzgerald
c63d57f6d7 Add some more doc comments 2018-06-22 11:10:37 -07:00
Nick Fitzgerald
5eda5504e9
Merge pull request #273 from FreeMasen/validate-ptr
Validate ptr
2018-06-19 16:45:31 -07:00
Nick Fitzgerald
224d20337f
Merge pull request #274 from fitzgen/js-sys
Expose objects and functions from the JavaScript global scope
2018-06-19 10:42:04 -07:00
Nick Fitzgerald
d9cac3bd90 Don't document descriptor functions
They aren't part of any public API, and are just an implementation detail of
wasm-bindgen.
2018-06-18 16:44:19 -07:00
Nick Fitzgerald
132103eb06 cli-support: Ignore missing descriptor functions
This can happen when a nested dependency crate exports things but the root crate
doesn't use them. In these cases, it is fine to ignore the missing descriptor,
because the thing it describes was removed as dead code.
2018-06-18 16:41:01 -07:00
Robert Masen
749ac6502f add ptr validation 2018-06-17 20:13:56 -05:00
R. Andrew Ohana
0938858aa8 webidl: add support for static attributes 2018-06-15 12:22:14 -07:00
R. Andrew Ohana
fe5cde8636 webidl: add support for static methods 2018-06-15 12:09:42 -07:00
Nick Fitzgerald
639ccd53ce
Merge pull request #269 from ohanar/webidl_constructor
webidl: add support for (named) constructors
2018-06-15 11:35:29 -07:00
Robert Masen
2d7e7cd73e Update js formatting 2018-06-15 12:55:37 -05:00
Robert Masen
19d6cf1488 Copy doc comments from Rust to JS (#265)
* backend comments complete

* better matching

* gen comments

* Add example

* Move test bindings gen to own fn

* move build step into build fn

* add fn to read js, refactor gen_bindings/test to allow for this

* Add comments test

* Update readmes

* add comments to travis

* fix broken tests

* +x on build.sh

* fix wbg cmd in build.sh

* Address fitzgen's comments
2018-06-15 09:20:56 -07:00
R. Andrew Ohana
cbec42e86c webidl: add support for named constructors 2018-06-14 16:20:20 -07:00
R. Andrew Ohana
c65cb51fba webidl: add support for constructors 2018-06-14 16:15:25 -07:00
R. Andrew Ohana
400015a061 webidl: refactor method/getter/getter generation 2018-06-14 14:39:04 -07:00
R. Andrew Ohana
be0e436c03 webidl: add basic support for attributes 2018-06-11 18:45:19 -07:00
R. Andrew Ohana
d065f4b05d webidl: add support for typedefs 2018-06-11 18:43:45 -07:00
R. Andrew Ohana
04907477ba webidl: translate methods from camelCase to snake_case 2018-06-09 21:49:42 -07:00
Santiago Pastorino
37eaca47b4
Pretty print output on main example 2018-06-07 14:58:20 -03:00
Santiago Pastorino
d6ec2289fc
Remove wrong types conversion from js to rust
We can revisit this when we have better tests.
2018-06-07 14:57:44 -03:00
Santiago Pastorino
fa8961e56a
Add prototype of wasm-bindgen-typescript 2018-06-04 17:28:12 -03:00
Nick Fitzgerald
8865e019f8 webidl: add features necessary to support Event.initEvent
1. Adds support for binding `DOMString` arguments to `&str`.

2. Ignore whether an argument is optional, and just always emit bindings for it.
2018-06-01 16:41:15 -07:00
Nick Fitzgerald
cb5bd3b9c9
Merge pull request #225 from fitzgen/webidl
webidl: Add logging and use env_logger in the tests
2018-06-01 16:09:36 -07:00
Nick Fitzgerald
8faebc56f2 webidl: Add logging and use env_logger in the tests 2018-06-01 16:09:15 -07:00
Alex Crichton
659583b40d
Implement PartialEq for JsValue (#217)
Dispatch to JS's `===` operator internally
2018-06-01 16:47:45 -05:00
Alex Crichton
cb1e5cf136
Optimize JsValue::{from_bool, undefined, null} constructors (#220)
This commit optimizes constructing an instance of `JsValue` which is one of
`null`, `undefined`, `true`, or `false`. These are commonly created on the Rust
side of things and since there's only a limited set of values we can easily
prepopulate the global slab with a few entries and use hardcoded indices to
refer to these constants. This should avoid the need to travel into JS to insert
a `null` or and `undefined` into the global slab.
2018-06-01 16:46:42 -05:00
Nick Fitzgerald
346d2fda22
Merge pull request #223 from fitzgen/webidl
webidl: emit methods for regular operations on interfaces
2018-06-01 14:22:11 -07:00
Alex Crichton
a4428f01b6 Update parity-wasm dependency 2018-06-01 07:48:32 -07:00
Nick Fitzgerald
7ea0a7cc26 webidl: emit methods for regular operations 2018-05-31 22:54:40 -07:00
Nick Fitzgerald
c7819930b4 backend::ast: rustfmt 2018-05-31 22:52:43 -07:00
Nick Fitzgerald
ce8238cdd8 webidl: Compile and test the bindings emitted from WebIDL compilation 2018-05-31 22:52:43 -07:00
Nick Fitzgerald
a3d91bdd7c webidl: make writing new tests really easy 2018-05-30 15:45:01 -07:00
Nick Fitzgerald
c773b29d6d webidl: add compile and compile_file
These will be the functions invoked by crates compiling WebIDL into wasm-bindgen
Rust sources inside `build.rs`.
2018-05-30 14:30:40 -07:00
Nick Fitzgerald
a30ccd7c18 webidl: Use Default for pub tokens (#215) 2018-05-30 15:07:20 -05:00
Nick Fitzgerald
4a54e6fd52
Merge pull request #214 from fitzgen/webidl
Add a WebIDL frontend
2018-05-30 11:52:16 -07:00
Alex Crichton
6d23c8533b Avoid deprecated constructor 2018-05-29 18:02:00 -07:00
Alex Crichton
5e94dc2b75 Update parity-wasm dependency 2018-05-29 18:00:09 -07:00
Nick Fitzgerald
3879f6f427 Introduce the wasm-bindgen-webidl frontend
This is still a work in progress. Parse WebIDL source text and convert it into
wasm-bindgen AST, so that we can automatically emit bindings for the types and
functions described in the WebIDL.
2018-05-29 14:22:53 -07:00
Nick Fitzgerald
6885ea073e Only derive extra traits when the extra-traits feature is enabled 2018-05-29 11:24:40 -07:00
Nick Fitzgerald
07d5afa268 backend: All AST types should implement Eq 2018-05-25 16:33:22 -07:00
Nick Fitzgerald
018f083402 backend: All AST types should implement Debug 2018-05-25 16:20:07 -07:00
Nick Fitzgerald
50b8842b95 Add a feature for printing the macro's generated code (#212) 2018-05-25 18:17:54 -05:00
Alex Crichton
4c27c349ea Bump to 0.2.11 2018-05-24 08:56:28 -07:00
Alex Crichton
7009c506c1 Revert "Revert "Revert "Disable the span feature temporarily"""
This reverts commit b3cb44eb53.
2018-05-24 07:16:36 -07:00
Robert Masen
4ddd93d75d add char support (#206)
* add char support

* add char test

* remove __wbindgen_char fns

* re-order travis script

* update serve script

* remove binds to unused char functions

* add more wide character items to chars list

* remove unused code

* add char to readme

* remove built file
2018-05-22 12:34:41 -05:00
Alex Crichton
17861a45ab Improve the --wasm2asm flag of wasm2es6js
* Don't glob import modules an instead selectively only import required items
* Be compatible with node.js and avoid the usage of `self`
2018-05-22 08:31:35 -07:00
Alex Crichton
dd76707ea1 Prevent use-after-free with vectors
Awhile back slices switched to being raw views into wasm memory, but this
doens't work if we free the underlying memory unconditionally! Moving around a
`Vec` is already moving a lot of data, so let's copy it onto the JS heap instead
of leaving it in the wasm heap.
2018-05-21 11:23:46 -07:00
Alex Crichton
cfe7ebd463 Disallow structs w/ lifetime/type parameters
These can't work currently with wasm-bindgen, but maybe one day!

Closes #200
2018-05-21 09:13:17 -07:00
Alex Crichton
b3cb44eb53 Revert "Revert "Disable the span feature temporarily""
This reverts commit a10a0c8cfd.
2018-05-21 08:08:21 -07:00
Alex Crichton
a10a0c8cfd Revert "Disable the span feature temporarily"
This reverts commit 45b68870dc.
2018-05-21 07:30:10 -07:00
Alex Crichton
e76f5537e0 Upgrade to new versions of proc-macro2
Gonna get some nice spans back!
2018-05-21 07:29:34 -07:00
Alex Crichton
627ca1d638 Bump to 0.2.10 2018-05-17 10:40:24 -07:00
Alex Crichton
45b68870dc Disable the span feature temporarily
It's broken on nightly and needs fixing
2018-05-17 10:39:44 -07:00
Alex Crichton
5d28b90069 Bump to 0.2.9 2018-05-11 16:04:41 -07:00
Alex Crichton
7647019162 Fix build on CI 2018-05-11 08:48:42 -07:00
Alex Crichton
ca8809b4e9 Don't try to codegen static into an impl
Closes #194
2018-05-11 08:28:09 -07:00
Alex Crichton
06664b34ce Fix parsing some Rust keywords in attributes
Closes #193
2018-05-09 08:01:57 -07:00
Gergely Nagy
02adf6defa Fix generated binding for functions returning structs.
This only affects --no-modules and --nodejs modes.

Fixes #190.
2018-05-06 18:17:33 +02:00
Alex Crichton
237fff0698 Map u64/i64 to BigInt in JS
This commit is an implementation of mapping u64/i64 to `BigInt` in JS through
the unstable BigInt APIs. The BigInt type will ship soon in Chrome and so this
commit builds out the necessary support for wasm-bindgen to use it!
2018-05-05 18:51:20 -07:00
Alex Crichton
48a823c685 Remove slice logic of "commit to wasm"
When adding support for mutable slices I was under the impression that if the
wasm memory was reallocated while we were using it then we'd have to commit the
changes from the original buffer back to the new buffer. What I didn't know,
however, is that once the wasm memory is reallocated then all views into it are
supposed to be defunkt.

It looks like node 9 didn't have this implementation quite right and it appears
fixed in node 10, causing the deleted test here to fail. While this commit does
raise the question of whether this is the right approach to interact with slices
in JS I think the answer is still "yes". The user can always initiate the copy
if need be and that seems strictly better than copying 100% of the time.
2018-05-05 14:52:22 -07:00
Alex Crichton
139b7a1aae Don't use the global stack for string lengths
This commit updates the `Abi` associated type for all slice types to a
`WasmSlice` type, an aggregate of two `u32` integers. This translates to an ABI
where when passed as a function argument it expands to two integer arguments,
and when passed as a return value it passes a return pointer as the first
argument to get filled in.

This is hopefully more forwards-compatible with the host bindings proposal which
uses this strategy for passing string arguments at least. It's a little sketchy
what we're doing as there's not really a stable ABI yet, but hopefully this'll
all be relatively stable for awhile!
2018-05-02 21:03:50 -07:00
Alex Crichton
4304a262c6 Fix enums defined in submodules 2018-05-02 10:17:16 -07:00
Alex Crichton
0566a97485 Add support for mutable slices
This commit adds support for mutable slices to pass the boundary between JS and
Rust. While mutable slices cannot be used as return values they can be listed as
arguments to both exported functions as well as imported functions.

When passing a mutable slice into a Rust function (aka having it as an argument
to an exported Rust function) then like before with a normal slice it's copied
into the wasm memory. Afterwards, however, the updates in the wasm memory will
be reflected back into the original slice. This does require a lot of copying
and probably isn't the most efficient, but it should at least work for the time
being.

The real nifty part happens when Rust passes a mutable slice out to JS. When
doing this it's a very cheap operation that just gets a subarray of the main
wasm memory. Now the wasm memory's buffer can change over time which can produce
surprising results where memory is modified in JS but it may not be reflected
back into Rust. To accomodate this when a JS imported function returns any
updates to the buffer are copied back to Rust if Rust's memory buffer has
changed in the meantime.

Along the way this fixes usage of `slice` to instead use `subarray` as that's
what we really want, no copying. All methods have been updated to use `subarray`
accessors instead of `slice` or constructing new arrays.

Closes #53
2018-05-01 10:06:35 -07:00
Alex Crichton
fbb12f519b Bump to 0.2.8 2018-04-30 19:23:44 -07:00
Alex Crichton
dadcff15ef Add an example of wasm2asm and wasm-bindgen
This commit adds an example of executing the `wasm2asm` tool to generate asm.js
output instead of WebAssembly. This is often useful when supporting older
browsers, such as IE 11, that doesn't have native support for WebAssembly.
2018-04-30 13:29:34 -07:00
Alex Crichton
6f95e5c531 Print errors to stderr instead of stdout 2018-04-30 13:24:29 -07:00
Alex Crichton
7cef4a66b8 Merge remote-tracking branch 'alex/master' 2018-04-29 16:38:08 -07:00
Alex Crichton
befdf07a07 Bump to 0.2.7 2018-04-27 19:48:57 -07:00
Alex Crichton
4a873af8d1 Enable cargo test where possible
Currently `#[wasm_bindgen]` generates a bunch of references to symbols that
don't actually exist on non-wasm targets, making it more difficult to get a
crate working across multiple platforms. This commit updates the symbol
references to be dummy ones that panic on non-wasm targets to allow simple
testing/benchmarking to work on native targets.

While this isn't a perfect solution for #114 it's probably as good as we can do
for now pending upstream Cargo features, so I'm gonna say that it...

Closes #114
2018-04-27 15:01:35 -07:00
Alex Crichton
ba03cc3684
Merge pull request #173 from rustwasm/ts-default
Emit `*.d.ts` file by default
2018-04-27 12:40:14 -05:00
Alex Crichton
89bd10f974 Emit *.d.ts file by default 2018-04-27 07:15:34 -07:00
Alex Crichton
b8895b3a95 Add JsValue::{from_serde, into_serde}
These functions are activated with the `serde-serialization` feature of the
`wasm-bindgen` crate. When activated they will allow passing any arbitrary value
into JS that implements the `Serialize` trait and receiving any value from JS
using the `Deserialize` trait. The interchange between JS and Rust is JSON.

Closes #96
2018-04-26 20:45:22 -07:00
Alex Crichton
acb5eac96a Bump to 0.2.6 2018-04-26 19:14:09 -07:00
Alex Crichton
b7bbcf5ea9 Fix compat with current nightly 2018-04-26 19:12:56 -07:00
Alex Crichton
6d5ebaf5ac Update parity-wasm and wasmi 2018-04-26 18:42:49 -07:00
Alex Crichton
412bebca72 Add support for version specifications
This commit adds a `#[wasm_bindgen(version = "...")]` attribute support. This
information is eventually written into a `__wasm_pack_unstable` section.
Currently this is a strawman for the proposal in ashleygwilliams/wasm-pack#101
2018-04-25 22:23:02 -07:00
Alex Crichton
d9a71b43db Assert empty JS heap/stack in tests
Turns out there was a bug when passing a vector of `JsValue` instances back to
JS all objects were leaked rather than correctly removed from the global slab.
2018-04-25 22:15:28 -07:00
Alex Crichton
faed98b843 Correct how slices are iterated over
This commit fixes how the `getArrayJsValueFromWasm` function is defined to
correctly iterate over the slice by looking at the values rather than the
indices.

Closes #169
2018-04-25 21:58:49 -07:00
Alex Crichton
b2ecf56cb6
Merge pull request #165 from jryans/spans-feature
Add `spans` feature to control `proc-macro2`
2018-04-25 15:23:23 -05:00
J. Ryan Stinnett
11e274b477 Add spans feature to control proc-macro2
Using `proc-macro2`'s `nightly` feature is a good default for most use cases.
However, it causes a build error if used together with crates such as
`cssparser` that also use `proc-macro2` from a build script.

This change adds a default enabled feature `spans` that users can disable if
they need to work around this conflict.

Fixes #160.
2018-04-25 14:42:21 -05:00
Alex Crichton
5f59d95130 Migrate to the failure crate
Currently errors are reported via Rust panics but there's lots more errors being
added over time so this commit starts the movement towards the `failure` crate
to more idiomatically report errors as well as provide better error messages
over time.
2018-04-25 11:57:17 -07:00
Alex Crichton
2b9c48d5f9 Favor if let instead of is_some + unwrap 2018-04-23 11:25:30 -07:00
Alex Crichton
8ae6fe19a3
Merge pull request #153 from FreeMasen/master
include fetch arg for wasm2es6js
2018-04-23 13:23:24 -05:00
robert masen
79a49b2a56 update fetch to take a string parameter 2018-04-23 09:04:30 -05:00
Robert Masen
cbccd2028d include fetch arg for wasm2es6js 2018-04-23 08:41:02 -05:00
Joshua Sheard
0caa6d2ec4
Fix Typescript definition of constructor arguments 2018-04-22 10:57:00 +01:00
Alex Crichton
4436c0eae6 Avoid invoking a function pointer with JsStatic
The previous codegen wasn't enough to convince LLVM that the function pointer
was a constant value and could be aggressively inlined, so this updates the
`JsStatic` internals slightly to guarantee to LLVM that the function pointer is
constant and no dynamic dispatch is needed after all
2018-04-21 13:14:33 -07:00
Alex Crichton
4100dc9c53 Recommend installation from crates.io, not git 2018-04-20 19:07:56 -07:00
Alex Crichton
7108206835 Implement readonly struct fields
Add support for `#[wasm_bindgen(readonly)]` which indicates that an exported
struct field is readonly and attempting to set it in JS will throw an exception.

Closes #151
2018-04-20 10:56:10 -07:00
Alex Crichton
3b4bf475be Bump to 0.2.5 2018-04-19 18:46:41 -07:00
Alex Crichton
c6f7d3dfd5 Fix methods returning Self
Rewrite any instance of `Self` to the name of the class

Closes #137
2018-04-19 18:43:37 -07:00
Alex Crichton
ce31859590 Generate accessors for public struct fields
Automatically infer public struct fields as "JS wants to access this" and
generate appropriate getters/setters for the field. At this time the field is
required to implement `Copy`, but we will probably want to relax that in the
future to at least encompass `JsValue` and maybe other `Clone` values as well.

Closes #121
2018-04-19 16:49:46 -07:00
Alex Crichton
f3c05e5339 Fix compat with stable 2018-04-19 14:28:30 -07:00
Alex Crichton
eb73e05b7a Deserialize less to match schema versions
Currently the entire `Program` is deserialized to match schema versions but this
is likely to fail when the schema changes. Instead just deserialize the
schema/version fields, compare those, and if successful go ahead and deserialize
everything.
2018-04-19 13:36:59 -07:00
Alex Crichton
0ade4b8cac Add a --no-modules-global flag
This can be used to configure the name of the global that's initialized so it's
not unconditionally `wasm_bindgen`.

Closes #145
2018-04-19 13:33:58 -07:00
Alex Crichton
212703671a No need to expose ptr in TypeScript
This was needed long ago but is no longer needed!

Closes #147
2018-04-19 13:28:50 -07:00
Alex Crichton
748184ae66 Work with #![no_std] contexts
This commit adds support for both `#![no_std]` in the wasm-bindgen runtime
support (disabled by default with an on-by-default `std` feature). This also
adds support to work and compile in the context of `#![no_std]` crates.

Closes #146
2018-04-19 13:24:30 -07:00
Alex Crichton
792a8e132e Fix unused variables in generated code
Also deny all warnings in tests to prevent this creeping back in.

Closes #141
2018-04-19 13:16:59 -07:00
Alex Crichton
45e4983e8c Use self instead of window
That should hopefully get us more compatible with web workers!

Closes #144
2018-04-19 07:20:04 -07:00
Alex Crichton
055a8fb803 Bump to 0.2.4 2018-04-18 07:18:11 -07:00
Alex Crichton
7d5f2e4152 Enable the visit feature of syn 2018-04-18 07:16:14 -07:00
Alex Crichton
c74230b4a9 Bump to 0.2.3 2018-04-17 13:07:43 -07:00
Alex Crichton
9a6a15f605 Fix compilation and support on 32-bit targets 2018-04-17 11:42:10 -07:00
Alex Crichton
f80a7067a0 Use a struct instead of a bool variant
Helps it be a bit more readable!
2018-04-17 11:29:03 -07:00
Alex Crichton
0e032955fb Use a length accessor instead of byteLength
This way we should be naturally compatible with normal JS arrays that get passed
in as well!

Closes #133
2018-04-16 13:50:21 -07:00
Alex Crichton
efb64b87d4 Extract Rust2Js like Js2Rust was extracted
Along the way clean up a lot of the formatting of the auto-generated code to
make it a bit prettier by default.
2018-04-16 13:31:56 -07:00
Alex Crichton
5efde3abe9 Be sure to generate classes for empty structs
Closes #131
2018-04-16 08:05:18 -07:00
Alex Crichton
f8ecf912c7 Clean up the generated JS a bit 2018-04-16 07:56:55 -07:00
Alex Crichton
d96e7309ad Format generated JS of export shims nicer
Apply a few indents and a few strategic slashes to make it look a bit nicer
2018-04-16 07:56:05 -07:00
Alex Crichton
c64f178543 Support closures with "rich" arguments
This commit adds support for closures with arguments like strings and such. In
other words, closures passed to JS can now have the same suite of arguments as
all functions that can be exported from Rust, as one might expect!

At this time due to the way trait objects work closures still cannot use types
with references like `&str`, but bare values like `String` or `ImportedType`
should work just fine.

Closes #104
2018-04-16 07:51:51 -07:00
konstin
f63635fce9 Fix merge-breakage 2018-04-15 15:36:59 +02:00
konstin
3999642f66 Merge remote-tracking branch 'upstream/master' into new 2018-04-15 01:50:23 +02:00
konstin
770d7365c4 Fix compilation and docs
The compilation part is effectively a cherry pick from master
2018-04-15 01:39:43 +02:00
konstin
f45ce1f239 Do only use ConstructorToken when needed
Also removing some effectively dead code
2018-04-15 01:29:09 +02:00
Alex Crichton
0e6325d833 Overhaul the conversion traits
This commit overhauls the conversion traits used for types crossing the Rust/JS
boundary. Previously there were a few ad-hoc traits but now there've been
slightly reduced and decoupled.

Conversion from Rust values to JS values is now exclusively done through
`IntoWasmAbi` with no special treatment for references. Conversion from JS to
Rust is a bit trickier as we want to create references in Rust which have
implications in terms of safety. As a result there are now three traits for
this, `FromWasmAbi`, `RefFromWasmAbi`, and `RefMutFromWasmAbi`. These three
traits are implemented for various types and specially dispatched to depending
on the type of argument in the code generator.

The goal of this commit is to lay the groundwork for using these traits in
closures with straightforward-ish definitions.
2018-04-14 12:01:07 -07:00
Alex Crichton
9976971e7e Fix CI 2018-04-14 11:34:37 -07:00
konstin
e87b32fb22 Allow arbitratry constructor names 2018-04-14 11:19:17 -07:00
konstin
32ab5a5644 Suppport for javascript constructors
This is a conservative version where the function used for the constructor must be called `new`
2018-04-14 11:19:17 -07:00
Alex Crichton
a8d6ca3d62 Add support for mutable stack closures
This commit adds support for passing `&mut FnMut(..)` to JS via imports. These
closures cannot be invoked recursively in JS (they invalidate themselves while
they're being invoked) and otherwise work the same as `&Fn(..)` closures.

Closes #123
2018-04-14 11:16:16 -07:00
Alex Crichton
3305621012 Overhaul how type information gets to the CLI
This commit is a complete overhaul of how the `#[wasm_bindgen]` macro
communicates type information to the CLI tool, and it's done in a somewhat...
unconventional fashion.

Today we've got a problem where the generated JS needs to understand the types
of each function exported or imported. This understanding is what enables it to
generate the appropriate JS wrappers and such. We want to, however, be quite
flexible and extensible in types that are supported across the boundary, which
means that internally we rely on the trait system to resolve what's what.

Communicating the type information historically was done by creating a four byte
"descriptor" and using associated type projections to communicate that to the
CLI tool. Unfortunately four bytes isn't a lot of space to cram information like
arguments to a generic function, tuple types, etc. In general this just wasn't
flexible enough and the way custom references were treated was also already a
bit of a hack.

This commit takes a radical step of creating a **descriptor function** for each
function imported/exported. The really crazy part is that the `wasm-bindgen` CLI
tool now embeds a wasm interpreter and executes these functions when the CLI
tool is invoked. By allowing arbitrary functions to get executed it's now *much*
easier to inform `wasm-bindgen` about complicated structures of types. Rest
assured though that all these descriptor functions are automatically unexported
and gc'd away, so this should not have any impact on binary sizes

A new internal trait, `WasmDescribe`, is added to represent a description of all
types, sort of like a serialization of the structure of a type that
`wasm-bindgen` can understand. This works by calling a special exported function
with a `u32` value a bunch of times. This means that when we run a descriptor we
effectively get a `Vec<u32>` in the `wasm-bindgen` CLI tool. This list of
integers can then be parsed into a rich `enum` for the JS generation to work
with.

This commit currently only retains feature parity with the previous
implementation. I hope to soon solve issues like #123, #104, and #111 with this
support.
2018-04-14 11:15:28 -07:00
Alex Crichton
eb9a6524b9 Bump to 0.2.2 2018-04-13 07:50:24 -07:00
Alex Crichton
8854936599 Tweak initialization with --no-modules
* Have the global `wasm_bindgen` variable be a function which runs
  initialization rather than exporting an `init` function.
* Save off the wasm object on `wasm_bindgen.wasm` so the memory can be accessed
* Tidy up the code slightly
2018-04-13 07:44:35 -07:00
Alex Crichton
98016324f7 Merge branch 'umd' of https://github.com/csharad/wasm-bindgen 2018-04-13 07:34:27 -07:00
Sharad Chand
85c9f2319c Expose on window.wasm_bindgen 2018-04-13 14:25:27 +05:45
Sharad Chand
ffdb8a6a32 Simplified the preamble 2018-04-12 10:31:13 +05:45
Alex Crichton
b9b8756cd0 Demangle Rust symbols by default 2018-04-11 11:43:18 -07:00
Sharad Chand
aa6487b6f1 panic when modules used 2018-04-11 14:22:20 +05:45
Sharad Chand
8c935d5d94 Change flag to --no-modules 2018-04-11 13:59:58 +05:45
Mark Andrus Roberts
0aef97215c Call fs.readFileSync with __dirname
Node's fs APIs resolve relative paths relative to the current working directory:

https://nodejs.org/api/fs.html#fs_file_paths

This creates a problem if you try to require the wasm-bindgen-generated
JavaScript from a different directory. For example, if you have

  build/foo.js
  build/foo_bg.js
  build/foo_bg.wasm

and another script, script/index.js, that requires build/foo.js. We can instead
use __dirname to get the correct path to the file.
2018-04-09 17:38:22 -07:00
Alex Crichton
656d69816d Move all tests to the same suite
Nowadays the compile times are mitigated with incremental compilation and
otherwise it's much more ergonomic to run only one test if they're all in the
same suite.
2018-04-09 15:32:06 -07:00
Alex Crichton
60ac57331b Bump to 0.2.1 2018-04-09 15:18:39 -07:00
Alex Crichton
a3e5485b86 Add examples/documentation for closures 2018-04-09 14:34:21 -07:00
Alex Crichton
66bdd92fa2 More aggressively gc module
As soon as we've removed unneeded exports immediately run a gc pass to ensure
that we don't bind functions in JS that don't actually end up getting needed.
2018-04-09 14:34:21 -07:00
Alex Crichton
f7f0d578e7 Support long-lived closures
Docs coming soon!
2018-04-09 14:34:21 -07:00
Alex Crichton
28d6c1bc12 Support stack closures with up to 7 arguments 2018-04-09 14:34:21 -07:00
Alex Crichton
c0cad447c1 Initial support for closures
This commit starts wasm-bindgen down the path of supporting closures. We
discussed this at the recent Rust All-Hands but I ended up needing to pretty
significantly scale back the ambitions of what closures are supported. This
commit is just the initial support and provides only a small amount of support
but will hopefully provide a good basis for future implementations.

Specifically this commit adds support for passing `&Fn(...)` to an *imported
function*, but nothing elese. The `&Fn` type can have any lifetime and the JS
object is invalidated as soon as the import returns. The arguments and return
value of `Fn` must currently implement the `WasmAbi` trait, aka they can't
require any conversions like strings/types/etc.

I'd like to soon expand this to `&mut FnMut` as well as `'static` closures that
can be passed around for a long time in JS, but for now I'm putting that off
until later. I'm not currently sure how to implement richer argument types, but
hopefully that can be figured out at some point!
2018-04-09 14:34:21 -07:00
Alex Crichton
a699455f03 Walk the prototype chain looking for descriptors
Looks like this breakage may occur in some scenarios so let's try to
future-proof ourselves!

Closes #109
2018-04-09 06:16:41 -07:00
Sharad Chand
ee1e3abd45 Am an idiot 2018-04-07 13:22:03 +05:45
Sharad Chand
b9192592a9 Updated docopts 2018-04-07 13:17:56 +05:45
Sharad Chand
e8f4b7ed86 Skip window assertions 2018-04-07 13:08:57 +05:45
Sharad Chand
0bd8713bd5 Dropped node support in umd -> amd 2018-04-07 13:06:36 +05:45
Sharad Chand
2b9af53030 wasm is compiled, mod in uncompiled 2018-04-06 12:59:07 +05:45
Sharad Chand
1a428d69da {global} not referenced 2018-04-05 20:30:58 +05:45
Sharad Chand
2877d0bdb6 UMD import added 2018-04-05 19:50:26 +05:45
Sharad Chand
3a83b02de0 Added umd switch 2018-04-04 20:06:53 +05:45
Alex Crichton
9723fdd69b
Merge pull request #100 from sendilkumarn/remove-coder-func
Reduce the JS file size and optimizing encoder and decoder functions
2018-04-04 08:46:36 -05:00
Sendil Kumar N
64d7c8d082
Update lib.rs 2018-04-04 11:27:27 +02:00
Sendil Kumar
9421edaab5 add missed out TextEncoder 2018-04-04 11:22:34 +02:00
Sendil Kumar
6d5afbb3d2 reduce the js file generated code
remove node test for browser test

update usages

revert test-support changes
2018-04-04 11:22:32 +02:00
Alex Crichton
0d1759abd5 Add description to backend crate 2018-04-03 14:02:04 -07:00
Alex Crichton
de3a7e3242 Remove nodejs-checking logic from math exports
Instead create a temporary vector which is used to later invoke the generic
`export` function
2018-04-03 13:29:26 -07:00
Alex Crichton
62e9f580d0 Use Context::export in write_classes
No need to doubly check for `nodejs`
2018-04-03 13:25:10 -07:00
Alex Crichton
23f6049619 Fixup various refactoring issues 2018-04-03 13:20:56 -07:00
Alex Crichton
7f614c3c3a Reduce node/browser duplication
Centralize the export of a function to one location to reduce duplication in
various other locations checking whether Node is being targeted or not.
2018-04-03 13:12:28 -07:00
Alex Crichton
cc11505dc8 Remove an unused unsafe block 2018-04-03 12:53:24 -07:00
Alex Crichton
455e86ef6d Merge branch 'node-math' of https://github.com/ashleygwilliams/wasm-bindgen 2018-04-03 12:53:15 -07:00
Alex Crichton
1ff9ccf072 Tighten up getStringFromWasm a bit
no need for some extra locals here
2018-04-03 12:44:35 -07:00
Alex Crichton
978b5ada63 Tighten up passStringToWasm a bit
Only emit `throw` on debug mode primarily
2018-04-03 12:44:09 -07:00
Alex Crichton
f1e8e2bee0 Remove GLOBAL_ARGUMENT_CNT JS binding
This is easier to manage statically so no need to track it dynamically
2018-04-03 12:38:33 -07:00
Alex Crichton
a805e04a81 Track next_global at codegen time
No need to track it at runtime as we should statically know its value!
2018-04-03 12:24:35 -07:00
Alex Crichton
8e5f5d20fc Remove accidental double braces 2018-04-03 12:24:19 -07:00
Alex Crichton
76cc1ca295 Fix imports of TextEncoder/TextDecoder 2018-04-03 08:09:25 -07:00
Alex Crichton
30b1964255 Bump all crates to 0.2 2018-04-03 07:10:07 -07:00
Alex Crichton
bb2e0c205f
Merge pull request #77 from dflemstr/wasm-construct-js-class
Add support for constructing JsValue instances generically
2018-04-03 16:08:30 +02:00
Alex Crichton
782378e7c0 Update dependencies 2018-04-03 07:07:14 -07:00
David Flemström
540ccfac9d Only generate JS class constructor export if import is needed 2018-04-03 11:28:25 +02:00
Alex Crichton
03433a0ef6 Update to recent WasmBoundary abi changes 2018-04-02 09:59:08 -07:00
David Flemström
73619b5d15 Add support for constructing JsValue instances generically 2018-04-02 09:59:01 -07:00