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}
374
375Valdi::JSValueRef QuickJSJavaScriptContext::newFunction(const Valdi::Ref<Valdi::JSFunction>& callable,
376 Valdi::JSExceptionTracker& exceptionTracker) {
377 auto guard = _threadAccessChecker.guard();
378 // TODO(simon): Use functionName
379
380 auto functionObject =
381 checkCallAndGetValue(exceptionTracker, JS_NewObjectProtoClass(_context, _functionPrototype, _functionClassID));
382 if (!exceptionTracker) {
383 return Valdi::JSValueRef();
384 }
385
386 setObjectCallable(fromValdiJSValue(functionObject.get()), callable);
387
388 if (!callable->getReferenceInfo().getName().isEmpty()) {
389 auto value = newStringUTF8(callable->getReferenceInfo().getName().toStringView(), exceptionTracker);
390 if (!exceptionTracker) {
391 return Valdi::JSValueRef();
392 }
393
394 // JS_DefinePropertyValueStr() automatically releases the given value.
395 auto retainedName = JS_DupValue(_context, fromValdiJSValue(value.get()));
396
397 checkCall(exceptionTracker,
398 JS_DefinePropertyValueStr(_context, fromValdiJSValue(functionObject.get()), "name", retainedName, 0));
399
400 if (!exceptionTracker) {
401 return Valdi::JSValueRef();
402 }
403 }
404
405 return functionObject;
406}
407
408size_t QuickJSJavaScriptContext::associateWeakReference(const JSValue& value,
409 Valdi::JSExceptionTracker& exceptionTracker) {

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