Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions lib/VM/JSObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,10 +1455,11 @@ CallResult<bool> JSObject::putNamedWithReceiver_RJS(
// object/proxy/internal setter, and the property is writable,
// just write into the same slot.

bool isSameObj = *selfHandle == propObj &&
selfHandle.getHermesValue().getRaw() == receiver->getRaw();

if (LLVM_LIKELY(
*selfHandle == propObj &&
selfHandle.getHermesValue().getRaw() == receiver->getRaw() &&
!desc.flags.accessor && !desc.flags.internalSetter &&
isSameObj && !desc.flags.accessor && !desc.flags.internalSetter &&
!desc.flags.hostObject && !desc.flags.proxyObject &&
desc.flags.writable)) {
auto shv = SmallHermesValue::encodeHermesValue(*valueHandle, runtime);
Expand Down Expand Up @@ -1520,7 +1521,7 @@ CallResult<bool> JSObject::putNamedWithReceiver_RJS(
return false;
}

if (*selfHandle == propObj && desc.flags.internalSetter) {
if (isSameObj && desc.flags.internalSetter) {
return internalSetter(
selfHandle, runtime, name, desc, valueHandle, opFlags);
}
Expand Down
30 changes: 30 additions & 0 deletions test/hermes/regress-array-proxy-length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// RUN: %hermes -O %s | %FileCheck --match-full-lines %s

print("proxy-length");
// CHECK: proxy-length

let output = [];
let arr = new Proxy([], {
defineProperty(target, property, attributes) {
output.push("def-" + property);
return Reflect.defineProperty(target, property, attributes)
},
deleteProperty(target, property) {
output.push("del-" + property);
return Reflect.deleteProperty(target, property)
},
});

arr.push('a', 'b', 'c')
arr.pop()
arr.shift()
arr.length = 1
print(output);
// CHECK-NEXT: def-0,def-1,def-2,def-length,del-2,def-length,def-0,del-1,def-length,def-length