WebAssembly: import updated spec tests
authorjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Jun 2017 22:31:04 +0000 (22:31 +0000)
committerjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Jun 2017 22:31:04 +0000 (22:31 +0000)
commitdde6a7a832696d800428fdfbe127d8bf3f499f4c
tree39dc39a3c1e586c9fa4173470a458ba25c17b61a
parenta0b1812fa3a11e6cd99df4c8d74d345e5da69aa4
WebAssembly: import updated spec tests
https://bugs.webkit.org/show_bug.cgi?id=173287
<rdar://problem/32725975>

Reviewed by Saam Barati.

Import spec tests as of 31c641cc15f2aedbec2fa45a5185f68416df578b,
with a few modifications so things work.

Fix a bunch of bugs found through this process, and punt a few tests (which I
marked as blocked by this bug).

Fixes:

Fix load / store alignment: r216908 erroneously implemented it as bit alignment
instead of byte alignment. It was also missing memory-alignment.js despite it
being in the ChangeLog, so add it too. This allows spec-test/align.wast.js to
pass.

Tables can be imported or in a section. There can be only one, but sections can
be empty. An Elements section can exist if there's no Table, as long as it is
also empty.

Memories can be imported or in a section. There can be only one, but sections
can be empty. A Data section can exist if there's no Memory, as long as it is
also empty.

Prototypes: stringify without .prototype. in the string.

WebAssembly.Table.prototype.grow was plain wrong: it takes a delta parameter,
not a final size, and throws a RangeError on failure, not a TypeError.

Fix compile / instantiate so the reject the promise if given an argument of the
wrong type (instead of failing instantly).

Fix async on neuter test.

Element section shouldn't affect any Table if any of the elements are out of
bounds. We need to process it in two passes.

Segment section shouldn't affect any Data if any of the segments are out of
bounds. We need to process it in two passes.

Empty data segments are valid, but only when there is no memory. Their index
still gets validated, and has to be zero.

Punts:

Error messages with context, the test seems overly restrictive but this is
minor.

compile/instantiate/validate property descriptors.

UTF-8 bugs.

Temporarily disable NaN tests. We need to go back and implement the following
semantics: https://github.com/WebAssembly/spec/pull/414 This doesn't matter as
much as getting all the other tests passing.

Worth noting for NaNs: f64.no_fold_mul_one (also a NaN test) as well as
no_fold_promote_demote (an interesting corner case which we get wrong). mul by
one is (assert_return (invoke \"f64.no_fold_mul_one\" (i64.const
0x7ff4000000000000)) (i64.const 0x7ff8000000000000)) which means converting sNaN
to qNaN, and promote/demote is (assert_return (invoke \"no_fold_promote_demote\"
(i32.const 0x7fa00000)) (i32.const 0x7fc00000)) which is the same. I'm not sure
why they're not allowed.

JSTests:

* wasm.yaml:
* wasm/function-tests/i32-load8-s.js:
* wasm/function-tests/memory-access-past-4gib.js:
(const.op.of.WASM.opcodes):
* wasm/function-tests/memory-alignment.js: Added.
(const.op.of.WASM.opcodes):
* wasm/function-tests/memory-section-and-import.js:
* wasm/js-api/Module-compile.js:
(async.testPromiseAPI):
* wasm/js-api/dont-mmap-zero-byte-memory.js:
(testMems):
* wasm/js-api/element.js:
(assert.throws.new.WebAssembly.Module.builder.WebAssembly):
* wasm/js-api/neutered-inputs.js:
(const.testFunction): Deleted.
(const.testConstructor): Deleted.
* wasm/js-api/table.js:
(assert.throws.new.WebAssembly.Module.builder.WebAssembly):
(new.WebAssembly.Module):
(assert.throws):
(assertBadTableImport):
(assert.throws.WebAssembly.Table.prototype.grow):
(assertBadTableInstance): Deleted.
* wasm/js-api/test_Data.js:
(DataSectionWithoutMemory):
* wasm/spec-harness/index.js:
(module):
(uniqueTest): Deleted.
(assert_invalid): Deleted.
(assert_soft_invalid): Deleted.
(register): Deleted.
(call): Deleted.
(get instance): Deleted.
(exports): Deleted.
(run): Deleted.
(assert_unlinkable): Deleted.
(assert_uninstantiable): Deleted.
(assert_trap): Deleted.
(try.f): Deleted.
(catch): Deleted.
(assert_exhaustion): Deleted.
(assert_return): Deleted.
(assert_return_nan): Deleted.
* wasm/spec-harness/testharness.css: Removed.
* wasm/spec-harness/testharness.js: Removed.
* wasm/spec-harness/testharnessreport.js: Removed.
* wasm/spec-harness/wasm-constants.js:
(assertTraps):
(assertWasmThrows):
* wasm/spec-harness/wasm-module-builder.js:
(Binary.prototype.emit_section):
(Binary):
(WasmFunctionBuilder.prototype.addBody):
(WasmFunctionBuilder.prototype.end):
(WasmFunctionBuilder):
(WasmModuleBuilder.prototype.stringToBytes):
(WasmModuleBuilder.prototype.addCustomSection):
(WasmModuleBuilder.prototype.addFunctionTableInit):
(WasmModuleBuilder.prototype.appendToTable):
(WasmModuleBuilder.prototype.toArray):
(WasmModuleBuilder.prototype.toBuffer):
(WasmModuleBuilder.prototype.instantiate):
(WasmModuleBuilder):
* wasm/spec-tests/address.wast.js:
* wasm/spec-tests/align.wast.js: Added.
* wasm/spec-tests/binary.wast.js:
* wasm/spec-tests/block.wast.js:
* wasm/spec-tests/br.wast.js:
* wasm/spec-tests/br_if.wast.js:
* wasm/spec-tests/br_table.wast.js:
* wasm/spec-tests/call.wast.js:
* wasm/spec-tests/call_indirect.wast.js:
* wasm/spec-tests/comments.wast.js:
* wasm/spec-tests/const.wast.js: Added.
* wasm/spec-tests/conversions.wast.js: Added.
* wasm/spec-tests/custom_section.wast.js:
* wasm/spec-tests/exports.wast.js:
* wasm/spec-tests/f32.wast.js: Added.
* wasm/spec-tests/f64.wast.js: Added.
* wasm/spec-tests/fac.wast.js:
* wasm/spec-tests/float_exprs.wast.js: Added.
* wasm/spec-tests/float_misc.wast.js: Added.
* wasm/spec-tests/func.wast.js:
* wasm/spec-tests/globals.wast.js:
* wasm/spec-tests/if.wast.js:
* wasm/spec-tests/imports.wast.js:
* wasm/spec-tests/inline-module.wast.js: Added.
* wasm/spec-tests/jsapi.js:
(testJSAPI.test):
(testJSAPI):
* wasm/spec-tests/labels.wast.js:
* wasm/spec-tests/loop.wast.js:
* wasm/spec-tests/memory.wast.js:
* wasm/spec-tests/memory_trap.wast.js: Added.
* wasm/spec-tests/names.wast.js:
* wasm/spec-tests/nop.wast.js:
* wasm/spec-tests/return.wast.js:
* wasm/spec-tests/stack.wast.js:
* wasm/spec-tests/token.wast.js: Added.
* wasm/spec-tests/type.wast.js: Added.
* wasm/spec-tests/typecheck.wast.js:
* wasm/spec-tests/unreachable.wast.js:
* wasm/spec-tests/unreached-invalid.wast.js:
* wasm/spec-tests/unwind.wast.js:
* wasm/spec-tests/utf8-custom-section-id.wast.js: Added.
* wasm/spec-tests/utf8-import-field.wast.js: Added.
* wasm/spec-tests/utf8-import-module.wast.js: Added.

Source/JavaScriptCore:

* wasm/WasmB3IRGenerator.cpp:
* wasm/WasmFunctionParser.h:
* wasm/WasmModuleParser.cpp:
* wasm/WasmModuleParser.h:
* wasm/WasmParser.h:
(JSC::Wasm::Parser<SuccessType>::consumeUTF8String):
* wasm/generateWasm.py:
(memoryLog2Alignment):
* wasm/js/JSWebAssemblyTable.cpp:
(JSC::JSWebAssemblyTable::grow):
* wasm/js/JSWebAssemblyTable.h:
* wasm/js/WebAssemblyCompileErrorPrototype.cpp:
* wasm/js/WebAssemblyInstancePrototype.cpp:
* wasm/js/WebAssemblyLinkErrorPrototype.cpp:
* wasm/js/WebAssemblyMemoryPrototype.cpp:
* wasm/js/WebAssemblyModulePrototype.cpp:
* wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::evaluate):
* wasm/js/WebAssemblyPrototype.cpp:
(JSC::webAssemblyCompileFunc):
(JSC::resolve):
(JSC::instantiate):
(JSC::compileAndInstantiate):
(JSC::webAssemblyInstantiateFunc):
* wasm/js/WebAssemblyRuntimeErrorPrototype.cpp:
* wasm/js/WebAssemblyTablePrototype.cpp:
(JSC::webAssemblyTableProtoFuncGrow):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218216 268f45cc-cd09-0410-ab3c-d52691b4dbfc
78 files changed:
JSTests/ChangeLog
JSTests/wasm.yaml
JSTests/wasm/function-tests/i32-load8-s.js
JSTests/wasm/function-tests/memory-access-past-4gib.js
JSTests/wasm/function-tests/memory-alignment.js [new file with mode: 0644]
JSTests/wasm/function-tests/memory-section-and-import.js
JSTests/wasm/js-api/Module-compile.js
JSTests/wasm/js-api/dont-mmap-zero-byte-memory.js
JSTests/wasm/js-api/element.js
JSTests/wasm/js-api/neutered-inputs.js
JSTests/wasm/js-api/table.js
JSTests/wasm/js-api/test_Data.js
JSTests/wasm/spec-harness/index.js
JSTests/wasm/spec-harness/testharness.css [deleted file]
JSTests/wasm/spec-harness/testharness.js [deleted file]
JSTests/wasm/spec-harness/testharnessreport.js [deleted file]
JSTests/wasm/spec-harness/wasm-constants.js
JSTests/wasm/spec-harness/wasm-module-builder.js
JSTests/wasm/spec-tests/address.wast.js
JSTests/wasm/spec-tests/align.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/binary.wast.js
JSTests/wasm/spec-tests/block.wast.js
JSTests/wasm/spec-tests/br.wast.js
JSTests/wasm/spec-tests/br_if.wast.js
JSTests/wasm/spec-tests/br_table.wast.js
JSTests/wasm/spec-tests/call.wast.js
JSTests/wasm/spec-tests/call_indirect.wast.js
JSTests/wasm/spec-tests/comments.wast.js
JSTests/wasm/spec-tests/const.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/conversions.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/custom_section.wast.js
JSTests/wasm/spec-tests/exports.wast.js
JSTests/wasm/spec-tests/f32.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/f64.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/fac.wast.js
JSTests/wasm/spec-tests/float_exprs.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/float_misc.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/func.wast.js
JSTests/wasm/spec-tests/globals.wast.js
JSTests/wasm/spec-tests/if.wast.js
JSTests/wasm/spec-tests/imports.wast.js
JSTests/wasm/spec-tests/inline-module.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/jsapi.js
JSTests/wasm/spec-tests/labels.wast.js
JSTests/wasm/spec-tests/loop.wast.js
JSTests/wasm/spec-tests/memory.wast.js
JSTests/wasm/spec-tests/memory_trap.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/names.wast.js
JSTests/wasm/spec-tests/nop.wast.js
JSTests/wasm/spec-tests/return.wast.js
JSTests/wasm/spec-tests/stack.wast.js
JSTests/wasm/spec-tests/token.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/type.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/typecheck.wast.js
JSTests/wasm/spec-tests/unreachable.wast.js
JSTests/wasm/spec-tests/unreached-invalid.wast.js
JSTests/wasm/spec-tests/unwind.wast.js
JSTests/wasm/spec-tests/utf8-custom-section-id.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/utf8-import-field.wast.js [new file with mode: 0644]
JSTests/wasm/spec-tests/utf8-import-module.wast.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
Source/JavaScriptCore/wasm/WasmFunctionParser.h
Source/JavaScriptCore/wasm/WasmModuleParser.cpp
Source/JavaScriptCore/wasm/WasmModuleParser.h
Source/JavaScriptCore/wasm/WasmParser.h
Source/JavaScriptCore/wasm/generateWasm.py
Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp
Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h
Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorPrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorPrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp