From d3f5c8300e8c824252cfae2eb22add634ed2a5dc Mon Sep 17 00:00:00 2001 From: Sandor Molnar Date: Tue, 30 Aug 2022 02:51:29 +0300 Subject: [PATCH] Backed out 2 changesets (bug 1775424) for causing linux hazard build bustage in js/loader/ModuleLoaderBase.cpp CLOSED TREE Backed out changeset a043a84a771c (bug 1775424) Backed out changeset 19bc4fafd300 (bug 1775424) --- dom/base/test/jsmodules/chrome.ini | 1 - dom/base/test/jsmodules/importmaps/chrome.ini | 1 - .../test_import_meta_resolve_importMap.html | 49 ---------- .../jsmodules/test_import_meta_resolve.html | 65 ------------- js/loader/ModuleLoaderBase.cpp | 93 +------------------ js/loader/ModuleLoaderBase.h | 12 --- js/src/jit-test/tests/modules/import-meta.js | 21 ++--- js/src/shell/ModuleLoader.cpp | 75 +-------------- js/src/shell/ModuleLoader.h | 15 --- .../import-meta-resolve-importmap.html.ini | 12 ++- ...ort-meta-resolve-multiple-scripts.html.ini | 9 ++ 11 files changed, 30 insertions(+), 323 deletions(-) delete mode 100644 dom/base/test/jsmodules/importmaps/test_import_meta_resolve_importMap.html delete mode 100644 dom/base/test/jsmodules/test_import_meta_resolve.html create mode 100644 testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-multiple-scripts.html.ini diff --git a/dom/base/test/jsmodules/chrome.ini b/dom/base/test/jsmodules/chrome.ini index ef9145652241..02a37a0ecf74 100644 --- a/dom/base/test/jsmodules/chrome.ini +++ b/dom/base/test/jsmodules/chrome.ini @@ -27,7 +27,6 @@ support-files = [test_scriptNotParsedAsModule.html] [test_typeAttrCaseInsensitive.html] [test_moduleNotFound.html] -[test_import_meta_resolve.html] [test_importNotFound.html] [test_syntaxError.html] [test_syntaxErrorAsync.html] diff --git a/dom/base/test/jsmodules/importmaps/chrome.ini b/dom/base/test/jsmodules/importmaps/chrome.ini index fb569187513e..f5d84e56bb62 100644 --- a/dom/base/test/jsmodules/importmaps/chrome.ini +++ b/dom/base/test/jsmodules/importmaps/chrome.ini @@ -17,7 +17,6 @@ prefs = [test_dynamic_import_reject_importMap.html] [test_externalImportMap.html] -[test_import_meta_resolve_importMap.html] [test_inline_module_reject_importMap.html] [test_load_importMap_with_base.html] [test_load_importMap_with_base2.html] diff --git a/dom/base/test/jsmodules/importmaps/test_import_meta_resolve_importMap.html b/dom/base/test/jsmodules/importmaps/test_import_meta_resolve_importMap.html deleted file mode 100644 index df1bed2e565f..000000000000 --- a/dom/base/test/jsmodules/importmaps/test_import_meta_resolve_importMap.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - Test import.meta.resolve with import maps - - - - - - - - - - - - - - diff --git a/dom/base/test/jsmodules/test_import_meta_resolve.html b/dom/base/test/jsmodules/test_import_meta_resolve.html deleted file mode 100644 index 66eedc95bcb9..000000000000 --- a/dom/base/test/jsmodules/test_import_meta_resolve.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - Test import.meta.resolve - - - - - - - - - - - - - - - - - - diff --git a/js/loader/ModuleLoaderBase.cpp b/js/loader/ModuleLoaderBase.cpp index e64ff4091379..656d28a90ed2 100644 --- a/js/loader/ModuleLoaderBase.cpp +++ b/js/loader/ModuleLoaderBase.cpp @@ -141,75 +141,6 @@ JSObject* ModuleLoaderBase::HostResolveImportedModule( return module; } -// static -bool ModuleLoaderBase::ImportMetaResolve(JSContext* cx, unsigned argc, - Value* vp) { - CallArgs args = CallArgsFromVp(argc, vp); - RootedValue modulePrivate( - cx, js::GetFunctionNativeReserved(&args.callee(), ModulePrivateSlot)); - - // https://html.spec.whatwg.org/#hostgetimportmetaproperties - // Step 4.1. Set specifier to ? ToString(specifier). - // - // https://tc39.es/ecma262/#sec-tostring - RootedValue v(cx, args.get(ImportMetaResolveSpecifierArg)); - RootedString specifier(cx, JS::ToString(cx, v)); - if (!specifier) { - return false; - } - - // Step 4.2, 4.3 are implemented in ImportMetaResolveImpl. - RootedString url(cx, ImportMetaResolveImpl(cx, modulePrivate, specifier)); - if (!url) { - return false; - } - - // Step 4.4. Return the serialization of url. - args.rval().setString(url); - return true; -} - -// static -JSString* ModuleLoaderBase::ImportMetaResolveImpl( - JSContext* aCx, JS::Handle aReferencingPrivate, - JS::Handle aSpecifier) { - RefPtr script = - static_cast(aReferencingPrivate.toPrivate()); - MOZ_ASSERT(script->IsModuleScript()); - MOZ_ASSERT(JS::GetModulePrivate(script->ModuleRecord()) == - aReferencingPrivate); - - RefPtr loader = GetCurrentModuleLoader(aCx); - if (!loader) { - return nullptr; - } - - nsAutoJSString specifier; - if (!specifier.init(aCx, aSpecifier)) { - return nullptr; - } - - auto result = loader->ResolveModuleSpecifier(script, specifier); - if (result.isErr()) { - JS::Rooted error(aCx); - nsresult rv = HandleResolveFailure(aCx, script, specifier, - result.unwrapErr(), 0, 0, &error); - if (NS_FAILED(rv)) { - JS_ReportOutOfMemory(aCx); - return nullptr; - } - - JS_SetPendingException(aCx, error); - - return nullptr; - } - - nsCOMPtr uri = result.unwrap(); - nsAutoCString url; - MOZ_ALWAYS_SUCCEEDS(uri->GetAsciiSpec(url)); - return JS_NewStringCopyZ(aCx, url.get()); -} - // static bool ModuleLoaderBase::HostPopulateImportMeta( JSContext* aCx, JS::Handle aReferencingPrivate, @@ -230,28 +161,8 @@ bool ModuleLoaderBase::HostPopulateImportMeta( return false; } - // https://html.spec.whatwg.org/#import-meta-url - if (!JS_DefineProperty(aCx, aMetaObject, "url", urlString, - JSPROP_ENUMERATE)) { - return false; - } - - // https://html.spec.whatwg.org/#import-meta-resolve - // Define 'resolve' function on the import.meta object. - JSFunction* resolveFunc = js::DefineFunctionWithReserved( - aCx, aMetaObject, "resolve", ImportMetaResolve, ImportMetaResolveNumArgs, - JSPROP_ENUMERATE); - if (!resolveFunc) { - return false; - } - - // Store the 'active script' of the meta object into the function slot. - // https://html.spec.whatwg.org/#active-script - RootedObject resolveFuncObj(aCx, JS_GetFunctionObject(resolveFunc)); - js::SetFunctionNativeReserved(resolveFuncObj, ModulePrivateSlot, - aReferencingPrivate); - - return true; + return JS_DefineProperty(aCx, aMetaObject, "url", urlString, + JSPROP_ENUMERATE); } // static diff --git a/js/loader/ModuleLoaderBase.h b/js/loader/ModuleLoaderBase.h index 6c4943bf8ec6..03fad2d8bbaf 100644 --- a/js/loader/ModuleLoaderBase.h +++ b/js/loader/ModuleLoaderBase.h @@ -296,10 +296,6 @@ class ModuleLoaderBase : public nsISupports { static bool HostPopulateImportMeta(JSContext* aCx, JS::Handle aReferencingPrivate, JS::Handle aMetaObject); - static bool ImportMetaResolve(JSContext* cx, unsigned argc, Value* vp); - static JSString* ImportMetaResolveImpl( - JSContext* aCx, JS::Handle aReferencingPrivate, - JS::Handle aSpecifier); static bool HostImportModuleDynamically( JSContext* aCx, JS::Handle aReferencingPrivate, JS::Handle aModuleRequest, JS::Handle aPromise); @@ -382,14 +378,6 @@ class ModuleLoaderBase : public nsISupports { nsresult CreateModuleScript(ModuleLoadRequest* aRequest); - // The slot stored in ImportMetaResolve function. - enum { ModulePrivateSlot = 0, SlotCount }; - - // The number of args in ImportMetaResolve. - static const uint32_t ImportMetaResolveNumArgs = 1; - // The index of the 'specifier' argument in ImportMetaResolve. - static const uint32_t ImportMetaResolveSpecifierArg = 0; - public: static mozilla::LazyLogModule gCspPRLog; static mozilla::LazyLogModule gModuleLoaderBaseLog; diff --git a/js/src/jit-test/tests/modules/import-meta.js b/js/src/jit-test/tests/modules/import-meta.js index 98697fa2e189..aab134cd0bde 100644 --- a/js/src/jit-test/tests/modules/import-meta.js +++ b/js/src/jit-test/tests/modules/import-meta.js @@ -20,11 +20,6 @@ assertEq(get(), import.meta); assertEq("url" in import.meta, true); assertEq(import.meta.url.endsWith("import-meta.js"), true); -assertEq("resolve" in import.meta, true); - -assertEq(import.meta.resolve("./x"), - import.meta.url.replace("import-meta.js", "x")); - import getOtherMetaObject from "exportImportMeta.js"; let otherImportMeta = getOtherMetaObject(); @@ -35,13 +30,11 @@ assertEq(otherImportMeta.url.endsWith("exportImportMeta.js"), true); assertEq(Object.isExtensible(import.meta), true); -for (const name of Reflect.ownKeys(import.meta)) { - const desc = Object.getOwnPropertyDescriptor(import.meta, name); - assertEq(desc.writable, true); - assertEq(desc.enumerable, true); - assertEq(desc.configurable, true); - assertEq(desc.value, import.meta[name]); -} +var desc = Object.getOwnPropertyDescriptor(import.meta, "url"); +assertEq(desc.writable, true); +assertEq(desc.enumerable, true); +assertEq(desc.configurable, true); +assertEq(desc.value, import.meta.url); // The import.meta object's prototype is null. assertEq(Object.getPrototypeOf(import.meta), null); @@ -54,14 +47,12 @@ assertEq(import.meta.newProp, 42); let found = new Set(Reflect.ownKeys(import.meta)); -assertEq(found.size, 3); +assertEq(found.size, 2); assertEq(found.has("url"), true); assertEq(found.has("newProp"), true); -assertEq(found.has("resolve"), true); delete import.meta.url; delete import.meta.newProp; -delete import.meta.resolve; found = new Set(Reflect.ownKeys(import.meta)); assertEq(found.size, 0); diff --git a/js/src/shell/ModuleLoader.cpp b/js/src/shell/ModuleLoader.cpp index e95341eacf89..d917fbbcce65 100644 --- a/js/src/shell/ModuleLoader.cpp +++ b/js/src/shell/ModuleLoader.cpp @@ -13,7 +13,6 @@ #include "NamespaceImports.h" #include "builtin/TestingUtility.h" // js::CreateScriptPrivate -#include "js/Conversions.h" #include "js/MapAndSet.h" #include "js/Modules.h" #include "js/PropertyAndElement.h" // JS_DefineProperty, JS_GetProperty @@ -85,34 +84,6 @@ bool ModuleLoader::GetImportMetaProperties(JSContext* cx, return scx->moduleLoader->populateImportMeta(cx, privateValue, metaObject); } -bool ModuleLoader::ImportMetaResolve(JSContext* cx, unsigned argc, Value* vp) { - CallArgs args = CallArgsFromVp(argc, vp); - RootedValue modulePrivate( - cx, js::GetFunctionNativeReserved(&args.callee(), ModulePrivateSlot)); - - // https://html.spec.whatwg.org/#hostgetimportmetaproperties - // Step 4.1. Set specifier to ? ToString(specifier). - // - // https://tc39.es/ecma262/#sec-tostring - RootedValue v(cx, args.get(ImportMetaResolveSpecifierArg)); - RootedString specifier(cx, JS::ToString(cx, v)); - if (!specifier) { - return false; - } - - // Step 4.2, 4.3 are implemented in importMetaResolve. - ShellContext* scx = GetShellContext(cx); - RootedString url(cx); - if (!scx->moduleLoader->importMetaResolve(cx, modulePrivate, specifier, - &url)) { - return false; - } - - // Step 4.4. Return the serialization of url. - args.rval().setString(url); - return true; -} - // static bool ModuleLoader::ImportModuleDynamically(JSContext* cx, JS::HandleValue referencingPrivate, @@ -217,35 +188,7 @@ bool ModuleLoader::populateImportMeta(JSContext* cx, } RootedValue pathValue(cx, StringValue(path)); - if (!JS_DefineProperty(cx, metaObject, "url", pathValue, JSPROP_ENUMERATE)) { - return false; - } - - JSFunction* resolveFunc = js::DefineFunctionWithReserved( - cx, metaObject, "resolve", ImportMetaResolve, ImportMetaResolveNumArgs, - JSPROP_ENUMERATE); - if (!resolveFunc) { - return false; - } - - RootedObject resolveFuncObj(cx, JS_GetFunctionObject(resolveFunc)); - js::SetFunctionNativeReserved(resolveFuncObj, ModulePrivateSlot, - privateValue); - - return true; -} - -bool ModuleLoader::importMetaResolve(JSContext* cx, - JS::Handle referencingPrivate, - JS::Handle specifier, - JS::MutableHandle urlOut) { - Rooted path(cx, resolve(cx, specifier, referencingPrivate)); - if (!path) { - return false; - } - - urlOut.set(path); - return true; + return JS_DefineProperty(cx, metaObject, "url", pathValue, JSPROP_ENUMERATE); } bool ModuleLoader::dynamicImport(JSContext* cx, @@ -365,16 +308,6 @@ JSLinearString* ModuleLoader::resolve(JSContext* cx, return nullptr; } - return resolve(cx, name, referencingInfo); -} - -JSLinearString* ModuleLoader::resolve(JSContext* cx, HandleString specifier, - HandleValue referencingInfo) { - Rooted name(cx, JS_EnsureLinearString(cx, specifier)); - if (!name) { - return nullptr; - } - if (IsJavaScriptURL(name) || IsAbsolutePath(name)) { return name; } @@ -429,11 +362,7 @@ JSLinearString* ModuleLoader::resolve(JSContext* cx, HandleString specifier, return nullptr; } - Rooted linear(cx, JS_EnsureLinearString(cx, result)); - if (!linear) { - return nullptr; - } - return normalizePath(cx, linear); + return JS_EnsureLinearString(cx, result); } JSObject* ModuleLoader::loadAndParse(JSContext* cx, HandleString pathArg) { diff --git a/js/src/shell/ModuleLoader.h b/js/src/shell/ModuleLoader.h index c8f01473560b..1543a27c0c05 100644 --- a/js/src/shell/ModuleLoader.h +++ b/js/src/shell/ModuleLoader.h @@ -31,7 +31,6 @@ class ModuleLoader { HandleObject moduleRequest); static bool GetImportMetaProperties(JSContext* cx, HandleValue privateValue, HandleObject metaObject); - static bool ImportMetaResolve(JSContext* cx, unsigned argc, Value* vp); static bool ImportModuleDynamically(JSContext* cx, HandleValue referencingPrivate, HandleObject moduleRequest, @@ -49,10 +48,6 @@ class ModuleLoader { HandleObject moduleRequest); bool populateImportMeta(JSContext* cx, HandleValue privateValue, HandleObject metaObject); - bool importMetaResolve(JSContext* cx, - JS::Handle referencingPrivate, - JS::Handle specifier, - JS::MutableHandle urlOut); bool dynamicImport(JSContext* cx, HandleValue referencingPrivate, HandleObject moduleRequest, HandleObject promise); bool doDynamicImport(JSContext* cx, HandleValue referencingPrivate, @@ -67,8 +62,6 @@ class ModuleLoader { HandleObject module); JSLinearString* resolve(JSContext* cx, HandleObject moduleRequestArg, HandleValue referencingInfo); - JSLinearString* resolve(JSContext* cx, HandleString specifier, - HandleValue referencingInfo); bool getScriptPath(JSContext* cx, HandleValue privateValue, MutableHandle pathOut); JSLinearString* normalizePath(JSContext* cx, Handle path); @@ -78,14 +71,6 @@ class ModuleLoader { // The following are used for pinned atoms which do not need rooting. JSAtom* loadPathStr = nullptr; JSAtom* pathSeparatorStr = nullptr; - - // The slot stored in ImportMetaResolve function. - enum { ModulePrivateSlot = 0, SlotCount }; - - // The number of args in ImportMetaResolve. - static const uint32_t ImportMetaResolveNumArgs = 1; - // The index of the 'specifier' argument in ImportMetaResolve. - static const uint32_t ImportMetaResolveSpecifierArg = 0; } JS_HAZ_NON_GC_POINTER; } // namespace shell diff --git a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-importmap.html.ini b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-importmap.html.ini index 99127cb189ae..7061f202badc 100644 --- a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-importmap.html.ini +++ b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-importmap.html.ini @@ -1,2 +1,12 @@ [import-meta-resolve-importmap.html] - prefs: [dom.importMaps.enabled:true] + [import.meta.resolve() given an import mapped bare specifier] + expected: FAIL + + [import.meta.resolve() given an import mapped URL-like specifier] + expected: FAIL + + [Testing the ToString() step of import.meta.resolve() via import maps] + expected: FAIL + + [import(import.meta.resolve(x)) can be different from import(x)] + expected: FAIL diff --git a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-multiple-scripts.html.ini b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-multiple-scripts.html.ini new file mode 100644 index 000000000000..10415a7fdacb --- /dev/null +++ b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-multiple-scripts.html.ini @@ -0,0 +1,9 @@ +[import-meta-resolve-multiple-scripts.html] + [import.meta.resolve resolves URLs relative to the import.meta.url, not relative to the active script when it is called: another global's inline script] + expected: FAIL + + [import.meta.resolve still works if its global has been destroyed (by detaching the iframe)] + expected: FAIL + + [import.meta.resolve resolves URLs relative to the import.meta.url, not relative to the active script when it is called: another module script] + expected: FAIL