Repository navigation
Commit cebdad8
committed
[JSC] Implement import-assertion and JSON module
https://bugs.webkit.org/show_bug.cgi?id=243622
Reviewed by Alexey Shvayka and Ryosuke Niwa.
This patch implements import-assertions and JSON module.
1. Import assertions' syntax work was already done. We propagate assertions through ScriptFetchParameters, which already exists.
2. Get "type" assertion, and based on that, we parse JSON if it is "json".
3. Add SyntheticModuleRecord (this is described in the spec), and materialize JSON module as SyntheticModuleRecord.
4. Fix MIMETypeRegistry::isSupportedJSONMIMEType. "text/json" is explicitly listed in [1], so we should say true for that.
5. Dynamic import also gets assertions via its second parameter.
One test262 test is failing just because our harness is not handling it well (so this is not a bug in JSON module implementation).
WPT failures are due to old module loader's behavior (so, fixing it requires update of module loader implementation, not related to
JSON module itself).
[1]: https://mimesniff.spec.whatwg.org/#json-mime-type
* JSTests/test262/config.yaml:
* JSTests/test262/expectations.yaml:
* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/css-module-worker-test-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-bom.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-bom.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-bom.any.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/json-module-service-worker-test.https-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/non-object.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/non-object.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/non-object.any.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type-expected.txt:
* LayoutTests/platform/gtk/TestExpectations:
* Source/JavaScriptCore/API/JSAPIGlobalObject.mm:
(JSC::JSAPIGlobalObject::moduleLoaderImportModule):
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/builtins/ModuleLoader.js:
(requestSatisfy):
* Source/JavaScriptCore/heap/Heap.cpp:
(JSC::Heap::Heap):
* Source/JavaScriptCore/heap/Heap.h:
* Source/JavaScriptCore/heap/HeapSubspaceTypes.h:
* Source/JavaScriptCore/jsc.cpp:
(GlobalObject::moduleLoaderImportModule):
(GlobalObject::moduleLoaderFetch):
* Source/JavaScriptCore/parser/ModuleAnalyzer.cpp:
(JSC::ModuleAnalyzer::appendRequestedModule):
* Source/JavaScriptCore/parser/ModuleAnalyzer.h:
* Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:
(JSC::tryCreateAssertion):
(JSC::ImportDeclarationNode::analyzeModule):
(JSC::ExportAllDeclarationNode::analyzeModule):
(JSC::ExportNamedDeclarationNode::analyzeModule):
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseImportAssertions):
* Source/JavaScriptCore/parser/SourceProvider.h:
* Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp:
(JSC::AbstractModuleRecord::appendRequestedModule):
(JSC::AbstractModuleRecord::link):
(JSC::AbstractModuleRecord::evaluate):
(JSC::AbstractModuleRecord::dump):
* Source/JavaScriptCore/runtime/AbstractModuleRecord.h:
(JSC::AbstractModuleRecord::requestedModules const):
* Source/JavaScriptCore/runtime/Completion.cpp:
(JSC::retrieveAssertionsFromDynamicImportOptions):
* Source/JavaScriptCore/runtime/Completion.h:
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildrenImpl):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::syntheticModuleRecordStructure const):
* Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/JSModuleLoader.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/JSONObject.cpp:
(JSC::JSONParse):
(JSC::JSONParseWithException):
* Source/JavaScriptCore/runtime/JSONObject.h:
* Source/JavaScriptCore/runtime/OptionsList.h:
* Source/JavaScriptCore/runtime/ScriptFetchParameters.h:
(JSC::ScriptFetchParameters::ScriptFetchParameters):
(JSC::ScriptFetchParameters::type const):
(JSC::ScriptFetchParameters::integrity const):
(JSC::ScriptFetchParameters::isTopLevelModule const):
(JSC::ScriptFetchParameters::create):
(JSC::ScriptFetchParameters::~ScriptFetchParameters): Deleted.
* Source/JavaScriptCore/runtime/SyntheticModuleRecord.cpp: Added.
(JSC::SyntheticModuleRecord::createStructure):
(JSC::SyntheticModuleRecord::create):
(JSC::SyntheticModuleRecord::SyntheticModuleRecord):
(JSC::SyntheticModuleRecord::destroy):
(JSC::SyntheticModuleRecord::finishCreation):
(JSC::SyntheticModuleRecord::visitChildrenImpl):
(JSC::SyntheticModuleRecord::link):
(JSC::SyntheticModuleRecord::evaluate):
(JSC::SyntheticModuleRecord::tryCreateWithExportNamesAndValues):
(JSC::SyntheticModuleRecord::tryCreateDefaultExportSyntheticModule):
(JSC::SyntheticModuleRecord::parseJSONModule):
* Source/JavaScriptCore/runtime/SyntheticModuleRecord.h: Added.
* Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp:
(JSC::JSWebAssemblyInstance::tryCreate):
* Source/WebCore/bindings/js/CachedModuleScriptLoader.cpp:
(WebCore::CachedModuleScriptLoader::create):
(WebCore::CachedModuleScriptLoader::CachedModuleScriptLoader):
* Source/WebCore/bindings/js/CachedModuleScriptLoader.h:
* Source/WebCore/bindings/js/ModuleScriptLoader.h:
(WebCore::ModuleScriptLoader::parameters):
(WebCore::ModuleScriptLoader::ModuleScriptLoader):
* Source/WebCore/bindings/js/ScriptController.cpp:
(WebCore::ScriptController::loadModuleScriptInWorld):
(WebCore::ScriptController::loadModuleScript):
(WebCore::ScriptController::evaluateModule):
* Source/WebCore/bindings/js/ScriptController.h:
* Source/WebCore/bindings/js/ScriptModuleLoader.cpp:
(WebCore::ScriptModuleLoader::fetch):
(WebCore::ScriptModuleLoader::importModule):
(WebCore::ScriptModuleLoader::notifyFinished):
* Source/WebCore/bindings/js/ScriptModuleLoader.h:
* Source/WebCore/bindings/js/WorkerModuleScriptLoader.cpp:
(WebCore::WorkerModuleScriptLoader::create):
(WebCore::WorkerModuleScriptLoader::WorkerModuleScriptLoader):
* Source/WebCore/bindings/js/WorkerModuleScriptLoader.h:
* Source/WebCore/bindings/js/WorkerScriptFetcher.h:
* Source/WebCore/dom/LoadableModuleScript.cpp:
(WebCore::LoadableModuleScript::LoadableModuleScript):
* Source/WebCore/dom/ModuleFetchParameters.h:
(WebCore::ModuleFetchParameters::create):
(WebCore::ModuleFetchParameters::ModuleFetchParameters):
(WebCore::ModuleFetchParameters::integrity const): Deleted.
(WebCore::ModuleFetchParameters::isTopLevelModule const): Deleted.
* Source/WebCore/platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::isSupportedJSONMIMEType):
* Source/WebCore/workers/WorkerOrWorkletScriptController.cpp:
(WebCore::WorkerOrWorkletScriptController::loadAndEvaluateModule):
* Source/WebCore/workers/WorkerThread.cpp:
(WebCore::WorkerThread::evaluateScriptIfNecessary):
* Tools/TestWebKitAPI/Tests/WebCore/MIMETypeRegistry.cpp:
(TestWebKitAPI::TEST):
Canonical link: https://commits.webkit.org/253234@main1 parent 6f10652 commit cebdad8
75 files changed
Lines changed: 767 additions & 274 deletions
File tree
- JSTests/test262
- LayoutTests
- imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element
- css-module
- import-assertions
- json-module
- platform/gtk
- Source
- JavaScriptCore
- API
- JavaScriptCore.xcodeproj
- builtins
- heap
- parser
- runtime
- wasm/js
- WebCore
- bindings/js
- dom
- platform
- workers
- Tools/TestWebKitAPI/Tests/WebCore
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | | - | |
22 | | - | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2040 | 2040 | | |
2041 | 2041 | | |
2042 | 2042 | | |
| 2043 | + | |
| 2044 | + | |
2043 | 2045 | | |
2044 | 2046 | | |
2045 | 2047 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5440 | 5440 | | |
5441 | 5441 | | |
5442 | 5442 | | |
| 5443 | + | |
| 5444 | + | |
| 5445 | + | |
| 5446 | + | |
| 5447 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
6 | 5 | | |
7 | | - | |
| 6 | + | |
8 | 7 | | |
9 | 8 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
14 | 12 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
11 | 11 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
9 | 5 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
20 | 14 | | |
0 commit comments