1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Copyright 2008 the V8 project authors. All rights reserved.
2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without
3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are
4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met:
5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions of source code must retain the above copyright
7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       notice, this list of conditions and the following disclaimer.
8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions in binary form must reproduce the above
9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       copyright notice, this list of conditions and the following
10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       disclaimer in the documentation and/or other materials provided
11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       with the distribution.
12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Neither the name of Google Inc. nor the names of its
13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       contributors may be used to endorse or promote products derived
14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       from this software without specific prior written permission.
15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction props(x) {
29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  var array = [];
30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  for (var p in x) array.push(p);
31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  return array.sort();
32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction f1() {
35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.x = 1;
36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction f2(x) {
39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.x = x;
40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction f3(x) {
43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.x = x;
44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.y = 1;
45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.z = f1;
46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction f4(x) {
49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.x = x;
50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.y = 1;
51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  if (x == 1) return;
52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.z = f1;
53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko1_1 = new f1();
56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(1, o1_1.x, "1");
57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko1_2 = new f1();
58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(1, o1_1.x, "2");
59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x"], props(o1_1), "3");
60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x"], props(o1_2), "4");
61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko2_1 = new f2(0);
63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko2_2 = new f2(0);
64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x"], props(o2_1));
65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x"], props(o2_2));
66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko3_1 = new f3(0);
68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko3_2 = new f3(0);
69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x", "y", "z"], props(o3_1));
70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x", "y", "z"], props(o3_2));
71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko4_0_1 = new f4(0);
73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko4_0_2 = new f4(0);
74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x", "y", "z"], props(o4_0_1));
75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x", "y", "z"], props(o4_0_2));
76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko4_1_1 = new f4(1);
78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko4_1_2 = new f4(1);
79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x", "y"], props(o4_1_1));
80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertArrayEquals(["x", "y"], props(o4_1_2));
81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction f5(x, y) {
83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.x = x;
84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.y = y;
85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction f6(x, y) {
88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.y = y;
89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.x = x;
90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction f7(x, y, z) {
93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.x = x;
94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.y = y;
95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction testArgs(fun) {
98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  obj = new fun();
99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertArrayEquals(["x", "y"], props(obj));
100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(void 0, obj.x);
101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(void 0, obj.y);
102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  obj = new fun("x");
104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertArrayEquals(["x", "y"], props(obj));
105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals("x", obj.x);
106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals(void 0, obj.y);
107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  obj = new fun("x", "y");
109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertArrayEquals(["x", "y"], props(obj));
110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals("x", obj.x);
111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals("y", obj.y);
112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  obj = new fun("x", "y", "z");
114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertArrayEquals(["x", "y"], props(obj));
115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals("x", obj.x);
116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  assertEquals("y", obj.y);
117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfor (var i = 0; i < 10; i++) {
120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  testArgs(f5);
121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  testArgs(f6);
122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  testArgs(f7);
123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfunction g(){
126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  this.x=1
127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}
128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko = new g();
130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(1, o.x);
131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko = new g();
132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(1, o.x);
133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockg.prototype = {y:2}
134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko = new g();
135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(1, o.x);
136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(2, o.y);
137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocko = new g();
138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(1, o.x);
139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockassertEquals(2, o.y);
140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
141