Skip to content

Commit 3e8ccb1

Browse files
michaelficarraptomato
authored andcommitted
address my own comments
1 parent e0738ee commit 3e8ccb1

11 files changed

+90
-26
lines changed

harness/iteratorZipUtils.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ function _assertIsNullProtoMutableObject(object, label) {
9090
}
9191
}
9292

93-
// Assert that the `zipped` iterator results as for Iterator.zip for the first `count` elements.
94-
// Assumes inputs is an array of arrays of length >= count.
93+
// Assert that the `zipped` iterator yields the first `count` outputs of Iterator.zip.
94+
// Assumes `inputs` is an array of arrays, each with length >= `count`.
9595
// Advances `zipped` by `count` steps.
9696
function assertZipped(zipped, inputs, count, label) {
9797
// Last returned elements array.
@@ -117,14 +117,12 @@ function assertZipped(zipped, inputs, count, label) {
117117
assert.compareArray(value, expected, itemLabel + ": values");
118118

119119
// Ensure value is a packed array with default data properties.
120-
//
121-
// This operation is destructive, so it has to happen last.
122120
assertIsPackedArray(value, itemLabel);
123121
}
124122
}
125123

126-
// Assert that the `zipped` iterator results as for Iterator.zipKeyed for the first `count` elements.
127-
// Assumes inputs is an object whose values are arrays of length >= count.
124+
// Assert that the `zipped` iterator yields the first `count` outputs of Iterator.zipKeyed.
125+
// Assumes `inputs` is an object whose values are arrays, each with length >= `count`.
128126
// Advances `zipped` by `count` steps.
129127
function assertZippedKeyed(zipped, inputs, count, label) {
130128
// Last returned elements array.
@@ -154,8 +152,6 @@ function assertZippedKeyed(zipped, inputs, count, label) {
154152
assert.compareArray(Object.values(value), expectedValues, itemLabel + ": result object values");
155153

156154
// Ensure resulting object is a null-prototype mutable object with default data properties.
157-
//
158-
// This operation is destructive, so it has to happen last.
159155
_assertIsNullProtoMutableObject(value, itemLabel);
160156
}
161157
}

test/built-ins/Iterator/zip/iterables-iteration-after-reading-options.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,25 @@ assert.compareArray(log, [
4949
"get padding",
5050
"get iterator",
5151
]);
52+
53+
for (var mode of [undefined, "shortest", "strict"]) {
54+
log.length = 0;
55+
56+
options = {
57+
get mode() {
58+
log.push("get mode");
59+
return mode;
60+
},
61+
get padding() {
62+
log.push("unexpected get padding");
63+
return [];
64+
}
65+
};
66+
67+
Iterator.zip(iterables, options);
68+
69+
assert.compareArray(log, [
70+
"get mode",
71+
"get iterator",
72+
]);
73+
}

test/built-ins/Iterator/zip/iterables-iteration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var iterableReturningThrowingIterator = {
7070

7171
// "iterables" argument must be an iterable.
7272
assert.throws(TypeError, function() {
73-
Iterator.zip({});
73+
Iterator.zip(Object.create(null));
7474
});
7575

7676
// GetIteratorFlattenable accepts both iterables and iterators.
@@ -116,7 +116,7 @@ var elements = [
116116
makeProxyWithGetHandler("second", iterableReturningThrowingIterator),
117117

118118
// An object without any iteration methods.
119-
makeProxyWithGetHandler("third", {}),
119+
makeProxyWithGetHandler("third", Object.create(null)),
120120
];
121121

122122
var elementsIter = elements.values();

test/built-ins/Iterator/zip/iterator-non-iterable.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ features: [joint-iteration]
99
---*/
1010

1111
var invalidIterables = [
12-
{},
13-
{ next() {}, return() {} },
14-
function() {}
12+
Object.create(null),
13+
Object.create(null, {
14+
next: { value: function(){} },
15+
return: { value: function(){} },
16+
}),
1517
];
1618

1719
// Throws a TypeError for invalid iterables values.

test/built-ins/Iterator/zip/non-constructible.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ description: >
1212
features: [joint-iteration]
1313
---*/
1414

15-
assert.throws(TypeError, () => {
16-
new Iterator.zip();
17-
});
18-
1915
assert.throws(TypeError, () => {
2016
new Iterator.zip([]);
2117
});

test/built-ins/Iterator/zip/options-padding.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ features: [joint-iteration]
1919
var validPadding = [
2020
undefined,
2121
[],
22+
Object("string"),
2223
];
2324

2425
var invalidPadding = [
@@ -45,7 +46,7 @@ for (var padding of invalidPadding) {
4546
});
4647
}
4748

48-
// Invalid padding options are ignored when mode is not "longest".
49+
// Invalid padding options are okay when mode is not "longest" because the padding option is not read.
4950
for (var padding of invalidPadding) {
5051
Iterator.zip([], {padding});
5152
Iterator.zip([], {mode: undefined, padding});

test/built-ins/Iterator/zipKeyed/iterables-iteration-after-reading-options.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,25 @@ assert.compareArray(log, [
4747
"get padding",
4848
"own-keys",
4949
]);
50+
51+
for (var mode of [undefined, "shortest", "strict"]) {
52+
log.length = 0;
53+
54+
options = {
55+
get mode() {
56+
log.push("get mode");
57+
return mode;
58+
},
59+
get padding() {
60+
log.push("unexpected get padding");
61+
return [];
62+
}
63+
};
64+
65+
Iterator.zipKeyed(iterables, options);
66+
67+
assert.compareArray(log, [
68+
"get mode",
69+
"own-keys",
70+
]);
71+
}

test/built-ins/Iterator/zipKeyed/iterables-iteration-get-abrupt-completion.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,40 @@ var second = {
7777
},
7878
};
7979

80+
var symbol = {
81+
next() {
82+
log.push("unexpected call to next method");
83+
},
84+
return() {
85+
log.push("unexpected call to return method");
86+
},
87+
};
88+
89+
var arrayIndex = {
90+
next() {
91+
log.push("unexpected call to next method");
92+
},
93+
return() {
94+
// Called with the correct receiver and no arguments.
95+
assert.sameValue(this, arrayIndex);
96+
assert.sameValue(arguments.length, 0);
97+
98+
// NB: Log after above asserts, because failures aren't propagated.
99+
log.push("close array-indexed iterator");
100+
101+
// IteratorClose ignores new exceptions when called with a Throw completion.
102+
throw new Test262Error();
103+
},
104+
};
105+
80106
var iterables = {
107+
[Symbol()]: symbol,
81108
first,
82109
second,
83110
get third() {
84111
throw new ExpectedError();
85-
}
112+
},
113+
5: arrayIndex,
86114
};
87115

88116
assert.throws(ExpectedError, function() {
@@ -93,4 +121,5 @@ assert.throws(ExpectedError, function() {
93121
assert.compareArray(log, [
94122
"close second iterator",
95123
"close first iterator",
124+
"close array-indexed iterator",
96125
]);

test/built-ins/Iterator/zipKeyed/non-constructible.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ description: >
1212
features: [joint-iteration]
1313
---*/
1414

15-
assert.throws(TypeError, () => {
16-
new Iterator.zipKeyed();
17-
});
18-
1915
assert.throws(TypeError, () => {
2016
new Iterator.zipKeyed({});
2117
});

test/built-ins/Iterator/zipKeyed/options-padding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ features: [joint-iteration]
1818

1919
var validPadding = [
2020
undefined,
21-
[],
21+
{},
2222
];
2323

2424
var invalidPadding = [
@@ -45,7 +45,7 @@ for (var padding of invalidPadding) {
4545
});
4646
}
4747

48-
// Invalid padding options are ignored when mode is not "longest".
48+
// Invalid padding options are okay when mode is not "longest" because the padding option is not read.
4949
for (var padding of invalidPadding) {
5050
Iterator.zipKeyed({}, {padding});
5151
Iterator.zipKeyed({}, {mode: undefined, padding});

0 commit comments

Comments
 (0)