Commit Graph

1005 Commits

Author SHA1 Message Date
Alex Crichton
32fd1227e4
Merge pull request #910 from alexcrichton/fix-text-encoder-edge
Fix polyfill of `TextEncoder` and `TextDecoder`
2018-10-03 00:07:30 -07:00
Alex Crichton
157750fd99 Fix TypeScript for generated constructors
It accidentally had a stray colon!

Closes #917
2018-10-03 00:00:54 -07:00
Alex Crichton
32b62b4358 Fix exporting structs with BorrowMut in scope
Apparently the codegen wasn't precise enough such that a trait import
could cause method resolution to go awry!

Closes #919
2018-10-02 23:56:15 -07:00
Alex Crichton
332beecabe Add a number of #[inline] annotation through crates
Adding `#[inline]` will typically improve codegen for optimized builds
without LTO (so far the majority in practice) by allowing functions that
otherwise couldn't be inlined across codegen units to get inlined
across codegen units.

Right now `wasm-bindgen` has a lot of functions that are very small and
delegate to other functions, but aren't otherwise candidates for
inlining because they're concrete.

I was poking around in release-mode wasm recently and noticed an
alarming number of functions for tiny pieces of functionality, which
motivates this patch!
2018-10-01 15:31:09 -07:00
Alex Crichton
9c085dc0f5
Merge pull request #914 from alexcrichton/rename-polyfill
Rename `polyfill` to `vendor_prefix`
2018-10-01 14:47:07 -07:00
Alex Crichton
f75349262a Rename polyfill to vendor_prefix
cc #906
2018-10-01 14:45:30 -07:00
Alex Crichton
8e7238d15f Fix test --release
Unfortuantely we need to do some linking trickery to make sure a custom
section is correctly pulled in...
2018-10-01 14:44:21 -07:00
Alex Crichton
a7e9da0a81
Merge pull request #879 from alexcrichton/closure-zst
Improve codegen for `Closure<T>`
2018-10-01 14:41:13 -07:00
Alex Crichton
bb7271aa43 Fix our WebIDL for Safari
This commit employs the strategy described in #908 to apply a
non-breaking change to fix WebIDL to be compatible with all browsers,
including Safari.

The problem here is that `BaseAudioContext` and `AudioScheduledSourceNode`
are not types in Safari, but they are types in Firefox/Chrome. The fix
here was to move the contents of these two interfaces into mixins, and
then include the mixins in all classes which inherit from these two
classes. That should have the same effect as defining the methods
inherently on the original interface.

Additionally a special `[RustDeprecated]` attribute to WebIDL was added
to signify interfaces this has happened to. Currently it's directly
tailored towards this case of "this intermediate class doesn't exist in
all browsers", but we may want to refine and extend the deprecation
message over time.

Although it's possible we could do this as a breaking change to
`web-sys` I'm hoping that we can do this as a non-breaking change for
now and then eventually on the next breaking release batch all these
changes together, deleting the intermediate classes. This is also
hopefully a good trial run for how stable web-sys can be when it's
actually stable!

cc #897
cc #908
2018-10-01 12:24:37 -07:00
Nick Fitzgerald
0a48d2bc29 web-sys: allow unused import warning
This import is only used if some features get used and it is way easier to just
quiet the warning when those features aren't used than to try and `cfg` this
import.
2018-10-01 09:53:03 -07:00
Alex Crichton
717cfa303d Fix polyfill of TextEncoder and TextDecoder
This commit does a few things, including:

* Fixing the generated JS of `wasm-bindgen` to allow polyfills to work.
  (a minor tweak of the generated JS)

* All examples are updated to include a Webpack-specific polyfill for
  these two types to get examples working in Edge.

* A new page has been added to the guide about supported browsers. This
  mentions known caveats like IE 11 requiring `wasm2js` as well as
  documenting some `TextEncoder` and `TextDecoder` workarounds for Edge.

Closes #895
2018-09-30 10:16:20 -07:00
Alex Crichton
8ba41cce6e Improve codegen for Closure<T>
This commit improves the codegen for `Closure<T>`, primarily for ZST
where the closure doesn't actually capture anything. Previously
`wasm-bindgen` would unconditionally allocate an `Rc` for a fat pointer,
meaning that it would always hit the allocator even when the `Box<T>`
didn't actually contain an allocation. Now the reference count for the
closure is stored on the JS object rather than in Rust.

Some more advanced tests were added along the way to ensure that
functionality didn't regress, and otherwise the calling convention for
`Closure` changed a good deal but should still be the same user-facing.
The primary change was that the reference count reaching zero may cause
JS to need to run the destructor. It simply returns this information in
`Drop for Closure` and otherwise when calling it now also retains a
function pointer that runs the destructor.

Closes #874
2018-09-29 07:00:53 -07:00
Alex Crichton
230b8f61fd Fix WebIDL mixin attributes on Window
Previously the "container attribute" were set to the attributes of the
mixin itself, but we want the container attributes to be that of the
type which includes the mixin (like `Window`) as those attributes
contain information about whether or not bindings are `structural`.

The end result with this is that the `structural` tag is now used for
properties on `Window`, correctly generating setters/getters.

Closes #904
2018-09-28 21:41:48 -07:00
Alex Crichton
3c14f7a6eb Implement a polyfill attribute for imports
Allow using imported APIs under alternative names, such as prefixed
names, for web APIs when the exact API differs across browsers.
2018-09-28 13:43:00 -07:00
Alex Crichton
7447c30ba4
Merge pull request #903 from alexcrichton/doc-constructors
Add more documentation to `web-sys` constructors
2018-09-27 13:51:07 -07:00
Alex Crichton
f3dd28e294 Add more documentation to web-sys constructors
Closes #899
2018-09-27 12:35:46 -07:00
Alex Crichton
fd1a00db76 Escape HTML text in browser failure messages
When browser tests fail we're appending to `innerHTML`, which means that
we need to escape some characters for all to show up!

Closes #898
2018-09-27 12:21:41 -07:00
Alex Crichton
65fc8228f1 Remove a stray script 2018-09-27 12:21:41 -07:00
Alex Crichton
7ecf4aae87 cargo +nightly fmt --all
Rustfmt all the things!
2018-09-26 08:26:00 -07:00
Alex Crichton
18e089fa85 Add some Cargo metadata for web-sys 2018-09-26 08:07:33 -07:00
Nick Fitzgerald
4c766c5c7a Start web-sys at 0.3.0 2018-09-26 07:37:51 -07:00
Nick Fitzgerald
f834a427d7 Bump to version 0.2.23 (and js-sys and wasm-bindgen-futures to 0.3.0) 2018-09-26 07:31:54 -07:00
Nick Fitzgerald
ee0e4bc089
Merge pull request #887 from fitzgen/iterating-over-js-values
Iterating over js values
2018-09-25 16:04:50 -07:00
Nick Fitzgerald
7db28b4548 js-sys: run rustfmt 2018-09-25 14:30:26 -07:00
Nick Fitzgerald
f9cd329b14 js-sys: Add js_sys::try_iter for iterating over any JsValue
Fixes #776
2018-09-25 14:30:26 -07:00
Nick Fitzgerald
e3d2ea2628 js-sys: Catch exceptions thrown in Reflect APIs
Proxies passed to Reflect APIs can throw for any of these operations and it is a
bit of a mess.
2018-09-25 14:30:26 -07:00
Alex Crichton
9b99ebfc87
Merge pull request #886 from alexcrichton/tweak-features
Update and improve crate features in `web-sys`
2018-09-25 12:26:45 -07:00
Alex Crichton
97cceebe7e Update and improve crate features in web-sys
* Regenerate the list of features for the crate given recent
  improvements, enabling some more types to be bound.
* Add feature gates for the `css` and `console` namespaces (modules),
  gating the APIs by default. Now `web_sys` has zero APIs unless they're
  requested.
* Improved the "required feature" documentation for `struct` types to
  not list parent classes and mention just the `struct` type instead.
2018-09-25 11:27:22 -07:00
Nick Fitzgerald
6edb871c36 js-sy: Add a doc comment for js_sys::IntoIter 2018-09-25 11:21:56 -07:00
Nick Fitzgerald
dc22965e71 js-sys: Add doc comment for js_sys::Iter 2018-09-25 11:21:56 -07:00
Nick Fitzgerald
2c62795a8d
Merge pull request #880 from alexcrichton/better-link-mem-intrinsics
Improve `link_mem_intrinsics` hack
2018-09-24 17:20:54 -07:00
Alex Crichton
b256b98e38 Improve link_mem_intrinsics hack
Previously the `link_mem_intrinsics` hack actually had a runtime
overhead by storing a value into a global location, but it turns out we
can actually use a non-inlined function call as part of the *descriptor*
which requires this to be in the final binary, but we'll end up snip'ing
the value at the end.

All in all this should mean that it's not a zero-overhead solution for
linking these intrinsics! The `#[wasm_bindgen]` attribute already has
other problems if the descriptors don't show up, so that's the least of
our issues!
2018-09-24 15:43:04 -07:00
Alex Crichton
7b495468f6 Implement support for Uint8ClampedArray
This commit implements support for binding APIs that take
`Uint8ClampedArray` in JS. This is pretty rare but comes up in a
`web-sys` binding or two, and we're now able to bind these APIs instead
of having to omit the bindings.

The `Uint8ClampedArray` type is bound by using the `Clamped` marker
struct in Rust. For example this is declaring a JS API that takes
`Uint8ClampedArray`:

    use wasm_bindgen::Clamped;

    #[wasm_bindgen]
    extern {
        fn takes_clamped(a: Clamped<&[u8]>);
    }

The `Clamped` type currently only works when wrapping the `&[u8]`, `&mut
[u8]`, and `Vec<u8>` types. Everything else will produce an error at
`wasm-bindgen` time.

Closes #421
2018-09-24 13:58:37 -07:00
Alex Crichton
b91817f181 Remove no-longer-needed math bindings
All these functions are now provided by upstream compiler-builtins, so
there's no need for us to be binding them automatically. The remaining
`Math_*` functions are also no longer needed on nightly after
https://github.com/rust-lang/rust/pull/54257 but that PR isn't on beta,
so we'll need to leave these here for awhile while beta rides the trains
2018-09-24 10:42:04 -07:00
Alex Crichton
c5d3ca9c00
Merge pull request #862 from alexcrichton/more-types
Enable union types without interfaces in WebIDL
2018-09-24 10:00:26 -07:00
Alex Crichton
d098d3cf28 Enable union types without interfaces in WebIDL
Bind them all as `JsValue` as that's the "least common ancestor" we can
work with. Fixes up one location in WebIDL where `Option<JsValue>`
arose as we haven't implemented that.

Closes #817
2018-09-24 09:33:22 -07:00
Alex Crichton
9a1fa5a81b
Merge pull request #870 from alexcrichton/no-constructor-token
Remove the need for a `ConstructorToken`
2018-09-21 21:40:08 -07:00
Alex Crichton
75f005be23 Support #[wasm_bindgen(setter, js_name = ...)]
Previously we'd require the explicit `js_name` to *also* start with
`set_`, but when explicitly specified it shouldn't be mangled at all!

Closes #584
2018-09-21 17:54:26 -07:00
Alex Crichton
3f85d7db9f Remove the need for a ConstructorToken
This commit removes the need for an injected `ConstructorToken` type and
also cleans up the story we have for generating constructors a bit.
After this commit a `constructor()` is omitted entirely if we're in
non-debug mode and there's no actual listed constructor. Additionally we
don't deal with splat arguments and rerouting constructors, Nick was
kind enough to enlighten me about `Object.create` which is creating an
instance without running the constructor!

Instances of an exported type are now created through one of two
methods:

* If `#[wasm_bindgen(constructor)]` is present, then a `constructor` is
  generated with the appropriate signature. If a constructor is not
  present and we're in debug mode, a throwing constructor is generated.
  If we're in release mode and there's no constructor, no constructor is
  generated.

* Otherwise if a binding returns an instance of a type (or otherwise
  needs to manfuacture an instance, then it will cause an internal
  `__wrap` function to be generated. This function will use
  `Object.create` to create an instance without running the constructor.

This should ideally clean up our generated JS for classes quite a bit,
making it much more lean-and-mean!
2018-09-21 17:42:06 -07:00
Alex Crichton
534cceafc8 Improve error message for infer_setter_property
If the setter doesn't start with `set_*` then we currently panic, but
panicking is bad! Instead let's thread through structured errors to make
sure they make their way to the top
2018-09-21 17:29:50 -07:00
Alex Crichton
ab3688d01a Only generate JS null checks in debug mode
In non-debug mode Rust is already checking these pointers, so let's only
generate the relevant code in debug mode.
2018-09-21 16:10:02 -07:00
Alex Crichton
51ec485c94 Bump to 0.2.22 2018-09-21 13:41:58 -07:00
Alex Crichton
ebe73a537c
Merge pull request #866 from alexcrichton/fix-lto
More conservatively patch closure descriptors
2018-09-21 13:35:16 -07:00
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
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