Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / v8 / test / mjsunit / regress / regress-2615.js
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 a = [1];
29 Object.defineProperty(a, "1", {writable:false, configurable:false, value: 100});
30 assertThrows("a.unshift(4);", TypeError);
31 assertEquals([1, 100, 100], a);
32 var desc = Object.getOwnPropertyDescriptor(a, "1");
33 assertEquals(false, desc.writable);
34 assertEquals(false, desc.configurable);
35
36 a = [1];
37 var g = function() { return 100; };
38 Object.defineProperty(a, "1", {get:g});
39 assertThrows("a.unshift(0);", TypeError);
40 assertEquals([1, 100, 100], a);
41 desc = Object.getOwnPropertyDescriptor(a, "1");
42 assertEquals(false, desc.configurable);
43 assertEquals(g, desc.get);
44
45 a = [1];
46 var c = 0;
47 var s = function(v) { c += 1; };
48 Object.defineProperty(a, "1", {set:s});
49 a.unshift(10);
50 assertEquals([10, undefined, undefined], a);
51 assertEquals(1, c);
52 desc = Object.getOwnPropertyDescriptor(a, "1");
53 assertEquals(false, desc.configurable);
54 assertEquals(s, desc.set);
55
56 a = [1];
57 Object.defineProperty(a, "1", {configurable:false, value:10});
58 assertThrows("a.splice(1,1);", TypeError);
59 assertEquals([1, 10], a);
60 desc = Object.getOwnPropertyDescriptor(a, "1");
61 assertEquals(false, desc.configurable);
62
63 a = [0,1,2,3,4,5,6];
64 Object.defineProperty(a, "3", {configurable:false, writable:false, value:3});
65 assertThrows("a.splice(1,4);", TypeError);
66 assertEquals([0,5,6,3,,,,], a);
67 desc = Object.getOwnPropertyDescriptor(a, "3");
68 assertEquals(false, desc.configurable);
69 assertEquals(false, desc.writable);
70
71 a = [0,1,2,3,4,5,6];
72 Object.defineProperty(a, "5", {configurable:false, value:5});
73 assertThrows("a.splice(1,4);", TypeError);
74 assertEquals([0,5,6,3,4,5,,], a);
75 desc = Object.getOwnPropertyDescriptor(a, "5");
76 assertEquals(false, desc.configurable);
77
78 a = [1,2,3,,5];
79 Object.defineProperty(a, "1", {configurable:false, writable:true, value:2});
80 assertEquals(1, a.shift());
81 assertEquals([2,3,,5], a);
82 desc = Object.getOwnPropertyDescriptor(a, "1");
83 assertEquals(false, desc.configurable);
84 assertEquals(true, desc.writable);
85 assertThrows("a.shift();", TypeError);
86 assertEquals([3,3,,5], a);
87 desc = Object.getOwnPropertyDescriptor(a, "1");
88 assertEquals(false, desc.configurable);
89 assertEquals(true, desc.writable);
90
91 a = [1,2,3];
92 Object.defineProperty(a, "2", {configurable:false, value:3});
93 assertThrows("a.pop();", TypeError);
94 assertEquals([1,2,3], a);
95 desc = Object.getOwnPropertyDescriptor(a, "2");
96 assertEquals(false, desc.configurable);