Issue #1691 - Part 3: Finish implementing import meta. https://bugzilla.mozilla.org/show_bug.cgi?id=1427610

(cherry picked from commit a8625238ac846fb7eb103646ddb8634a5860f067)
This commit is contained in:
Brian Smith 2023-04-08 15:01:22 -05:00 • committed by roytam1
commit 3f4985ce6c
18 changed files with 207 additions and 9 deletions

View file

@ -4102,6 +4102,23 @@ ShellGetModulePrivate(JSContext* cx, unsigned argc, Value* vp)
return true;
}
ShellModuleMetadataHook(JSContext* cx, HandleObject module, HandleObject metaObject)
{
// For the shell, just use the script's filename as the base URL.
RootedScript script(cx, module->as<ModuleObject>().script());
const char* filename = script->scriptSource()->filename();
MOZ_ASSERT(filename);
RootedString url(cx, NewStringCopyZ<CanGC>(cx, filename));
if (!url)
return false;
if (!JS_DefineProperty(cx, metaObject, "url", url, JSPROP_ENUMERATE))
return false;
return true;
}
static bool
GetModuleLoadPath(JSContext* cx, unsigned argc, Value* vp)
{
@ -8038,6 +8055,7 @@ main(int argc, char** argv, char** envp)
js::SetPreserveWrapperCallback(cx, DummyPreserveWrapperCallback);
JS::SetModuleResolveHook(cx->runtime(), CallModuleResolveHook);
JS::SetModuleMetadataHook(cx, ShellModuleMetadataHook);
result = Shell(cx, &op, envp);