Carries out the actual execution of the module code
| 107 | |
| 108 | // Carries out the actual execution of the module code |
| 109 | GJS_JSAPI_RETURN_CONVENTION |
| 110 | bool evaluate_import(JSContext* cx, JS::HandleObject module, |
| 111 | const char* source, size_t source_len, |
| 112 | const char* filename, const char* uri) { |
| 113 | JS::SourceText<mozilla::Utf8Unit> buf; |
| 114 | if (!buf.init(cx, source, source_len, JS::SourceOwnership::Borrowed)) |
| 115 | return false; |
| 116 | |
| 117 | JS::EnvironmentChain scope_chain{cx, JS::SupportUnscopables::No}; |
| 118 | if (!scope_chain.append(module)) { |
| 119 | JS_ReportOutOfMemory(cx); |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | JS::CompileOptions options(cx); |
| 124 | options.setFileAndLine(filename, 1).setNonSyntacticScope(true); |
| 125 | |
| 126 | JS::RootedObject priv(cx, build_private(cx, uri)); |
| 127 | if (!priv) |
| 128 | return false; |
| 129 | |
| 130 | JS::RootedScript script(cx, JS::Compile(cx, options, buf)); |
| 131 | if (!script) |
| 132 | return false; |
| 133 | |
| 134 | JS::SetScriptPrivate(script, JS::ObjectValue(*priv)); |
| 135 | JS::RootedValue ignored_retval(cx); |
| 136 | if (!JS_ExecuteScript(cx, scope_chain, script, &ignored_retval)) |
| 137 | return false; |
| 138 | |
| 139 | GjsContextPrivate* gjs = GjsContextPrivate::from_cx(cx); |
| 140 | gjs->schedule_gc_if_needed(); |
| 141 | |
| 142 | gjs_debug(GJS_DEBUG_IMPORTER, "Importing module %s succeeded", |
| 143 | m_name.get()); |
| 144 | |
| 145 | return true; |
| 146 | } |
| 147 | |
| 148 | // Loads JS code from a file and imports it |
| 149 | GJS_JSAPI_RETURN_CONVENTION |
nothing calls this directly
no test coverage detected