* define: * @cx: the #JSContext * @id: Name under which the module was registered with add() * @module_out: Return location for a #JSObject * * Loads a builtin native-code module called @name into @module_out by calling * the function to define it. * * Returns: true on success, false if an exception was thrown. */
| 56 | * Returns: true on success, false if an exception was thrown. |
| 57 | */ |
| 58 | bool Gjs::NativeModuleDefineFuncs::define( |
| 59 | JSContext* cx, const char* id, JS::MutableHandleObject module_out) const { |
| 60 | gjs_debug(GJS_DEBUG_NATIVE, "Defining native module '%s'", id); |
| 61 | |
| 62 | const auto& iter = m_modules.find(id); |
| 63 | |
| 64 | if (iter == m_modules.end()) { |
| 65 | gjs_throw(cx, "No native module '%s' has registered itself", id); |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | return iter->second(cx, module_out); |
| 70 | } |
no test coverage detected