diff options
author | Evan Welsh <contact@evanwelsh.com> | 2020-10-16 18:25:00 -0500 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2020-12-03 16:46:34 -0800 |
commit | 88f7a54ebb0c51ec36ee3670f7686fdd5d55771c (patch) | |
tree | 8db51cdfe5d7440acf88652d2af75b6118d59452 /gjs/module.cpp | |
parent | 3c3592f90a24c55c6d4af9491d27f81e5453367f (diff) | |
download | gjs-88f7a54ebb0c51ec36ee3670f7686fdd5d55771c.tar.gz |
Add native registry for GI modules.
Diffstat (limited to 'gjs/module.cpp')
-rw-r--r-- | gjs/module.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/gjs/module.cpp b/gjs/module.cpp index 4e4a8b6a..d10b4727 100644 --- a/gjs/module.cpp +++ b/gjs/module.cpp @@ -20,9 +20,11 @@ #include <js/RootingAPI.h> #include <js/SourceText.h> #include <js/TypeDecls.h> +#include <js/Value.h> #include <jsapi.h> // for JS_DefinePropertyById, ... #include "gjs/context-private.h" +#include "gjs/global.h" #include "gjs/jsapi-util.h" #include "gjs/mem-private.h" #include "gjs/module.h" @@ -247,3 +249,23 @@ gjs_module_import(JSContext *cx, decltype(GjsScriptModule::klass) constexpr GjsScriptModule::klass; decltype(GjsScriptModule::class_ops) constexpr GjsScriptModule::class_ops; + +/** + * gjs_get_native_registry: + * + * @brief Retrieves a global's native registry from the NATIVE_REGISTRY slot. + * Registries are JS Map objects created with JS::NewMapObject instead + * of GCHashMaps (used elsewhere in GJS) because the objects need to be + * exposed to internal JS code and accessed from native C++ code. + * + * @param global a global #JSObject + * + * @returns the registry map as a #JSObject + */ +JSObject* gjs_get_native_registry(JSObject* global) { + JS::Value native_registry = + gjs_get_global_slot(global, GjsGlobalSlot::NATIVE_REGISTRY); + + g_assert(native_registry.isObject()); + return &native_registry.toObject(); +} |