| 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 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 var name = names[i] | 145 var name = names[i] |
| 146 if (IS_SYMBOL(name)) continue | 146 if (IS_SYMBOL(name)) continue |
| 147 var desc = this.getOwnPropertyDescriptor(TO_STRING(name)) | 147 var desc = this.getOwnPropertyDescriptor(TO_STRING(name)) |
| 148 if (!IS_UNDEFINED(desc) && desc.enumerable) { | 148 if (!IS_UNDEFINED(desc) && desc.enumerable) { |
| 149 enumerableNames[count++] = names[i] | 149 enumerableNames[count++] = names[i] |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 return enumerableNames | 152 return enumerableNames |
| 153 } | 153 } |
| 154 | 154 |
| 155 function DerivedEnumerateTrap() { | 155 // Implements part of ES6 9.5.11 Proxy.[[Enumerate]]: |
| 156 var names = this.getPropertyNames() | 156 // Call the trap, which should return an iterator, exhaust the iterator, |
| 157 var enumerableNames = [] | 157 // and return an array containing the values. |
| 158 for (var i = 0, count = 0; i < names.length; ++i) { | 158 function ProxyEnumerate(trap, handler, target) { |
| 159 var name = names[i] | 159 // 7. Let trapResult be ? Call(trap, handler, «target»). |
| 160 if (IS_SYMBOL(name)) continue | 160 var trap_result = %_Call(trap, handler, target); |
| 161 var desc = this.getPropertyDescriptor(TO_STRING(name)) | 161 // 8. If Type(trapResult) is not Object, throw a TypeError exception. |
| 162 if (!IS_UNDEFINED(desc)) { | 162 if (!IS_SPEC_OBJECT(trap_result)) { |
| 163 if (!desc.configurable) { | 163 throw MakeTypeError(kProxyHandlerReturned, handler, "non-Object", |
| 164 throw MakeTypeError(kProxyPropNotConfigurable, | 164 "enumerate"); |
| 165 this, name, "getPropertyDescriptor") | 165 } |
| 166 } | 166 // 9. Return trapResult. |
| 167 if (desc.enumerable) enumerableNames[count++] = names[i] | 167 var result = []; |
| 168 for (var it = trap_result.next(); !it.done; it = trap_result.next()) { |
| 169 var key = it.value; |
| 170 // Not yet spec'ed as of 2015-11-25, but will be spec'ed soon: |
| 171 // If the iterator returns a non-string value, throw a TypeError. |
| 172 if (!IS_STRING(key)) { |
| 173 throw MakeTypeError(kProxyHandlerReturned, handler, "non-String", |
| 174 "enumerate-iterator"); |
| 168 } | 175 } |
| 176 result.push(key); |
| 169 } | 177 } |
| 170 return enumerableNames | 178 return result; |
| 171 } | |
| 172 | |
| 173 function ProxyEnumerate(proxy) { | |
| 174 var handler = %GetHandler(proxy) | |
| 175 if (IS_UNDEFINED(handler.enumerate)) { | |
| 176 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) | |
| 177 } else { | |
| 178 return ToNameArray(handler.enumerate(), "enumerate", false) | |
| 179 } | |
| 180 } | 179 } |
| 181 | 180 |
| 182 //------------------------------------------------------------------- | 181 //------------------------------------------------------------------- |
| 183 %SetCode(GlobalProxy, ProxyCreate); | 182 %SetCode(GlobalProxy, ProxyCreate); |
| 184 | 183 |
| 185 //Set up non-enumerable properties of the Proxy object. | 184 //Set up non-enumerable properties of the Proxy object. |
| 186 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ | 185 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ |
| 187 "createFunction", ProxyCreateFunction | 186 "createFunction", ProxyCreateFunction |
| 188 ]); | 187 ]); |
| 189 | 188 |
| 190 // ------------------------------------------------------------------- | 189 // ------------------------------------------------------------------- |
| 191 // Exports | 190 // Exports |
| 192 | 191 |
| 193 utils.Export(function(to) { | 192 utils.Export(function(to) { |
| 194 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct; | 193 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct; |
| 195 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap; | 194 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap; |
| 196 to.ProxyDerivedKeysTrap = DerivedKeysTrap; | 195 to.ProxyDerivedKeysTrap = DerivedKeysTrap; |
| 197 }); | 196 }); |
| 198 | 197 |
| 199 %InstallToContext([ | 198 %InstallToContext([ |
| 200 "derived_get_trap", DerivedGetTrap, | 199 "derived_get_trap", DerivedGetTrap, |
| 201 "derived_has_trap", DerivedHasTrap, | 200 "derived_has_trap", DerivedHasTrap, |
| 202 "derived_set_trap", DerivedSetTrap, | 201 "derived_set_trap", DerivedSetTrap, |
| 203 "proxy_enumerate", ProxyEnumerate, | 202 "proxy_enumerate", ProxyEnumerate, |
| 204 ]); | 203 ]); |
| 205 | 204 |
| 206 }) | 205 }) |
| OLD | NEW |