| 1116 | } |
| 1117 | |
| 1118 | int32_t QuickJSJavaScriptContext::valueToInt(const Valdi::JSValue& value, Valdi::JSExceptionTracker& exceptionTracker) { |
| 1119 | auto guard = _threadAccessChecker.guard(); |
| 1120 | int32_t number = 0; |
| 1121 | |
| 1122 | if (!checkCall(exceptionTracker, JS_ToInt32(_context, &number, fromValdiJSValue(value)))) { |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | return number; |
| 1127 | } |
| 1128 | |
| 1129 | Valdi::Ref<Valdi::RefCountable> QuickJSJavaScriptContext::valueToWrappedObject( |
| 1130 | const Valdi::JSValue& value, Valdi::JSExceptionTracker& /*exceptionTracker*/) { |
| 1131 | auto guard = _threadAccessChecker.guard(); |
| 1132 | return Valdi::unwrapNativeClassInstanceData(getObjectWrappedObject(fromValdiJSValue(value))); |
| 1133 | } |
| 1134 | |
| 1135 | Valdi::Ref<Valdi::JSFunction> QuickJSJavaScriptContext::valueToFunction( |
| 1136 | const Valdi::JSValue& value, Valdi::JSExceptionTracker& /*exceptionTracker*/) { |
| 1137 | auto guard = _threadAccessChecker.guard(); |
| 1138 | return Valdi::Ref(getObjectCallable(fromValdiJSValue(value))); |
| 1139 | } |
| 1140 | |
| 1141 | Valdi::JSTypedArray QuickJSJavaScriptContext::valueToTypedArray(const Valdi::JSValue& value, |
| 1142 | Valdi::JSExceptionTracker& exceptionTracker) { |
| 1143 | auto guard = _threadAccessChecker.guard(); |
| 1144 | auto jsValue = fromValdiJSValue(value); |
| 1145 | |
| 1146 | if (JS_IsArrayBuffer(_context, jsValue) != 0) { |
| 1147 | size_t size = 0; |
| 1148 | auto* buffer = JS_GetArrayBuffer(_context, &size, jsValue); |
| 1149 | |
| 1150 | if (!checkCall(exceptionTracker, buffer == nullptr ? -1 : 0)) { |
| 1151 | return Valdi::JSTypedArray(); |
| 1152 | } |
| 1153 | |
| 1154 | return Valdi::JSTypedArray(Valdi::ArrayBuffer, buffer, size, toUnretainedJSValueRef(jsValue)); |
| 1155 | } else { |
| 1156 | auto arrayType = JS_GetTypedArrayType(_context, jsValue); |
| 1157 | if (arrayType == JS_TYPED_ARRAY_NONE) { |
| 1158 | checkCallAndGetValue(exceptionTracker, JS_ThrowTypeError(_context, "value is not a typed array")); |
| 1159 | return Valdi::JSTypedArray(); |
| 1160 | } |
| 1161 | |
| 1162 | auto arrayBuffer = checkCallAndGetValue(exceptionTracker, |
| 1163 | JS_GetTypedArrayBuffer(_context, jsValue, nullptr, nullptr, nullptr)); |
| 1164 | if (!exceptionTracker) { |
| 1165 | return Valdi::JSTypedArray(); |
| 1166 | } |
| 1167 | |
| 1168 | size_t length = 0; |
| 1169 | size_t bytesLength = 0; |
| 1170 | auto* ptr = JS_GetTypedArrayData(_context, jsValue, &length, &bytesLength); |
| 1171 | if (!checkCall(exceptionTracker, ptr == nullptr ? -1 : 0)) { |
| 1172 | return Valdi::JSTypedArray(); |
| 1173 | } |
| 1174 | |
| 1175 | auto type = toValdiTypedArrayType(arrayType); |
nothing calls this directly
no test coverage detected