[WebAssembly][Modules] Prototype wasm import
https://bugs.webkit.org/show_bug.cgi?id=184600
Reviewed by JF Bastien.
JSTests:
Add wasm and wat files since module loader want to load wasm files from FS.
Currently, importing the other modules from wasm is not supported.
- wasm.yaml:
- wasm/modules/constant.wasm: Added.
- wasm/modules/constant.wat: Added.
- wasm/modules/js-wasm-function-namespace.js: Added.
(assert.throws):
- wasm/modules/js-wasm-function.js: Added.
(assert.throws):
- wasm/modules/js-wasm-global-namespace.js: Added.
(assert.throws):
- wasm/modules/js-wasm-global.js: Added.
(assert.throws):
- wasm/modules/js-wasm-memory-namespace.js: Added.
(assert.throws):
- wasm/modules/js-wasm-memory.js: Added.
(assert.throws):
- wasm/modules/js-wasm-start.js: Added.
(then):
- wasm/modules/js-wasm-table-namespace.js: Added.
(assert.throws):
- wasm/modules/js-wasm-table.js: Added.
(assert.throws):
- wasm/modules/memory.wasm: Added.
- wasm/modules/memory.wat: Added.
- wasm/modules/start.wasm: Added.
- wasm/modules/start.wat: Added.
- wasm/modules/sum.wasm: Added.
- wasm/modules/sum.wat: Added.
- wasm/modules/table.wasm: Added.
- wasm/modules/table.wat: Added.
Source/JavaScriptCore:
This patch is an initial attempt to implement Wasm loading in module pipeline.
Currently,
- We only support Wasm loading in the JSC shell. Once loading mechanism is specified
in whatwg HTML, we should integrate this into WebCore.
- We only support exporting values from Wasm. Wasm module cannot import anything from
the other modules now.
When loading a file, JSC shell checks wasm magic. If the wasm magic is found, JSC shell
loads the file with WebAssemblySourceProvider. It is wrapped into JSSourceCode and
module loader pipeline just handles it as the same to JS. When parsing a module, we
checks the type of JSSourceCode. If the source code is Wasm source code, we create a
WebAssemblyModuleRecord instead of JSModuleRecord. Our module pipeline handles
AbstractModuleRecord and Wasm module is instantiated, linked, and evaluated.
- builtins/ModuleLoaderPrototype.js:
(globalPrivate.newRegistryEntry):
(requestInstantiate):
(link):
(convertShebangToJSComment):
(fillBufferWithContentsOfFile):
(fetchModuleFromLocalFileSystem):
(GlobalObject::moduleLoaderFetch):
(JSC::WebAssemblySourceProvider::create):
(JSC::WebAssemblySourceProvider::WebAssemblySourceProvider):
- runtime/AbstractModuleRecord.cpp:
(JSC::AbstractModuleRecord::hostResolveImportedModule):
(JSC::AbstractModuleRecord::link):
(JSC::AbstractModuleRecord::evaluate):
(JSC::identifierToJSValue): Deleted.
- runtime/AbstractModuleRecord.h:
- runtime/JSModuleLoader.cpp:
(JSC::JSModuleLoader::evaluate):
- runtime/JSModuleRecord.cpp:
(JSC::JSModuleRecord::link):
(JSC::JSModuleRecord::instantiateDeclarations):
- runtime/JSModuleRecord.h:
- runtime/ModuleLoaderPrototype.cpp:
(JSC::moduleLoaderPrototypeParseModule):
(JSC::moduleLoaderPrototypeRequestedModules):
(JSC::moduleLoaderPrototypeModuleDeclarationInstantiation):
- wasm/js/JSWebAssemblyHelpers.h:
(JSC::getWasmBufferFromValue):
(JSC::createSourceBufferFromValue):
- wasm/js/JSWebAssemblyInstance.cpp:
(JSC::JSWebAssemblyInstance::finalizeCreation):
(JSC::JSWebAssemblyInstance::createPrivateModuleKey):
(JSC::JSWebAssemblyInstance::create):
- wasm/js/JSWebAssemblyInstance.h:
- wasm/js/WebAssemblyInstanceConstructor.cpp:
(JSC::constructJSWebAssemblyInstance):
- wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::prepareLink):
(JSC::WebAssemblyModuleRecord::link):
- wasm/js/WebAssemblyModuleRecord.h:
- wasm/js/WebAssemblyPrototype.cpp:
(JSC::resolve):
(JSC::instantiate):
(JSC::compileAndInstantiate):
(JSC::WebAssemblyPrototype::instantiate):
(JSC::webAssemblyInstantiateFunc):
(JSC::webAssemblyValidateFunc):
- wasm/js/WebAssemblyPrototype.h: