Commit Graph

419 Commits

Author SHA1 Message Date
Alex Crichton
1d0c333a2b Run cargo fmt over all code 2019-08-12 11:28:37 -07:00
Alex Crichton
67e858e32a
Merge pull request #1638 from ThomasdenH/master
Add is_truthy, is_falsy
2019-08-08 12:35:01 -05:00
Alex Crichton
adde6c2da7 Correct base calculation in anyref allocator
This `base` value is the raw value coming out of the first call to
`table.grow`. Throwing in the addition of `JSIDX_RESERVED` just wasn't
right!
2019-08-01 12:00:33 -07:00
Pauan
59af3186af Fixing CI build error 2019-07-19 23:32:58 +02:00
Pauan
7b6ef7087e Adding in note to the intern docs 2019-07-19 23:29:34 +02:00
Pauan
f8da1e672f Fixing unsafe_get_str function 2019-07-19 22:15:07 +02:00
Pauan
554ef90035 Fixing issue with wasm-interpreter 2019-07-19 22:03:33 +02:00
Pauan
c82253ca68 Fixing doc test error 2019-07-18 23:40:16 +02:00
Pauan
366ed2308f Adding in docs for intern 2019-07-18 22:40:56 +02:00
Pauan
544ec49e02 Shifting the unsafe responsibility a bit 2019-07-18 22:21:48 +02:00
Pauan
ca15a59ace Changing from uluru to HashMap 2019-07-18 21:51:29 +02:00
Pauan
3177fa9edc Minor doc fix 2019-07-18 21:51:29 +02:00
Pauan
2405fad319 Shifting the unsafety guarantees around 2019-07-18 21:51:29 +02:00
Pauan
4e504654d1 Undoing some formatting 2019-07-18 21:51:28 +02:00
Pauan
fd88626e38 Fixing compile errors 2019-07-18 21:51:28 +02:00
Pauan
2ee4c54f00 Changing to use WasmSlice for the caching 2019-07-18 21:51:28 +02:00
Pauan
f7e8e70684 Fixing compile errors 2019-07-18 21:51:28 +02:00
Pauan
f28cfc26fe Fixing some things for the cache 2019-07-18 21:51:28 +02:00
Pauan
0359da2060 Potential fix for OptionIntoWasmAbi? 2019-07-18 21:51:28 +02:00
Pauan
0a61e12bd1 Making interning manual 2019-07-18 21:51:28 +02:00
Pauan
86a8842f24 Changing IntoWasmAbi to use interning 2019-07-18 21:51:28 +02:00
Richard Dodd
2541507789 Add in (unsafe and incorrect) impls of Send/Sync that are now required. 2019-07-06 16:30:29 +01:00
Thomas
0ee7236698 Define is_truthy in terms of is_falsy 2019-07-02 19:06:44 +02:00
Thomas
e61f691e0b Add is_truthy, is_falsy 2019-07-02 18:44:06 +02:00
Alex Crichton
792ab403a1
Merge pull request #1625 from alexcrichton/less-return-ptr
Remove `__wbindgen_global_argument_ptr` intrinsic
2019-06-26 13:36:57 +02:00
Alex Crichton
b9c27b93a5 Update all non-mutable slices into Rust to use AllocCopy
This commit migrates all non-mutable slices incoming into Rust to use
the standard `AllocCopy` binding instead of using a custom `Slice`
binding defined by `wasm-bindgen`. This is done by freeing the memory
from Rust rather than freeing the memory from JS. We can't do this for
mutable slices yet but otherwise this should be working well!
2019-06-25 05:44:32 -07:00
Alex Crichton
eb550f5b4f Remove __wbindgen_global_argument_ptr intrinsic
We don't actually need this since we can simply pass in a number like 8
for the return pointer all the time. There's no need to allocate more
space in static data for a return pointer tha may not even get used!
2019-06-25 05:24:08 -07:00
Alex Crichton
a021a967b2 Remove the long-defunkt Stack trait
This was used oh-so-long ago but hasn't been used in a very long time
since then. It's served no purpose for a very long time now and I don't
think we have a plan for giving it a purpose any time soon, so let's
remove it.
2019-06-25 05:08:50 -07:00
Alex Crichton
d9e53ac2f6 Switch to debug_assert_eq! in intrinic
Reduce the code size of wasm files by avoiding an `assert_eq!` and panic
code in production builds.
2019-06-25 04:55:16 -07:00
Alex Crichton
83a3f5d44a Run cargo fmt --all 2019-06-13 08:30:06 -07:00
Alex Crichton
6796bc6895 Communicate exceptions through global memory
Instead of allocating space on the stack and returning a pointer we
should be able to use a single global memory location to communicate
this error payload information. This shouldn't run into any reentrancy
issues since it's only stored just before returning to wasm and it's
always read just after returning from wasm.
2019-06-11 11:41:05 -07:00
Alex Crichton
cfd3e0406f Split symbol intrinsics into two
This allows using WebIDL bindings types to describe both of them instead
of having a custom ABI, allowing for more direct and rich bindings
eventually!
2019-06-05 07:52:14 -07:00
Alex Crichton
3b5e3edd18 Fix anyref closure transformations
* Catch all closures by walking all `Descriptor` values and looking for
  either `Function` or `Closure`.
* Update the correct arguments for wasm by ensuring that the closure
  modifications skip the first two arguments.
2019-06-05 07:52:14 -07:00
Alex Crichton
68c5233f80 First refactor for WebIDL bindings
This commit starts the `wasm-bindgen` CLI tool down the road to being a
true polyfill for WebIDL bindings. This refactor is probably the first
of a few, but is hopefully the largest and most sprawling and everything
will be a bit more targeted from here on out.

The goal of this refactoring is to separate out the massive
`crates/cli-support/src/js/mod.rs` into a number of separate pieces of
functionality. It currently takes care of basically everything
including:

* Binding intrinsics
* Handling anyref transformations
* Generating all JS for imports/exports
* All the logic for how to import and how to name imports
* Execution and management of wasm-bindgen closures

Many of these are separable concerns and most overlap with WebIDL
bindings. The internal refactoring here is intended to make it more
clear who's responsible for what as well as making some existing
operations much more straightforward. At a high-level, the following
changes are done:

1. A `src/webidl.rs` module is introduced. The purpose of this module is
   to take all of the raw wasm-bindgen custom sections from the module
   and transform them into a WebIDL bindings section.

  This module has a placeholder `WebidlCustomSection` which is nowhere
  near the actual custom section but if you squint is in theory very
  similar. It's hoped that this will eventually become the true WebIDL
  custom section, currently being developed in an external crate.

  Currently, however, the WebIDL bindings custom section only covers a
  subset of the functionality we export to wasm-bindgen users. To avoid
  leaving them high and dry this module also contains an auxiliary
  custom section named `WasmBindgenAux`. This custom section isn't
  intended to have a binary format, but is intended to represent a
  theoretical custom section necessary to couple with WebIDL bindings to
  achieve all our desired functionality in `wasm-bindgen`. It'll never
  be standardized, but it'll also never be serialized :)

2. The `src/webidl.rs` module now takes over quite a bit of
   functionality from `src/js/mod.rs`. Namely it handles synthesis of an
   `export_map` and an `import_map` mapping export/import IDs to exactly
   what's expected to be hooked up there. This does not include type
   information (as that's in the bindings section) but rather includes
   things like "this is the method of class A" or "this import is from
   module `foo`" and things like that. These could arguably be subsumed
   by future JS features as well, but that's for another time!

3. All handling of wasm-bindgen "descriptor functions" now happens in a
   dedicated `src/descriptors.rs` module. The output of this module is
   its own custom section (intended to be immediately consumed by the
   WebIDL module) which is in theory what we want to ourselves emit one
   day but rustc isn't capable of doing so right now.

4. Invocations and generations of imports are completely overhauled.
   Using the `import_map` generated in the WebIDL step all imports are
   now handled much more precisely in one location rather than
   haphazardly throughout the module. This means we have precise
   information about each import of the module and we only modify
   exactly what we're looking at. This also vastly simplifies intrinsic
   generation since it's all simply a codegen part of the `rust2js.rs`
   module now.

5. Handling of direct imports which don't have a JS shim generated is
   slightly different from before and is intended to be
   future-compatible with WebIDL bindings in its full glory, but we'll
   need to update it to handle cases for constructors and method calls
   eventually as well.

6. Intrinsic definitions now live in their own file (`src/intrinsic.rs`)
   and have a separated definition for their symbol name and signature.
   The actual implementation of each intrinsic lives in `rust2js.rs`

There's a number of TODO items to finish before this merges. This
includes reimplementing the anyref pass and actually implementing import
maps for other targets. Those will come soon in follow-up commits, but
the entire `tests/wasm/main.rs` suite is currently passing and this
seems like a good checkpoint.
2019-06-05 07:52:14 -07:00
Alex Crichton
82467f9793 Use dyn with all trait objects
Fixes new warnings showing up on nightly nowadays.
2019-06-03 08:28:55 -07:00
Alex Crichton
c876bd6268
Merge pull request #1570 from DiamondLovesYou/master
Support 8 argument closures.
2019-06-03 09:36:41 -05:00
Richard Diamond
03218d9d3c Support 8 argument closures. 2019-06-01 04:19:26 -05:00
Gus Caplan
2cc40a27d2
Run fmt and clippy 2019-05-28 09:52:44 -05:00
Alex Crichton
b964201831
Merge pull request #1531 from alexcrichton/less-cruft
Remove thread_local! weirdness in `anyref.rs`
2019-05-13 11:52:17 -05:00
Alex Crichton
79dba40e61 Remove thread_local! weirdness in anyref.rs
Resolves an old comment long since been fixed, and confirmed that we
still don't generate extra cruft!

Closes #1523
2019-05-13 09:35:15 -07:00
Alex Crichton
542076d658 Protect against segfaults calling destroyed closures
This commit updates the drop glue generated for closures to simply
ignore null pointers. The drop glue can be called in erroneous
situations such as when a closure is invoked after it's been destroyed.
In these cases we don't want to segfault and/or corrupt memory but
instead let the normal error message from the invoke glue continue to
get propagated.

Closes #1526
2019-05-13 07:22:33 -07:00
Nick Fitzgerald
3348ecebdf rustfmt src/anyref.rs 2019-05-09 15:57:21 -07:00
Nick Fitzgerald
450c9234ad Add the anyref_heap_live_count function
This is useful for debugging and writing tests that assert various operations do
not leak `JsValue`s.
2019-05-09 15:57:21 -07:00
Nick Fitzgerald
f4c5532982 Reorder and organize instrinsic extern declarations 2019-05-09 09:17:13 -07:00
Alex Crichton
c96e3ce097 Fix __wbindgen_object_drop_ref unnecessary bindings
This commit fixes an issue where bindings for
`__wbindgen_object_drop_ref` are generated even if the function isn't
actually used by the final wasm file. This is currently due to the fact
that we run gc passes pretty late in wasm-bindgen and one of the
intrinsics that ended up getting gc'd referenced the
`__wbindgen_object_drop_ref` intrinsic function.

The fix here is somewhat naive by just updating the intrinsic to not
actually use `__wbindgen_object_drop_ref`. This may not be a long-term
solution but it should be good enough for now at least.
2019-05-01 12:13:12 -07:00
Alex Crichton
ff1addbbaa Run cargo fmt 2019-04-16 10:52:27 -07:00
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
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