1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-02-02 15:09:23 -05:00

[spidermonkey] JSObject as a key, not std::string

There is a small progress, but still repeated requests to python's doc search fail.
This commit is contained in:
Witold Filipczyk 2024-09-20 18:54:49 +02:00
parent 1de2de8b1c
commit 2133aca5a0
2 changed files with 8 additions and 4 deletions

View File

@ -182,7 +182,7 @@ CompileExampleModule(JSContext* cx, const char* filename, const char* code, size
//
// NOTE: This example assumes only one JSContext/GlobalObject is used, but in
// general the registry needs to be distinct for each GlobalObject.
static std::map<std::u16string, JS::PersistentRootedObject> moduleRegistry;
std::map<JSObject *, JS::PersistentRootedObject> moduleRegistry;
// Callback for embedding to provide modules for import statements. This example
// hardcodes sources, but an embedding would normally load files here.
@ -202,9 +202,10 @@ ExampleResolveHook(JSContext* cx, JS::HandleValue modulePrivate, JS::HandleObjec
return nullptr;
}
std::u16string filename(specChars.get());
JSObject *global = JS::CurrentGlobalOrNull(cx);
// If we already resolved before, return same module.
auto search = moduleRegistry.find(filename);
auto search = moduleRegistry.find(global);
if (search != moduleRegistry.end()) {
return search->second;
@ -221,7 +222,7 @@ ExampleResolveHook(JSContext* cx, JS::HandleValue modulePrivate, JS::HandleObjec
// Register result in table.
if (mod) {
moduleRegistry.emplace(filename, JS::PersistentRootedObject(cx, mod));
moduleRegistry[global] = JS::PersistentRootedObject(cx, mod);
return mod;
}
JS_ReportErrorASCII(cx, "Cannot resolve import specifier");
@ -466,7 +467,6 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
goto release_and_fail;
}
#if 1
// Register a hook in order to provide modules
JS::SetModuleResolveHook(JS_GetRuntime(ctx), ExampleResolveHook);

View File

@ -54,6 +54,7 @@
#include "viewer/text/link.h"
#include "viewer/text/vs.h"
#include <map>
static bool window_get_property_closed(JSContext *cx, unsigned int argc, JS::Value *vp);
static bool window_get_property_event(JSContext *cx, unsigned int argc, JS::Value *vp);
@ -87,6 +88,8 @@ struct el_message {
struct el_window *elwin;
};
extern std::map<JSObject *, JS::PersistentRootedObject> moduleRegistry;
static void
window_finalize(JS::GCContext *op, JSObject *obj)
{
@ -104,6 +107,7 @@ window_finalize(JS::GCContext *op, JSObject *obj)
free_list(elwin->listeners);
mem_free(elwin);
}
moduleRegistry.erase(obj);
}
JSClassOps window_ops = {