WebAssembly JS API: check and test in-call / out-call values
authorjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jan 2017 20:24:36 +0000 (20:24 +0000)
committerjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jan 2017 20:24:36 +0000 (20:24 +0000)
commit00ef5ba7ed9f2a5677708b83751fd763ba689cde
treeadabfa0da48de5ea20328787fb3676b119594bd8
parentb9cbbe9a6c5c9a2db4a28f9a11fc6255289ceab8
WebAssembly JS API: check and test in-call / out-call values
https://bugs.webkit.org/show_bug.cgi?id=164876
<rdar://problem/29844107>

Reviewed by Saam Barati.

JSTests:

* wasm.yaml:
* wasm/assert.js: add an assert for NaN comparison
* wasm/fuzz/export-function.js: Added. Generate random wasm export
signatures, and call them with random parameters.
(const.paramExporter):
(const.setBuffer):
(const.types.generate):
(generate):
* wasm/js-api/export-arity.js: Added.
(const.paramExporter): Test that mismatched arities when JS calls
wasm follow the defined semantics: i32 is 0, f32 / f64 are NaN.
https://github.com/WebAssembly/design/blob/master/JS.md#exported-function-exotic-objects
* wasm/js-api/export-void-is-undef.js: Added. Test that "void"
wasm functions return "undefined" in JS.

Source/JavaScriptCore:

* wasm/WasmBinding.cpp:
(JSC::Wasm::wasmToJs): fix the wasm -> JS call coercions for f32 /
f64 which the assotiated tests inadvertently tripped on: the
previous code wasn't correctly performing JSValue boxing for
"double" values. This change is slightly involved because it
requires two scratch registers to materialize the
`DoubleEncodeOffset` value. This change therefore reorganizes the
code to first generate traps, then handle all integers (freeing
all GPRs), and then all the floating-point values.
* wasm/js/WebAssemblyFunction.cpp:
(JSC::callWebAssemblyFunction): Implement the defined semantics
for mismatched arities when JS calls wasm:
https://github.com/WebAssembly/design/blob/master/JS.md#exported-function-exotic-objects
  - i32 is 0, f32 / f64 are NaN.
  - wasm functions which return "void" are "undefined" in JS.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210244 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JSTests/ChangeLog
JSTests/wasm.yaml
JSTests/wasm/Builder.js
JSTests/wasm/assert.js
JSTests/wasm/fuzz/export-function.js [new file with mode: 0644]
JSTests/wasm/js-api/export-arity.js [new file with mode: 0644]
JSTests/wasm/js-api/export-void-is-undef.js [new file with mode: 0644]
JSTests/wasm/self-test/test_BuilderJSON.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wasm/WasmBinding.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp