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

Method valueToTypedArray

valdi/src/valdi/quickjs/QuickJSJavaScriptContext.cpp:881–919  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

879
880Valdi::JSValueRef QuickJSJavaScriptContext::getObjectPropertyForIndex(const Valdi::JSValue& object,
881 size_t index,
882 Valdi::JSExceptionTracker& exceptionTracker) {
883 auto guard = _threadAccessChecker.guard();
884 return checkCallAndGetValue(exceptionTracker,
885 JS_GetPropertyUint32(_context, fromValdiJSValue(object), static_cast<uint32_t>(index)));
886}
887
888JSValue QuickJSJavaScriptContext::getConstructorFromObject(const Valdi::JSValue& object,
889 const std::string_view& propertyName,
890 Valdi::JSExceptionTracker& exceptionTracker) {
891 auto value = getObjectProperty(object, propertyName, exceptionTracker);
892 if (!exceptionTracker) {
893 return JS_UNDEFINED;
894 }
895 auto jsValue = fromValdiJSValue(value.get());
896
897 if (JS_IsConstructor(_context, jsValue) == 0) {
898 exceptionTracker.onError(Valdi::Error(STRING_FORMAT("{} is not a constructor", propertyName)));
899 return JS_UNDEFINED;
900 }
901
902 value.unsafeReleaseValue();
903
904 return jsValue;
905}
906
907bool QuickJSJavaScriptContext::hasObjectProperty(const Valdi::JSValue& object,
908 const Valdi::JSPropertyName& propertyName) {
909 auto guard = _threadAccessChecker.guard();
910 return JS_HasProperty(_context, fromValdiJSValue(object), fromValdiJSPropertyName(propertyName)) != 0;
911}
912
913void QuickJSJavaScriptContext::setObjectProperty(const Valdi::JSValue& object,
914 const std::string_view& propertyName,
915 const Valdi::JSValue& propertyValue,
916 bool enumerable,
917 Valdi::JSExceptionTracker& exceptionTracker) {
918 auto guard = _threadAccessChecker.guard();
919 // JS_SetProperty() automatically releases the given value.
920 auto retainedJsValue = JS_DupValue(_context, fromValdiJSValue(propertyValue));
921
922 if (VALDI_LIKELY(enumerable)) {

Callers

nothing calls this directly

Calls 4

JSTypedArrayClass · 0.85
toValdiTypedArrayTypeFunction · 0.85
guardMethod · 0.80
fromValdiJSValueFunction · 0.70

Tested by

no test coverage detected