mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-27 08:09:35 +00:00
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:
@@ -812,7 +812,7 @@ HostResolveImportedModule(JSContext* aCx,
|
||||
if (!string.init(aCx, aSpecifier)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!aModule || !aCx) {
|
||||
if (!script || !aCx) {
|
||||
// Our module context was ripped out from under us...
|
||||
return nullptr;
|
||||
}
|
||||
@@ -839,6 +839,34 @@ HostResolveImportedModule(JSContext* aCx,
|
||||
return ms->ModuleRecord();
|
||||
}
|
||||
|
||||
bool
|
||||
HostPopulateImportMeta(JSContext* aCx, JS::Handle<JSObject*> aModule,
|
||||
JS::Handle<JSObject*> aMetaObject)
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(aModule);
|
||||
|
||||
JS::Value value = JS::GetModulePrivate(aModule);
|
||||
if (value.isUndefined()) {
|
||||
JS_ReportErrorASCII(aCx, "Module script not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto script = static_cast<ModuleScript*>(value.toPrivate());
|
||||
MOZ_DIAGNOSTIC_ASSERT(script->ModuleRecord() == aModule);
|
||||
|
||||
nsAutoCString url;
|
||||
MOZ_DIAGNOSTIC_ASSERT(script->BaseURL());
|
||||
MOZ_ALWAYS_SUCCEEDS(script->BaseURL()->GetAsciiSpec(url));
|
||||
|
||||
JS::Rooted<JSString*> urlString(aCx, JS_NewStringCopyZ(aCx, url.get()));
|
||||
if (!urlString) {
|
||||
JS_ReportOutOfMemory(aCx);
|
||||
return false;
|
||||
}
|
||||
|
||||
return JS_DefineProperty(aCx, aMetaObject, "url", urlString, JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
static void
|
||||
EnsureModuleResolveHook(JSContext* aCx)
|
||||
{
|
||||
@@ -848,6 +876,7 @@ EnsureModuleResolveHook(JSContext* aCx)
|
||||
}
|
||||
|
||||
JS::SetModuleResolveHook(rt, HostResolveImportedModule);
|
||||
JS::SetModuleMetadataHook(aCx, HostPopulateImportMeta);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user