OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --strong-mode --allow-natives-syntax |
| 6 |
| 7 "use strict"; |
| 8 |
| 9 function pre_inc(x) { |
| 10 return ++x; |
| 11 } |
| 12 |
| 13 function post_inc(x) { |
| 14 return x++; |
| 15 } |
| 16 |
| 17 function pre_dec(x) { |
| 18 return --x; |
| 19 } |
| 20 |
| 21 function post_dec(x) { |
| 22 return x--; |
| 23 } |
| 24 |
| 25 function getTestFuncs() { |
| 26 return [ |
| 27 function(x){ |
| 28 "use strong"; |
| 29 let y = x; |
| 30 assertEquals(++y, pre_inc(x)); |
| 31 try { |
| 32 assertEquals(x+1, y) |
| 33 } catch (e) { |
| 34 assertUnreachable(); |
| 35 } |
| 36 }, |
| 37 function(x){ |
| 38 "use strong"; |
| 39 let y = x; |
| 40 assertEquals(y++, post_inc(x)); |
| 41 try { |
| 42 assertEquals(x+1, y) |
| 43 } catch (e) { |
| 44 assertUnreachable(); |
| 45 } |
| 46 }, |
| 47 function(x){ |
| 48 "use strong"; |
| 49 let y = x; |
| 50 assertEquals(--y, pre_dec(x)); |
| 51 try { |
| 52 assertEquals(x-1, y) |
| 53 } catch (e) { |
| 54 assertUnreachable(); |
| 55 } |
| 56 }, |
| 57 function(x){ |
| 58 "use strong"; |
| 59 let y = x; |
| 60 assertEquals(y--, post_dec(x)); |
| 61 try { |
| 62 assertEquals(x-1, y) |
| 63 } catch (e) { |
| 64 assertUnreachable(); |
| 65 } |
| 66 }, |
| 67 function(x){ |
| 68 "use strong"; |
| 69 let obj = { foo: x }; |
| 70 let y = ++obj.foo; |
| 71 assertEquals(y, pre_inc(x)); |
| 72 try { |
| 73 assertEquals(x+1, obj.foo) |
| 74 } catch (e) { |
| 75 assertUnreachable(); |
| 76 } |
| 77 }, |
| 78 function(x){ |
| 79 "use strong"; |
| 80 let obj = { foo: x }; |
| 81 let y = obj.foo++; |
| 82 assertEquals(y, post_inc(x)); |
| 83 try { |
| 84 assertEquals(x+1, obj.foo) |
| 85 } catch (e) { |
| 86 assertUnreachable(); |
| 87 } |
| 88 }, |
| 89 function(x){ |
| 90 "use strong"; |
| 91 let obj = { foo: x }; |
| 92 let y = --obj.foo; |
| 93 assertEquals(y, pre_dec(x)); |
| 94 try { |
| 95 assertEquals(x-1, obj.foo) |
| 96 } catch (e) { |
| 97 assertUnreachable(); |
| 98 } |
| 99 }, |
| 100 function(x){ |
| 101 "use strong"; |
| 102 let obj = { foo: x }; |
| 103 let y = obj.foo--; |
| 104 assertEquals(y, post_dec(x)); |
| 105 try { |
| 106 assertEquals(x-1, obj.foo) |
| 107 } catch (e) { |
| 108 assertUnreachable(); |
| 109 } |
| 110 }, |
| 111 ]; |
| 112 } |
| 113 |
| 114 let nonNumberValues = [ |
| 115 {}, |
| 116 (function(){}), |
| 117 [], |
| 118 (class Foo {}), |
| 119 "", |
| 120 "foo", |
| 121 "NaN", |
| 122 Object(""), |
| 123 false, |
| 124 null, |
| 125 undefined |
| 126 ]; |
| 127 |
| 128 // Check prior input of None works |
| 129 for (let func of getTestFuncs()) { |
| 130 for (let value of nonNumberValues) { |
| 131 assertThrows(function(){func(value)}, TypeError); |
| 132 assertThrows(function(){func(value)}, TypeError); |
| 133 assertThrows(function(){func(value)}, TypeError); |
| 134 %OptimizeFunctionOnNextCall(func); |
| 135 assertThrows(function(){func(value)}, TypeError); |
| 136 %DeoptimizeFunction(func); |
| 137 } |
| 138 } |
| 139 |
| 140 // Check prior input of Smi works |
| 141 for (let func of getTestFuncs()) { |
| 142 func(1); |
| 143 func(1); |
| 144 func(1); |
| 145 for (let value of nonNumberValues) { |
| 146 assertThrows(function(){func(value)}, TypeError); |
| 147 assertThrows(function(){func(value)}, TypeError); |
| 148 assertThrows(function(){func(value)}, TypeError); |
| 149 %OptimizeFunctionOnNextCall(func); |
| 150 assertThrows(function(){func(value)}, TypeError); |
| 151 %DeoptimizeFunction(func); |
| 152 } |
| 153 } |
| 154 |
| 155 // Check prior input of Number works |
| 156 for (let func of getTestFuncs()) { |
| 157 func(9999999999999); |
| 158 func(9999999999999); |
| 159 func(9999999999999); |
| 160 for (let value of nonNumberValues) { |
| 161 assertThrows(function(){func(value)}, TypeError); |
| 162 assertThrows(function(){func(value)}, TypeError); |
| 163 assertThrows(function(){func(value)}, TypeError); |
| 164 %OptimizeFunctionOnNextCall(func); |
| 165 assertThrows(function(){func(value)}, TypeError); |
| 166 %DeoptimizeFunction(func); |
| 167 } |
| 168 } |
OLD | NEW |