Skip to content

Commit

Permalink
Fix setting array elements through JSI (facebook#38521)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#38521

`HermesRuntimeImpl::setValueAtIndexImpl` directly called
`setElementAt`, which meant that it would not handle index-like
properties properly. Use `putComputed_RJS` instead, which will check
for such properties.

Reviewed By: avp

Differential Revision: D47617445

fbshipit-source-id: c3505670960bd6223bd014f138cee191267a5315
  • Loading branch information
neildhar authored and facebook-github-bot committed Jul 20, 2023
1 parent b675667 commit 2669f8c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/react-native/ReactCommon/jsi/jsi/test/testlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,20 @@ TEST_P(JSITest, ArrayTest) {
Array alpha2 = Array(rt, 1);
alpha2 = std::move(alpha);
EXPECT_EQ(alpha2.size(rt), 4);

// Test getting/setting an element that is an accessor.
auto arrWithAccessor =
eval(
"Object.defineProperty([], '0', {set(){ throw 72 }, get(){ return 45 }});")
.getObject(rt)
.getArray(rt);
try {
arrWithAccessor.setValueAtIndex(rt, 0, 1);
FAIL() << "Expected exception";
} catch (const JSError& err) {
EXPECT_EQ(err.value().getNumber(), 72);
}
EXPECT_EQ(arrWithAccessor.getValueAtIndex(rt, 0).getNumber(), 45);
}

TEST_P(JSITest, FunctionTest) {
Expand Down

0 comments on commit 2669f8c

Please sign in to comment.