source: webkit/trunk/Source/JavaScriptCore/parser/SourceProvider.cpp

Last change on this file was 290300, checked in by [email protected], 3 years ago

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

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 size: 2.2 KB
Line 
1/*
2* Copyright (C) 2013-2021 Apple Inc. All Rights Reserved.
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions
6* are met:
7* 1. Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* 2. Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12*
13* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*/
25
26#include "config.h"
27#include "SourceProvider.h"
28
29namespace JSC {
30
31DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(StringSourceProvider);
32
33SourceProvider::SourceProvider(const SourceOrigin& sourceOrigin, String&& sourceURL, const TextPosition& startPosition, SourceProviderSourceType sourceType)
34: m_sourceType(sourceType)
35, m_sourceOrigin(sourceOrigin)
36, m_sourceURL(WTFMove(sourceURL))
37, m_startPosition(startPosition)
38{
39}
40
41SourceProvider::~SourceProvider()
42{
43}
44
45void SourceProvider::getID()
46{
47if (!m_id) {
48static std::atomic<SourceID> nextProviderID = nullID;
49m_id = ++nextProviderID;
50RELEASE_ASSERT(m_id);
51}
52}
53
54#if ENABLE(WEBASSEMBLY)
55BaseWebAssemblySourceProvider::BaseWebAssemblySourceProvider(const SourceOrigin& sourceOrigin, String&& sourceURL)
56: SourceProvider(sourceOrigin, WTFMove(sourceURL), TextPosition(), SourceProviderSourceType::WebAssembly)
57{
58}
59#endif
60
61} // namespace JSC
62
Note: See TracBrowser for help on using the repository browser.