forked from mirrors/gecko-dev
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)
This commit is contained in:
parent
f05a07c983
commit
d3f5c8300e
11 changed files with 30 additions and 323 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>Test import.meta.resolve with import maps</title>
|
||||
</head>
|
||||
<body onload='testLoaded()'>
|
||||
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
"simple": "./module_simpleExport.js"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script>
|
||||
var wasRun = false;
|
||||
var hasThrown = false;
|
||||
window.onerror = handleError;
|
||||
|
||||
function handleError(msg, url, line, col, error) {
|
||||
ok(error instanceof TypeError, "Thrown error should be TypeError.");
|
||||
hasThrown = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
ok(import.meta.resolve("simple") ==
|
||||
"chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/module_simpleExport.js",
|
||||
"calling import.meta.resolve with a specifier from import map.");
|
||||
wasRun = true;
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
// should throw a TypeError
|
||||
import.meta.resolve("fail");
|
||||
</script>
|
||||
|
||||
<script>
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function testLoaded() {
|
||||
ok(wasRun, "Check inline module has run.");
|
||||
ok(hasThrown, "Check inline module has thrown.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>Test import.meta.resolve</title>
|
||||
</head>
|
||||
<body onload='testLoaded()'>
|
||||
|
||||
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script>
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function assertThrowsTypeError(fn, msg) {
|
||||
let hasThrown = false;
|
||||
try {
|
||||
fn();
|
||||
} catch (error) {
|
||||
hasThrown = true;
|
||||
ok(error instanceof TypeError, "Thrown error should be TypeError.");
|
||||
}
|
||||
ok(hasThrown, msg);
|
||||
}
|
||||
|
||||
function testLoaded() {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
is(typeof import.meta.resolve, "function", "resolve should be a function.");
|
||||
is(import.meta.resolve.name, "resolve", "resolve.name should be 'resolve'.");
|
||||
is(import.meta.resolve.length, 1, "resolve.length should be 1.");
|
||||
is(Object.getPrototypeOf(import.meta.resolve), Function.prototype,
|
||||
"prototype of resolve should be Function.prototype.");
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
is(import.meta.resolve("http://example.com/"), "http://example.com/",
|
||||
"resolve specifiers with absolute path.");
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
is(import.meta.resolve("./x"), (new URL("./x", import.meta.url)).href,
|
||||
"resolve specifiers with relative path.");
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
assertThrowsTypeError(() => new import.meta.resolve("./x"),
|
||||
"import.meta.resolve is not a constructor.");
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
// Fails to resolve the specifier should throw a TypeError.
|
||||
assertThrowsTypeError(() => import.meta.resolve("failed"),
|
||||
"import.meta.resolve should throw if fails to resolve");
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
for (const name of Reflect.ownKeys(import.meta)) {
|
||||
const desc = Object.getOwnPropertyDescriptor(import.meta, name);
|
||||
is(desc.writable, true, name + ".writable should be true.");
|
||||
is(desc.enumerable, true, name + ".enumerable should be true.");
|
||||
is(desc.configurable, true, name + ".configurable should be true.");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
@ -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<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSString*> aSpecifier) {
|
||||
RefPtr<ModuleScript> script =
|
||||
static_cast<ModuleScript*>(aReferencingPrivate.toPrivate());
|
||||
MOZ_ASSERT(script->IsModuleScript());
|
||||
MOZ_ASSERT(JS::GetModulePrivate(script->ModuleRecord()) ==
|
||||
aReferencingPrivate);
|
||||
|
||||
RefPtr<ModuleLoaderBase> 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<JS::Value> 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<nsIURI> 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<JS::Value> 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
|
||||
|
|
|
|||
|
|
@ -296,10 +296,6 @@ class ModuleLoaderBase : public nsISupports {
|
|||
static bool HostPopulateImportMeta(JSContext* aCx,
|
||||
JS::Handle<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSObject*> aMetaObject);
|
||||
static bool ImportMetaResolve(JSContext* cx, unsigned argc, Value* vp);
|
||||
static JSString* ImportMetaResolveImpl(
|
||||
JSContext* aCx, JS::Handle<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSString*> aSpecifier);
|
||||
static bool HostImportModuleDynamically(
|
||||
JSContext* aCx, JS::Handle<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSObject*> aModuleRequest, JS::Handle<JSObject*> 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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<JS::Value> referencingPrivate,
|
||||
JS::Handle<JSString*> specifier,
|
||||
JS::MutableHandle<JSString*> urlOut) {
|
||||
Rooted<JSLinearString*> 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<JSLinearString*> 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<JSLinearString*> 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) {
|
||||
|
|
|
|||
|
|
@ -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<JS::Value> referencingPrivate,
|
||||
JS::Handle<JSString*> specifier,
|
||||
JS::MutableHandle<JSString*> 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<JSLinearString*> pathOut);
|
||||
JSLinearString* normalizePath(JSContext* cx, Handle<JSLinearString*> 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in a new issue