| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 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 --noalways-opt |
| 29 |
| 30 var globalObject = new Function("return this")(); |
| 31 //Cache the original Math object for re-optimizations |
| 32 var mathObject = Math; |
| 33 var NOT_OPTIMIZED = 2; |
| 34 var OPTIMIZED = 1; |
| 35 |
| 36 function getPi() { |
| 37 return Math.PI; |
| 38 } |
| 39 |
| 40 function optimizeGetPi() { |
| 41 assertUnoptimized(getPi); |
| 42 var pi = getPi(); |
| 43 getPi(); |
| 44 %OptimizeFunctionOnNextCall(getPi); |
| 45 getPi(); |
| 46 assertOptimized(getPi); |
| 47 //Optimized result must always be equal to the unoptimized result |
| 48 assertEquals(pi, getPi()); |
| 49 } |
| 50 |
| 51 |
| 52 optimizeGetPi(); |
| 53 assertOptimized(getPi); |
| 54 //normal assignment should deoptimize |
| 55 Math = {PI: 1.24}; |
| 56 assertUnoptimized(getPi); |
| 57 assertEquals(getPi(), 1.24); |
| 58 Math = mathObject; |
| 59 |
| 60 |
| 61 optimizeGetPi(); |
| 62 assertOptimized(getPi); |
| 63 //delete should deoptimize |
| 64 delete Math; |
| 65 assertUnoptimized(getPi); |
| 66 try { |
| 67 getPi(); |
| 68 assertTrue(false); |
| 69 } |
| 70 catch(e) { |
| 71 assertTrue(true); |
| 72 } |
| 73 Math = mathObject; |
| 74 |
| 75 |
| 76 optimizeGetPi(); |
| 77 assertOptimized(getPi); |
| 78 //defining accessor descriptor should deoptimize |
| 79 Object.defineProperty(globalObject, "Math", { |
| 80 get: function() { |
| 81 return {PI: 1.24}; |
| 82 }, |
| 83 set: function(value) { |
| 84 Object.defineProperty(globalObject, "Math", { |
| 85 value: value, |
| 86 enumerable: true, |
| 87 writable: true, |
| 88 configurable: true |
| 89 }); |
| 90 }, |
| 91 configurable: true, |
| 92 enumerable: true |
| 93 }); |
| 94 assertUnoptimized(getPi); |
| 95 assertEquals(getPi(), 1.24); |
| 96 Math = mathObject; |
| 97 |
| 98 optimizeGetPi(); |
| 99 assertOptimized(getPi); |
| 100 //defining data descriptor should deoptimize |
| 101 Object.defineProperty(globalObject, "Math", { |
| 102 value: {PI: 1.24}, |
| 103 configurable: true, |
| 104 enumerable: true, |
| 105 writable: true |
| 106 }); |
| 107 assertUnoptimized(getPi); |
| 108 assertEquals(getPi(), 1.24); |
| 109 Math = mathObject; |
| 110 |
| 111 |
| 112 optimizeGetPi(); |
| 113 assertOptimized(getPi); |
| OLD | NEW |