Index: src/js/proxy.js |
diff --git a/src/js/proxy.js b/src/js/proxy.js |
index d1202f7066bd2d66170f7518f0b95376fb77807a..3885e408add350acff7d74276a48a28f7eb8cb5c 100644 |
--- a/src/js/proxy.js |
+++ b/src/js/proxy.js |
@@ -152,30 +152,31 @@ |
return enumerableNames |
} |
-// Implements part of ES6 9.5.11 Proxy.[[Enumerate]]: |
-// Call the trap, which should return an iterator, exhaust the iterator, |
-// and return an array containing the values. |
-function ProxyEnumerate(trap, handler, target) { |
- // 7. Let trapResult be ? Call(trap, handler, «target»). |
- var trap_result = %_Call(trap, handler, target); |
- // 8. If Type(trapResult) is not Object, throw a TypeError exception. |
- if (!IS_SPEC_OBJECT(trap_result)) { |
- throw MakeTypeError(kProxyHandlerReturned, handler, "non-Object", |
- "enumerate"); |
- } |
- // 9. Return trapResult. |
- var result = []; |
- for (var it = trap_result.next(); !it.done; it = trap_result.next()) { |
- var key = it.value; |
- // Not yet spec'ed as of 2015-11-25, but will be spec'ed soon: |
- // If the iterator returns a non-string value, throw a TypeError. |
- if (!IS_STRING(key)) { |
- throw MakeTypeError(kProxyHandlerReturned, handler, "non-String", |
- "enumerate-iterator"); |
- } |
- result.push(key); |
- } |
- return result; |
+function DerivedEnumerateTrap() { |
+ var names = this.getPropertyNames() |
+ var enumerableNames = [] |
+ for (var i = 0, count = 0; i < names.length; ++i) { |
+ var name = names[i] |
+ if (IS_SYMBOL(name)) continue |
+ var desc = this.getPropertyDescriptor(TO_STRING(name)) |
+ if (!IS_UNDEFINED(desc)) { |
+ if (!desc.configurable) { |
+ throw MakeTypeError(kProxyPropNotConfigurable, |
+ this, name, "getPropertyDescriptor") |
+ } |
+ if (desc.enumerable) enumerableNames[count++] = names[i] |
+ } |
+ } |
+ return enumerableNames |
+} |
+ |
+function ProxyEnumerate(proxy) { |
+ var handler = %GetHandler(proxy) |
+ if (IS_UNDEFINED(handler.enumerate)) { |
+ return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) |
+ } else { |
+ return ToNameArray(handler.enumerate(), "enumerate", false) |
+ } |
} |
//------------------------------------------------------------------- |