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

Function InvokeCallable

valdi/src/valdi/v8/V8JavaScriptContext.cpp:291–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291static 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
337JSValueRef V8JavaScriptContext::newFunction(const Ref<JSFunction>& callable, JSExceptionTracker& exceptionTracker) {
338 v8::HandleScope handleScope(_isolate);

Callers

nothing calls this directly

Calls 15

GetDataMethod · 0.80
LengthMethod · 0.80
setThisValueMethod · 0.80
ThisMethod · 0.80
interruptRequestedMethod · 0.80
GetReturnValueMethod · 0.80
getExceptionAndClearMethod · 0.80
toValdiJSValueFunction · 0.70
fromValdiJSValueFunction · 0.70
getMethod · 0.65
CastFunction · 0.50
GetIsolateMethod · 0.45

Tested by

no test coverage detected