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: --harmony-proxies --allow-natives-syntax |
| 6 |
| 7 "use strict"; |
| 8 |
| 9 // Test non-JSObject receiver. |
| 10 function f(o) { |
| 11 var result = []; |
| 12 for (var i in o) { |
| 13 result.push(i); |
| 14 } |
| 15 return result; |
| 16 } |
| 17 |
| 18 assertEquals(["0"], f("a")); |
| 19 assertEquals(["0"], f("a")); |
| 20 %OptimizeFunctionOnNextCall(f); |
| 21 assertEquals(["0","1","2"], f("bla")); |
| 22 |
| 23 // Test the lazy deopt points. |
| 24 var keys = ["a", "b", "c", "d"]; |
| 25 var has_keys = []; |
| 26 var deopt_has = false; |
| 27 var deopt_enum = false; |
| 28 |
| 29 var handler = { |
| 30 enumerate: function(target) { |
| 31 if (deopt_enum) { |
| 32 %DeoptimizeFunction(f2); |
| 33 deopt_enum = false; |
| 34 } |
| 35 return keys; |
| 36 }, |
| 37 |
| 38 getPropertyDescriptor: function(k) { |
| 39 if (deopt_has) { |
| 40 %DeoptimizeFunction(f2); |
| 41 deopt_has = false; |
| 42 } |
| 43 has_keys.push(k); |
| 44 return {value: 10, configurable: true, writable: false, enumerable: true}; |
| 45 } |
| 46 }; |
| 47 |
| 48 |
| 49 var proxy = Proxy.create(handler); |
| 50 var o = {__proto__: proxy}; |
| 51 |
| 52 function f2(o) { |
| 53 var result = []; |
| 54 for (var i in o) { |
| 55 result.push(i); |
| 56 } |
| 57 return result; |
| 58 } |
| 59 |
| 60 function check_f2() { |
| 61 assertEquals(keys, f2(o)); |
| 62 assertEquals(keys, has_keys); |
| 63 has_keys.length = 0; |
| 64 } |
| 65 |
| 66 check_f2(); |
| 67 check_f2(); |
| 68 // Test lazy deopt after GetPropertyNamesFast |
| 69 %OptimizeFunctionOnNextCall(f2); |
| 70 deopt_enum = true; |
| 71 check_f2(); |
| 72 // Test lazy deopt after FILTER_KEY |
| 73 %OptimizeFunctionOnNextCall(f2); |
| 74 deopt_has = true; |
| 75 check_f2(); |
OLD | NEW |