Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
- Remove unused `flags
- Do not use `deepEqual.js`
- Assert `return` never got when `this` value is invalid
- Use `TemporalHelpers` to observer get / call
  • Loading branch information
sosukesuzuki committed Sep 13, 2024
1 parent f617443 commit 21273ca
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 39 deletions.
30 changes: 18 additions & 12 deletions test/built-ins/Iterator/from/get-return-method-when-call-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ info: |
5. Let returnMethod be ? GetMethod(iterator, "return").
features: [iterator-helpers]
flags: []
includes: [temporalHelpers.js, compareArray.js]
---*/

let returnGetCount = 0;
const iter = {
get return() {
returnGetCount++;
return function () {
return { value: 5, done: true };
};
},
};
const calls = [];

const iter = TemporalHelpers.propertyBagObserver(calls, {
return () {
return { value: 5, done: true };
},
}, "originalIter");

const wrapper = Iterator.from(iter);
assert.sameValue(returnGetCount, 0);
assert.compareArray(calls, [
"get originalIter[Symbol.iterator]",
"get originalIter.next",
]);

wrapper.return();
assert.sameValue(returnGetCount, 1);
assert.compareArray(calls, [
"get originalIter[Symbol.iterator]",
"get originalIter.next",
"get originalIter.return"
]);
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,31 @@ info: |
...
7. Return ? Call(returnMethod, iterator).
includes: [deepEqual.js]
features: [iterator-helpers]
flags: []
includes: [temporalHelpers.js, compareArray.js]
---*/

let returnCallCount = 0;
const iter = {
const calls = [];

const expectedIteratorResult = { value: 5, done: true };
const originalIter = {
return () {
returnCallCount++;
return { value: 5, done: true };
return expectedIteratorResult;
},
};
TemporalHelpers.observeMethod(calls, originalIter, "return", "originalIter");
const iter = TemporalHelpers.propertyBagObserver(calls, originalIter, "originalIter");

const wrapper = Iterator.from(iter);
assert.compareArray(calls, [
"get originalIter[Symbol.iterator]",
"get originalIter.next",
]);

assert.deepEqual(wrapper.return(), { value: 5, done: true });
assert.sameValue(returnCallCount, 1);
assert.sameValue(wrapper.return(), expectedIteratorResult);
assert.compareArray(calls, [
"get originalIter[Symbol.iterator]",
"get originalIter.next",
"get originalIter.return",
"call originalIter.return",
]);
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ info: |
6. If returnMethod is undefined, then
a. Return CreateIterResultObject(undefined, true).
includes: [deepEqual.js]
features: [iterator-helpers]
flags: []
---*/

const iter = {};
const wrapper = Iterator.from(iter);

assert.deepEqual(wrapper.return(), { value: undefined, done: true });
const result = wrapper.return();
assert(result.hasOwnProperty("value"));
assert.sameValue(result.value, undefined);
assert.sameValue(result.done, true);
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@ info: |
2. Perform ? RequireInternalSlot(O, [[Iterated]]).
features: [iterator-helpers]
flags: []
includes: [temporalHelpers.js, compareArray.js]
---*/

const iter = {};
const WrapForValidIteratorPrototype = Object.getPrototypeOf(Iterator.from(iter));
const WrapForValidIteratorPrototype = Object.getPrototypeOf(Iterator.from({}));

assert.throws(TypeError, function() {
WrapForValidIteratorPrototype.return.call({});
});
{
assert.throws(TypeError, function() {
WrapForValidIteratorPrototype.return.call({});
});
}

let returnCallCount = 0;
assert.throws(TypeError, function() {
WrapForValidIteratorPrototype.return.call({
return () {
returnCallCount++;
return { value: 5, done: true };
}
});
});
assert.sameValue(returnCallCount, 0);
{
const originalIter = {
return() {
return { value: 5, done: true };
},
};

const calls = [];
TemporalHelpers.observeMethod(calls, originalIter, "return", "originalIter");
const iter = TemporalHelpers.propertyBagObserver(calls, originalIter, "originalIter");

assert.throws(TypeError, function() {
WrapForValidIteratorPrototype.return.call(iter);
});
assert.compareArray(calls, []);
}

0 comments on commit 21273ca

Please sign in to comment.