Commit Graph

1008 Commits

Author SHA1 Message Date
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
Alex Crichton
986f561209
Merge pull request #765 from alexcrichton/fix-some-overloads
Change how naming overloaded methods works
2018-08-31 09:49:46 -07:00
Richard Dodd
ce1cb84327 Merge branch 'master' into variadic_js_functions 2018-08-31 10:08:53 +01:00
Richard Dodd
958e557c86 try removing typecheck 2018-08-31 09:59:11 +01:00
Alex Crichton
3204c514ab Fix typos 2018-08-30 22:31:03 -07:00
Alex Crichton
c9c776b0b4 Review comments 2018-08-30 16:29:51 -07:00
Alex Crichton
de6aa6c97e Automatically change the schema version on all publishes
Closes #773
2018-08-30 13:26:07 -07:00
Alex Crichton
dd3dba9285 Delete lots of now-unused code 2018-08-30 12:54:54 -07:00
Alex Crichton
923abc7d85 Migrate constructors to new naming scheme 2018-08-30 12:54:54 -07:00
Alex Crichton
5a4a34d4a1 Migrate methods to new naming scheme
Allows deletion of `create_basic_method`!
2018-08-30 12:54:54 -07:00
Alex Crichton
15d4338abe Reimplement name disambiguation on overloading
This commit reimplements how we disambiguate function names on overloading.
Previously functions would be first be disambiguated if they had multiple
instances of the same name, and *then* functions would be disambiguated
aftewards by if their arguments expanded to more than one type to generate.

This commit instead collects everything into one list during the first pass.
This one list contains all signatures known for a given name. Later this list is
walked in one pass to generate all methods necessary, expanding names all at
once instead of two steps.

This should improve the naming of methods across multiple functions which also
have optional arguments. Support in this commit is just enough for namespaces,
but following commits will update the strategy for mixins/interfaces.
Additionally only new code was added in this commit which duplicates a lot of
functionality, but subsequent commits will remove the old code that will
eventually no longer be used.
2018-08-30 12:54:54 -07:00
Alex Crichton
0a18ca4490 Minor tweaks to first_pass.rs
Nothing much of consequence
2018-08-30 12:54:54 -07:00
Alex Crichton
6cf3b90e63 Deindent a few helper functions in dictionaries
No need for it to be an inner function now that it's using methods!
2018-08-30 12:54:54 -07:00
Alex Crichton
4f76a00024 Refactor creation of functions in the backend
This commit refactors the lowest-level primitive for creating functions into a
new `create_one_function` function. This doesn't take into account overloading
but is suitable for things like `create_{getter,setter}`. Eventually the
overloading will be implemented in terms of this function.
2018-08-30 12:54:54 -07:00
Alex Crichton
0a38e44f1f Refactor a method for listing all mixins
This'll hopefully be reusable in more than one location!
2018-08-30 12:54:54 -07:00
Alex Crichton
b9dc937d73 Refactor WebIDL code generation
This commit refactors WebIDL code generation to walk over the fields of
`FirstPassRecord` instead of walking the AST again. This helps remove
redundancies like checking `is_chrome_only` as well as revisiting partial
interfaces and such. This should make it more clear that the first pass's job is
to walk the AST and collect all relevant information, while the codegen pass is
purely about appending items to a `Program`.

Additionally this refactoring will also soon be used to prepare different data
structures for operation overloadings, avoiding the need to walk those ASTs
twice.
2018-08-30 12:54:54 -07:00
Alex Crichton
e25feccc11 webidl: Remove support for Uint8ClampedArray
Our bindings currently translate this to `&[u8]` which is actually `Uint8Array`.
We'll need to fix #421 before supporting this.
2018-08-30 10:34:50 -07:00
Alex Crichton
1565459107
Merge pull request #761 from alexcrichton/more-globals
web-sys: Add support for `Global`-scope methods
2018-08-28 18:36:53 -07:00
Alex Crichton
0fb31b2bc4 Don't enable nightly feature of proc-macro2
This is no longer needed as of rustc 1.30.0 and the `proc-macro2` crate will now
automatically detect whether it can use spans or not!
2018-08-28 17:24:43 -07:00
Alex Crichton
36b854b69c web-sys: Add support for Global-scope methods
This commit adds further support for the `Global` attribute to not only emit
structural accessors but also emit functions that don't take `&self`. All
methods on a `[Global]` interface will not require `&self` and will call
functions and/or access properties on the global scope.

This should enable things like:

    Window::location() // returns `Location`
    Window::fetch(...) // invokes the `fetch` function

Closes #659
2018-08-28 17:20:31 -07:00
Alex Crichton
5ed7b806d1 Fix getStringFromWasm for shared memory
We currently pass a raw view into wasm's memory for `getStringFromWasm`, but if
the memory is actually shared then `TextDecoder` rejects `SharedArrayBuffer` and
won't actually decode anything. Work around this for now with an extra copy into
a local buffer, and then pass that buffer to `getStringFromWasm` whenever memory
is shared.
2018-08-28 10:58:26 -07:00
Alex Crichton
f7e6fa2a04 Bump dependency on parity-wasm to 0.32.0
Brings support for atomic instructions!
2018-08-28 10:12:56 -07:00
Nick Fitzgerald
26c351ecf4 js-sys: Make MDN URLs into links 2018-08-27 15:18:48 -07:00
Alex Crichton
d9bc0a3176 Bump to 0.2.19 2018-08-27 13:39:23 -07:00
Alex Crichton
c89182b1fd Merge remote-tracking branch 'origin/master' into bump 2018-08-27 13:38:53 -07:00
Alex Crichton
98008b9e77 Bump to 0.2.18
At the same time, also add a `publish.rs` script to ease our publishing woes.
2018-08-27 13:37:55 -07:00
Alex Crichton
e1474110d4 Add an accessor for wasm's own memory as a JS object
In addition to closing #495 this'll be useful eventually when instantiating
multiple wasm modules from Rust as you'd now be able to acquire a reference to
the current module in Rust itself.
2018-08-27 11:05:55 -07:00
Alex Crichton
85fd49f90a Fix importing same types in two modules/crates
This'll hopefully fix fallout from 4f4da747ad
2018-08-27 09:59:47 -07:00
Alex Crichton
9fc43f8a19
Merge pull request #752 from alexcrichton/remove-hack
Remove a hack around an LLVM bug
2018-08-26 15:43:07 -07:00
Alex Crichton
856892d11d
Merge pull request #750 from alexcrichton/import-memory
Add support for modules importing memory
2018-08-26 15:42:24 -07:00
Alex Crichton
335c0b1ab6 Add support for modules importing memory
The default of Rust wasm binaries is to export the memory that they contain, but
LLD also supports an `--import-memory` option where memory is imported into a
module instead. It's looking like importing memory is along the lines of how
shared memory wasm modules will work (they'll all import the same memory).

This commit adds support to wasm-bindgen to support modules which import memory.
Memory accessors are tweaked to no longer always assume that the wasm module
exports its memory. Additionally JS bindings will create a `memory` option
automatically because LLD always imports memory from an `env` module which won't
actually exist.
2018-08-26 15:41:36 -07:00
Alex Crichton
0cd04ca85e
Merge pull request #749 from alexcrichton/wasm-memory
Add WebAssembly.Memory to js-sys
2018-08-26 15:40:58 -07:00
Alex Crichton
bb7ca348c2 Add WebAssembly.Memory to js-sys
This adds definitions for the `WebAssembly.Memory` type to `js-sys`.
2018-08-26 15:40:37 -07:00
Alex Crichton
4f4da747ad Remove a hack around an LLVM bug
This has since been fixed in rust-lang/rust#52506
2018-08-25 10:45:51 -07:00
Alex Crichton
9729efe50e Remove casting to &mut T for JS casts
I discussed this with @fitzgen awhile back and this sort of casting seems
especially problematic when you have code along the lines of:

    let mut x: HtmlElement = ...;
    {
        let y: &mut JsValue = x.as_ref();
        *y = 3.into();
    }
    x.some_html_element_method();

as that will immediately throw! We didn't have a use case for mutable casting
other than consistency, so this commit removes it for now. We can possibly add
it back in later if motivated, but for now it seems reasonable to try to avoid
these sorts of pitfalls!
2018-08-24 20:45:11 -07:00
Roberto Huertas
042cfad5ce feat(extends): extend promise 2018-08-24 02:15:02 +02:00
Richard Dodd
e92536f300 Allow Vec as well as slice 2018-08-21 13:47:00 +01:00
Richard Dodd
496d8cadd8 Actually span makes more sense on whole function 2018-08-21 13:12:25 +01:00
Richard Dodd
5342a26fd0 Clean up checking code a bit 2018-08-21 13:11:53 +01:00
Richard Dodd
385e805509 Work on review comments 2018-08-21 12:55:09 +01:00
Alex Crichton
bf791efe2c Fix wasm-interpreter with mixed types of imports
We counted all imports until the index of the descriptor function, now we only
count imported functions
2018-08-20 16:18:09 -07:00
Alex Crichton
6343f2659a Remove dependency on wasmi
This is a pretty heavyweight dependency which accounts for a surprising amount
of runtime for larger modules in `wasm-bindgen`. We don't need 90% of the crate
and so this commit bundles a small interpreter for instructions we know are only
going to appear in describe-related functions.
2018-08-20 15:14:56 -07:00
Alex Crichton
7486fa5104
Merge pull request #710 from RazerM/master
Add more WebAssembly bindings
2018-08-20 14:17:24 -07:00
Alex Crichton
2972599ee3 Fix some mistakes from WeakRef support
* Be sure to free the pointer, not `this.ptr` which is always 0
* Unconditionally attempt to free data and let Rust throw an exception if it's
  null
2018-08-20 14:14:55 -07:00
Frazer McLean
1ea1410f98 Catch errors in Table and Module constructors 2018-08-20 22:12:29 +02:00
Frazer McLean
7432f5ff5c Merge branch 'master' of git://github.com/rustwasm/wasm-bindgen 2018-08-20 21:55:42 +02:00
Alex Crichton
86d1ab513b
Merge pull request #741 from alexcrichton/duplicate-statics
Support importing same-name statics from two modules
2018-08-20 11:37:21 -07:00
Alex Crichton
ccae331b2a
Merge pull request #740 from alexcrichton/catch-constructors
Fix the `constructor` and `catch` attributes combined
2018-08-20 11:37:02 -07:00
Alex Crichton
61491eafbf Add experimental support for WeakRef
This commit adds experimental support for `WeakRef` to be used to automatically
free wasm objects instead of having to always call the `free` function manually.
Note that when enabled the `free` function for all exported objects is still
generated, it's just optionally invoked by the application.

Support isn't exposed through a CLI flag right now due to the early stages of
the `WeakRef` proposal, but the env var `WASM_BINDGEN_WEAKREF` can be used to
enable this generation. Upon doing so the output can then be edited slightly as
well to work in the SpiderMonkey shell and it looks like this is working!

Closes #704
2018-08-20 11:18:02 -07:00
Alex Crichton
f8cf4ab732 Support importing same-name statics from two modules
Closes #714
2018-08-20 10:56:58 -07:00
Alex Crichton
4195af68e7 Fix the constructor and catch attributes combined
This commit fixes annotations that include both the `constructor` and `catch`
attributes on imported types, ensuring that we infer the right type being
returned after extracting the first type parameter of the `Result`.

Closes #735
2018-08-20 10:40:54 -07:00
Alex Crichton
ddc42738cf Tweak some WebIDL type names in methods
Instead of `dom_str`, `byte_str`, and `usv_str`, emit `str` for all of them.
Similarly for `unrestricted_f64` just do `f64` instead. This reflects how we
interpret the types already in terms of Rust types and although technically
makes it possible to have name collisions in WebIDL they don't come up in
practice.
2018-08-20 10:32:04 -07:00
Alex Crichton
92b7de3d3d Skip args in overloaded method names if all same
This commit updates how we name overloaded methods. Previously all argument
names were concatenated, but after this commit it only concatenates argument
names where at least one possibility has a different type. Otherwise if all
possibilities have the same type name it in theory isn't adding too much more
information!

Additionally this commit also switches to using `_with_` consistently everywhere
instead of `_with_` for constructors and `_using_` for methods.

Closes #712
2018-08-20 10:30:02 -07:00
Alex Crichton
a4bf239eff
Merge pull request #739 from Hywan/string-replace-regexp
feat(js-sys) Implement `String.replace(&str, …)`
2018-08-20 07:55:05 -07:00
Ivan Enderlin
1e27b588e2
feat(js-sys) Implement String.replace(&str, …). 2018-08-20 11:01:56 +02:00
Ivan Enderlin
a9a1e69f30
feat(js-sys) Implement String.split with regexp. 2018-08-20 10:42:12 +02:00
Alex Crichton
6d49c76bc4
Merge pull request #734 from alexcrichton/stabilize
Remove `use_extern_macros` features
2018-08-19 18:12:00 -07:00
Frazer McLean
19ee28d769 Don’t need catch for Module static methods 2018-08-20 01:50:27 +02:00
Alex Crichton
d4297ad2d3 Remove use_extern_macros features
This has now been stabilized!
2018-08-19 14:33:01 -07:00
Danielle Pham
4f294224f0 Add bindings for String.prototype.split 2018-08-19 15:09:45 -04:00
Danielle Pham
8698084a43 Add binding for String.prototype.search 2018-08-19 14:52:10 -04:00
Danielle Pham
44877880bb Add bindings for String.prototype.replace 2018-08-19 14:42:22 -04:00
Danielle Pham
7b53b1c88e Add binding for String.prototype.match 2018-08-19 13:59:00 -04:00
Mason Stallmo
b330bd1bf1 Refactor inheritance checks into their own tests 2018-08-19 11:27:04 -05:00
Mason Stallmo
1762b3cba0 Add extends to js-sys:Intl.PluralRules 2018-08-19 11:03:55 -05:00
Mason Stallmo
ee131888da Add extends to js-sys:Intl.NumberFormat 2018-08-19 10:19:03 -05:00
Mason Stallmo
780c7236f1 Add extends to js-sys:Intl.DateTimeFormat 2018-08-19 10:13:25 -05:00
Mason Stallmo
f0811d5ac0 Add extends to js-sys:Intl.Collater 2018-08-19 10:03:56 -05:00
Richard Dodd
003cf102f1 Fix webidl 2018-08-19 14:28:45 +01:00
Richard Dodd
7c83c73919 Comment typo 2018-08-19 13:41:23 +01:00
Richard Dodd
a4835304eb Add codegen to make test work. 2018-08-19 13:39:16 +01:00
Alex Crichton
9c6225fd80
Merge pull request #720 from kraai/patch-1
Test for and add extends attributes
2018-08-18 22:15:30 -07:00
Alex Crichton
1fd52b08a3
Merge pull request #724 from eminence/partial_mixin
Fix missing WindowOrWorkerGlobalScope partial interface mixins.
2018-08-18 22:10:17 -07:00
Alex Crichton
3697ddf4c0
Merge pull request #723 from mstallmo/add-extends-to-js-sys
Add extends attributes for js_sys:Generator
2018-08-18 22:09:16 -07:00
Alex Crichton
a12fc46a55
Merge pull request #728 from quelledanielle/js_string_from_code_point
Add bindings for String.from_code_point
2018-08-18 22:08:48 -07:00
Danielle Pham
27d48ad267 Add bindings for String.from_code_point 2018-08-18 21:35:38 -04:00
Danielle Pham
00a0152adf Rename local param to locale 2018-08-18 21:05:12 -04:00
Danielle Pham
0d3f706195 Add binding for String.prototype.localeCompare 2018-08-18 21:05:02 -04:00
Richard Dodd
d9fd2147a0 [wip] support variadic javascript function parameters 2018-08-18 22:15:29 +01:00
Andrew Chin
302f7ba21d Fix missing WindowOrWorkerGlobalScope partial interface mixins.
Without the "mixin" keyword, wasm_bindgen_webidl would report:

     Partial interface WindowOrWorkerGlobalScope missing non-partial interface

Also, including the "mixin" keyword here is consistent with the official
webidl spec (for example see https://fetch.spec.whatwg.org/#fetch-method)
2018-08-18 11:23:29 -04:00
Mason Stallmo
c543b5d149 Add extends attributes for js_sys:Generator 2018-08-18 09:11:07 -05:00
Frazer McLean
751f226170 Merge branch 'master' of git://github.com/rustwasm/wasm-bindgen 2018-08-18 01:58:11 +02:00
Matt Kraai
6dccb7f777 Remove blank line
Part of #670
2018-08-17 14:50:15 -07:00
Matt Kraai
bec3178e3c Make all errors extend Object
Part of #670
2018-08-17 13:10:56 -07:00
Matt Kraai
687412ec50 Test for AsRef implementations
Part of #670
2018-08-17 13:09:30 -07:00
Alex Crichton
57693ee11a Bump to 0.2.17 2018-08-16 23:36:42 -07:00
Alex Crichton
a4e8fb6686 Fix compile on latest nightly 2018-08-16 23:30:40 -07:00
Alex Crichton
37068cb47f Fix tests on nightly 2018-08-16 23:25:57 -07:00
R. Andrew Ohana
25b6f5d982
Merge pull request #702 from alexcrichton/dictionaries
Implement support for WebIDL dictionaries
2018-08-16 13:06:06 -07:00
Frazer McLean
ffccfdee7d WebAssembly::Table::new takes an object 2018-08-16 20:41:07 +02:00
Frazer McLean
b519c290f9 futures should be a dev dependency 2018-08-16 20:40:19 +02:00
Matt Kraai
c8d0c57990 Check that all errors are instances of Object
Part of #670
2018-08-16 07:14:12 -07:00
Alex Crichton
d6e48195b3 Implement support for WebIDL dictionaries
This commit adds support for generating bindings for dictionaries defined in
WebIDL. Dictionaries are associative arrays which are simply objects in JS with
named keys and some values. In Rust given a dictionary like:

    dictionary Foo {
        long field;
    };

we'll generate a struct like:

    pub struct Foo {
        obj: js_sys::Object,
    }

    impl Foo {
        pub fn new() -> Foo { /* make a blank object */ }

        pub fn field(&mut self, val: i32) -> &mut Self {
            // set the field using `js_sys::Reflect`
        }
    }

    // plus a bunch of AsRef, From, and wasm abi impls

At the same time this adds support for partial dictionaries and dictionary
inheritance. All dictionary fields are optional by default and hence only have
builder-style setters, but dictionaries can also have required fields. Required
fields are exposed as arguments to the `new` constructor.

Closes #241
2018-08-15 17:08:27 -07:00
Nick Fitzgerald
b8afa0abde web-sys: Use mixins instead of [NoInterfaceObject] interfaces and implements
I think these might all be from before WebIDL mixins existed. Either way,
multiple inheritance of interfaces that don't have exposed interface objects is
equivalent to mixins.
2018-08-15 16:57:23 -07:00
Nick Fitzgerald
69cc7725d6 webidl: Add some more logging for debugging code generation 2018-08-15 16:57:23 -07:00
Nick Fitzgerald
9616ef3633 web-sys: Remove a bunch of mozilla extensions from our webidl 2018-08-15 16:57:23 -07:00
Nick Fitzgerald
703e2a3fbe web-sys: Fix typedef of nsISupports
The JS Object type is named "object" in webidl, not "Object".
2018-08-15 16:57:23 -07:00
Nick Fitzgerald
88582ec47c webidl: Fix warning about partial interfaces without non-partial definition 2018-08-15 16:57:23 -07:00
Nick Fitzgerald
13fe2b4aca
Merge pull request #709 from fitzgen/webidl-and-logging
Webidl and logging
2018-08-15 15:09:53 -07:00
Frazer McLean
b698eb5d6a Add more WebAssembly bindings 2018-08-15 23:45:28 +02:00
Sendil Kumar N
190b45d59c
Merge pull request #708 from sendilkumarn/extends-arr
Adds Extends to TypedArrays
2018-08-15 23:45:04 +02:00
Nick Fitzgerald
ea137a951b web-sys: Remove a few more interfaces from gecko's test suite 2018-08-15 14:34:59 -07:00
Nick Fitzgerald
21063fd42f webidl: Make logging a little more consistently formatted
This commit makes these changes:

* Unsupported constructs always log "unsupported" for easy `grep`ing
* There is always a "<generic message> : <details>" format now, so we can easily
  use `cut` to grab the generic message and count which kinds of things are our
  biggest missing features.
* Make sure that we have different `warn!` logs for each kind of unsupported
  thing, instead of grouping them together.

Put all that together and this is the current state of `wasm-bindgen-webidl` and
`web-sys`:

```
$ grep WARN stderr.txt | grep wasm_bindgen_webidl | grep -i unsupported | cut -d ' ' -f5- | cut -d ':' -f 1 | sort | uniq -c | sort -rn
    387 Unsupported WebIDL Dictionary definition
    139 Unsupported argument type
     70 Unsupported return type
     47 Unsupported WebIDL Callback definition
     22 Unsupported WebIDL extended attribute
     18 Unsupported unnamed operation
      9 Unsupported WebIDL CallbackInterface definition
      7 Unsupported WebIDL Stringifier interface member
      7 Unsupported WebIDL Maplike interface member
      2 Unsupported webidl stringifier
      2 Unsupported WebIDL Setlike interface member
      2 Unsupported stringifier on type
```
2018-08-15 14:24:09 -07:00
Sendil Kumar
af9ecac296 js-sys: Add extends attributes for js_sys::Float64Array
address review comments

add review comments
2018-08-15 22:50:27 +02:00
Nick Fitzgerald
c1f7b42662 web-sys: Provide more info in logs when type conversion fails 2018-08-15 11:45:45 -07:00