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
915JSTypedArray V8JavaScriptContext::valueToTypedArray(const JSValue& value, JSExceptionTracker& exceptionTracker) {
916 v8::HandleScope handleScope(_isolate);
917
918 v8::Local<v8::Value> val = fromValdiJSValue(_isolate, value, exceptionTracker);
919 if (!val->IsTypedArray()) {
920 exceptionTracker.onError("Value is not TypedArray");
921 return JSTypedArray();
922 }
923 v8::Local<v8::TypedArray> arr = v8::Local<v8::TypedArray>::Cast(val);
924 const auto type = getTypedArrayType(val);
925 void* data = arr->Buffer()->Data();
926 const size_t length = arr->ByteLength();
927 return JSTypedArray(type, data, length, toRetainedJSValueRef(IndirectV8Persistent::make(_isolate, val)));
928}
929
930Ref<JSFunction> V8JavaScriptContext::valueToFunction(const JSValue& value, JSExceptionTracker& exceptionTracker) {
931 v8::HandleScope handleScope(_isolate);
932
933 auto val = v8::Local<v8::Function>::Cast(fromValdiJSValue(_isolate, value, exceptionTracker));
934 if (!val->IsFunction()) {
935 exceptionTracker.onError("Was not provided with a function value");
936 return nullptr;
937 }
938
939 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(_isolate, _context);
940 v8::Local<v8::Private> privateProp = _functionDataProperty.Get(_isolate);
941 if (val->HasPrivate(context, privateProp).IsNothing()) {

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