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
272bool QuickJSJavaScriptContext::checkCall(Valdi::JSExceptionTracker& exceptionTracker, int retValue) {
273 if (retValue < 0) {
274 setExceptionToTracker(exceptionTracker);
275 return false;
276 }
277 return true;
278}
279
280Valdi::JSValueRef QuickJSJavaScriptContext::getGlobalObject(Valdi::JSExceptionTracker& exceptionTracker) {
281 auto guard = _threadAccessChecker.guard();
282 return checkCallAndGetValue(exceptionTracker, JS_GetGlobalObject(_context));
283}
284
285bool QuickJSJavaScriptContext::supportsPreCompilation() const {
286 return true;
287}
288
289Valdi::BytesView QuickJSJavaScriptContext::preCompile(const std::string_view& script,
290 const std::string_view& sourceFilename,
291 Valdi::JSExceptionTracker& exceptionTracker) {
292 auto guard = _threadAccessChecker.guard();
293 auto formattedScript = Valdi::formatJsModule(script);
294
295 auto evalResult = checkCallAndGetValue(exceptionTracker,
296 JS_Eval(_context,
297 reinterpret_cast<const char*>(formattedScript.data()),
298 formattedScript.length(),
299 sourceFilename.data(),
300 JS_EVAL_FLAG_COMPILE_ONLY));
301 if (!exceptionTracker) {
302 return Valdi::BytesView();
303 }
304
305 size_t objectSize = 0;

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