| 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 14 matching lines...) Expand all Loading... |
| 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 // Test that the inline caches correctly detect that constant | 28 // Test that the inline caches correctly detect that constant |
| 29 // functions on value prototypes change. | 29 // functions on value prototypes change. |
| 30 | 30 |
| 31 function testString() { | 31 function testString() { |
| 32 function f(s, expected) { | 32 function f(s, expected) { |
| 33 var result = s.toString(); | 33 var result = s.toString(); |
| 34 assertEquals(expected, result); | 34 assertEquals(expected, result); |
| 35 }; | 35 } |
| 36 | 36 |
| 37 for (var i = 0; i < 10; i++) { | 37 for (var i = 0; i < 10; i++) { |
| 38 var s = String.fromCharCode(i); | 38 var s = String.fromCharCode(i); |
| 39 f(s, s); | 39 f(s, s); |
| 40 } | 40 } |
| 41 | 41 |
| 42 String.prototype.toString = function() { return "ostehaps"; }; | 42 String.prototype.toString = function() { return "ostehaps"; }; |
| 43 | 43 |
| 44 for (var i = 0; i < 10; i++) { | 44 for (var i = 0; i < 10; i++) { |
| 45 var s = String.fromCharCode(i); | 45 var s = String.fromCharCode(i); |
| 46 f(s, "ostehaps"); | 46 f(s, "ostehaps"); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 testString(); | 50 testString(); |
| 51 | 51 |
| 52 | 52 |
| 53 function testNumber() { | 53 function testNumber() { |
| 54 Number.prototype.toString = function() { return 0; }; | 54 Number.prototype.toString = function() { return 0; }; |
| 55 | 55 |
| 56 function f(n, expected) { | 56 function f(n, expected) { |
| 57 var result = n.toString(); | 57 var result = n.toString(); |
| 58 assertEquals(expected, result); | 58 assertEquals(expected, result); |
| 59 }; | 59 } |
| 60 | 60 |
| 61 for (var i = 0; i < 10; i++) { | 61 for (var i = 0; i < 10; i++) { |
| 62 f(i, 0); | 62 f(i, 0); |
| 63 } | 63 } |
| 64 | 64 |
| 65 Number.prototype.toString = function() { return 42; }; | 65 Number.prototype.toString = function() { return 42; }; |
| 66 | 66 |
| 67 for (var i = 0; i < 10; i++) { | 67 for (var i = 0; i < 10; i++) { |
| 68 f(i, 42); | 68 f(i, 42); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 testNumber(); | 72 testNumber(); |
| 73 | 73 |
| 74 | 74 |
| 75 function testBoolean() { | 75 function testBoolean() { |
| 76 Boolean.prototype.toString = function() { return 0; }; | 76 Boolean.prototype.toString = function() { return 0; }; |
| 77 | 77 |
| 78 function f(b, expected) { | 78 function f(b, expected) { |
| 79 var result = b.toString(); | 79 var result = b.toString(); |
| 80 assertEquals(expected, result); | 80 assertEquals(expected, result); |
| 81 }; | 81 } |
| 82 | 82 |
| 83 for (var i = 0; i < 10; i++) { | 83 for (var i = 0; i < 10; i++) { |
| 84 f((i % 2 == 0), 0); | 84 f((i % 2 == 0), 0); |
| 85 } | 85 } |
| 86 | 86 |
| 87 Boolean.prototype.toString = function() { return 42; }; | 87 Boolean.prototype.toString = function() { return 42; }; |
| 88 | 88 |
| 89 for (var i = 0; i < 10; i++) { | 89 for (var i = 0; i < 10; i++) { |
| 90 f((i % 2 == 0), 42); | 90 f((i % 2 == 0), 42); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 testBoolean(); | 94 testBoolean(); |
| OLD | NEW |