| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 function testGlobals() { | 44 function testGlobals() { |
| 45 assertEquals("[object global]", this[toStringName]()); | 45 assertEquals("[object global]", this[toStringName]()); |
| 46 assertEquals("[object global]", global[toStringName]()); | 46 assertEquals("[object global]", global[toStringName]()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 testGlobals(); | 49 testGlobals(); |
| 50 | 50 |
| 51 | 51 |
| 52 function F() {} | 52 function F() {} |
| 53 | 53 |
| 54 F.prototype.one = function() {return 'one'; } | 54 F.prototype.one = function() {return 'one'; }; |
| 55 F.prototype.two = function() {return 'two'; } | 55 F.prototype.two = function() {return 'two'; }; |
| 56 F.prototype.three = function() {return 'three'; } | 56 F.prototype.three = function() {return 'three'; }; |
| 57 | 57 |
| 58 var keys = | 58 var keys = |
| 59 ['one', 'one', 'one', 'one', 'two', 'two', 'one', 'three', 'one', 'two']; | 59 ['one', 'one', 'one', 'one', 'two', 'two', 'one', 'three', 'one', 'two']; |
| 60 | 60 |
| 61 function testKeyTransitions() { | 61 function testKeyTransitions() { |
| 62 var i, key, result, message; | 62 var i, key, result, message; |
| 63 | 63 |
| 64 var f = new F(); | 64 var f = new F(); |
| 65 | 65 |
| 66 // Custom call generators | 66 // Custom call generators |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Function is a constant property | 111 // Function is a constant property |
| 112 key = 'one'; | 112 key = 'one'; |
| 113 for (i = 0; i != 10; i++) { | 113 for (i = 0; i != 10; i++) { |
| 114 assertEquals(key, f[key]()); | 114 assertEquals(key, f[key]()); |
| 115 if (i == 5) { | 115 if (i == 5) { |
| 116 key = 'two'; // the name change should case a miss | 116 key = 'two'; // the name change should case a miss |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Function is a fast property | 120 // Function is a fast property |
| 121 f.field = function() { return 'field'; } | 121 f.field = function() { return 'field'; }; |
| 122 key = 'field'; | 122 key = 'field'; |
| 123 for (i = 0; i != 10; i++) { | 123 for (i = 0; i != 10; i++) { |
| 124 assertEquals(key, f[key]()); | 124 assertEquals(key, f[key]()); |
| 125 if (i == 5) { | 125 if (i == 5) { |
| 126 key = 'two'; // the name change should case a miss | 126 key = 'two'; // the name change should case a miss |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Calling on slow case object | 130 // Calling on slow case object |
| 131 f.prop = 0; | 131 f.prop = 0; |
| 132 delete f.prop; // force the object to the slow case | 132 delete f.prop; // force the object to the slow case |
| 133 f.four = function() { return 'four'; } | 133 f.four = function() { return 'four'; }; |
| 134 f.five = function() { return 'five'; } | 134 f.five = function() { return 'five'; }; |
| 135 | 135 |
| 136 key = 'four'; | 136 key = 'four'; |
| 137 for (i = 0; i != 10; i++) { | 137 for (i = 0; i != 10; i++) { |
| 138 assertEquals(key, f[key]()); | 138 assertEquals(key, f[key]()); |
| 139 if (i == 5) { | 139 if (i == 5) { |
| 140 key = 'five'; | 140 key = 'five'; |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 // Calling on global object | 144 // Calling on global object |
| (...skipping 11 matching lines...) Expand all Loading... |
| 156 testKeyTransitions(); | 156 testKeyTransitions(); |
| 157 | 157 |
| 158 function testTypeTransitions() { | 158 function testTypeTransitions() { |
| 159 var f = new F(); | 159 var f = new F(); |
| 160 var s = ''; | 160 var s = ''; |
| 161 var m = 'one'; | 161 var m = 'one'; |
| 162 var i; | 162 var i; |
| 163 | 163 |
| 164 s = ''; | 164 s = ''; |
| 165 for (i = 0; i != 10; i++) { | 165 for (i = 0; i != 10; i++) { |
| 166 if (i == 5) { F.prototype.one = function() { return '1'; } } | 166 if (i == 5) { F.prototype.one = function() { return '1'; }; } |
| 167 s += f[m](); | 167 s += f[m](); |
| 168 } | 168 } |
| 169 assertEquals("oneoneoneoneone11111", s); | 169 assertEquals("oneoneoneoneone11111", s); |
| 170 | 170 |
| 171 s = ''; | 171 s = ''; |
| 172 for (i = 0; i != 10; i++) { | 172 for (i = 0; i != 10; i++) { |
| 173 if (i == 5) { f.__proto__ = { one: function() { return 'I'; } } } | 173 if (i == 5) { f.__proto__ = { one: function() { return 'I'; } }; } |
| 174 s += f[m](); | 174 s += f[m](); |
| 175 } | 175 } |
| 176 assertEquals("11111IIIII", s); | 176 assertEquals("11111IIIII", s); |
| 177 | 177 |
| 178 s = ''; | 178 s = ''; |
| 179 for (i = 0; i != 10; i++) { | 179 for (i = 0; i != 10; i++) { |
| 180 if (i == 5) { f.one = function() { return 'ONE'; } } | 180 if (i == 5) { f.one = function() { return 'ONE'; }; } |
| 181 s += f[m](); | 181 s += f[m](); |
| 182 } | 182 } |
| 183 assertEquals("IIIIIONEONEONEONEONE", s); | 183 assertEquals("IIIIIONEONEONEONEONE", s); |
| 184 | 184 |
| 185 m = 'toString'; | 185 m = 'toString'; |
| 186 | 186 |
| 187 s = ''; | 187 s = ''; |
| 188 var obj = { toString: function() { return '2'; } }; | 188 var obj = { toString: function() { return '2'; } }; |
| 189 for (i = 0; i != 10; i++) { | 189 for (i = 0; i != 10; i++) { |
| 190 if (i == 5) { obj = "TWO"; } | 190 if (i == 5) { obj = "TWO"; } |
| 191 s += obj[m](); | 191 s += obj[m](); |
| 192 } | 192 } |
| 193 assertEquals("22222TWOTWOTWOTWOTWO", s); | 193 assertEquals("22222TWOTWOTWOTWOTWO", s); |
| 194 | 194 |
| 195 s = ''; | 195 s = ''; |
| 196 obj = { toString: function() { return 'ONE'; } }; | 196 obj = { toString: function() { return 'ONE'; } }; |
| 197 m = 'toString'; | 197 m = 'toString'; |
| 198 for (i = 0; i != 10; i++) { | 198 for (i = 0; i != 10; i++) { |
| 199 if (i == 5) { obj = 1; } | 199 if (i == 5) { obj = 1; } |
| 200 s += obj[m](); | 200 s += obj[m](); |
| 201 } | 201 } |
| 202 assertEquals("ONEONEONEONEONE11111", s); | 202 assertEquals("ONEONEONEONEONE11111", s); |
| 203 } | 203 } |
| 204 | 204 |
| 205 testTypeTransitions(); | 205 testTypeTransitions(); |
| OLD | NEW |