* gjs_import_native_module: * @cx: the #JSContext * @importer: the root importer * @id_str: Name under which the module was registered with add() * * Imports a builtin native-code module so that it is available to JS code as * `imports[id_str]`. * * Returns: true on success, false if an exception was thrown. */
| 258 | * Returns: true on success, false if an exception was thrown. |
| 259 | */ |
| 260 | bool gjs_import_native_module(JSContext* cx, JS::HandleObject importer, |
| 261 | const char* id_str) { |
| 262 | gjs_debug(GJS_DEBUG_IMPORTER, "Importing '%s'", id_str); |
| 263 | |
| 264 | JS::RootedObject native_registry( |
| 265 | cx, gjs_get_native_registry(JS::CurrentGlobalOrNull(cx))); |
| 266 | |
| 267 | JS::RootedId id(cx, gjs_intern_string_to_id(cx, id_str)); |
| 268 | if (id.isVoid()) |
| 269 | return false; |
| 270 | |
| 271 | JS::RootedObject module(cx); |
| 272 | if (!gjs_global_registry_get(cx, native_registry, id, &module)) |
| 273 | return false; |
| 274 | |
| 275 | if (!module && |
| 276 | (!Gjs::NativeModuleDefineFuncs::get().define(cx, id_str, &module) || |
| 277 | !gjs_global_registry_set(cx, native_registry, id, module))) |
| 278 | return false; |
| 279 | |
| 280 | return define_meta_properties(cx, module, nullptr, id_str, importer) && |
| 281 | JS_DefineProperty(cx, importer, id_str, module, |
| 282 | GJS_MODULE_PROP_FLAGS); |
| 283 | } |
| 284 | |
| 285 | GJS_JSAPI_RETURN_CONVENTION |
| 286 | static bool import_module_init(JSContext* cx, GFile* file, |
no test coverage detected