|
8 | 8 |
|
9 | 9 | #include "FFICache.h" |
10 | 10 | #include "FFICall.h" |
| 11 | +#include "JSErrors.h" |
11 | 12 | #include "ObjCTypes.h" |
12 | 13 | #include <JavaScriptCore/JSObjectRef.h> |
13 | 14 | #include <JavaScriptCore/JSPromiseDeferred.h> |
|
70 | 71 | } |
71 | 72 |
|
72 | 73 | EncodedJSValue JSC_HOST_CALL FunctionWrapper::call(ExecState* execState) { |
73 | | - FunctionWrapper* call = jsCast<FunctionWrapper*>(execState->callee().asCell()); |
| 74 | + NS_TRY { |
| 75 | + FunctionWrapper* call = jsCast<FunctionWrapper*>(execState->callee().asCell()); |
74 | 76 |
|
75 | | - const std::unique_ptr<FFICall>& c = Metadata::getProperFunctionFromContainer<std::unique_ptr<FFICall>>(call->functionsContainer(), execState->argumentCount(), [](const std::unique_ptr<FFICall>& fficall) { return static_cast<int>(fficall.get()->parametersCount()); }); |
76 | | - FFICall* callee = c.get(); |
| 77 | + const std::unique_ptr<FFICall>& c = Metadata::getProperFunctionFromContainer<std::unique_ptr<FFICall>>(call->functionsContainer(), execState->argumentCount(), [](const std::unique_ptr<FFICall>& fficall) { return static_cast<int>(fficall.get()->parametersCount()); }); |
| 78 | + FFICall* callee = c.get(); |
77 | 79 |
|
78 | | - ASSERT(callee); |
| 80 | + ASSERT(callee); |
79 | 81 |
|
80 | | - FFICall::Invocation invocation(callee); |
81 | | - ReleasePoolHolder releasePoolHolder(execState); |
82 | | - |
83 | | - JSC::VM& vm = execState->vm(); |
| 82 | + FFICall::Invocation invocation(callee); |
| 83 | + ReleasePoolHolder releasePoolHolder(execState); |
84 | 84 |
|
85 | | - [[TNSRuntime current] tryCollectGarbage]; |
| 85 | + JSC::VM& vm = execState->vm(); |
86 | 86 |
|
87 | | - auto scope = DECLARE_THROW_SCOPE(vm); |
| 87 | + [[TNSRuntime current] tryCollectGarbage]; |
88 | 88 |
|
89 | | - callee->preCall(execState, invocation); |
90 | | - if (scope.exception()) { |
91 | | - return JSValue::encode(scope.exception()); |
92 | | - } |
93 | | - |
94 | | - @try { |
95 | | - { |
96 | | - JSLock::DropAllLocks locksDropper(execState); |
97 | | - ffi_call(callee->cif()->get(), FFI_FN(invocation.function), invocation.resultBuffer(), reinterpret_cast<void**>(invocation._buffer + callee->argsArrayOffset())); |
98 | | - } |
| 89 | + auto scope = DECLARE_THROW_SCOPE(vm); |
99 | 90 |
|
| 91 | + callee->preCall(execState, invocation); |
100 | 92 | if (scope.exception()) { |
101 | | - // in the ffi call the native method could reach javascript code throwing an error we don't need the code below to execute |
102 | 93 | return JSValue::encode(scope.exception()); |
103 | 94 | } |
104 | 95 |
|
105 | | - JSValue result = callee->returnType().read(execState, invocation._buffer + callee->returnOffset(), callee->returnTypeCell().get()); |
| 96 | + @try { |
| 97 | + { |
| 98 | + JSLock::DropAllLocks locksDropper(execState); |
| 99 | + ffi_call(callee->cif()->get(), FFI_FN(invocation.function), invocation.resultBuffer(), reinterpret_cast<void**>(invocation._buffer + callee->argsArrayOffset())); |
| 100 | + } |
| 101 | + |
| 102 | + if (scope.exception()) { |
| 103 | + // in the ffi call the native method could reach javascript code throwing an error we don't need the code below to execute |
| 104 | + return JSValue::encode(scope.exception()); |
| 105 | + } |
106 | 106 |
|
107 | | - callee->postCall(execState, invocation); |
108 | | - return JSValue::encode(result); |
109 | | - } @catch (NSException* exception) { |
110 | | - return throwVMError(execState, scope, createErrorFromNSException([TNSRuntime current], execState, exception)); |
| 107 | + JSValue result = callee->returnType().read(execState, invocation._buffer + callee->returnOffset(), callee->returnTypeCell().get()); |
| 108 | + |
| 109 | + callee->postCall(execState, invocation); |
| 110 | + return JSValue::encode(result); |
| 111 | + } @catch (NSException* exception) { |
| 112 | + return throwVMError(execState, scope, createErrorFromNSException([TNSRuntime current], execState, exception)); |
| 113 | + } |
111 | 114 | } |
| 115 | + NS_CATCH_THROW_TO_JS(execState) |
| 116 | + |
| 117 | + return JSValue::encode(jsUndefined()); |
112 | 118 | } |
113 | 119 |
|
114 | 120 | JSObject* FunctionWrapper::async(ExecState* execState, JSValue thisValue, const ArgList& arguments) { |
|
0 commit comments