| 25 | } |
| 26 | |
| 27 | JSValueRef 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 | |
| 63 | void finalize(JSObjectRef object) { |
| 64 | Valdi::RefCountableAutoreleasePool::release(JSObjectGetPrivate(object)); |
no test coverage detected