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

Function gjs_js_define_system_stuff

modules/system.cpp:289–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289bool gjs_js_define_system_stuff(JSContext* cx, JS::MutableHandleObject module) {
290 module.set(JS_NewPlainObject(cx));
291
292 if (!JS_DefineFunctions(cx, module, &module_funcs[0]))
293 return false;
294
295 GjsContextPrivate* gjs = GjsContextPrivate::from_cx(cx);
296 const char* program_name = gjs->program_name();
297 const char* program_path = gjs->program_path();
298
299 JS::RootedValue v_program_invocation_name{cx};
300 JS::RootedValue v_program_path{cx, JS::NullValue()};
301 if (program_path) {
302 if (!gjs_string_from_utf8(cx, program_path, &v_program_path))
303 return false;
304 }
305
306 JS::RootedObject program_args_getter{
307 cx, JS_GetFunctionObject(js::NewFunctionByIdWithReserved(
308 cx, get_program_args, 0, 0, gjs->atoms().program_args()))};
309
310 return program_args_getter &&
311 gjs_string_from_utf8(cx, program_name, &v_program_invocation_name) &&
312 // The name is modeled after program_invocation_name, part of glibc
313 JS_DefinePropertyById(cx, module,
314 gjs->atoms().program_invocation_name(),
315 v_program_invocation_name,
316 GJS_MODULE_PROP_FLAGS | JSPROP_READONLY) &&
317 JS_DefinePropertyById(cx, module, gjs->atoms().program_path(),
318 v_program_path,
319 GJS_MODULE_PROP_FLAGS | JSPROP_READONLY) &&
320 JS_DefinePropertyById(cx, module, gjs->atoms().program_args(),
321 program_args_getter, nullptr,
322 GJS_MODULE_PROP_FLAGS) &&
323 JS_DefinePropertyById(cx, module, gjs->atoms().version(),
324 GJS_VERSION,
325 GJS_MODULE_PROP_FLAGS | JSPROP_READONLY);
326}

Callers

nothing calls this directly

Calls 4

gjs_string_from_utf8Function · 0.85
setMethod · 0.80
program_nameMethod · 0.80
program_pathMethod · 0.80

Tested by

no test coverage detected