MCPcopy Create free account
hub / github.com/GNOME/gjs / gjs_import_native_module

Function gjs_import_native_module

gjs/importer.cpp:260–283  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

258 * Returns: true on success, false if an exception was thrown.
259 */
260bool 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
285GJS_JSAPI_RETURN_CONVENTION
286static bool import_module_init(JSContext* cx, GFile* file,

Callers 1

do_importFunction · 0.85

Calls 8

gjs_debugFunction · 0.85
gjs_get_native_registryFunction · 0.85
gjs_intern_string_to_idFunction · 0.85
gjs_global_registry_getFunction · 0.85
gjs_global_registry_setFunction · 0.85
define_meta_propertiesFunction · 0.85
defineMethod · 0.80
getFunction · 0.50

Tested by

no test coverage detected