Bug 783829 - Fix for bug when enumerating just enumerable symbols. r=efaust

This commit is contained in:
Tom Schuster 2014-12-17 00:28:38 +01:00
parent 7ed0e36ad2
commit d398e6a3f7
4 changed files with 56 additions and 6 deletions

View File

@ -0,0 +1,33 @@
// Make sure that we can find own, enumerable symbols.
var symbol = Symbol("bad");
var symbol2 = Symbol("good");
var proxy = new Proxy({}, {
ownKeys() {
return [symbol, symbol2];
},
getOwnPropertyDescriptor(target, name) {
if (name == symbol)
return {configurable: true, enumerable: false, value: {}};
// Only this enumerable symbol should be defined.
if (name == symbol2)
return {configurable: true, enumerable: true, value: {}};
assertEq(true, false);
},
get(target, name) {
// Slightly confusing, but these are the descriptors that defineProperties
// is going to define on the object.
if (name == symbol)
return {configurable: true, value: "bad"};
if (name == symbol2)
return {configurable: true, value: "good"};
assertEq(true, false);
}
});
assertEq(Object.getOwnPropertySymbols(proxy).length, 2);
var obj = {};
Object.defineProperties(obj, proxy);
assertEq(Object.getOwnPropertySymbols(obj).length, 1);
assertEq(symbol in obj, false);
assertEq(symbol2 in obj, true);
assertEq(obj[symbol2], "good");

View File

@ -312,14 +312,31 @@ Snapshot(JSContext *cx, HandleObject pobj_, unsigned flags, AutoIdVector *props)
// will filter out unwanted keys, per the flags.
if (!Proxy::ownPropertyKeys(cx, pobj, proxyProps))
return false;
Rooted<PropertyDescriptor> desc(cx);
for (size_t n = 0, len = proxyProps.length(); n < len; n++) {
bool enumerable = false;
// We need to filter, if the caller just wants enumerable
// symbols.
if (!(flags & JSITER_HIDDEN)) {
if (!Proxy::getOwnPropertyDescriptor(cx, pobj, proxyProps[n], &desc))
return false;
enumerable = desc.isEnumerable();
}
if (!Enumerate(cx, pobj, proxyProps[n], enumerable, flags, ht, props))
return false;
}
} else {
// Returns enumerable property names (no symbols).
if (!Proxy::getOwnEnumerablePropertyKeys(cx, pobj, proxyProps))
return false;
}
for (size_t n = 0, len = proxyProps.length(); n < len; n++) {
if (!Enumerate(cx, pobj, proxyProps[n], true, flags, ht, props))
return false;
for (size_t n = 0, len = proxyProps.length(); n < len; n++) {
if (!Enumerate(cx, pobj, proxyProps[n], true, flags, ht, props))
return false;
}
}
} else {
MOZ_CRASH("non-native objects must have an enumerate op");

View File

@ -10,7 +10,7 @@ function test() {
if (typeof timeout != "function")
return;
var p = Proxy.create({ enumerate: function() { return Array(1e9); }});
var p = Proxy.create({ keys: function() { return Array(1e9); }});
expectExitCode(6);
timeout(0.001);

View File

@ -5,7 +5,7 @@
*/
function test() {
var p = Proxy.create({ enumerate: function() { return { get length() { throw 1; }}; }});
var p = Proxy.create({ keys: function() { return { get length() { throw 1; }}; }});
try {
for (i in p);