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