From ef217a94a8fa752d75ad2854704be90b3d427426 Mon Sep 17 00:00:00 2001 From: Fedor Date: Thu, 16 Jul 2020 03:48:35 +0300 Subject: [PATCH] Implement module type scripting. --- dom/base/nsJSUtils.cpp | 13 +- dom/base/nsJSUtils.h | 8 +- dom/base/test/jsmodules/test_syntaxError.html | 15 +- .../test/jsmodules/test_syntaxErrorAsync.html | 15 +- .../jsmodules/test_syntaxErrorInline.html | 15 +- .../test_syntaxErrorInlineAsync.html | 15 +- dom/script/ModuleLoadRequest.cpp | 53 +- dom/script/ModuleLoadRequest.h | 6 + dom/script/ModuleScript.cpp | 80 ++- dom/script/ModuleScript.h | 28 +- dom/script/ScriptLoader.cpp | 263 ++++---- dom/script/ScriptLoader.h | 1 + js/src/builtin/Module.js | 568 ++++++++++++++---- js/src/builtin/ModuleObject.cpp | 150 +++-- js/src/builtin/ModuleObject.h | 56 +- js/src/builtin/ReflectParse.cpp | 2 +- js/src/builtin/SelfHostingDefines.h | 16 +- js/src/builtin/Utilities.js | 19 +- js/src/frontend/BytecodeCompiler.cpp | 2 +- js/src/frontend/BytecodeEmitter.cpp | 2 +- js/src/frontend/Parser.cpp | 2 +- .../tests/modules/ambiguous-star-export.js | 15 +- .../tests/modules/bad-namespace-created.js | 17 + js/src/jit-test/tests/modules/bug-1284486.js | 39 +- js/src/jit-test/tests/modules/bug-1287410.js | 2 + js/src/jit-test/tests/modules/bug-1394492.js | 6 + js/src/jit-test/tests/modules/global-scope.js | 18 +- .../tests/modules/module-evaluation.js | 33 +- js/src/js.msg | 10 +- js/src/jsapi.cpp | 20 +- js/src/jsapi.h | 19 +- js/src/vm/CommonPropertyNames.h | 4 +- js/src/vm/SelfHosting.cpp | 65 +- 33 files changed, 1113 insertions(+), 464 deletions(-) create mode 100644 js/src/jit-test/tests/modules/bad-namespace-created.js create mode 100644 js/src/jit-test/tests/modules/bug-1394492.js diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp index c24adc739..65965d74b 100644 --- a/dom/base/nsJSUtils.cpp +++ b/dom/base/nsJSUtils.cpp @@ -308,17 +308,18 @@ nsJSUtils::CompileModule(JSContext* aCx, } nsresult -nsJSUtils::ModuleDeclarationInstantiation(JSContext* aCx, JS::Handle aModule) +nsJSUtils::ModuleInstantiate(JSContext* aCx, JS::Handle aModule) { - PROFILER_LABEL("nsJSUtils", "ModuleDeclarationInstantiation", + PROFILER_LABEL("nsJSUtils", "ModuleInstantiate", js::ProfileEntry::Category::JS); MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext()); MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(nsContentUtils::IsInMicroTask()); NS_ENSURE_TRUE(xpc::Scriptability::Get(aModule).Allowed(), NS_OK); - if (!JS::ModuleDeclarationInstantiation(aCx, aModule)) { + if (!JS::ModuleInstantiate(aCx, aModule)) { return NS_ERROR_FAILURE; } @@ -326,9 +327,9 @@ nsJSUtils::ModuleDeclarationInstantiation(JSContext* aCx, JS::Handle } nsresult -nsJSUtils::ModuleEvaluation(JSContext* aCx, JS::Handle aModule) +nsJSUtils::ModuleEvaluate(JSContext* aCx, JS::Handle aModule) { - PROFILER_LABEL("nsJSUtils", "ModuleEvaluation", + PROFILER_LABEL("nsJSUtils", "ModuleEvaluate", js::ProfileEntry::Category::JS); MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext()); @@ -338,7 +339,7 @@ nsJSUtils::ModuleEvaluation(JSContext* aCx, JS::Handle aModule) NS_ENSURE_TRUE(xpc::Scriptability::Get(aModule).Allowed(), NS_OK); - if (!JS::ModuleEvaluation(aCx, aModule)) { + if (!JS::ModuleEvaluate(aCx, aModule)) { return NS_ERROR_FAILURE; } diff --git a/dom/base/nsJSUtils.h b/dom/base/nsJSUtils.h index 4affab2d3..9eea6ae83 100644 --- a/dom/base/nsJSUtils.h +++ b/dom/base/nsJSUtils.h @@ -116,11 +116,11 @@ public: JS::CompileOptions &aCompileOptions, JS::MutableHandle aModule); - static nsresult ModuleDeclarationInstantiation(JSContext* aCx, - JS::Handle aModule); + static nsresult ModuleInstantiate(JSContext* aCx, + JS::Handle aModule); - static nsresult ModuleEvaluation(JSContext* aCx, - JS::Handle aModule); + static nsresult ModuleEvaluate(JSContext* aCx, + JS::Handle aModule); // Returns false if an exception got thrown on aCx. Passing a null // aElement is allowed; that wil produce an empty aScopeChain. diff --git a/dom/base/test/jsmodules/test_syntaxError.html b/dom/base/test/jsmodules/test_syntaxError.html index 53f95c96c..5bd688fe3 100644 --- a/dom/base/test/jsmodules/test_syntaxError.html +++ b/dom/base/test/jsmodules/test_syntaxError.html @@ -4,20 +4,27 @@ - + diff --git a/dom/base/test/jsmodules/test_syntaxErrorAsync.html b/dom/base/test/jsmodules/test_syntaxErrorAsync.html index 35d923755..3593d9dd7 100644 --- a/dom/base/test/jsmodules/test_syntaxErrorAsync.html +++ b/dom/base/test/jsmodules/test_syntaxErrorAsync.html @@ -4,20 +4,27 @@ - + diff --git a/dom/base/test/jsmodules/test_syntaxErrorInline.html b/dom/base/test/jsmodules/test_syntaxErrorInline.html index 705bc5902..b85b954ec 100644 --- a/dom/base/test/jsmodules/test_syntaxErrorInline.html +++ b/dom/base/test/jsmodules/test_syntaxErrorInline.html @@ -4,22 +4,29 @@ - -