Commit Graph

918 Commits

Author SHA1 Message Date
Alex Crichton
1410b5253d
Merge pull request #944 from alexcrichton/windows-slash
Fix web-sys build on some Windows builds
2018-10-08 12:46:44 -07:00
Alex Crichton
18deb5e848 Fix web-sys build on some Windows builds
The official pathname separator on Windows is `\` instead of `/`, but
we've been unconditionally using `/`. This typically works on Windows
because Cargo's default `OUT_DIR` listing is a normal `C:\...` path
which works with either `/` or `\`. If, however, a user sets
`CARGO_TARGET_DIR` to a UNC-style path like `\\?\C:\...` then `/` is
*not* the same as `\`, but rather `/` is interpreted as part of the file
name (to allow file names with `/` in the name).

Let's bypass all this and just use a build script output env var.

Closes #943
2018-10-08 10:19:43 -07:00
Alex Crichton
79e4324a3b Update parity-wasm dependency
While doing this, make `parity-wasm` a public dependency of all crates
instead of using the `Any` trick as that's not really needed any more.
2018-10-08 10:01:53 -07:00
Alex Crichton
4750927f11 Import the wasm-gc-api crate into this repository
The `wasm-bindgen` crate is effectively the only user of this crate now
that the `wasm-gc` tool has been deprecated. It's also much easier to
keep it in this repository as it's easier to sync changes to
`parity-wasm`. I'd also like to start refactoring out utilities for
managing a `parity_wasm::Module` to share between this crate and the
other CLI support code.
2018-10-05 14:21:59 -07:00
Alex Crichton
c210ccd596 Bump to 0.2.24 2018-10-05 09:53:19 -07:00
Alex Crichton
7eb49acf0d Allow passing extra args to node in test runner
This can be useful for enabling experimental features
2018-10-04 22:20:23 -07:00
Nick Fitzgerald
7ea3ee60b7
Merge pull request #927 from alexcrichton/fix-browser
Fix the `no_modules` example by fixing `--browser`
2018-10-03 16:34:31 -07:00
Alex Crichton
3f357f46eb Fix the no_modules example by fixing --browser
Recent refactorings forgot a case of emitting code for
`cachedTextDecoder`!
2018-10-03 15:54:57 -07:00
Alex Crichton
9eaba6e28b Filter only for RustDeprecated in attrs
Previously any string-related attribute would emit a deprecation
warning!

cc #925
2018-10-03 15:44:58 -07:00
Alex Crichton
84bda02bbf
Merge pull request #923 from alexcrichton/extends-path
Parse `Path`s in `extends` attributes
2018-10-03 10:38:50 -07:00
Alex Crichton
5df8e20815 Parse Paths in extends attributes
Closes #916
2018-10-03 09:14:23 -07:00
Alex Crichton
4a5e13b08b
Merge pull request #920 from alexcrichton/fix-borrow-mut
Fix exporting structs with `BorrowMut` in scope
2018-10-03 09:09:36 -07:00
Alex Crichton
05742177c2
Merge pull request #921 from alexcrichton/fix-typescript
Fix TypeScript for generated constructors
2018-10-03 09:09:23 -07:00
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