Bug 1246318 - Remove the enumerate trap from ES6 proxies. r=efaust

This commit is contained in:
Tom Schuster 2016-02-10 00:12:24 +01:00
parent 369af34f4a
commit 9ebc4ea621
9 changed files with 37 additions and 114 deletions

View File

@ -37,9 +37,6 @@ const Branch = function(branchName) {
value: this.get(target, name, receiver) value: this.get(target, name, receiver)
}; };
}, },
enumerate(target) {
return branchKeys(branchName)[Symbol.iterator]();
},
ownKeys(target) { ownKeys(target) {
return branchKeys(branchName); return branchKeys(branchName);
}, },

View File

@ -1,16 +0,0 @@
// Throwing [[Enumerate]] handler
load(libdir + "asserts.js");
let handler = new Proxy({}, {
get: function(target, name) {
assertEq(name, "enumerate");
throw new SyntaxError();
}
});
let proxy = new Proxy({}, handler);
assertThrowsInstanceOf(function() {
for (let x in proxy)
assertEq(true, false);
}, SyntaxError)

View File

@ -1,16 +0,0 @@
// Basic [[Enumerate]] functionality test
let inner = [];
let handler = {
enumerate: function(target) {
assertEq(target, inner);
assertEq(arguments.length, 1);
assertEq(this, handler);
return (function*() { yield 'a'; })();
}
};
let x;
for (let y in new Proxy(inner, handler)) {
x = y;
}
assertEq(x, 'a');

View File

@ -1,15 +0,0 @@
// Returning primitive from [[Enumerate]] handler
load(libdir + "asserts.js");
let handler = {
enumerate: function() {
return undefined;
}
};
let proxy = new Proxy({}, handler);
assertThrowsInstanceOf(function() {
for (let x in proxy)
assertEq(true, false);
}, TypeError)

View File

@ -724,52 +724,6 @@ ScriptedDirectProxyHandler::delete_(JSContext* cx, HandleObject proxy, HandleId
return result.succeed(); return result.succeed();
} }
// ES6 (14 October, 2014) 9.5.11 Proxy.[[Enumerate]]
bool
ScriptedDirectProxyHandler::enumerate(JSContext* cx, HandleObject proxy,
MutableHandleObject objp) const
{
// step 1
RootedObject handler(cx, GetDirectProxyHandlerObject(proxy));
// step 2
if (!handler) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_PROXY_REVOKED);
return false;
}
// step 3: unnecessary assert
// step 4
RootedObject target(cx, proxy->as<ProxyObject>().target());
// step 5-6
RootedValue trap(cx);
if (!GetProperty(cx, handler, handler, cx->names().enumerate, &trap))
return false;
// step 7
if (trap.isUndefined())
return GetIterator(cx, target, 0, objp);
// step 8-9
Value argv[] = {
ObjectOrNullValue(target)
};
RootedValue trapResult(cx);
if (!Invoke(cx, ObjectValue(*handler), trap, ArrayLength(argv), argv, &trapResult))
return false;
// step 10
if (trapResult.isPrimitive()) {
ReportInvalidTrapResult(cx, proxy, cx->names().enumerate);
return false;
}
// step 11
objp.set(&trapResult.toObject());
return true;
}
// ES6 (22 May, 2014) 9.5.7 Proxy.[[HasProperty]](P) // ES6 (22 May, 2014) 9.5.7 Proxy.[[HasProperty]](P)
bool bool
ScriptedDirectProxyHandler::has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const ScriptedDirectProxyHandler::has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const

View File

@ -28,7 +28,6 @@ class ScriptedDirectProxyHandler : public BaseProxyHandler {
AutoIdVector& props) const override; AutoIdVector& props) const override;
virtual bool delete_(JSContext* cx, HandleObject proxy, HandleId id, virtual bool delete_(JSContext* cx, HandleObject proxy, HandleId id,
ObjectOpResult& result) const override; ObjectOpResult& result) const override;
virtual bool enumerate(JSContext* cx, HandleObject proxy, MutableHandleObject objp) const override;
/* These two are standard internal methods but aren't implemented to spec yet. */ /* These two are standard internal methods but aren't implemented to spec yet. */
virtual bool getPrototype(JSContext* cx, HandleObject proxy, virtual bool getPrototype(JSContext* cx, HandleObject proxy,

View File

@ -0,0 +1,37 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
"use strict";
let steps = [];
const object = {
__proto__: {
"xyz": 42
}
};
const proxy = new Proxy(object, {
ownKeys(target) {
steps.push("ownKeys")
return ["a", "b"];
},
getOwnPropertyDescriptor(target, property) {
steps.push("getOwn-" + property);
return {
value: undefined,
configurable: true,
writable: true,
enumerable: (property === "a")
};
}
});
let iterated = [];
for (let x in proxy)
iterated.push(x);
assertEq(iterated.toString(), "a,xyz");
assertEq(steps.toString(), "ownKeys,getOwn-a,getOwn-b");
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -53,16 +53,6 @@ assertThrowsInstanceOf(() => createProxy({a: 5}).a = 0, TypeError);
assertEq(delete createProxy({}).a, true); assertEq(delete createProxy({}).a, true);
assertEq(delete createProxy(Object.defineProperty({}, "a", {configurable: false})).a, false); assertEq(delete createProxy(Object.defineProperty({}, "a", {configurable: false})).a, false);
// [[Enumerate]]
for (var k in createProxy({})) {
// No properties in object.
assertEq(true, false);
}
for (var k in createProxy({a: 5})) {
// Properties in object.
assertEq(k, "a");
}
// [[OwnPropertyKeys]] // [[OwnPropertyKeys]]
assertEq(Object.getOwnPropertyNames(createProxy({})).length, 0); assertEq(Object.getOwnPropertyNames(createProxy({})).length, 0);
assertEq(Object.getOwnPropertyNames(createProxy({a: 5})).length, 1); assertEq(Object.getOwnPropertyNames(createProxy({a: 5})).length, 1);

View File

@ -294,13 +294,6 @@ SpecialPowersHandler.prototype = {
return props; return props;
}, },
enumerate(target) {
return (function*() {
for (let property in this.wrappedObject)
yield property;
}).call(this);
},
preventExtensions(target) { preventExtensions(target) {
throw "Can't call preventExtensions on SpecialPowers wrapped object"; throw "Can't call preventExtensions on SpecialPowers wrapped object";
} }