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

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