| 289 | } |
| 290 | |
| 291 | static void InvokeCallable(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 292 | auto isolate = info.GetIsolate(); |
| 293 | v8::HandleScope handleScope(isolate); |
| 294 | |
| 295 | auto context = unsafeBridge<V8JavaScriptContext>(isolate->GetData(static_cast<int>(IsolateDataSlot::ContextSlot))); |
| 296 | |
| 297 | auto data = v8::Local<v8::External>::Cast(info.Data())->Value(); |
| 298 | if (data == nullptr) { |
| 299 | isolate->ThrowError("Provided function data was null"); |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | auto callable = unsafeBridge<JSFunction>(data); |
| 304 | JSValueRef outArguments[info.Length()]; |
| 305 | for (int i = 0; i < info.Length(); i++) { |
| 306 | outArguments[i] = |
| 307 | JSValueRef::makeUnretained(*context, toValdiJSValue(IndirectV8Persistent::make(isolate, info[i]))); |
| 308 | } |
| 309 | |
| 310 | JSExceptionTracker tracker(*context); |
| 311 | JSFunctionNativeCallContext callContext( |
| 312 | *context, outArguments, info.Length(), tracker, callable->getReferenceInfo()); |
| 313 | callContext.setThisValue(toValdiJSValue(IndirectV8Persistent::make(isolate, info.This()))); |
| 314 | |
| 315 | if (context->interruptRequested()) { |
| 316 | context->onInterrupt(); |
| 317 | } |
| 318 | |
| 319 | auto result = (*callable)(callContext); |
| 320 | |
| 321 | if (VALDI_LIKELY(tracker)) { |
| 322 | auto returnValue = fromValdiJSValue(isolate, result.get(), tracker); |
| 323 | if (VALDI_LIKELY(tracker)) { |
| 324 | info.GetReturnValue().Set(returnValue); |
| 325 | return; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | auto exception = fromValdiJSValue(isolate, tracker.getExceptionAndClear().get(), tracker); |
| 330 | if (VALDI_LIKELY(tracker)) { |
| 331 | isolate->ThrowException(exception); |
| 332 | } else { |
| 333 | isolate->ThrowError("Something went terriblely wrong and can't unpack underlying exception"); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | JSValueRef V8JavaScriptContext::newFunction(const Ref<JSFunction>& callable, JSExceptionTracker& exceptionTracker) { |
| 338 | v8::HandleScope handleScope(_isolate); |
nothing calls this directly
no test coverage detected