diff options
author | Brian Smith <brian@dbsoft.org> | 2023-04-08 15:01:22 -0500 |
---|---|---|
committer | Brian Smith <brian@dbsoft.org> | 2023-04-27 13:32:52 -0500 |
commit | 6eecfad57c57c4c305149d1f5634628e80b0cca6 (patch) | |
tree | 99f5ac2f20d4b7895562c38502de690d1160a8f1 /dom/script | |
parent | 12291f8248618690d78e2f93265eea3aeee333d2 (diff) | |
download | uxp-6eecfad57c57c4c305149d1f5634628e80b0cca6.tar.gz |
Issue #1691 - Part 3: Finish implementing import meta.
https://bugzilla.mozilla.org/show_bug.cgi?id=1427610
(cherry picked from commit a8625238ac846fb7eb103646ddb8634a5860f067)
Diffstat (limited to 'dom/script')
-rw-r--r-- | dom/script/ScriptLoader.cpp | 31 |
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 |