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

Function callAsFunction

valdi/src/valdi/jscore/JSCoreCustomClasses.cpp:27–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27JSValueRef callAsFunction(JSContextRef ctx,
28 JSObjectRef function,
29 JSObjectRef thisObject,
30 size_t argumentCount,
31 const JSValueRef arguments[],
32 JSValueRef* exception) {
33 auto* attachedJsFunctionData = getAttachedJsFunctionData(function);
34 auto& jsContext = attachedJsFunctionData->jsContext;
35
36 Valdi::JSValueRef outArguments[argumentCount];
37 for (size_t i = 0; i < argumentCount; i++) {
38 outArguments[i] = Valdi::JSValueRef::makeUnretained(
39 jsContext, toValdiJSValue(JSCoreRef(arguments[i], JSValueGetType(ctx, arguments[i]))));
40 }
41
42 Valdi::JSExceptionTracker exceptionTracker(attachedJsFunctionData->jsContext);
43 Valdi::JSFunctionNativeCallContext callContext(attachedJsFunctionData->jsContext,
44 outArguments,
45 static_cast<size_t>(argumentCount),
46 exceptionTracker,
47 attachedJsFunctionData->function->getReferenceInfo());
48 callContext.setThisValue(toValdiJSValue(JSCoreRef(thisObject, kJSTypeObject)));
49
50 if (attachedJsFunctionData->jsContext.interruptRequested()) {
51 attachedJsFunctionData->jsContext.onInterrupt();
52 }
53
54 auto result = (*attachedJsFunctionData->function)(callContext);
55
56 if (VALDI_LIKELY(exceptionTracker)) {
57 return fromValdiJSValue(result.get()).valueRef;
58 } else {
59 return onJsCallError(ctx, exceptionTracker, exception);
60 }
61}
62
63void finalize(JSObjectRef object) {
64 Valdi::RefCountableAutoreleasePool::release(JSObjectGetPrivate(object));

Callers 1

callMethod · 0.85

Calls 9

JSCoreRefClass · 0.85
setThisValueMethod · 0.80
interruptRequestedMethod · 0.80
toValdiJSValueFunction · 0.70
fromValdiJSValueFunction · 0.70
onJsCallErrorFunction · 0.70
getMethod · 0.65
onInterruptMethod · 0.45

Tested by

no test coverage detected