Skip to content

Commit 15ab4f0

Browse files
committed
splice must not perform HasProperty past the end of the deleted range.
(cherry picked from commit dd3d3a9)
1 parent 6387ead commit 15ab4f0

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/ArrayPrototypeBuiltins.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ protected Object splice(Object thisArg, Object[] args,
19981998
if (actualDeleteCount > 0) {
19991999
// copy deleted elements into result array
20002000
branchDelete.enter(this);
2001-
spliceRead(thisObj, actualStart, actualDeleteCount, aObj, len);
2001+
spliceRead(thisObj, actualStart, actualDeleteCount, aObj);
20022002
}
20032003
setLength(aObj, actualDeleteCount);
20042004

@@ -2065,15 +2065,16 @@ final boolean mustUseElementwise(JSDynamicObject obj, long expectedLength, Scrip
20652065
array.length(obj) != expectedLength;
20662066
}
20672067

2068-
private void spliceRead(Object thisObj, long actualStart, long actualDeleteCount, Object aObj, long length) {
2068+
private void spliceRead(Object thisObj, long actualStart, long actualDeleteCount, Object aObj) {
2069+
final long deleteEnd = actualDeleteCount + actualStart;
20692070
long kPlusStart = actualStart;
20702071
if (!hasProperty(thisObj, kPlusStart)) {
2071-
kPlusStart = nextElementIndex(thisObj, kPlusStart, length);
2072+
kPlusStart = nextElementIndex(thisObj, kPlusStart, deleteEnd);
20722073
}
2073-
while (kPlusStart < (actualDeleteCount + actualStart)) {
2074+
while (kPlusStart < deleteEnd) {
20742075
Object fromValue = read(thisObj, kPlusStart);
20752076
writeOwn(aObj, kPlusStart - actualStart, fromValue);
2076-
kPlusStart = nextElementIndex(thisObj, kPlusStart, length);
2077+
kPlusStart = nextElementIndex(thisObj, kPlusStart, deleteEnd);
20772078
}
20782079
}
20792080

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/array/JSArrayNextElementIndexNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -161,11 +161,11 @@ public long nextObjectViaFullEnumeration(JSDynamicObject object, long currentInd
161161
public long nextObjectViaPolling(Object object, long currentIndex, long length, @SuppressWarnings("unused") boolean isArray,
162162
@Cached @Shared JSHasPropertyNode hasPropertyNode) {
163163
long index = currentIndex + 1;
164-
while (!hasPropertyNode.executeBoolean(object, index)) {
164+
while (index < length && !hasPropertyNode.executeBoolean(object, index)) {
165165
index++;
166-
if (index >= length) {
167-
return JSRuntime.MAX_SAFE_INTEGER_LONG;
168-
}
166+
}
167+
if (index >= length) {
168+
return JSRuntime.MAX_SAFE_INTEGER_LONG;
169169
}
170170
return index;
171171
}

0 commit comments

Comments
 (0)