blob: e3436ff3be1ca2ef8c5683d6ef0c020939bb4110 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2008 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 array = [];
30 for (var p in x) array.push(p);
31 return array.sort();
32}
33
Steve Block3ce2e202009-11-05 08:53:23 +000034assertEquals(0, props({}).length, "olen0");
35assertEquals(1, props({x:1}).length, "olen1");
36assertEquals(2, props({x:1, y:2}).length, "olen2");
Steve Blocka7e24c12009-10-30 11:49:00 +000037
Steve Block3ce2e202009-11-05 08:53:23 +000038assertArrayEquals(["x"], props({x:1}), "x");
39assertArrayEquals(["x", "y"], props({x:1, y:2}), "xy");
40assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3}), "xyzoom");
Steve Blocka7e24c12009-10-30 11:49:00 +000041
Steve Block3ce2e202009-11-05 08:53:23 +000042assertEquals(0, props([]).length, "alen0");
43assertEquals(1, props([1]).length, "alen1");
44assertEquals(2, props([1,2]).length, "alen2");
Steve Blocka7e24c12009-10-30 11:49:00 +000045
Steve Block3ce2e202009-11-05 08:53:23 +000046assertArrayEquals(["0"], props([1]), "0");
47assertArrayEquals(["0", "1"], props([1,2]), "01");
48assertArrayEquals(["0", "1", "2"], props([1,2,3]), "012");
Steve Blocka7e24c12009-10-30 11:49:00 +000049
50var o = {};
51var a = [];
52for (var i = 0x0020; i < 0x01ff; i+=2) {
53 var s = 'char:' + String.fromCharCode(i);
54 a.push(s);
55 o[s] = i;
56}
Steve Block3ce2e202009-11-05 08:53:23 +000057assertArrayEquals(a, props(o), "charcodes");
Steve Blocka7e24c12009-10-30 11:49:00 +000058
59var a = [];
Steve Block3ce2e202009-11-05 08:53:23 +000060assertEquals(0, props(a).length, "proplen0");
Steve Blocka7e24c12009-10-30 11:49:00 +000061a[Math.pow(2,30)-1] = 0;
Steve Block3ce2e202009-11-05 08:53:23 +000062assertEquals(1, props(a).length, "proplen1");
Steve Blocka7e24c12009-10-30 11:49:00 +000063a[Math.pow(2,31)-1] = 0;
Steve Block3ce2e202009-11-05 08:53:23 +000064assertEquals(2, props(a).length, "proplen2");
Steve Blocka7e24c12009-10-30 11:49:00 +000065a[1] = 0;
Steve Block3ce2e202009-11-05 08:53:23 +000066assertEquals(3, props(a).length, "proplen3");
Steve Blocka7e24c12009-10-30 11:49:00 +000067
68for (var hest = 'hest' in {}) { }
Steve Block3ce2e202009-11-05 08:53:23 +000069assertEquals('hest', hest, "empty-no-override");
Steve Blocka7e24c12009-10-30 11:49:00 +000070
71var result = '';
72for (var p in {a : [0], b : 1}) { result += p; }
Steve Block3ce2e202009-11-05 08:53:23 +000073assertEquals('ab', result, "ab");
Steve Blocka7e24c12009-10-30 11:49:00 +000074
75var result = '';
76for (var p in {a : {v:1}, b : 1}) { result += p; }
Steve Block3ce2e202009-11-05 08:53:23 +000077assertEquals('ab', result, "ab-nodeep");
Steve Blocka7e24c12009-10-30 11:49:00 +000078
79var result = '';
80for (var p in { get a() {}, b : 1}) { result += p; }
Steve Block3ce2e202009-11-05 08:53:23 +000081assertEquals('ab', result, "abget");
Steve Blocka7e24c12009-10-30 11:49:00 +000082
83var result = '';
84for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; }
Steve Block3ce2e202009-11-05 08:53:23 +000085assertEquals('ab', result, "abgetset");
Steve Blocka7e24c12009-10-30 11:49:00 +000086