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

Method load_native_module

gjs/global.cpp:117–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115 }
116
117 GJS_JSAPI_RETURN_CONVENTION
118 static bool load_native_module(JSContext* m_cx, unsigned argc,
119 JS::Value* vp) {
120 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
121
122 // This function should never be directly exposed to user code, so we
123 // can be strict.
124 g_assert(argc == 1);
125 g_assert(args[0].isString());
126
127 JS::RootedString str{m_cx, args[0].toString()};
128 JS::UniqueChars id(JS_EncodeStringToUTF8(m_cx, str));
129
130 if (!id)
131 return false;
132
133 JS::RootedObject native_obj(m_cx);
134
135 if (!Gjs::NativeModuleDefineFuncs::get().define(m_cx, id.get(),
136 &native_obj)) {
137 gjs_throw(m_cx, "Failed to load native module: %s", id.get());
138 return false;
139 }
140
141 args.rval().setObject(*native_obj);
142 return true;
143 }
144};
145
146const JSClassOps defaultclassops = JS::DefaultGlobalClassOps;

Callers

nothing calls this directly

Calls 5

gjs_throwFunction · 0.85
defineMethod · 0.80
getFunction · 0.50
toStringMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected