From 98de6872cd05a17e9df3e97e3bc524e15690c463 Mon Sep 17 00:00:00 2001 From: Ryan Tremblay Date: Sun, 24 May 2020 17:54:29 -0700 Subject: [PATCH 1/3] Enable array buffers since the current JSC version used in react native supports them --- ReactCommon/jsi/JSCRuntime.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/ReactCommon/jsi/JSCRuntime.cpp b/ReactCommon/jsi/JSCRuntime.cpp index 0a09afb7dae6fa..1da1e4539a0093 100644 --- a/ReactCommon/jsi/JSCRuntime.cpp +++ b/ReactCommon/jsi/JSCRuntime.cpp @@ -922,24 +922,17 @@ 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; - throw std::runtime_error("Unsupported"); +bool JSCRuntime::isArrayBuffer(const jsi::Object &obj) const { + auto typedArrayType = JSValueGetTypedArrayType(ctx_, objectRef(obj), nullptr); + return typedArrayType == kJSTypedArrayTypeArrayBuffer; } -uint8_t *JSCRuntime::data(const jsi::ArrayBuffer & /*obj*/) { - // TODO: T23270523 - This would fail on builds that use our custom JSC - // return static_cast( - // JSObjectGetArrayBufferBytesPtr(ctx_, objectRef(obj), nullptr)); - throw std::runtime_error("Unsupported"); +uint8_t *JSCRuntime::data(const jsi::ArrayBuffer &obj) { + return static_cast(JSObjectGetArrayBufferBytesPtr(ctx_, objectRef(obj), nullptr)); } -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); - throw std::runtime_error("Unsupported"); +size_t JSCRuntime::size(const jsi::ArrayBuffer &obj) { + return JSObjectGetArrayBufferByteLength(ctx_, objectRef(obj), nullptr); } bool JSCRuntime::isFunction(const jsi::Object &obj) const { From be548fd86d0a4c3896871bf21c557572e4470060 Mon Sep 17 00:00:00 2001 From: Ryan Tremblay Date: Tue, 26 May 2020 16:50:49 -0700 Subject: [PATCH 2/3] Add compile time checks for iOS/MacOS versions before calling array buffer related JSC functions --- ReactCommon/jsi/JSCRuntime.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ReactCommon/jsi/JSCRuntime.cpp b/ReactCommon/jsi/JSCRuntime.cpp index 1da1e4539a0093..a9c0d44c898ae2 100644 --- a/ReactCommon/jsi/JSCRuntime.cpp +++ b/ReactCommon/jsi/JSCRuntime.cpp @@ -276,6 +276,9 @@ class JSCRuntime : public jsi::Runtime { #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0 #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 @@ -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 @@ -923,16 +929,28 @@ bool JSCRuntime::isArray(const jsi::Object &obj) const { } 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) { +#if defined(_JSC_NO_ARRAY_BUFFERS) + throw std::runtime_error("Unsupported"); +#else return static_cast(JSObjectGetArrayBufferBytesPtr(ctx_, objectRef(obj), nullptr)); +#endif } 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); +#endif } bool JSCRuntime::isFunction(const jsi::Object &obj) const { From e0027664f96ce2a5ab937630945e7f2c5b868be6 Mon Sep 17 00:00:00 2001 From: Ryan Tremblay Date: Thu, 28 May 2020 20:09:05 -0700 Subject: [PATCH 3/3] Restore original formatting to not break linting(?) rules --- ReactCommon/jsi/JSCRuntime.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ReactCommon/jsi/JSCRuntime.cpp b/ReactCommon/jsi/JSCRuntime.cpp index a9c0d44c898ae2..7fa26885060ee0 100644 --- a/ReactCommon/jsi/JSCRuntime.cpp +++ b/ReactCommon/jsi/JSCRuntime.cpp @@ -932,7 +932,8 @@ 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); + auto typedArrayType = JSValueGetTypedArrayType(ctx_, objectRef(obj), + nullptr); return typedArrayType == kJSTypedArrayTypeArrayBuffer; #endif } @@ -941,7 +942,8 @@ uint8_t *JSCRuntime::data(const jsi::ArrayBuffer &obj) { #if defined(_JSC_NO_ARRAY_BUFFERS) throw std::runtime_error("Unsupported"); #else - return static_cast(JSObjectGetArrayBufferBytesPtr(ctx_, objectRef(obj), nullptr)); + return static_cast( + JSObjectGetArrayBufferBytesPtr(ctx_, objectRef(obj), nullptr)); #endif }