OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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 |
| 28 // Flags: --allow-natives-syntax |
| 29 |
| 30 // Check that objects that are used for prototypes are in the fast mode. |
| 31 |
| 32 function Super() { |
| 33 } |
| 34 |
| 35 |
| 36 function Sub() { |
| 37 } |
| 38 |
| 39 |
| 40 function AddProps(obj) { |
| 41 for (var i = 0; i < 26; i++) { |
| 42 obj["x" + i] = 0; |
| 43 } |
| 44 } |
| 45 |
| 46 |
| 47 function DoProtoMagic(proto, set__proto__) { |
| 48 if (set__proto__) { |
| 49 (new Sub()).__proto__ = proto; |
| 50 } else { |
| 51 Sub.prototype = proto; |
| 52 } |
| 53 } |
| 54 |
| 55 |
| 56 function test(use_new, add_first, set__proto__, same_map_as) { |
| 57 var proto = use_new ? new Super() : {}; |
| 58 |
| 59 // New object is fast. |
| 60 assertTrue(%HasFastProperties(proto)); |
| 61 |
| 62 if (add_first) { |
| 63 AddProps(proto); |
| 64 // Adding this many properties makes it slow. |
| 65 assertFalse(%HasFastProperties(proto)); |
| 66 DoProtoMagic(proto, set__proto__); |
| 67 // Making it a prototype makes it fast again. |
| 68 assertTrue(%HasFastProperties(proto)); |
| 69 } else { |
| 70 DoProtoMagic(proto, set__proto__); |
| 71 // Still fast |
| 72 assertTrue(%HasFastProperties(proto)); |
| 73 AddProps(proto); |
| 74 // Setting the bit means it is still fast with all these properties. |
| 75 assertTrue(%HasFastProperties(proto)); |
| 76 } |
| 77 if (same_map_as && !add_first) { |
| 78 assertTrue(%HaveSameMap(same_map_as, proto)); |
| 79 } |
| 80 return proto; |
| 81 } |
| 82 |
| 83 |
| 84 for (var i = 0; i < 4; i++) { |
| 85 var set__proto__ = ((i & 1) != 0); |
| 86 var use_new = ((i & 2) != 0); |
| 87 |
| 88 test(use_new, true, set__proto__); |
| 89 |
| 90 var last = test(use_new, false, set__proto__); |
| 91 test(use_new, false, set__proto__, last); |
| 92 } |
OLD | NEW |