Commit Graph

912 Commits

Author SHA1 Message Date
Alex Crichton
a117c057fb More conservatively patch closure descriptors
Previously `wasm-bindgen` would take its `breaks_if_inlined` shims and
attempt to remove them entirely, replacing calls to `breaks_if_inlined`
to the imported closure factories. This worked great in that it would
remove the `breaks_if_inlined` funtion entirely, removing the "cost" of
the `#[inline(never)]`.

Unfortunately as #864 discovered this is "too clever by half". LLVM's
aggressive optimizations won't inline `breaks_if_inlined`, but it may
still change the ABI! We can't replace calls to `breaks_if_inlined` if
the signature changes, because the function its calling has a fixed signature.

This commit cops out a bit and instead of replacing calls to
`breaks_if_inlined` to the imported closure factories, we instead
rewrite calls to `__wbindgen_describe_closure` to the closure factories.
This means that the `breaks_if_inlined` shims do not get removed. It
also means that the closure factory shims have a third and final
argument (what would be the function pointer of the descriptor function)
which is dead and unused.

This should be a functional solution for now and let us iterate on a
true fix later on (if needed). For now the cost of this
`#[inline(never)]` and the extra unused argument should be quite small.

Closes #864
2018-09-21 13:34:59 -07:00
Nick Fitzgerald
c517b00825
Merge pull request #861 from alexcrichton/less-moz
Purge a number of Mozilla-specific WebIDL
2018-09-21 09:57:12 -07:00
Ivan Enderlin
54b2482d03
doc(readme) Add links to doc & clean
This patch adds a link to the crate's documentation. It also removes a reference to #275, which is closed now.
2018-09-21 10:08:11 +02:00
Alex Crichton
a2d6a8ff53 Use anyref helper to reduce some code duplication 2018-09-20 17:26:49 -07:00
Alex Crichton
8c720bee50 Purge a number of Mozilla-specific WebIDL
Did a bunch of grepping for `moz*` and searched for "moz" in rustdoc,
deleting anything that looked mozilla-specific. Now there's nothing left
with the "moz" prefix in rustdoc!
2018-09-20 17:19:36 -07:00
Alex Crichton
3efe51eb8b Reorganize and rewrite examples
This commit is a large-ish scale reorganization of our examples. The
main goal here is to have a dedicated section of the guide for example,
and all examples will be listed there. Each example's `README` is now
just boilerplate pointing at the guide along with a blurb about how to
run it.

Some examples like `math` and `smorgasboard` have been deleted as they
didn't really serve much purpose, and others like `closures` have been
rewritten with `web-sys` instead of hand-bound bindings.

Overall it's hoped that this puts us in a good and consistent state for
our examples, with all of them being described in the guide, excerpts
are in the guide, and they're all relatively idiomatically using
`web-sys`.
2018-09-20 16:45:30 -07:00
Anton Danilkin
f808594efa Add String.raw 2018-09-20 00:40:14 +03:00
Nick Fitzgerald
e9212cfa43
Merge pull request #853 from alexcrichton/clone
Add `#[derive(Clone, Debug)]` to all web-sys types
2018-09-19 13:20:40 -07:00
Michael Hoffmann
f7b511588b Add binding for Object.entries() 2018-09-19 21:32:05 +02:00
Michael Hoffmann
326e4c0262 Add binding for Object.getPrototypeOf() 2018-09-19 21:10:40 +02:00
Michael Hoffmann
76969bd1e3 Add binding for Object.getOwnPropertySymbols() 2018-09-19 20:58:46 +02:00
Alex Crichton
3f68c43d06 Add #[derive(Clone, Debug)] to all web-sys types
They're all cloneable and debuggable!
2018-09-19 11:54:32 -07:00
Michael Hoffmann
4e18493fd7 Add binding for Object.getOwnPropertyNames() 2018-09-19 20:43:50 +02:00
Alex Crichton
5832ff3ca1
Merge pull request #847 from alexcrichton/fix-window
Move all methods on `Window` back to methods
2018-09-18 16:59:46 -07:00
Alex Crichton
a83d561bb3 Add js_sys::global 2018-09-18 15:40:49 -07:00
Alex Crichton
300aca38c2 Squelch warnings in webidl tests 2018-09-18 14:30:24 -07:00
Alex Crichton
604ecd9529 Squelch warnings in webidl tests 2018-09-18 14:30:01 -07:00
Alex Crichton
bbc46f92c6 Fix web-sys Location test 2018-09-18 14:16:01 -07:00
Alex Crichton
7cf4213283 Allow returning Result from functions
This commit adds support for exporting a function defined in Rust that returns a
`Result`, translating the `Ok` variant to the actual return value and the `Err`
variant to an exception that's thrown in JS.

The support for return types and descriptors was rejiggered a bit to be a bit
more abstract and more well suited for this purpose. We no longer distinguish
between functions with a return value and those without a return value.
Additionally a new trait, `ReturnWasmAbi`, is used for converting return values.
This trait is an internal implementation detail, however, and shouldn't surface
itself to users much (if at all).

Closes #841
2018-09-18 13:13:59 -07:00
Alex Crichton
fe31615ca1 Fix webidl-tests fallout 2018-09-17 17:36:53 -07:00
Alex Crichton
f24828a16b Add a top-level web_sys::window function
Returns `Option<Window>` and can be used as a convenience to get a handle to the
global `window` object.
2018-09-17 17:36:53 -07:00
Alex Crichton
99e1b352e5 Translate the WindowProxy type to Window.
This is roughly defined by
https://html.spec.whatwg.org/multipage/window-object.html#windowproxy and
otherwise fits the bill how otherwise only `interface WindowProxy;` exists in
the WebIDL.
2018-09-17 17:36:53 -07:00
Alex Crichton
8cf9da4981 Translate the Global attribute to "structural"
All APIs on `Windows` are tagged where `Window` has `[Global]`, and they all
need to be structurally accessed rather than through a prototype.
2018-09-17 17:36:53 -07:00
Alex Crichton
c67582a315 Remove support for scoped static methods
This is intended to address #834 where we don't actually want methods scoped
like this! Instead we'll provide one unique accessor for the `window` object
itself.
2018-09-17 17:36:53 -07:00
Nick Fitzgerald
a37fa45100
Merge pull request #845 from alexcrichton/more-webidl
Uncommented some WebIDL TODO
2018-09-17 15:29:49 -07:00
Nick Fitzgerald
b38b9da499
Merge pull request #846 from alexcrichton/no-modules
Remove `Module` node from the backend AST
2018-09-17 15:19:57 -07:00
Nick Fitzgerald
6ce5e6e1dd
Merge pull request #831 from alexcrichton/more-webidl-types
Add bindings for a few more "long long" types
2018-09-17 15:17:17 -07:00
Alex Crichton
9daa11592a Remove Module node from the backend AST
This is a roundabout way to say that this addresses the last comment on #23,
namely if you only use the `console` submodule from `web_sys` it doesn't
actually link correctly!

The problem here has to do with codegen units and the compiler. The compiler
will create a codegen unit for each `mod` in the source code. If a codegen unit
isn't actually used, then the codegen unit is removed from the final link step.
This causes problems for web-sys where the JSON description of our program was
part of the main CGU but not in each submodule, so when submodules were only
used the descriptor program in the main CGU was not included.

The fix in this commit is to instead generate a descriptor program in the
submodule itself instead of leaving it in the main CGU. By removing the `Module`
node in the AST this naturally happens as the descriptor is only generated in
the same module as all other associated items.
2018-09-17 13:50:26 -07:00
Alex Crichton
a02c4c1410 Uncommented some WebIDL TODO
This partially reverts commit 4b4bed5ce2 by
restoring a number of items to our WebIDL

Closes #839
2018-09-17 13:25:10 -07:00
Nick Fitzgerald
1ee579093b
Merge pull request #832 from myelin-ai/device-pixel-ratio
Add devicePixelRatio to Window
2018-09-17 10:12:43 -07:00
Sendil Kumar N
a897715f50
Merge pull request #838 from brisad/object-get-descriptors
Object get descriptors
2018-09-17 10:47:46 +02:00
Michael Hoffmann
2d91fa11b5 Add binding for Object.getOwnPropertyDescriptors() 2018-09-16 23:02:46 +02:00
Michael Hoffmann
b005e96fd9 Add binding for Object.getOwnPropertyDescriptor() 2018-09-16 22:55:15 +02:00
Anton Danilkin
61eb7df0c8 Update weedle 2018-09-16 23:39:00 +03:00
Anton Danilkin
df18c4b042 Update weedle: use special instead of specials 2018-09-16 21:19:20 +03:00
Michael Hoffmann
191e7dc1fb Add binding for Object.defineProperties() 2018-09-15 22:30:27 +02:00
Ruben Schmidmeister
170ac21473
Add devicePixelRatio attribute 2018-09-15 12:42:23 +02:00
Alex Crichton
ae60bb4ba8 Translate LongLong types to f64
Any LongLong still present after flattening now gets translated to a `f64` type
so we can bind these types. While not a true integral value or truely 64-bits of
integer precision, it's all JS has anyway!
2018-09-14 18:54:29 -07:00
Alex Crichton
941397745d Enable DOMTimeStamp as UnsignedLongLong
This is apparently how webidl defines it!
2018-09-14 18:44:38 -07:00
Josh Triplett
96a70c41be reset_indentation: Don't emit indentation on blank lines
This resulted in trailing whitespace in the generated file. In addition
to wasting space in a file that gets served over the wire, this also
gets highlighted as a problem when reviewing the generated file in an
editor that highlights trailing whitespace.
2018-09-13 22:13:07 -07:00
Josh Triplett
1c52fb1b2f Remove leading and trailing blanks from the --no-modules output
The output using modules already uses string formatting that carefully
avoids emitting leading and trailing blanks; adjust the --no-modules
output to match.
2018-09-13 22:10:59 -07:00
Nick Fitzgerald
2fc499d66d
Merge pull request #819 from fitzgen/webidl-interfaces-should-extend-object
webidl: All interfaces implicitly extend `Object`
2018-09-12 16:21:48 -07:00
Nick Fitzgerald
e2e815a477 guide: Add documentation for testing with wasm-bindgen-test 2018-09-12 15:40:09 -07:00
Nick Fitzgerald
93a510ef93 webidl: All interfaces implicitly extend Object
This information is embedded within the algorithm for constructing interfaces
and their prototypes in the section for ECMAScript glue in the WebIDL spec...

This really *should* make the `wasm_bindgen_backend::ast::ImportType::extends`
member from a `Vec<Ident>` into a `Vec<syn::Path>` so that we could use
`js_sys::Object` in the extends field, but that is a huge pain because then the
`ImportedTypes` trait needs to be changed, and all of its implementers, etc...
2018-09-12 15:25:09 -07:00
Alex Crichton
a59a10d6df Fix tests on nightly 2018-09-12 10:20:03 -07:00
Alex Crichton
e5af22ee4e
Merge pull request #814 from brisad/object-define-property
Add binding for Object.defineProperty()
2018-09-12 09:13:03 -07:00
Michael Hoffmann
fe6ad5447e Add binding for Object.defineProperty() 2018-09-12 07:39:39 +02:00
Alex Crichton
9ca024a812
Merge pull request #792 from afdw/master
Add support for variadic arguments in WebIDL
2018-09-11 16:05:56 -07:00
Anton Danilkin
096848199e Introduce a constant 2018-09-11 23:10:03 +03:00
Nick Fitzgerald
f6b199cfb0 web-sys: Crate metadata should point to the web-sys section of the wasm-bindgen guide 2018-09-10 17:56:03 -07:00
Anton Danilkin
9f4ed536df Use js_sys::Array, generate _n methods for ergonomics 2018-09-11 00:37:59 +03:00
Alex Crichton
8181f7fa95 Implement WebIDL callback interfaces
This commit implements callback interfaces for WebIDL, the final WebIDL
construct that we were unconditionally ignoring! Callback interfaces are
implemented as dictionaries of callbacks. Single-operation callback interfaces
are also expanded when flattening to accept a `Function` as well, in accordance
with the WebIDL spec.

New features have been added to `web-sys` for all the new callback interface
types. Additionally the `EventTarget.webidl` was tweaked to not have
`EventListener?` as this is required for all functional usage and there's no
need to keep that sort of web browser compat here.

Closes #258
2018-09-10 12:00:50 -07:00
Alex Crichton
116a19962f Change how filtering is done in WebIDL
Instead of actually modifying the `FirstPassRecord` let's instead just skip
relevant entries when we come across them. This should help us retain knowledge
that `optional SomeImportedType arg` can be bound even though `SomeImportedType`
may not exist.

One small tweak was needed to modify the AST afterwards to remove `extends`
annotations which aren't actually defined, but other than that this should...

Closes #802
2018-09-10 11:58:31 -07:00
Alex Crichton
be4ead7c8a
Merge pull request #797 from alexcrichton/iterator
Implement the `Iterator` trait for JS iterators
2018-09-10 11:40:56 -07:00
Alex Crichton
b7d7d28418 Expand LongLong to (i32 or f64) instead of i64
This commit tweaks WebIDL expansion of the "long long" and "unsigned long long"
types to expand to a union of an 32-bit integer and a double. This reflects how
almost none of the APIs on the web today actually work with a `BigInt` (what the
previous Rust type of `i64` translates to) and how JS itself fundamentally
operates with these APIs.

Eventually this may not be necessary if we can natively connect to C++ engines
with the `i64` type, but until that day comes this should provide more useful
interfaces as they shoudl work in all browsers.

Closes #800
2018-09-10 11:40:20 -07:00
Alex Crichton
f2608d3155 Implement the Iterator trait for JS iterators
This commit implements the standard library's `Iterator` trait for the
`js_sys::Iterator` type, using the iterator protocol described on [MDN]

Closes #777

[MDN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
2018-09-10 10:38:04 -07:00
Anton Danilkin
14eb317509 Merge remote-tracking branch 'upstream/master' 2018-09-07 13:46:20 +03:00
Alex Crichton
f18b10ca52 Bump to 0.2.21 2018-09-06 22:10:11 -07:00
Alex Crichton
e632dd3fda Parse names before we take the module
Otherwise when we try to parse the names there's no module with contents!
2018-09-06 22:08:04 -07:00
Alex Crichton
457efc0f31 Implement support for WebIDL Callback types
This commit adds support for the WebIDL `Callback` type by translating all
callbacks to the `js_sys::Function` type. This will enable passing raw JS values
into callbacks as well as Rust valus using the `Closure` type.

This commit doesn't currently implement "callback interfaces" in WebIDL, that's
left for a follow-up commit.
2018-09-06 19:50:46 -07:00
Alex Crichton
1cd2229c66
Merge pull request #795 from fitzgen/lots-more-js-sys-bindings
Lots more js-sys bindings
2018-09-06 16:42:18 -07:00
Nick Fitzgerald
bfff31fcb9 js-sys: Expose bindings to WebAssembly.Table.prototype.set
Part of #275
2018-09-06 15:02:01 -07:00
Alex Crichton
8f9514d216 Update syn to 0.15
New and faster parsers!
2018-09-06 15:01:24 -07:00
Nick Fitzgerald
8dbb0fc5f2 js-sys: Expose bindings to WebAssembly.Table.prototype.grow
Par of #275
2018-09-06 14:58:46 -07:00
Nick Fitzgerald
2d4f36c9da js-sys: Add bindings to WebAssembly.Table.prototype.get
Part of #275
2018-09-06 14:54:49 -07:00
Alex Crichton
e67397ec27
Merge pull request #793 from alexcrichton/bump
Bump to 0.2.20
2018-09-06 14:49:54 -07:00
Alex Crichton
9d5898ab48 Bump to 0.2.20 2018-09-06 14:49:43 -07:00
Nick Fitzgerald
fb5e6e9c06 js-sys: Add bindings for WebAssembly.instantiateStreaming
Part of #275
2018-09-06 14:47:37 -07:00
Alex Crichton
5a3cd893e0 Implement AsRef<JsValue> for Closure<T>
This commit adds an implementation of `AsRef<JsValue>` for the `Closure<T>`
type. Previously this was not possible because the `JsValue` didn't actually
exist until the closure was passed to JS, but the implementation has been
changed to ... something a bit more unconventional. The end result, however, is
that `Closure<T>` now always contains a `JsValue`.

The end result of this work is intended to be a precursor to binding callbacks
in `web-sys` as `JsValue` everywhere but still allowing usage with `Closure<T>`.
2018-09-06 14:46:59 -07:00
Nick Fitzgerald
021cbbab71 js-sys: Add bindings for WebAssembly.instantiate
Part of #275
2018-09-06 14:35:45 -07:00
Nick Fitzgerald
8b5f5a7560 js-sys: Add exports getter to WebAssembly.Instance
Part of #275
2018-09-06 14:16:28 -07:00
Nick Fitzgerald
cb2aa999c0 js-sys: Define imports for WebAssembly.Instance and its constructor
Part of #670 and #275
2018-09-06 14:16:18 -07:00
Nick Fitzgerald
66d155d708 js-sys: Add extends to Reflect
Part of #670
2018-09-06 13:42:16 -07:00
Nick Fitzgerald
bfff8661c1 js-sys: Add extends to Math
Part of #670
2018-09-06 13:39:30 -07:00
Nick Fitzgerald
5df2347a7a js-sys: Add extends to JSON
Part of #670
2018-09-06 13:32:31 -07:00
Alex Crichton
cda71757d3 Tweak ArrayBuffer IDL type expansion slightly
A few small changes here:

* `ArrayBufferView` and `BufferSource` are expanded to themselves plus
  `Uint8ArrayMut` instead of `Object` to ensure we keep the original type.
* Generating an argument type for `ArrayBufferView`, `BufferSource`, and
  `Object` all now generate shared references instead of owned objects, which is
  a little more consistent with the other interface types.
2018-09-06 10:09:03 -07:00
Anton Danilkin
1c0a34ff8e Add support for variadic arguments in WebIDL 2018-09-06 20:02:12 +03:00
Benjamin Kampmann
6efbf5076c Adding Uint8ArrayMut, disable mutability for all other than this one 2018-09-06 16:24:43 +02:00
Benjamin Kampmann
3076e40b21 Require shared refs to be mutable 2018-09-06 16:24:17 +02:00
Benjamin Kampmann
8b08fc16c5 Making ArrayBufferView & BufferSource a union 2018-09-06 16:23:39 +02:00
Benjamin Kampmann
031ba39036 Bump weedle version 2018-09-06 16:22:26 +02:00
Benjamin Kampmann
cb8411b346 Add BufferSource && ArrayBufferView to &[u8] 2018-09-06 16:22:24 +02:00
Alex Crichton
038b087ba3 Provide docs.rs metadata for generating docs
Makes sure that docs.rs, when it supports it, provides all the documentation for
all our features!
2018-09-05 12:57:36 -07:00
Alex Crichton
269c491380
Gate web-sys APIs on activated features (#790)
* Gate `web-sys` APIs on activated features

Currently the compile times of `web-sys` are unfortunately prohibitive,
increasing the barrier to using it. This commit updates the crate to instead
have all APIs gated by a set of Cargo features which affect what bindings are
generated at compile time (and which are then compiled by rustc). It's
significantly faster to activate only a handful of features vs all thousand of
them!

A magical env var is added to print the list of all features that should be
generated, and then necessary logic is added to ferry features from the build
script to the webidl crate which then uses that as a filter to remove items
after parsing. Currently parsing is pretty speedy so we'll unconditionally parse
all WebIDL files, but this may change in the future!

For now this will make the `web-sys` crate a bit less ergonomic to use as lots
of features will need to be specified, but it should make it much more
approachable in terms of first-user experience with compile times.

* Fix AppVeyor testing web-sys

* FIx a typo

* Udpate feature listings from rebase conflicts

* Add some crate docs and such
2018-09-05 12:55:30 -07:00
Alex Crichton
c6d3011cff
Merge pull request #785 from afdw/master
Add initial support for unions in return types, add more fixes for case of identifiers
2018-09-05 09:26:42 -07:00
Anton Danilkin
e5f382eccf Remove support for non-object unions, add more comments 2018-09-05 18:15:02 +03:00
Alex Crichton
6b0cea73cd Fix regression of missing documentation
I forgot to add MDN docs for #765 to member operations, but this commit adds
them back!

Closes #786
2018-09-04 14:52:56 -07:00
Anton Danilkin
fcd890a70e Remove dead code 2018-09-04 21:03:23 +03:00
Anton Danilkin
095f86fa51 Use object type whenever possible 2018-09-03 21:37:58 +03:00
Alex Crichton
a22094c023
Merge pull request #787 from bspeice/patch-1
[WIP] Remove --wasm2asm flag, use binaryen directly
2018-09-03 11:24:04 -07:00
Bradlee Speice
0965b77af8 Remove --wasm2js flag entirely 2018-09-03 13:56:55 -04:00
Alex Crichton
1a00e94324
Merge pull request #726 from derekdreery/variadic_js_functions
Support variadic javascript function parameters
2018-09-03 10:28:58 -07:00
Richard Dodd
5c7e638b8c Handle variadic no args more gracefully. 2018-09-03 09:50:26 +01:00
Bradlee Speice
c69833f253 Fix some references I missed 2018-09-02 22:32:19 -04:00
bspeice
724eb53d3c
Update wasm2es6js.rs
Binaryen renamed the tool to wasm2js instead of wasm2asm - https://github.com/WebAssembly/binaryen/pull/1642
2018-09-02 22:02:15 -04:00
Anton Danilkin
75ac7ca64e Fix nullable union types 2018-09-02 20:37:12 +03:00
Anton Danilkin
ff516d0211 Add initial support for unions in return types, add more fixes for case of identifiers 2018-09-02 15:09:51 +03:00
Richard Dodd
e279987fa4 Merge remote-tracking branch 'upstream/master' into variadic_js_functions 2018-09-01 22:24:27 +01:00
Richard Dodd
7d5d845608 Add docs and remove typecheck from variadic attribute 2018-09-01 13:55:35 +01:00
Alex Crichton
cfb4be8d3c Handle [Unforgeable] on interfaces
In addition to handling it on methods look like it also shows up on interfaces!

Closes #780
2018-08-31 17:38:34 -07:00