Commit Graph

46 Commits

Author SHA1 Message Date
Alex Crichton
57693ee11a Bump to 0.2.17 2018-08-16 23:36:42 -07:00
Nick Fitzgerald
8974a57fb9 Bump to version 0.2.16 2018-08-13 14:27:10 -07:00
Alex Crichton
11553a1af2 Implement JsCast for all imported types
This commit implements the `JsCast` trait automatically for all imported types
in `#[wasm_bindgen] extern { ... }` blocks. The main change here was to generate
an `instanceof` shim for all imported types in case it's needed.

All imported types now also implement `AsRef<JsValue>` and `AsMut<JsValue>`
2018-08-07 12:59:51 -07:00
Anton Danilkin
e70c9015ff Rename special to indexing 2018-08-07 00:06:04 +03:00
Anton Danilkin
ef3f086102 Merge remote-tracking branch 'upstream/master'
# Conflicts:
#	crates/webidl/src/first_pass.rs
#	crates/webidl/src/lib.rs
#	crates/webidl/src/util.rs
2018-08-06 23:37:12 +03:00
Alex Crichton
d5b81595ec Remove support for the version attribute
First added in #161 this never ended up panning out, so let's remove the
experimental suport which isn't actually used by anything today and hold off on
any other changes until an RFC happens.
2018-08-06 13:30:28 -05:00
Anton Danilkin
fd2b2140a9 Add support for getters, setters and deleters 2018-08-05 23:32:51 +03:00
Alex Crichton
eee71de0ce
Support asynchronous tests (#600)
* Tweak the implementation of heap closures

This commit updates the implementation of the `Closure` type to internally store
an `Rc` and be suitable for dropping a `Closure` during the execution of the
closure. This is currently needed for promises but may be generally useful as
well!

* Support asynchronous tests

This commit adds support for executing tests asynchronously. This is modeled
by tests returning a `Future` instead of simply executing inline, and is
signified with `#[wasm_bindgen_test(async)]`.

Support for this is added through a new `wasm-bindgen-futures` crate which is a
binding between the `futures` crate and JS `Promise` objects.

Lots more details can be found in the details of the commit, but one of the end
results is that the `web-sys` tests are now entirely contained in the same test
suite and don't need `npm install` to be run to execute them!

* Review tweaks

* Add some bindings for `Function.call` to `js_sys`

Name them `call0`, `call1`, `call2`, ... for the number of arguments being
passed.

* Use oneshots channels with `JsFuture`

It did indeed clean up the implementation!
2018-08-01 15:52:24 -05:00
Nick Fitzgerald
9a0470b1c4 Bump to 0.2.15 2018-07-26 14:53:59 -07:00
Nick Fitzgerald
3f5a0fb31c Bump to 0.2.14 2018-07-25 09:46:45 -07:00
Alex Crichton
82c2dfa7b2
Bump to 0.2.13 (#536) 2018-07-21 23:10:47 -05:00
Alex Crichton
aa348f963f
Bump to 0.2.12 (#515)
* Bump to 0.2.12

* Update all version numbers and deps
* Update all listed authors to `["The wasm-bindgen Developers"]`
* Update `repository` links to specific paths for each crate
* Update `homepage` links to the online book
* Update all links away from `alexcrichton/wasm-bindgen`
* Add `#[doc]` directives for HTML URLs

* Update more version requirements

* Fill out CHANGELOG
2018-07-19 14:57:04 -05:00
R. Andrew Ohana
80384d8da9 address my comments for #470 2018-07-13 22:36:51 -07:00
Julius Rakow
862e4c50f6
backend: add const to ast 2018-07-13 19:59:21 +02:00
Stephan Wolski
a981dfd507
webidl: initial enum support
Add enum support to the WebIDL interface generator.
2018-07-10 20:28:34 -04: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
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
R. Andrew Ohana
0938858aa8 webidl: add support for static attributes 2018-06-15 12:22:14 -07: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
Alex Crichton
4c27c349ea Bump to 0.2.11 2018-05-24 08:56:28 -07:00
Alex Crichton
627ca1d638 Bump to 0.2.10 2018-05-17 10:40:24 -07:00
Alex Crichton
5d28b90069 Bump to 0.2.9 2018-05-11 16:04:41 -07:00
Alex Crichton
fbb12f519b Bump to 0.2.8 2018-04-30 19:23:44 -07:00
Alex Crichton
befdf07a07 Bump to 0.2.7 2018-04-27 19:48:57 -07:00
Alex Crichton
acb5eac96a Bump to 0.2.6 2018-04-26 19:14:09 -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
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
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
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
055a8fb803 Bump to 0.2.4 2018-04-18 07:18:11 -07:00
Alex Crichton
c74230b4a9 Bump to 0.2.3 2018-04-17 13:07:43 -07:00
Alex Crichton
5efde3abe9 Be sure to generate classes for empty structs
Closes #131
2018-04-16 08:05:18 -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
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
60ac57331b Bump to 0.2.1 2018-04-09 15:18:39 -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
30b1964255 Bump all crates to 0.2 2018-04-03 07:10:07 -07:00
David Flemström
73619b5d15 Add support for constructing JsValue instances generically 2018-04-02 09:59:01 -07:00
Alex Crichton
7880545b3b Finish fixing fallout in all tests 2018-03-31 09:15:39 -07:00
Alex Crichton
cdbb31f3a9 Start removal of vector special-casing
This commit starts wasm-bindgen down a path of removing the special
casing it currently has around vectors, slices, and strings. This has
long been a thorn in wasm-bindgen's side as it doesn't handle other
kinds of vectors and otherwise is very inflexible with future additions.
Additionally it leads to a lot of duplicated-ish code throughout various
portions of codegen.

The fundamental reason for this was that two arguments were required to
be passed back to wasm, and I couldn't figure out a way to shove both
those arguments into a function argument. The new strategy here is that
there is one global stack well known to both JS and Rust which arguments
*may* also be transferred between.

By default all ABI arguments pass as literal function arguments, but if
two or more arguments need to be passed then the extra ones are all
passed through this global stack. The stack is effectively temporary
scratch space when crossing the JS/Rust boundary (both ways). No long
term storage is intended here.

The `simple` test is passing as a result of this commit, using strings
internally. The `Vector` type in the AST has been removed (yay!) and the
bulk of the implementation of slices and vectors now resides in the
`wasm-bindgen` crate itself, defining how to pass all these arguments
around. The JS generator, however, still needs to know about all the
sorts of vectors so it can generate appropriate code for JS.

Future commits will continue cleanup and get the rest of the tests
working.
2018-03-31 07:57:47 -07:00
Nick Fitzgerald
393841779a Rename directories to remove "wasm-bindgen-" prefix in sub-crates 2018-03-29 08:28:25 -07:00