Skip to content

Commit

Permalink
Remove redundant ifdefs for ArrayBuffer backwards compatibility (#39302)
Browse files Browse the repository at this point in the history
Summary:
We're well past a minimum iOS 10 / macOS 10.11 version. Let's remove these ifdefs that seemed to have been added for backwards compatibility around the use of [ArrayBuffers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)

## Changelog:

[IOS] [REMOVED] - Remove redundant ifdefs for ArrayBuffer backwards compatibility

Pull Request resolved: #39302

Test Plan: CI should pass.

Reviewed By: rshest

Differential Revision: D49007666

Pulled By: javache

fbshipit-source-id: 03ebe303eda45ce043e3c2f9e2a5165ba798b15c
  • Loading branch information
Saadnajmi authored and facebook-github-bot committed Sep 6, 2023
1 parent 8973978 commit fb30fca
Showing 1 changed file with 0 additions and 65 deletions.
65 changes: 0 additions & 65 deletions packages/react-native/ReactCommon/jsc/JSCRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,29 +291,10 @@ class JSCRuntime : public jsi::Runtime {
} while (0)

#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
// This takes care of watch and tvos (due to backwards compatibility in
// Availability.h
#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
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400
#define _JSC_HAS_INSPECTABLE
#endif
#endif
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_11
// Only one of these should be set for a build. If somehow that's not
// true, this will be a compile-time error and it can be resolved when
// 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
namespace {
Expand Down Expand Up @@ -361,18 +342,6 @@ JSStringRef getFunctionString() {
static JSStringRef func = JSStringCreateWithUTF8CString("Function");
return func;
}

#if !defined(_JSC_FAST_IS_ARRAY)
JSStringRef getArrayString() {
static JSStringRef array = JSStringCreateWithUTF8CString("Array");
return array;
}

JSStringRef getIsArrayString() {
static JSStringRef isArray = JSStringCreateWithUTF8CString("isArray");
return isArray;
}
#endif
} // namespace

// std::string utility
Expand Down Expand Up @@ -988,55 +957,21 @@ void JSCRuntime::setPropertyValue(
}

bool JSCRuntime::isArray(const jsi::Object& obj) const {
#if !defined(_JSC_FAST_IS_ARRAY)
JSObjectRef global = JSContextGetGlobalObject(ctx_);
JSStringRef arrayString = getArrayString();
JSValueRef exc = nullptr;
JSValueRef arrayCtorValue =
JSObjectGetProperty(ctx_, global, arrayString, &exc);
JSC_ASSERT(exc);
JSObjectRef arrayCtor = JSValueToObject(ctx_, arrayCtorValue, &exc);
JSC_ASSERT(exc);
JSStringRef isArrayString = getIsArrayString();
JSValueRef isArrayValue =
JSObjectGetProperty(ctx_, arrayCtor, isArrayString, &exc);
JSC_ASSERT(exc);
JSObjectRef isArray = JSValueToObject(ctx_, isArrayValue, &exc);
JSC_ASSERT(exc);
JSValueRef arg = objectRef(obj);
JSValueRef result =
JSObjectCallAsFunction(ctx_, isArray, nullptr, 1, &arg, &exc);
JSC_ASSERT(exc);
return JSValueToBoolean(ctx_, result);
#else
return JSValueIsArray(ctx_, objectRef(obj));
#endif
}

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<uint8_t*>(
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 {
Expand Down

0 comments on commit fb30fca

Please sign in to comment.