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

Function load_module_init

gjs/importer.cpp:314–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312}
313
314GJS_JSAPI_RETURN_CONVENTION
315static JSObject* load_module_init(JSContext* cx, JS::HandleObject in_object,
316 GFile* file) {
317 bool found;
318 const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
319
320 // First we check if js module has already been loaded
321 if (!JS_HasPropertyById(cx, in_object, atoms.module_init(), &found))
322 return nullptr;
323 if (found) {
324 JS::RootedValue v_module(cx);
325 if (!JS_GetPropertyById(cx, in_object, atoms.module_init(),
326 &v_module))
327 return nullptr;
328 if (v_module.isObject())
329 return &v_module.toObject();
330
331 Gjs::AutoChar full_path{g_file_get_parse_name(file)};
332 gjs_throw(cx, "Unexpected non-object module __init__ imported from %s",
333 full_path.get());
334 return nullptr;
335 }
336
337 JS::RootedObject module_obj(cx, JS_NewPlainObject(cx));
338 if (!module_obj)
339 return nullptr;
340
341 if (!import_module_init(cx, file, module_obj))
342 return nullptr;
343
344 if (!JS_DefinePropertyById(cx, in_object, atoms.module_init(), module_obj,
345 GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT))
346 return nullptr;
347
348 return module_obj;
349}
350
351GJS_JSAPI_RETURN_CONVENTION
352static bool load_module_elements(JSContext* cx, JS::HandleObject in_object,

Callers 2

load_module_elementsFunction · 0.85

Calls 3

gjs_throwFunction · 0.85
import_module_initFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected