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

Method newFunction

valdi/src/valdi/quickjs/QuickJSJavaScriptContext.cpp:375–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373 auto guard = _threadAccessChecker.guard();
374 const auto* cString = JS_AtomToCString(_context, fromValdiJSPropertyName(propertyName));
375 if (cString == nullptr) {
376 return Valdi::StringBox();
377 }
378
379 auto convertedString = Valdi::StringCache::makeStringFromCLiteral(cString);
380
381 JS_FreeCString(_context, cString);
382
383 return convertedString;
384}
385
386Valdi::JSValueRef QuickJSJavaScriptContext::newObject(Valdi::JSExceptionTracker& exceptionTracker) {
387 auto guard = _threadAccessChecker.guard();
388 return checkCallAndGetValue(exceptionTracker, JS_NewObject(_context));
389}
390
391Valdi::JSValueRef QuickJSJavaScriptContext::newFunction(const Valdi::Ref<Valdi::JSFunction>& callable,
392 Valdi::JSExceptionTracker& exceptionTracker) {
393 auto guard = _threadAccessChecker.guard();
394 // TODO(simon): Use functionName
395
396 auto functionObject =
397 checkCallAndGetValue(exceptionTracker, JS_NewObjectProtoClass(_context, _functionPrototype, _functionClassID));
398 if (!exceptionTracker) {
399 return Valdi::JSValueRef();
400 }
401
402 setObjectCallable(fromValdiJSValue(functionObject.get()), callable);
403
404 if (!callable->getReferenceInfo().getName().isEmpty()) {
405 auto value = newStringUTF8(callable->getReferenceInfo().getName().toStringView(), exceptionTracker);
406 if (!exceptionTracker) {
407 return Valdi::JSValueRef();
408 }
409

Callers

nothing calls this directly

Calls 8

setObjectCallableFunction · 0.85
JS_DupValueFunction · 0.85
guardMethod · 0.80
fromValdiJSValueFunction · 0.70
getMethod · 0.65
isEmptyMethod · 0.45
getNameMethod · 0.45
toStringViewMethod · 0.45

Tested by

no test coverage detected