| 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 |
| 11 // ---------------------------------------------------------------------------- | 11 // ---------------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 // | 13 // |
| 14 var GlobalProxy = global.Proxy; | 14 var GlobalProxy = global.Proxy; |
| 15 var MakeTypeError; | |
| 16 | |
| 17 utils.Import(function(from) { | |
| 18 MakeTypeError = from.MakeTypeError; | |
| 19 }); | |
| 20 | 15 |
| 21 //---------------------------------------------------------------------------- | 16 //---------------------------------------------------------------------------- |
| 22 | 17 |
| 23 function ProxyCreateRevocable(target, handler) { | 18 function ProxyCreateRevocable(target, handler) { |
| 24 var p = new GlobalProxy(target, handler); | 19 var p = new GlobalProxy(target, handler); |
| 25 return {proxy: p, revoke: () => %JSProxyRevoke(p)}; | 20 return {proxy: p, revoke: () => %JSProxyRevoke(p)}; |
| 26 } | 21 } |
| 27 | 22 |
| 28 // ------------------------------------------------------------------- | |
| 29 // Proxy Builtins | |
| 30 | |
| 31 // Implements part of ES6 9.5.11 Proxy.[[Enumerate]]: | |
| 32 // Call the trap, which should return an iterator, exhaust the iterator, | |
| 33 // and return an array containing the values. | |
| 34 function ProxyEnumerate(trap, handler, target) { | |
| 35 // 7. Let trapResult be ? Call(trap, handler, «target»). | |
| 36 var trap_result = %_Call(trap, handler, target); | |
| 37 // 8. If Type(trapResult) is not Object, throw a TypeError exception. | |
| 38 if (!IS_RECEIVER(trap_result)) { | |
| 39 throw MakeTypeError(kProxyEnumerateNonObject); | |
| 40 } | |
| 41 // 9. Return trapResult. | |
| 42 var result = []; | |
| 43 for (var it = trap_result.next(); !it.done; it = trap_result.next()) { | |
| 44 var key = it.value; | |
| 45 // Not yet spec'ed as of 2015-11-25, but will be spec'ed soon: | |
| 46 // If the iterator returns a non-string value, throw a TypeError. | |
| 47 if (!IS_STRING(key)) { | |
| 48 throw MakeTypeError(kProxyEnumerateNonString); | |
| 49 } | |
| 50 result.push(key); | |
| 51 } | |
| 52 return result; | |
| 53 } | |
| 54 | |
| 55 //------------------------------------------------------------------- | 23 //------------------------------------------------------------------- |
| 56 | 24 |
| 57 //Set up non-enumerable properties of the Proxy object. | 25 //Set up non-enumerable properties of the Proxy object. |
| 58 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ | 26 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ |
| 59 "revocable", ProxyCreateRevocable | 27 "revocable", ProxyCreateRevocable |
| 60 ]); | 28 ]); |
| 61 | 29 |
| 62 // ------------------------------------------------------------------- | |
| 63 // Exports | |
| 64 | |
| 65 %InstallToContext([ | |
| 66 "proxy_enumerate", ProxyEnumerate, | |
| 67 ]); | |
| 68 | |
| 69 }) | 30 }) |
| OLD | NEW |