Commit Graph

2437 Commits

Author SHA1 Message Date
Alex Crichton
c4776becbb Touch up descriptions of has_type 2019-04-12 10:54:36 -07:00
Alex Crichton
657b97b6d8
Merge pull request #1405 from RReverser/instanceof
Add support for customising `instanceof` behaviour
2019-04-12 12:50:06 -05:00
Alex Crichton
1a40ba759c
Merge pull request #1448 from alexcrichton/isize-usize
Add support for isize/usize arrays
2019-04-12 11:42:00 -05:00
Ingvar Stepanyan
c77b46af7d Add has_type and update is_instance_of docs 2019-04-12 17:41:51 +01:00
Ingvar Stepanyan
cb880bdbff Add customisable is_type_of 2019-04-12 17:23:42 +01:00
Alex Crichton
4211fcd992
Merge pull request #1444 from alexcrichton/partial-eq
Add PartialEq/Eq to many `js-sys` types
2019-04-12 11:03:05 -05: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
e39404e633 Add support for isize/usize arrays
Closes #1426
2019-04-12 08:56:36 -07:00
Alex Crichton
018b9b4e09 Fix compile of js-sys 2019-04-12 08:54:23 -07:00
Alex Crichton
529d0bd29a
Merge pull request #1447 from alexcrichton/js-sys-tweaks
Improve Boolean/Number/JsString consistency
2019-04-12 10:50:56 -05: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
560cb022ca
Merge pull request #1442 from alexcrichton/fix-encode-into
Fix a bug using `encodeInto` truncating strings
2019-04-11 09:34:16 -05:00
Alex Crichton
3906e4066d Fix a bug using encodeInto truncating strings
The last write accidentally wasn't accounted for in the returned length
of the string and we unfortunately don't have any test coverage of
`encodeInto` since it requires Firefox nightly right now (and doesn't
work in Node yet).

Closes #1436
2019-04-11 07:25:27 -07:00
Alex Crichton
d3fbf707e1
Merge pull request #1434 from alexcrichton/bump
Bump to 0.2.41
2019-04-10 16:11:34 -05:00
Alex Crichton
02394724ea Bump to 0.2.41 2019-04-10 10:53:32 -07:00
Alex Crichton
b670ea44d0
Merge pull request #1431 from alexcrichton/function-table
Add an accessor for the function table
2019-04-08 12:42:28 -05:00
Alex Crichton
7e5e401076 Add an accessor for the function table
This commit adds an intrinsics to the `wasm_bindgen` crate which
accesses the `WebAssembly.Table` which is the function table of the
module. Eventually the thinking is that a module would import its own
function table via native wasm functionality (via `anyref` and such),
but until that's implemented let's add a binding for it ourselves!

Closes #1427
2019-04-08 10:40:46 -07:00
Nick Fitzgerald
a9a23020c4
Merge pull request #1430 from alexcrichton/better-errors
Improve error message for non-copy struct fields
2019-04-08 10:16:21 -07:00
Alex Crichton
b6d041e4d5 Remove debugging code accidentally added in #1416 2019-04-08 07:49:58 -07:00
Alex Crichton
e4400ac8b4 Improve error message for non-copy struct fields
Make sure the error message points to the type in question instead of to
the `#[wasm_bindgen]` macro which can be overly confusing!
2019-04-08 07:35:14 -07:00
Alex Crichton
16745edf3f
Merge pull request #1416 from alexcrichton/js-string-valid-utf16
Add warnings about UTF-16 vs UTF-8 strings
2019-04-05 10:12:32 -05: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
Alex Crichton
d75ae42d4f
Merge pull request #1425 from c410-f3r/rustfmt
Update CONTRIBUTING to inform about code formatting
2019-04-05 08:25:45 -05:00
Caio
a9ad9a96db Update CONTRIBUTING to inform about code formatting 2019-04-05 09:41:00 -03:00
Alex Crichton
aa0aff674c
Merge pull request #1424 from fitzgen/fix-imports
Don't put anything before ES module imports
2019-04-04 20:27:37 -05:00
Nick Fitzgerald
dff9b9b1e3 Don't put anything before ES module imports
Because of some incorrect use of `js.push_str(..)`, we could sometimes emit code
before the ES modules imports, which is syntactically invalid:

    const __exports = {};
    import { Thing } from '...'; // Syntax error!

This has been fixed by making sure that the correct `imports` or `imports_post`
string is built up. We now also assert that the `js` string is empty at the
location where we add imports if we're using ES modules.
2019-04-04 15:53:43 -07:00
Alex Crichton
863a8b9cea
Merge pull request #1423 from alexcrichton/fix
Fix imported usage of `wasm_bindgen` macro
2019-04-04 13:42:20 -05:00
Alex Crichton
f48fdec21e Fix imported usage of wasm_bindgen macro
Make sure it refers to `__wasm_bindgen_class_marker` via an absolute
path!

Closes #1422
2019-04-04 09:56:16 -07:00
Alex Crichton
76a03adfa6
Merge pull request #1419 from alexcrichton/init-is-hard
Fix instantiation with a `Module`
2019-04-02 16:41:34 -05:00
Alex Crichton
e3473f5e9e Fix instantiation with a Module
This commit fixes the `init` function when passed a
`WebAssembly.Module`. Upon closer reading of the [spec] we see there's
two possible return values from `WebAssembly.instantiate`. If passed a
`Module`, it will return only the `Instance`. If passed a buffer source,
though, it'll return an object with the module/instance.

The fix here is to check the result value is an `Instance`, and if so
assume the input must have been a module so it's paired up in the
output.

Closes #1418

[spec]: http://webassembly.github.io/spec/js-api/index.html#webassembly-namespace
2019-04-02 14:19:24 -07:00
Alex Crichton
fa674df109
Merge pull request #1412 from c410-f3r/init-ts
Add TS type for init fn
2019-04-02 15:46:34 -05:00
Alex Crichton
a1c457bd15
Merge pull request #1414 from RReverser/smaller-realloc
Optimise encodeInto reallocations
2019-04-02 10:26:03 -05:00
Nick Fitzgerald
f367a4247b
Merge pull request #1417 from alexcrichton/closure-ref
Support 1-reference argument closures
2019-04-01 16:21:54 -07:00
Caio
b6317e3f24 Add TS type for init fn 2019-04-01 19:45:53 -03:00
Alex Crichton
d48f4995e5 Support 1-reference argument closures
This is work towards #1399, although it's just for one-argument closures
where the first argument is a reference. No other closures with
references in argument position are supported yet
2019-04-01 14:31:21 -07:00
Ingvar Stepanyan
2f28b8b80e Optimise encodeInto reallocations
Instead of doubling the size on each iteration, use precise upper limit (3 * JS length) if the string turned out not to be ASCII-only. This results in maximum of 1 reallocation instead of O(log N).

Some dummy examples of what this would change:
 - 1000 of ASCII chars: no change, allocates 1000 bytes and bails out.
 - 1000 ASCII chars + 1 '😃': before allocated 1000 bytes and reallocated to 2000; now allocates 1000 bytes and reallocates to 1006.
 - 1000 of '😃' chars: before allocated 1000 bytes, reallocated to 2000, finally reallocated again to 4000; now allocates 1000 bytes and reallocates to 4000 right away.

Related issue: #1313
2019-04-01 13:08:08 +01:00
Alex Crichton
c5f18b6099
Merge pull request #1408 from samcday/impl-debug-on-closure
Implement Debug on Closures
2019-03-29 07:32:11 -05:00
Sam Day
1914bba0be Implement Debug on Closures
resolves #1387
2019-03-29 09:07:48 +01:00
Alex Crichton
1121393203
Merge pull request #1403 from RReverser/expose-constructor
Add `constructor` property to `Object`
2019-03-28 10:55:22 -03:00
Alex Crichton
30b258515d
Merge pull request #1401 from alexcrichton/fix-u32
Fix handling of `u32` between Rust and JS
2019-03-27 17:38:00 -03:00
Alex Crichton
0160f6af45 Fix handling of u32 between Rust and JS
All numbers in WebAssembly are signed and then each operation on them
may optionally have an unsigned version. This means that when we pass
large signed numbers to JS they actually show up as large negative
numbers even though JS numbers can faithfully represent the type.

This is fixed by adding `>>>0` in a few locations in the generated
bindings to coerce the JS value into an unsigned value.

Closes #1388
2019-03-27 13:37:14 -07:00
Ingvar Stepanyan
db17e9d2a7 Add constructor property to Object 2019-03-27 14:25:55 +00:00
Alex Crichton
98e554c1fa
Merge pull request #1402 from samcday/patch-1
Quick typo fix in closure.rs
2019-03-27 08:08:04 -04:00
Alex Crichton
05fbbb2b92
Merge pull request #1358 from stevebob/book-linkcheck-pr
Installing and running the linkcheck mdbook backend
2019-03-27 08:04:49 -04:00
Sam
ea01043e9a
Quick type fix in closure.rs 2019-03-27 13:03:50 +01:00
Stephen Sherratt
3c12e13c04 Use rust template in mdbook test 2019-03-27 07:38:35 +00:00
Alex Crichton
e3aabcb27d
Merge pull request #1398 from RReverser/is-like-none
Consistently expose `is_like_none`
2019-03-26 14:29:46 -05:00
Ingvar Stepanyan
a5f5c7a9e8 Consistently expose is_like_none
Aside from visual deduplication, this actually fixes a bug in js2rust.rs where it didn't call `expose_is_like_none` but used `isLikeNone` inside of `arg.get_64()` branch.
2019-03-26 18:53:55 +00:00