Skip to content

Commit 216d583

Browse files
committed
fix: use len > 0 guard for unshift fast path
1 parent f992be8 commit 216d583

File tree

1 file changed

+5
-1
lines changed
  • core/engine/src/builtins/array

1 file changed

+5
-1
lines changed

core/engine/src/builtins/array/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,11 @@ impl Array {
12941294

12951295
// Small optimization for arrays using dense properties.
12961296
// Mirrors the fast-path in `shift`.
1297-
if o.is_array() {
1297+
// Guard: only take the fast path when len > 0, because for empty
1298+
// arrays (len == 0) there are no own indexed properties and `Set`
1299+
// must traverse the prototype chain (which may have setters that
1300+
// freeze the array or make `length` non-writable mid-operation).
1301+
if o.is_array() && len > 0 {
12981302
let mut o_borrow = o.borrow_mut();
12991303
let props = &mut o_borrow.properties_mut().indexed_properties;
13001304

0 commit comments

Comments
 (0)