Debian Codegraph @

rhino/testsrc/jstests/extensions/external-array-test.js

raw symbols SCIP
1 load('testsrc/assert.js');
2
3 function checkArray(expectedCount) {
4 for (var i = 0; i < testArrayLength; i++) {
5 assertEquals(i, testArray[i]);
6 }
7
8 var eltCount = 0;
9 for (var n in testArray) {
10 eltCount++;
11 }
12 assertEquals(expectedCount, eltCount);
13 }
14
15 assertTrue(testArray != undefined);
16 assertEquals(testArrayLength, testArray.length);
17
18 // Set newly-created array to an array of values
19 for (var i = 0; i < testArrayLength; i++) {
20 testArray[i] = i;
21 }
22
23 checkArray(testArrayLength);
24
25 if (!regularArray) {
26 // External data means that we can't extend the array
27 assertThrows(function() {
28 testArray[testArrayLength] = testArrayLength;
29 });
30 // Also that stuff after the end of the array is "undefined"
31 assertEquals(testArray[testArrayLength], undefined);
32 }
33
34 // Should be able to handle non-indexed properties as well, and still be enumerable
35 testArray.stringField = 'Hello!';
36 testArray.intField = 42;
37
38 for (var i = 0; i < testArrayLength; i++) {
39 assertEquals(i, testArray[i]);
40 }
41
42 // Adding non-indexed properties should affect the element count but not "length"
43 assertEquals('Hello!', testArray.stringField);
44 assertEquals(42, testArray.intField);
45 assertEquals(testArrayLength, testArray.length);
46
47 var eltCount = 0;
48 for (var n in testArray) {
49 eltCount++;
50 }
51 assertEquals(testArrayLength + 2, eltCount);