Commit Graph

259 Commits

Author SHA1 Message Date
Caio
0c4cdefd07 Rustfmt 2019-04-29 09:45:23 -03:00
Alex Crichton
36c0a1347d
Merge pull request #1492 from RReverser/function-new-with-args
Add bindings for `new Function(args, body)`
2019-04-26 12:05:46 -05:00
Ingvar Stepanyan
814f576b1d Add bindings for new Function(args, body)
We don't support variadic args in front, but, luckily for us, `new Function` accepts comma-separated args as a single string as well (see updated JSON test for an example).
2019-04-26 17:42:23 +01:00
Ingvar Stepanyan
85eea18658 Adds missing variadic bindings for string methods
- `JsString::from_code_point` - allows to create JS strings using slice of codes in WASM memory.
 - `JsString::from_char_code` - same as above, but also uses updated signature with `u16` instead of `u32` (partially helps with #1460 at least for the new binding).
2019-04-26 16:57:34 +01:00
Alex Crichton
26f9d86f62
Merge pull request #1487 from ibaryshnikov/shared_array_buffer_tests
Added tests for SharedArrayBuffer
2019-04-26 09:38:16 -05:00
Kevin Gibbons
70480ad29d fix test 2019-04-25 21:21:17 -07:00
Kevin Gibbons
a32d2553fc js-sys: add Object.fromEntries 2019-04-25 20:52:29 -07:00
Alex Crichton
26df24ae6a
Merge pull request #1484 from alexcrichton/new-node
Upgrade version of node.js used on Azure
2019-04-25 22:14:31 -05:00
ibaryshnikov
af22a26880 added tests for SharedArrayBuffer 2019-04-26 10:59:06 +08:00
Alex Crichton
7e512ba187
Merge pull request #1463 from ibaryshnikov/atomics-support
added Atomics and SharedArrayBuffer
2019-04-25 21:48:55 -05:00
Alex Crichton
dea5bad698 Fix test for node 12 2019-04-25 19:30:32 -07:00
ibaryshnikov
b05ae44a8c changed f64 to i32 in static methods of Atomics, changed static_method_of to js_namespace, set typed_array type to Int32Array in notify and wait methods 2019-04-26 01:56:58 +08:00
ibaryshnikov
58245b0587 changed String to JsString in Atomics::wait 2019-04-26 00:02:19 +08:00
ibaryshnikov
de2c2cf26c fixed Atomics::wait and Atomics::wait_with_timeout return type 2019-04-25 19:18:31 +08:00
Ingvar Stepanyan
680a6bbb0c Remove PartialEq<char> for JsString for now
This seems to spark controversy, so removing for now but should be easy enough to still add in the future.
2019-04-24 13:40:18 +01:00
ibaryshnikov
0759bfa7e2 f32 changed to f64 in Atomics 2019-04-24 00:27:15 +08:00
ibaryshnikov
f1eaefdf0d fixed value types in Atomics methods 2019-04-24 00:25:25 +08:00
ibaryshnikov
1071457c3d added SharedArrayBuffer and Atomics to js-sys 2019-04-24 00:01:15 +08:00
Ingvar Stepanyan
bc4a98d146 Add JsString <-> char conversions
These are pretty common and already supported via ABI conversions, yet pretty easy to get wrong when converting them manually.

Fixes #1363.
2019-04-23 15:54:06 +01:00
Ingvar Stepanyan
d7650863ab Fix or suppress {primitive}::new warnings in tests
Constructing boxed primitives was deprecated in #1447.

Some tests have been still using these methods, so this PR either updates them to use newly added {primitive}::from implementations or adds `#[allow(deprecated)]` where necessary.
2019-04-17 18:25:45 +01:00
Alex Crichton
ff1addbbaa Run cargo fmt 2019-04-16 10:52:27 -07:00
Alex Crichton
526b253b47
Merge pull request #1451 from RReverser/more-static-namespaces
Transform Math, Reflect and JSON into static namespaces
2019-04-15 09:41:40 -05:00
Ingvar Stepanyan
ed45ca72da Fix more DataView documentation mistakes
I fixed few copy-paste mistakes in https://github.com/rustwasm/wasm-bindgen/pull/1372, but haven't noticed that they go even deeper :(
2019-04-15 14:31:23 +01:00
Ingvar Stepanyan
62b7d3e3c4 Transform JSON into a namespace 2019-04-13 02:22:19 +01:00
Ingvar Stepanyan
75c2971ab9 Transform Reflect into a namespace 2019-04-13 02:21:33 +01:00
Ingvar Stepanyan
fe939bc911 Transform Math into a namespace 2019-04-13 02:20:24 +01:00
Ingvar Stepanyan
2f524ee494 Leverage new is_type_of for iterator protocol
Treats any object of shape `{ next: function }` as an iterator via new `is_type_of` method. This is consistent with JavaScript iteration protocol which we already respect.

Also fixes a minor issue that `is_function` was unnecessarily called twice (once explicitly and once as part of `dyn_into` which now does the same check).
2019-04-12 20:30:41 +01:00
Ingvar Stepanyan
cb880bdbff Add customisable is_type_of 2019-04-12 17:23:42 +01:00
Alex Crichton
ba1f67d854 Remove some unnecessary unsafe in js-sys 2019-04-12 09:02:39 -07:00
Alex Crichton
df8da56a6c Add PartialEq/Eq to many js-sys types
This commit adds `#[derive(PartialEq, Eq)]` to many types throughout
`js-sys`. These types are basically all based on `Object`, which means
that `Object.is` can be used for `PartialEq` and the `Eq` requirements
are upheld.

The macro has also been updated to internally store the deref target
instead of unconditionally storing `JsValue`, allowing `#[derive]` to
work a bit better in these situations.
2019-04-12 09:02:33 -07:00
Alex Crichton
018b9b4e09 Fix compile of js-sys 2019-04-12 08:54:23 -07:00
Alex Crichton
ba88ae8b64 Improve Boolean/Number/JsString consistency
* Ensure `PartialEq` is implemented from these types to native Rust types
* Implement `From` between these type and native Rust types
* Deprecated `Number::new` and `Boolean::new` to discourage use of the
  object forms, recommending the `from` constructors instead.

Closes #1446
2019-04-12 08:50:29 -07:00
Alex Crichton
df6e15e3ab Bump to 0.2.42 2019-04-11 07:39:45 -07:00
Alex Crichton
02394724ea Bump to 0.2.41 2019-04-10 10:53:32 -07:00
Alex Crichton
44738e049a Add warnings about UTF-16 vs UTF-8 strings
This commit aims to address #1348 via a number of strategies:

* Documentation is updated to warn about UTF-16 vs UTF-8 problems
  between JS and Rust. Notably documenting that `as_string` and handling
  of arguments is lossy when there are lone surrogates.

* A `JsString::is_valid_utf16` method was added to test whether
  `as_string` is lossless or not.

The intention is that most default behavior of `wasm-bindgen` will
remain, but where necessary bindings will use `JsString` instead of
`str`/`String` and will manually check for `is_valid_utf16` as
necessary. It's also hypothesized that this is relatively rare and not
too performance critical, so an optimized intrinsic for `is_valid_utf16`
is not yet provided.

Closes #1348
2019-04-05 08:11:50 -07:00
Ingvar Stepanyan
db17e9d2a7 Add constructor property to Object 2019-03-27 14:25:55 +00:00
Alex Crichton
a6fe0cefa8 Migrate all crates to the 2018 edition
Most of the CLI crates were already in the 2018 edition, and it turns
out that one of the macro crates was already in the 2018 edition so we
may as well move everything to the 2018 edition!

Always nice to remove those `extern crate` statements nowadays!

This commit also does a `cargo fmt --all` to make sure we're conforming
with style again.
2019-03-26 08:10:53 -07:00
Ingvar Stepanyan
11bb8f03c2 Remove string allocation from try_iter
This allows to significantly speed up iteration over small collections, where string encoding is the primary overhead.

Related to #1386, but works around only this partial case.
2019-03-26 12:22:54 +00:00
Alex Crichton
6803c619bb Bump to 0.2.40 2019-03-21 17:08:48 -07:00
Alex Crichton
d49d8c9e1b
Merge pull request #1372 from RReverser/fix-dataview-docs
Fix docs for DataView::get*int32*
2019-03-20 13:47:10 -05:00
Ingvar Stepanyan
4e806bab70 Fix docs for DataView::get*int32* 2019-03-20 18:32:34 +00:00
Ingvar Stepanyan
c5260f29aa Merge TypedArray definitions into a macro 2019-03-20 17:25:35 +00:00
Alex Crichton
228f58dca3 Bump to 0.2.39 2019-03-13 11:02:27 -07:00
ibaryshnikov
fa0a3610af issue-1317-typed-array-typo-fixed 2019-03-06 22:12:48 +03:00
Alex Crichton
5de3189411 Fix js-sys and web-sys tests 2019-03-05 08:00:47 -08:00
Alex Crichton
a659f27c07 Bump to 0.2.38 2019-03-04 09:11:23 -08:00
Alex Crichton
4181fb311a Add experimental support for the anyref type
This commit adds experimental support to `wasm-bindgen` to emit and
leverage the `anyref` native wasm type. This native type is still in a
proposal status (the reference-types proposal). The intention of
`anyref` is to be able to directly hold JS values in wasm and pass the
to imported functions, namely to empower eventual host bindings (now
renamed WebIDL bindings) integration where we can skip JS shims
altogether for many imports.

This commit doesn't actually affect wasm-bindgen's behavior at all
as-is, but rather this support requires an opt-in env var to be
configured. Once the support is stable in browsers it's intended that
this will add a CLI switch for turning on this support, eventually
defaulting it to `true` in the far future.

The basic strategy here is to take the `stack` and `slab` globals in the
generated JS glue and move them into wasm using a table. This new table
in wasm is managed at the fringes via injected shims. At
`wasm-bindgen`-time the CLI will rewrite exports and imports with shims
that actually use `anyref` if needed, performing loads/stores inside the
wasm module instead of externally in the wasm module.

This should provide a boost over what we have today, but it's not a
fantastic strategy long term. We have a more grand vision for `anyref`
being a first-class type in the language, but that's on a much longer
horizon and this is currently thought to be the best we can do in terms
of integration in the near future.

The stack/heap JS tables are combined into one wasm table. The stack
starts at the end of the table and grows down with a stack pointer (also
injected). The heap starts at the end and grows up (state managed in
linear memory). The anyref transformation here will hook up various
intrinsics in wasm-bindgen to the runtime functionality if the anyref
supoprt is enabled.

The main tricky treatment here was applied to closures, where we need JS
to use a different function pointer than the one Rust gives it to use a
JS function pointer empowered with anyref. This works by switching up a
bit how descriptors work, embedding the shims to call inside descriptors
rather than communicated at runtime. This means that we're accessing
constant values in the generated JS and we can just update the constant
value accessed.
2019-02-20 07:28:54 -08:00
Alex Crichton
e9f423d57e Bump to 0.2.37 2019-02-15 08:16:24 -08:00
Alex Crichton
c49b87b2d8
Merge pull request #1225 from Pauan/get_index
Adding in Reflect::get_f64, Reflect::get_u32, Reflect::set_f64, and Reflect::set_u32
2019-02-13 13:10:40 -06:00
Nick Fitzgerald
802cfedcbd Bump to 0.2.36 2019-02-12 13:19:02 -08:00