[JSC] Improve wasm wpt test results by fixing miscellaneous issues
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Jul 2019 22:41:54 +0000 (22:41 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Jul 2019 22:41:54 +0000 (22:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199783

Reviewed by Mark Lam.

JSTests:

Fix our spec tests.

* wasm/js-api/Module-compile.js:
* wasm/js-api/test_basic_api.js:
(const.c.in.constructorProperties.switch):
* wasm/js-api/validate.js:
* wasm/js-api/web-assembly-instantiate.js:
* wasm/spec-tests/jsapi.js:
(testJSAPI.get test):
(testJSAPI.set test):

LayoutTests/imported/w3c:

Import web-platform-tests/wasm/jsapi. Some of tests are failing just because imported wpt tests are old.
They are fixed in the upstream. When upgrading wpt tests, we can mark them PASS.

* resources/import-expectations.json:
* web-platform-tests/wasm/jsapi/assertions.js: Added.
(assert_function_name):
(assert_function_length):
* web-platform-tests/wasm/jsapi/bad-imports.js: Added.
(test_bad_imports):
* web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.html: Added.
* web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.js: Added.
(test_bad_imports):
* web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/constructor/w3c-import.log: Added.
* web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/global/constructor.any.html: Added.
* web-platform-tests/wasm/jsapi/global/constructor.any.js: Added.
(assert_Global):
(test):
(test.get assert_array_equals):
(string_appeared_here.test):
(string_appeared_here.toString):
(string_appeared_here.valueOf):
(string_appeared_here.name.format_value):
* web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/global/constructor.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/global/toString.any.html: Added.
* web-platform-tests/wasm/jsapi/global/toString.any.js: Added.
(test):
* web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/global/toString.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/global/value-set.any.html: Added.
* web-platform-tests/wasm/jsapi/global/value-set.any.js: Added.
(test):
(string_appeared_here.name.of.immutableOptions.test):
(string_appeared_here.name.of.mutableOptions.test):
* web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/global/value-set.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/global/valueOf.any.html: Added.
* web-platform-tests/wasm/jsapi/global/valueOf.any.js: Added.
(test):
* web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/global/valueOf.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/global/w3c-import.log: Added.
* web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.html: Added.
* web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.js: Added.
(test_bad_imports):
* web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/instance/constructor.any.html: Added.
* web-platform-tests/wasm/jsapi/instance/constructor.any.js: Added.
(assert_exported_function):
* web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/instance/constructor.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/instance/exports.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/instance/exports.any.html: Added.
* web-platform-tests/wasm/jsapi/instance/exports.any.js: Added.
(setup):
(test):
* web-platform-tests/wasm/jsapi/instance/exports.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/instance/exports.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/instance/toString.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/instance/toString.any.html: Added.
* web-platform-tests/wasm/jsapi/instance/toString.any.js: Added.
(test):
* web-platform-tests/wasm/jsapi/instance/toString.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/instance/toString.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/instance/w3c-import.log: Added.
* web-platform-tests/wasm/jsapi/interface.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/interface.any.html: Added.
* web-platform-tests/wasm/jsapi/interface.any.js: Added.
(test_operations):
(test):
(const.name.of.interfaces.test):
* web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/interface.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/memory/buffer.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/memory/buffer.any.html: Added.
* web-platform-tests/wasm/jsapi/memory/buffer.any.js: Added.
(test):
* web-platform-tests/wasm/jsapi/memory/buffer.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/memory/buffer.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/memory/constructor.any.html: Added.
* web-platform-tests/wasm/jsapi/memory/constructor.any.js: Added.
(assert_Memory):
(test):
(const.value.of.outOfRangeValues.test):
(test.get new):
(test.get assert_array_equals):
* web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/memory/constructor.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/memory/grow.any.html: Added.
* web-platform-tests/wasm/jsapi/memory/grow.any.js: Added.
(assert_ArrayBuffer):
(test):
(valueOf):
(const.value.of.outOfRangeValues.test):
* web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/memory/grow.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/memory/toString.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/memory/toString.any.html: Added.
* web-platform-tests/wasm/jsapi/memory/toString.any.js: Added.
(test):
* web-platform-tests/wasm/jsapi/memory/toString.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/memory/toString.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/memory/w3c-import.log: Added.
* web-platform-tests/wasm/jsapi/module/constructor.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/constructor.any.html: Added.
* web-platform-tests/wasm/jsapi/module/constructor.any.js: Added.
(setup):
(test):
* web-platform-tests/wasm/jsapi/module/constructor.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/constructor.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/module/customSections.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/customSections.any.html: Added.
* web-platform-tests/wasm/jsapi/module/customSections.any.js: Added.
(assert_ArrayBuffer):
(assert_sections):
(setup):
(test):
* web-platform-tests/wasm/jsapi/module/customSections.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/customSections.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/exports.any.html: Added.
* web-platform-tests/wasm/jsapi/module/exports.any.js: Added.
(setup):
(assert_ModuleExportDescriptor):
(assert_exports):
(test):
* web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/exports.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/module/imports.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/imports.any.html: Added.
* web-platform-tests/wasm/jsapi/module/imports.any.js: Added.
(assert_ModuleImportDescriptor):
(assert_imports):
(setup):
(test):
* web-platform-tests/wasm/jsapi/module/imports.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/imports.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/module/toString.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/toString.any.html: Added.
* web-platform-tests/wasm/jsapi/module/toString.any.js: Added.
(test):
* web-platform-tests/wasm/jsapi/module/toString.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/module/toString.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/module/w3c-import.log: Added.
* web-platform-tests/wasm/jsapi/table/assertions.js: Added.
(assert_equal_to_array):
* web-platform-tests/wasm/jsapi/table/constructor.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/constructor.any.html: Added.
* web-platform-tests/wasm/jsapi/table/constructor.any.js: Added.
(assert_Table):
(test):
(const.value.of.outOfRangeValues.test):
(test.get const):
* web-platform-tests/wasm/jsapi/table/constructor.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/constructor.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/table/get-set.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/get-set.any.html: Added.
* web-platform-tests/wasm/jsapi/table/get-set.any.js: Added.
(setup):
(test):
(test.set assert_equal_to_array):
(test.const.fn):
(valueOf):
(const.value.of.outOfRangeValues.test):
* web-platform-tests/wasm/jsapi/table/get-set.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/get-set.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/table/grow.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/grow.any.html: Added.
* web-platform-tests/wasm/jsapi/table/grow.any.js: Added.
(nulls):
(test):
(valueOf):
(const.value.of.outOfRangeValues.test):
* web-platform-tests/wasm/jsapi/table/grow.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/grow.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/table/length.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/length.any.html: Added.
* web-platform-tests/wasm/jsapi/table/length.any.js: Added.
(test):
* web-platform-tests/wasm/jsapi/table/length.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/length.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/table/toString.any-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/toString.any.html: Added.
* web-platform-tests/wasm/jsapi/table/toString.any.js: Added.
(test):
* web-platform-tests/wasm/jsapi/table/toString.any.worker-expected.txt: Added.
* web-platform-tests/wasm/jsapi/table/toString.any.worker.html: Added.
* web-platform-tests/wasm/jsapi/table/w3c-import.log: Added.
* web-platform-tests/wasm/jsapi/w3c-import.log: Added.
* web-platform-tests/wasm/jsapi/wasm-constants.js: Added.
(bytes):
(bytesWithHeader):
(makeSig):
(makeSig_v_x):
(makeSig_v_xx):
(makeSig_r_v):
(makeSig_r_x):
(makeSig_r_xx):
(assertTraps):
(assertWasmThrows):
* web-platform-tests/wasm/jsapi/wasm-module-builder.js: Added.
(Binary.prototype.emit_u8):
(Binary.prototype.emit_u16):
(Binary.prototype.emit_u32):
(Binary.prototype.emit_u32v):
(Binary.prototype.emit_bytes):
(Binary.prototype.emit_string):
(Binary.prototype.emit_header):
(Binary.prototype.emit_section):
(Binary):
(WasmFunctionBuilder):
(WasmFunctionBuilder.prototype.exportAs):
(WasmFunctionBuilder.prototype.exportFunc):
(WasmFunctionBuilder.prototype.addBody):
(WasmFunctionBuilder.prototype.addLocals):
(WasmFunctionBuilder.prototype.end):
(WasmGlobalBuilder):
(WasmGlobalBuilder.prototype.exportAs):
(WasmModuleBuilder):
(WasmModuleBuilder.prototype.addStart):
(WasmModuleBuilder.prototype.addMemory):
(WasmModuleBuilder.prototype.addExplicitSection):
(WasmModuleBuilder.prototype.addType):
(WasmModuleBuilder.prototype.addGlobal):
(WasmModuleBuilder.prototype.addFunction):
(WasmModuleBuilder.prototype.addImport):
(WasmModuleBuilder.prototype.addImportedGlobal):
(WasmModuleBuilder.prototype.addImportedMemory):
(WasmModuleBuilder.prototype.addImportedTable):
(WasmModuleBuilder.prototype.addExport):
(WasmModuleBuilder.prototype.addExportOfKind):
(WasmModuleBuilder.prototype.addDataSegment):
(WasmModuleBuilder.prototype.exportMemoryAs):
(WasmModuleBuilder.prototype.addFunctionTableInit):
(WasmModuleBuilder.prototype.appendToTable):
(WasmModuleBuilder.prototype.setFunctionTableLength):
(WasmModuleBuilder.prototype.toArray):
(WasmModuleBuilder.prototype.toBuffer):
(WasmModuleBuilder.prototype.instantiate):

Source/JavaScriptCore:

This patch fixes miscellaneous issues in our Wasm JS API implementation to improve WPT score.
I picked trivial ones in this patch to make this easily reviewable.

1. Remove WebAssemblyPrototype. It does not exist in the spec. Merging WebAssemblyPrototype into JSWebAssembly.
2. Fix various attributes. It does not match to the usual JSC builtin's convention. But this change
   is correct because they are changed to be matched against WebIDL definition, and WebAssembly implementation
   follows WebIDL. In the future, we could move WebCore WebIDL things into WTF layer and even use (or leverage
   some of utility functions) in our WebAssembly JS API implementation.
3. Fix how we interpret "present" in WebAssembly spec. This does not mean [[HasProperty]] result. It follows to
   WebIDL spec, and it means that [[Get]] result is not undefined.
4. Add argument count check to Module.customSections, which is required because the method is defined in WebIDL.
5. Fix toNonWrappingUint32 to match it to WebIDL's conversion rule.

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* JavaScriptCore.xcodeproj/project.pbxproj:
* Sources.txt:
* builtins/WebAssembly.js: Renamed from Source/JavaScriptCore/builtins/WebAssemblyPrototype.js.
* jit/Repatch.cpp:
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* runtime/JSModuleLoader.cpp:
(JSC::moduleLoaderParseModule):
* wasm/js/JSWebAssembly.cpp:
(JSC::JSWebAssembly::create):
(JSC::JSWebAssembly::finishCreation):
(JSC::reject):
(JSC::webAssemblyModuleValidateAsyncInternal):
(JSC::webAssemblyCompileFunc):
(JSC::resolve):
(JSC::JSWebAssembly::webAssemblyModuleValidateAsync):
(JSC::instantiate):
(JSC::compileAndInstantiate):
(JSC::JSWebAssembly::instantiate):
(JSC::webAssemblyModuleInstantinateAsyncInternal):
(JSC::JSWebAssembly::webAssemblyModuleInstantinateAsync):
(JSC::webAssemblyInstantiateFunc):
(JSC::webAssemblyValidateFunc):
(JSC::webAssemblyCompileStreamingInternal):
(JSC::webAssemblyInstantiateStreamingInternal):
* wasm/js/JSWebAssembly.h:
* wasm/js/JSWebAssemblyHelpers.h:
(JSC::toNonWrappingUint32):
* wasm/js/WebAssemblyCompileErrorConstructor.cpp:
(JSC::WebAssemblyCompileErrorConstructor::finishCreation):
* wasm/js/WebAssemblyInstanceConstructor.cpp:
(JSC::WebAssemblyInstanceConstructor::finishCreation):
* wasm/js/WebAssemblyInstancePrototype.cpp:
* wasm/js/WebAssemblyLinkErrorConstructor.cpp:
(JSC::WebAssemblyLinkErrorConstructor::finishCreation):
* wasm/js/WebAssemblyMemoryConstructor.cpp:
(JSC::constructJSWebAssemblyMemory):
(JSC::WebAssemblyMemoryConstructor::finishCreation):
* wasm/js/WebAssemblyMemoryPrototype.cpp:
* wasm/js/WebAssemblyModuleConstructor.cpp:
(JSC::webAssemblyModuleCustomSections):
(JSC::WebAssemblyModuleConstructor::finishCreation):
* wasm/js/WebAssemblyPrototype.cpp: Removed.
* wasm/js/WebAssemblyPrototype.h: Removed.
* wasm/js/WebAssemblyRuntimeErrorConstructor.cpp:
(JSC::WebAssemblyRuntimeErrorConstructor::finishCreation):
* wasm/js/WebAssemblyTableConstructor.cpp:
(JSC::constructJSWebAssemblyTable):
(JSC::WebAssemblyTableConstructor::finishCreation):
* wasm/js/WebAssemblyTablePrototype.cpp:

Source/WebCore:

Remove WebAssemblyPrototype.

Tests: imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/interface.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/interface.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.worker.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.html
       imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.worker.html

* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::compileStreaming):
(WebCore::JSDOMWindowBase::instantiateStreaming):

LayoutTests:

* platform/ios-simulator/TestExpectations:
* platform/win/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247457 268f45cc-cd09-0410-ab3c-d52691b4dbfc

171 files changed:
JSTests/ChangeLog
JSTests/wasm/js-api/Module-compile.js
JSTests/wasm/js-api/test_basic_api.js
JSTests/wasm/js-api/validate.js
JSTests/wasm/js-api/web-assembly-instantiate.js
JSTests/wasm/spec-tests/jsapi.js
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/resources/import-expectations.json
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/assertions.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/bad-imports.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/w3c-import.log [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/w3c-import.log [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/w3c-import.log [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/w3c-import.log [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/w3c-import.log [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/assertions.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/w3c-import.log [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/w3c-import.log [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/wasm-constants.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/wasm-module-builder.js [new file with mode: 0644]
LayoutTests/platform/ios-simulator/TestExpectations
LayoutTests/platform/win/TestExpectations
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/DerivedSources-input.xcfilelist
Source/JavaScriptCore/DerivedSources-output.xcfilelist
Source/JavaScriptCore/DerivedSources.make
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/Sources.txt
Source/JavaScriptCore/builtins/WebAssembly.js [moved from Source/JavaScriptCore/builtins/WebAssemblyPrototype.js with 100% similarity]
Source/JavaScriptCore/jit/Repatch.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSModuleLoader.cpp
Source/JavaScriptCore/wasm/js/JSWebAssembly.cpp
Source/JavaScriptCore/wasm/js/JSWebAssembly.h
Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h
Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp [deleted file]
Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.h [deleted file]
Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMWindowBase.cpp

index f2c0f63..204f284 100644 (file)
@@ -1,3 +1,21 @@
+2019-07-15  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Improve wasm wpt test results by fixing miscellaneous issues
+        https://bugs.webkit.org/show_bug.cgi?id=199783
+
+        Reviewed by Mark Lam.
+
+        Fix our spec tests.
+
+        * wasm/js-api/Module-compile.js:
+        * wasm/js-api/test_basic_api.js:
+        (const.c.in.constructorProperties.switch):
+        * wasm/js-api/validate.js:
+        * wasm/js-api/web-assembly-instantiate.js:
+        * wasm/spec-tests/jsapi.js:
+        (testJSAPI.get test):
+        (testJSAPI.set test):
+
 2019-07-15  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed, rolling out r247440.
index d723bf4..d5a8599 100644 (file)
@@ -2,7 +2,7 @@ import * as assert from '../assert.js';
 import Builder from '../Builder.js';
 
 assert.isFunction(WebAssembly.compile);
-assert.isFunction(WebAssembly.__proto__.compile);
+assert.truthy(WebAssembly.hasOwnProperty('compile'));
 assert.eq(WebAssembly.compile.length, 1);
 
 async function testPromiseAPI() {
index 2158743..5e37210 100644 (file)
@@ -78,7 +78,7 @@ for (const c in constructorProperties) {
         for (const invalid of invalidInstanceImports)
             assert.throws(() => new WebAssembly[c](new WebAssembly.Module(emptyModuleArray), invalid), TypeError, `second argument to WebAssembly.Instance must be undefined or an Object (evaluating 'new WebAssembly[c](new WebAssembly.Module(emptyModuleArray), invalid)')`);
         assert.isNotUndef(instance.exports);
-        checkAccessorOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports", { configurable: true, enumerable: false });
+        checkAccessorOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports", { configurable: true, enumerable: true });
         assert.throws(() => WebAssembly.Instance.prototype.exports = undefined, TypeError, `Attempted to assign to readonly property.`);
         assert.throws(() => WebAssembly.Instance.prototype.exports, TypeError, `expected |this| value to be an instance of WebAssembly.Instance`);
         assert.isUndef(instance.exports.__proto__);
index 4fe83c2..d5d9e99 100644 (file)
@@ -2,7 +2,7 @@ import * as assert from '../assert.js';
 import Builder from '../Builder.js';
 
 assert.isFunction(WebAssembly.validate);
-assert.isFunction(WebAssembly.__proto__.validate);
+assert.truthy(WebAssembly.hasOwnProperty('validate'));
 assert.eq(WebAssembly.validate.length, 1);
 
 {
index f606725..1b6b714 100644 (file)
@@ -2,7 +2,7 @@ import * as assert from '../assert.js';
 import Builder from '../Builder.js';
 
 assert.isFunction(WebAssembly.instantiate);
-assert.isFunction(WebAssembly.__proto__.instantiate);
+assert.truthy(WebAssembly.hasOwnProperty('instantiate'));
 assert.eq(WebAssembly.instantiate.length, 1);
 
 {
index 8e5d228..2969f07 100644 (file)
@@ -230,7 +230,7 @@ test(() => {
     const moduleImportsDesc = Object.getOwnPropertyDescriptor(Module, 'imports');
     assert_equals(typeof moduleImportsDesc.value, "function");
     assert_equals(moduleImportsDesc.writable, true);
-    assert_equals(moduleImportsDesc.enumerable, false);
+    assert_equals(moduleImportsDesc.enumerable, true);
     assert_equals(moduleImportsDesc.configurable, true);
 }, "'WebAssembly.Module.imports' data property");
 
@@ -265,7 +265,7 @@ test(() => {
     const moduleExportsDesc = Object.getOwnPropertyDescriptor(Module, 'exports');
     assert_equals(typeof moduleExportsDesc.value, "function");
     assert_equals(moduleExportsDesc.writable, true);
-    assert_equals(moduleExportsDesc.enumerable, false);
+    assert_equals(moduleExportsDesc.enumerable, true);
     assert_equals(moduleExportsDesc.configurable, true);
 }, "'WebAssembly.Module.exports' data property");
 
@@ -296,7 +296,7 @@ test(() => {
     const customSectionsDesc = Object.getOwnPropertyDescriptor(Module, 'customSections');
     assert_equals(typeof customSectionsDesc.value, "function");
     assert_equals(customSectionsDesc.writable, true);
-    assert_equals(customSectionsDesc.enumerable, false);
+    assert_equals(customSectionsDesc.enumerable, true);
     assert_equals(customSectionsDesc.configurable, true);
 }, "'WebAssembly.Module.customSections' data property");
 
@@ -307,7 +307,7 @@ test(() => {
     assertThrows(() => moduleCustomSections(), TypeError);
     assertThrows(() => moduleCustomSections(undefined), TypeError);
     assertThrows(() => moduleCustomSections({}), TypeError);
-    var arr = moduleCustomSections(emptyModule);
+    var arr = moduleCustomSections(emptyModule, undefined);
     assert_equals(arr instanceof Array, true);
     assert_equals(arr.length, 0);
 }, "'WebAssembly.Module.customSections' method");
@@ -367,7 +367,7 @@ test(() => {
     const exportsDesc = Object.getOwnPropertyDescriptor(instanceProto, 'exports');
     assert_equals(typeof exportsDesc.get, "function");
     assert_equals(exportsDesc.set, undefined);
-    assert_equals(exportsDesc.enumerable, false);
+    assert_equals(exportsDesc.enumerable, true);
     assert_equals(exportsDesc.configurable, true);
     const exportsGetter = exportsDesc.get;
     assertThrows(() => exportsGetter.call(), TypeError);
@@ -415,11 +415,11 @@ test(() => {
     assertThrows(() => Memory(), TypeError);
     assertThrows(() => new Memory(1), TypeError);
     assertThrows(() => new Memory({initial:{valueOf() { throw new Error("here")}}}), Error);
-    assertThrows(() => new Memory({initial:-1}), RangeError);
-    assertThrows(() => new Memory({initial:Math.pow(2,32)}), RangeError);
+    assertThrows(() => new Memory({initial:-1}), TypeError);
+    assertThrows(() => new Memory({initial:Math.pow(2,32)}), TypeError);
     assertThrows(() => new Memory({initial:1, maximum: Math.pow(2,32)/Math.pow(2,14) }), RangeError);
     assertThrows(() => new Memory({initial:2, maximum:1 }), RangeError);
-    assertThrows(() => new Memory({maximum: -1 }), RangeError);
+    assertThrows(() => new Memory({maximum: -1 }), TypeError);
     assert_equals(new Memory({initial:1}) instanceof Memory, true);
     assert_equals(new Memory({initial:1.5}).buffer.byteLength, WasmPage);
 }, "'WebAssembly.Memory' constructor function");
@@ -451,7 +451,7 @@ test(() => {
     const bufferDesc = Object.getOwnPropertyDescriptor(memoryProto, 'buffer');
     assert_equals(typeof bufferDesc.get, "function");
     assert_equals(bufferDesc.set, undefined);
-    assert_equals(bufferDesc.enumerable, false);
+    assert_equals(bufferDesc.enumerable, true);
     assert_equals(bufferDesc.configurable, true);
 }, "'WebAssembly.Memory.prototype.buffer' accessor property");
 
@@ -467,7 +467,7 @@ test(() => {
 test(() => {
     const memGrowDesc = Object.getOwnPropertyDescriptor(memoryProto, 'grow');
     assert_equals(typeof memGrowDesc.value, "function");
-    assert_equals(memGrowDesc.enumerable, false);
+    assert_equals(memGrowDesc.enumerable, true);
     assert_equals(memGrowDesc.configurable, true);
 }, "'WebAssembly.Memory.prototype.grow' data property");
 
@@ -477,8 +477,8 @@ test(() => {
     assert_equals(memGrow.length, 1);
     assertThrows(() => memGrow.call(), TypeError);
     assertThrows(() => memGrow.call({}), TypeError);
-    assertThrows(() => memGrow.call(mem1, -1), RangeError);
-    assertThrows(() => memGrow.call(mem1, Math.pow(2,32)), RangeError);
+    assertThrows(() => memGrow.call(mem1, -1), TypeError);
+    assertThrows(() => memGrow.call(mem1, Math.pow(2,32)), TypeError);
     var mem = new Memory({initial:1, maximum:2});
     var buf = mem.buffer;
     assert_equals(buf.byteLength, WasmPage);
@@ -516,10 +516,10 @@ test(() => {
     assertThrows(() => new Table({initial:1, element:"any"}), TypeError);
     assertThrows(() => new Table({initial:1, element:{valueOf() { return "funcref" }}}), TypeError);
     assertThrows(() => new Table({initial:{valueOf() { throw new Error("here")}}, element:"funcref"}), Error);
-    assertThrows(() => new Table({initial:-1, element:"funcref"}), RangeError);
-    assertThrows(() => new Table({initial:Math.pow(2,32), element:"funcref"}), RangeError);
+    assertThrows(() => new Table({initial:-1, element:"funcref"}), TypeError);
+    assertThrows(() => new Table({initial:Math.pow(2,32), element:"funcref"}), TypeError);
     assertThrows(() => new Table({initial:2, maximum:1, element:"funcref"}), RangeError);
-    assertThrows(() => new Table({initial:2, maximum:Math.pow(2,32), element:"funcref"}), RangeError);
+    assertThrows(() => new Table({initial:2, maximum:Math.pow(2,32), element:"funcref"}), TypeError);
     assert_equals(new Table({initial:1, element:"funcref"}) instanceof Table, true);
     assert_equals(new Table({initial:1.5, element:"funcref"}) instanceof Table, true);
     assert_equals(new Table({initial:1, maximum:1.5, element:"funcref"}) instanceof Table, true);
@@ -553,7 +553,7 @@ test(() => {
     const lengthDesc = Object.getOwnPropertyDescriptor(tableProto, 'length');
     assert_equals(typeof lengthDesc.get, "function");
     assert_equals(lengthDesc.set, undefined);
-    assert_equals(lengthDesc.enumerable, false);
+    assert_equals(lengthDesc.enumerable, true);
     assert_equals(lengthDesc.configurable, true);
 }, "'WebAssembly.Table.prototype.length' accessor data property");
 
@@ -570,7 +570,7 @@ test(() => {
 test(() => {
     const getDesc = Object.getOwnPropertyDescriptor(tableProto, 'get');
     assert_equals(typeof getDesc.value, "function");
-    assert_equals(getDesc.enumerable, false);
+    assert_equals(getDesc.enumerable, true);
     assert_equals(getDesc.configurable, true);
 }, "'WebAssembly.Table.prototype.get' data property");
 
@@ -585,15 +585,15 @@ test(() => {
     assert_equals(get.call(tbl1, 1.5), null);
     assertThrows(() => get.call(tbl1, 2), RangeError);
     assertThrows(() => get.call(tbl1, 2.5), RangeError);
-    assertThrows(() => get.call(tbl1, -1), RangeError);
-    assertThrows(() => get.call(tbl1, Math.pow(2,33)), RangeError);
+    assertThrows(() => get.call(tbl1, -1), TypeError);
+    assertThrows(() => get.call(tbl1, Math.pow(2,33)), TypeError);
     assertThrows(() => get.call(tbl1, {valueOf() { throw new Error("hi") }}), Error);
 }, "'WebAssembly.Table.prototype.get' method");
 
 test(() => {
     const setDesc = Object.getOwnPropertyDescriptor(tableProto, 'set');
     assert_equals(typeof setDesc.value, "function");
-    assert_equals(setDesc.enumerable, false);
+    assert_equals(setDesc.enumerable, true);
     assert_equals(setDesc.configurable, true);
 }, "'WebAssembly.Table.prototype.set' data property");
 
@@ -605,8 +605,8 @@ test(() => {
     assertThrows(() => set.call({}), TypeError);
     assertThrows(() => set.call(tbl1, 0), TypeError);
     assertThrows(() => set.call(tbl1, 2, null), RangeError);
-    assertThrows(() => set.call(tbl1, -1, null), RangeError);
-    assertThrows(() => set.call(tbl1, Math.pow(2,33), null), RangeError);
+    assertThrows(() => set.call(tbl1, -1, null), TypeError);
+    assertThrows(() => set.call(tbl1, Math.pow(2,33), null), TypeError);
     assertThrows(() => set.call(tbl1, 0, undefined), TypeError);
     assertThrows(() => set.call(tbl1, 0, {}), TypeError);
     assertThrows(() => set.call(tbl1, 0, function() {}), TypeError);
@@ -619,7 +619,7 @@ test(() => {
 test(() => {
     const tblGrowDesc = Object.getOwnPropertyDescriptor(tableProto, 'grow');
     assert_equals(typeof tblGrowDesc.value, "function");
-    assert_equals(tblGrowDesc.enumerable, false);
+    assert_equals(tblGrowDesc.enumerable, true);
     assert_equals(tblGrowDesc.configurable, true);
 }, "'WebAssembly.Table.prototype.grow' data property");
 
@@ -629,8 +629,8 @@ test(() => {
     assert_equals(tblGrow.length, 1);
     assertThrows(() => tblGrow.call(), TypeError);
     assertThrows(() => tblGrow.call({}), TypeError);
-    assertThrows(() => tblGrow.call(tbl1, -1), RangeError);
-    assertThrows(() => tblGrow.call(tbl1, Math.pow(2,32)), RangeError);
+    assertThrows(() => tblGrow.call(tbl1, -1), TypeError);
+    assertThrows(() => tblGrow.call(tbl1, Math.pow(2,32)), TypeError);
     var tbl = new Table({element:"funcref", initial:1, maximum:2});
     assert_equals(tbl.length, 1);
     assert_equals(tbl.grow(0), 1);
index f359d31..dcb4e59 100644 (file)
@@ -1,3 +1,13 @@
+2019-07-15  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Improve wasm wpt test results by fixing miscellaneous issues
+        https://bugs.webkit.org/show_bug.cgi?id=199783
+
+        Reviewed by Mark Lam.
+
+        * platform/ios-simulator/TestExpectations:
+        * platform/win/TestExpectations:
+
 2019-07-15  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed, rolling out r247440.
index d997e94..94bafb3 100644 (file)
@@ -1,3 +1,262 @@
+2019-07-15  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Improve wasm wpt test results by fixing miscellaneous issues
+        https://bugs.webkit.org/show_bug.cgi?id=199783
+
+        Reviewed by Mark Lam.
+
+        Import web-platform-tests/wasm/jsapi. Some of tests are failing just because imported wpt tests are old.
+        They are fixed in the upstream. When upgrading wpt tests, we can mark them PASS.
+
+        * resources/import-expectations.json:
+        * web-platform-tests/wasm/jsapi/assertions.js: Added.
+        (assert_function_name):
+        (assert_function_length):
+        * web-platform-tests/wasm/jsapi/bad-imports.js: Added.
+        (test_bad_imports):
+        * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.html: Added.
+        * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.js: Added.
+        (test_bad_imports):
+        * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/constructor/w3c-import.log: Added.
+        * web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/global/constructor.any.html: Added.
+        * web-platform-tests/wasm/jsapi/global/constructor.any.js: Added.
+        (assert_Global):
+        (test):
+        (test.get assert_array_equals):
+        (string_appeared_here.test):
+        (string_appeared_here.toString):
+        (string_appeared_here.valueOf):
+        (string_appeared_here.name.format_value):
+        * web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/global/constructor.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/global/toString.any.html: Added.
+        * web-platform-tests/wasm/jsapi/global/toString.any.js: Added.
+        (test):
+        * web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/global/toString.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/global/value-set.any.html: Added.
+        * web-platform-tests/wasm/jsapi/global/value-set.any.js: Added.
+        (test):
+        (string_appeared_here.name.of.immutableOptions.test):
+        (string_appeared_here.name.of.mutableOptions.test):
+        * web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/global/value-set.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/global/valueOf.any.html: Added.
+        * web-platform-tests/wasm/jsapi/global/valueOf.any.js: Added.
+        (test):
+        * web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/global/valueOf.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/global/w3c-import.log: Added.
+        * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.html: Added.
+        * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.js: Added.
+        (test_bad_imports):
+        * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/instance/constructor.any.html: Added.
+        * web-platform-tests/wasm/jsapi/instance/constructor.any.js: Added.
+        (assert_exported_function):
+        * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/instance/constructor.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/instance/exports.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/instance/exports.any.html: Added.
+        * web-platform-tests/wasm/jsapi/instance/exports.any.js: Added.
+        (setup):
+        (test):
+        * web-platform-tests/wasm/jsapi/instance/exports.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/instance/exports.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/instance/toString.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/instance/toString.any.html: Added.
+        * web-platform-tests/wasm/jsapi/instance/toString.any.js: Added.
+        (test):
+        * web-platform-tests/wasm/jsapi/instance/toString.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/instance/toString.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/instance/w3c-import.log: Added.
+        * web-platform-tests/wasm/jsapi/interface.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/interface.any.html: Added.
+        * web-platform-tests/wasm/jsapi/interface.any.js: Added.
+        (test_operations):
+        (test):
+        (const.name.of.interfaces.test):
+        * web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/interface.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/memory/buffer.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/memory/buffer.any.html: Added.
+        * web-platform-tests/wasm/jsapi/memory/buffer.any.js: Added.
+        (test):
+        * web-platform-tests/wasm/jsapi/memory/buffer.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/memory/buffer.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/memory/constructor.any.html: Added.
+        * web-platform-tests/wasm/jsapi/memory/constructor.any.js: Added.
+        (assert_Memory):
+        (test):
+        (const.value.of.outOfRangeValues.test):
+        (test.get new):
+        (test.get assert_array_equals):
+        * web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/memory/constructor.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/memory/grow.any.html: Added.
+        * web-platform-tests/wasm/jsapi/memory/grow.any.js: Added.
+        (assert_ArrayBuffer):
+        (test):
+        (valueOf):
+        (const.value.of.outOfRangeValues.test):
+        * web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/memory/grow.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/memory/toString.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/memory/toString.any.html: Added.
+        * web-platform-tests/wasm/jsapi/memory/toString.any.js: Added.
+        (test):
+        * web-platform-tests/wasm/jsapi/memory/toString.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/memory/toString.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/memory/w3c-import.log: Added.
+        * web-platform-tests/wasm/jsapi/module/constructor.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/constructor.any.html: Added.
+        * web-platform-tests/wasm/jsapi/module/constructor.any.js: Added.
+        (setup):
+        (test):
+        * web-platform-tests/wasm/jsapi/module/constructor.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/constructor.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/module/customSections.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/customSections.any.html: Added.
+        * web-platform-tests/wasm/jsapi/module/customSections.any.js: Added.
+        (assert_ArrayBuffer):
+        (assert_sections):
+        (setup):
+        (test):
+        * web-platform-tests/wasm/jsapi/module/customSections.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/customSections.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/exports.any.html: Added.
+        * web-platform-tests/wasm/jsapi/module/exports.any.js: Added.
+        (setup):
+        (assert_ModuleExportDescriptor):
+        (assert_exports):
+        (test):
+        * web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/exports.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/module/imports.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/imports.any.html: Added.
+        * web-platform-tests/wasm/jsapi/module/imports.any.js: Added.
+        (assert_ModuleImportDescriptor):
+        (assert_imports):
+        (setup):
+        (test):
+        * web-platform-tests/wasm/jsapi/module/imports.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/imports.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/module/toString.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/toString.any.html: Added.
+        * web-platform-tests/wasm/jsapi/module/toString.any.js: Added.
+        (test):
+        * web-platform-tests/wasm/jsapi/module/toString.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/module/toString.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/module/w3c-import.log: Added.
+        * web-platform-tests/wasm/jsapi/table/assertions.js: Added.
+        (assert_equal_to_array):
+        * web-platform-tests/wasm/jsapi/table/constructor.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/constructor.any.html: Added.
+        * web-platform-tests/wasm/jsapi/table/constructor.any.js: Added.
+        (assert_Table):
+        (test):
+        (const.value.of.outOfRangeValues.test):
+        (test.get const):
+        * web-platform-tests/wasm/jsapi/table/constructor.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/constructor.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/table/get-set.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/get-set.any.html: Added.
+        * web-platform-tests/wasm/jsapi/table/get-set.any.js: Added.
+        (setup):
+        (test):
+        (test.set assert_equal_to_array):
+        (test.const.fn):
+        (valueOf):
+        (const.value.of.outOfRangeValues.test):
+        * web-platform-tests/wasm/jsapi/table/get-set.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/get-set.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/table/grow.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/grow.any.html: Added.
+        * web-platform-tests/wasm/jsapi/table/grow.any.js: Added.
+        (nulls):
+        (test):
+        (valueOf):
+        (const.value.of.outOfRangeValues.test):
+        * web-platform-tests/wasm/jsapi/table/grow.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/grow.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/table/length.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/length.any.html: Added.
+        * web-platform-tests/wasm/jsapi/table/length.any.js: Added.
+        (test):
+        * web-platform-tests/wasm/jsapi/table/length.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/length.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/table/toString.any-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/toString.any.html: Added.
+        * web-platform-tests/wasm/jsapi/table/toString.any.js: Added.
+        (test):
+        * web-platform-tests/wasm/jsapi/table/toString.any.worker-expected.txt: Added.
+        * web-platform-tests/wasm/jsapi/table/toString.any.worker.html: Added.
+        * web-platform-tests/wasm/jsapi/table/w3c-import.log: Added.
+        * web-platform-tests/wasm/jsapi/w3c-import.log: Added.
+        * web-platform-tests/wasm/jsapi/wasm-constants.js: Added.
+        (bytes):
+        (bytesWithHeader):
+        (makeSig):
+        (makeSig_v_x):
+        (makeSig_v_xx):
+        (makeSig_r_v):
+        (makeSig_r_x):
+        (makeSig_r_xx):
+        (assertTraps):
+        (assertWasmThrows):
+        * web-platform-tests/wasm/jsapi/wasm-module-builder.js: Added.
+        (Binary.prototype.emit_u8):
+        (Binary.prototype.emit_u16):
+        (Binary.prototype.emit_u32):
+        (Binary.prototype.emit_u32v):
+        (Binary.prototype.emit_bytes):
+        (Binary.prototype.emit_string):
+        (Binary.prototype.emit_header):
+        (Binary.prototype.emit_section):
+        (Binary):
+        (WasmFunctionBuilder):
+        (WasmFunctionBuilder.prototype.exportAs):
+        (WasmFunctionBuilder.prototype.exportFunc):
+        (WasmFunctionBuilder.prototype.addBody):
+        (WasmFunctionBuilder.prototype.addLocals):
+        (WasmFunctionBuilder.prototype.end):
+        (WasmGlobalBuilder):
+        (WasmGlobalBuilder.prototype.exportAs):
+        (WasmModuleBuilder):
+        (WasmModuleBuilder.prototype.addStart):
+        (WasmModuleBuilder.prototype.addMemory):
+        (WasmModuleBuilder.prototype.addExplicitSection):
+        (WasmModuleBuilder.prototype.addType):
+        (WasmModuleBuilder.prototype.addGlobal):
+        (WasmModuleBuilder.prototype.addFunction):
+        (WasmModuleBuilder.prototype.addImport):
+        (WasmModuleBuilder.prototype.addImportedGlobal):
+        (WasmModuleBuilder.prototype.addImportedMemory):
+        (WasmModuleBuilder.prototype.addImportedTable):
+        (WasmModuleBuilder.prototype.addExport):
+        (WasmModuleBuilder.prototype.addExportOfKind):
+        (WasmModuleBuilder.prototype.addDataSegment):
+        (WasmModuleBuilder.prototype.exportMemoryAs):
+        (WasmModuleBuilder.prototype.addFunctionTableInit):
+        (WasmModuleBuilder.prototype.appendToTable):
+        (WasmModuleBuilder.prototype.setFunctionTableLength):
+        (WasmModuleBuilder.prototype.toArray):
+        (WasmModuleBuilder.prototype.toBuffer):
+        (WasmModuleBuilder.prototype.instantiate):
+
 2019-07-15  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed, rolling out r247440.
index 7957f50..c426228 100644 (file)
     "web-platform-tests/visual-viewport": "import", 
     "web-platform-tests/wai-aria": "skip", 
     "web-platform-tests/wasm": "skip", 
+    "web-platform-tests/wasm/jsapi": "import", 
     "web-platform-tests/web-animations": "skip", 
     "web-platform-tests/web-nfc": "skip", 
     "web-platform-tests/webaudio": "import", 
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/assertions.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/assertions.js
new file mode 100644 (file)
index 0000000..151a406
--- /dev/null
@@ -0,0 +1,17 @@
+function assert_function_name(fn, name, description) {
+  const propdesc = Object.getOwnPropertyDescriptor(fn, "name");
+  assert_equals(typeof propdesc, "object", `${description} should have name property`);
+  assert_false(propdesc.writable, "writable", `${description} name should not be writable`);
+  assert_false(propdesc.enumerable, "enumerable", `${description} name should not be enumerable`);
+  assert_true(propdesc.configurable, "configurable", `${description} name should be configurable`);
+  assert_equals(propdesc.value, name, `${description} name should be ${name}`);
+}
+
+function assert_function_length(fn, length, description) {
+  const propdesc = Object.getOwnPropertyDescriptor(fn, "length");
+  assert_equals(typeof propdesc, "object", `${description} should have length property`);
+  assert_false(propdesc.writable, "writable", `${description} length should not be writable`);
+  assert_false(propdesc.enumerable, "enumerable", `${description} length should not be enumerable`);
+  assert_true(propdesc.configurable, "configurable", `${description} length should be configurable`);
+  assert_equals(propdesc.value, length, `${description} length should be ${length}`);
+}
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/bad-imports.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/bad-imports.js
new file mode 100644 (file)
index 0000000..f076baa
--- /dev/null
@@ -0,0 +1,140 @@
+function test_bad_imports(t) {
+  for (const value of [null, true, "", Symbol(), 1, 0.1, NaN]) {
+    t(`Non-object imports argument: ${format_value(value)}`,
+      new TypeError(),
+      builder => {},
+      value);
+  }
+
+  for (const value of [undefined, null, true, "", Symbol(), 1, 0.1, NaN]) {
+    const imports = {
+      "module": value,
+    };
+    t(`Non-object module: ${format_value(value)}`,
+      new TypeError(),
+      builder => {
+        builder.addImport("module", "fn", kSig_v_v);
+      },
+      value);
+  }
+
+  t(`Missing imports argument`,
+    new TypeError(),
+    builder => {
+      builder.addImport("module", "fn", kSig_v_v);
+    });
+
+  for (const [value, name] of [[undefined, "undefined"], [{}, "empty object"], [{ "module\0": null }, "wrong property"]]) {
+    t(`Imports argument with missing property: ${name}`,
+      new TypeError(),
+      builder => {
+        builder.addImport("module", "fn", kSig_v_v);
+      },
+      value);
+  }
+
+  t(`Importing an i64 global`,
+    new WebAssembly.LinkError(),
+    builder => {
+      builder.addImportedGlobal("module", "global", kWasmI64);
+    },
+    {
+      "module": {
+        "global": 0,
+      },
+    });
+
+  for (const value of [undefined, null, true, "", Symbol(), 1, 0.1, NaN, {}]) {
+    t(`Importing a function with an incorrectly-typed value: ${format_value(value)}`,
+      new WebAssembly.LinkError(),
+      builder => {
+        builder.addImport("module", "fn", kSig_v_v);
+      },
+      {
+        "module": {
+          "fn": value,
+        },
+      });
+  }
+
+  const nonGlobals = [
+    [undefined],
+    [null],
+    [true],
+    [""],
+    [Symbol()],
+    [{}, "plain object"],
+    [WebAssembly.Global, "WebAssembly.Global"],
+    [WebAssembly.Global.prototype, "WebAssembly.Global.prototype"],
+    [Object.create(WebAssembly.Global.prototype), "Object.create(WebAssembly.Global.prototype)"],
+  ];
+
+  for (const [value, name = format_value(value)] of nonGlobals) {
+    t(`Importing a global with an incorrectly-typed value: ${name}`,
+      new WebAssembly.LinkError(),
+      builder => {
+        builder.addImportedGlobal("module", "global", kWasmI32);
+      },
+      {
+        "module": {
+          "global": value,
+        },
+      });
+  }
+
+  const nonMemories = [
+    [undefined],
+    [null],
+    [true],
+    [""],
+    [Symbol()],
+    [1],
+    [0.1],
+    [NaN],
+    [{}, "plain object"],
+    [WebAssembly.Memory, "WebAssembly.Memory"],
+    [WebAssembly.Memory.prototype, "WebAssembly.Memory.prototype"],
+    [Object.create(WebAssembly.Memory.prototype), "Object.create(WebAssembly.Memory.prototype)"],
+  ];
+
+  for (const [value, name = format_value(value)] of nonMemories) {
+    t(`Importing memory with an incorrectly-typed value: ${name}`,
+      new WebAssembly.LinkError(),
+      builder => {
+        builder.addImportedMemory("module", "memory", 0, 128);
+      },
+      {
+        "module": {
+          "memory": value,
+        },
+      });
+  }
+
+  const nonTables = [
+    [undefined],
+    [null],
+    [true],
+    [""],
+    [Symbol()],
+    [1],
+    [0.1],
+    [NaN],
+    [{}, "plain object"],
+    [WebAssembly.Table, "WebAssembly.Table"],
+    [WebAssembly.Table.prototype, "WebAssembly.Table.prototype"],
+    [Object.create(WebAssembly.Table.prototype), "Object.create(WebAssembly.Table.prototype)"],
+  ];
+
+  for (const [value, name = format_value(value)] of nonTables) {
+    t(`Importing table with an incorrectly-typed value: ${name}`,
+      new WebAssembly.LinkError(),
+      builder => {
+        builder.addImportedTable("module", "table", 0, 128);
+      },
+      {
+        "module": {
+          "table": value,
+        },
+      });
+  }
+}
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt
new file mode 100644 (file)
index 0000000..5d37480
--- /dev/null
@@ -0,0 +1,34 @@
+CONSOLE MESSAGE: line 68: TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+Harness Error (FAIL), message = TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+PASS WebAssembly.instantiate(module): Non-object imports argument: null 
+PASS WebAssembly.instantiate(module): Non-object imports argument: true 
+PASS WebAssembly.instantiate(module): Non-object imports argument: "" 
+PASS WebAssembly.instantiate(module): Non-object imports argument: symbol "Symbol()" 
+PASS WebAssembly.instantiate(module): Non-object imports argument: 1 
+PASS WebAssembly.instantiate(module): Non-object imports argument: 0.1 
+PASS WebAssembly.instantiate(module): Non-object imports argument: NaN 
+PASS WebAssembly.instantiate(module): Non-object module: undefined 
+PASS WebAssembly.instantiate(module): Non-object module: null 
+PASS WebAssembly.instantiate(module): Non-object module: true 
+PASS WebAssembly.instantiate(module): Non-object module: "" 
+PASS WebAssembly.instantiate(module): Non-object module: symbol "Symbol()" 
+PASS WebAssembly.instantiate(module): Non-object module: 1 
+PASS WebAssembly.instantiate(module): Non-object module: 0.1 
+PASS WebAssembly.instantiate(module): Non-object module: NaN 
+PASS WebAssembly.instantiate(module): Missing imports argument 
+PASS WebAssembly.instantiate(module): Imports argument with missing property: undefined 
+PASS WebAssembly.instantiate(module): Imports argument with missing property: empty object 
+PASS WebAssembly.instantiate(module): Imports argument with missing property: wrong property 
+PASS WebAssembly.instantiate(module): Importing an i64 global 
+PASS WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: undefined 
+PASS WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: null 
+PASS WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: true 
+PASS WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: "" 
+PASS WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: symbol "Symbol()" 
+PASS WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: 1 
+PASS WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: 0.1 
+PASS WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: NaN 
+PASS WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: object "[object Object]" 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.js
new file mode 100644 (file)
index 0000000..8670029
--- /dev/null
@@ -0,0 +1,23 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+// META: script=/wasm/jsapi/bad-imports.js
+
+test_bad_imports((name, error, build, ...arguments) => {
+  promise_test(t => {
+    const builder = new WasmModuleBuilder();
+    build(builder);
+    const buffer = builder.toBuffer();
+    const module = new WebAssembly.Module(buffer);
+    return promise_rejects(t, error, WebAssembly.instantiate(module, ...arguments));
+  }, `WebAssembly.instantiate(module): ${name}`);
+});
+
+test_bad_imports((name, error, build, ...arguments) => {
+  promise_test(t => {
+    const builder = new WasmModuleBuilder();
+    build(builder);
+    const buffer = builder.toBuffer();
+    return promise_rejects(t, error, WebAssembly.instantiate(buffer, ...arguments));
+  }, `WebAssembly.instantiate(buffer): ${name}`);
+});
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..5ee9e4d
--- /dev/null
@@ -0,0 +1,33 @@
+
+Harness Error (FAIL), message = Error in remote http://localhost:8800/wasm/jsapi/bad-imports.js: TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+PASS WebAssembly.instantiate(module): Non-object imports argument: null 
+PASS WebAssembly.instantiate(module): Non-object imports argument: true 
+PASS WebAssembly.instantiate(module): Non-object imports argument: "" 
+PASS WebAssembly.instantiate(module): Non-object imports argument: symbol "Symbol()" 
+PASS WebAssembly.instantiate(module): Non-object imports argument: 1 
+PASS WebAssembly.instantiate(module): Non-object imports argument: 0.1 
+PASS WebAssembly.instantiate(module): Non-object imports argument: NaN 
+PASS WebAssembly.instantiate(module): Non-object module: undefined 
+PASS WebAssembly.instantiate(module): Non-object module: null 
+PASS WebAssembly.instantiate(module): Non-object module: true 
+PASS WebAssembly.instantiate(module): Non-object module: "" 
+PASS WebAssembly.instantiate(module): Non-object module: symbol "Symbol()" 
+PASS WebAssembly.instantiate(module): Non-object module: 1 
+PASS WebAssembly.instantiate(module): Non-object module: 0.1 
+PASS WebAssembly.instantiate(module): Non-object module: NaN 
+PASS WebAssembly.instantiate(module): Missing imports argument 
+PASS WebAssembly.instantiate(module): Imports argument with missing property: undefined 
+TIMEOUT WebAssembly.instantiate(module): Imports argument with missing property: empty object Test timed out
+NOTRUN WebAssembly.instantiate(module): Imports argument with missing property: wrong property 
+NOTRUN WebAssembly.instantiate(module): Importing an i64 global 
+NOTRUN WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: undefined 
+NOTRUN WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: null 
+NOTRUN WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: true 
+NOTRUN WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: "" 
+NOTRUN WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: symbol "Symbol()" 
+NOTRUN WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: 1 
+NOTRUN WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: 0.1 
+NOTRUN WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: NaN 
+NOTRUN WebAssembly.instantiate(module): Importing a function with an incorrectly-typed value: object "[object Object]" 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/w3c-import.log b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/w3c-import.log
new file mode 100644 (file)
index 0000000..7197fd2
--- /dev/null
@@ -0,0 +1,17 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+       https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.js
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt
new file mode 100644 (file)
index 0000000..ae4d28b
--- /dev/null
@@ -0,0 +1,37 @@
+
+FAIL name undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(fn, "name")')
+FAIL length undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(fn, "length")')
+PASS No arguments 
+PASS Calling 
+FAIL Order of evaluation undefined is not a constructor (evaluating 'new WebAssembly.Global')
+PASS Invalid descriptor argument 
+PASS Invalid type argument 
+FAIL i64 with default undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Default value for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Explicit value undefined for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value null for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value true for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value false for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value 2 for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value "3" for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with toString for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with valueOf for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Default value for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Explicit value undefined for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value null for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value true for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value false for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value 2 for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value "3" for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with toString for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with valueOf for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Default value for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Explicit value undefined for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value null for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value true for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value false for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value 2 for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value "3" for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with toString for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with valueOf for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.js
new file mode 100644 (file)
index 0000000..7a45cc4
--- /dev/null
@@ -0,0 +1,121 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/assertions.js
+
+function assert_Global(actual, expected) {
+  assert_equals(Object.getPrototypeOf(actual), WebAssembly.Global.prototype,
+                "prototype");
+  assert_true(Object.isExtensible(actual), "extensible");
+
+  assert_equals(actual.value, expected, "value");
+  assert_equals(actual.valueOf(), expected, "valueOf");
+}
+
+test(() => {
+  assert_function_name(WebAssembly.Global, "Global", "WebAssembly.Global");
+}, "name");
+
+test(() => {
+  assert_function_length(WebAssembly.Global, 1, "WebAssembly.Global");
+}, "length");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly.Global());
+}, "No arguments");
+
+test(() => {
+  const argument = { "value": "i32" };
+  assert_throws(new TypeError(), () => WebAssembly.Global(argument));
+}, "Calling");
+
+test(() => {
+  const order = [];
+
+  new WebAssembly.Global({
+    get value() {
+      order.push("descriptor value");
+      return {
+        toString() {
+          order.push("descriptor value toString");
+          return "f64";
+        },
+      };
+    },
+
+    get mutable() {
+      order.push("descriptor mutable");
+      return false;
+    },
+  }, {
+    valueOf() {
+      order.push("value valueOf()");
+    }
+  });
+
+  assert_array_equals(order, [
+    "descriptor mutable",
+    "descriptor value",
+    "descriptor value toString",
+    "value valueOf()",
+  ]);
+}, "Order of evaluation");
+
+test(() => {
+  const invalidArguments = [
+    undefined,
+    null,
+    false,
+    true,
+    "",
+    "test",
+    Symbol(),
+    1,
+    NaN,
+    {},
+  ];
+  for (const invalidArgument of invalidArguments) {
+    assert_throws(new TypeError(),
+                  () => new WebAssembly.Global(invalidArgument),
+                  `new Global(${format_value(invalidArgument)})`);
+  }
+}, "Invalid descriptor argument");
+
+test(() => {
+  const invalidTypes = ["i16", "i128", "f16", "f128", "u32", "u64", "i32\0"];
+  for (const value of invalidTypes) {
+    const argument = { value };
+    assert_throws(new TypeError(), () => new WebAssembly.Global(argument));
+  }
+}, "Invalid type argument");
+
+test(() => {
+  const argument = { "value": "i64" };
+  const global = new WebAssembly.Global(argument);
+  assert_throws(new TypeError(), () => global.value);
+  assert_throws(new TypeError(), () => global.valueOf());
+}, "i64 with default");
+
+for (const type of ["i32", "f32", "f64"]) {
+  test(() => {
+    const argument = { "value": type };
+    const global = new WebAssembly.Global(argument);
+    assert_Global(global, 0);
+  }, `Default value for type ${type}`);
+
+  const valueArguments = [
+    [undefined, 0],
+    [null, 0],
+    [true, 1],
+    [false, 0],
+    [2, 2],
+    ["3", 3],
+    [{ toString() { return "5" } }, 5, "object with toString"],
+    [{ valueOf() { return "8" } }, 8, "object with valueOf"],
+  ];
+  for (const [value, expected, name = format_value(value)] of valueArguments) {
+    test(() => {
+      const argument = { "value": type };
+      const global = new WebAssembly.Global(argument, value);
+      assert_Global(global, expected);
+    }, `Explicit value ${name} for type ${type}`);
+  }
+}
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..ae4d28b
--- /dev/null
@@ -0,0 +1,37 @@
+
+FAIL name undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(fn, "name")')
+FAIL length undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(fn, "length")')
+PASS No arguments 
+PASS Calling 
+FAIL Order of evaluation undefined is not a constructor (evaluating 'new WebAssembly.Global')
+PASS Invalid descriptor argument 
+PASS Invalid type argument 
+FAIL i64 with default undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Default value for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Explicit value undefined for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value null for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value true for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value false for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value 2 for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value "3" for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with toString for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with valueOf for type i32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Default value for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Explicit value undefined for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value null for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value true for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value false for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value 2 for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value "3" for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with toString for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with valueOf for type f32 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Default value for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Explicit value undefined for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value null for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value true for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value false for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value 2 for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value "3" for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with toString for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+FAIL Explicit value object with valueOf for type f64 undefined is not a constructor (evaluating 'new WebAssembly.Global(argument, value)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any-expected.txt
new file mode 100644 (file)
index 0000000..0e91a9b
--- /dev/null
@@ -0,0 +1,3 @@
+
+FAIL Object.prototype.toString on an Global undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.js
new file mode 100644 (file)
index 0000000..ca02557
--- /dev/null
@@ -0,0 +1,7 @@
+// META: global=jsshell
+
+test(() => {
+  const argument = { "value": "i32" };
+  const global = new WebAssembly.Global(argument);
+  assert_class_string(global, "WebAssembly.Global");
+}, "Object.prototype.toString on an Global");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..0e91a9b
--- /dev/null
@@ -0,0 +1,3 @@
+
+FAIL Object.prototype.toString on an Global undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt
new file mode 100644 (file)
index 0000000..c6d3c41
--- /dev/null
@@ -0,0 +1,35 @@
+
+FAIL Branding undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+FAIL Immutable i32 (missing) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (undefined) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (null) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (false) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (empty string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (zero) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable i32 (true) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable i32 (one) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable i32 (string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable i32 (true on prototype) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (missing) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (undefined) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (null) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (false) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (empty string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (zero) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f32 (true) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f32 (one) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f32 (string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f32 (true on prototype) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (missing) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (undefined) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (null) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (false) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (empty string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (zero) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f64 (true) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f64 (one) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f64 (string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f64 (true on prototype) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL i64 with default undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Calling setter without argument undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.js
new file mode 100644 (file)
index 0000000..b4e6770
--- /dev/null
@@ -0,0 +1,94 @@
+// META: global=jsshell
+
+test(() => {
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Global,
+    WebAssembly.Global.prototype,
+  ];
+
+  const desc = Object.getOwnPropertyDescriptor(WebAssembly.Global.prototype, "value");
+  assert_equals(typeof desc, "object");
+
+  const getter = desc.get;
+  assert_equals(typeof getter, "function");
+
+  const setter = desc.set;
+  assert_equals(typeof setter, "function");
+
+  for (const thisValue of thisValues) {
+    assert_throws(new TypeError(), () => getter.call(thisValue), `getter with this=${format_value(thisValue)}`);
+    assert_throws(new TypeError(), () => setter.call(thisValue, 1), `setter with this=${format_value(thisValue)}`);
+  }
+}, "Branding");
+
+for (const type of ["i32", "f32", "f64"]) {
+  const immutableOptions = [
+    [{}, "missing"],
+    [{ "mutable": undefined }, "undefined"],
+    [{ "mutable": null }, "null"],
+    [{ "mutable": false }, "false"],
+    [{ "mutable": "" }, "empty string"],
+    [{ "mutable": 0 }, "zero"],
+  ];
+  for (const [opts, name] of immutableOptions) {
+    test(() => {
+      opts.value = type;
+      const global = new WebAssembly.Global(opts);
+      assert_equals(global.value, 0, "initial value");
+      assert_equals(global.valueOf(), 0, "initial valueOf");
+
+      assert_throws(new TypeError(), () => global.value = 1);
+
+      assert_equals(global.value, 0, "post-set value");
+      assert_equals(global.valueOf(), 0, "post-set valueOf");
+    }, `Immutable ${type} (${name})`);
+  }
+
+  const mutableOptions = [
+    [{ "mutable": true }, "true"],
+    [{ "mutable": 1 }, "one"],
+    [{ "mutable": "x" }, "string"],
+    [Object.create({ "mutable": true }), "true on prototype"],
+  ];
+  for (const [opts, name] of mutableOptions) {
+    test(() => {
+      opts.value = type;
+      const global = new WebAssembly.Global(opts);
+      assert_equals(global.value, 0, "initial value");
+      assert_equals(global.valueOf(), 0, "initial valueOf");
+
+      global.value = 1;
+
+      assert_equals(global.value, 1, "post-set value");
+      assert_equals(global.valueOf(), 1, "post-set valueOf");
+    }, `Mutable ${type} (${name})`);
+  }
+}
+
+test(() => {
+  const argument = { "value": "i64", "mutable": true };
+  const global = new WebAssembly.Global(argument);
+  assert_throws(new TypeError(), () => global.value);
+  assert_throws(new TypeError(), () => global.value = 0);
+  assert_throws(new TypeError(), () => global.valueOf());
+}, "i64 with default");
+
+
+test(() => {
+  const argument = { "value": "i32", "mutable": true };
+  const global = new WebAssembly.Global(argument);
+  const desc = Object.getOwnPropertyDescriptor(WebAssembly.Global.prototype, "value");
+  assert_equals(typeof desc, "object");
+
+  const setter = desc.set;
+  assert_equals(typeof setter, "function");
+
+  assert_throws(new TypeError(), () => setter.call(global));
+}, "Calling setter without argument");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..c6d3c41
--- /dev/null
@@ -0,0 +1,35 @@
+
+FAIL Branding undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+FAIL Immutable i32 (missing) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (undefined) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (null) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (false) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (empty string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable i32 (zero) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable i32 (true) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable i32 (one) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable i32 (string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable i32 (true on prototype) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (missing) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (undefined) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (null) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (false) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (empty string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f32 (zero) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f32 (true) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f32 (one) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f32 (string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f32 (true on prototype) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (missing) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (undefined) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (null) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (false) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (empty string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Immutable f64 (zero) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f64 (true) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f64 (one) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f64 (string) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL Mutable f64 (true on prototype) undefined is not a constructor (evaluating 'new WebAssembly.Global(opts)')
+FAIL i64 with default undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+FAIL Calling setter without argument undefined is not a constructor (evaluating 'new WebAssembly.Global(argument)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt
new file mode 100644 (file)
index 0000000..27d5640
--- /dev/null
@@ -0,0 +1,3 @@
+
+FAIL Branding undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.js
new file mode 100644 (file)
index 0000000..176c5a7
--- /dev/null
@@ -0,0 +1,22 @@
+// META: global=jsshell
+
+test(() => {
+  const argument = { "value": "i32" };
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Global,
+    WebAssembly.Global.prototype,
+  ];
+
+  const fn = WebAssembly.Global.prototype.valueOf;
+
+  for (const thisValue of thisValues) {
+    assert_throws(new TypeError(), () => fn.call(thisValue), `this=${format_value(thisValue)}`);
+  }
+}, "Branding");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..27d5640
--- /dev/null
@@ -0,0 +1,3 @@
+
+FAIL Branding undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/w3c-import.log b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/w3c-import.log
new file mode 100644 (file)
index 0000000..ab1f3ef
--- /dev/null
@@ -0,0 +1,20 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+       https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/constructor.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/toString.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/value-set.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/global/valueOf.any.js
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt
new file mode 100644 (file)
index 0000000..a01fb3d
--- /dev/null
@@ -0,0 +1,34 @@
+CONSOLE MESSAGE: line 68: TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+Harness Error (FAIL), message = TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+PASS new WebAssembly.Instance(module): Non-object imports argument: null 
+PASS new WebAssembly.Instance(module): Non-object imports argument: true 
+PASS new WebAssembly.Instance(module): Non-object imports argument: "" 
+PASS new WebAssembly.Instance(module): Non-object imports argument: symbol "Symbol()" 
+PASS new WebAssembly.Instance(module): Non-object imports argument: 1 
+PASS new WebAssembly.Instance(module): Non-object imports argument: 0.1 
+PASS new WebAssembly.Instance(module): Non-object imports argument: NaN 
+PASS new WebAssembly.Instance(module): Non-object module: undefined 
+PASS new WebAssembly.Instance(module): Non-object module: null 
+PASS new WebAssembly.Instance(module): Non-object module: true 
+PASS new WebAssembly.Instance(module): Non-object module: "" 
+PASS new WebAssembly.Instance(module): Non-object module: symbol "Symbol()" 
+PASS new WebAssembly.Instance(module): Non-object module: 1 
+PASS new WebAssembly.Instance(module): Non-object module: 0.1 
+PASS new WebAssembly.Instance(module): Non-object module: NaN 
+PASS new WebAssembly.Instance(module): Missing imports argument 
+PASS new WebAssembly.Instance(module): Imports argument with missing property: undefined 
+PASS new WebAssembly.Instance(module): Imports argument with missing property: empty object 
+PASS new WebAssembly.Instance(module): Imports argument with missing property: wrong property 
+PASS new WebAssembly.Instance(module): Importing an i64 global 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: undefined 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: null 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: true 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: "" 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: symbol "Symbol()" 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: 1 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: 0.1 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: NaN 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: object "[object Object]" 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.js
new file mode 100644 (file)
index 0000000..24c51c1
--- /dev/null
@@ -0,0 +1,14 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+// META: script=/wasm/jsapi/bad-imports.js
+
+test_bad_imports((name, error, build, ...arguments) => {
+  test(() => {
+    const builder = new WasmModuleBuilder();
+    build(builder);
+    const buffer = builder.toBuffer();
+    const module = new WebAssembly.Module(buffer);
+    assert_throws(error, () => new WebAssembly.Instance(module, ...arguments));
+  }, `new WebAssembly.Instance(module): ${name}`);
+});
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..a09da4e
--- /dev/null
@@ -0,0 +1,35 @@
+CONSOLE MESSAGE: line 1774: TypeError: null is not an object (evaluating 'this.message_target.removeEventListener')
+CONSOLE MESSAGE: line 68: TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+Harness Error (FAIL), message = TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+PASS new WebAssembly.Instance(module): Non-object imports argument: null 
+PASS new WebAssembly.Instance(module): Non-object imports argument: true 
+PASS new WebAssembly.Instance(module): Non-object imports argument: "" 
+PASS new WebAssembly.Instance(module): Non-object imports argument: symbol "Symbol()" 
+PASS new WebAssembly.Instance(module): Non-object imports argument: 1 
+PASS new WebAssembly.Instance(module): Non-object imports argument: 0.1 
+PASS new WebAssembly.Instance(module): Non-object imports argument: NaN 
+PASS new WebAssembly.Instance(module): Non-object module: undefined 
+PASS new WebAssembly.Instance(module): Non-object module: null 
+PASS new WebAssembly.Instance(module): Non-object module: true 
+PASS new WebAssembly.Instance(module): Non-object module: "" 
+PASS new WebAssembly.Instance(module): Non-object module: symbol "Symbol()" 
+PASS new WebAssembly.Instance(module): Non-object module: 1 
+PASS new WebAssembly.Instance(module): Non-object module: 0.1 
+PASS new WebAssembly.Instance(module): Non-object module: NaN 
+PASS new WebAssembly.Instance(module): Missing imports argument 
+PASS new WebAssembly.Instance(module): Imports argument with missing property: undefined 
+PASS new WebAssembly.Instance(module): Imports argument with missing property: empty object 
+PASS new WebAssembly.Instance(module): Imports argument with missing property: wrong property 
+PASS new WebAssembly.Instance(module): Importing an i64 global 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: undefined 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: null 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: true 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: "" 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: symbol "Symbol()" 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: 1 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: 0.1 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: NaN 
+PASS new WebAssembly.Instance(module): Importing a function with an incorrectly-typed value: object "[object Object]" 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt
new file mode 100644 (file)
index 0000000..bb97fc8
--- /dev/null
@@ -0,0 +1,12 @@
+
+PASS name 
+PASS length 
+PASS No arguments 
+PASS Non-Module arguments 
+PASS Non-object imports 
+PASS Calling 
+PASS Empty module 
+PASS getter order for imports object 
+PASS imports 
+FAIL exports WebAssembly.Module doesn't parse at byte 87: 3th Export isn't immutable, named 'global' (evaluating 'new WebAssembly.Module(buffer)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.js
new file mode 100644 (file)
index 0000000..61a8f53
--- /dev/null
@@ -0,0 +1,227 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+// META: script=/wasm/jsapi/assertions.js
+
+function assert_exported_function(fn, { name, length }, description) {
+  assert_equals(Object.getPrototypeOf(fn), Function.prototype,
+                `${description}: prototype`);
+
+  assert_function_name(fn, name, description);
+  assert_function_length(fn, length, description);
+}
+
+function assert_Instance(instance, expected_exports) {
+  assert_equals(Object.getPrototypeOf(instance), WebAssembly.Instance.prototype,
+                "prototype");
+  assert_true(Object.isExtensible(instance), "extensible");
+
+  assert_equals(instance.exports, instance.exports, "exports should be idempotent");
+  const exports = instance.exports;
+
+  assert_equals(Object.getPrototypeOf(exports), null, "exports prototype");
+  assert_false(Object.isExtensible(exports), "extensible exports");
+  for (const [key, expected] of Object.entries(expected_exports)) {
+    const property = Object.getOwnPropertyDescriptor(exports, key);
+    assert_equals(typeof property, "object", `${key} should be present`);
+    assert_false(property.writable, `${key}: writable`);
+    assert_true(property.enumerable, `${key}: enumerable`);
+    assert_false(property.configurable, `${key}: configurable`);
+    const actual = property.value;
+    assert_true(Object.isExtensible(actual), `${key}: extensible`);
+
+    switch (expected.kind) {
+    case "function":
+      assert_exported_function(actual, expected, `value of ${key}`);
+      break;
+    case "global":
+      assert_equals(Object.getPrototypeOf(actual), WebAssembly.Global.prototype,
+                    `value of ${key}: prototype`);
+      assert_equals(actual.value, expected.value, `value of ${key}: value`);
+      assert_equals(actual.valueOf(), expected.value, `value of ${key}: valueOf()`);
+      break;
+    case "memory":
+      assert_equals(Object.getPrototypeOf(actual), WebAssembly.Memory.prototype,
+                    `value of ${key}: prototype`);
+      assert_equals(Object.getPrototypeOf(actual.buffer), ArrayBuffer.prototype,
+                    `value of ${key}: prototype of buffer`);
+      assert_equals(actual.buffer.byteLength, 0x10000 * expected.size, `value of ${key}: size of buffer`);
+      const array = new Uint8Array(actual.buffer);
+      assert_equals(array[0], 0, `value of ${key}: first element of buffer`);
+      assert_equals(array[array.byteLength - 1], 0, `value of ${key}: last element of buffer`);
+      break;
+    case "table":
+      assert_equals(Object.getPrototypeOf(actual), WebAssembly.Table.prototype,
+                    `value of ${key}: prototype`);
+      assert_equals(actual.length, expected.length, `value of ${key}: length of table`);
+      break;
+    }
+  }
+}
+
+let emptyModuleBinary;
+setup(() => {
+  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+});
+
+test(() => {
+  assert_function_name(WebAssembly.Instance, "Instance", "WebAssembly.Instance");
+}, "name");
+
+test(() => {
+  assert_function_length(WebAssembly.Instance, 1, "WebAssembly.Instance");
+}, "length");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly.Instance());
+}, "No arguments");
+
+test(() => {
+  const invalidArguments = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Module,
+    WebAssembly.Module.prototype,
+  ];
+  for (const argument of invalidArguments) {
+    assert_throws(new TypeError(), () => new WebAssembly.Instance(argument),
+                  `new Instance(${format_value(argument)})`);
+  }
+}, "Non-Module arguments");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const invalidArguments = [
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+  ];
+  for (const argument of invalidArguments) {
+    assert_throws(new TypeError(), () => new WebAssembly.Instance(module, argument),
+                  `new Instance(module, ${format_value(argument)})`);
+  }
+}, "Non-object imports");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  assert_throws(new TypeError(), () => WebAssembly.Instance(module));
+}, "Calling");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const arguments = [
+    [],
+    [undefined],
+    [{}],
+  ];
+  for (const value of arguments) {
+    const instance = new WebAssembly.Instance(module, ...arguments);
+    assert_Instance(instance, {});
+  }
+}, "Empty module");
+
+test(() => {
+  const builder = new WasmModuleBuilder();
+  builder.addImportedGlobal("module", "global1", kWasmI32);
+  builder.addImportedGlobal("module", "global2", kWasmI32);
+  const buffer = builder.toBuffer();
+  const module = new WebAssembly.Module(buffer);
+  const order = [];
+  const imports = {
+    get module() {
+      order.push("module getter");
+      return {
+        get global1() {
+          order.push("global1 getter");
+          return 0;
+        },
+        get global2() {
+          order.push("global2 getter");
+          return 0;
+        },
+      }
+    },
+  };
+  new WebAssembly.Instance(module, imports);
+  const expected = [
+    "module getter",
+    "global1 getter",
+    "module getter",
+    "global2 getter",
+  ];
+  assert_array_equals(order, expected);
+}, "getter order for imports object");
+
+test(() => {
+  const builder = new WasmModuleBuilder();
+
+  builder.addImport("module", "fn", kSig_v_v);
+  builder.addImportedGlobal("module", "global", kWasmI32);
+  builder.addImportedMemory("module", "memory", 0, 128);
+  builder.addImportedTable("module", "table", 0, 128);
+
+  const buffer = builder.toBuffer();
+  const module = new WebAssembly.Module(buffer);
+  const instance = new WebAssembly.Instance(module, {
+    "module": {
+      "fn": function() {},
+      "global": 0,
+      "memory": new WebAssembly.Memory({ "initial": 64, maximum: 128 }),
+      "table": new WebAssembly.Table({ "element": "anyfunc", "initial": 64, maximum: 128 }),
+    },
+    get "module2"() {
+      assert_unreached("Should not get modules that are not imported");
+    },
+  });
+  assert_Instance(instance, {});
+}, "imports");
+
+test(() => {
+  const builder = new WasmModuleBuilder();
+
+  builder
+    .addFunction("fn", kSig_v_d)
+    .addBody([
+        kExprEnd
+    ])
+    .exportFunc();
+  builder
+    .addFunction("fn2", kSig_v_v)
+    .addBody([
+        kExprEnd
+    ])
+    .exportFunc();
+
+  builder.setFunctionTableLength(1);
+  builder.addExportOfKind("table", kExternalTable, 0);
+
+  builder.addGlobal(kWasmI32, true)
+    .exportAs("global")
+    .init = 7;
+  builder.addGlobal(kWasmF64, true)
+    .exportAs("global2")
+    .init = 1.2;
+
+  builder.addMemory(4, 8, true);
+
+  const buffer = builder.toBuffer()
+  const module = new WebAssembly.Module(buffer);
+
+  const instance = new WebAssembly.Instance(module, {});
+  const expected = {
+    "fn": { "kind": "function", "name": "0", "length": 1 },
+    "fn2": { "kind": "function", "name": "1", "length": 0 },
+    "table": { "kind": "table", "length": 1 },
+    "global": { "kind": "global", "value": 7 },
+    "global2": { "kind": "global", "value": 1.2 },
+    "memory": { "kind": "memory", "size": 4 },
+  };
+  assert_Instance(instance, expected);
+}, "exports");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..bb97fc8
--- /dev/null
@@ -0,0 +1,12 @@
+
+PASS name 
+PASS length 
+PASS No arguments 
+PASS Non-Module arguments 
+PASS Non-object imports 
+PASS Calling 
+PASS Empty module 
+PASS getter order for imports object 
+PASS imports 
+FAIL exports WebAssembly.Module doesn't parse at byte 87: 3th Export isn't immutable, named 'global' (evaluating 'new WebAssembly.Module(buffer)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any-expected.txt
new file mode 100644 (file)
index 0000000..670f281
--- /dev/null
@@ -0,0 +1,5 @@
+
+PASS Branding 
+PASS Setting (sloppy mode) 
+PASS Setting (strict mode) 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.js
new file mode 100644 (file)
index 0000000..3142391
--- /dev/null
@@ -0,0 +1,53 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+
+let emptyModuleBinary;
+setup(() => {
+  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+});
+
+test(() => {
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Instance,
+    WebAssembly.Instance.prototype,
+  ];
+
+  const desc = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports");
+  assert_equals(typeof desc, "object");
+
+  const getter = desc.get;
+  assert_equals(typeof getter, "function");
+
+  assert_equals(typeof desc.set, "undefined");
+
+  for (const thisValue of thisValues) {
+    assert_throws(new TypeError(), () => getter.call(thisValue), `this=${format_value(thisValue)}`);
+  }
+}, "Branding");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const instance = new WebAssembly.Instance(module);
+  const exports = instance.exports;
+  instance.exports = {};
+  assert_equals(instance.exports, exports, "Should not change the exports");
+}, "Setting (sloppy mode)");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const instance = new WebAssembly.Instance(module);
+  const exports = instance.exports;
+  assert_throws(new TypeError(), () => {
+    "use strict";
+    instance.exports = {};
+  });
+  assert_equals(instance.exports, exports, "Should not change the exports");
+}, "Setting (strict mode)");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..670f281
--- /dev/null
@@ -0,0 +1,5 @@
+
+PASS Branding 
+PASS Setting (sloppy mode) 
+PASS Setting (strict mode) 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any-expected.txt
new file mode 100644 (file)
index 0000000..73038a9
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Object.prototype.toString on an Instance 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.js
new file mode 100644 (file)
index 0000000..08dcb14
--- /dev/null
@@ -0,0 +1,10 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+
+test(() => {
+  const emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const instance = new WebAssembly.Instance(module);
+  assert_class_string(instance, "WebAssembly.Instance");
+}, "Object.prototype.toString on an Instance");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..73038a9
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Object.prototype.toString on an Instance 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/w3c-import.log b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/w3c-import.log
new file mode 100644 (file)
index 0000000..e689698
--- /dev/null
@@ -0,0 +1,20 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+       https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/constructor.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/exports.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/instance/toString.any.js
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any-expected.txt
new file mode 100644 (file)
index 0000000..a2a92dd
--- /dev/null
@@ -0,0 +1,85 @@
+CONSOLE MESSAGE: line 154: TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+Harness Error (FAIL), message = TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+PASS WebAssembly: property descriptor 
+PASS WebAssembly: calling 
+PASS WebAssembly: constructing 
+PASS WebAssembly.Module: property descriptor 
+PASS WebAssembly.Module: prototype 
+PASS WebAssembly.Module: prototype.constructor 
+PASS WebAssembly.Instance: property descriptor 
+PASS WebAssembly.Instance: prototype 
+PASS WebAssembly.Instance: prototype.constructor 
+PASS WebAssembly.Memory: property descriptor 
+PASS WebAssembly.Memory: prototype 
+PASS WebAssembly.Memory: prototype.constructor 
+PASS WebAssembly.Table: property descriptor 
+PASS WebAssembly.Table: prototype 
+PASS WebAssembly.Table: prototype.constructor 
+FAIL WebAssembly.Global: property descriptor assert_equals: expected "object" but got "undefined"
+FAIL WebAssembly.Global: prototype undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(interface_object, "prototype")')
+FAIL WebAssembly.Global: prototype.constructor undefined is not an object (evaluating 'interface_object.prototype')
+PASS WebAssembly.CompileError: property descriptor 
+PASS WebAssembly.CompileError: prototype 
+PASS WebAssembly.CompileError: prototype.constructor 
+PASS WebAssembly.LinkError: property descriptor 
+PASS WebAssembly.LinkError: prototype 
+PASS WebAssembly.LinkError: prototype.constructor 
+PASS WebAssembly.RuntimeError: property descriptor 
+PASS WebAssembly.RuntimeError: prototype 
+PASS WebAssembly.RuntimeError: prototype.constructor 
+PASS WebAssembly.validate 
+PASS WebAssembly.validate: name 
+PASS WebAssembly.validate: length 
+PASS WebAssembly.compile 
+PASS WebAssembly.compile: name 
+PASS WebAssembly.compile: length 
+PASS WebAssembly.instantiate 
+PASS WebAssembly.instantiate: name 
+PASS WebAssembly.instantiate: length 
+FAIL WebAssembly.Module.exports assert_equals: expected (undefined) undefined but got (function) function "function exports() {
+    [native code]
+}"
+PASS WebAssembly.Module.exports: name 
+PASS WebAssembly.Module.exports: length 
+FAIL WebAssembly.Module.imports assert_equals: expected (undefined) undefined but got (function) function "function imports() {
+    [native code]
+}"
+PASS WebAssembly.Module.imports: name 
+PASS WebAssembly.Module.imports: length 
+FAIL WebAssembly.Module.customSections assert_equals: expected (undefined) undefined but got (function) function "function customSections() {
+    [native code]
+}"
+PASS WebAssembly.Module.customSections: name 
+PASS WebAssembly.Module.customSections: length 
+PASS WebAssembly.Instance.exports 
+PASS WebAssembly.Instance.exports: getter 
+PASS WebAssembly.Instance.exports: setter 
+FAIL WebAssembly.Memory.grow assert_equals: expected (undefined) undefined but got (function) function "function grow() {
+    [native code]
+}"
+PASS WebAssembly.Memory.grow: name 
+PASS WebAssembly.Memory.grow: length 
+PASS WebAssembly.Memory.buffer 
+PASS WebAssembly.Memory.buffer: getter 
+PASS WebAssembly.Memory.buffer: setter 
+FAIL WebAssembly.Table.grow assert_equals: expected (undefined) undefined but got (function) function "function grow() {
+    [native code]
+}"
+PASS WebAssembly.Table.grow: name 
+PASS WebAssembly.Table.grow: length 
+FAIL WebAssembly.Table.get assert_equals: expected (undefined) undefined but got (function) function "function get() {
+    [native code]
+}"
+PASS WebAssembly.Table.get: name 
+PASS WebAssembly.Table.get: length 
+FAIL WebAssembly.Table.set assert_equals: expected (undefined) undefined but got (function) function "function set() {
+    [native code]
+}"
+PASS WebAssembly.Table.set: name 
+PASS WebAssembly.Table.set: length 
+PASS WebAssembly.Table.length 
+PASS WebAssembly.Table.length: getter 
+PASS WebAssembly.Table.length: setter 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.js
new file mode 100644 (file)
index 0000000..5d76ac5
--- /dev/null
@@ -0,0 +1,160 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/assertions.js
+
+function test_operations(object, object_name, operations) {
+  for (const [name, length] of operations) {
+    test(() => {
+      const propdesc = Object.getOwnPropertyDescriptor(object, name);
+      assert_equals(typeof propdesc, "object");
+      assert_true(propdesc.writable, "writable");
+      assert_true(propdesc.enumerable, "enumerable");
+      assert_true(propdesc.configurable, "configurable");
+      assert_equals(propdesc.value, WebAssembly[name]);
+    }, `${object_name}.${name}`);
+
+    test(() => {
+      assert_function_name(object[name], name, `${object_name}.${name}`);
+    }, `${object_name}.${name}: name`);
+
+    test(() => {
+      assert_function_length(object[name], length, `${object_name}.${name}`);
+    }, `${object_name}.${name}: length`);
+  }
+}
+
+function test_attributes(object, object_name, attributes) {
+  for (const [name, mutable] of attributes) {
+    test(() => {
+      const propdesc = Object.getOwnPropertyDescriptor(object, name);
+      assert_equals(typeof propdesc, "object");
+      assert_true(propdesc.enumerable, "enumerable");
+      assert_true(propdesc.configurable, "configurable");
+    }, `${object_name}.${name}`);
+
+    test(() => {
+      const propdesc = Object.getOwnPropertyDescriptor(object, name);
+      assert_equals(typeof propdesc, "object");
+      assert_equals(typeof propdesc.get, "function");
+      assert_function_name(propdesc.get, "get " + name, `getter for "${name}"`);
+      assert_function_length(propdesc.get, 0, `getter for "${name}"`);
+    }, `${object_name}.${name}: getter`);
+
+    test(() => {
+      const propdesc = Object.getOwnPropertyDescriptor(object, name);
+      assert_equals(typeof propdesc, "object");
+      if (mutable) {
+        assert_equals(typeof propdesc.set, "function");
+        assert_function_name(propdesc.set, "set " + name, `setter for "${name}"`);
+        assert_function_length(propdesc.set, 1, `setter for "${name}"`);
+      } else {
+        assert_equals(typeof propdesc.set, "undefined");
+      }
+    }, `${object_name}.${name}: setter`);
+  }
+}
+
+test(() => {
+  const propdesc = Object.getOwnPropertyDescriptor(this, "WebAssembly");
+  assert_equals(typeof propdesc, "object");
+  assert_true(propdesc.writable, "writable");
+  assert_false(propdesc.enumerable, "enumerable");
+  assert_true(propdesc.configurable, "configurable");
+  assert_equals(propdesc.value, this.WebAssembly);
+}, "WebAssembly: property descriptor");
+
+test(() => {
+  assert_throws(new TypeError(), () => WebAssembly());
+}, "WebAssembly: calling");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly());
+}, "WebAssembly: constructing");
+
+const interfaces = [
+  "Module",
+  "Instance",
+  "Memory",
+  "Table",
+  "Global",
+  "CompileError",
+  "LinkError",
+  "RuntimeError",
+];
+
+for (const name of interfaces) {
+  test(() => {
+    const propdesc = Object.getOwnPropertyDescriptor(WebAssembly, name);
+    assert_equals(typeof propdesc, "object");
+    assert_true(propdesc.writable, "writable");
+    assert_false(propdesc.enumerable, "enumerable");
+    assert_true(propdesc.configurable, "configurable");
+    assert_equals(propdesc.value, WebAssembly[name]);
+  }, `WebAssembly.${name}: property descriptor`);
+
+  test(() => {
+    const interface_object = WebAssembly[name];
+    const propdesc = Object.getOwnPropertyDescriptor(interface_object, "prototype");
+    assert_equals(typeof propdesc, "object");
+    assert_false(propdesc.writable, "writable");
+    assert_false(propdesc.enumerable, "enumerable");
+    assert_false(propdesc.configurable, "configurable");
+  }, `WebAssembly.${name}: prototype`);
+
+  test(() => {
+    const interface_object = WebAssembly[name];
+    const interface_prototype_object = interface_object.prototype;
+    const propdesc = Object.getOwnPropertyDescriptor(interface_prototype_object, "constructor");
+    assert_equals(typeof propdesc, "object");
+    assert_true(propdesc.writable, "writable");
+    assert_false(propdesc.enumerable, "enumerable");
+    assert_true(propdesc.configurable, "configurable");
+    assert_equals(propdesc.value, interface_object);
+  }, `WebAssembly.${name}: prototype.constructor`);
+}
+
+test_operations(WebAssembly, "WebAssembly", [
+  ["validate", 1],
+  ["compile", 1],
+  ["instantiate", 1],
+]);
+
+
+test_operations(WebAssembly.Module, "WebAssembly.Module", [
+  ["exports", 1],
+  ["imports", 1],
+  ["customSections", 2],
+]);
+
+
+test_attributes(WebAssembly.Instance.prototype, "WebAssembly.Instance", [
+  ["exports", false],
+]);
+
+
+test_operations(WebAssembly.Memory.prototype, "WebAssembly.Memory", [
+  ["grow", 1],
+]);
+
+test_attributes(WebAssembly.Memory.prototype, "WebAssembly.Memory", [
+  ["buffer", false],
+]);
+
+
+test_operations(WebAssembly.Table.prototype, "WebAssembly.Table", [
+  ["grow", 1],
+  ["get", 1],
+  ["set", 2],
+]);
+
+test_attributes(WebAssembly.Table.prototype, "WebAssembly.Table", [
+  ["length", false],
+]);
+
+
+test_operations(WebAssembly.Global.prototype, "WebAssembly.Global", [
+  ["valueOf", 0],
+]);
+
+test_attributes(WebAssembly.Global.prototype, "WebAssembly.Global", [
+  ["value", true],
+]);
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..9be5ab6
--- /dev/null
@@ -0,0 +1,86 @@
+CONSOLE MESSAGE: line 1774: TypeError: null is not an object (evaluating 'this.message_target.removeEventListener')
+CONSOLE MESSAGE: line 154: TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+Harness Error (FAIL), message = TypeError: undefined is not an object (evaluating 'WebAssembly.Global.prototype')
+
+PASS WebAssembly: property descriptor 
+PASS WebAssembly: calling 
+PASS WebAssembly: constructing 
+PASS WebAssembly.Module: property descriptor 
+PASS WebAssembly.Module: prototype 
+PASS WebAssembly.Module: prototype.constructor 
+PASS WebAssembly.Instance: property descriptor 
+PASS WebAssembly.Instance: prototype 
+PASS WebAssembly.Instance: prototype.constructor 
+PASS WebAssembly.Memory: property descriptor 
+PASS WebAssembly.Memory: prototype 
+PASS WebAssembly.Memory: prototype.constructor 
+PASS WebAssembly.Table: property descriptor 
+PASS WebAssembly.Table: prototype 
+PASS WebAssembly.Table: prototype.constructor 
+FAIL WebAssembly.Global: property descriptor assert_equals: expected "object" but got "undefined"
+FAIL WebAssembly.Global: prototype undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(interface_object, "prototype")')
+FAIL WebAssembly.Global: prototype.constructor undefined is not an object (evaluating 'interface_object.prototype')
+PASS WebAssembly.CompileError: property descriptor 
+PASS WebAssembly.CompileError: prototype 
+PASS WebAssembly.CompileError: prototype.constructor 
+PASS WebAssembly.LinkError: property descriptor 
+PASS WebAssembly.LinkError: prototype 
+PASS WebAssembly.LinkError: prototype.constructor 
+PASS WebAssembly.RuntimeError: property descriptor 
+PASS WebAssembly.RuntimeError: prototype 
+PASS WebAssembly.RuntimeError: prototype.constructor 
+PASS WebAssembly.validate 
+PASS WebAssembly.validate: name 
+PASS WebAssembly.validate: length 
+PASS WebAssembly.compile 
+PASS WebAssembly.compile: name 
+PASS WebAssembly.compile: length 
+PASS WebAssembly.instantiate 
+PASS WebAssembly.instantiate: name 
+PASS WebAssembly.instantiate: length 
+FAIL WebAssembly.Module.exports assert_equals: expected (undefined) undefined but got (function) function "function exports() {
+    [native code]
+}"
+PASS WebAssembly.Module.exports: name 
+PASS WebAssembly.Module.exports: length 
+FAIL WebAssembly.Module.imports assert_equals: expected (undefined) undefined but got (function) function "function imports() {
+    [native code]
+}"
+PASS WebAssembly.Module.imports: name 
+PASS WebAssembly.Module.imports: length 
+FAIL WebAssembly.Module.customSections assert_equals: expected (undefined) undefined but got (function) function "function customSections() {
+    [native code]
+}"
+PASS WebAssembly.Module.customSections: name 
+PASS WebAssembly.Module.customSections: length 
+PASS WebAssembly.Instance.exports 
+PASS WebAssembly.Instance.exports: getter 
+PASS WebAssembly.Instance.exports: setter 
+FAIL WebAssembly.Memory.grow assert_equals: expected (undefined) undefined but got (function) function "function grow() {
+    [native code]
+}"
+PASS WebAssembly.Memory.grow: name 
+PASS WebAssembly.Memory.grow: length 
+PASS WebAssembly.Memory.buffer 
+PASS WebAssembly.Memory.buffer: getter 
+PASS WebAssembly.Memory.buffer: setter 
+FAIL WebAssembly.Table.grow assert_equals: expected (undefined) undefined but got (function) function "function grow() {
+    [native code]
+}"
+PASS WebAssembly.Table.grow: name 
+PASS WebAssembly.Table.grow: length 
+FAIL WebAssembly.Table.get assert_equals: expected (undefined) undefined but got (function) function "function get() {
+    [native code]
+}"
+PASS WebAssembly.Table.get: name 
+PASS WebAssembly.Table.get: length 
+FAIL WebAssembly.Table.set assert_equals: expected (undefined) undefined but got (function) function "function set() {
+    [native code]
+}"
+PASS WebAssembly.Table.set: name 
+PASS WebAssembly.Table.set: length 
+PASS WebAssembly.Table.length 
+PASS WebAssembly.Table.length: getter 
+PASS WebAssembly.Table.length: setter 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any-expected.txt
new file mode 100644 (file)
index 0000000..670f281
--- /dev/null
@@ -0,0 +1,5 @@
+
+PASS Branding 
+PASS Setting (sloppy mode) 
+PASS Setting (strict mode) 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.js
new file mode 100644 (file)
index 0000000..b04460b
--- /dev/null
@@ -0,0 +1,50 @@
+// META: global=jsshell
+
+test(() => {
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Memory,
+    WebAssembly.Memory.prototype,
+  ];
+
+  const desc = Object.getOwnPropertyDescriptor(WebAssembly.Memory.prototype, "buffer");
+  assert_equals(typeof desc, "object");
+
+  const getter = desc.get;
+  assert_equals(typeof getter, "function");
+
+  assert_equals(typeof desc.set, "undefined");
+
+  for (const thisValue of thisValues) {
+    assert_throws(new TypeError(), () => getter.call(thisValue), `this=${format_value(thisValue)}`);
+  }
+}, "Branding");
+
+test(() => {
+  const argument = { "initial": 0 };
+  const memory = new WebAssembly.Memory(argument);
+  const memory2 = new WebAssembly.Memory(argument);
+  const buffer = memory.buffer;
+  assert_not_equals(buffer, memory2.buffer, "Need two distinct buffers");
+  memory.buffer = memory2.buffer;
+  assert_equals(memory.buffer, buffer, "Should not change the buffer");
+}, "Setting (sloppy mode)");
+
+test(() => {
+  const argument = { "initial": 0 };
+  const memory = new WebAssembly.Memory(argument);
+  const memory2 = new WebAssembly.Memory(argument);
+  const buffer = memory.buffer;
+  assert_not_equals(buffer, memory2.buffer, "Need two distinct buffers");
+  assert_throws(new TypeError(), () => {
+    "use strict";
+    memory.buffer = memory2.buffer;
+  });
+  assert_equals(memory.buffer, buffer, "Should not change the buffer");
+}, "Setting (strict mode)");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..670f281
--- /dev/null
@@ -0,0 +1,5 @@
+
+PASS Branding 
+PASS Setting (sloppy mode) 
+PASS Setting (strict mode) 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt
new file mode 100644 (file)
index 0000000..074a2e6
--- /dev/null
@@ -0,0 +1,24 @@
+
+PASS name 
+PASS length 
+PASS No arguments 
+PASS Calling 
+PASS Invalid descriptor argument 
+PASS Undefined initial value in descriptor 
+PASS Out-of-range initial value in descriptor: NaN 
+PASS Out-of-range maximum value in descriptor: NaN 
+PASS Out-of-range initial value in descriptor: Infinity 
+PASS Out-of-range maximum value in descriptor: Infinity 
+PASS Out-of-range initial value in descriptor: -Infinity 
+PASS Out-of-range maximum value in descriptor: -Infinity 
+PASS Out-of-range initial value in descriptor: -1 
+PASS Out-of-range maximum value in descriptor: -1 
+PASS Out-of-range initial value in descriptor: 4294967296 
+PASS Out-of-range maximum value in descriptor: 4294967296 
+PASS Out-of-range initial value in descriptor: 68719476736 
+PASS Out-of-range maximum value in descriptor: 68719476736 
+PASS Proxy descriptor 
+PASS Order of evaluation for descriptor 
+PASS Zero initial 
+PASS Non-zero initial 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.js
new file mode 100644 (file)
index 0000000..f9907ca
--- /dev/null
@@ -0,0 +1,137 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/assertions.js
+
+function assert_Memory(memory, expected) {
+  assert_equals(Object.getPrototypeOf(memory), WebAssembly.Memory.prototype,
+                "prototype");
+  assert_true(Object.isExtensible(memory), "extensible");
+
+  // https://github.com/WebAssembly/spec/issues/840
+  assert_equals(memory.buffer, memory.buffer, "buffer should be idempotent");
+  assert_equals(Object.getPrototypeOf(memory.buffer), ArrayBuffer.prototype,
+                "prototype of buffer");
+  assert_true(Object.isExtensible(memory.buffer), "buffer extensibility");
+  assert_equals(memory.buffer.byteLength, 0x10000 * expected.size, "size of buffer");
+  if (expected.size > 0) {
+    const array = new Uint8Array(memory.buffer);
+    assert_equals(array[0], 0, "first element of buffer");
+    assert_equals(array[array.byteLength - 1], 0, "last element of buffer");
+  }
+}
+
+test(() => {
+  assert_function_name(WebAssembly.Memory, "Memory", "WebAssembly.Memory");
+}, "name");
+
+test(() => {
+  assert_function_length(WebAssembly.Memory, 1, "WebAssembly.Memory");
+}, "length");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly.Memory());
+}, "No arguments");
+
+test(() => {
+  const argument = { "initial": 0 };
+  assert_throws(new TypeError(), () => WebAssembly.Memory(argument));
+}, "Calling");
+
+test(() => {
+  const invalidArguments = [
+    undefined,
+    null,
+    false,
+    true,
+    "",
+    "test",
+    Symbol(),
+    1,
+    NaN,
+    {},
+  ];
+  for (const invalidArgument of invalidArguments) {
+    assert_throws(new TypeError(),
+                  () => new WebAssembly.Memory(invalidArgument),
+                  `new Memory(${format_value(invalidArgument)})`);
+  }
+}, "Invalid descriptor argument");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly.Memory({ "initial": undefined }));
+}, "Undefined initial value in descriptor");
+
+const outOfRangeValues = [
+  NaN,
+  Infinity,
+  -Infinity,
+  -1,
+  0x100000000,
+  0x1000000000,
+];
+
+for (const value of outOfRangeValues) {
+  test(() => {
+    assert_throws(new TypeError(), () => new WebAssembly.Memory({ "initial": value }));
+  }, `Out-of-range initial value in descriptor: ${format_value(value)}`);
+
+  test(() => {
+    assert_throws(new TypeError(), () => new WebAssembly.Memory({ "initial": 0, "maximum": value }));
+  }, `Out-of-range maximum value in descriptor: ${format_value(value)}`);
+}
+
+test(() => {
+  const proxy = new Proxy({}, {
+    has(o, x) {
+      assert_unreached(`Should not call [[HasProperty]] with ${x}`);
+    },
+    get(o, x) {
+      return 0;
+    },
+  });
+  new WebAssembly.Memory(proxy);
+}, "Proxy descriptor");
+
+test(() => {
+  const order = [];
+
+  new WebAssembly.Memory({
+    get maximum() {
+      order.push("maximum");
+      return {
+        valueOf() {
+          order.push("maximum valueOf");
+          return 1;
+        },
+      };
+    },
+
+    get initial() {
+      order.push("initial");
+      return {
+        valueOf() {
+          order.push("initial valueOf");
+          return 1;
+        },
+      };
+    },
+  });
+
+  assert_array_equals(order, [
+    "initial",
+    "initial valueOf",
+    "maximum",
+    "maximum valueOf",
+  ]);
+}, "Order of evaluation for descriptor");
+
+test(() => {
+  const argument = { "initial": 0 };
+  const memory = new WebAssembly.Memory(argument);
+  assert_Memory(memory, { "size": 0 });
+}, "Zero initial");
+
+test(() => {
+  const argument = { "initial": 4 };
+  const memory = new WebAssembly.Memory(argument);
+  assert_Memory(memory, { "size": 4 });
+}, "Non-zero initial");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..074a2e6
--- /dev/null
@@ -0,0 +1,24 @@
+
+PASS name 
+PASS length 
+PASS No arguments 
+PASS Calling 
+PASS Invalid descriptor argument 
+PASS Undefined initial value in descriptor 
+PASS Out-of-range initial value in descriptor: NaN 
+PASS Out-of-range maximum value in descriptor: NaN 
+PASS Out-of-range initial value in descriptor: Infinity 
+PASS Out-of-range maximum value in descriptor: Infinity 
+PASS Out-of-range initial value in descriptor: -Infinity 
+PASS Out-of-range maximum value in descriptor: -Infinity 
+PASS Out-of-range initial value in descriptor: -1 
+PASS Out-of-range maximum value in descriptor: -1 
+PASS Out-of-range initial value in descriptor: 4294967296 
+PASS Out-of-range maximum value in descriptor: 4294967296 
+PASS Out-of-range initial value in descriptor: 68719476736 
+PASS Out-of-range maximum value in descriptor: 68719476736 
+PASS Proxy descriptor 
+PASS Order of evaluation for descriptor 
+PASS Zero initial 
+PASS Non-zero initial 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt
new file mode 100644 (file)
index 0000000..33489b6
--- /dev/null
@@ -0,0 +1,19 @@
+
+PASS Missing arguments 
+PASS Branding 
+PASS Zero initial 
+PASS Zero initial with valueOf 
+PASS Non-zero initial 
+PASS Zero initial with respected maximum 
+PASS Zero initial with respected maximum grown twice 
+PASS Zero initial growing too much 
+PASS Out-of-range argument: undefined 
+PASS Out-of-range argument: NaN 
+PASS Out-of-range argument: Infinity 
+PASS Out-of-range argument: -Infinity 
+PASS Out-of-range argument: -1 
+PASS Out-of-range argument: 4294967296 
+PASS Out-of-range argument: 68719476736 
+PASS Out-of-range argument: "0x100000000" 
+PASS Out-of-range argument: object "[object Object]" 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.js
new file mode 100644 (file)
index 0000000..9530039
--- /dev/null
@@ -0,0 +1,170 @@
+// META: global=jsshell
+
+function assert_ArrayBuffer(actual, expected, message) {
+  // https://github.com/WebAssembly/spec/issues/840
+  assert_equals(Object.getPrototypeOf(actual), ArrayBuffer.prototype,
+                `${message}: prototype`);
+  if (expected.detached) {
+    // https://github.com/tc39/ecma262/issues/678
+    let byteLength;
+    try {
+      byteLength = actual.byteLength;
+    } catch (e) {
+      byteLength = 0;
+    }
+    assert_equals(byteLength, 0, `${message}: detached size`);
+  } else {
+    assert_equals(actual.byteLength, 0x10000 * expected.size, `${message}: size`);
+    if (expected.size > 0) {
+      const array = new Uint8Array(actual);
+      assert_equals(array[0], 0, `${message}: first element`);
+      assert_equals(array[array.byteLength - 1], 0, `${message}: last element`);
+    }
+  }
+}
+
+test(() => {
+  const argument = { "initial": 0 };
+  const memory = new WebAssembly.Memory(argument);
+  assert_throws(new TypeError(), () => memory.grow());
+}, "Missing arguments");
+
+test(t => {
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Memory,
+    WebAssembly.Memory.prototype,
+  ];
+
+  const argument = {
+    valueOf: t.unreached_func("Should not touch the argument (valueOf)"),
+    toString: t.unreached_func("Should not touch the argument (toString)"),
+  };
+
+  const fn = WebAssembly.Memory.prototype.grow;
+
+  for (const thisValue of thisValues) {
+    assert_throws(new TypeError(), () => fn.call(thisValue, argument), `this=${format_value(thisValue)}`);
+  }
+}, "Branding");
+
+test(() => {
+  const argument = { "initial": 0 };
+  const memory = new WebAssembly.Memory(argument);
+  const oldMemory = memory.buffer;
+  assert_ArrayBuffer(oldMemory, { "size": 0 }, "Buffer before growing");
+
+  const result = memory.grow(2);
+  assert_equals(result, 0);
+
+  const newMemory = memory.buffer;
+  assert_not_equals(oldMemory, newMemory);
+  assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");
+  assert_ArrayBuffer(newMemory, { "size": 2 }, "New buffer after growing");
+}, "Zero initial");
+
+test(() => {
+  const argument = { "initial": { valueOf() { return 0 } } };
+  const memory = new WebAssembly.Memory(argument);
+  const oldMemory = memory.buffer;
+  assert_ArrayBuffer(oldMemory, { "size": 0 }, "Buffer before growing");
+
+  const result = memory.grow({ valueOf() { return 2 } });
+  assert_equals(result, 0);
+
+  const newMemory = memory.buffer;
+  assert_not_equals(oldMemory, newMemory);
+  assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");
+  assert_ArrayBuffer(newMemory, { "size": 2 }, "New buffer after growing");
+}, "Zero initial with valueOf");
+
+test(() => {
+  const argument = { "initial": 3 };
+  const memory = new WebAssembly.Memory(argument);
+  const oldMemory = memory.buffer;
+  assert_ArrayBuffer(oldMemory, { "size": 3 }, "Buffer before growing");
+
+  const result = memory.grow(2);
+  assert_equals(result, 3);
+
+  const newMemory = memory.buffer;
+  assert_not_equals(oldMemory, newMemory);
+  assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");
+  assert_ArrayBuffer(newMemory, { "size": 5 }, "New buffer after growing");
+}, "Non-zero initial");
+
+test(() => {
+  const argument = { "initial": 0, "maximum": 2 };
+  const memory = new WebAssembly.Memory(argument);
+  const oldMemory = memory.buffer;
+  assert_ArrayBuffer(oldMemory, { "size": 0 }, "Buffer before growing");
+
+  const result = memory.grow(2);
+  assert_equals(result, 0);
+
+  const newMemory = memory.buffer;
+  assert_not_equals(oldMemory, newMemory);
+  assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");
+  assert_ArrayBuffer(newMemory, { "size": 2 }, "New buffer after growing");
+}, "Zero initial with respected maximum");
+
+test(() => {
+  const argument = { "initial": 0, "maximum": 2 };
+  const memory = new WebAssembly.Memory(argument);
+  const oldMemory = memory.buffer;
+  assert_ArrayBuffer(oldMemory, { "size": 0 }, "Buffer before growing");
+
+  const result = memory.grow(1);
+  assert_equals(result, 0);
+
+  const newMemory = memory.buffer;
+  assert_not_equals(oldMemory, newMemory);
+  assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing once");
+  assert_ArrayBuffer(newMemory, { "size": 1 }, "New buffer after growing once");
+
+  const result2 = memory.grow(1);
+  assert_equals(result2, 1);
+
+  const newestMemory = memory.buffer;
+  assert_not_equals(newMemory, newestMemory);
+  assert_ArrayBuffer(oldMemory, { "detached": true }, "New buffer after growing twice");
+  assert_ArrayBuffer(newMemory, { "detached": true }, "New buffer after growing twice");
+  assert_ArrayBuffer(newestMemory, { "size": 2 }, "Newest buffer after growing twice");
+}, "Zero initial with respected maximum grown twice");
+
+test(() => {
+  const argument = { "initial": 1, "maximum": 2 };
+  const memory = new WebAssembly.Memory(argument);
+  const oldMemory = memory.buffer;
+  assert_ArrayBuffer(oldMemory, { "size": 1 }, "Buffer before growing");
+
+  assert_throws(new RangeError(), () => memory.grow(2));
+  assert_equals(memory.buffer, oldMemory);
+  assert_ArrayBuffer(memory.buffer, { "size": 1 }, "Buffer before trying to grow");
+}, "Zero initial growing too much");
+
+const outOfRangeValues = [
+  undefined,
+  NaN,
+  Infinity,
+  -Infinity,
+  -1,
+  0x100000000,
+  0x1000000000,
+  "0x100000000",
+  { valueOf() { return 0x100000000; } },
+];
+
+for (const value of outOfRangeValues) {
+  test(() => {
+    const argument = { "initial": 0 };
+    const memory = new WebAssembly.Memory(argument);
+    assert_throws(new TypeError(), () => memory.grow(value));
+  }, `Out-of-range argument: ${format_value(value)}`);
+}
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..33489b6
--- /dev/null
@@ -0,0 +1,19 @@
+
+PASS Missing arguments 
+PASS Branding 
+PASS Zero initial 
+PASS Zero initial with valueOf 
+PASS Non-zero initial 
+PASS Zero initial with respected maximum 
+PASS Zero initial with respected maximum grown twice 
+PASS Zero initial growing too much 
+PASS Out-of-range argument: undefined 
+PASS Out-of-range argument: NaN 
+PASS Out-of-range argument: Infinity 
+PASS Out-of-range argument: -Infinity 
+PASS Out-of-range argument: -1 
+PASS Out-of-range argument: 4294967296 
+PASS Out-of-range argument: 68719476736 
+PASS Out-of-range argument: "0x100000000" 
+PASS Out-of-range argument: object "[object Object]" 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any-expected.txt
new file mode 100644 (file)
index 0000000..65e4440
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Object.prototype.toString on an Memory 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.js
new file mode 100644 (file)
index 0000000..4e15d75
--- /dev/null
@@ -0,0 +1,7 @@
+// META: global=jsshell
+
+test(() => {
+  const argument = { "initial": 0 };
+  const memory = new WebAssembly.Memory(argument);
+  assert_class_string(memory, "WebAssembly.Memory");
+}, "Object.prototype.toString on an Memory");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..65e4440
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Object.prototype.toString on an Memory 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/w3c-import.log b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/w3c-import.log
new file mode 100644 (file)
index 0000000..006643b
--- /dev/null
@@ -0,0 +1,20 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+       https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/buffer.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/toString.any.js
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any-expected.txt
new file mode 100644 (file)
index 0000000..6d12237
--- /dev/null
@@ -0,0 +1,10 @@
+
+PASS name 
+PASS length 
+PASS No arguments 
+PASS Calling 
+PASS Invalid arguments 
+PASS Empty buffer 
+PASS Prototype 
+PASS Extensibility 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.js
new file mode 100644 (file)
index 0000000..32f183f
--- /dev/null
@@ -0,0 +1,60 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+// META: script=/wasm/jsapi/assertions.js
+
+let emptyModuleBinary;
+setup(() => {
+  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+});
+
+test(() => {
+  assert_function_name(WebAssembly.Module, "Module", "WebAssembly.Module");
+}, "name");
+
+test(() => {
+  assert_function_length(WebAssembly.Module, 1, "WebAssembly.Module");
+}, "length");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly.Module());
+}, "No arguments");
+
+test(() => {
+  assert_throws(new TypeError(), () => WebAssembly.Module(emptyModuleBinary));
+}, "Calling");
+
+test(() => {
+  const invalidArguments = [
+    undefined,
+    null,
+    true,
+    "test",
+    Symbol(),
+    7,
+    NaN,
+    {},
+    ArrayBuffer,
+    ArrayBuffer.prototype,
+    Array.from(emptyModuleBinary),
+  ];
+  for (const argument of invalidArguments) {
+    assert_throws(new TypeError(), () => new WebAssembly.Module(argument),
+                  `new Module(${format_value(argument)})`);
+  }
+}, "Invalid arguments");
+
+test(() => {
+  const buffer = new Uint8Array();
+  assert_throws(new WebAssembly.CompileError(), () => new WebAssembly.Module(buffer));
+}, "Empty buffer");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  assert_equals(Object.getPrototypeOf(module), WebAssembly.Module.prototype);
+}, "Prototype");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  assert_true(Object.isExtensible(module));
+}, "Extensibility");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..6d12237
--- /dev/null
@@ -0,0 +1,10 @@
+
+PASS name 
+PASS length 
+PASS No arguments 
+PASS Calling 
+PASS Invalid arguments 
+PASS Empty buffer 
+PASS Prototype 
+PASS Extensibility 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any-expected.txt
new file mode 100644 (file)
index 0000000..4c8d91e
--- /dev/null
@@ -0,0 +1,10 @@
+
+PASS Missing arguments 
+PASS Non-Module arguments 
+PASS Branding 
+PASS Empty module 
+PASS Empty module: array caching 
+PASS Custom sections 
+PASS Custom sections with surrogate pairs 
+FAIL Custom sections with U+FFFD assert_equals: expected 1 but got 0
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.js
new file mode 100644 (file)
index 0000000..58ac63b
--- /dev/null
@@ -0,0 +1,162 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+
+function assert_ArrayBuffer(buffer, expected) {
+  assert_equals(Object.getPrototypeOf(buffer), ArrayBuffer.prototype, "Prototype");
+  assert_true(Object.isExtensible(buffer), "isExtensible");
+  assert_array_equals(new Uint8Array(buffer), expected);
+}
+
+function assert_sections(sections, expected) {
+  assert_true(Array.isArray(sections), "Should be array");
+  assert_equals(Object.getPrototypeOf(sections), Array.prototype, "Prototype");
+  assert_true(Object.isExtensible(sections), "isExtensible");
+
+  assert_equals(sections.length, expected.length);
+  for (let i = 0; i < expected.length; ++i) {
+    assert_ArrayBuffer(sections[i], expected[i]);
+  }
+}
+
+let emptyModuleBinary;
+setup(() => {
+  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+});
+
+test(() => {
+  assert_throws(new TypeError(), () => WebAssembly.Module.customSections());
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  assert_throws(new TypeError(), () => WebAssembly.Module.customSections(module));
+}, "Missing arguments");
+
+test(() => {
+  const invalidArguments = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Module,
+    WebAssembly.Module.prototype,
+  ];
+  for (const argument of invalidArguments) {
+    assert_throws(new TypeError(), () => WebAssembly.Module.customSections(argument, ""),
+                  `customSections(${format_value(argument)})`);
+  }
+}, "Non-Module arguments");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const fn = WebAssembly.Module.customSections;
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Module,
+    WebAssembly.Module.prototype,
+  ];
+  for (const thisValue of thisValues) {
+    assert_sections(fn.call(thisValue, module, ""), []);
+  }
+}, "Branding");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  assert_sections(WebAssembly.Module.customSections(module, ""), []);
+}, "Empty module");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  assert_not_equals(WebAssembly.Module.customSections(module, ""),
+                    WebAssembly.Module.customSections(module, ""));
+}, "Empty module: array caching");
+
+test(() => {
+  const bytes1 = [87, 101, 98, 65, 115, 115, 101, 109, 98, 108, 121];
+  const bytes2 = [74, 83, 65, 80, 73];
+
+  const binary = new Binary;
+  binary.emit_section(kUnknownSectionCode, section => {
+    section.emit_string("name");
+    section.emit_bytes(bytes1);
+  });
+  binary.emit_section(kUnknownSectionCode, section => {
+    section.emit_string("name");
+    section.emit_bytes(bytes2);
+  });
+  binary.emit_section(kUnknownSectionCode, section => {
+    section.emit_string("foo");
+    section.emit_bytes(bytes1);
+  });
+
+  const builder = new WasmModuleBuilder();
+  builder.addExplicitSection(binary);
+  const buffer = builder.toBuffer()
+  const module = new WebAssembly.Module(buffer);
+
+  assert_sections(WebAssembly.Module.customSections(module, "name"), [
+    bytes1,
+    bytes2,
+  ])
+
+  assert_sections(WebAssembly.Module.customSections(module, "foo"), [
+    bytes1,
+  ])
+
+  assert_sections(WebAssembly.Module.customSections(module, ""), [])
+  assert_sections(WebAssembly.Module.customSections(module, "\0"), [])
+  assert_sections(WebAssembly.Module.customSections(module, "name\0"), [])
+  assert_sections(WebAssembly.Module.customSections(module, "foo\0"), [])
+}, "Custom sections");
+
+test(() => {
+  const bytes = [87, 101, 98, 65, 115, 115, 101, 109, 98, 108, 121];
+  const name = "yee\uD801\uDC37eey"
+
+  const binary = new Binary;
+  binary.emit_section(kUnknownSectionCode, section => {
+    section.emit_string(name);
+    section.emit_bytes(bytes);
+  });
+
+  const builder = new WasmModuleBuilder();
+  builder.addExplicitSection(binary);
+  const buffer = builder.toBuffer();
+  const module = new WebAssembly.Module(buffer);
+
+  assert_sections(WebAssembly.Module.customSections(module, name), [
+    bytes,
+  ]);
+  assert_sections(WebAssembly.Module.customSections(module, "yee\uFFFDeey"), []);
+  assert_sections(WebAssembly.Module.customSections(module, "yee\uFFFD\uFFFDeey"), []);
+}, "Custom sections with surrogate pairs");
+
+test(() => {
+  const bytes = [87, 101, 98, 65, 115, 115, 101, 109, 98, 108, 121];
+
+  const binary = new Binary;
+  binary.emit_section(kUnknownSectionCode, section => {
+    section.emit_string("na\uFFFDme");
+    section.emit_bytes(bytes);
+  });
+
+  const builder = new WasmModuleBuilder();
+  builder.addExplicitSection(binary);
+  const buffer = builder.toBuffer();
+  const module = new WebAssembly.Module(buffer);
+
+  assert_sections(WebAssembly.Module.customSections(module, "name"), []);
+  assert_sections(WebAssembly.Module.customSections(module, "na\uFFFDme"), [
+    bytes,
+  ]);
+  assert_sections(WebAssembly.Module.customSections(module, "na\uDC01me"), [
+    bytes,
+  ]);
+}, "Custom sections with U+FFFD");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..4c8d91e
--- /dev/null
@@ -0,0 +1,10 @@
+
+PASS Missing arguments 
+PASS Non-Module arguments 
+PASS Branding 
+PASS Empty module 
+PASS Empty module: array caching 
+PASS Custom sections 
+PASS Custom sections with surrogate pairs 
+FAIL Custom sections with U+FFFD assert_equals: expected 1 but got 0
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any-expected.txt
new file mode 100644 (file)
index 0000000..da4156c
--- /dev/null
@@ -0,0 +1,8 @@
+
+PASS Missing arguments 
+PASS Non-Module arguments 
+PASS Branding 
+PASS Empty module 
+PASS Empty module: array caching 
+FAIL exports WebAssembly.Module doesn't parse at byte 87: 3th Export isn't immutable, named 'global' (evaluating 'new WebAssembly.Module(buffer)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.js
new file mode 100644 (file)
index 0000000..e63a885
--- /dev/null
@@ -0,0 +1,130 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+
+let emptyModuleBinary;
+setup(() => {
+  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+});
+
+function assert_ModuleExportDescriptor(export_, expected) {
+  assert_equals(Object.getPrototypeOf(export_), Object.prototype, "Prototype");
+  assert_true(Object.isExtensible(export_), "isExtensible");
+
+  const name = Object.getOwnPropertyDescriptor(export_, "name");
+  assert_true(name.writable, "name: writable");
+  assert_true(name.enumerable, "name: enumerable");
+  assert_true(name.configurable, "name: configurable");
+  assert_equals(name.value, expected.name);
+
+  const kind = Object.getOwnPropertyDescriptor(export_, "kind");
+  assert_true(kind.writable, "kind: writable");
+  assert_true(kind.enumerable, "kind: enumerable");
+  assert_true(kind.configurable, "kind: configurable");
+  assert_equals(kind.value, expected.kind);
+}
+
+function assert_exports(exports, expected) {
+  assert_true(Array.isArray(exports), "Should be array");
+  assert_equals(Object.getPrototypeOf(exports), Array.prototype, "Prototype");
+  assert_true(Object.isExtensible(exports), "isExtensible");
+
+  assert_equals(exports.length, expected.length);
+  for (let i = 0; i < expected.length; ++i) {
+    assert_ModuleExportDescriptor(exports[i], expected[i]);
+  }
+}
+
+test(() => {
+  assert_throws(new TypeError(), () => WebAssembly.Module.exports());
+}, "Missing arguments");
+
+test(() => {
+  const invalidArguments = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Module,
+    WebAssembly.Module.prototype,
+  ];
+  for (const argument of invalidArguments) {
+    assert_throws(new TypeError(), () => WebAssembly.Module.exports(argument),
+                  `exports(${format_value(argument)})`);
+  }
+}, "Non-Module arguments");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const fn = WebAssembly.Module.exports;
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Module,
+    WebAssembly.Module.prototype,
+  ];
+  for (const thisValue of thisValues) {
+    assert_array_equals(fn.call(thisValue, module), []);
+  }
+}, "Branding");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const exports = WebAssembly.Module.exports(module);
+  assert_exports(exports, []);
+}, "Empty module");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  assert_not_equals(WebAssembly.Module.exports(module), WebAssembly.Module.exports(module));
+}, "Empty module: array caching");
+
+test(() => {
+  const builder = new WasmModuleBuilder();
+
+  builder
+    .addFunction("fn", kSig_v_v)
+    .addBody([
+        kExprEnd
+    ])
+    .exportFunc();
+  builder
+    .addFunction("fn2", kSig_v_v)
+    .addBody([
+        kExprEnd
+    ])
+    .exportFunc();
+
+  builder.setFunctionTableLength(1);
+  builder.addExportOfKind("table", kExternalTable, 0);
+
+  builder.addGlobal(kWasmI32, true)
+    .exportAs("global")
+    .init = 7;
+  builder.addGlobal(kWasmF64, true)
+    .exportAs("global2")
+    .init = 1.2;
+
+  builder.addMemory(0, 256, true);
+
+  const buffer = builder.toBuffer()
+  const module = new WebAssembly.Module(buffer);
+  const exports = WebAssembly.Module.exports(module);
+  const expected = [
+    { "kind": "function", "name": "fn" },
+    { "kind": "function", "name": "fn2" },
+    { "kind": "table", "name": "table" },
+    { "kind": "global", "name": "global" },
+    { "kind": "global", "name": "global2" },
+    { "kind": "memory", "name": "memory" },
+  ];
+  assert_exports(exports, expected);
+}, "exports");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..da4156c
--- /dev/null
@@ -0,0 +1,8 @@
+
+PASS Missing arguments 
+PASS Non-Module arguments 
+PASS Branding 
+PASS Empty module 
+PASS Empty module: array caching 
+FAIL exports WebAssembly.Module doesn't parse at byte 87: 3th Export isn't immutable, named 'global' (evaluating 'new WebAssembly.Module(buffer)')
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any-expected.txt
new file mode 100644 (file)
index 0000000..4723e63
--- /dev/null
@@ -0,0 +1,9 @@
+
+PASS Missing arguments 
+PASS Non-Module arguments 
+PASS Branding 
+PASS Return type 
+PASS Empty module 
+PASS Empty module: array caching 
+PASS imports 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.js
new file mode 100644 (file)
index 0000000..640da59
--- /dev/null
@@ -0,0 +1,120 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+
+function assert_ModuleImportDescriptor(import_, expected) {
+  assert_equals(Object.getPrototypeOf(import_), Object.prototype, "Prototype");
+  assert_true(Object.isExtensible(import_), "isExtensible");
+
+  const module = Object.getOwnPropertyDescriptor(import_, "module");
+  assert_true(module.writable, "module: writable");
+  assert_true(module.enumerable, "module: enumerable");
+  assert_true(module.configurable, "module: configurable");
+  assert_equals(module.value, expected.module);
+
+  const name = Object.getOwnPropertyDescriptor(import_, "name");
+  assert_true(name.writable, "name: writable");
+  assert_true(name.enumerable, "name: enumerable");
+  assert_true(name.configurable, "name: configurable");
+  assert_equals(name.value, expected.name);
+
+  const kind = Object.getOwnPropertyDescriptor(import_, "kind");
+  assert_true(kind.writable, "kind: writable");
+  assert_true(kind.enumerable, "kind: enumerable");
+  assert_true(kind.configurable, "kind: configurable");
+  assert_equals(kind.value, expected.kind);
+}
+
+function assert_imports(imports, expected) {
+  assert_true(Array.isArray(imports), "Should be array");
+  assert_equals(Object.getPrototypeOf(imports), Array.prototype, "Prototype");
+  assert_true(Object.isExtensible(imports), "isExtensible");
+
+  assert_equals(imports.length, expected.length);
+  for (let i = 0; i < expected.length; ++i) {
+    assert_ModuleImportDescriptor(imports[i], expected[i]);
+  }
+}
+
+let emptyModuleBinary;
+setup(() => {
+  emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+});
+
+test(() => {
+  assert_throws(new TypeError(), () => WebAssembly.Module.imports());
+}, "Missing arguments");
+
+test(() => {
+  const invalidArguments = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Module,
+    WebAssembly.Module.prototype,
+  ];
+  for (const argument of invalidArguments) {
+    assert_throws(new TypeError(), () => WebAssembly.Module.imports(argument),
+                  `imports(${format_value(argument)})`);
+  }
+}, "Non-Module arguments");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const fn = WebAssembly.Module.imports;
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Module,
+    WebAssembly.Module.prototype,
+  ];
+  for (const thisValue of thisValues) {
+    assert_array_equals(fn.call(thisValue, module), []);
+  }
+}, "Branding");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const imports = WebAssembly.Module.imports(module);
+  assert_true(Array.isArray(imports));
+}, "Return type");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  const imports = WebAssembly.Module.imports(module);
+  assert_imports(imports, []);
+}, "Empty module");
+
+test(() => {
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  assert_not_equals(WebAssembly.Module.imports(module), WebAssembly.Module.imports(module));
+}, "Empty module: array caching");
+
+test(() => {
+  const builder = new WasmModuleBuilder();
+
+  builder.addImport("module", "fn", kSig_v_v);
+  builder.addImportedGlobal("module", "global", kWasmI32);
+  builder.addImportedMemory("module", "memory", 0, 128);
+  builder.addImportedTable("module", "table", 0, 128);
+
+  const buffer = builder.toBuffer()
+  const module = new WebAssembly.Module(buffer);
+  const imports = WebAssembly.Module.imports(module);
+  const expected = [
+    { "module": "module", "kind": "function", "name": "fn" },
+    { "module": "module", "kind": "global", "name": "global" },
+    { "module": "module", "kind": "memory", "name": "memory" },
+    { "module": "module", "kind": "table", "name": "table" },
+  ];
+  assert_imports(imports, expected);
+}, "imports");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..4723e63
--- /dev/null
@@ -0,0 +1,9 @@
+
+PASS Missing arguments 
+PASS Non-Module arguments 
+PASS Branding 
+PASS Return type 
+PASS Empty module 
+PASS Empty module: array caching 
+PASS imports 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any-expected.txt
new file mode 100644 (file)
index 0000000..b13e61e
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Object.prototype.toString on an Module 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.js
new file mode 100644 (file)
index 0000000..d9231a1
--- /dev/null
@@ -0,0 +1,9 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+
+test(() => {
+  const emptyModuleBinary = new WasmModuleBuilder().toBuffer();
+  const module = new WebAssembly.Module(emptyModuleBinary);
+  assert_class_string(module, "WebAssembly.Module");
+}, "Object.prototype.toString on an Module");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..b13e61e
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Object.prototype.toString on an Module 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/w3c-import.log b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/w3c-import.log
new file mode 100644 (file)
index 0000000..e66a985
--- /dev/null
@@ -0,0 +1,21 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+       https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/constructor.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/customSections.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/exports.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/imports.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/module/toString.any.js
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/assertions.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/assertions.js
new file mode 100644 (file)
index 0000000..dde2fd7
--- /dev/null
@@ -0,0 +1,11 @@
+function assert_equal_to_array(table, expected, message) {
+  assert_equals(table.length, expected.length, `${message}: length`);
+  assert_throws(new RangeError(), () => table.get(-1), `${message}: table.get(-1)`);
+  for (let i = 0; i < expected.length; ++i) {
+    assert_equals(table.get(i), expected[i], `${message}: table.get(${i} of ${expected.length})`);
+  }
+  assert_throws(new RangeError(), () => table.get(expected.length),
+                `${message}: table.get(${expected.length} of ${expected.length})`);
+  assert_throws(new RangeError(), () => table.get(expected.length + 1),
+                `${message}: table.get(${expected.length + 1} of ${expected.length})`);
+}
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any-expected.txt
new file mode 100644 (file)
index 0000000..a312505
--- /dev/null
@@ -0,0 +1,28 @@
+
+PASS name 
+PASS length 
+PASS No arguments 
+PASS Calling 
+PASS Empty descriptor 
+PASS Invalid descriptor argument 
+PASS Undefined initial value in descriptor 
+PASS Undefined element value in descriptor 
+PASS Out-of-range initial value in descriptor: NaN 
+PASS Out-of-range maximum value in descriptor: NaN 
+PASS Out-of-range initial value in descriptor: Infinity 
+PASS Out-of-range maximum value in descriptor: Infinity 
+PASS Out-of-range initial value in descriptor: -Infinity 
+PASS Out-of-range maximum value in descriptor: -Infinity 
+PASS Out-of-range initial value in descriptor: -1 
+PASS Out-of-range maximum value in descriptor: -1 
+PASS Out-of-range initial value in descriptor: 4294967296 
+PASS Out-of-range maximum value in descriptor: 4294967296 
+PASS Out-of-range initial value in descriptor: 68719476736 
+PASS Out-of-range maximum value in descriptor: 68719476736 
+PASS Initial value exceeds maximum 
+PASS Basic (zero) 
+PASS Basic (non-zero) 
+PASS Proxy descriptor 
+PASS Type conversion for descriptor.element 
+PASS Order of evaluation for descriptor 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.js
new file mode 100644 (file)
index 0000000..e924bdb
--- /dev/null
@@ -0,0 +1,173 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/assertions.js
+
+function assert_Table(actual, expected) {
+  assert_equals(Object.getPrototypeOf(actual), WebAssembly.Table.prototype,
+                "prototype");
+  assert_true(Object.isExtensible(actual), "extensible");
+
+  assert_equals(actual.length, expected.length, "length");
+  for (let i = 0; i < expected.length; ++i) {
+    assert_equals(actual.get(i), null, `actual.get(${i})`);
+  }
+}
+
+test(() => {
+  assert_function_name(WebAssembly.Table, "Table", "WebAssembly.Table");
+}, "name");
+
+test(() => {
+  assert_function_length(WebAssembly.Table, 1, "WebAssembly.Table");
+}, "length");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly.Table());
+}, "No arguments");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 0 };
+  assert_throws(new TypeError(), () => WebAssembly.Table(argument));
+}, "Calling");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly.Table({}));
+}, "Empty descriptor");
+
+test(() => {
+  const invalidArguments = [
+    undefined,
+    null,
+    false,
+    true,
+    "",
+    "test",
+    Symbol(),
+    1,
+    NaN,
+    {},
+  ];
+  for (const invalidArgument of invalidArguments) {
+    assert_throws(new TypeError(),
+                  () => new WebAssembly.Table(invalidArgument),
+                  `new Table(${format_value(invalidArgument)})`);
+  }
+}, "Invalid descriptor argument");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly.Table({ "element": "anyfunc", "initial": undefined }));
+}, "Undefined initial value in descriptor");
+
+test(() => {
+  assert_throws(new TypeError(), () => new WebAssembly.Table({ "element": undefined, "initial": 0 }));
+}, "Undefined element value in descriptor");
+
+const outOfRangeValues = [
+  NaN,
+  Infinity,
+  -Infinity,
+  -1,
+  0x100000000,
+  0x1000000000,
+];
+
+for (const value of outOfRangeValues) {
+  test(() => {
+    assert_throws(new TypeError(), () => new WebAssembly.Table({ "element": "anyfunc", "initial": value }));
+  }, `Out-of-range initial value in descriptor: ${format_value(value)}`);
+
+  test(() => {
+    assert_throws(new TypeError(), () => new WebAssembly.Table({ "element": "anyfunc", "initial": 0, "maximum": value }));
+  }, `Out-of-range maximum value in descriptor: ${format_value(value)}`);
+}
+
+test(() => {
+  assert_throws(new RangeError(), () => new WebAssembly.Table({ "element": "anyfunc", "initial": 10, "maximum": 9 }));
+}, "Initial value exceeds maximum");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 0 };
+  const table = new WebAssembly.Table(argument);
+  assert_Table(table, { "length": 0 });
+}, "Basic (zero)");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_Table(table, { "length": 5 });
+}, "Basic (non-zero)");
+
+test(() => {
+  const proxy = new Proxy({}, {
+    has(o, x) {
+      assert_unreached(`Should not call [[HasProperty]] with ${x}`);
+    },
+    get(o, x) {
+      switch (x) {
+      case "element":
+        return "anyfunc";
+      case "initial":
+      case "maximum":
+        return 0;
+      default:
+        return undefined;
+      }
+    },
+  });
+  const table = new WebAssembly.Table(proxy);
+  assert_Table(table, { "length": 0 });
+}, "Proxy descriptor");
+
+test(() => {
+  const table = new WebAssembly.Table({
+    "element": {
+      toString() { return "anyfunc"; },
+    },
+    "initial": 1,
+  });
+  assert_Table(table, { "length": 1 });
+}, "Type conversion for descriptor.element");
+
+test(() => {
+  const order = [];
+
+  new WebAssembly.Table({
+    get maximum() {
+      order.push("maximum");
+      return {
+        valueOf() {
+          order.push("maximum valueOf");
+          return 1;
+        },
+      };
+    },
+
+    get initial() {
+      order.push("initial");
+      return {
+        valueOf() {
+          order.push("initial valueOf");
+          return 1;
+        },
+      };
+    },
+
+    get element() {
+      order.push("element");
+      return {
+        toString() {
+          order.push("element toString");
+          return "anyfunc";
+        },
+      };
+    },
+  });
+
+  assert_array_equals(order, [
+    "element",
+    "element toString",
+    "initial",
+    "initial valueOf",
+    "maximum",
+    "maximum valueOf",
+  ]);
+}, "Order of evaluation for descriptor");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..a312505
--- /dev/null
@@ -0,0 +1,28 @@
+
+PASS name 
+PASS length 
+PASS No arguments 
+PASS Calling 
+PASS Empty descriptor 
+PASS Invalid descriptor argument 
+PASS Undefined initial value in descriptor 
+PASS Undefined element value in descriptor 
+PASS Out-of-range initial value in descriptor: NaN 
+PASS Out-of-range maximum value in descriptor: NaN 
+PASS Out-of-range initial value in descriptor: Infinity 
+PASS Out-of-range maximum value in descriptor: Infinity 
+PASS Out-of-range initial value in descriptor: -Infinity 
+PASS Out-of-range maximum value in descriptor: -Infinity 
+PASS Out-of-range initial value in descriptor: -1 
+PASS Out-of-range maximum value in descriptor: -1 
+PASS Out-of-range initial value in descriptor: 4294967296 
+PASS Out-of-range maximum value in descriptor: 4294967296 
+PASS Out-of-range initial value in descriptor: 68719476736 
+PASS Out-of-range maximum value in descriptor: 68719476736 
+PASS Initial value exceeds maximum 
+PASS Basic (zero) 
+PASS Basic (non-zero) 
+PASS Proxy descriptor 
+PASS Type conversion for descriptor.element 
+PASS Order of evaluation for descriptor 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any-expected.txt
new file mode 100644 (file)
index 0000000..dac3284
--- /dev/null
@@ -0,0 +1,31 @@
+
+PASS Missing arguments: get 
+PASS Branding: get 
+PASS Missing arguments: set 
+PASS Branding: set 
+FAIL Basic assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Growing assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Setting out-of-bounds assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Setting non-function assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Setting non-wasm function assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Setting non-wasm arrow function assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+PASS Getting out-of-range argument: undefined 
+PASS Setting out-of-range argument: undefined 
+PASS Getting out-of-range argument: NaN 
+PASS Setting out-of-range argument: NaN 
+PASS Getting out-of-range argument: Infinity 
+PASS Setting out-of-range argument: Infinity 
+PASS Getting out-of-range argument: -Infinity 
+PASS Setting out-of-range argument: -Infinity 
+PASS Getting out-of-range argument: -1 
+PASS Setting out-of-range argument: -1 
+PASS Getting out-of-range argument: 4294967296 
+PASS Setting out-of-range argument: 4294967296 
+PASS Getting out-of-range argument: 68719476736 
+PASS Setting out-of-range argument: 68719476736 
+PASS Getting out-of-range argument: "0x100000000" 
+PASS Setting out-of-range argument: "0x100000000" 
+PASS Getting out-of-range argument: object "[object Object]" 
+PASS Setting out-of-range argument: object "[object Object]" 
+PASS Order of argument conversion 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.js
new file mode 100644 (file)
index 0000000..2bb43a9
--- /dev/null
@@ -0,0 +1,220 @@
+// META: global=jsshell
+// META: script=/wasm/jsapi/wasm-constants.js
+// META: script=/wasm/jsapi/wasm-module-builder.js
+// META: script=assertions.js
+
+let functions;
+setup(() => {
+  const builder = new WasmModuleBuilder();
+
+  builder
+    .addFunction("fn", kSig_v_d)
+    .addBody([
+        kExprEnd
+    ])
+    .exportFunc();
+  builder
+    .addFunction("fn2", kSig_v_v)
+    .addBody([
+        kExprEnd
+    ])
+    .exportFunc();
+
+  const buffer = builder.toBuffer()
+  const module = new WebAssembly.Module(buffer);
+  const instance = new WebAssembly.Instance(module, {});
+  functions = instance.exports;
+});
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_throws(new TypeError(), () => table.get());
+}, "Missing arguments: get");
+
+test(t => {
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Table,
+    WebAssembly.Table.prototype,
+  ];
+
+  const argument = {
+    valueOf: t.unreached_func("Should not touch the argument (valueOf)"),
+    toString: t.unreached_func("Should not touch the argument (toString)"),
+  };
+
+  const fn = WebAssembly.Table.prototype.get;
+
+  for (const thisValue of thisValues) {
+    assert_throws(new TypeError(), () => fn.call(thisValue, argument), `this=${format_value(thisValue)}`);
+  }
+}, "Branding: get");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_throws(new TypeError(), () => table.set());
+  assert_throws(new TypeError(), () => table.set(0));
+}, "Missing arguments: set");
+
+test(t => {
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Table,
+    WebAssembly.Table.prototype,
+  ];
+
+  const argument = {
+    valueOf: t.unreached_func("Should not touch the argument (valueOf)"),
+    toString: t.unreached_func("Should not touch the argument (toString)"),
+  };
+
+  const fn = WebAssembly.Table.prototype.set;
+
+  for (const thisValue of thisValues) {
+    assert_throws(new TypeError(), () => fn.call(thisValue, argument, null), `this=${format_value(thisValue)}`);
+  }
+}, "Branding: set");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_equal_to_array(table, [null, null, null, null, null]);
+
+  const {fn, fn2} = functions;
+
+  assert_equals(table.set(0, fn), undefined, "set() returns undefined.");
+  table.set(2, fn2);
+  table.set(4, fn);
+
+  assert_equal_to_array(table, [fn, null, fn2, null, fn]);
+
+  table.set(0, null);
+  assert_equal_to_array(table, [null, null, fn2, null, fn]);
+}, "Basic");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_equal_to_array(table, [null, null, null, null, null]);
+
+  const {fn, fn2} = functions;
+
+  table.set(0, fn);
+  table.set(2, fn2);
+  table.set(4, fn);
+
+  assert_equal_to_array(table, [fn, null, fn2, null, fn]);
+
+  table.grow(4);
+
+  assert_equal_to_array(table, [fn, null, fn2, null, fn, null, null, null, null]);
+}, "Growing");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_equal_to_array(table, [null, null, null, null, null]);
+
+  const {fn} = functions;
+
+  assert_throws(new RangeError(), () => table.set(-1, fn));
+  assert_throws(new RangeError(), () => table.set(5, fn));
+  assert_equal_to_array(table, [null, null, null, null, null]);
+}, "Setting out-of-bounds");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 1 };
+  const table = new WebAssembly.Table(argument);
+  assert_equal_to_array(table, [null]);
+
+  const invalidArguments = [
+    undefined,
+    true,
+    false,
+    "test",
+    Symbol(),
+    7,
+    NaN,
+    {},
+  ];
+  for (const argument of invalidArguments) {
+    assert_throws(new TypeError(), () => table.set(0, argument),
+                  `set(${format_value(argument)})`);
+  }
+  assert_equal_to_array(table, [null]);
+}, "Setting non-function");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 1 };
+  const table = new WebAssembly.Table(argument);
+  assert_equal_to_array(table, [null]);
+
+  const fn = function() {};
+  assert_throws(new TypeError(), () => table.set(0, fn));
+  assert_equal_to_array(table, [null]);
+}, "Setting non-wasm function");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 1 };
+  const table = new WebAssembly.Table(argument);
+  assert_equal_to_array(table, [null]);
+
+  const fn = () => {};
+  assert_throws(new TypeError(), () => table.set(0, fn));
+  assert_equal_to_array(table, [null]);
+}, "Setting non-wasm arrow function");
+
+const outOfRangeValues = [
+  undefined,
+  NaN,
+  Infinity,
+  -Infinity,
+  -1,
+  0x100000000,
+  0x1000000000,
+  "0x100000000",
+  { valueOf() { return 0x100000000; } },
+];
+
+for (const value of outOfRangeValues) {
+  test(() => {
+    const argument = { "element": "anyfunc", "initial": 1 };
+    const table = new WebAssembly.Table(argument);
+    assert_throws(new TypeError(), () => table.get(value));
+  }, `Getting out-of-range argument: ${format_value(value)}`);
+
+  test(() => {
+    const argument = { "element": "anyfunc", "initial": 1 };
+    const table = new WebAssembly.Table(argument);
+    assert_throws(new TypeError(), () => table.set(value, null));
+  }, `Setting out-of-range argument: ${format_value(value)}`);
+}
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 1 };
+  const table = new WebAssembly.Table(argument);
+  let called = 0;
+  const value = {
+    valueOf() {
+      called++;
+      return 0;
+    },
+  };
+  assert_throws(new TypeError(), () => table.set(value, {}));
+  assert_equals(called, 1);
+}, "Order of argument conversion");
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..dac3284
--- /dev/null
@@ -0,0 +1,31 @@
+
+PASS Missing arguments: get 
+PASS Branding: get 
+PASS Missing arguments: set 
+PASS Branding: set 
+FAIL Basic assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Growing assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Setting out-of-bounds assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Setting non-function assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Setting non-wasm function assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Setting non-wasm arrow function assert_throws: undefined: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+PASS Getting out-of-range argument: undefined 
+PASS Setting out-of-range argument: undefined 
+PASS Getting out-of-range argument: NaN 
+PASS Setting out-of-range argument: NaN 
+PASS Getting out-of-range argument: Infinity 
+PASS Setting out-of-range argument: Infinity 
+PASS Getting out-of-range argument: -Infinity 
+PASS Setting out-of-range argument: -Infinity 
+PASS Getting out-of-range argument: -1 
+PASS Setting out-of-range argument: -1 
+PASS Getting out-of-range argument: 4294967296 
+PASS Setting out-of-range argument: 4294967296 
+PASS Getting out-of-range argument: 68719476736 
+PASS Setting out-of-range argument: 68719476736 
+PASS Getting out-of-range argument: "0x100000000" 
+PASS Setting out-of-range argument: "0x100000000" 
+PASS Getting out-of-range argument: object "[object Object]" 
+PASS Setting out-of-range argument: object "[object Object]" 
+PASS Order of argument conversion 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any-expected.txt
new file mode 100644 (file)
index 0000000..60d21e0
--- /dev/null
@@ -0,0 +1,16 @@
+
+PASS Missing arguments 
+PASS Branding 
+FAIL Basic assert_throws: before: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Reached maximum assert_throws: before: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Exceeded maximum assert_throws: before: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+PASS Out-of-range argument: undefined 
+PASS Out-of-range argument: NaN 
+PASS Out-of-range argument: Infinity 
+PASS Out-of-range argument: -Infinity 
+PASS Out-of-range argument: -1 
+PASS Out-of-range argument: 4294967296 
+PASS Out-of-range argument: 68719476736 
+PASS Out-of-range argument: "0x100000000" 
+PASS Out-of-range argument: object "[object Object]" 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.js
new file mode 100644 (file)
index 0000000..d3efb51
--- /dev/null
@@ -0,0 +1,86 @@
+// META: global=jsshell
+// META: script=assertions.js
+
+function nulls(n) {
+  return Array(n).fill(null);
+}
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_throws(new TypeError(), () => table.grow());
+}, "Missing arguments");
+
+test(t => {
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Table,
+    WebAssembly.Table.prototype,
+  ];
+
+  const argument = {
+    valueOf: t.unreached_func("Should not touch the argument (valueOf)"),
+    toString: t.unreached_func("Should not touch the argument (toString)"),
+  };
+
+  const fn = WebAssembly.Table.prototype.grow;
+
+  for (const thisValue of thisValues) {
+    assert_throws(new TypeError(), () => fn.call(thisValue, argument), `this=${format_value(thisValue)}`);
+  }
+}, "Branding");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_equal_to_array(table, nulls(5), "before");
+
+  const result = table.grow(3);
+  assert_equals(result, 5);
+  assert_equal_to_array(table, nulls(8), "after");
+}, "Basic");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 3, "maximum": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_equal_to_array(table, nulls(3), "before");
+
+  const result = table.grow(2);
+  assert_equals(result, 3);
+  assert_equal_to_array(table, nulls(5), "after");
+}, "Reached maximum");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 2, "maximum": 5 };
+  const table = new WebAssembly.Table(argument);
+  assert_equal_to_array(table, nulls(2), "before");
+
+  assert_throws(new RangeError(), () => table.grow(4));
+  assert_equal_to_array(table, nulls(2), "after");
+}, "Exceeded maximum");
+
+const outOfRangeValues = [
+  undefined,
+  NaN,
+  Infinity,
+  -Infinity,
+  -1,
+  0x100000000,
+  0x1000000000,
+  "0x100000000",
+  { valueOf() { return 0x100000000; } },
+];
+
+for (const value of outOfRangeValues) {
+  test(() => {
+    const argument = { "element": "anyfunc", "initial": 1 };
+    const table = new WebAssembly.Table(argument);
+    assert_throws(new TypeError(), () => table.grow(value));
+  }, `Out-of-range argument: ${format_value(value)}`);
+}
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..60d21e0
--- /dev/null
@@ -0,0 +1,16 @@
+
+PASS Missing arguments 
+PASS Branding 
+FAIL Basic assert_throws: before: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Reached maximum assert_throws: before: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+FAIL Exceeded maximum assert_throws: before: table.get(-1) function "() => table.get(-1)" threw object "TypeError: Expect an integer argument in the range: [0, 2^32 - 1]" ("TypeError") expected object "RangeError" ("RangeError")
+PASS Out-of-range argument: undefined 
+PASS Out-of-range argument: NaN 
+PASS Out-of-range argument: Infinity 
+PASS Out-of-range argument: -Infinity 
+PASS Out-of-range argument: -1 
+PASS Out-of-range argument: 4294967296 
+PASS Out-of-range argument: 68719476736 
+PASS Out-of-range argument: "0x100000000" 
+PASS Out-of-range argument: object "[object Object]" 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any-expected.txt
new file mode 100644 (file)
index 0000000..670f281
--- /dev/null
@@ -0,0 +1,5 @@
+
+PASS Branding 
+PASS Setting (sloppy mode) 
+PASS Setting (strict mode) 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.js
new file mode 100644 (file)
index 0000000..a6a9661
--- /dev/null
@@ -0,0 +1,46 @@
+// META: global=jsshell
+
+test(() => {
+  const thisValues = [
+    undefined,
+    null,
+    true,
+    "",
+    Symbol(),
+    1,
+    {},
+    WebAssembly.Table,
+    WebAssembly.Table.prototype,
+  ];
+
+  const desc = Object.getOwnPropertyDescriptor(WebAssembly.Table.prototype, "length");
+  assert_equals(typeof desc, "object");
+
+  const getter = desc.get;
+  assert_equals(typeof getter, "function");
+
+  assert_equals(typeof desc.set, "undefined");
+
+  for (const thisValue of thisValues) {
+    assert_throws(new TypeError(), () => getter.call(thisValue), `this=${format_value(thisValue)}`);
+  }
+}, "Branding");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 2 };
+  const table = new WebAssembly.Table(argument);
+  assert_equals(table.length, 2, "Initial length");
+  table.length = 4;
+  assert_equals(table.length, 2, "Should not change the length");
+}, "Setting (sloppy mode)");
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 2 };
+  const table = new WebAssembly.Table(argument);
+  assert_equals(table.length, 2, "Initial length");
+  assert_throws(new TypeError(), () => {
+    "use strict";
+    table.length = 4;
+  });
+  assert_equals(table.length, 2, "Should not change the length");
+}, "Setting (strict mode)");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..670f281
--- /dev/null
@@ -0,0 +1,5 @@
+
+PASS Branding 
+PASS Setting (sloppy mode) 
+PASS Setting (strict mode) 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any-expected.txt
new file mode 100644 (file)
index 0000000..923d633
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Object.prototype.toString on an Table 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.js
new file mode 100644 (file)
index 0000000..e576477
--- /dev/null
@@ -0,0 +1,7 @@
+// META: global=jsshell
+
+test(() => {
+  const argument = { "element": "anyfunc", "initial": 0 };
+  const table = new WebAssembly.Table(argument);
+  assert_class_string(table, "WebAssembly.Table");
+}, "Object.prototype.toString on an Table");
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.worker-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.worker-expected.txt
new file mode 100644 (file)
index 0000000..923d633
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Object.prototype.toString on an Table 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.worker.html b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.worker.html
new file mode 100644 (file)
index 0000000..2382913
--- /dev/null
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/w3c-import.log b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/w3c-import.log
new file mode 100644 (file)
index 0000000..6a9ecce
--- /dev/null
@@ -0,0 +1,22 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+       https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/assertions.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/constructor.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/get-set.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/grow.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/length.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/table/toString.any.js
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/w3c-import.log b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/w3c-import.log
new file mode 100644 (file)
index 0000000..c4c117f
--- /dev/null
@@ -0,0 +1,21 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+       https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/assertions.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/bad-imports.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/interface.any.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/wasm-constants.js
+/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/wasm-module-builder.js
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/wasm-constants.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/wasm-constants.js
new file mode 100644 (file)
index 0000000..f056f9c
--- /dev/null
@@ -0,0 +1,374 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-wasm
+
+function bytes() {
+  var buffer = new ArrayBuffer(arguments.length);
+  var view = new Uint8Array(buffer);
+  for (var i = 0; i < arguments.length; i++) {
+    var val = arguments[i];
+    if ((typeof val) == "string") val = val.charCodeAt(0);
+    view[i] = val | 0;
+  }
+  return buffer;
+}
+
+// Header declaration constants
+var kWasmH0 = 0;
+var kWasmH1 = 0x61;
+var kWasmH2 = 0x73;
+var kWasmH3 = 0x6d;
+
+var kWasmV0 = 1;
+var kWasmV1 = 0;
+var kWasmV2 = 0;
+var kWasmV3 = 0;
+
+var kHeaderSize = 8;
+var kPageSize = 65536;
+
+function bytesWithHeader() {
+  var buffer = new ArrayBuffer(kHeaderSize + arguments.length);
+  var view = new Uint8Array(buffer);
+  view[0] = kWasmH0;
+  view[1] = kWasmH1;
+  view[2] = kWasmH2;
+  view[3] = kWasmH3;
+  view[4] = kWasmV0;
+  view[5] = kWasmV1;
+  view[6] = kWasmV2;
+  view[7] = kWasmV3;
+  for (var i = 0; i < arguments.length; i++) {
+    var val = arguments[i];
+    if ((typeof val) == "string") val = val.charCodeAt(0);
+    view[kHeaderSize + i] = val | 0;
+  }
+  return buffer;
+}
+
+let kDeclNoLocals = 0;
+
+// Section declaration constants
+let kUnknownSectionCode = 0;
+let kTypeSectionCode = 1;      // Function signature declarations
+let kImportSectionCode = 2;    // Import declarations
+let kFunctionSectionCode = 3;  // Function declarations
+let kTableSectionCode = 4;     // Indirect function table and other tables
+let kMemorySectionCode = 5;    // Memory attributes
+let kGlobalSectionCode = 6;    // Global declarations
+let kExportSectionCode = 7;    // Exports
+let kStartSectionCode = 8;     // Start function declaration
+let kElementSectionCode = 9;  // Elements section
+let kCodeSectionCode = 10;      // Function code
+let kDataSectionCode = 11;     // Data segments
+let kNameSectionCode = 12;     // Name section (encoded as string)
+
+let kWasmFunctionTypeForm = 0x60;
+let kWasmAnyFunctionTypeForm = 0x70;
+
+let kResizableMaximumFlag = 1;
+
+// Function declaration flags
+let kDeclFunctionName   = 0x01;
+let kDeclFunctionImport = 0x02;
+let kDeclFunctionLocals = 0x04;
+let kDeclFunctionExport = 0x08;
+
+// Local types
+let kWasmStmt = 0x40;
+let kWasmI32 = 0x7f;
+let kWasmI64 = 0x7e;
+let kWasmF32 = 0x7d;
+let kWasmF64 = 0x7c;
+let kWasmS128 = 0x7b;
+
+let kExternalFunction = 0;
+let kExternalTable = 1;
+let kExternalMemory = 2;
+let kExternalGlobal = 3;
+
+let kTableZero = 0;
+let kMemoryZero = 0;
+
+// Useful signatures
+let kSig_i_i = makeSig([kWasmI32], [kWasmI32]);
+let kSig_l_l = makeSig([kWasmI64], [kWasmI64]);
+let kSig_i_l = makeSig([kWasmI64], [kWasmI32]);
+let kSig_i_ii = makeSig([kWasmI32, kWasmI32], [kWasmI32]);
+let kSig_i_iii = makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]);
+let kSig_d_dd = makeSig([kWasmF64, kWasmF64], [kWasmF64]);
+let kSig_l_ll = makeSig([kWasmI64, kWasmI64], [kWasmI64]);
+let kSig_i_dd = makeSig([kWasmF64, kWasmF64], [kWasmI32]);
+let kSig_v_v = makeSig([], []);
+let kSig_i_v = makeSig([], [kWasmI32]);
+let kSig_l_v = makeSig([], [kWasmI64]);
+let kSig_f_v = makeSig([], [kWasmF64]);
+let kSig_d_v = makeSig([], [kWasmF64]);
+let kSig_v_i = makeSig([kWasmI32], []);
+let kSig_v_ii = makeSig([kWasmI32, kWasmI32], []);
+let kSig_v_iii = makeSig([kWasmI32, kWasmI32, kWasmI32], []);
+let kSig_v_l = makeSig([kWasmI64], []);
+let kSig_v_d = makeSig([kWasmF64], []);
+let kSig_v_dd = makeSig([kWasmF64, kWasmF64], []);
+let kSig_v_ddi = makeSig([kWasmF64, kWasmF64, kWasmI32], []);
+let kSig_s_v = makeSig([], [kWasmS128]);
+
+function makeSig(params, results) {
+  return {params: params, results: results};
+}
+
+function makeSig_v_x(x) {
+  return makeSig([x], []);
+}
+
+function makeSig_v_xx(x) {
+  return makeSig([x, x], []);
+}
+
+function makeSig_r_v(r) {
+  return makeSig([], [r]);
+}
+
+function makeSig_r_x(r, x) {
+  return makeSig([x], [r]);
+}
+
+function makeSig_r_xx(r, x) {
+  return makeSig([x, x], [r]);
+}
+
+// Opcodes
+let kExprUnreachable = 0x00;
+let kExprNop = 0x01;
+let kExprBlock = 0x02;
+let kExprLoop = 0x03;
+let kExprIf = 0x04;
+let kExprElse = 0x05;
+let kExprTry = 0x06;
+let kExprCatch = 0x07;
+let kExprThrow = 0x08;
+let kExprEnd = 0x0b;
+let kExprBr = 0x0c;
+let kExprBrIf = 0x0d;
+let kExprBrTable = 0x0e;
+let kExprReturn = 0x0f;
+let kExprCallFunction = 0x10;
+let kExprCallIndirect = 0x11;
+let kExprDrop = 0x1a;
+let kExprSelect = 0x1b;
+let kExprGetLocal = 0x20;
+let kExprSetLocal = 0x21;
+let kExprTeeLocal = 0x22;
+let kExprGetGlobal = 0x23;
+let kExprSetGlobal = 0x24;
+let kExprI32Const = 0x41;
+let kExprI64Const = 0x42;
+let kExprF32Const = 0x43;
+let kExprF64Const = 0x44;
+let kExprI32LoadMem = 0x28;
+let kExprI64LoadMem = 0x29;
+let kExprF32LoadMem = 0x2a;
+let kExprF64LoadMem = 0x2b;
+let kExprI32LoadMem8S = 0x2c;
+let kExprI32LoadMem8U = 0x2d;
+let kExprI32LoadMem16S = 0x2e;
+let kExprI32LoadMem16U = 0x2f;
+let kExprI64LoadMem8S = 0x30;
+let kExprI64LoadMem8U = 0x31;
+let kExprI64LoadMem16S = 0x32;
+let kExprI64LoadMem16U = 0x33;
+let kExprI64LoadMem32S = 0x34;
+let kExprI64LoadMem32U = 0x35;
+let kExprI32StoreMem = 0x36;
+let kExprI64StoreMem = 0x37;
+let kExprF32StoreMem = 0x38;
+let kExprF64StoreMem = 0x39;
+let kExprI32StoreMem8 = 0x3a;
+let kExprI32StoreMem16 = 0x3b;
+let kExprI64StoreMem8 = 0x3c;
+let kExprI64StoreMem16 = 0x3d;
+let kExprI64StoreMem32 = 0x3e;
+let kExprMemorySize = 0x3f;
+let kExprGrowMemory = 0x40;
+let kExprI32Eqz = 0x45;
+let kExprI32Eq = 0x46;
+let kExprI32Ne = 0x47;
+let kExprI32LtS = 0x48;
+let kExprI32LtU = 0x49;
+let kExprI32GtS = 0x4a;
+let kExprI32GtU = 0x4b;
+let kExprI32LeS = 0x4c;
+let kExprI32LeU = 0x4d;
+let kExprI32GeS = 0x4e;
+let kExprI32GeU = 0x4f;
+let kExprI64Eqz = 0x50;
+let kExprI64Eq = 0x51;
+let kExprI64Ne = 0x52;
+let kExprI64LtS = 0x53;
+let kExprI64LtU = 0x54;
+let kExprI64GtS = 0x55;
+let kExprI64GtU = 0x56;
+let kExprI64LeS = 0x57;
+let kExprI64LeU = 0x58;
+let kExprI64GeS = 0x59;
+let kExprI64GeU = 0x5a;
+let kExprF32Eq = 0x5b;
+let kExprF32Ne = 0x5c;
+let kExprF32Lt = 0x5d;
+let kExprF32Gt = 0x5e;
+let kExprF32Le = 0x5f;
+let kExprF32Ge = 0x60;
+let kExprF64Eq = 0x61;
+let kExprF64Ne = 0x62;
+let kExprF64Lt = 0x63;
+let kExprF64Gt = 0x64;
+let kExprF64Le = 0x65;
+let kExprF64Ge = 0x66;
+let kExprI32Clz = 0x67;
+let kExprI32Ctz = 0x68;
+let kExprI32Popcnt = 0x69;
+let kExprI32Add = 0x6a;
+let kExprI32Sub = 0x6b;
+let kExprI32Mul = 0x6c;
+let kExprI32DivS = 0x6d;
+let kExprI32DivU = 0x6e;
+let kExprI32RemS = 0x6f;
+let kExprI32RemU = 0x70;
+let kExprI32And = 0x71;
+let kExprI32Ior = 0x72;
+let kExprI32Xor = 0x73;
+let kExprI32Shl = 0x74;
+let kExprI32ShrS = 0x75;
+let kExprI32ShrU = 0x76;
+let kExprI32Rol = 0x77;
+let kExprI32Ror = 0x78;
+let kExprI64Clz = 0x79;
+let kExprI64Ctz = 0x7a;
+let kExprI64Popcnt = 0x7b;
+let kExprI64Add = 0x7c;
+let kExprI64Sub = 0x7d;
+let kExprI64Mul = 0x7e;
+let kExprI64DivS = 0x7f;
+let kExprI64DivU = 0x80;
+let kExprI64RemS = 0x81;
+let kExprI64RemU = 0x82;
+let kExprI64And = 0x83;
+let kExprI64Ior = 0x84;
+let kExprI64Xor = 0x85;
+let kExprI64Shl = 0x86;
+let kExprI64ShrS = 0x87;
+let kExprI64ShrU = 0x88;
+let kExprI64Rol = 0x89;
+let kExprI64Ror = 0x8a;
+let kExprF32Abs = 0x8b;
+let kExprF32Neg = 0x8c;
+let kExprF32Ceil = 0x8d;
+let kExprF32Floor = 0x8e;
+let kExprF32Trunc = 0x8f;
+let kExprF32NearestInt = 0x90;
+let kExprF32Sqrt = 0x91;
+let kExprF32Add = 0x92;
+let kExprF32Sub = 0x93;
+let kExprF32Mul = 0x94;
+let kExprF32Div = 0x95;
+let kExprF32Min = 0x96;
+let kExprF32Max = 0x97;
+let kExprF32CopySign = 0x98;
+let kExprF64Abs = 0x99;
+let kExprF64Neg = 0x9a;
+let kExprF64Ceil = 0x9b;
+let kExprF64Floor = 0x9c;
+let kExprF64Trunc = 0x9d;
+let kExprF64NearestInt = 0x9e;
+let kExprF64Sqrt = 0x9f;
+let kExprF64Add = 0xa0;
+let kExprF64Sub = 0xa1;
+let kExprF64Mul = 0xa2;
+let kExprF64Div = 0xa3;
+let kExprF64Min = 0xa4;
+let kExprF64Max = 0xa5;
+let kExprF64CopySign = 0xa6;
+let kExprI32ConvertI64 = 0xa7;
+let kExprI32SConvertF32 = 0xa8;
+let kExprI32UConvertF32 = 0xa9;
+let kExprI32SConvertF64 = 0xaa;
+let kExprI32UConvertF64 = 0xab;
+let kExprI64SConvertI32 = 0xac;
+let kExprI64UConvertI32 = 0xad;
+let kExprI64SConvertF32 = 0xae;
+let kExprI64UConvertF32 = 0xaf;
+let kExprI64SConvertF64 = 0xb0;
+let kExprI64UConvertF64 = 0xb1;
+let kExprF32SConvertI32 = 0xb2;
+let kExprF32UConvertI32 = 0xb3;
+let kExprF32SConvertI64 = 0xb4;
+let kExprF32UConvertI64 = 0xb5;
+let kExprF32ConvertF64 = 0xb6;
+let kExprF64SConvertI32 = 0xb7;
+let kExprF64UConvertI32 = 0xb8;
+let kExprF64SConvertI64 = 0xb9;
+let kExprF64UConvertI64 = 0xba;
+let kExprF64ConvertF32 = 0xbb;
+let kExprI32ReinterpretF32 = 0xbc;
+let kExprI64ReinterpretF64 = 0xbd;
+let kExprF32ReinterpretI32 = 0xbe;
+let kExprF64ReinterpretI64 = 0xbf;
+
+let kTrapUnreachable          = 0;
+let kTrapMemOutOfBounds       = 1;
+let kTrapDivByZero            = 2;
+let kTrapDivUnrepresentable   = 3;
+let kTrapRemByZero            = 4;
+let kTrapFloatUnrepresentable = 5;
+let kTrapFuncInvalid          = 6;
+let kTrapFuncSigMismatch      = 7;
+let kTrapInvalidIndex         = 8;
+
+let kTrapMsgs = [
+  "unreachable",
+  "memory access out of bounds",
+  "divide by zero",
+  "divide result unrepresentable",
+  "remainder by zero",
+  "integer result unrepresentable",
+  "invalid function",
+  "function signature mismatch",
+  "invalid index into function table"
+];
+
+function assertTraps(trap, code) {
+    var threwException = true;
+    try {
+      if (typeof code === 'function') {
+        code();
+      } else {
+        eval(code);
+      }
+      threwException = false;
+    } catch (e) {
+      assertEquals("object", typeof e);
+      assertEquals(kTrapMsgs[trap], e.message);
+      // Success.
+      return;
+    }
+    throw new MjsUnitAssertionError("Did not trap, expected: " + kTrapMsgs[trap]);
+}
+
+function assertWasmThrows(value, code) {
+    assertEquals("number", typeof(value));
+    try {
+      if (typeof code === 'function') {
+        code();
+      } else {
+        eval(code);
+      }
+    } catch (e) {
+      assertEquals("number", typeof e);
+      assertEquals(value, e);
+      // Success.
+      return;
+    }
+    throw new MjsUnitAssertionError("Did not throw at all, expected: " + value);
+}
diff --git a/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/wasm-module-builder.js b/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/wasm-module-builder.js
new file mode 100644 (file)
index 0000000..6e9284e
--- /dev/null
@@ -0,0 +1,555 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Used for encoding f32 and double constants to bits.
+let __buffer = new ArrayBuffer(8);
+let byte_view = new Int8Array(__buffer);
+let f32_view = new Float32Array(__buffer);
+let f64_view = new Float64Array(__buffer);
+
+class Binary extends Array {
+  emit_u8(val) {
+    this.push(val);
+  }
+
+  emit_u16(val) {
+    this.push(val & 0xff);
+    this.push((val >> 8) & 0xff);
+  }
+
+  emit_u32(val) {
+    this.push(val & 0xff);
+    this.push((val >> 8) & 0xff);
+    this.push((val >> 16) & 0xff);
+    this.push((val >> 24) & 0xff);
+  }
+
+  emit_u32v(val) {
+    while (true) {
+      let v = val & 0xff;
+      val = val >>> 7;
+      if (val == 0) {
+        this.push(v);
+        break;
+      }
+      this.push(v | 0x80);
+    }
+  }
+
+  emit_bytes(data) {
+    for (let i = 0; i < data.length; i++) {
+      this.push(data[i] & 0xff);
+    }
+  }
+
+  emit_string(string) {
+    // When testing illegal names, we pass a byte array directly.
+    if (string instanceof Array) {
+      this.emit_u32v(string.length);
+      this.emit_bytes(string);
+      return;
+    }
+
+    // This is the hacky way to convert a JavaScript string to a UTF8 encoded
+    // string only containing single-byte characters.
+    let string_utf8 = unescape(encodeURIComponent(string));
+    this.emit_u32v(string_utf8.length);
+    for (let i = 0; i < string_utf8.length; i++) {
+      this.emit_u8(string_utf8.charCodeAt(i));
+    }
+  }
+
+  emit_header() {
+    this.push(kWasmH0, kWasmH1, kWasmH2, kWasmH3,
+              kWasmV0, kWasmV1, kWasmV2, kWasmV3);
+  }
+
+  emit_section(section_code, content_generator) {
+    // Emit section name.
+    this.emit_u8(section_code);
+    // Emit the section to a temporary buffer: its full length isn't know yet.
+    let section = new Binary;
+    content_generator(section);
+    // Emit section length.
+    this.emit_u32v(section.length);
+    // Copy the temporary buffer.
+    this.push(...section);
+  }
+}
+
+class WasmFunctionBuilder {
+  constructor(module, name, type_index) {
+    this.module = module;
+    this.name = name;
+    this.type_index = type_index;
+    this.body = [];
+  }
+
+  exportAs(name) {
+    this.module.addExport(name, this.index);
+    return this;
+  }
+
+  exportFunc() {
+    this.exportAs(this.name);
+    return this;
+  }
+
+  addBody(body) {
+    this.body = body;
+    return this;
+  }
+
+  addLocals(locals) {
+    this.locals = locals;
+    return this;
+  }
+
+  end() {
+    return this.module;
+  }
+}
+
+class WasmGlobalBuilder {
+  constructor(module, type, mutable) {
+    this.module = module;
+    this.type = type;
+    this.mutable = mutable;
+    this.init = 0;
+  }
+
+  exportAs(name) {
+    this.module.exports.push({name: name, kind: kExternalGlobal,
+                              index: this.index});
+    return this;
+  }
+}
+
+class WasmModuleBuilder {
+  constructor() {
+    this.types = [];
+    this.imports = [];
+    this.exports = [];
+    this.globals = [];
+    this.functions = [];
+    this.function_table = [];
+    this.function_table_length = 0;
+    this.function_table_inits = [];
+    this.segments = [];
+    this.explicit = [];
+    this.num_imported_funcs = 0;
+    this.num_imported_globals = 0;
+    return this;
+  }
+
+  addStart(start_index) {
+    this.start_index = start_index;
+    return this;
+  }
+
+  addMemory(min, max, exp) {
+    this.memory = {min: min, max: max, exp: exp};
+    return this;
+  }
+
+  addExplicitSection(bytes) {
+    this.explicit.push(bytes);
+    return this;
+  }
+
+  addType(type) {
+    // TODO: canonicalize types?
+    this.types.push(type);
+    return this.types.length - 1;
+  }
+
+  addGlobal(local_type, mutable) {
+    let glob = new WasmGlobalBuilder(this, local_type, mutable);
+    glob.index = this.globals.length + this.num_imported_globals;
+    this.globals.push(glob);
+    return glob;
+  }
+
+  addFunction(name, type) {
+    let type_index = (typeof type) == "number" ? type : this.addType(type);
+    let func = new WasmFunctionBuilder(this, name, type_index);
+    func.index = this.functions.length + this.num_imported_funcs;
+    this.functions.push(func);
+    return func;
+  }
+
+  addImport(module = "", name, type) {
+    let type_index = (typeof type) == "number" ? type : this.addType(type);
+    this.imports.push({module: module, name: name, kind: kExternalFunction,
+                       type: type_index});
+    return this.num_imported_funcs++;
+  }
+
+  addImportedGlobal(module = "", name, type) {
+    let o = {module: module, name: name, kind: kExternalGlobal, type: type,
+             mutable: false}
+    this.imports.push(o);
+    return this.num_imported_globals++;
+  }
+
+  addImportedMemory(module = "", name, initial = 0, maximum) {
+    let o = {module: module, name: name, kind: kExternalMemory,
+             initial: initial, maximum: maximum};
+    this.imports.push(o);
+    return this;
+  }
+
+  addImportedTable(module = "", name, initial, maximum) {
+    let o = {module: module, name: name, kind: kExternalTable, initial: initial,
+             maximum: maximum};
+    this.imports.push(o);
+  }
+
+  addExport(name, index) {
+    this.exports.push({name: name, kind: kExternalFunction, index: index});
+    return this;
+  }
+
+  addExportOfKind(name, kind, index) {
+    this.exports.push({name: name, kind: kind, index: index});
+    return this;
+  }
+
+  addDataSegment(addr, data, is_global = false) {
+    this.segments.push({addr: addr, data: data, is_global: is_global});
+    return this.segments.length - 1;
+  }
+
+  exportMemoryAs(name) {
+    this.exports.push({name: name, kind: kExternalMemory, index: 0});
+  }
+
+  addFunctionTableInit(base, is_global, array) {
+    this.function_table_inits.push({base: base, is_global: is_global,
+                                    array: array});
+    if (!is_global) {
+      var length = base + array.length;
+      if (length > this.function_table_length) {
+        this.function_table_length = length;
+      }
+    }
+    return this;
+  }
+
+  appendToTable(array) {
+    return this.addFunctionTableInit(this.function_table.length, false, array);
+  }
+
+  setFunctionTableLength(length) {
+    this.function_table_length = length;
+    return this;
+  }
+
+  toArray(debug = false) {
+    let binary = new Binary;
+    let wasm = this;
+
+    // Add header
+    binary.emit_header();
+
+    // Add type section
+    if (wasm.types.length > 0) {
+      if (debug) print("emitting types @ " + binary.length);
+      binary.emit_section(kTypeSectionCode, section => {
+        section.emit_u32v(wasm.types.length);
+        for (let type of wasm.types) {
+          section.emit_u8(kWasmFunctionTypeForm);
+          section.emit_u32v(type.params.length);
+          for (let param of type.params) {
+            section.emit_u8(param);
+          }
+          section.emit_u32v(type.results.length);
+          for (let result of type.results) {
+            section.emit_u8(result);
+          }
+        }
+      });
+    }
+
+    // Add imports section
+    if (wasm.imports.length > 0) {
+      if (debug) print("emitting imports @ " + binary.length);
+      binary.emit_section(kImportSectionCode, section => {
+        section.emit_u32v(wasm.imports.length);
+        for (let imp of wasm.imports) {
+          section.emit_string(imp.module);
+          section.emit_string(imp.name || '');
+          section.emit_u8(imp.kind);
+          if (imp.kind == kExternalFunction) {
+            section.emit_u32v(imp.type);
+          } else if (imp.kind == kExternalGlobal) {
+            section.emit_u32v(imp.type);
+            section.emit_u8(imp.mutable);
+          } else if (imp.kind == kExternalMemory) {
+            var has_max = (typeof imp.maximum) != "undefined";
+            section.emit_u8(has_max ? 1 : 0); // flags
+            section.emit_u32v(imp.initial); // initial
+            if (has_max) section.emit_u32v(imp.maximum); // maximum
+          } else if (imp.kind == kExternalTable) {
+            section.emit_u8(kWasmAnyFunctionTypeForm);
+            var has_max = (typeof imp.maximum) != "undefined";
+            section.emit_u8(has_max ? 1 : 0); // flags
+            section.emit_u32v(imp.initial); // initial
+            if (has_max) section.emit_u32v(imp.maximum); // maximum
+          } else {
+            throw new Error("unknown/unsupported import kind " + imp.kind);
+          }
+        }
+      });
+    }
+
+    // Add functions declarations
+    let has_names = false;
+    let names = false;
+    if (wasm.functions.length > 0) {
+      if (debug) print("emitting function decls @ " + binary.length);
+      binary.emit_section(kFunctionSectionCode, section => {
+        section.emit_u32v(wasm.functions.length);
+        for (let func of wasm.functions) {
+          has_names = has_names || (func.name != undefined &&
+                                   func.name.length > 0);
+          section.emit_u32v(func.type_index);
+        }
+      });
+    }
+
+    // Add function_table.
+    if (wasm.function_table_length > 0) {
+      if (debug) print("emitting table @ " + binary.length);
+      binary.emit_section(kTableSectionCode, section => {
+        section.emit_u8(1);  // one table entry
+        section.emit_u8(kWasmAnyFunctionTypeForm);
+        section.emit_u8(1);
+        section.emit_u32v(wasm.function_table_length);
+        section.emit_u32v(wasm.function_table_length);
+      });
+    }
+
+    // Add memory section
+    if (wasm.memory != undefined) {
+      if (debug) print("emitting memory @ " + binary.length);
+      binary.emit_section(kMemorySectionCode, section => {
+        section.emit_u8(1);  // one memory entry
+        section.emit_u32v(kResizableMaximumFlag);
+        section.emit_u32v(wasm.memory.min);
+        section.emit_u32v(wasm.memory.max);
+      });
+    }
+
+    // Add global section.
+    if (wasm.globals.length > 0) {
+      if (debug) print ("emitting globals @ " + binary.length);
+      binary.emit_section(kGlobalSectionCode, section => {
+        section.emit_u32v(wasm.globals.length);
+        for (let global of wasm.globals) {
+          section.emit_u8(global.type);
+          section.emit_u8(global.mutable);
+          if ((typeof global.init_index) == "undefined") {
+            // Emit a constant initializer.
+            switch (global.type) {
+            case kWasmI32:
+              section.emit_u8(kExprI32Const);
+              section.emit_u32v(global.init);
+              break;
+            case kWasmI64:
+              section.emit_u8(kExprI64Const);
+              section.emit_u8(global.init);
+              break;
+            case kWasmF32:
+              section.emit_u8(kExprF32Const);
+              f32_view[0] = global.init;
+              section.emit_u8(byte_view[0]);
+              section.emit_u8(byte_view[1]);
+              section.emit_u8(byte_view[2]);
+              section.emit_u8(byte_view[3]);
+              break;
+            case kWasmF64:
+              section.emit_u8(kExprF64Const);
+              f64_view[0] = global.init;
+              section.emit_u8(byte_view[0]);
+              section.emit_u8(byte_view[1]);
+              section.emit_u8(byte_view[2]);
+              section.emit_u8(byte_view[3]);
+              section.emit_u8(byte_view[4]);
+              section.emit_u8(byte_view[5]);
+              section.emit_u8(byte_view[6]);
+              section.emit_u8(byte_view[7]);
+              break;
+            }
+          } else {
+            // Emit a global-index initializer.
+            section.emit_u8(kExprGetGlobal);
+            section.emit_u32v(global.init_index);
+          }
+          section.emit_u8(kExprEnd);  // end of init expression
+        }
+      });
+    }
+
+    // Add export table.
+    var mem_export = (wasm.memory != undefined && wasm.memory.exp);
+    var exports_count = wasm.exports.length + (mem_export ? 1 : 0);
+    if (exports_count > 0) {
+      if (debug) print("emitting exports @ " + binary.length);
+      binary.emit_section(kExportSectionCode, section => {
+        section.emit_u32v(exports_count);
+        for (let exp of wasm.exports) {
+          section.emit_string(exp.name);
+          section.emit_u8(exp.kind);
+          section.emit_u32v(exp.index);
+        }
+        if (mem_export) {
+          section.emit_string("memory");
+          section.emit_u8(kExternalMemory);
+          section.emit_u8(0);
+        }
+      });
+    }
+
+    // Add start function section.
+    if (wasm.start_index != undefined) {
+      if (debug) print("emitting start function @ " + binary.length);
+      binary.emit_section(kStartSectionCode, section => {
+        section.emit_u32v(wasm.start_index);
+      });
+    }
+
+    // Add table elements.
+    if (wasm.function_table_inits.length > 0) {
+      if (debug) print("emitting table @ " + binary.length);
+      binary.emit_section(kElementSectionCode, section => {
+        var inits = wasm.function_table_inits;
+        section.emit_u32v(inits.length);
+        section.emit_u8(0); // table index
+
+        for (let init of inits) {
+          if (init.is_global) {
+            section.emit_u8(kExprGetGlobal);
+          } else {
+            section.emit_u8(kExprI32Const);
+          }
+          section.emit_u32v(init.base);
+          section.emit_u8(kExprEnd);
+          section.emit_u32v(init.array.length);
+          for (let index of init.array) {
+            section.emit_u32v(index);
+          }
+        }
+      });
+    }
+
+    // Add function bodies.
+    if (wasm.functions.length > 0) {
+      // emit function bodies
+      if (debug) print("emitting code @ " + binary.length);
+      binary.emit_section(kCodeSectionCode, section => {
+        section.emit_u32v(wasm.functions.length);
+        for (let func of wasm.functions) {
+          // Function body length will be patched later.
+          let local_decls = [];
+          let l = func.locals;
+          if (l != undefined) {
+            let local_decls_count = 0;
+            if (l.i32_count > 0) {
+              local_decls.push({count: l.i32_count, type: kWasmI32});
+            }
+            if (l.i64_count > 0) {
+              local_decls.push({count: l.i64_count, type: kWasmI64});
+            }
+            if (l.f32_count > 0) {
+              local_decls.push({count: l.f32_count, type: kWasmF32});
+            }
+            if (l.f64_count > 0) {
+              local_decls.push({count: l.f64_count, type: kWasmF64});
+            }
+          }
+
+          let header = new Binary;
+          header.emit_u32v(local_decls.length);
+          for (let decl of local_decls) {
+            header.emit_u32v(decl.count);
+            header.emit_u8(decl.type);
+          }
+
+          section.emit_u32v(header.length + func.body.length);
+          section.emit_bytes(header);
+          section.emit_bytes(func.body);
+        }
+      });
+    }
+
+    // Add data segments.
+    if (wasm.segments.length > 0) {
+      if (debug) print("emitting data segments @ " + binary.length);
+      binary.emit_section(kDataSectionCode, section => {
+        section.emit_u32v(wasm.segments.length);
+        for (let seg of wasm.segments) {
+          section.emit_u8(0);  // linear memory index 0
+          if (seg.is_global) {
+            // initializer is a global variable
+            section.emit_u8(kExprGetGlobal);
+            section.emit_u32v(seg.addr);
+          } else {
+            // initializer is a constant
+            section.emit_u8(kExprI32Const);
+            section.emit_u32v(seg.addr);
+          }
+          section.emit_u8(kExprEnd);
+          section.emit_u32v(seg.data.length);
+          section.emit_bytes(seg.data);
+        }
+      });
+    }
+
+    // Add any explicitly added sections
+    for (let exp of wasm.explicit) {
+      if (debug) print("emitting explicit @ " + binary.length);
+      binary.emit_bytes(exp);
+    }
+
+    // Add function names.
+    if (has_names) {
+      if (debug) print("emitting names @ " + binary.length);
+      binary.emit_section(kUnknownSectionCode, section => {
+        section.emit_string("name");
+        var count = wasm.functions.length + wasm.num_imported_funcs;
+        section.emit_u32v(count);
+        for (var i = 0; i < wasm.num_imported_funcs; i++) {
+          section.emit_u8(0); // empty string
+          section.emit_u8(0); // local names count == 0
+        }
+        for (let func of wasm.functions) {
+          var name = func.name == undefined ? "" : func.name;
+          section.emit_string(name);
+          section.emit_u8(0);  // local names count == 0
+        }
+      });
+    }
+
+    return binary;
+  }
+
+  toBuffer(debug = false) {
+    let bytes = this.toArray(debug);
+    let buffer = new ArrayBuffer(bytes.length);
+    let view = new Uint8Array(buffer);
+    for (let i = 0; i < bytes.length; i++) {
+      let val = bytes[i];
+      if ((typeof val) == "string") val = val.charCodeAt(0);
+      view[i] = val | 0;
+    }
+    return new Uint8Array(buffer);
+  }
+
+  instantiate(...args) {
+    let module = new WebAssembly.Module(this.toBuffer());
+    let instance = new WebAssembly.Instance(module, ...args);
+    return instance;
+  }
+}
index 76c5689..0408652 100644 (file)
@@ -122,4 +122,6 @@ imported/w3c/web-platform-tests/css/css-lists/list-and-writing-mode-001.html [ F
 
 webkit.org/b/195466 imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute-width-1000px.html [ Pass Failure ]
 webkit.org/b/195466 imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/ready-states/autoplay.html [ Pass Failure ]
-webkit.org/b/195466 imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/error-codes/error.html [ Pass Failure ]
\ No newline at end of file
+webkit.org/b/195466 imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/error-codes/error.html [ Pass Failure ]
+
+imported/w3c/web-platform-tests/wasm [ Skip ]
index f32b4a8..0eed029 100644 (file)
@@ -4423,3 +4423,5 @@ webkit.org/b/197371 http/wpt/prefetch/link-prefetch-main-resource-redirect.html
 webkit.org/b/198112 http/tests/security/showModalDialog-sync-cross-origin-page-load2.html [ Skip ]
 
 webkit.org/b/198679 fast/events/fire-mousedown-while-pressing-mouse-button.html [ Failure ]
+
+imported/w3c/web-platform-tests/wasm [ Skip ]
index e43bb6b..6a04d38 100644 (file)
@@ -108,7 +108,6 @@ set(JavaScriptCore_OBJECT_LUT_SOURCES
     wasm/js/WebAssemblyMemoryPrototype.cpp
     wasm/js/WebAssemblyModuleConstructor.cpp
     wasm/js/WebAssemblyModulePrototype.cpp
-    wasm/js/WebAssemblyPrototype.cpp
     wasm/js/WebAssemblyRuntimeErrorConstructor.cpp
     wasm/js/WebAssemblyRuntimeErrorPrototype.cpp
     wasm/js/WebAssemblyTableConstructor.cpp
@@ -1011,8 +1010,8 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
     wasm/WasmPageCount.h
     wasm/WasmTierUpCount.h
 
+    wasm/js/JSWebAssembly.h
     wasm/js/JSWebAssemblyModule.h
-    wasm/js/WebAssemblyPrototype.h
 
 
     yarr/RegularExpression.h
@@ -1220,7 +1219,7 @@ set(JavaScriptCore_BUILTINS_SOURCES
     ${JAVASCRIPTCORE_DIR}/builtins/StringPrototype.js
     ${JAVASCRIPTCORE_DIR}/builtins/TypedArrayConstructor.js
     ${JAVASCRIPTCORE_DIR}/builtins/TypedArrayPrototype.js
-    ${JAVASCRIPTCORE_DIR}/builtins/WebAssemblyPrototype.js
+    ${JAVASCRIPTCORE_DIR}/builtins/WebAssembly.js
 )
 
 add_custom_command(
index 345c750..5f477ee 100644 (file)
@@ -1,3 +1,78 @@
+2019-07-15  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Improve wasm wpt test results by fixing miscellaneous issues
+        https://bugs.webkit.org/show_bug.cgi?id=199783
+
+        Reviewed by Mark Lam.
+
+        This patch fixes miscellaneous issues in our Wasm JS API implementation to improve WPT score.
+        I picked trivial ones in this patch to make this easily reviewable.
+
+        1. Remove WebAssemblyPrototype. It does not exist in the spec. Merging WebAssemblyPrototype into JSWebAssembly.
+        2. Fix various attributes. It does not match to the usual JSC builtin's convention. But this change
+           is correct because they are changed to be matched against WebIDL definition, and WebAssembly implementation
+           follows WebIDL. In the future, we could move WebCore WebIDL things into WTF layer and even use (or leverage
+           some of utility functions) in our WebAssembly JS API implementation.
+        3. Fix how we interpret "present" in WebAssembly spec. This does not mean [[HasProperty]] result. It follows to
+           WebIDL spec, and it means that [[Get]] result is not undefined.
+        4. Add argument count check to Module.customSections, which is required because the method is defined in WebIDL.
+        5. Fix toNonWrappingUint32 to match it to WebIDL's conversion rule.
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * Sources.txt:
+        * builtins/WebAssembly.js: Renamed from Source/JavaScriptCore/builtins/WebAssemblyPrototype.js.
+        * jit/Repatch.cpp:
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        * runtime/JSModuleLoader.cpp:
+        (JSC::moduleLoaderParseModule):
+        * wasm/js/JSWebAssembly.cpp:
+        (JSC::JSWebAssembly::create):
+        (JSC::JSWebAssembly::finishCreation):
+        (JSC::reject):
+        (JSC::webAssemblyModuleValidateAsyncInternal):
+        (JSC::webAssemblyCompileFunc):
+        (JSC::resolve):
+        (JSC::JSWebAssembly::webAssemblyModuleValidateAsync):
+        (JSC::instantiate):
+        (JSC::compileAndInstantiate):
+        (JSC::JSWebAssembly::instantiate):
+        (JSC::webAssemblyModuleInstantinateAsyncInternal):
+        (JSC::JSWebAssembly::webAssemblyModuleInstantinateAsync):
+        (JSC::webAssemblyInstantiateFunc):
+        (JSC::webAssemblyValidateFunc):
+        (JSC::webAssemblyCompileStreamingInternal):
+        (JSC::webAssemblyInstantiateStreamingInternal):
+        * wasm/js/JSWebAssembly.h:
+        * wasm/js/JSWebAssemblyHelpers.h:
+        (JSC::toNonWrappingUint32):
+        * wasm/js/WebAssemblyCompileErrorConstructor.cpp:
+        (JSC::WebAssemblyCompileErrorConstructor::finishCreation):
+        * wasm/js/WebAssemblyInstanceConstructor.cpp:
+        (JSC::WebAssemblyInstanceConstructor::finishCreation):
+        * wasm/js/WebAssemblyInstancePrototype.cpp:
+        * wasm/js/WebAssemblyLinkErrorConstructor.cpp:
+        (JSC::WebAssemblyLinkErrorConstructor::finishCreation):
+        * wasm/js/WebAssemblyMemoryConstructor.cpp:
+        (JSC::constructJSWebAssemblyMemory):
+        (JSC::WebAssemblyMemoryConstructor::finishCreation):
+        * wasm/js/WebAssemblyMemoryPrototype.cpp:
+        * wasm/js/WebAssemblyModuleConstructor.cpp:
+        (JSC::webAssemblyModuleCustomSections):
+        (JSC::WebAssemblyModuleConstructor::finishCreation):
+        * wasm/js/WebAssemblyPrototype.cpp: Removed.
+        * wasm/js/WebAssemblyPrototype.h: Removed.
+        * wasm/js/WebAssemblyRuntimeErrorConstructor.cpp:
+        (JSC::WebAssemblyRuntimeErrorConstructor::finishCreation):
+        * wasm/js/WebAssemblyTableConstructor.cpp:
+        (JSC::constructJSWebAssemblyTable):
+        (JSC::WebAssemblyTableConstructor::finishCreation):
+        * wasm/js/WebAssemblyTablePrototype.cpp:
+
 2019-07-15  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed, rolling out r247440.
index 5fc30d0..a76a5ed 100644 (file)
@@ -57,7 +57,7 @@ $(PROJECT_DIR)/builtins/StringIteratorPrototype.js
 $(PROJECT_DIR)/builtins/StringPrototype.js
 $(PROJECT_DIR)/builtins/TypedArrayConstructor.js
 $(PROJECT_DIR)/builtins/TypedArrayPrototype.js
-$(PROJECT_DIR)/builtins/WebAssemblyPrototype.js
+$(PROJECT_DIR)/builtins/WebAssembly.js
 $(PROJECT_DIR)/bytecode/BytecodeList.rb
 $(PROJECT_DIR)/create_hash_table
 $(PROJECT_DIR)/disassembler/udis86/optable.xml
@@ -183,7 +183,6 @@ $(PROJECT_DIR)/wasm/js/WebAssemblyMemoryConstructor.cpp
 $(PROJECT_DIR)/wasm/js/WebAssemblyMemoryPrototype.cpp
 $(PROJECT_DIR)/wasm/js/WebAssemblyModuleConstructor.cpp
 $(PROJECT_DIR)/wasm/js/WebAssemblyModulePrototype.cpp
-$(PROJECT_DIR)/wasm/js/WebAssemblyPrototype.cpp
 $(PROJECT_DIR)/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp
 $(PROJECT_DIR)/wasm/js/WebAssemblyRuntimeErrorPrototype.cpp
 $(PROJECT_DIR)/wasm/js/WebAssemblyTableConstructor.cpp
index 818c74f..6918b2a 100644 (file)
@@ -69,7 +69,6 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/WebAssemblyMemoryConstructor
 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/WebAssemblyMemoryPrototype.lut.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/WebAssemblyModuleConstructor.lut.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/WebAssemblyModulePrototype.lut.h
-$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/WebAssemblyPrototype.lut.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/WebAssemblyRuntimeErrorConstructor.lut.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/WebAssemblyRuntimeErrorPrototype.lut.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/WebAssemblyTableConstructor.lut.h
index 8ed0ac7..b59fe06 100644 (file)
@@ -119,7 +119,7 @@ JavaScriptCore_BUILTINS_SOURCES = \
     $(JavaScriptCore)/builtins/StringPrototype.js \
     $(JavaScriptCore)/builtins/TypedArrayConstructor.js \
     $(JavaScriptCore)/builtins/TypedArrayPrototype.js \
-    $(JavaScriptCore)/builtins/WebAssemblyPrototype.js \
+    $(JavaScriptCore)/builtins/WebAssembly.js \
 #
 
 # The combined output file depends on the contents of builtins and generator scripts, so
@@ -183,7 +183,6 @@ OBJECT_LUT_HEADERS = \
     WebAssemblyMemoryPrototype.lut.h \
     WebAssemblyModuleConstructor.lut.h \
     WebAssemblyModulePrototype.lut.h \
-    WebAssemblyPrototype.lut.h \
     WebAssemblyRuntimeErrorConstructor.lut.h \
     WebAssemblyRuntimeErrorPrototype.lut.h \
     WebAssemblyTableConstructor.lut.h \
index dd8fe4a..73f6ede 100644 (file)
                AD2FCC1F1DB59CB200B3E736 /* WebAssemblyRuntimeErrorPrototype.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCC131DB59C5900B3E736 /* WebAssemblyRuntimeErrorPrototype.lut.h */; };
                AD2FCC201DB59CB200B3E736 /* WebAssemblyTableConstructor.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCC141DB59C5900B3E736 /* WebAssemblyTableConstructor.lut.h */; };
                AD2FCC211DB59CB200B3E736 /* WebAssemblyTablePrototype.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCC151DB59C5900B3E736 /* WebAssemblyTablePrototype.lut.h */; };
-               AD2FCC2D1DB838FD00B3E736 /* WebAssemblyPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCC271DB838C400B3E736 /* WebAssemblyPrototype.h */; settings = {ATTRIBUTES = (Private, ); }; };
                AD412B341E7B2E9E008AF157 /* WasmContext.h in Headers */ = {isa = PBXBuildFile; fileRef = AD412B321E7B2E8A008AF157 /* WasmContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
                AD4252511E5D0E14009D2A97 /* FullCodeOrigin.h in Headers */ = {isa = PBXBuildFile; fileRef = AD4252501E5D0DEB009D2A97 /* FullCodeOrigin.h */; };
                AD4937C41DDBE6140077C807 /* AbstractModuleRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = AD4937C21DDBE60A0077C807 /* AbstractModuleRecord.h */; settings = {ATTRIBUTES = (Private, ); }; };
                AD2FCC131DB59C5900B3E736 /* WebAssemblyRuntimeErrorPrototype.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAssemblyRuntimeErrorPrototype.lut.h; sourceTree = "<group>"; };
                AD2FCC141DB59C5900B3E736 /* WebAssemblyTableConstructor.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAssemblyTableConstructor.lut.h; sourceTree = "<group>"; };
                AD2FCC151DB59C5900B3E736 /* WebAssemblyTablePrototype.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAssemblyTablePrototype.lut.h; sourceTree = "<group>"; };
-               AD2FCC261DB838C400B3E736 /* WebAssemblyPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebAssemblyPrototype.cpp; path = js/WebAssemblyPrototype.cpp; sourceTree = "<group>"; };
-               AD2FCC271DB838C400B3E736 /* WebAssemblyPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAssemblyPrototype.h; path = js/WebAssemblyPrototype.h; sourceTree = "<group>"; };
                AD2FCC321DC4045300B3E736 /* WasmFormat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmFormat.cpp; sourceTree = "<group>"; };
                AD412B321E7B2E8A008AF157 /* WasmContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmContext.h; sourceTree = "<group>"; };
                AD412B351E7B57C0008AF157 /* AllowMacroScratchRegisterUsageIf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AllowMacroScratchRegisterUsageIf.h; sourceTree = "<group>"; };
                E39D9D841D39000600667282 /* InterpreterInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterpreterInlines.h; sourceTree = "<group>"; };
                E39DA4A41B7E8B7C0084F33A /* JSModuleRecord.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSModuleRecord.cpp; sourceTree = "<group>"; };
                E39DA4A51B7E8B7C0084F33A /* JSModuleRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSModuleRecord.h; sourceTree = "<group>"; };
+               E39E030D22D9EA3E00408C18 /* WebAssembly.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = WebAssembly.js; sourceTree = "<group>"; };
                E39EEAF12281244C008474F4 /* ObjectToStringAdaptiveStructureWatchpoint.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectToStringAdaptiveStructureWatchpoint.cpp; sourceTree = "<group>"; };
                E39EEAF22281244C008474F4 /* ObjectToStringAdaptiveStructureWatchpoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ObjectToStringAdaptiveStructureWatchpoint.h; sourceTree = "<group>"; };
                E3A0531621342B660022EC14 /* WasmStreamingParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmStreamingParser.h; sourceTree = "<group>"; };
                                A1E0451B1C25B4B100BB663C /* StringPrototype.js */,
                                534C457A1BC703DC007476A7 /* TypedArrayConstructor.js */,
                                53917E831B791CB8000EBD33 /* TypedArrayPrototype.js */,
+                               E39E030D22D9EA3E00408C18 /* WebAssembly.js */,
                        );
                        path = builtins;
                        sourceTree = "<group>";
                                AD2FCB9B1DB585A600B3E736 /* WebAssemblyModulePrototype.h */,
                                AD4937C51DDCDCF00077C807 /* WebAssemblyModuleRecord.cpp */,
                                AD4937C61DDCDCF00077C807 /* WebAssemblyModuleRecord.h */,
-                               AD2FCC261DB838C400B3E736 /* WebAssemblyPrototype.cpp */,
-                               AD2FCC271DB838C400B3E736 /* WebAssemblyPrototype.h */,
                                AD2FCBBC1DB58DA400B3E736 /* WebAssemblyRuntimeErrorConstructor.cpp */,
                                AD2FCBBD1DB58DA400B3E736 /* WebAssemblyRuntimeErrorConstructor.h */,
                                AD2FCBBE1DB58DA400B3E736 /* WebAssemblyRuntimeErrorPrototype.cpp */,
                                AD2FCC031DB58DAD00B3E736 /* WebAssemblyModulePrototype.h in Headers */,
                                AD2FCC1D1DB59CB200B3E736 /* WebAssemblyModulePrototype.lut.h in Headers */,
                                AD4937C81DDD0AAE0077C807 /* WebAssemblyModuleRecord.h in Headers */,
-                               AD2FCC2D1DB838FD00B3E736 /* WebAssemblyPrototype.h in Headers */,
                                AD2FCBF91DB58DAD00B3E736 /* WebAssemblyRuntimeErrorConstructor.h in Headers */,
                                AD2FCC1E1DB59CB200B3E736 /* WebAssemblyRuntimeErrorConstructor.lut.h in Headers */,
                                AD2FCBFB1DB58DAD00B3E736 /* WebAssemblyRuntimeErrorPrototype.h in Headers */,
index e41b755..ee54ad9 100644 (file)
@@ -1053,7 +1053,6 @@ wasm/js/WebAssemblyMemoryPrototype.cpp
 wasm/js/WebAssemblyModuleConstructor.cpp
 wasm/js/WebAssemblyModulePrototype.cpp
 wasm/js/WebAssemblyModuleRecord.cpp
-wasm/js/WebAssemblyPrototype.cpp
 wasm/js/WebAssemblyRuntimeErrorConstructor.cpp
 wasm/js/WebAssemblyRuntimeErrorPrototype.cpp
 wasm/js/WebAssemblyTableConstructor.cpp
index 19e5c04..e388fb0 100644 (file)
@@ -51,6 +51,7 @@
 #include "JSCInlines.h"
 #include "JSModuleNamespaceObject.h"
 #include "JSWebAssembly.h"
+#include "JSWebAssemblyModule.h"
 #include "LinkBuffer.h"
 #include "ModuleNamespaceAccessCase.h"
 #include "PolymorphicAccess.h"
@@ -62,6 +63,8 @@
 #include "StructureStubInfo.h"
 #include "SuperSampler.h"
 #include "ThunkGenerators.h"
+#include "WebAssemblyFunction.h"
+#include "WebAssemblyToJSCallee.h"
 #include <wtf/CommaPrinter.h>
 #include <wtf/ListDump.h>
 #include <wtf/StringPrintStream.h>
index eace92b..b7cf0d0 100644 (file)
 #include "JSWeakObjectRef.h"
 #include "JSWeakSet.h"
 #include "JSWebAssembly.h"
+#include "JSWebAssemblyCompileError.h"
+#include "JSWebAssemblyInstance.h"
+#include "JSWebAssemblyLinkError.h"
+#include "JSWebAssemblyMemory.h"
+#include "JSWebAssemblyModule.h"
+#include "JSWebAssemblyRuntimeError.h"
+#include "JSWebAssemblyTable.h"
 #include "JSWithScope.h"
 #include "LazyClassStructureInlines.h"
 #include "LazyPropertyInlines.h"
 #include "WeakObjectRefPrototype.h"
 #include "WeakSetConstructor.h"
 #include "WeakSetPrototype.h"
-#include "WebAssemblyPrototype.h"
+#include "WebAssemblyCompileErrorConstructor.h"
+#include "WebAssemblyCompileErrorPrototype.h"
+#include "WebAssemblyFunction.h"
+#include "WebAssemblyInstanceConstructor.h"
+#include "WebAssemblyInstancePrototype.h"
+#include "WebAssemblyLinkErrorConstructor.h"
+#include "WebAssemblyLinkErrorPrototype.h"
+#include "WebAssemblyMemoryConstructor.h"
+#include "WebAssemblyMemoryPrototype.h"
+#include "WebAssemblyModuleConstructor.h"
+#include "WebAssemblyModulePrototype.h"
+#include "WebAssemblyModuleRecord.h"
+#include "WebAssemblyRuntimeErrorConstructor.h"
+#include "WebAssemblyRuntimeErrorPrototype.h"
+#include "WebAssemblyTableConstructor.h"
+#include "WebAssemblyTablePrototype.h"
 #include "WebAssemblyToJSCallee.h"
 #include <wtf/RandomNumber.h>
 
@@ -1060,7 +1082,6 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
 
 #if ENABLE(WEBASSEMBLY)
     if (Wasm::isSupported()) {
-        auto* webAssemblyPrototype = WebAssemblyPrototype::create(vm, this, WebAssemblyPrototype::createStructure(vm, this, m_objectPrototype.get()));
         m_webAssemblyModuleRecordStructure.initLater(
             [] (const Initializer<Structure>& init) {
                 init.set(WebAssemblyModuleRecord::createStructure(init.vm, init.owner, init.owner->m_objectPrototype.get()));
@@ -1081,7 +1102,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
             [] (const Initializer<Structure>& init) {
                 init.set(WebAssemblyToJSCallee::createStructure(init.vm, init.owner, jsNull()));
             });
-        auto* webAssembly = JSWebAssembly::create(vm, this, JSWebAssembly::createStructure(vm, this, webAssemblyPrototype));
+        auto* webAssembly = JSWebAssembly::create(vm, this, JSWebAssembly::createStructure(vm, this, m_objectPrototype.get()));
         putDirectWithoutTransition(vm, Identifier::fromString(exec, "WebAssembly"), webAssembly, static_cast<unsigned>(PropertyAttribute::DontEnum));
 
 #define CREATE_WEBASSEMBLY_PROTOTYPE(capitalName, lowerName, properName, instanceType, jsName, prototypeBase) \
index fad7c7a..fe5d601 100644 (file)
 #include "JSModuleNamespaceObject.h"
 #include "JSModuleRecord.h"
 #include "JSSourceCode.h"
+#include "JSWebAssembly.h"
 #include "ModuleAnalyzer.h"
 #include "Nodes.h"
 #include "ObjectConstructor.h"
 #include "Parser.h"
 #include "ParserError.h"
-#include "WebAssemblyPrototype.h"
 
 namespace JSC {
 
@@ -413,7 +413,7 @@ EncodedJSValue JSC_HOST_CALL moduleLoaderParseModule(ExecState* exec)
 
 #if ENABLE(WEBASSEMBLY)
     if (sourceCode.provider()->sourceType() == SourceProviderSourceType::WebAssembly)
-        return JSValue::encode(WebAssemblyPrototype::instantiate(exec, deferred, moduleKey, jsSourceCode));
+        return JSValue::encode(JSWebAssembly::instantiate(exec, deferred, moduleKey, jsSourceCode));
 #endif
 
     CodeProfiling profile(sourceCode);
index b9d4f32..9cbb0bb 100644 (file)
 
 #if ENABLE(WEBASSEMBLY)
 
+#include "CatchScope.h"
+#include "Exception.h"
+#include "FunctionPrototype.h"
+#include "JSCBuiltins.h"
 #include "JSCInlines.h"
+#include "JSModuleNamespaceObject.h"
+#include "JSPromiseDeferred.h"
+#include "JSToWasm.h"
+#include "JSWebAssemblyHelpers.h"
+#include "JSWebAssemblyInstance.h"
+#include "JSWebAssemblyModule.h"
+#include "ObjectConstructor.h"
+#include "Options.h"
+#include "PromiseDeferredTimer.h"
+#include "StrongInlines.h"
+#include "ThrowScope.h"
+#include "WasmBBQPlan.h"
+#include "WasmToJS.h"
+#include "WasmWorklist.h"
+#include "WebAssemblyInstanceConstructor.h"
+#include "WebAssemblyModuleConstructor.h"
+
+using JSC::Wasm::Plan;
+using JSC::Wasm::BBQPlan;
 
 namespace JSC {
 
@@ -46,16 +69,20 @@ FOR_EACH_WEBASSEMBLY_CONSTRUCTOR_TYPE(DEFINE_CALLBACK_FOR_CONSTRUCTOR)
 
 #undef DEFINE_CALLBACK_FOR_CONSTRUCTOR
 
+static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState*);
+static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState*);
+static EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState*);
+
 }
 
 #include "JSWebAssembly.lut.h"
 
 namespace JSC {
 
-const ClassInfo JSWebAssembly::s_info = { "WebAssembly", &Base::s_info, &jsWebAssemblyTable, nullptr, CREATE_METHOD_TABLE(JSWebAssembly) };
+const ClassInfo JSWebAssembly::s_info = { "WebAssembly", &Base::s_info, &webAssemblyTable, nullptr, CREATE_METHOD_TABLE(JSWebAssembly) };
 
 /* Source for JSWebAssembly.lut.h
-@begin jsWebAssemblyTable
+@begin webAssemblyTable
   CompileError    createWebAssemblyCompileError  DontEnum|PropertyCallback
   Instance        createWebAssemblyInstance      DontEnum|PropertyCallback
   LinkError       createWebAssemblyLinkError     DontEnum|PropertyCallback
@@ -63,13 +90,16 @@ const ClassInfo JSWebAssembly::s_info = { "WebAssembly", &Base::s_info, &jsWebAs
   Module          createWebAssemblyModule        DontEnum|PropertyCallback
   RuntimeError    createWebAssemblyRuntimeError  DontEnum|PropertyCallback
   Table           createWebAssemblyTable         DontEnum|PropertyCallback
+  compile         webAssemblyCompileFunc         Function 1
+  instantiate     webAssemblyInstantiateFunc     Function 1
+  validate        webAssemblyValidateFunc        Function 1
 @end
 */
 
-JSWebAssembly* JSWebAssembly::create(VM& vm, JSGlobalObject*, Structure* structure)
+JSWebAssembly* JSWebAssembly::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
 {
     auto* object = new (NotNull, allocateCell<JSWebAssembly>(vm.heap)) JSWebAssembly(vm, structure);
-    object->finishCreation(vm);
+    object->finishCreation(vm, globalObject);
     return object;
 }
 
@@ -78,10 +108,14 @@ Structure* JSWebAssembly::createStructure(VM& vm, JSGlobalObject* globalObject,
     return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
 }
 
-void JSWebAssembly::finishCreation(VM& vm)
+void JSWebAssembly::finishCreation(VM& vm, JSGlobalObject* globalObject)
 {
     Base::finishCreation(vm);
     ASSERT(inherits(vm, info()));
+    if (Options::useWebAssemblyStreamingApi()) {
+        JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("compileStreaming", webAssemblyCompileStreamingCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
+        JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("instantiateStreaming", webAssemblyInstantiateStreamingCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
+    }
 }
 
 JSWebAssembly::JSWebAssembly(VM& vm, Structure* structure)
@@ -89,6 +123,291 @@ JSWebAssembly::JSWebAssembly(VM& vm, Structure* structure)
 {
 }
 
+static void reject(ExecState* exec, CatchScope& catchScope, JSPromiseDeferred* promise)
+{
+    Exception* exception = catchScope.exception();
+    ASSERT(exception);
+    catchScope.clearException();
+    promise->reject(exec, exception->value());
+    CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, void());
+}
+
+static void webAssemblyModuleValidateAsyncInternal(ExecState* exec, JSPromiseDeferred* promise, Vector<uint8_t>&& source)
+{
+    VM& vm = exec->vm();
+    auto* globalObject = exec->lexicalGlobalObject();
+
+    Vector<Strong<JSCell>> dependencies;
+    dependencies.append(Strong<JSCell>(vm, globalObject));
+
+    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+
+    Wasm::Module::validateAsync(&vm.wasmContext, WTFMove(source), createSharedTask<Wasm::Module::CallbackType>([promise, globalObject, &vm] (Wasm::Module::ValidationResult&& result) mutable {
+        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, globalObject, result = WTFMove(result), &vm] () mutable {
+            auto scope = DECLARE_CATCH_SCOPE(vm);
+            ExecState* exec = globalObject->globalExec();
+            JSValue module = JSWebAssemblyModule::createStub(vm, exec, globalObject->webAssemblyModuleStructure(), WTFMove(result));
+            if (UNLIKELY(scope.exception())) {
+                reject(exec, scope, promise);
+                return;
+            }
+
+            promise->resolve(exec, module);
+            CLEAR_AND_RETURN_IF_EXCEPTION(scope, void());
+        });
+    }));
+}
+
+static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState* exec)
+{
+    VM& vm = exec->vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    auto* globalObject = exec->lexicalGlobalObject();
+
+    JSPromiseDeferred* promise = JSPromiseDeferred::tryCreate(exec, globalObject);
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+    {
+        auto catchScope = DECLARE_CATCH_SCOPE(vm);
+        Vector<uint8_t> source = createSourceBufferFromValue(vm, exec, exec->argument(0));
+
+        if (UNLIKELY(catchScope.exception()))
+            reject(exec, catchScope, promise);
+        else
+            webAssemblyModuleValidateAsyncInternal(exec, promise, WTFMove(source));
+
+        return JSValue::encode(promise->promise());
+    }
+}
+
+enum class Resolve { WithInstance, WithModuleRecord, WithModuleAndInstance };
+static void resolve(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSWebAssemblyInstance* instance, JSWebAssemblyModule* module, JSObject* importObject, Ref<Wasm::CodeBlock>&& codeBlock, Resolve resolveKind, Wasm::CreationMode creationMode)
+{
+    auto scope = DECLARE_CATCH_SCOPE(vm);
+    instance->finalizeCreation(vm, exec, WTFMove(codeBlock), importObject, creationMode);
+    RETURN_IF_EXCEPTION(scope, reject(exec, scope, promise));
+
+    if (resolveKind == Resolve::WithInstance)
+        promise->resolve(exec, instance);
+    else if (resolveKind == Resolve::WithModuleRecord) {
+        auto* moduleRecord = instance->moduleNamespaceObject()->moduleRecord();
+        if (Options::dumpModuleRecord())
+            moduleRecord->dump();
+        promise->resolve(exec, moduleRecord);
+    } else {
+        JSObject* result = constructEmptyObject(exec);
+        result->putDirect(vm, Identifier::fromString(&vm, "module"_s), module);
+        result->putDirect(vm, Identifier::fromString(&vm, "instance"_s), instance);
+        promise->resolve(exec, result);
+    }
+    CLEAR_AND_RETURN_IF_EXCEPTION(scope, void());
+}
+
+void JSWebAssembly::webAssemblyModuleValidateAsync(ExecState* exec, JSPromiseDeferred* promise, Vector<uint8_t>&& source)
+{
+    VM& vm = exec->vm();
+    auto catchScope = DECLARE_CATCH_SCOPE(vm);
+    webAssemblyModuleValidateAsyncInternal(exec, promise, WTFMove(source));
+    CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, void());
+}
+
+static void instantiate(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSWebAssemblyModule* module, JSObject* importObject, const Identifier& moduleKey, Resolve resolveKind, Wasm::CreationMode creationMode)
+{
+    auto scope = DECLARE_CATCH_SCOPE(vm);
+    // In order to avoid potentially recompiling a module. We first gather all the import/memory information prior to compiling code.
+    JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, exec, moduleKey, module, importObject, exec->lexicalGlobalObject()->webAssemblyInstanceStructure(), Ref<Wasm::Module>(module->module()), creationMode);
+    RETURN_IF_EXCEPTION(scope, reject(exec, scope, promise));
+
+    Vector<Strong<JSCell>> dependencies;
+    // The instance keeps the module alive.
+    dependencies.append(Strong<JSCell>(vm, instance));
+    dependencies.append(Strong<JSCell>(vm, importObject));
+    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+    // Note: This completion task may or may not get called immediately.
+    module->module().compileAsync(&vm.wasmContext, instance->memoryMode(), createSharedTask<Wasm::CodeBlock::CallbackType>([promise, instance, module, importObject, resolveKind, creationMode, &vm] (Ref<Wasm::CodeBlock>&& refCodeBlock) mutable {
+        RefPtr<Wasm::CodeBlock> codeBlock = WTFMove(refCodeBlock);
+        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, instance, module, importObject, resolveKind, creationMode, &vm, codeBlock = WTFMove(codeBlock)] () mutable {
+            ExecState* exec = instance->globalObject(vm)->globalExec();
+            resolve(vm, exec, promise, instance, module, importObject, codeBlock.releaseNonNull(), resolveKind, creationMode);
+        });
+    }), &Wasm::createJSToWasmWrapper, &Wasm::wasmToJSException);
+}
+
+static void compileAndInstantiate(VM& vm, ExecState* exec, JSPromiseDeferred* promise, const Identifier& moduleKey, JSValue buffer, JSObject* importObject, Resolve resolveKind, Wasm::CreationMode creationMode)
+{
+    auto scope = DECLARE_CATCH_SCOPE(vm);
+
+    auto* globalObject = exec->lexicalGlobalObject();
+
+    JSCell* moduleKeyCell = identifierToJSValue(vm, moduleKey).asCell();
+    Vector<Strong<JSCell>> dependencies;
+    dependencies.append(Strong<JSCell>(vm, importObject));
+    dependencies.append(Strong<JSCell>(vm, moduleKeyCell));
+    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+
+    Vector<uint8_t> source = createSourceBufferFromValue(vm, exec, buffer);
+    RETURN_IF_EXCEPTION(scope, reject(exec, scope, promise));
+
+    Wasm::Module::validateAsync(&vm.wasmContext, WTFMove(source), createSharedTask<Wasm::Module::CallbackType>([promise, importObject, moduleKeyCell, globalObject, resolveKind, creationMode, &vm] (Wasm::Module::ValidationResult&& result) mutable {
+        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, importObject, moduleKeyCell, globalObject, result = WTFMove(result), resolveKind, creationMode, &vm] () mutable {
+            auto scope = DECLARE_CATCH_SCOPE(vm);
+            ExecState* exec = globalObject->globalExec();
+            JSWebAssemblyModule* module = JSWebAssemblyModule::createStub(vm, exec, globalObject->webAssemblyModuleStructure(), WTFMove(result));
+            if (UNLIKELY(scope.exception()))
+                return reject(exec, scope, promise);
+
+            const Identifier moduleKey = JSValue(moduleKeyCell).toPropertyKey(exec);
+            if (UNLIKELY(scope.exception()))
+                return reject(exec, scope, promise);
+
+            instantiate(vm, exec, promise, module, importObject, moduleKey, resolveKind, creationMode);
+        });
+    }));
+}
+
+JSValue JSWebAssembly::instantiate(ExecState* exec, JSPromiseDeferred* promise, const Identifier& moduleKey, JSValue argument)
+{
+    VM& vm = exec->vm();
+    compileAndInstantiate(vm, exec, promise, moduleKey, argument, nullptr, Resolve::WithModuleRecord, Wasm::CreationMode::FromModuleLoader);
+    return promise->promise();
+}
+
+static void webAssemblyModuleInstantinateAsyncInternal(ExecState* exec, JSPromiseDeferred* promise, Vector<uint8_t>&& source, JSObject* importObject)
+{
+    auto* globalObject = exec->lexicalGlobalObject();
+    VM& vm = exec->vm();
+
+    Vector<Strong<JSCell>> dependencies;
+    dependencies.append(Strong<JSCell>(vm, importObject));
+    dependencies.append(Strong<JSCell>(vm, globalObject));
+    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+
+    Wasm::Module::validateAsync(&vm.wasmContext, WTFMove(source), createSharedTask<Wasm::Module::CallbackType>([promise, importObject, globalObject, &vm] (Wasm::Module::ValidationResult&& result) mutable {
+        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, importObject, globalObject, result = WTFMove(result), &vm] () mutable {
+            auto scope = DECLARE_CATCH_SCOPE(vm);
+            ExecState* exec = globalObject->globalExec();
+            JSWebAssemblyModule* module = JSWebAssemblyModule::createStub(vm, exec, globalObject->webAssemblyModuleStructure(), WTFMove(result));
+            if (UNLIKELY(scope.exception()))
+                return reject(exec, scope, promise);
+
+            instantiate(vm, exec, promise, module, importObject, JSWebAssemblyInstance::createPrivateModuleKey(),  Resolve::WithModuleAndInstance, Wasm::CreationMode::FromJS);
+            CLEAR_AND_RETURN_IF_EXCEPTION(scope, reject(exec, scope, promise));
+        });
+    }));
+}
+
+void JSWebAssembly::webAssemblyModuleInstantinateAsync(ExecState* exec, JSPromiseDeferred* promise, Vector<uint8_t>&& source, JSObject* importedObject)
+{
+    VM& vm = exec->vm();
+    auto catchScope = DECLARE_CATCH_SCOPE(vm);
+    webAssemblyModuleInstantinateAsyncInternal(exec, promise, WTFMove(source), importedObject);
+    CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, void());
+}
+
+static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState* exec)
+{
+    VM& vm = exec->vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    auto* globalObject = exec->lexicalGlobalObject();
+
+    JSPromiseDeferred* promise = JSPromiseDeferred::tryCreate(exec, globalObject);
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+    {
+        auto catchScope = DECLARE_CATCH_SCOPE(vm);
+
+        JSValue importArgument = exec->argument(1);
+        JSObject* importObject = importArgument.getObject();
+        if (UNLIKELY(!importArgument.isUndefined() && !importObject)) {
+            promise->reject(exec, createTypeError(exec,
+                "second argument to WebAssembly.instantiate must be undefined or an Object"_s, defaultSourceAppender, runtimeTypeForValue(vm, importArgument)));
+            CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise->promise()));
+        } else {
+            JSValue firstArgument = exec->argument(0);
+            if (auto* module = jsDynamicCast<JSWebAssemblyModule*>(vm, firstArgument))
+                instantiate(vm, exec, promise, module, importObject, JSWebAssemblyInstance::createPrivateModuleKey(), Resolve::WithInstance, Wasm::CreationMode::FromJS);
+            else
+                compileAndInstantiate(vm, exec, promise, JSWebAssemblyInstance::createPrivateModuleKey(), firstArgument, importObject, Resolve::WithModuleAndInstance, Wasm::CreationMode::FromJS);
+        }
+
+        return JSValue::encode(promise->promise());
+    }
+}
+
+static EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState* exec)
+{
+    VM& vm = exec->vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+
+    auto [base, byteSize] = getWasmBufferFromValue(exec, exec->argument(0));
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
+    BBQPlan plan(&vm.wasmContext, BBQPlan::Validation, Plan::dontFinalize());
+    // FIXME: We might want to throw an OOM exception here if we detect that something will OOM.
+    // https://bugs.webkit.org/show_bug.cgi?id=166015
+    return JSValue::encode(jsBoolean(plan.parseAndValidateModule(base, byteSize)));
+}
+
+EncodedJSValue JSC_HOST_CALL webAssemblyCompileStreamingInternal(ExecState* exec)
+{
+    VM& vm = exec->vm();
+    auto* globalObject = exec->lexicalGlobalObject();
+    auto catchScope = DECLARE_CATCH_SCOPE(vm);
+
+    JSPromiseDeferred* promise = JSPromiseDeferred::tryCreate(exec, globalObject);
+
+    Vector<Strong<JSCell>> dependencies;
+    dependencies.append(Strong<JSCell>(vm, globalObject));
+    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+
+    if (globalObject->globalObjectMethodTable()->compileStreaming)
+        globalObject->globalObjectMethodTable()->compileStreaming(globalObject, exec, promise, exec->argument(0));
+    else {
+        // CompileStreaming is not supported in jsc, only in browser environment
+        ASSERT_NOT_REACHED();
+    }
+
+    CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise->promise()));
+
+    return JSValue::encode(promise->promise());
+}
+
+EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateStreamingInternal(ExecState* exec)
+{
+    VM& vm = exec->vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    auto* globalObject = exec->lexicalGlobalObject();
+
+    JSPromiseDeferred* promise = JSPromiseDeferred::tryCreate(exec, globalObject);
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    {
+        auto catchScope = DECLARE_CATCH_SCOPE(vm);
+
+        JSValue importArgument = exec->argument(1);
+        JSObject* importObject = importArgument.getObject();
+        if (UNLIKELY(!importArgument.isUndefined() && !importObject)) {
+            promise->reject(exec, createTypeError(exec,
+                "second argument to WebAssembly.instantiateStreaming must be undefined or an Object"_s, defaultSourceAppender, runtimeTypeForValue(vm, importArgument)));
+            CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise->promise()));
+        } else {
+            if (globalObject->globalObjectMethodTable()->instantiateStreaming) {
+                Vector<Strong<JSCell>> dependencies;
+                dependencies.append(Strong<JSCell>(vm, globalObject));
+                dependencies.append(Strong<JSCell>(vm, importObject));
+                vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
+
+                // FIXME: <http://webkit.org/b/184888> if there's an importObject and it contains a Memory, then we can compile the module with the right memory type (fast or not) by looking at the memory's type.
+                globalObject->globalObjectMethodTable()->instantiateStreaming(globalObject, exec, promise, exec->argument(0), importObject);
+            } else {
+                // InstantiateStreaming is not supported in jsc, only in browser environment.
+                ASSERT_NOT_REACHED();
+            }
+        }
+        CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, JSValue::encode(promise->promise()));
+
+        return JSValue::encode(promise->promise());
+    }
+}
+
 } // namespace JSC
 
 #endif // ENABLE(WEBASSEMBLY)
index fb257e3..fd409af 100644 (file)
 #if ENABLE(WEBASSEMBLY)
 
 #include "JSObject.h"
-#include "JSWebAssemblyCompileError.h"
-#include "JSWebAssemblyInstance.h"
-#include "JSWebAssemblyLinkError.h"
-#include "JSWebAssemblyMemory.h"
-#include "JSWebAssemblyModule.h"
-#include "JSWebAssemblyRuntimeError.h"
-#include "JSWebAssemblyTable.h"
-#include "WebAssemblyCompileErrorConstructor.h"
-#include "WebAssemblyCompileErrorPrototype.h"
-#include "WebAssemblyFunction.h"
-#include "WebAssemblyInstanceConstructor.h"
-#include "WebAssemblyInstancePrototype.h"
-#include "WebAssemblyLinkErrorConstructor.h"
-#include "WebAssemblyLinkErrorPrototype.h"
-#include "WebAssemblyMemoryConstructor.h"
-#include "WebAssemblyMemoryPrototype.h"
-#include "WebAssemblyModuleConstructor.h"
-#include "WebAssemblyModulePrototype.h"
-#include "WebAssemblyModuleRecord.h"
-#include "WebAssemblyPrototype.h"
-#include "WebAssemblyRuntimeErrorConstructor.h"
-#include "WebAssemblyRuntimeErrorPrototype.h"
-#include "WebAssemblyTableConstructor.h"
-#include "WebAssemblyTablePrototype.h"
-#include "WebAssemblyToJSCallee.h"
+#include "JSPromiseDeferred.h"
 
 namespace JSC {
 
@@ -66,13 +42,20 @@ public:
 
     DECLARE_INFO;
 
+    JS_EXPORT_PRIVATE static void webAssemblyModuleValidateAsync(ExecState*, JSPromiseDeferred*, Vector<uint8_t>&&);
+    JS_EXPORT_PRIVATE static void webAssemblyModuleInstantinateAsync(ExecState*, JSPromiseDeferred*, Vector<uint8_t>&&, JSObject*);
+    static JSValue instantiate(ExecState*, JSPromiseDeferred*, const Identifier&, JSValue);
+
 protected:
-    void finishCreation(VM&);
+    void finishCreation(VM&, JSGlobalObject*);
 
 private:
     JSWebAssembly(VM&, Structure*);
 };
 
+EncodedJSValue JSC_HOST_CALL webAssemblyCompileStreamingInternal(ExecState*);
+EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateStreamingInternal(ExecState*);
+
 } // namespace JSC
 
 #endif // ENABLE(WEBASSEMBLY)
index 95ffa17..4311680 100644 (file)
@@ -39,15 +39,21 @@ ALWAYS_INLINE uint32_t toNonWrappingUint32(ExecState* exec, JSValue value)
 {
     VM& vm = exec->vm();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
-    double doubleValue = value.toInteger(exec);
+
+    if (value.isUInt32())
+        return value.asUInt32();
+
+    double doubleValue = value.toNumber(exec);
     RETURN_IF_EXCEPTION(throwScope, { });
-    if (doubleValue < 0 || doubleValue > UINT_MAX) {
-        throwException(exec, throwScope,
-            createRangeError(exec, "Expect an integer argument in the range: [0, 2^32 - 1]"_s));
-        return { };
+
+    if (!std::isnan(doubleValue) && !std::isinf(doubleValue)) {
+        double truncedValue = trunc(doubleValue);
+        if (truncedValue >= 0 && truncedValue <= UINT_MAX)
+            return static_cast<uint32_t>(truncedValue);
     }
 
-    return static_cast<uint32_t>(doubleValue);
+    throwException(exec, throwScope, createTypeError(exec, "Expect an integer argument in the range: [0, 2^32 - 1]"_s));
+    return { };
 }
 
 ALWAYS_INLINE std::pair<const uint8_t*, size_t> getWasmBufferFromValue(ExecState* exec, JSValue value)
index 7d70795..7f2d17d 100644 (file)
@@ -77,7 +77,7 @@ void WebAssemblyCompileErrorConstructor::finishCreation(VM& vm, WebAssemblyCompi
 {
     Base::finishCreation(vm, "CompileError"_s, NameVisibility::Visible, NameAdditionMode::WithoutStructureTransition);
     putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
-    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
+    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
 }
 
 WebAssemblyCompileErrorConstructor::WebAssemblyCompileErrorConstructor(VM& vm, Structure* structure)
index 548a3f9..6842f95 100644 (file)
@@ -108,7 +108,7 @@ void WebAssemblyInstanceConstructor::finishCreation(VM& vm, WebAssemblyInstanceP
 {
     Base::finishCreation(vm, "Instance"_s, NameVisibility::Visible, NameAdditionMode::WithoutStructureTransition);
     putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
-    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
+    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
 }
 
 WebAssemblyInstanceConstructor::WebAssemblyInstanceConstructor(VM& vm, Structure* structure)
index 10c2fec..f81b2a1 100644 (file)
@@ -45,7 +45,7 @@ const ClassInfo WebAssemblyInstancePrototype::s_info = { "WebAssembly.Instance",
 
 /* Source for WebAssemblyInstancePrototype.lut.h
  @begin prototypeTableWebAssemblyInstance
- exports webAssemblyInstanceProtoFuncExports DontEnum|Accessor 0
+ exports webAssemblyInstanceProtoFuncExports Accessor 0
  @end
  */
 
index 26202b8..473c263 100644 (file)
@@ -77,7 +77,7 @@ void WebAssemblyLinkErrorConstructor::finishCreation(VM& vm, WebAssemblyLinkErro
 {
     Base::finishCreation(vm, "LinkError"_s, NameVisibility::Visible, NameAdditionMode::WithoutStructureTransition);
     putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
-    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
+    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
 }
 
 WebAssemblyLinkErrorConstructor::WebAssemblyLinkErrorConstructor(VM& vm, Structure* structure)
index 86f9d8b..2405989 100644 (file)
@@ -79,12 +79,12 @@ static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyMemory(ExecState* exec
 
     Wasm::PageCount maximumPageCount;
     {
+        // In WebIDL, "present" means that [[Get]] result is undefined, not [[HasProperty]] result.
+        // https://heycam.github.io/webidl/#idl-dictionaries
         Identifier maximum = Identifier::fromString(&vm, "maximum");
-        bool hasProperty = memoryDescriptor->hasProperty(exec, maximum);
+        JSValue maxSizeValue = memoryDescriptor->get(exec, maximum);
         RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
-        if (hasProperty) {
-            JSValue maxSizeValue = memoryDescriptor->get(exec, maximum);
-            RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+        if (!maxSizeValue.isUndefined()) {
             uint32_t size = toNonWrappingUint32(exec, maxSizeValue);
             RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
             if (!Wasm::PageCount::isValid(size))
@@ -136,7 +136,7 @@ void WebAssemblyMemoryConstructor::finishCreation(VM& vm, WebAssemblyMemoryProto
 {
     Base::finishCreation(vm, "Memory"_s, NameVisibility::Visible, NameAdditionMode::WithoutStructureTransition);
     putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
-    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
+    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
 }
 
 WebAssemblyMemoryConstructor::WebAssemblyMemoryConstructor(VM& vm, Structure* structure)
index 082b08d..1441a9b 100644 (file)
@@ -48,8 +48,8 @@ const ClassInfo WebAssemblyMemoryPrototype::s_info = { "WebAssembly.Memory", &Ba
 
 /* Source for WebAssemblyMemoryPrototype.lut.h
 @begin prototypeTableWebAssemblyMemory
- grow   webAssemblyMemoryProtoFuncGrow   DontEnum|Function 1
- buffer webAssemblyMemoryProtoFuncBuffer DontEnum|Accessor 0
+ grow   webAssemblyMemoryProtoFuncGrow   Function 1
+ buffer webAssemblyMemoryProtoFuncBuffer Accessor 0
 @end
 */
 
index d96c4ec..730f4ec 100644 (file)
@@ -59,9 +59,9 @@ const ClassInfo WebAssemblyModuleConstructor::s_info = { "Function", &Base::s_in
 
 /* Source for WebAssemblyModuleConstructor.lut.h
  @begin constructorTableWebAssemblyModule
- customSections webAssemblyModuleCustomSections DontEnum|Function 2
- imports        webAssemblyModuleImports        DontEnum|Function 1
- exports        webAssemblyModuleExports        DontEnum|Function 1
+ customSections webAssemblyModuleCustomSections Function 2
+ imports        webAssemblyModuleImports        Function 1
+ exports        webAssemblyModuleExports        Function 1
  @end
  */
 
@@ -71,11 +71,14 @@ EncodedJSValue JSC_HOST_CALL webAssemblyModuleCustomSections(ExecState* exec)
     auto* globalObject = exec->lexicalGlobalObject();
     auto throwScope = DECLARE_THROW_SCOPE(vm);
 
-    JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->argument(0));
+    if (UNLIKELY(exec->argumentCount() < 2))
+        return JSValue::encode(throwException(exec, throwScope, createNotEnoughArgumentsError(exec)));
+
+    JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->uncheckedArgument(0));
     if (!module)
         return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, "WebAssembly.Module.customSections called with non WebAssembly.Module argument"_s)));
 
-    const String sectionNameString = exec->argument(1).getString(exec);
+    const String sectionNameString = exec->uncheckedArgument(1).getString(exec);
     RETURN_IF_EXCEPTION(throwScope, { });
 
     JSArray* result = constructEmptyArray(exec, nullptr, globalObject);
@@ -203,7 +206,7 @@ void WebAssemblyModuleConstructor::finishCreation(VM& vm, WebAssemblyModuleProto
 {
     Base::finishCreation(vm, "Module"_s, NameVisibility::Visible, NameAdditionMode::WithoutStructureTransition);
     putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
-    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
+    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
 }
 
 WebAssemblyModuleConstructor::WebAssemblyModuleConstructor(VM& vm, Structure* structure)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp
deleted file mode 100644 (file)
index 8a44433..0000000
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
- * Copyright (C) 2018 Oleksandr Skachkov <gskachkov@gmail.com>.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "WebAssemblyPrototype.h"
-
-#if ENABLE(WEBASSEMBLY)
-
-#include "CatchScope.h"
-#include "Exception.h"
-#include "FunctionPrototype.h"
-#include "JSCBuiltins.h"
-#include "JSCInlines.h"
-#include "JSModuleNamespaceObject.h"
-#include "JSPromiseDeferred.h"
-#include "JSToWasm.h"
-#include "JSWebAssemblyHelpers.h"
-#include "JSWebAssemblyInstance.h"
-#include "JSWebAssemblyModule.h"
-#include "ObjectConstructor.h"
-#include "Options.h"
-#include "PromiseDeferredTimer.h"
-#include "StrongInlines.h"
-#include "ThrowScope.h"
-#include "WasmBBQPlan.h"
-#include "WasmToJS.h"
-#include "WasmWorklist.h"
-#include "WebAssemblyInstanceConstructor.h"
-#include "WebAssemblyModuleConstructor.h"
-
-using JSC::Wasm::Plan;
-using JSC::Wasm::BBQPlan;
-
-namespace JSC {
-static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState*);
-static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState*);
-static EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState*);
-}
-
-#include "WebAssemblyPrototype.lut.h"
-
-namespace JSC {
-
-const ClassInfo WebAssemblyPrototype::s_info = { "WebAssembly", &Base::s_info, &prototypeTableWebAssembly, nullptr, CREATE_METHOD_TABLE(WebAssemblyPrototype) };
-
-/* Source for WebAssemblyPrototype.lut.h
- @begin prototypeTableWebAssembly
- compile     webAssemblyCompileFunc     DontEnum|Function 1
- instantiate webAssemblyInstantiateFunc DontEnum|Function 1
- validate    webAssemblyValidateFunc    DontEnum|Function 1
- @end
- */
-
-static void reject(ExecState* exec, CatchScope& catchScope, JSPromiseDeferred* promise)
-{
-    Exception* exception = catchScope.exception();
-    ASSERT(exception);
-    catchScope.clearException();
-    promise->reject(exec, exception->value());
-    CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, void());
-}
-
-static void webAssemblyModuleValidateAsyncInternal(ExecState* exec, JSPromiseDeferred* promise, Vector<uint8_t>&& source)
-{
-    VM& vm = exec->vm();
-    auto* globalObject = exec->lexicalGlobalObject();
-
-    Vector<Strong<JSCell>> dependencies;
-    dependencies.append(Strong<JSCell>(vm, globalObject));
-
-    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
-
-    Wasm::Module::validateAsync(&vm.wasmContext, WTFMove(source), createSharedTask<Wasm::Module::CallbackType>([promise, globalObject, &vm] (Wasm::Module::ValidationResult&& result) mutable {
-        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, globalObject, result = WTFMove(result), &vm] () mutable {
-            auto scope = DECLARE_CATCH_SCOPE(vm);
-            ExecState* exec = globalObject->globalExec();
-            JSValue module = JSWebAssemblyModule::createStub(vm, exec, globalObject->webAssemblyModuleStructure(), WTFMove(result));
-            if (UNLIKELY(scope.exception())) {
-                reject(exec, scope, promise);
-                return;
-            }
-
-            promise->resolve(exec, module);
-            CLEAR_AND_RETURN_IF_EXCEPTION(scope, void());
-        });
-    }));
-}
-
-static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState* exec)
-{
-    VM& vm = exec->vm();
-    auto throwScope = DECLARE_THROW_SCOPE(vm);
-    auto* globalObject = exec->lexicalGlobalObject();
-
-    JSPromiseDeferred* promise = JSPromiseDeferred::tryCreate(exec, globalObject);
-    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
-
-    {
-        auto catchScope = DECLARE_CATCH_SCOPE(vm);
-        Vector<uint8_t> source = createSourceBufferFromValue(vm, exec, exec->argument(0));
-
-        if (UNLIKELY(catchScope.exception()))
-            reject(exec, catchScope, promise);
-        else
-            webAssemblyModuleValidateAsyncInternal(exec, promise, WTFMove(source));
-
-        return JSValue::encode(promise->promise());
-    }
-}
-
-enum class Resolve { WithInstance, WithModuleRecord, WithModuleAndInstance };
-static void resolve(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSWebAssemblyInstance* instance, JSWebAssemblyModule* module, JSObject* importObject, Ref<Wasm::CodeBlock>&& codeBlock, Resolve resolveKind, Wasm::CreationMode creationMode)
-{
-    auto scope = DECLARE_CATCH_SCOPE(vm);
-    instance->finalizeCreation(vm, exec, WTFMove(codeBlock), importObject, creationMode);
-    RETURN_IF_EXCEPTION(scope, reject(exec, scope, promise));
-
-    if (resolveKind == Resolve::WithInstance)
-        promise->resolve(exec, instance);
-    else if (resolveKind == Resolve::WithModuleRecord) {
-        auto* moduleRecord = instance->moduleNamespaceObject()->moduleRecord();
-        if (Options::dumpModuleRecord())
-            moduleRecord->dump();
-        promise->resolve(exec, moduleRecord);
-    } else {
-        JSObject* result = constructEmptyObject(exec);
-        result->putDirect(vm, Identifier::fromString(&vm, "module"_s), module);
-        result->putDirect(vm, Identifier::fromString(&vm, "instance"_s), instance);
-        promise->resolve(exec, result);
-    }
-    CLEAR_AND_RETURN_IF_EXCEPTION(scope, void());
-}
-
-void WebAssemblyPrototype::webAssemblyModuleValidateAsync(ExecState* exec, JSPromiseDeferred* promise, Vector<uint8_t>&& source)
-{
-    VM& vm = exec->vm();
-    auto catchScope = DECLARE_CATCH_SCOPE(vm);
-    webAssemblyModuleValidateAsyncInternal(exec, promise, WTFMove(source));
-    CLEAR_AND_RETURN_IF_EXCEPTION(catchScope, void());
-}
-
-static void instantiate(VM& vm, ExecState* exec, JSPromiseDeferred* promise, JSWebAssemblyModule* module, JSObject* importObject, const Identifier& moduleKey, Resolve resolveKind, Wasm::CreationMode creationMode)
-{
-    auto scope = DECLARE_CATCH_SCOPE(vm);
-    // In order to avoid potentially recompiling a module. We first gather all the import/memory information prior to compiling code.
-    JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, exec, moduleKey, module, importObject, exec->lexicalGlobalObject()->webAssemblyInstanceStructure(), Ref<Wasm::Module>(module->module()), creationMode);
-    RETURN_IF_EXCEPTION(scope, reject(exec, scope, promise));
-
-    Vector<Strong<JSCell>> dependencies;
-    // The instance keeps the module alive.
-    dependencies.append(Strong<JSCell>(vm, instance));
-    dependencies.append(Strong<JSCell>(vm, importObject));
-    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
-    // Note: This completion task may or may not get called immediately.
-    module->module().compileAsync(&vm.wasmContext, instance->memoryMode(), createSharedTask<Wasm::CodeBlock::CallbackType>([promise, instance, module, importObject, resolveKind, creationMode, &vm] (Ref<Wasm::CodeBlock>&& refCodeBlock) mutable {
-        RefPtr<Wasm::CodeBlock> codeBlock = WTFMove(refCodeBlock);
-        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, instance, module, importObject, resolveKind, creationMode, &vm, codeBlock = WTFMove(codeBlock)] () mutable {
-            ExecState* exec = instance->globalObject(vm)->globalExec();
-            resolve(vm, exec, promise, instance, module, importObject, codeBlock.releaseNonNull(), resolveKind, creationMode);
-        });
-    }), &Wasm::createJSToWasmWrapper, &Wasm::wasmToJSException);
-}
-
-static void compileAndInstantiate(VM& vm, ExecState* exec, JSPromiseDeferred* promise, const Identifier& moduleKey, JSValue buffer, JSObject* importObject, Resolve resolveKind, Wasm::CreationMode creationMode)
-{
-    auto scope = DECLARE_CATCH_SCOPE(vm);
-
-    auto* globalObject = exec->lexicalGlobalObject();
-
-    JSCell* moduleKeyCell = identifierToJSValue(vm, moduleKey).asCell();
-    Vector<Strong<JSCell>> dependencies;
-    dependencies.append(Strong<JSCell>(vm, importObject));
-    dependencies.append(Strong<JSCell>(vm, moduleKeyCell));
-    vm.promiseDeferredTimer->addPendingPromise(vm, promise, WTFMove(dependencies));
-
-    Vector<uint8_t> source = createSourceBufferFromValue(vm, exec, buffer);
-    RETURN_IF_EXCEPTION(scope, reject(exec, scope, promise));
-
-    Wasm::Module::validateAsync(&vm.wasmContext, WTFMove(source), createSharedTask<Wasm::Module::CallbackType>([promise, importObject, moduleKeyCell, globalObject, resolveKind, creationMode, &vm] (Wasm::Module::ValidationResult&& result) mutable {
-        vm.promiseDeferredTimer->scheduleWorkSoon(promise, [promise, importObject, moduleKeyCell, globalObject, result = WTFMove(result), resolveKind, creationMode, &vm] () mutable {
-            auto scope = DECLARE_CATCH_SCOPE(vm);
-            ExecState* exec = globalObject->globalExec();
-            JSWebAssemblyModule* module = JSWebAssemblyModule::createStub(vm, exec,&