Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --harmony-proxies --allow-natives-syntax --expose-debug-as debug | 5 // Flags: --harmony-proxies --allow-natives-syntax --expose-debug-as debug |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 // Test non-JSObject receiver. | 9 // Test non-JSObject receiver. |
| 10 function f(o) { | 10 function f(o) { |
| 11 var result = []; | 11 var result = []; |
| 12 for (var i in o) { | 12 for (var i in o) { |
| 13 result.push(i); | 13 result.push(i); |
| 14 } | 14 } |
| 15 return result; | 15 return result; |
| 16 } | 16 } |
| 17 | 17 |
| 18 assertEquals(["0"], f("a")); | 18 assertEquals(["0"], f("a")); |
| 19 assertEquals(["0"], f("a")); | 19 assertEquals(["0"], f("a")); |
| 20 | 20 |
| 21 %OptimizeFunctionOnNextCall(f); | 21 %OptimizeFunctionOnNextCall(f); |
| 22 assertEquals(["0","1","2"], f("bla")); | 22 assertEquals(["0","1","2"], f("bla")); |
| 23 | 23 |
| 24 // Test the lazy deopt points. | 24 // Test the lazy deopt points. |
| 25 var keys = ["a", "b", "c", "d"]; | 25 var keys = ["a", "b", "c", "d"]; |
| 26 var has_keys = []; | 26 var property_descriptor_keys = []; |
| 27 var deopt_has = false; | |
| 28 var deopt_enum = false; | 27 var deopt_enum = false; |
| 28 var deopt_property_descriptor = false; | |
| 29 | 29 |
| 30 var handler = { | 30 var handler = { |
| 31 ownKeys() { | 31 ownKeys() { |
| 32 if (deopt_enum) { | 32 if (deopt_enum) { |
| 33 %DeoptimizeFunction(f2); | 33 %DeoptimizeFunction(f2); |
| 34 deopt_enum = false; | 34 deopt_enum = false; |
| 35 } | 35 } |
| 36 return keys; | 36 return keys; |
| 37 }, | 37 }, |
| 38 getOwnPropertyDescriptor() { return { enumerable: true, configurable: true }}, | 38 getOwnPropertyDescriptor(target, k) { |
| 39 | 39 if (deopt_property_descriptor) { |
| 40 has(target, k) { | |
| 41 if (deopt_has) { | |
| 42 %DeoptimizeFunction(f2); | 40 %DeoptimizeFunction(f2); |
| 43 deopt_has = false; | 41 deopt_property_descriptor = false; |
| 44 } | 42 } |
| 45 has_keys.push(k); | 43 property_descriptor_keys.push(k); |
| 46 return true; | 44 return { enumerable: true, configurable: true } |
| 47 } | 45 }, |
| 48 }; | 46 }; |
| 49 | 47 |
| 50 | 48 |
| 51 var proxy = new Proxy({}, handler); | 49 var proxy = new Proxy({}, handler); |
| 52 var o = {__proto__: proxy}; | 50 var o = {__proto__: proxy}; |
| 53 | 51 |
| 54 function f2(o) { | 52 function f2(o) { |
| 55 var result = []; | 53 var result = []; |
| 56 for (var i in o) { | 54 for (var i in o) { |
| 57 result.push(i); | 55 result.push(i); |
| 58 } | 56 } |
| 59 return result; | 57 return result; |
| 60 } | 58 } |
| 61 | 59 |
| 62 function check_f2() { | 60 function check_f2() { |
| 63 assertEquals(keys, f2(o)); | 61 assertEquals(keys, f2(o)); |
| 64 assertEquals(keys, has_keys); | 62 assertEquals(keys, property_descriptor_keys); |
| 65 has_keys.length = 0; | 63 property_descriptor_keys.length = 0; |
| 66 } | 64 } |
| 67 | 65 |
| 68 check_f2(); | 66 check_f2(); |
| 69 check_f2(); | 67 check_f2(); |
| 70 | 68 |
| 71 // Test lazy deopt after ForInEnumerate | 69 // Test lazy deopt after ForInEnumerate |
| 72 %OptimizeFunctionOnNextCall(f2); | 70 %OptimizeFunctionOnNextCall(f2); |
| 73 deopt_enum = true; | 71 deopt_enum = true; |
| 74 check_f2(); | 72 check_f2(); |
| 75 | 73 |
| 76 // Test lazy deopt after FILTER_KEY | 74 // Test lazy deopt after FILTER_KEY |
| 77 %OptimizeFunctionOnNextCall(f2); | 75 %OptimizeFunctionOnNextCall(f2); |
| 78 deopt_has = true; | 76 deopt_property_descriptor = true; |
| 79 check_f2(); | 77 check_f2(); |
| 80 | 78 |
| 79 | |
| 81 function f3(o) { | 80 function f3(o) { |
| 82 for (var i in o) { | 81 for (var i in o) { |
| 83 } | 82 } |
| 84 } | 83 } |
| 85 | 84 |
| 86 f3({__proto__:{x:1}}); | 85 f3({__proto__:{x:1}}); |
| 87 f3({__proto__:{x:1}}); | 86 f3({__proto__:{x:1}}); |
| 88 | 87 |
| 89 %OptimizeFunctionOnNextCall(f3); | 88 %OptimizeFunctionOnNextCall(f3); |
| 90 f3(undefined); | 89 f3(undefined); |
| 91 f3(null); | 90 f3(null); |
| 92 | 91 |
| 93 // Reliable repro for an issue previously flushed out by GC stress. | 92 // Reliable repro for an issue previously flushed out by GC stress. |
| 94 var handler2 = { | |
|
Jakob Kummerow
2016/03/18 14:12:00
That's weird. This careful setup of handler2/proxy
Camillo Bruni
2016/03/18 17:46:34
yeah, this confused me more that it should have...
| |
| 95 getPropertyDescriptor(target, k) { | |
| 96 has_keys.push(k); | |
| 97 return {value: 10, configurable: true, writable: false, enumerable: true}; | |
| 98 } | |
| 99 } | |
| 100 var proxy2 = new Proxy({}, handler2); | |
| 101 var o2 = {__proto__: proxy2}; | |
| 102 var p = {x: "x"} | 93 var p = {x: "x"} |
| 103 | 94 |
| 104 function f4(o, p) { | 95 function f4(o, p) { |
| 105 var result = []; | 96 var result = []; |
| 106 for (var i in o) { | 97 for (var i in o) { |
| 107 var j = p.x + "str"; | 98 var j = p.x + "str"; |
| 108 result.push(i); | 99 result.push(i); |
| 109 } | 100 } |
| 110 return result; | 101 return result; |
| 111 } | 102 } |
| 112 | 103 |
| 113 function check_f4() { | 104 function check_f4() { |
| 114 assertEquals(keys, f4(o, p)); | 105 assertEquals(keys, f4(o, p)); |
| 115 assertEquals(keys, has_keys); | 106 assertEquals(keys, property_descriptor_keys); |
| 116 has_keys.length = 0; | 107 property_descriptor_keys.length = 0; |
| 117 } | 108 } |
| 118 | 109 |
| 119 check_f4(); | 110 check_f4(); |
| 120 check_f4(); | 111 check_f4(); |
| 121 | 112 |
| 122 %OptimizeFunctionOnNextCall(f4); | 113 %OptimizeFunctionOnNextCall(f4); |
| 123 | 114 |
| 124 p.y = "y"; // Change map, cause eager deopt. | 115 p.y = "y"; // Change map, cause eager deopt. |
| 125 check_f4(); | 116 check_f4(); |
| 126 | 117 |
| 127 // Repro for Turbofan equivalent. | 118 // Repro for Turbofan equivalent. |
| 128 var x; | 119 var x; |
| 129 var count = 0; | 120 var count = 0; |
| 130 | 121 |
| 131 var Debug = debug.Debug; | 122 var Debug = debug.Debug; |
| 132 | 123 |
| 133 function listener(event, exec_state, event_data, data) { | 124 function listener(event, exec_state, event_data, data) { |
| 134 if (event == Debug.DebugEvent.Break) { | 125 if (event == Debug.DebugEvent.Break) { |
| 135 %DeoptimizeFunction(f5); | 126 %DeoptimizeFunction(f5); |
| 136 } | 127 } |
| 137 } | 128 } |
| 138 | 129 |
| 139 var handler3 = { | 130 var handler3 = { |
| 140 ownKeys() { return ["a", "b"] }, | 131 ownKeys() { return ["a", "b"] }, |
| 141 getOwnPropertyDescriptor() { return { enumerable: true, configurable: true }}, | 132 getOwnPropertyDescriptor(target, k) { |
| 142 | |
| 143 has(target, k) { | |
| 144 if (k == "a") count++; | 133 if (k == "a") count++; |
| 145 if (x) %ScheduleBreak(); | 134 if (x) %ScheduleBreak() |
|
Jakob Kummerow
2016/03/18 14:12:00
nit: why drop the semicolons?
Camillo Bruni
2016/03/18 17:46:34
random... will re-add ;)
| |
| 146 return true; | 135 return { enumerable: true, configurable: true } |
| 147 } | 136 } |
| 148 }; | 137 }; |
| 149 | 138 |
| 150 var proxy3 = new Proxy({}, handler3); | 139 var proxy3 = new Proxy({}, handler3); |
| 151 var o3 = {__proto__: proxy3}; | 140 var o3 = {__proto__: proxy3}; |
| 152 | 141 |
| 153 function f5() { | 142 function f5() { |
| 154 for (var p in o3) { | 143 for (var p in o3) { |
| 155 print(p); | 144 print(p); |
| 156 } | 145 } |
| 157 } | 146 } |
| 158 | 147 |
| 159 x = false; | 148 x = false; |
| 160 | 149 |
| 161 f5(); f5(); f5(); | 150 f5(); f5(); f5(); |
| 162 %OptimizeFunctionOnNextCall(f5); | 151 %OptimizeFunctionOnNextCall(f5); |
| 163 x = true; | 152 x = true; |
| 164 count = 0; | 153 count = 0; |
| 165 Debug.setListener(listener); | 154 Debug.setListener(listener); |
| 166 f5(); | 155 f5(); |
| 167 Debug.setListener(null); | 156 Debug.setListener(null); |
| 168 assertEquals(1, count); | 157 assertEquals(1, count); |
| OLD | NEW |