MCPcopy Create free account
hub / github.com/Snapchat/Valdi / preCompile

Method preCompile

valdi/src/valdi/quickjs/QuickJSJavaScriptContext.cpp:273–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273Valdi::BytesView QuickJSJavaScriptContext::preCompile(const std::string_view& script,
274 const std::string_view& sourceFilename,
275 Valdi::JSExceptionTracker& exceptionTracker) {
276 auto guard = _threadAccessChecker.guard();
277 auto formattedScript = Valdi::formatJsModule(script);
278
279 auto evalResult = checkCallAndGetValue(exceptionTracker,
280 JS_Eval(_context,
281 reinterpret_cast<const char*>(formattedScript.data()),
282 formattedScript.length(),
283 sourceFilename.data(),
284 JS_EVAL_FLAG_COMPILE_ONLY));
285 if (!exceptionTracker) {
286 return Valdi::BytesView();
287 }
288
289 size_t objectSize = 0;
290
291 auto* buffer = JS_WriteObject(_context, &objectSize, fromValdiJSValue(evalResult.get()), JS_WRITE_OBJ_BYTECODE);
292 if (buffer == nullptr) {
293 checkCallAndGetValue(exceptionTracker, JS_ThrowInternalError(_context, "Could not write object"));
294 return Valdi::BytesView();
295 }
296
297 auto jsModule = Valdi::makePreCompiledJsModule(reinterpret_cast<const Valdi::Byte*>(buffer), objectSize);
298
299 js_free(_context, buffer);
300
301 return jsModule;
302}
303
304Valdi::JSValueRef QuickJSJavaScriptContext::evaluatePreCompiled(const Valdi::BytesView& script,
305 const std::string_view& /*sourceFilename*/,

Callers

nothing calls this directly

Calls 8

formatJsModuleFunction · 0.85
makePreCompiledJsModuleFunction · 0.85
guardMethod · 0.80
fromValdiJSValueFunction · 0.70
getMethod · 0.65
BytesViewClass · 0.50
dataMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected