Skip to content

Commit 9014a7b

Browse files
committed
add test for relative-indexing-method proposal and enable test262 tests
1 parent af51bbc commit 9014a7b

File tree

2 files changed

+85
-3
lines changed

2 files changed

+85
-3
lines changed

graal-js/src/com.oracle.truffle.js.test.external/src/com/oracle/truffle/js/test/external/test262/Test262Runnable.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public class Test262Runnable extends TestRunnable {
8989

9090
private static final Set<String> SUPPORTED_FEATURES = new HashSet<>(Arrays.asList(new String[]{
9191
"AggregateError",
92+
"Array.prototype.at",
9293
"Array.prototype.flat",
9394
"Array.prototype.flatMap",
9495
"Array.prototype.values",
@@ -133,6 +134,7 @@ public class Test262Runnable extends TestRunnable {
133134
"Set",
134135
"SharedArrayBuffer",
135136
"String.fromCodePoint",
137+
"String.prototype.at",
136138
"String.prototype.endsWith",
137139
"String.prototype.includes",
138140
"String.prototype.matchAll",
@@ -155,6 +157,7 @@ public class Test262Runnable extends TestRunnable {
155157
"Symbol.toStringTag",
156158
"Symbol.unscopables",
157159
"TypedArray",
160+
"TypedArray.prototype.at",
158161
"Uint16Array",
159162
"Uint32Array",
160163
"Uint8Array",
@@ -220,19 +223,19 @@ public class Test262Runnable extends TestRunnable {
220223
"top-level-await",
221224
}));
222225
private static final Set<String> UNSUPPORTED_FEATURES = new HashSet<>(Arrays.asList(new String[]{
223-
"Array.prototype.at",
224226
"Atomics.waitAsync",
225227
"Intl.DateTimeFormat-dayPeriod",
226228
"Intl.DateTimeFormat-formatRange",
227229
"Intl.DateTimeFormat-fractionalSecondDigits",
228230
"IsHTMLDDA",
229-
"String.prototype.at",
230-
"TypedArray.prototype.at",
231231
"align-detached-buffer-semantics-with-web-reality",
232232
"arbitrary-module-namespace-names",
233233
"tail-call-optimization",
234234
}));
235235
private static final Set<String> ES2022_FEATURES = new HashSet<>(Arrays.asList(new String[]{
236+
"Array.prototype.at",
237+
"String.prototype.at",
238+
"TypedArray.prototype.at",
236239
"class-fields-private",
237240
"class-fields-public",
238241
"class-methods-private",
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2020, 2020, 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+
* Test for the relative-indexing-method proposal.
9+
* https://tc39.es/proposal-relative-indexing-method/
10+
*
11+
* @option ecmascript-version=2022
12+
*/
13+
14+
load('../assert.js');
15+
16+
function arrayPrototypeTest() {
17+
var arr = [0,1,2,3,4,5];
18+
19+
//in bound
20+
assertSame(0, arr.at(0));
21+
assertSame(1, arr.at(1));
22+
assertSame(5, arr.at(5));
23+
24+
//out of bound
25+
assertSame(undefined, arr.at(6));
26+
assertSame(5, arr.at(-1));
27+
assertSame(4, arr.at(-2));
28+
29+
//general
30+
assertSame(1, Array.prototype.at.length);
31+
}
32+
33+
function stringPrototypeTest() {
34+
var str = "Graal.js";
35+
36+
//in bound
37+
assertSame("G", str.at(0));
38+
assertSame("r", str.at(1));
39+
assertSame("s", str.at(7));
40+
41+
//out of bound
42+
assertSame(undefined, str.at(100));
43+
assertSame("s", str.at(-1));
44+
assertSame("j", str.at(-2));
45+
46+
//general
47+
assertSame(1, String.prototype.at.length);
48+
}
49+
50+
function typedArrayPrototypeTestIntl(constr) {
51+
var arr = new constr([0,1,2,3,4,5]);
52+
53+
//in bound
54+
assertSame(0, arr.at(0));
55+
assertSame(1, arr.at(1));
56+
assertSame(5, arr.at(5));
57+
58+
//out of bound
59+
assertSame(undefined, arr.at(100));
60+
assertSame(5, arr.at(-1));
61+
assertSame(4, arr.at(-2));
62+
63+
//general
64+
assertSame(1, constr.prototype.at.length);
65+
}
66+
67+
function typedArrayPrototypeTest() {
68+
var types = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array,
69+
Uint32Array, Float32Array, Float64Array];
70+
types.forEach( constr => {
71+
typedArrayPrototypeTestIntl(constr);
72+
});
73+
}
74+
75+
arrayPrototypeTest();
76+
stringPrototypeTest();
77+
typedArrayPrototypeTest();
78+
79+
true;

0 commit comments

Comments
 (0)