blob: 03001b6c79721855bf71c6997dc8bfc74fb4ecac [file] [log] [blame]
Leon Clarke4515c472010-02-03 11:58:03 +00001// Copyright 2010 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
28function props(x) {
29 var result = [];
30 for (var p in x) result.push(p);
31 return result;
32}
33
34function A() {
35 this.a1 = 1234;
36 this.a2 = "D";
37 this.a3 = false;
38}
39
40function B() {
41 this.b3 = false;
42 this.b2 = "D";
43 this.b1 = 1234;
44}
45
46function C() {
47 this.c3 = false;
48 this.c1 = 1234;
49 this.c2 = "D";
50}
51
52assertArrayEquals(["a1", "a2", "a3"], props(new A()));
53assertArrayEquals(["b3", "b2", "b1"], props(new B()));
54assertArrayEquals(["c3", "c1", "c2"], props(new C()));
55assertArrayEquals(["s1", "s2", "s3"], props({s1: 0, s2: 0, s3: 0}));
56assertArrayEquals(["s3", "s2", "s1"], props({s3: 0, s2: 0, s1: 0}));
57assertArrayEquals(["s3", "s1", "s2"], props({s3: 0, s1: 0, s2: 0}));
58
59var a = new A()
60a.a0 = 0;
61a.a4 = 0;
62assertArrayEquals(["a1", "a2", "a3", "a0", "a4"], props(a));
63
64var b = new B()
65b.b4 = 0;
66b.b0 = 0;
67assertArrayEquals(["b3", "b2", "b1", "b4", "b0"], props(b));
68
69var o1 = {s1: 0, s2: 0, s3: 0}
70o1.s0 = 0;
71o1.s4 = 0;
72assertArrayEquals(["s1", "s2", "s3", "s0", "s4"], props(o1));
73
74var o2 = {s3: 0, s2: 0, s1: 0}
75o2.s4 = 0;
76o2.s0 = 0;
77assertArrayEquals(["s3", "s2", "s1", "s4", "s0"], props(o2));