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

Method newFunction

valdi/src/valdi/v8/V8JavaScriptContext.cpp:337–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335 }
336}
337
338JSValueRef V8JavaScriptContext::newFunction(const Ref<JSFunction>& callable, JSExceptionTracker& exceptionTracker) {
339 v8::HandleScope handleScope(_isolate);
340
341 auto externalData =
342 IndirectV8Persistent::makeWeakExternal(_isolate, unsafeBridgeRetain(callable.get()), freeWrappedPointer);
343 auto funcTemplate = v8::FunctionTemplate::New(_isolate, InvokeCallable, externalData);
344
345 v8::Local<v8::Function> func;
346 funcTemplate->SetClassName(v8::String::NewFromUtf8Literal(_isolate, "ValdiFunctionObject"));
347
348 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(_isolate, _context);
349
350 if (!funcTemplate->GetFunction(context).ToLocal(&func)) {
351 exceptionTracker.onError("Failed to create function");
352 return JSValueRef();
353 }
354
355 if (!callable->getReferenceInfo().getName().isEmpty()) {
356 auto callableName = callable->getReferenceInfo().getName().toStringView();
357 v8::MaybeLocal<v8::String> maybeValue = v8::String::NewFromUtf8(
358 _isolate, callableName.data(), v8::NewStringType::kNormal, static_cast<int32_t>(callableName.length()));
359
360 if (maybeValue.IsEmpty()) {
361 exceptionTracker.onError("Failed to convert function name to string");
362 return JSValueRef();
363 }
364
365 func->SetName(maybeValue.ToLocalChecked());
366 }
367
368 func->SetPrivate(context, _functionDataProperty.Get(_isolate), externalData);
369 return toRetainedJSValueRef(IndirectV8Persistent::make(_isolate, func));
370}
371
372Valdi::JSValueRef V8JavaScriptContext::newBigInt(const Valdi::BigInt& value,

Callers 2

unmarshallMethod · 0.45
mainFunction · 0.45

Calls 13

unsafeBridgeRetainFunction · 0.85
ToLocalMethod · 0.80
ToLocalCheckedMethod · 0.80
getMethod · 0.65
onErrorMethod · 0.65
NewFunction · 0.50
isEmptyMethod · 0.45
getNameMethod · 0.45
toStringViewMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected