Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_5 / strict / 15.4.5.1.js
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 function arr() {
9   return Object.defineProperty([1, 2, 3, 4], 2, {configurable: false});
10 }
11
12 assertEq(testLenientAndStrict('var a = arr(); a.length = 2; a',
13                               returnsCopyOf([1, 2, 3]),
14                               raisesException(TypeError)),
15          true);
16
17 // Internally, SpiderMonkey has two representations for arrays:
18 // fast-but-inflexible, and slow-but-flexible. Adding a non-index property
19 // to an array turns it into the latter. We should test on both kinds.
20 function addx(obj) {
21   obj.x = 5;
22   return obj;
23 }
24
25 assertEq(testLenientAndStrict('var a = addx(arr()); a.length = 2; a',
26                               returnsCopyOf(addx([1, 2, 3])),
27                               raisesException(TypeError)),
28          true);
29
30 reportCompare(true, true);