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
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
function arr() {
return Object.defineProperty([1, 2, 3, 4], 2, {configurable: false});
}
assertEq(testLenientAndStrict('var a = arr(); a.length = 2; a',
returnsCopyOf([1, 2, 3]),
raisesException(TypeError)),
true);
// Internally, SpiderMonkey has two representations for arrays:
// fast-but-inflexible, and slow-but-flexible. Adding a non-index property
// to an array turns it into the latter. We should test on both kinds.
function addx(obj) {
obj.x = 5;
return obj;
}
assertEq(testLenientAndStrict('var a = addx(arr()); a.length = 2; a',
returnsCopyOf(addx([1, 2, 3])),
raisesException(TypeError)),
true);
reportCompare(true, true);
|