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

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