[gjs/ewlsh/fix-dynamic-module-resolution] Test a few tweaks



commit 86141106ffbea9a49e9f439f16b4490b886a6dc5
Author: Evan Welsh <contact evanwelsh com>
Date:   Sun Jul 18 13:06:15 2021 -0700

    Test a few tweaks

 gjs/internal.cpp           | 9 +++++----
 modules/internal/loader.js | 4 +++-
 2 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gjs/internal.cpp b/gjs/internal.cpp
index a803eda4..30c1f9ae 100644
--- a/gjs/internal.cpp
+++ b/gjs/internal.cpp
@@ -551,7 +551,9 @@ static bool load_async_executor(JSContext* cx, unsigned argc, JS::Value* vp) {
 
     JS::Value priv_value = js::GetFunctionNativeReserved(&args.callee(), 0);
     g_assert(!priv_value.isNull() && "Executor called twice");
-    GjsAutoUnref<GFile> file = G_FILE(priv_value.toPrivate());
+    GjsAutoChar uri = reinterpret_cast<char*>(priv_value.toPrivate());
+    GjsAutoUnref<GFile> file = g_file_new_for_uri(uri);
+
     g_assert(file && "Executor called twice");
     // We now own the GFile, and will pass the reference to the GAsyncResult, so
     // remove it from the executor's private slot so it doesn't become dangling
@@ -573,8 +575,6 @@ bool gjs_internal_load_resource_or_file_async(JSContext* cx, unsigned argc,
                              &uri))
         return handle_wrong_args(cx);
 
-    GjsAutoUnref<GFile> file = g_file_new_for_uri(uri.get());
-
     JS::RootedObject executor(cx,
                               JS_GetFunctionObject(js::NewFunctionWithReserved(
                                   cx, load_async_executor, 2, 0,
@@ -583,7 +583,8 @@ bool gjs_internal_load_resource_or_file_async(JSContext* cx, unsigned argc,
         return false;
 
     // Stash the file object for the callback to find later; executor owns it
-    js::SetFunctionNativeReserved(executor, 0, JS::PrivateValue(file.copy()));
+    js::SetFunctionNativeReserved(executor, 0,
+                                  JS::PrivateValue(g_strdup(uri.get())));
 
     JSObject* promise = JS::NewPromiseObject(cx, executor);
     if (!promise)
diff --git a/modules/internal/loader.js b/modules/internal/loader.js
index 0d44f510..10c0bf51 100644
--- a/modules/internal/loader.js
+++ b/modules/internal/loader.js
@@ -141,7 +141,7 @@ class ModuleLoader extends InternalModuleLoader {
      * @returns {import("../types").Module}
      */
     async resolveModuleAsync(specifier, importingModuleURI) {
-        const registry = getRegistry(this.global);
+        let registry = getRegistry(this.global);
 
         // Check if the module has already been loaded
         let module = registry.get(specifier);
@@ -161,6 +161,8 @@ class ModuleLoader extends InternalModuleLoader {
             if (!result)
                 return null;
 
+            registry = getRegistry(this.global);
+
             // Check if module loaded while awaiting.
             module = registry.get(uri.uri);
             if (module)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]