summaryrefslogtreecommitdiff
path: root/dom/script
diff options
context:
space:
mode:
Diffstat (limited to 'dom/script')
-rw-r--r--dom/script/ScriptLoader.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
index 6aba06f3f9..70db30a625 100644
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -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