Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Unified Diff: src/js/proxy.js

Issue 1474083003: [proxies] Implement [[Enumerate]] and [[OwnPropertyKeys]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: gcmole fix Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/key-accumulator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/proxy.js
diff --git a/src/js/proxy.js b/src/js/proxy.js
index 3885e408add350acff7d74276a48a28f7eb8cb5c..d1202f7066bd2d66170f7518f0b95376fb77807a 100644
--- a/src/js/proxy.js
+++ b/src/js/proxy.js
@@ -152,31 +152,30 @@ function DerivedKeysTrap() {
return enumerableNames
}
-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]
- }
+// 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");
}
- 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)
+ // 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;
}
//-------------------------------------------------------------------
« no previous file with comments | « no previous file | src/key-accumulator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698