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

Function compile_module

gjs/internal.cpp:155–176  ·  view source on GitHub ↗

* compile_module: * @cx: the current JSContext * @uri: The URI of the module * @source: The source text of the module * @v_module_out: (out): Return location for the module as a JS value * * Compiles the a module source text into an internal #Module object given the * module's URI as the first argument. * * Returns: whether an error occurred while compiling the module. */

Source from the content-addressed store, hash-verified

153 * Returns: whether an error occurred while compiling the module.
154 */
155static bool compile_module(JSContext* cx, const JS::UniqueChars& uri,
156 JS::HandleString source,
157 JS::MutableHandleValue v_module_out) {
158 JS::CompileOptions options(cx);
159 options.setFileAndLine(uri.get(), 1).setSourceIsLazy(false);
160
161 size_t text_len;
162 char16_t* text;
163 if (!gjs_string_get_char16_data(cx, source, &text, &text_len))
164 return false;
165
166 JS::SourceText<char16_t> buf;
167 if (!buf.init(cx, text, text_len, JS::SourceOwnership::TakeOwnership))
168 return false;
169
170 JS::RootedObject new_module(cx, JS::CompileModule(cx, options, buf));
171 if (!new_module)
172 return false;
173
174 v_module_out.setObject(*new_module);
175 return true;
176}
177
178/**
179 * gjs_internal_compile_internal_module:

Calls 3

getMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected