Skip to content

Commit 6031905

Browse files
tsaichienfacebook-github-bot
authored andcommitted
Fix JSI isArray method to match JS Array.isArray (#53998)
Summary: Pull Request resolved: #53998 As the previous few diffs, JSI `isArray` API should follow `Array.isArray` from the JS spec. The current implementation does not consider Proxy objects, only Array exotic objects. Changelog: [Internal] Reviewed By: lavenzg Differential Revision: D83391784 fbshipit-source-id: 6db8e5a48458a1aa57006fb0747f62ec78efa675
1 parent 990ca0d commit 6031905

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/react-native/ReactCommon/jsc/JSCRuntime.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,14 @@ void JSCRuntime::setPropertyValue(
10471047
}
10481048

10491049
bool JSCRuntime::isArray(const jsi::Object& obj) const {
1050-
return JSValueIsArray(ctx_, objectRef(obj));
1050+
// JSValueIsArray only returns true if the object is a JS array. There's no
1051+
// public JSC API equivalent to Array.isArray, so we call the JS function
1052+
// through JSI directly.
1053+
auto constRt = const_cast<JSCRuntime*>(this);
1054+
auto isArrayFn = constRt->global()
1055+
.getPropertyAsObject(*constRt, "Array")
1056+
.getPropertyAsFunction(*constRt, "isArray");
1057+
return isArrayFn.call(*constRt, obj).asBool();
10511058
}
10521059

10531060
bool JSCRuntime::isArrayBuffer(const jsi::Object& obj) const {

0 commit comments

Comments
 (0)