mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
57 lines
1.8 KiB
/*===
|
|
[1,2,null,4]
|
|
[1,2,null,4,null,null,null,null]
|
|
[1,2,null,4,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"foo"]
|
|
2 1 2 entry-in-proto undefined
|
|
[1,2]
|
|
===*/
|
|
|
|
/* E5.1 Section 15.12.3, algorithm JA(), step 6 indicates that array elements
|
|
* must be enumerated in ascending array index order, and that the value of
|
|
* the "length" property must be obeyed. All missing elements are 'undefined'
|
|
* and will serialize as "null".
|
|
*
|
|
* In particular, if an ancestor has an array index property above the Array's
|
|
* "length", it must not be serialized.
|
|
*
|
|
* Also, sparse arrays (internal array part has been abandoned) must still
|
|
* enumerate according to array index order.
|
|
*/
|
|
|
|
function arrayLengthTest1() {
|
|
var arr;
|
|
var k;
|
|
|
|
// base case
|
|
arr = [ 1, 2, undefined, 4 ];
|
|
print(JSON.stringify(arr));
|
|
|
|
// length must be obeyed even if no elements have been added
|
|
arr = [ 1, 2, undefined, 4 ];
|
|
arr.length = 8;
|
|
print(JSON.stringify(arr));
|
|
|
|
arr = [ 1, 2 ];
|
|
arr[100] = 'foo';
|
|
arr[3] = 4;
|
|
print(JSON.stringify(arr));
|
|
}
|
|
|
|
// Note: this test changes Array.prototype so run this last
|
|
function arrayLengthTest2() {
|
|
var arr;
|
|
|
|
arr = [ 1, 2 ];
|
|
Array.prototype[2] = 'entry-in-proto';
|
|
|
|
print(arr.length, arr[0], arr[1], arr[2], arr[3]);
|
|
|
|
print(JSON.stringify(arr));
|
|
}
|
|
|
|
try {
|
|
arrayLengthTest1();
|
|
arrayLengthTest2();
|
|
} catch (e) {
|
|
print(e.name);
|
|
}
|
|
|