1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
* Contributor:
* Jeff Walden <jwalden+code@mit.edu>
*/
//-----------------------------------------------------------------------------
var BUGNUMBER = 858381;
var summary =
"Array length redefinition behavior with non-configurable elements";
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
function addDataProperty(obj, prop, value, enumerable, configurable, writable)
{
var desc =
{ enumerable: enumerable,
configurable: configurable,
writable: writable,
value: value };
Object.defineProperty(obj, prop, desc);
}
function nonstrict()
{
var arr = [0, , 2, , , 5];
addDataProperty(arr, 31415926, "foo", true, true, true);
addDataProperty(arr, 123456789, "bar", true, true, false);
addDataProperty(arr, 8675309, "qux", false, true, true);
addDataProperty(arr, 1735039, "eit", false, true, false);
addDataProperty(arr, 987654321, "fun", false, true, false);
// non-array indexes to spice things up
addDataProperty(arr, "foopy", "sdfsd", false, false, false);
addDataProperty(arr, 4294967296, "psych", true, false, false);
addDataProperty(arr, 4294967295, "psych", true, false, false);
addDataProperty(arr, 27182818, "eep", false, false, false);
// Truncate...but only as far as possible.
arr.length = 1;
assertEq(arr.length, 27182819);
var props = Object.getOwnPropertyNames(arr).sort();
var expected =
["0", "2", "5", "1735039", "8675309", "27182818",
"foopy", "4294967296", "4294967295", "length"].sort();
assertEq(props.length, expected.length);
for (var i = 0; i < props.length; i++)
assertEq(props[i], expected[i], "unexpected property: " + props[i]);
}
nonstrict();
function strict()
{
"use strict";
var arr = [0, , 2, , , 5];
addDataProperty(arr, 31415926, "foo", true, true, true);
addDataProperty(arr, 123456789, "bar", true, true, false);
addDataProperty(arr, 8675309, "qux", false, true, true);
addDataProperty(arr, 1735039, "eit", false, true, false);
addDataProperty(arr, 987654321, "fun", false, true, false);
// non-array indexes to spice things up
addDataProperty(arr, "foopy", "sdfsd", false, false, false);
addDataProperty(arr, 4294967296, "psych", true, false, false);
addDataProperty(arr, 4294967295, "psych", true, false, false);
addDataProperty(arr, 27182818, "eep", false, false, false);
try
{
arr.length = 1;
throw new Error("didn't throw?!");
}
catch (e)
{
assertEq(e instanceof TypeError, true,
"non-configurable property should trigger TypeError, got " + e);
}
assertEq(arr.length, 27182819);
var props = Object.getOwnPropertyNames(arr).sort();
var expected =
["0", "2", "5", "1735039", "8675309", "27182818",
"foopy", "4294967296", "4294967295", "length"].sort();
assertEq(props.length, expected.length);
for (var i = 0; i < props.length; i++)
assertEq(props[i], expected[i], "unexpected property: " + props[i]);
}
strict();
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");
|