Commit Graph

440 Commits

Author SHA1 Message Date
Satoshi Amemiya
efeefbd4c1 Support String.prototype.codePointAt 2018-06-26 22:07:34 +09:00
Satoshi Amemiya
ae847861e7 String - includes() support 2018-06-26 21:10:19 +09:00
belfz
a30509d142 implements Object.seal binding 2018-06-26 14:02:42 +02:00
xeqlol
a369f7a246 WeakMap bindings 2018-06-26 13:12:32 +05:00
Tim Ryan
5925871a05 Adds support for the UInt8Array constructor and its fill method. 2018-06-26 00:34:17 -04:00
R. Andrew Ohana
cc1db03e5a use both npm and yarn in ci 2018-06-25 17:22:51 -07:00
Nick Fitzgerald
0851025ca5 js: Implement bindings for Array.prototype.filter 2018-06-25 16:19:07 -07:00
Nick Fitzgerald
3212b0a019
Merge pull request #312 from jonathan-s/moar-methods
Lots of methods for Math
2018-06-25 14:44:36 -07:00
Jonathan Sundqvist
e05b1ae6ba Add clz32 to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
9b70f14a1c Add ceil to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
2de2a815d5 Add cube root (cbrt) to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
5eb744c7d6 Add atanh to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
3223a9af75 Add atan2 to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
7e514b939f Add atan to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
4b812ee47d Add asinh to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
94255c1ba9 Add asin to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
d40a314a91 Add acosh to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
230650055c Add acos to Math 2018-06-25 22:52:04 +02:00
Jonathan Sundqvist
9633642e6e Add abs to Math 2018-06-25 22:52:04 +02:00
Lachezar Lechev
44444920a4 Merge branch 'master' into string-support 2018-06-25 22:20:38 +02:00
Lachezar Lechev
36e79d23c4 String - startsWith/substring/indexOf 2018-06-25 21:30:04 +02:00
Nick Fitzgerald
7a688d6967
Merge branch 'master' into string-substr 2018-06-25 11:31:42 -07:00
Lachezar Lechev
d28d81f38d Add basic support for String.prototype.charAt() (#306)
* String - charAt() implementation

* String - charAt() - add js_class
2018-06-25 11:24:44 -07:00
Nick Fitzgerald
eb04d15a65 js: Add bindings to Object.keys 2018-06-25 10:45:53 -07:00
Lachezar Lechev
b81dc46220 String - substr() support 2018-06-24 23:03:39 +02:00
Sendil Kumar
32bc9f271c rebase to handle JsString 2018-06-24 20:48:37 +02:00
Sendil Kumar
233b35254f Merge branch 'master' into number-fixed-exponential 2018-06-24 20:46:53 +02:00
R. Andrew Ohana
21f49d0302 reenable part of js_globals::Number::to_locale_string 2018-06-24 10:43:24 -07:00
Sendil Kumar
0f57398917 Add to_fixed and to_exponential function 2018-06-24 10:08:23 +02:00
R. Andrew Ohana
8abecba983 fix and disable test js_globals::Number::to_locale_string 2018-06-23 18:25:47 -07:00
R. Andrew Ohana
35c5dafdd2 js globals: return JsString rather than String 2018-06-23 17:15:13 -07:00
Nick Fitzgerald
b1cbb56224
Merge branch 'master' into master 2018-06-23 16:19:08 -07:00
Nick Fitzgerald
0f5badf95e
Merge pull request #299 from jonathan-s/number
Adds valueOf and toString to Number
2018-06-23 16:04:35 -07:00
Alexander Kryvomaz
9e07c4935c bindings for Function.length and Function.name 2018-06-23 23:41:28 +03:00
Jonathan Sundqvist
6b5974d1bd Add toLocaleString to Number 2018-06-23 19:03:55 +02:00
Jonathan Sundqvist
f636f7b28d Add toPrecision to Number 2018-06-23 18:18:58 +02:00
Jonathan Sundqvist
bf56d5815b Add the binding of to_string to Number 2018-06-23 17:38:13 +02:00
Jonathan Sundqvist
a7f8e071fe Add the binding valueOf to number 2018-06-23 14:43:43 +02:00
belfz
e255925292 implements Object.prototype.valueOf() binding 2018-06-23 12:11:46 +02:00
kzvi
5ae6ee7aec add JsString binding to src/js.rs and tests 2018-06-22 17:51:44 -07:00
Jonathan Sundqvist
99ee74d153 Add binding for concat 2018-06-22 10:55:50 -07:00
Nick Fitzgerald
7825122feb Merge branch 'expose-bindings/object-to-locale-string' of https://github.com/belfz/wasm-bindgen into rollup 2018-06-22 10:51:17 -07:00
Nick Fitzgerald
ce14de21c3 Merge branch 'array-method' of https://github.com/jonathan-s/wasm-bindgen into rollup 2018-06-22 10:45:33 -07:00
belfz
39465c896c implements Object.prototype.toLocaleString() binding 2018-06-22 13:36:44 +02:00
Jonathan Sundqvist
a7bb555944 Add Sort to Array 2018-06-22 09:01:41 +02:00
robertdurst
a9ca64b689 Implement Array.length binding 2018-06-21 21:30:57 -07:00
Nick Fitzgerald
9e01e67aa3
Merge pull request #289 from wismer/array-iterator-method-bindings
Array iterator method bindings
2018-06-21 15:24:25 -07:00
Matt Long
a95476a8ee add binding for entries method 2018-06-21 17:21:35 -04:00
Matt Long
4cc73877a6 add binding for keys method 2018-06-21 17:00:02 -04:00
belfz
dd3740e2fb allows using &JsValue as an arg to Object's has_own_property 2018-06-21 22:51:30 +02:00
belfz
420eaffcb3 adds missing unit tests for property_is_enumerable 2018-06-21 21:32:03 +02:00
belfz
1e1276410a implements Object.prototype.isPrototypeOf() binding 2018-06-21 13:56:24 +02:00
belfz
77ad68673c implements Object.isPrototypeOf binding 2018-06-21 07:36:24 +02:00
Matt Long
a8cd428850 add binding for includes 2018-06-20 18:36:10 -04:00
Matt Long
eb6c2a239c add binding for toString 2018-06-20 18:23:26 -04:00
Matt Long
3cf522d2df add bindings for unshift 2018-06-20 18:07:30 -04:00
Matt Long
68acbeab25 add binding for shift 2018-06-20 18:03:26 -04:00
Matt Long
d705cd8bbf add binding for reverse 2018-06-20 18:00:58 -04:00
Matt Long
4611d7bdba add binding for push 2018-06-20 17:58:15 -04:00
Matt Long
73081180cd add binding for pop 2018-06-20 17:55:25 -04:00
Matt Long
2f6f734216 add binding for copyWithin 2018-06-20 17:51:02 -04:00
Matt Long
d155136f0e add binding for fill 2018-06-20 17:49:34 -04:00
Matt Long
e8bb0c2f98 add binding for slice 2018-06-20 17:46:10 -04:00
Matt Long
0b80888c0d add binding for join 2018-06-20 17:38:47 -04:00
Matt Long
667733e929 add binding for lastIndexOf 2018-06-20 17:36:35 -04:00
Matt Long
4a96ba3c72 add binding for indexOf 2018-06-20 17:23:38 -04:00
Jonathan Sundqvist
d89c7958eb Js binding for to_string 2018-06-20 21:55:41 +02:00
Nick Fitzgerald
5eda5504e9
Merge pull request #273 from FreeMasen/validate-ptr
Validate ptr
2018-06-19 16:45:31 -07:00
Nick Fitzgerald
224d20337f
Merge pull request #274 from fitzgen/js-sys
Expose objects and functions from the JavaScript global scope
2018-06-19 10:42:04 -07:00
Nick Fitzgerald
7b0e779ffd test: remove unnecessary test.ts files
The testing infrastructure will add exactly this default `test.ts` when it isn't
explicitly specified.
2018-06-19 10:17:42 -07:00
Nick Fitzgerald
a201cafdea test: Move Object-related js_globals tests to submodule file 2018-06-19 10:15:09 -07:00
Nick Fitzgerald
161fce9d50 Expose objects and functions from the JavaScript global scope
These are bindings to JavaScript's standard, built-in objects and their methods
and properties.

This does *not* include any Web, Node, or any other JS environment APIs. Only
the things that are guaranteed to exist in the global scope by the ECMAScript
standard.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
2018-06-18 16:41:01 -07:00
Robert Masen
e9ea2dabc1 add Validate ptr test 2018-06-18 15:34:48 -05:00
R. Andrew Ohana
d123bedc20 change some asserts to assert_(eq|ne)s 2018-06-18 13:10:07 -07:00
R. Andrew Ohana
0938858aa8 webidl: add support for static attributes 2018-06-15 12:22:14 -07:00
R. Andrew Ohana
fe5cde8636 webidl: add support for static methods 2018-06-15 12:09:42 -07:00
Nick Fitzgerald
639ccd53ce
Merge pull request #269 from ohanar/webidl_constructor
webidl: add support for (named) constructors
2018-06-15 11:35:29 -07:00
Robert Masen
19d6cf1488 Copy doc comments from Rust to JS (#265)
* backend comments complete

* better matching

* gen comments

* Add example

* Move test bindings gen to own fn

* move build step into build fn

* add fn to read js, refactor gen_bindings/test to allow for this

* Add comments test

* Update readmes

* add comments to travis

* fix broken tests

* +x on build.sh

* fix wbg cmd in build.sh

* Address fitzgen's comments
2018-06-15 09:20:56 -07:00
R. Andrew Ohana
cbec42e86c webidl: add support for named constructors 2018-06-14 16:20:20 -07:00
R. Andrew Ohana
c65cb51fba webidl: add support for constructors 2018-06-14 16:15:25 -07:00
R. Andrew Ohana
9b8c0b8fb9 small cleanup in testing framework 2018-06-11 18:00:33 -07:00
R. Andrew Ohana
077f50c6f2 webidl: add initial support for integration tests 2018-06-10 23:04:17 -07:00
Alex Crichton
659583b40d
Implement PartialEq for JsValue (#217)
Dispatch to JS's `===` operator internally
2018-06-01 16:47:45 -05:00
Alex Crichton
ad89d8457e
Fix tests by pinning versions of webpack (#219)
Looks like a newer version of webpack has broken tests, so let's use
package-lock.json to pin to an older version while we wait for a fix.
2018-06-01 13:42:59 -05:00
Nick Fitzgerald
daabbbd06e Add a stub test module for when we have webidl tests 2018-05-29 14:20:15 -07:00
Robert Masen
4ddd93d75d add char support (#206)
* add char support

* add char test

* remove __wbindgen_char fns

* re-order travis script

* update serve script

* remove binds to unused char functions

* add more wide character items to chars list

* remove unused code

* add char to readme

* remove built file
2018-05-22 12:34:41 -05:00
Alex Crichton
dd76707ea1 Prevent use-after-free with vectors
Awhile back slices switched to being raw views into wasm memory, but this
doens't work if we free the underlying memory unconditionally! Moving around a
`Vec` is already moving a lot of data, so let's copy it onto the JS heap instead
of leaving it in the wasm heap.
2018-05-21 11:23:46 -07:00
Alex Crichton
ca8809b4e9 Don't try to codegen static into an impl
Closes #194
2018-05-11 08:28:09 -07:00
Alex Crichton
06664b34ce Fix parsing some Rust keywords in attributes
Closes #193
2018-05-09 08:01:57 -07:00
Alex Crichton
237fff0698 Map u64/i64 to BigInt in JS
This commit is an implementation of mapping u64/i64 to `BigInt` in JS through
the unstable BigInt APIs. The BigInt type will ship soon in Chrome and so this
commit builds out the necessary support for wasm-bindgen to use it!
2018-05-05 18:51:20 -07:00
Alex Crichton
48a823c685 Remove slice logic of "commit to wasm"
When adding support for mutable slices I was under the impression that if the
wasm memory was reallocated while we were using it then we'd have to commit the
changes from the original buffer back to the new buffer. What I didn't know,
however, is that once the wasm memory is reallocated then all views into it are
supposed to be defunkt.

It looks like node 9 didn't have this implementation quite right and it appears
fixed in node 10, causing the deleted test here to fail. While this commit does
raise the question of whether this is the right approach to interact with slices
in JS I think the answer is still "yes". The user can always initiate the copy
if need be and that seems strictly better than copying 100% of the time.
2018-05-05 14:52:22 -07:00
Alex Crichton
139b7a1aae Don't use the global stack for string lengths
This commit updates the `Abi` associated type for all slice types to a
`WasmSlice` type, an aggregate of two `u32` integers. This translates to an ABI
where when passed as a function argument it expands to two integer arguments,
and when passed as a return value it passes a return pointer as the first
argument to get filled in.

This is hopefully more forwards-compatible with the host bindings proposal which
uses this strategy for passing string arguments at least. It's a little sketchy
what we're doing as there's not really a stable ABI yet, but hopefully this'll
all be relatively stable for awhile!
2018-05-02 21:03:50 -07:00
Alex Crichton
4304a262c6 Fix enums defined in submodules 2018-05-02 10:17:16 -07:00
Alex Crichton
0566a97485 Add support for mutable slices
This commit adds support for mutable slices to pass the boundary between JS and
Rust. While mutable slices cannot be used as return values they can be listed as
arguments to both exported functions as well as imported functions.

When passing a mutable slice into a Rust function (aka having it as an argument
to an exported Rust function) then like before with a normal slice it's copied
into the wasm memory. Afterwards, however, the updates in the wasm memory will
be reflected back into the original slice. This does require a lot of copying
and probably isn't the most efficient, but it should at least work for the time
being.

The real nifty part happens when Rust passes a mutable slice out to JS. When
doing this it's a very cheap operation that just gets a subarray of the main
wasm memory. Now the wasm memory's buffer can change over time which can produce
surprising results where memory is modified in JS but it may not be reflected
back into Rust. To accomodate this when a JS imported function returns any
updates to the buffer are copied back to Rust if Rust's memory buffer has
changed in the meantime.

Along the way this fixes usage of `slice` to instead use `subarray` as that's
what we really want, no copying. All methods have been updated to use `subarray`
accessors instead of `slice` or constructing new arrays.

Closes #53
2018-05-01 10:06:35 -07:00
Alex Crichton
4a873af8d1 Enable cargo test where possible
Currently `#[wasm_bindgen]` generates a bunch of references to symbols that
don't actually exist on non-wasm targets, making it more difficult to get a
crate working across multiple platforms. This commit updates the symbol
references to be dummy ones that panic on non-wasm targets to allow simple
testing/benchmarking to work on native targets.

While this isn't a perfect solution for #114 it's probably as good as we can do
for now pending upstream Cargo features, so I'm gonna say that it...

Closes #114
2018-04-27 15:01:35 -07:00
Alex Crichton
b8895b3a95 Add JsValue::{from_serde, into_serde}
These functions are activated with the `serde-serialization` feature of the
`wasm-bindgen` crate. When activated they will allow passing any arbitrary value
into JS that implements the `Serialize` trait and receiving any value from JS
using the `Deserialize` trait. The interchange between JS and Rust is JSON.

Closes #96
2018-04-26 20:45:22 -07:00
Alex Crichton
412bebca72 Add support for version specifications
This commit adds a `#[wasm_bindgen(version = "...")]` attribute support. This
information is eventually written into a `__wasm_pack_unstable` section.
Currently this is a strawman for the proposal in ashleygwilliams/wasm-pack#101
2018-04-25 22:23:02 -07:00
Alex Crichton
d9a71b43db Assert empty JS heap/stack in tests
Turns out there was a bug when passing a vector of `JsValue` instances back to
JS all objects were leaked rather than correctly removed from the global slab.
2018-04-25 22:15:28 -07:00
Alex Crichton
faed98b843 Correct how slices are iterated over
This commit fixes how the `getArrayJsValueFromWasm` function is defined to
correctly iterate over the slice by looking at the values rather than the
indices.

Closes #169
2018-04-25 21:58:49 -07:00
Alex Crichton
7108206835 Implement readonly struct fields
Add support for `#[wasm_bindgen(readonly)]` which indicates that an exported
struct field is readonly and attempting to set it in JS will throw an exception.

Closes #151
2018-04-20 10:56:10 -07:00
Alex Crichton
c6f7d3dfd5 Fix methods returning Self
Rewrite any instance of `Self` to the name of the class

Closes #137
2018-04-19 18:43:37 -07:00
Alex Crichton
ce31859590 Generate accessors for public struct fields
Automatically infer public struct fields as "JS wants to access this" and
generate appropriate getters/setters for the field. At this time the field is
required to implement `Copy`, but we will probably want to relax that in the
future to at least encompass `JsValue` and maybe other `Clone` values as well.

Closes #121
2018-04-19 16:49:46 -07:00
Alex Crichton
212703671a No need to expose ptr in TypeScript
This was needed long ago but is no longer needed!

Closes #147
2018-04-19 13:28:50 -07:00
Alex Crichton
748184ae66 Work with #![no_std] contexts
This commit adds support for both `#![no_std]` in the wasm-bindgen runtime
support (disabled by default with an on-by-default `std` feature). This also
adds support to work and compile in the context of `#![no_std]` crates.

Closes #146
2018-04-19 13:24:30 -07:00
Alex Crichton
792a8e132e Fix unused variables in generated code
Also deny all warnings in tests to prevent this creeping back in.

Closes #141
2018-04-19 13:16:59 -07:00
Alex Crichton
0e032955fb Use a length accessor instead of byteLength
This way we should be naturally compatible with normal JS arrays that get passed
in as well!

Closes #133
2018-04-16 13:50:21 -07:00
Alex Crichton
5efde3abe9 Be sure to generate classes for empty structs
Closes #131
2018-04-16 08:05:18 -07:00
Alex Crichton
c64f178543 Support closures with "rich" arguments
This commit adds support for closures with arguments like strings and such. In
other words, closures passed to JS can now have the same suite of arguments as
all functions that can be exported from Rust, as one might expect!

At this time due to the way trait objects work closures still cannot use types
with references like `&str`, but bare values like `String` or `ImportedType`
should work just fine.

Closes #104
2018-04-16 07:51:51 -07:00
konstin
3999642f66 Merge remote-tracking branch 'upstream/master' into new 2018-04-15 01:50:23 +02:00
konstin
f45ce1f239 Do only use ConstructorToken when needed
Also removing some effectively dead code
2018-04-15 01:29:09 +02:00
konstin
e87b32fb22 Allow arbitratry constructor names 2018-04-14 11:19:17 -07:00
konstin
32ab5a5644 Suppport for javascript constructors
This is a conservative version where the function used for the constructor must be called `new`
2018-04-14 11:19:17 -07:00
Alex Crichton
a8d6ca3d62 Add support for mutable stack closures
This commit adds support for passing `&mut FnMut(..)` to JS via imports. These
closures cannot be invoked recursively in JS (they invalidate themselves while
they're being invoked) and otherwise work the same as `&Fn(..)` closures.

Closes #123
2018-04-14 11:16:16 -07:00
Alex Crichton
656d69816d Move all tests to the same suite
Nowadays the compile times are mitigated with incremental compilation and
otherwise it's much more ergonomic to run only one test if they're all in the
same suite.
2018-04-09 15:32:06 -07:00
Alex Crichton
aaff0be441 Fix closure tests 2018-04-09 14:40:01 -07:00
Alex Crichton
f7f0d578e7 Support long-lived closures
Docs coming soon!
2018-04-09 14:34:21 -07:00
Alex Crichton
c0cad447c1 Initial support for closures
This commit starts wasm-bindgen down the path of supporting closures. We
discussed this at the recent Rust All-Hands but I ended up needing to pretty
significantly scale back the ambitions of what closures are supported. This
commit is just the initial support and provides only a small amount of support
but will hopefully provide a good basis for future implementations.

Specifically this commit adds support for passing `&Fn(...)` to an *imported
function*, but nothing elese. The `&Fn` type can have any lifetime and the JS
object is invalidated as soon as the import returns. The arguments and return
value of `Fn` must currently implement the `WasmAbi` trait, aka they can't
require any conversions like strings/types/etc.

I'd like to soon expand this to `&mut FnMut` as well as `'static` closures that
can be passed around for a long time in JS, but for now I'm putting that off
until later. I'm not currently sure how to implement richer argument types, but
hopefully that can be figured out at some point!
2018-04-09 14:34:21 -07:00
Alex Crichton
7f614c3c3a Reduce node/browser duplication
Centralize the export of a function to one location to reduce duplication in
various other locations checking whether Node is being targeted or not.
2018-04-03 13:12:28 -07:00
Alex Crichton
455e86ef6d Merge branch 'node-math' of https://github.com/ashleygwilliams/wasm-bindgen 2018-04-03 12:53:15 -07:00
David Flemström
86625e78bc Fix tests that are missing wasm_import_module 2018-04-03 11:28:25 +02:00
Alex Crichton
188d368583 Add some missing features to tests 2018-04-02 09:59:07 -07:00
David Flemström
73619b5d15 Add support for constructing JsValue instances generically 2018-04-02 09:59:01 -07:00
Alex Crichton
80243acc37 Fix running node tests 2018-03-29 14:49:36 -07:00
Ashley Williams
c525ecffc2 feat(test): add a failing math test 2018-03-29 22:29:39 +02:00
Ashley Williams
ae51c3b6f7 feat(node): support node enums 2018-03-29 17:11:28 +02:00
Ashley Williams
256b34736e feat(node): support node classes 2018-03-29 16:08:50 +02:00
Alex Crichton
a0bfb8103b Generate node.js require directives for --nodejs 2018-03-29 01:47:44 -07:00
Alex Crichton
02b7021053 Leverage new rustc wasm features
This commit leverages two new attributes in the Rust compiler,
`#[wasm_custom_section]` and `#[wasm_import_module]`. These two attributes allow
removing a lot of hacks found in wasm-bindgen and also allows removing the
requirement of `wasm-opt` to remove the unused data sections.

This does require two new nightly features but we already required the
`proc_macro` nightly feature and these will hopefully be stabilized before that
feature!
2018-03-24 10:36:19 -07:00
Alex Crichton
7ebc428646 Implement a js_name customization
This'll allow binding multiple signatures of a JS function as well as otherwise
changing the name of the JS function you're calling from the Rust function that
you're defining.

Closes #72
2018-03-22 19:05:14 -07:00
Alex Crichton
30936a6b22 Allow specifying getter/setter properties
Should help with style clashes!
2018-03-22 18:21:41 -07:00
Alex Crichton
8830f540a9 Add a structural bindgen attribute
This attribute indicates that methods are to be accessed in a structural method
rather than through their class. This should allow direct access to properties
embedded on objects rather than forcing all objects to have a class/prototype.
2018-03-22 17:37:27 -07:00
Alex Crichton
0e1fee5ddd Rename namespace to js_namespace
Along the way remove the namespace in Rust as this ended up causing too many
problems, alas! The `js_namespace` attribute now almost exclusively modifies the
JS bindings, hence the "js" in the name now.
2018-03-22 17:03:51 -07:00
Alex Crichton
4a4f8b18b6 Rename static to namespace
This commit renames the `static` attribute to `namespace` and simultaneously
reduces and expands the scope. The `namespace` attribute can now be applied to
all imports in addition to functions, and it no longer recognizes full typed
paths but rather just a bare identifier. The `namespace` attribute will generate
a Rust namespace to invoke the item through if one doesn't already exist (aka
bindign a type).
2018-03-21 09:55:16 -07:00
Alex Crichton
8e894fcfc5 Implement static imports
This allows importing static objects like `document`, `window`, or an arbitrary
JS object from a module
2018-03-21 08:09:59 -07:00
Alex Crichton
5638126598 Add more math intrinsics to test
Just in case more crop up!
2018-03-19 14:23:54 -07:00
William Lundstedt
89a00bee29 Support passing custom types by value into JS imports 2018-03-16 00:09:18 +00:00
Nick Fitzgerald
12d7c93a40 Add a test for using a dependency's types in bindings 2018-03-07 11:57:51 -08:00
Alex Crichton
8254d9f516 Add an option to detect node at runtime
Sometimes builds are done once and used in both the browser and in node, so add
an option to do runtime detection if necessary
2018-03-07 08:50:56 -08:00
Sendil Kumar
49a7b9fef5 Merge branch 'master' into fix-no-mangle 2018-03-05 23:26:22 +01:00
Sendil Kumar
0dd8a77757 fix: remove unwanted no_mangle and extern wherever applicable 2018-03-05 23:25:15 +01:00
Sendil Kumar
d5ac523fe2 feat: rename generated file to have bg instead of wasm 2018-03-05 22:25:14 +01:00
Alex Crichton
d9e1dae298 Migrate from rollup to webpack in tests
Building on the previous commit to invoke not invoke `npm install` this takes
the commit a step further (to hopefully fix some races) to use Webpack's native
bundled wasm support.

It turns out the circular dependencies between the wasm module and the module
using it wasn't quite working out so a number of imports had to be tweaked, but
otherwise it's a nice transition where we don't have to base64 encode anything
in tests any more!
2018-03-02 19:20:14 -08:00
Ryan Levick
37da9eba14 Address feedback on commit dab6ba1 2018-02-28 17:29:40 +01:00
Ryan Levick
dab6ba1df8 Enable returning a vector of js values 2018-02-28 10:56:56 +01:00
Ryan Levick
3ae6614738 Add test for custom values in enums 2018-02-23 17:44:48 +01:00
Ryan Levick
3a270b6510 Add test for enums 2018-02-23 17:30:18 +01:00
Alex Crichton
d66bc25749 Automatically bind float math functions
These tend to have one "pretty obvious" definition in JS anyway, so
let's paper over this deficiency in rustc for now by automatically
resolving any imports for these functions.

Closes #28
2018-02-17 16:44:31 -08:00
Alex Crichton
3c58aa7310 Support integer/float slices/vectors
Closes #5
2018-02-16 18:58:37 -08:00
Alex Crichton
7802535948 Fix #[wasm_bindgen] on structs with no exports
It should still be usable in other types!

Closes #27
2018-02-16 13:50:14 -08:00
Alex Crichton
9183236522 Implement getter/setter bindings 2018-02-14 13:16:02 -08:00
Alex Crichton
be368a6570 Don't look up properties in import shims
This'll match more closely what wasm eventually does natively, which is
importing these functions directly and not allowing changing them over time.

Closes #25
2018-02-14 12:51:58 -08:00
Alex Crichton
29771b574c Migrate from a macro to an attribute
This commit migrates from `wasm_bindgen!`-the-macro to
`#[wasm_bindgen]`-the-attribute. The actual mechanics of the macro are
relatively simple in just generating some shims here and there, but wrapping
everything in one huge macro invocation can often seem intimidating as it gives
off this feeling of "oh dear anything can happen here!" Using an attribute
should curb expectations much more greatly of "oh there's just some extra stuff
happening behind the scenes".

The usage is otherwise relatively straightforward and close to what it was
before, but check out the DESIGN.md/README.md changes for more info!
2018-02-08 10:18:16 -08:00
Alex Crichton
e9d612a343 Implement optionally catching exceptions 2018-02-06 19:04:12 -08:00
Alex Crichton
43ee52bcbf Change schemes for encoding custom type names
Store JSON a utf-32, map hashes of names to a `char` and store that name
in the map, and then do a reverse mapping when generating JS
2018-02-06 16:56:26 -08:00
Alex Crichton
8312f3ae9f Fix programs with two wasm_bindgen! invocations
Saw the bug coming. Added an assert. Assert tripped. Bug now fixed!
2018-02-06 15:52:44 -08:00
Alex Crichton
ec5f0a29f7 Add a #[wasm_bindgen(constructor)] attribute
This can be used for specifying that a static function should actually delegate
to `new`
2018-02-06 15:25:46 -08:00
Alex Crichton
e60aa6a990 Rename JsObject to JsValue
Let's reserve `JsObject` for something we actually know is an object
2018-02-06 15:04:46 -08:00
Alex Crichton
56b7fa453a Fix some class import methods and auto gc
The runtime functions are now moved to the `wasm-bindgen` crate and are
auto-gc'd if they don't end up actually being required.
2018-02-06 08:58:15 -08:00
Alex Crichton
28966d9853 Fix String type in imports 2018-02-06 08:39:49 -08:00
Alex Crichton
d2f2ed8c1a Get the import-class test working 2018-02-06 08:23:51 -08:00
Alex Crichton
d5ff725913 Greatly simplify handling of types in Rust
Push the compiler to do trait resolution to figure out what each type is bound
with in JS, and that way we can accept effectively all types (so long as they
implement a trait).
2018-02-06 07:56:14 -08:00
Alex Crichton
0320bc0d7c more-wip 2018-02-05 16:39:11 -08:00
Alex Crichton
8f8da49dab wip 2018-02-05 14:24:25 -08:00
Alex Crichton
c51a342cb3 Rewrite wasm-bindgen with ES6 modules in mind
This commit is a mostly-rewrite of the `wasm-bindgen` tool. After some recent
discussions it's clear that the previous model wasn't quite going to cut it, and
this iteration is one which primarily embraces ES6 modules and the idea that
this is a polyfill for host bindings.

The overall interface and functionality hasn't changed much but the underlying
technology has now changed significantly. Previously `wasm-bindgen` would emit a
JS file that acted as an ES6 module but had a bit of a wonky interface. It
exposed an async function for instantiation of the wasm module, but that's the
bundler's job, not ours!

Instead this iteration views each input and output as a discrete ES6 module. The
input wasm file is interpreted as "this *should* be an ES6 module with rich
types" and the output is "well here's some ES6 modules that fulfill that
contract". Notably the tool now replaces the original wasm ES6 module with a JS
ES6 module that has the "rich interface". Additionally a second ES6 module is
emitted (the actual wasm file) which imports and exports to the original ES6
module.

This strategy is hoped to be much more amenable to bundlers and controlling how
the wasm itself is instantiated. The emitted files files purely assume ES6
modules and should be able to work as-is once ES6 module integration for wasm is
completed.

Note that there aren't a ton of tools to pretend a wasm module is an ES6 module
at the moment but those should be coming soon! In the meantime a local
`wasm2es6js` hack was added to help make *something* work today. The README has
also been updated with instructions for interacting with this model.
2018-01-29 21:50:01 -08:00
Alex Crichton
b38c273ee5 Add an --output-js flag
This'll output just vanilla JS rather than TypeScript!

Closes #8
2018-01-24 19:15:34 -08:00
Alex Crichton
0b81185c99 Expose primitive information about JsObject
Adds bindings for wbindgen to fill in via JS bindings to read the various
primitive properties of a JS value.
2017-12-31 15:45:47 -08:00
Alex Crichton
4151461ab9 Expose construction of a JsObject as a string
Start fleshing out the `JsObject` API!
2017-12-31 14:44:44 -08:00
Alex Crichton
bef908a9b1 Add an option to "uglify" imports
This commit adds an option to "uglify" the wasm module's imports/exports so
those which are controlled by bindgen are renamed to a shorter (probably one
letter) names. This'll hopefully help cut down on both the wasm size slightly
and also the generated JS as the glue we're talking to wasm over won't require
such large names all the time.
2017-12-24 15:32:40 -08:00
Alex Crichton
6aacff6a80 Further optimize non-debug output
Remove a bunch of exception throws in favor of type casts in TypeScript and
remove some type assertions as well that TypeScript should uphold.
2017-12-20 13:24:18 -08:00
Alex Crichton
b548239e02 Don't generate code for dead imports 2017-12-20 11:34:53 -08:00
Alex Crichton
5e80b082a9 Allow imports to return JS objects 2017-12-20 10:44:08 -08:00
Alex Crichton
294c5e147b Support passing booleans back and forth 2017-12-20 10:22:18 -08:00
Alex Crichton
5fe842e9bd Allow extra exports not part of wasm-bindgen
Currently throw them all in an interface under `extra` in the main exports
interface. May change in the future...
2017-12-20 08:11:06 -08:00
Alex Crichton
a12a8f414c Support imports outside of wasm_bindgen! 2017-12-20 07:58:41 -08:00
Alex Crichton
66ae545bff Add support for raw pointers in Rust 2017-12-20 07:35:14 -08:00
Alex Crichton
d3387d591f Start optimizing code size:
* Use a bundled custom `WasmRefCell` instead of the one in the standard library.
  This one primarily doesn't panic via libstd which means that its code
  footprint is much smaller.
* Add a `throw` function to `wasm_bindgen`-the-crate which can be used to throw
  an exception in JS from Rust. This is useful as a cheap way to throw an
  exception code-wise (little code bloat) and it's also a great way of reporting
  error messages to JS!
* Cut down on the code size of `__wbindgen_malloc` by aborting on huge requests
  earlier.
* Use a custom `assert_not_null` function which delegates to `throw` to test for
  incoming null pointers
2017-12-19 19:53:55 -08:00
Alex Crichton
85cdb51719 Generate TypeScript by default instead of JS
This is what's needed in the immediate future anyway, so let's do that!
2017-12-19 19:06:48 -08:00
Alex Crichton
946e5317fe Support passing JS objects through Rust 2017-12-19 09:25:41 -08:00
Alex Crichton
eda9beae25 Get imports working in a basic capacity 2017-12-18 21:43:16 -08:00
Alex Crichton
1ffcb90d2d Ensure class arguments have the expected type 2017-12-18 19:01:37 -08:00
Alex Crichton
ebc97438e7 Add a test that two mutable borrows is not ok 2017-12-18 16:24:31 -08:00
Alex Crichton
eebe8b21a2 Fix generation for a fn with two string args 2017-12-18 16:13:37 -08:00
Alex Crichton
62808e8d99 Add some tests for exceptions 2017-12-18 14:44:09 -08:00
Alex Crichton
6593b5ef69 Classes are now working! 2017-12-18 14:31:01 -08:00
Alex Crichton
7c510a8a7e Start adding support for classes 2017-12-18 12:39:14 -08:00
Alex Crichton
2225942000 Test two macro invocations 2017-12-14 21:56:40 -08:00
Alex Crichton
1b4f10217c Start handling strings 2017-12-14 21:55:21 -08:00
Alex Crichton
d5897c6e56 Test the eventual desired interface 2017-12-14 20:07:26 -08:00
Alex Crichton
d2d9f6be11 Avoid registry/git repo updates in tests
Use the main lockfile as a template, also print out how long each
command takes.
2017-12-14 19:36:41 -08:00
Alex Crichton
2926e6e9f4 Initial commit 2017-12-14 19:31:01 -08:00