Debian Codegraph @

js/src/tests/test262/built-ins/RegExp/match-indices/indices-array-element.js

raw
1 // Copyright 2019 Ron Buckton. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 description: A matching element of indices is an Array with exactly two number properties.
6 esid: sec-getmatchindicesarray
7 features: [regexp-match-indices]
8 info: |
9 GetMatchIndicesArray ( S, match )
10 5. Return CreateArrayFromList(« _match_.[[StartIndex]], _match_.[[EndIndex]] »).
11 ---*/
12
13 let input = "abcd";
14 let match = /b(c)/d.exec(input);
15 let indices = match.indices;
16
17 // `indices[0]` is an array
18 assert.sameValue(Object.getPrototypeOf(indices[0]), Array.prototype);
19 assert.sameValue(indices[0].length, 2);
20 assert.sameValue(typeof indices[0][0], "number");
21 assert.sameValue(typeof indices[0][1], "number");
22
23 // `indices[1]` is an array
24 assert.sameValue(Object.getPrototypeOf(indices[1]), Array.prototype);
25 assert.sameValue(indices[1].length, 2);
26 assert.sameValue(typeof indices[1][0], "number");
27 assert.sameValue(typeof indices[1][1], "number");
28
29 reportCompare(0, 0);