Skip to content

Commit 850509e

Browse files
OracleLabsAutomationelkorchi
authored andcommitted
[GR-64696] Backport to 24.2: Correction of Array.prototype.flat() producing a foreign array.
PullRequest: js/3496
2 parents 53ceb45 + bbef026 commit 850509e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
load("./assert.js")
9+
10+
// Original test-case from the fuzzer
11+
function f0() {
12+
return f0;
13+
}
14+
const v1 = [64,-16952,591226145];
15+
v1[5] = f0;
16+
v1[3] = v1;
17+
const v4 = this.Java.to(v1);
18+
const v5 = v4.flat();
19+
function f6(a7, a8) {
20+
return v4;
21+
}
22+
function f9(a10) {
23+
return v4;
24+
}
25+
f6[Symbol.species] = f9;
26+
v5.constructor = f6;
27+
assertThrows(() => v5.flat(), TypeError);
28+
29+
// Simplified test-case
30+
Object.defineProperty(Array, Symbol.species, { value: Java.type('java.util.ArrayList') });
31+
assertSameContent([42, 211, -1], [[42, 211], -1].flat());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2444,7 +2444,7 @@ private static final class InnerFlattenCallNode extends JavaScriptRootNode {
24442444
@Override
24452445
public Object execute(VirtualFrame frame) {
24462446
Object[] arguments = frame.getArguments();
2447-
JSDynamicObject resultArray = (JSDynamicObject) arguments[0];
2447+
Object resultArray = arguments[0];
24482448
Object element = arguments[1];
24492449
long elementLen = (long) arguments[2];
24502450
long targetIndex = (long) arguments[3];

0 commit comments

Comments
 (0)