Add tests for the case of <iterator>.return in the iteration protocol being an object that's uncallable and compares equal to undefined#1287
Conversation
|
I believe we decided in #1184 that tests involving HTML Document Dot All Exotic Objects belong in the web platform tests, rather than here. |
|
The functionality under test here is: 1) the evaluation semantics of YieldExpression: yield* AssignmentExpression in step 5c(iii), and 2) IteratorClose's step 4. It seems strange to have tests of those steps not in test262. Looking through #1184, it seems the tests being contemplated were of how For additional context, SpiderMonkey tests have an |
|
There are some issues on these tests to be solved before they become good to land: While using a host defined api is fine, some predictability from the specs is still necessary:
This is what is known from the normative text in the specs. Plus the subsections:
There isn't anything saying in the specs this object is callable or not. I wonder what exactly we would be testing if we have a host defined api to return one of these objects that are non-callable. All we know from the specs is:
Now I want to make sure we really need to differentiate a The first test throws a TypeError on a var iter = {
[Symbol.iterator]() { return this; },
next() { return {}; },
return: $262.uncallableAndIsHTMLDDA(),
};
var outer = (function*() { yield* iter; })();
outer.next();Let's see the specs: https://tc39.github.io/ecma262/#sec-generator-function-definitions-runtime-semantics-evaluation For the second step, using a for-of loop, there is the IterationClose: What needs to be extracted here is whether the IsHTMLDDA object is callable or not. Because that seems the place returning the TypeError execution. The challenge for these tests is how do we detect the specific getmethod call is failing. This PR already shows that Test262 is missing coverage for this abrupt completion even on regular objects. on a search in the It seems that tests for other IteratorClose calls might be missing as well. So these would be cases like: var badIter = {
[Symbol.iterator]() { return this; },
next() { return {}; },
return: {}
};
var caught;
function* g() {
try {
yield * badIter;
} catch (err) {
caught = err.constructor;
}
}
var iter = g();
iter.next();
iter.return();
assert.sameValue(caught, TypeError);Same would go with for some calls to IteratorClose: var badIter = {
[Symbol.iterator]() { return this; },
next() { return {}; },
return: {}
};
// for-of
assert.throws(TypeError, function() {
for (var x of badIter) break;
});
// destructuring assignment
assert.throws(TypeError, function() {
var [x] = badIter;
});We need to make a case for that on IsHTMLDDA, but for that we would need to assert from the specs the object is not callable. The problem with assuming the host defined on Test262 would always return a non callable object wouldn't make much of a distinction for the coverage identified here. Which, btw, are you interested to send a PR for these too? |
|
In any case, even if I feel this is too much specific, I'm not into blocking anything, but we should make sure this goes to a proper folder where this tests will have a better identification. Would you mind moving these specific tests to a folder named |
|
It's silly, but The rough test idea could be applied to other properties on iterators, for sure. I didn't because it's not a bug we have and because I'm already short on time for this presumed simple fix in SpiderMonkey. :-( Generally we test only errors like this when we find buggy code, or in testing during implementation. IRC and other conversation suggests this should go in w-p-t, so I have web-platform-tests/wpt#7855 pending as well. I'd prefer a landing here because understanding these tests is wholly TC39's domain, but I'm not inclined to argue it strongly. |
It actually also reproduces in Chrome, so it's not just Firefox. (I didn't check other browsers.) So providing test coverage in test262 seems even more reasonable to me, because it's definitely a cross-implementation issue. :-) |
|
The tests are ES domain as they are checking for behavior on closing iterator. The object you're providing is a very specific one, but still worth of testing, as the specs predicts it. There are minor fixes to be done on the test structure (e.g. the features flag, etc) but the only thing I want to guarantee is to store them in an exclusive folder, as I mentioned before: This way should be easier to browser for specific IsHTMLDDA tests and prevent runs from exploding if they do not support DDA and haven't implemented any folder for this.
That's not different for most of us, I'll have at least a new issue open so we can keep track of this missing coverage. |
This can be done in eshost, so no hosts actually need to do anything :) |
|
@jswalden rwaldron/eshost@e535f86 is this sufficient? |
|
Better with the minor tweak in the comment I left on it, to be sure, but yes -- quite sufficient. |
|
@jswalden would you please confirm if you're planning to move the files to the annexB folder I mentioned above? I'm planning to merge when this is up. |
|
@leobalter Yeah, I'll move them. |
|
@jswalden I had one question here: rwaldron/eshost@e535f86 thx! |
… protocol, being an object that's uncallable and compares equal to `undefined`.
3eacab9 to
76c1a8f
Compare
This is generally very cheesy. But it happens that if you slot in
$262.uncallableAndIsHTMLDDA = () => document.allin SpiderMonkey, these tests fail right now, because we did a loose-equality check againstundefinedrather than a strict-equality check. So, it would be nice to have upstream testing of that in case other implementations are similarly buggy.Note that per the very peculiar requirements of
$262.uncallableAndIsHTMLDDA, hosts that don't supportdocument.allor anything stupid like it can just addto their support files to run these tests. The
[[IsHTMLDDA]]aspects could be omitted from the object returned by this function, and it wouldn't change the tests' behaviors.https://github.com/tc39/test262/blob/master/INTERPRETING.md currently suggests the version in https://github.com/tc39/test262/blob/master/package.json will be incremented for "substantive" changes. This might or might not be. If it is, let me know what I should bump it to -- I left it alone because I'm vaguely guessing the feature-guard is enough for hosts' ease of updating here.