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

Method valueToFunction

valdi/src/valdi/v8/V8JavaScriptContext.cpp:915–938  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

913}
914
915Ref<JSFunction> V8JavaScriptContext::valueToFunction(const JSValue& value, JSExceptionTracker& exceptionTracker) {
916 v8::HandleScope handleScope(_isolate);
917
918 auto val = v8::Local<v8::Function>::Cast(fromValdiJSValue(_isolate, value, exceptionTracker));
919 if (!val->IsFunction()) {
920 exceptionTracker.onError("Was not provided with a function value");
921 return nullptr;
922 }
923
924 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(_isolate, _context);
925 v8::Local<v8::Private> privateProp = _functionDataProperty.Get(_isolate);
926 if (val->HasPrivate(context, privateProp).IsNothing()) {
927 exceptionTracker.onError("Provided function was not wrapped by the v8 js context");
928 return nullptr;
929 }
930
931 auto data = v8::Local<v8::External>::Cast(val->GetPrivate(context, privateProp).ToLocalChecked());
932 if (!data->IsExternal()) {
933 exceptionTracker.onError("Provided function did not contain data of the expected type");
934 return nullptr;
935 }
936
937 return unsafeBridge<JSFunction>(data->Value());
938}
939
940ValueType V8JavaScriptContext::getValueType(const JSValue& value) {
941 v8::HandleScope handleScope(_isolate);

Callers 1

jsFunctionToFunctionFunction · 0.45

Calls 8

ToLocalCheckedMethod · 0.80
fromValdiJSValueFunction · 0.70
onErrorMethod · 0.65
CastFunction · 0.50
NewFunction · 0.50
GetMethod · 0.45
IsNothingMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected