| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 | 40 |
| 41 function AddProps(obj) { | 41 function AddProps(obj) { |
| 42 for (var i = 0; i < 26; i++) { | 42 for (var i = 0; i < 26; i++) { |
| 43 obj["x" + i] = 0; | 43 obj["x" + i] = 0; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 function DoProtoMagic(proto, set__proto__) { | 48 function DoProtoMagic(proto, set__proto__) { |
| 49 var receiver; |
| 49 if (set__proto__) { | 50 if (set__proto__) { |
| 50 (new Sub()).__proto__ = proto; | 51 receiver = new Sub(); |
| 52 receiver.__proto__ = proto; |
| 51 } else { | 53 } else { |
| 52 Sub.prototype = proto; | 54 Sub.prototype = proto; |
| 53 // Need to instantiate Sub to mark .prototype as prototype. Make sure the | 55 // Need to instantiate Sub to mark .prototype as prototype. Make sure the |
| 54 // instantiated object is used so that the allocation is not optimized away. | 56 // instantiated object is used so that the allocation is not optimized away. |
| 55 %DebugPrint(new Sub()); | 57 receiver = new Sub(); |
| 56 } | 58 } |
| 59 // Prototypes are made fast when ICs encounter them. |
| 60 function ic() { return typeof receiver.foo; } |
| 61 ic(); |
| 62 ic(); |
| 57 } | 63 } |
| 58 | 64 |
| 59 | 65 |
| 60 function test(use_new, add_first, set__proto__) { | 66 function test(use_new, add_first, set__proto__) { |
| 61 var proto = use_new ? new Super() : {}; | 67 var proto = use_new ? new Super() : {}; |
| 62 | 68 |
| 63 // New object is fast. | 69 // New object is fast. |
| 64 assertTrue(%HasFastProperties(proto)); | 70 assertTrue(%HasFastProperties(proto)); |
| 65 | 71 |
| 66 if (add_first) { | 72 if (add_first) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 assertTrue(key == 'a'); | 111 assertTrue(key == 'a'); |
| 106 break; | 112 break; |
| 107 } | 113 } |
| 108 assertTrue(%HasFastProperties(x)); | 114 assertTrue(%HasFastProperties(x)); |
| 109 x.d = 4; | 115 x.d = 4; |
| 110 assertTrue(%HasFastProperties(x)); | 116 assertTrue(%HasFastProperties(x)); |
| 111 for (key in x) { | 117 for (key in x) { |
| 112 assertTrue(key == 'a'); | 118 assertTrue(key == 'a'); |
| 113 break; | 119 break; |
| 114 } | 120 } |
| OLD | NEW |