Commit Graph

419 Commits

Author SHA1 Message Date
Ivan Enderlin
c450fbf237
feat(js) Support exception on WebAssembly::validate. 2018-07-04 15:51:55 +02:00
Jannik Keye
008f17143b fix: Reflect.has target should be &Object 2018-07-04 15:32:34 +02:00
Ivan Enderlin
fe25a9a268
feat(js) Implement the WebAssembly.validate binding. 2018-07-04 15:27:01 +02:00
Marcin Baraniecki
2694dd4dee
Merge pull request #385 from toVersus/js_date
bindings for date.getDay/getFullYear
2018-07-04 14:56:22 +02:00
Jannik Keye
3442f9d9d7 fix: Reflect.has 2018-07-04 13:18:06 +02:00
Jannik Keye
1397f9b05a feat: add Reflect.setPrototypeOf 2018-07-04 13:13:35 +02:00
Jannik Keye
eb3f67a36f feat: add Reflect.set 2018-07-04 13:08:43 +02:00
Jannik Keye
fc82ba4ec3 feat: add Reflect.preventExtensions 2018-07-04 12:56:37 +02:00
Jannik Keye
e36f982391 feat: add Reflect.ownKeys 2018-07-04 12:53:38 +02:00
toversus
e95994fd19 bindings for Date.prototype.getFullYear() 2018-07-04 19:52:12 +09:00
Jannik Keye
eb245d5503 feat: add Reflect.isExtensible 2018-07-04 12:49:07 +02:00
Jannik Keye
7c297ccfb4 feat: add Reflect.has 2018-07-04 12:44:49 +02:00
toversus
3007e813ea bindings for Date.prototype.getDay() 2018-07-04 19:41:06 +09:00
Jannik Keye
edddd4b08e feat: add Reflect.getPrototypeOf 2018-07-04 12:39:56 +02:00
Jannik Keye
2422c5e945 feat: add Reflect.getOwnPropertyDescriptor 2018-07-04 12:35:40 +02:00
Jannik Keye
3ba00bc13c feat: add Reflect.get 2018-07-04 12:31:24 +02:00
Jannik Keye
5fa18f8f40 feat: add Reflect.deleteProperty 2018-07-04 12:24:52 +02:00
Jannik Keye
07a726b9dc feat: add Reflect.defineProperty 2018-07-04 12:17:01 +02:00
Jannik Keye
13b3b0d87a feat: add Reflect.construct 2018-07-04 12:07:02 +02:00
Jannik Keye
592d426e4f feat: add Reflect.apply 2018-07-04 11:43:34 +02:00
Alexander Kryvomaz
eac2b05b1b added catch attribute to the Generator methods, consistent rust keyword name 2018-07-04 01:22:56 +03:00
Alexander Kryvomaz
b797bbc39c bindings for Generator.throw() 2018-07-03 23:48:54 +03:00
Alexander Kryvomaz
39d79eb037 bindings for Generator.return() 2018-07-03 23:47:10 +03:00
Alexander Kryvomaz
6e95ba20f1 bindings for Generator.next() 2018-07-03 23:42:49 +03:00
Jonathan Sundqvist
17fde01243
Merge pull request #378 from jhenninger/math-bindings
Bindings for Math.pow, round, sign, sin, sinh, sqrt, tan, tanh and trunc
2018-07-03 21:08:28 +02:00
Johannes Henninger
b689a78351 Bindings for Math.pow, round, sign, sin, sinh, sqrt, tan, tanh and trunc 2018-07-03 20:00:56 +02:00
Ivan Enderlin
df5fec22d9
fix(js) Use f64 instead of Number. 2018-07-03 14:26:00 +02:00
Ivan Enderlin
fe4c150431
Merge branch 'master' into js_date 2018-07-03 14:12:05 +02:00
Johannes Henninger
6dede6f20f Use f64 for most Math.* bindings (#369) 2018-07-02 23:41:57 -05:00
Marcin Baraniecki
dcb3415da8 Expose bindings/object is* methods (#363)
* implements Object.isExtensible() binding

* implements Object.isFrozen() binding

* implements Object.isSealed() binding
2018-07-02 10:32:16 -05:00
Marcin Baraniecki
37fc159061 implements Object.preventExtensions() binding (#364) 2018-07-02 10:31:40 -05:00
Sendil Kumar N
10ffe8b3be
Merge pull request #361 from brisad/string-lower-and-upper-case
Bindings for string lower and upper case
2018-07-02 09:26:47 +02:00
belfz
1d04203e89 implements Object.values() binding 2018-07-01 23:50:10 +02:00
Michael Hoffmann
d5d451b94b Add binding for String.prototype.toUpperCase 2018-07-01 23:12:42 +02:00
Michael Hoffmann
58560f1408 Add binding for String.prototype.toLowerCase 2018-07-01 23:11:13 +02:00
Jonathan Sundqvist
bfffd58683
Merge pull request #359 from akryvomaz/master
bindings for Function.prototype.bind, decodeURIComponent, encodeURIComponent
2018-07-01 16:55:18 +02:00
Alexander Kryvomaz
609bf34d60 bindings for encodeURIComponent 2018-07-01 15:59:12 +03:00
Alexander Kryvomaz
0f07dd9048 bindings for decodeURIComponent 2018-07-01 15:53:44 +03:00
Alexander Kryvomaz
f850a6fafc bindings for Function.prototype.bind() 2018-07-01 15:44:36 +03:00
belfz
ce9b95635d implements Object.setPrototypeOf() binding 2018-07-01 11:52:22 +02:00
Satoshi Amemiya
f9c804db20 Add support for js::Error 2018-06-29 23:24:46 +09:00
Nick Fitzgerald
37293ee42a
Merge pull request #344 from autodidaddict/math-externs
Binding for Math.cos,cosh,exp,expml,fround,imul,log,log10,log1p,log2
2018-06-28 15:52:45 -07:00
Nick Fitzgerald
5ff6329d29
Merge pull request #349 from jannikkeye/bindings-map
Add bindings for Map.xx
2018-06-28 15:46:07 -07:00
Nick Fitzgerald
e31da84bce
Merge pull request #340 from ohanar/rustfmt
Use rustfmt for standarized formatting
2018-06-28 15:17:23 -07:00
Jannik Keye
d868ff26ef Add bindings for Set.xx (#347)
* feat(Set): add Set.add

* feat(Set): add Set.clear

* feat(Set): add Set.delete

* feat(Set): add Set.has

* feat(Set): add Set.new

* feat(Set): add Set.size

* feat(Set/SetIterator): add Set.entries

* feat(Set/SetIterator): add Set.keys

* feat(Set/SetIterator): add Set.values
2018-06-28 15:57:49 -05:00
Chris Kolodin
9193218648 add bindings for array.prototype.some() (#341)
following the example set in https://github.com/rustwasm/wasm-bindgen/pull/314
2018-06-28 15:57:01 -05:00
Jannik Keye
e0a70417ce feat(Map/MapIterator): add Map.values 2018-06-28 22:00:02 +02:00
Jannik Keye
fc131ee97e feat(Map/MapIterator): add Map.keys 2018-06-28 21:59:11 +02:00
Jannik Keye
228abaa4ae feat(Map/MapIterator): add Map.entries 2018-06-28 21:58:34 +02:00
Jannik Keye
ea19775639 feat(Map): add Map.size 2018-06-28 21:56:49 +02:00
Jannik Keye
6f90bd677b feat(Map): add Map.set 2018-06-28 21:55:55 +02:00
Jannik Keye
27ee57175a feat(Map): add Map.new 2018-06-28 21:55:10 +02:00
Jannik Keye
07e61e1175 feat(Map): add Map.has 2018-06-28 21:54:10 +02:00
Jannik Keye
e0b399643a feat(Map): add Map.get 2018-06-28 21:53:20 +02:00
Jannik Keye
f7e4019e72 feat(Map): add Map.delete 2018-06-28 21:52:27 +02:00
Jannik Keye
ab0546963b feat(Map): add Map.clear 2018-06-28 21:51:39 +02:00
Kevin Hoffman
81e68517f2 Adding line separator in code docs above MDN URLs. 2018-06-28 15:05:10 -04:00
Kevin Hoffman
3e84b97de2 Binding for Math.cos,cosh,exp,expml,fround,imul,log,log10,log1p,log2 2018-06-28 12:46:53 -04:00
R. Andrew Ohana
9127a0419f rustfmt all the things 2018-06-27 22:42:34 -07:00
Nick Fitzgerald
40722b7ae3
Merge pull request #333 from Hywan/js_boolean
feat(js) Implement `Boolean` bindings.
2018-06-27 14:36:00 -07:00
Nick Fitzgerald
5aa648a2e8
Merge pull request #335 from xeqlol/weakset-bindings
Implement Weakset bindings
2018-06-27 14:27:48 -07:00
Nick Fitzgerald
e40a359278
Merge pull request #336 from belfz/expose-bindings/array-prototype-every
implements Array.prototype.every()
2018-06-27 09:11:21 -07:00
Nick Fitzgerald
4ba61c1c20
Merge pull request #332 from Hywan/js_test
test(js) Fix file permissions, and update a comment
2018-06-27 09:08:26 -07:00
belfz
dacf406dbd implements Array.prototype.every() 2018-06-27 13:45:47 +02:00
Dimitrii Nemkov
72be16c8ff Forgotten comment 2018-06-27 13:48:32 +05:00
Dimitrii Nemkov
761a9272ca Added WeakSet delete method 2018-06-27 13:44:01 +05:00
Dimitrii Nemkov
6b798a3508 Added WeakSet add method 2018-06-27 13:38:33 +05:00
Dimitrii Nemkov
846e5aaacc Added WeakSet has method 2018-06-27 13:26:53 +05:00
Dimitrii Nemkov
a0dda505d9 Added WeakSet constructor 2018-06-27 13:15:47 +05:00
Ivan Enderlin
a4d47afda6
feat(js) Implement the Date.UTC binding. 2018-06-27 09:41:16 +02:00
Ivan Enderlin
e334c0c5af
feat(js) Implement the Date.now binding. 2018-06-27 09:40:40 +02:00
Ivan Enderlin
869d99b870
feat(js) Implement Number.new binding. 2018-06-27 09:36:37 +02:00
Ivan Enderlin
91bc7a199c
feat(js) Implement Boolean bindings.
Cf https://github.com/rustwasm/wasm-bindgen/issues/275.
2018-06-27 09:07:47 +02:00
Ivan Enderlin
c99c0f8483
test(js) Fix file permissions, and update a comment. 2018-06-27 08:33:37 +02:00
gaurikholkar
073cf7455b binding for Math.floor 2018-06-27 10:44:43 +05:30
Nick Fitzgerald
c16b9a903c
Merge pull request #330 from elpiel/string-prototypes
String - length, trim, trimLeft, trimRight, trimStart, trimEnd, valueOf, toString
2018-06-26 17:10:15 -07:00
Lachezar Lechev
16517fadcb String - toString and valueOf 2018-06-26 22:21:51 +02:00
Lachezar Lechev
9f087241a1 String - length, trim, trimStart & trimLeft, trimEnd & trimRight 2018-06-26 22:10:25 +02:00
Nick Fitzgerald
919c2bedac
Merge pull request #318 from xeqlol/weakmap-bindings
WeakMap bindings
2018-06-26 12:55:30 -07:00
Nick Fitzgerald
f0614e92e8
Merge pull request #328 from akryvomaz/master
bindings for Function.apply() and Function.toString()
2018-06-26 12:54:10 -07:00
Dimitrii Nemkov
a6c7b4b69f Changed keys' type JsValue -> Object, changed description of WeakMap constructor 2018-06-26 23:50:31 +05:00
Alexander Kryvomaz
48061aaab6 bindings for Function.prototype.apply() and Function.prototype.toString() 2018-06-26 21:35:28 +03:00
Dimitrii Nemkov
a6d62c696f Merge branch 'master' into weakmap-bindings 2018-06-26 23:29:48 +05:00
Herman J. Radtke III
3833c94400
js: Implement bindings for Array.isArray 2018-06-26 11:11:02 -07:00
Nick Fitzgerald
df5862bd7e
Merge branch 'master' into string-code_point_at 2018-06-26 10:39:26 -07:00
Nick Fitzgerald
ff80029cf0
Merge branch 'master' into string-concat 2018-06-26 10:32:42 -07:00
Nick Fitzgerald
6dcbc4a0cc
Merge branch 'master' into date 2018-06-26 10:25:26 -07:00
Nick Fitzgerald
e8c6c40f10
Merge pull request #323 from rail44/string-char_code_at
Support String.prototype.charCodeAt
2018-06-26 10:23:10 -07:00
Nick Fitzgerald
c836639229
Merge pull request #322 from belfz/expose-bindings/object-seal
implements Object.seal() binding
2018-06-26 10:22:00 -07:00
Nick Fitzgerald
0f7db31888 js: Sort Array bindings alphabetically 2018-06-26 10:18:31 -07:00
Nick Fitzgerald
552f3c7c66 Merge branch 'string-includes' of https://github.com/rail44/wasm-bindgen into string-includes 2018-06-26 10:17:26 -07:00
Satoshi Amemiya
3d72a90481 Support String.prototype.concat 2018-06-27 00:48:09 +09:00
Sendil Kumar
ef27cb6392 Add date constructor 2018-06-26 16:55:40 +02:00
Sendil Kumar
f9ae7f49ad Add date to date string
fix failing test case
2018-06-26 16:55:40 +02:00
Sendil Kumar
dd3e8cc8b8 Add date to iso string 2018-06-26 16:55:40 +02:00
Sendil Kumar
8f21393c6b Add date to json 2018-06-26 16:55:40 +02:00
Sendil Kumar
be44ad8ad8 Add date to locale date string 2018-06-26 16:55:40 +02:00
Sendil Kumar
4e05bc470f Add date to locale string 2018-06-26 16:55:40 +02:00
Sendil Kumar
c0aba821d5 Add date to locale time string 2018-06-26 16:55:40 +02:00
Sendil Kumar
ca17ef8d7c Add date to string 2018-06-26 16:55:40 +02:00
Sendil Kumar
f30de17c2b Add date to time string 2018-06-26 16:55:39 +02:00
Sendil Kumar
033ba3f3a7 Add date to utc string 2018-06-26 16:55:39 +02:00
Sendil Kumar
cd189d53c4 Add date value of 2018-06-26 16:55:36 +02:00
Satoshi Amemiya
22fdcf02b2 Support String.prototype.charCodeAt 2018-06-26 22:09:43 +09:00
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
Nick Fitzgerald
0851025ca5 js: Implement bindings for Array.prototype.filter 2018-06-25 16:19:07 -07:00
Nick Fitzgerald
031ded116b js: Fix missing space at start of doc comment 2018-06-25 16:17:53 -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
Jonathan Sundqvist
ee31080b09 Format comments so they become more readable in editor 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
8e8a02bf73 js.rs - remove todo 2018-06-25 21:32:48 +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
Nick Fitzgerald
56fa901442 js::Object: Sort methods alphabetically 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
Sendil Kumar
f5e050d087 fix url link 2018-06-24 10:10:52 +02:00
Sendil Kumar
0f57398917 Add to_fixed and to_exponential function 2018-06-24 10:08:23 +02: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
R. Andrew Ohana
d79f982a01
Merge pull request #295 from kzvi/js-class-attr
add js_class attribute for defining what class an imported method is for
2018-06-22 21:38:14 -07:00
kzvi
5ae6ee7aec add JsString binding to src/js.rs and tests 2018-06-22 17:51:44 -07:00
Nick Fitzgerald
c63d57f6d7 Add some more doc comments 2018-06-22 11:10:37 -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
Jonathan Sundqvist
de4eea119d Make array methods in alphabetical order 2018-06-22 08:59:11 +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
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
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
Nick Fitzgerald
e4dcb8f85e Add associated constants for common JS values 2018-06-18 16:41:01 -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
cb1e5cf136
Optimize JsValue::{from_bool, undefined, null} constructors (#220)
This commit optimizes constructing an instance of `JsValue` which is one of
`null`, `undefined`, `true`, or `false`. These are commonly created on the Rust
side of things and since there's only a limited set of values we can easily
prepopulate the global slab with a few entries and use hardcoded indices to
refer to these constants. This should avoid the need to travel into JS to insert
a `null` or and `undefined` into the global slab.
2018-06-01 16:46:42 -05: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
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
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
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
65acc3b692 Tighten up codegen with JsStatic a bit
This requires some `unsafe` as we have knowledge that LLVM doesn't, but
shouldn't be too harmful.
2018-04-21 13:52:28 -07:00
Alex Crichton
4436c0eae6 Avoid invoking a function pointer with JsStatic
The previous codegen wasn't enough to convince LLVM that the function pointer
was a constant value and could be aggressively inlined, so this updates the
`JsStatic` internals slightly to guarantee to LLVM that the function pointer is
constant and no dynamic dispatch is needed after all
2018-04-21 13:14:33 -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
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
Alex Crichton
0e6325d833 Overhaul the conversion traits
This commit overhauls the conversion traits used for types crossing the Rust/JS
boundary. Previously there were a few ad-hoc traits but now there've been
slightly reduced and decoupled.

Conversion from Rust values to JS values is now exclusively done through
`IntoWasmAbi` with no special treatment for references. Conversion from JS to
Rust is a bit trickier as we want to create references in Rust which have
implications in terms of safety. As a result there are now three traits for
this, `FromWasmAbi`, `RefFromWasmAbi`, and `RefMutFromWasmAbi`. These three
traits are implemented for various types and specially dispatched to depending
on the type of argument in the code generator.

The goal of this commit is to lay the groundwork for using these traits in
closures with straightforward-ish definitions.
2018-04-14 12:01:07 -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
3305621012 Overhaul how type information gets to the CLI
This commit is a complete overhaul of how the `#[wasm_bindgen]` macro
communicates type information to the CLI tool, and it's done in a somewhat...
unconventional fashion.

Today we've got a problem where the generated JS needs to understand the types
of each function exported or imported. This understanding is what enables it to
generate the appropriate JS wrappers and such. We want to, however, be quite
flexible and extensible in types that are supported across the boundary, which
means that internally we rely on the trait system to resolve what's what.

Communicating the type information historically was done by creating a four byte
"descriptor" and using associated type projections to communicate that to the
CLI tool. Unfortunately four bytes isn't a lot of space to cram information like
arguments to a generic function, tuple types, etc. In general this just wasn't
flexible enough and the way custom references were treated was also already a
bit of a hack.

This commit takes a radical step of creating a **descriptor function** for each
function imported/exported. The really crazy part is that the `wasm-bindgen` CLI
tool now embeds a wasm interpreter and executes these functions when the CLI
tool is invoked. By allowing arbitrary functions to get executed it's now *much*
easier to inform `wasm-bindgen` about complicated structures of types. Rest
assured though that all these descriptor functions are automatically unexported
and gc'd away, so this should not have any impact on binary sizes

A new internal trait, `WasmDescribe`, is added to represent a description of all
types, sort of like a serialization of the structure of a type that
`wasm-bindgen` can understand. This works by calling a special exported function
with a `u32` value a bunch of times. This means that when we run a descriptor we
effectively get a `Vec<u32>` in the `wasm-bindgen` CLI tool. This list of
integers can then be parsed into a rich `enum` for the JS generation to work
with.

This commit currently only retains feature parity with the previous
implementation. I hope to soon solve issues like #123, #104, and #111 with this
support.
2018-04-14 11:15:28 -07:00
Alex Crichton
a3e5485b86 Add examples/documentation for closures 2018-04-09 14:34:21 -07:00
Alex Crichton
f7f0d578e7 Support long-lived closures
Docs coming soon!
2018-04-09 14:34:21 -07:00
Alex Crichton
28d6c1bc12 Support stack closures with up to 7 arguments 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
03433a0ef6 Update to recent WasmBoundary abi changes 2018-04-02 09:59:08 -07:00
David Flemström
73619b5d15 Add support for constructing JsValue instances generically 2018-04-02 09:59:01 -07:00
Alex Crichton
7880545b3b Finish fixing fallout in all tests 2018-03-31 09:15:39 -07:00
Alex Crichton
cdbb31f3a9 Start removal of vector special-casing
This commit starts wasm-bindgen down a path of removing the special
casing it currently has around vectors, slices, and strings. This has
long been a thorn in wasm-bindgen's side as it doesn't handle other
kinds of vectors and otherwise is very inflexible with future additions.
Additionally it leads to a lot of duplicated-ish code throughout various
portions of codegen.

The fundamental reason for this was that two arguments were required to
be passed back to wasm, and I couldn't figure out a way to shove both
those arguments into a function argument. The new strategy here is that
there is one global stack well known to both JS and Rust which arguments
*may* also be transferred between.

By default all ABI arguments pass as literal function arguments, but if
two or more arguments need to be passed then the extra ones are all
passed through this global stack. The stack is effectively temporary
scratch space when crossing the JS/Rust boundary (both ways). No long
term storage is intended here.

The `simple` test is passing as a result of this commit, using strings
internally. The `Vector` type in the AST has been removed (yay!) and the
bulk of the implementation of slices and vectors now resides in the
`wasm-bindgen` crate itself, defining how to pass all these arguments
around. The JS generator, however, still needs to know about all the
sorts of vectors so it can generate appropriate code for JS.

Future commits will continue cleanup and get the rest of the tests
working.
2018-03-31 07:57:47 -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
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
91295f4d16 Fix wasm sizes on nightly
Looks like the recent changes to `Vec::with_capacity` meant that our previous
codegen to avoid panics no longer avoids panics. Let's pick up the `try_reserve`
unstable feature for now and hopefully it'll be stabilized before the other
pieces in the future.
2018-03-20 15:19:45 -07:00
Alex Crichton
0970fa2998 Fix duplicated definition of a constant 2018-02-16 19:06:48 -08:00
Alex Crichton
f3c0fc369a Fix compatibility with LLD
Ensure the runtime library is always at least linked as it has important symbols
that we'll use later.
2018-02-10 10:06:56 -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
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
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
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
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
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
97be6d35ce Add get_mut to WasmRefCell 2017-12-21 12:28:30 -08:00
Alex Crichton
44a9555313 Extract null check throw to a separate function
Slightly smaller callsite!
2017-12-21 12:25:13 -08:00
Alex Crichton
91fddfd10f Improve consistency of prefixes 2017-12-19 20:00:25 -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
946e5317fe Support passing JS objects through Rust 2017-12-19 09:25:41 -08:00
Alex Crichton
2926e6e9f4 Initial commit 2017-12-14 19:31:01 -08:00