OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 function props(x) { | 28 function props(x) { |
29 var array = []; | 29 var array = []; |
30 for (var p in x) array.push(p); | 30 for (var p in x) array.push(p); |
31 return array.sort(); | 31 return array.sort(); |
32 } | 32 } |
33 | 33 |
34 assertEquals(0, props({}).length); | 34 assertEquals(0, props({}).length, "olen0"); |
35 assertEquals(1, props({x:1}).length); | 35 assertEquals(1, props({x:1}).length, "olen1"); |
36 assertEquals(2, props({x:1, y:2}).length); | 36 assertEquals(2, props({x:1, y:2}).length, "olen2"); |
37 | 37 |
38 assertArrayEquals(["x"], props({x:1})); | 38 assertArrayEquals(["x"], props({x:1}), "x"); |
39 assertArrayEquals(["x", "y"], props({x:1, y:2})); | 39 assertArrayEquals(["x", "y"], props({x:1, y:2}), "xy"); |
40 assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3})); | 40 assertArrayEquals(["x", "y", "zoom"], props({x:1, y:2, zoom:3}), "xyzoom"); |
41 | 41 |
42 assertEquals(0, props([]).length); | 42 assertEquals(0, props([]).length, "alen0"); |
43 assertEquals(1, props([1]).length); | 43 assertEquals(1, props([1]).length, "alen1"); |
44 assertEquals(2, props([1,2]).length); | 44 assertEquals(2, props([1,2]).length, "alen2"); |
45 | 45 |
46 assertArrayEquals(["0"], props([1])); | 46 assertArrayEquals(["0"], props([1]), "0"); |
47 assertArrayEquals(["0", "1"], props([1,2])); | 47 assertArrayEquals(["0", "1"], props([1,2]), "01"); |
48 assertArrayEquals(["0", "1", "2"], props([1,2,3])); | 48 assertArrayEquals(["0", "1", "2"], props([1,2,3]), "012"); |
49 | 49 |
50 var o = {}; | 50 var o = {}; |
51 var a = []; | 51 var a = []; |
52 for (var i = 0x0020; i < 0x01ff; i+=2) { | 52 for (var i = 0x0020; i < 0x01ff; i+=2) { |
53 var s = 'char:' + String.fromCharCode(i); | 53 var s = 'char:' + String.fromCharCode(i); |
54 a.push(s); | 54 a.push(s); |
55 o[s] = i; | 55 o[s] = i; |
56 } | 56 } |
57 assertArrayEquals(a, props(o)); | 57 assertArrayEquals(a, props(o), "charcodes"); |
58 | 58 |
59 var a = []; | 59 var a = []; |
60 assertEquals(0, props(a).length); | 60 assertEquals(0, props(a).length, "proplen0"); |
61 a[Math.pow(2,30)-1] = 0; | 61 a[Math.pow(2,30)-1] = 0; |
62 assertEquals(1, props(a).length); | 62 assertEquals(1, props(a).length, "proplen1"); |
63 a[Math.pow(2,31)-1] = 0; | 63 a[Math.pow(2,31)-1] = 0; |
64 assertEquals(2, props(a).length); | 64 assertEquals(2, props(a).length, "proplen2"); |
65 a[1] = 0; | 65 a[1] = 0; |
66 assertEquals(3, props(a).length); | 66 assertEquals(3, props(a).length, "proplen3"); |
67 | 67 |
68 for (var hest = 'hest' in {}) { } | 68 for (var hest = 'hest' in {}) { } |
69 assertEquals('hest', hest); | 69 assertEquals('hest', hest, "empty-no-override"); |
70 | 70 |
71 var result = ''; | 71 var result = ''; |
72 for (var p in {a : [0], b : 1}) { result += p; } | 72 for (var p in {a : [0], b : 1}) { result += p; } |
73 assertEquals('ab', result); | 73 assertEquals('ab', result, "ab"); |
74 | 74 |
75 var result = ''; | 75 var result = ''; |
76 for (var p in {a : {v:1}, b : 1}) { result += p; } | 76 for (var p in {a : {v:1}, b : 1}) { result += p; } |
77 assertEquals('ab', result); | 77 assertEquals('ab', result, "ab-nodeep"); |
78 | 78 |
79 var result = ''; | 79 var result = ''; |
80 for (var p in { get a() {}, b : 1}) { result += p; } | 80 for (var p in { get a() {}, b : 1}) { result += p; } |
81 assertEquals('ab', result); | 81 assertEquals('ab', result, "abget"); |
82 | 82 |
83 var result = ''; | 83 var result = ''; |
84 for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; } | 84 for (var p in { get a() {}, set a(x) {}, b : 1}) { result += p; } |
85 assertEquals('ab', result); | 85 assertEquals('ab', result, "abgetset"); |
86 | 86 |
OLD | NEW |