| 965 | } |
| 966 | |
| 967 | JSTypedArray HermesJavaScriptContext::valueToTypedArray(const JSValue& value, JSExceptionTracker& exceptionTracker) { |
| 968 | hermes::vm::GCScope gcScope(*_runtime); |
| 969 | auto* hermesValue = toPinnedHermesValue(value); |
| 970 | |
| 971 | if (hermes::vm::vmisa<hermes::vm::JSArrayBuffer>(*hermesValue)) { |
| 972 | auto handle = hermes::vm::Handle<hermes::vm::JSArrayBuffer>::vmcast(hermesValue); |
| 973 | if (!handle->attached()) { |
| 974 | return JSTypedArray(); |
| 975 | } |
| 976 | |
| 977 | auto* data = handle->getDataBlock(*_runtime); |
| 978 | auto size = handle->size(); |
| 979 | |
| 980 | return JSTypedArray(TypedArrayType::ArrayBuffer, data, size, JSValueRef::makeUnretained(*this, value)); |
| 981 | } else if (hermes::vm::vmisa<hermes::vm::JSTypedArrayBase>(*hermesValue)) { |
| 982 | auto handle = hermes::vm::Handle<hermes::vm::JSTypedArrayBase>::vmcast(hermesValue); |
| 983 | if (!handle->attached(*_runtime)) { |
| 984 | return JSTypedArray(); |
| 985 | } |
| 986 | |
| 987 | auto type = getTypedArrayType(*hermesValue); |
| 988 | auto* data = handle->begin(*_runtime); |
| 989 | auto size = static_cast<size_t>(handle->getByteLength()); |
| 990 | auto* arrayBuffer = handle->getBuffer(*_runtime); |
| 991 | |
| 992 | return JSTypedArray( |
| 993 | type, data, size, toJSValueRef(hermes::vm::HermesValue::encodeObjectValue(arrayBuffer, *_runtime))); |
| 994 | } else { |
| 995 | exceptionTracker.onError("Not a TypedArray or ArrayBuffer"); |
| 996 | return JSTypedArray(); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | static bool hasNativeState(hermes::vm::Runtime& runtime, const hermes::vm::Handle<hermes::vm::JSObject>& jsObject) { |
| 1001 | if (!canReceiveNativeState(jsObject.get())) { |
nothing calls this directly
no test coverage detected