|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 |
|
3 /* |
|
4 * Any copyright is dedicated to the Public Domain. |
|
5 * http://creativecommons.org/licenses/publicdomain/ |
|
6 */ |
|
7 |
|
8 var out = {}; |
|
9 |
|
10 function arr() { |
|
11 return Object.defineProperty([1, 2, 3, 4], 2, {configurable: false}); |
|
12 } |
|
13 |
|
14 function nonStrict1(out) |
|
15 { |
|
16 var a = out.array = arr(); |
|
17 a.length = 2; |
|
18 } |
|
19 |
|
20 function strict1(out) |
|
21 { |
|
22 "use strict"; |
|
23 var a = out.array = arr(); |
|
24 a.length = 2; |
|
25 return a; |
|
26 } |
|
27 |
|
28 out.array = null; |
|
29 nonStrict1(out); |
|
30 assertEq(deepEqual(out.array, [1, 2, 3]), true); |
|
31 |
|
32 out.array = null; |
|
33 try |
|
34 { |
|
35 strict1(out); |
|
36 throw "no error"; |
|
37 } |
|
38 catch (e) |
|
39 { |
|
40 assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); |
|
41 } |
|
42 assertEq(deepEqual(out.array, [1, 2, 3]), true); |
|
43 |
|
44 // Internally, SpiderMonkey has two representations for arrays: |
|
45 // fast-but-inflexible, and slow-but-flexible. Adding a non-index property |
|
46 // to an array turns it into the latter. We should test on both kinds. |
|
47 function addx(obj) { |
|
48 obj.x = 5; |
|
49 return obj; |
|
50 } |
|
51 |
|
52 function nonStrict2(out) |
|
53 { |
|
54 var a = out.array = addx(arr()); |
|
55 a.length = 2; |
|
56 } |
|
57 |
|
58 function strict2(out) |
|
59 { |
|
60 "use strict"; |
|
61 var a = out.array = addx(arr()); |
|
62 a.length = 2; |
|
63 } |
|
64 |
|
65 out.array = null; |
|
66 nonStrict2(out); |
|
67 assertEq(deepEqual(out.array, addx([1, 2, 3])), true); |
|
68 |
|
69 out.array = null; |
|
70 try |
|
71 { |
|
72 strict2(out); |
|
73 throw "no error"; |
|
74 } |
|
75 catch (e) |
|
76 { |
|
77 assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); |
|
78 } |
|
79 assertEq(deepEqual(out.array, addx([1, 2, 3])), true); |
|
80 |
|
81 if (typeof reportCompare === "function") |
|
82 reportCompare(true, true); |
|
83 |
|
84 print("Tests complete"); |