Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable array buffers in JSCRuntime.cpp #28961

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions ReactCommon/jsi/JSCRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ class JSCRuntime : public jsi::Runtime {
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth noting, this existing define looks wrong to me. I believe _JSC_FAST_IS_ARRAY will never be defined on Android, so will always use the slow version. Presumably this should be fixed, though I didn't really want to overload this PR.

#define _JSC_FAST_IS_ARRAY
#endif
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0
#define _JSC_NO_ARRAY_BUFFERS
#endif
#endif
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_11
Expand All @@ -284,6 +287,9 @@ class JSCRuntime : public jsi::Runtime {
// we understand why.
#define _JSC_FAST_IS_ARRAY
#endif
#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_12
#define _JSC_NO_ARRAY_BUFFERS
#endif
#endif

// JSStringRef utilities
Expand Down Expand Up @@ -922,24 +928,31 @@ bool JSCRuntime::isArray(const jsi::Object &obj) const {
#endif
}

bool JSCRuntime::isArrayBuffer(const jsi::Object & /*obj*/) const {
// TODO: T23270523 - This would fail on builds that use our custom JSC
// auto typedArrayType = JSValueGetTypedArrayType(ctx_, objectRef(obj),
// nullptr); return typedArrayType == kJSTypedArrayTypeArrayBuffer;
bool JSCRuntime::isArrayBuffer(const jsi::Object &obj) const {
#if defined(_JSC_NO_ARRAY_BUFFERS)
throw std::runtime_error("Unsupported");
#else
auto typedArrayType = JSValueGetTypedArrayType(ctx_, objectRef(obj),
nullptr);
return typedArrayType == kJSTypedArrayTypeArrayBuffer;
#endif
}

uint8_t *JSCRuntime::data(const jsi::ArrayBuffer & /*obj*/) {
// TODO: T23270523 - This would fail on builds that use our custom JSC
// return static_cast<uint8_t*>(
// JSObjectGetArrayBufferBytesPtr(ctx_, objectRef(obj), nullptr));
uint8_t *JSCRuntime::data(const jsi::ArrayBuffer &obj) {
#if defined(_JSC_NO_ARRAY_BUFFERS)
throw std::runtime_error("Unsupported");
#else
return static_cast<uint8_t*>(
JSObjectGetArrayBufferBytesPtr(ctx_, objectRef(obj), nullptr));
#endif
}

size_t JSCRuntime::size(const jsi::ArrayBuffer & /*obj*/) {
// TODO: T23270523 - This would fail on builds that use our custom JSC
// return JSObjectGetArrayBufferByteLength(ctx_, objectRef(obj), nullptr);
size_t JSCRuntime::size(const jsi::ArrayBuffer &obj) {
#if defined(_JSC_NO_ARRAY_BUFFERS)
throw std::runtime_error("Unsupported");
#else
return JSObjectGetArrayBufferByteLength(ctx_, objectRef(obj), nullptr);
ryantrem marked this conversation as resolved.
Show resolved Hide resolved
#endif
}

bool JSCRuntime::isFunction(const jsi::Object &obj) const {
Expand Down