The adder should be gotten before the iterator.
Motivation: Once this is done we should be able to use a for-of loop
instead which leads to cleaner code and correct behavior once the
for-of loop correctly supports abrupt completion.
BUG=None
LOG=N
R=adamk
Review URL: https://codereview.chromium.org/
949933002
Cr-Commit-Position: refs/heads/master@{#26803}
var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) {
- iter = GetIterator(iterable);
adder = this.add;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['add', this]);
}
+ iter = GetIterator(iterable);
}
%_SetInitialize(this);
var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) {
- iter = GetIterator(iterable);
adder = this.set;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['set', this]);
}
+ iter = GetIterator(iterable);
}
%_MapInitialize(this);
var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) {
- iter = GetIterator(iterable);
adder = this.set;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['set', this]);
}
+ iter = GetIterator(iterable);
}
%WeakCollectionInitialize(this);
var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) {
- iter = GetIterator(iterable);
adder = this.add;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['add', this]);
}
+ iter = GetIterator(iterable);
}
%WeakCollectionInitialize(this);
TestCollectionToString(Set);
TestCollectionToString(WeakMap);
TestCollectionToString(WeakSet);
+
+
+function TestConstructorOrderOfAdderIterator(ctor, adderName) {
+ var iterable = new Map();
+ iterable.set({}, {});
+ iterable.set({}, {});
+ var iterableFunction = iterable[Symbol.iterator];
+ Object.defineProperty(iterable, Symbol.iterator, {
+ get: function() {
+ log += 'iterator';
+ return iterableFunction;
+ }
+ });
+
+ var log = '';
+ var adderFunction = ctor.prototype[adderName];
+
+ Object.defineProperty(ctor.prototype, adderName, {
+ get: function() {
+ log += adderName;
+ return adderFunction;
+ }
+ });
+
+ new ctor(iterable);
+ assertEquals(adderName + 'iterator', log);
+
+ Object.defineProperty(ctor.prototype, adderName, {
+ value: adderFunction
+ });
+}
+TestConstructorOrderOfAdderIterator(Map, 'set');
+TestConstructorOrderOfAdderIterator(Set, 'add');
+TestConstructorOrderOfAdderIterator(WeakMap, 'set');
+TestConstructorOrderOfAdderIterator(WeakSet, 'add');