Bug 1216751 part 2. For value iterators, "entries", "keys", and "values" must just come from Array.prototype. r=qdot

This commit is contained in:
Boris Zbarsky 2016-02-17 22:58:00 -05:00
parent a7cbbd23ab
commit dcb6669fbd
4 changed files with 46 additions and 2 deletions

View File

@ -2316,6 +2316,39 @@ class MethodDefiner(PropertyDefiner):
})
break
if (not static and
maplikeOrSetlikeOrIterable and
maplikeOrSetlikeOrIterable.isIterable() and
maplikeOrSetlikeOrIterable.isValueIterator()):
# Add our keys/values/entries
self.regular.append({
"name": "keys",
"methodInfo": False,
"selfHostedName": "ArrayKeys",
"length": 0,
"flags": "JSPROP_ENUMERATE",
"condition": PropertyDefiner.getControllingCondition(m,
descriptor)
})
self.regular.append({
"name": "values",
"methodInfo": False,
"selfHostedName": "ArrayValues",
"length": 0,
"flags": "JSPROP_ENUMERATE",
"condition": PropertyDefiner.getControllingCondition(m,
descriptor)
})
self.regular.append({
"name": "entries",
"methodInfo": False,
"selfHostedName": "ArrayEntries",
"length": 0,
"flags": "JSPROP_ENUMERATE",
"condition": PropertyDefiner.getControllingCondition(m,
descriptor)
})
if not static:
stringifier = descriptor.operations['Stringifier']
if (stringifier and

View File

@ -3632,6 +3632,11 @@ class IDLIterable(IDLMaplikeOrSetlikeOrIterableBase):
we generate our functions as if they were part of the interface
specification during parsing.
"""
# We only need to add entries/keys/values here if we're a pair iterator.
# Value iterators just copy these from %ArrayPrototype% instead.
if not self.isPairIterator():
return
# object entries()
self.addMethod("entries", members, False, self.iteratorType,
affectsNothing=True, newObject=True)

View File

@ -78,7 +78,7 @@ def WebIDLTest(parser, harness):
# __iterable to it for the iterable<> case.
iterableMembers.append(("__iterable", WebIDL.IDLIterable))
valueIterableMembers = list(iterableMembers)
valueIterableMembers = [("__iterable", WebIDL.IDLIterable)]
valueIterableMembers.append(("__indexedgetter", WebIDL.IDLMethod))
valueIterableMembers.append(("length", WebIDL.IDLAttribute))

View File

@ -52,6 +52,12 @@
testExistence("IterableSingle: ", itr, base_properties);
is(itr[Symbol.iterator], Array.prototype[Symbol.iterator],
"IterableSingle: Should be using %ArrayIterator% for @@iterator");
is(itr.keys, Array.prototype.keys,
"IterableSingle: Should be using %ArrayIterator% for 'keys'");
is(itr.entries, Array.prototype.entries,
"IterableSingle: Should be using %ArrayIterator% for 'entries'");
is(itr.values, itr[Symbol.iterator],
"IterableSingle: Should be using @@iterator for 'values'");
var keys = [...itr.keys()];
var values = [...itr.values()];
var entries = [...itr.entries()];
@ -85,7 +91,7 @@
is(entry.value, undefined, "IterableDouble: Entry iterator value should be undefined");
is(entry.done, true, "IterableSingle: Entry iterator done should be true");
is(Object.prototype.toString.call(Object.getPrototypeOf(key_itr)),
"[object TestInterfaceIterableSingleIteratorPrototype]",
"[object Array Iterator]",
"iterator prototype should have the right brand");
// Simple dual type iterable creation and functionality test