OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 // |
| 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions |
| 6 // are met: |
| 7 // 1. Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. |
| 9 // 2. Redistributions in binary form must reproduce the above copyright |
| 10 // notice, this list of conditions and the following disclaimer in the |
| 11 // documentation and/or other materials provided with the distribution. |
| 12 // |
| 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 |
| 24 if (this.description) |
| 25 description("Test caching with re-entrancy."); |
| 26 |
| 27 function test1() { |
| 28 var objects = [{prop:1}, {get prop(){return 2}}]; |
| 29 |
| 30 function g(o) { |
| 31 return o.prop; |
| 32 } |
| 33 |
| 34 for (var i = 0; i < 10000; i++) { |
| 35 var o = { |
| 36 get prop() { |
| 37 try { |
| 38 g(objects[++j]); |
| 39 }catch(e){ |
| 40 } |
| 41 return 1; |
| 42 } |
| 43 }; |
| 44 o[i] = i; |
| 45 objects.push(o); |
| 46 } |
| 47 var j=0; |
| 48 g(objects[0]); |
| 49 g(objects[1]); |
| 50 g(objects[2]); |
| 51 g(objects[3]); |
| 52 } |
| 53 |
| 54 |
| 55 function test2() { |
| 56 var objects = [Object.create({prop:1}), Object.create({get prop(){return 2}}
)]; |
| 57 |
| 58 function g(o) { |
| 59 return o.prop; |
| 60 } |
| 61 var proto = { |
| 62 get prop() { |
| 63 try { |
| 64 g(objects[++j]); |
| 65 }catch(e){ |
| 66 } |
| 67 return 1; |
| 68 } |
| 69 }; |
| 70 for (var i = 0; i < 10000; i++) { |
| 71 var o = Object.create(proto); |
| 72 o[i] = i; |
| 73 objects.push(o); |
| 74 } |
| 75 var j=0; |
| 76 g(objects[0]); |
| 77 g(objects[1]); |
| 78 g(objects[2]); |
| 79 g(objects[3]); |
| 80 } |
| 81 |
| 82 |
| 83 function test3() { |
| 84 var objects = [Object.create(Object.create({prop:1})), Object.create(Object.
create({get prop(){return 2}}))]; |
| 85 |
| 86 function g(o) { |
| 87 return o.prop; |
| 88 } |
| 89 var proto = { |
| 90 get prop() { |
| 91 try { |
| 92 g(objects[++j]); |
| 93 }catch(e){ |
| 94 } |
| 95 return 1; |
| 96 } |
| 97 }; |
| 98 for (var i = 0; i < 10000; i++) { |
| 99 var o = Object.create(Object.create(proto)); |
| 100 o[i] = i; |
| 101 objects.push(o); |
| 102 } |
| 103 var j=0; |
| 104 g(objects[0]); |
| 105 g(objects[1]); |
| 106 g(objects[2]); |
| 107 g(objects[3]); |
| 108 } |
| 109 |
| 110 test1(); |
| 111 test2(); |
| 112 test3(); |
OLD | NEW |