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

Function import_module_init

gjs/importer.cpp:285–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283}
284
285GJS_JSAPI_RETURN_CONVENTION
286static bool import_module_init(JSContext* cx, GFile* file,
287 JS::HandleObject module_obj) {
288 gsize script_len = 0; // Do not use size_t, may be different width
289 Gjs::AutoError error;
290
291 GjsContextPrivate* gjs = GjsContextPrivate::from_cx(cx);
292 JS::RootedValue ignored{cx};
293
294 Gjs::AutoChar script;
295 if (!g_file_load_contents(file, nullptr, script.out(), &script_len, nullptr,
296 &error)) {
297 if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY) &&
298 !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY) &&
299 !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
300 gjs_throw_gerror_message(cx, error);
301 return false;
302 }
303
304 return true;
305 }
306 g_assert(script);
307
308 Gjs::AutoChar full_path{g_file_get_parse_name(file)};
309
310 return gjs->eval_with_scope(module_obj, script, script_len, full_path,
311 &ignored);
312}
313
314GJS_JSAPI_RETURN_CONVENTION
315static JSObject* load_module_init(JSContext* cx, JS::HandleObject in_object,

Callers 1

load_module_initFunction · 0.85

Calls 3

gjs_throw_gerror_messageFunction · 0.85
eval_with_scopeMethod · 0.80
outMethod · 0.45

Tested by

no test coverage detected