Ignore:
Timestamp:
Feb 22, 2022, 5:21:01 AM (4 years ago)
Author:
[email protected]
Message:

Initial support for Wasm/ESM-integration in the WebCore module loader
https://bugs.webkit.org/show_bug.cgi?id=236268

Patch by Asumu Takikawa <[email protected]> on 2022-02-22
Reviewed by Yusuke Suzuki.

LayoutTests/imported/w3c:

Add test suite for Wasm/ESM integration proposal to WPT Wasm WebAPI
tests.

  • web-platform-tests/wasm/webapi/esm-integration/execute-start.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/execute-start.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/exported-names.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/exported-names.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/invalid-bytecode.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/invalid-bytecode.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/js-wasm-cycle-errors.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/js-wasm-cycle-errors.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/js-wasm-cycle.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/js-wasm-cycle.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/module-parse-error.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/module-parse-error.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resolve-export.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resolve-export.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resolve-export.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/execute-start.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/exported-names.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/invalid-bytecode.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/invalid-module.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-function-error.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-function-error.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-global.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-global.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-memory.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-memory.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-table.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-table.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-value.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle-value.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle.js: Added.

(f):

  • web-platform-tests/wasm/webapi/esm-integration/resources/js-wasm-cycle.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/log.js: Added.

(export.logExec):

  • web-platform-tests/wasm/webapi/esm-integration/resources/resolve-export.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-export-i64-global.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-export-to-wasm.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-error-from-wasm.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-from-wasm.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-func.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-func.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-global.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-global.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-memory.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-memory.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-table.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-import-table.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-js-cycle.js: Added.

(let.jsFunc):
(export.mutateBindings):

  • web-platform-tests/wasm/webapi/esm-integration/resources/wasm-js-cycle.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/worker-helper.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/worker.js: Added.
  • web-platform-tests/wasm/webapi/esm-integration/resources/worker.wasm: Added.
  • web-platform-tests/wasm/webapi/esm-integration/wasm-import-wasm-export.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/wasm-import-wasm-export.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/wasm-import.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/wasm-import.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/wasm-js-cycle.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/wasm-js-cycle.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/wasm-to-wasm-link-error.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/wasm-to-wasm-link-error.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/worker-import.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/worker-import.tentative.html: Added.
  • web-platform-tests/wasm/webapi/esm-integration/worker.tentative-expected.txt: Added.
  • web-platform-tests/wasm/webapi/esm-integration/worker.tentative.html: Added.

Source/JavaScriptCore:

Adjust WebAssemblySourceProvider to inherit from a new abstract base
class that exposes the data as a pointer and size, to allow
implementations other than a Vector. Also add initialization
and cleanup methods managed by RAII class.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • parser/SourceProvider.cpp:

(JSC::BaseWebAssemblySourceProvider::BaseWebAssemblySourceProvider):

  • parser/SourceProvider.h:

(JSC::BaseWebAssemblySourceProvider::lockUnderlyingBuffer):
(JSC::BaseWebAssemblySourceProvider::unlockUnderlyingBuffer):
(JSC::WebAssemblySourceProviderBufferGuard::WebAssemblySourceProviderBufferGuard):
(JSC::WebAssemblySourceProviderBufferGuard::~WebAssemblySourceProviderBufferGuard):

  • runtime/CachedTypes.cpp:

(JSC::CachedWebAssemblySourceProvider::encode):

  • tools/JSDollarVM.cpp:
  • wasm/js/JSWebAssemblyHelpers.h:

(JSC::getWasmBufferFromValue):
(JSC::createSourceBufferFromValue):

Source/WebCore:

Add initial WebAssembly script support for WebCore module loading. It
does not yet support Wasm scripts in workers. Detection of Wasm
modules is currently done by MIME type, not by import assertions.

  • Headers.cmake:
  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::hasWasmMIMEType const):

  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::evaluateModule):

  • bindings/js/ScriptController.h:
  • bindings/js/ScriptModuleLoader.cpp:

(WebCore::ScriptModuleLoader::evaluate):
(WebCore::ScriptModuleLoader::notifyFinished):

  • bindings/js/ScriptModuleLoader.h:
  • bindings/js/WebAssemblyCachedScriptSourceProvider.h: Added.
  • bindings/js/WebAssemblyScriptSourceCode.h: Copied from Source/JavaScriptCore/parser/SourceProvider.cpp.

(WebCore::WebAssemblyScriptSourceCode::WebAssemblyScriptSourceCode):
(WebCore::WebAssemblyScriptSourceCode::jsSourceCode const):

  • platform/MIMETypeRegistry.cpp:

(WebCore::MIMETypeRegistry::isSupportedWebAssemblyMIMEType):

  • platform/MIMETypeRegistry.h:
  • workers/WorkerOrWorkletScriptController.cpp:

(WebCore::WorkerOrWorkletScriptController::evaluateModule):

  • workers/WorkerOrWorkletScriptController.h:

Source/WTF:

Add preference flag for Wasm/ESM Integration.

  • Scripts/Preferences/WebPreferencesExperimental.yaml:

LayoutTests:

Add Wasm module MIME type for HTTP tests, and add tests.

  • http/conf/mime.types:
  • http/tests/wasm/resources/empty-module.wasm: Added.
  • http/tests/wasm/wasm-esm-disabled-with-setting-expected.txt: Added.
  • http/tests/wasm/wasm-esm-disabled-with-setting.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/tools/JSDollarVM.cpp

    r288815 r290300  
    19081908        RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(false)));
    19091909
    1910     auto data = getWasmBufferFromValue(globalObject, callFrame->argument(0));
     1910    JSValue value = callFrame->argument(0);
     1911    BaseWebAssemblySourceProvider* provider = nullptr;
     1912    if (auto* source = jsDynamicCast<JSSourceCode*>(vm, value))
     1913        provider = static_cast<BaseWebAssemblySourceProvider*>(source->sourceCode().provider());
     1914    WebAssemblySourceProviderBufferGuard guard(provider);
     1915
     1916    auto data = getWasmBufferFromValue(globalObject, value, guard);
    19111917    RETURN_IF_EXCEPTION(scope, encodedJSValue());
    19121918    RELEASE_AND_RETURN(scope, JSValue::encode(jsNumber(static_cast<int32_t>(thisObject->streamingParser().addBytes(bitwise_cast<const uint8_t*>(data.first), data.second)))));
     
    20032009        RELEASE_AND_RETURN(scope, JSValue::encode(jsBoolean(false)));
    20042010
    2005     auto data = getWasmBufferFromValue(globalObject, callFrame->argument(0));
     2011    JSValue value = callFrame->argument(0);
     2012    BaseWebAssemblySourceProvider* provider = nullptr;
     2013    if (auto* source = jsDynamicCast<JSSourceCode*>(vm, value))
     2014        provider = static_cast<BaseWebAssemblySourceProvider*>(source->sourceCode().provider());
     2015    WebAssemblySourceProviderBufferGuard guard(provider);
     2016
     2017    auto data = getWasmBufferFromValue(globalObject, value, guard);
    20062018    RETURN_IF_EXCEPTION(scope, { });
    20072019    thisObject->streamingCompiler().addBytes(bitwise_cast<const uint8_t*>(data.first), data.second);
Note: See TracChangeset for help on using the changeset viewer.