mirror of https://github.com/tc39/test262.git
Add tests for the case of <iterator>.return, as used in the iteration protocol, being an object that's uncallable and compares equal to `undefined`.
This commit is contained in:
parent
d36a1777b4
commit
76c1a8fa3a
|
@ -64,6 +64,16 @@ properties of the global scope prior to test execution.
|
||||||
6. Return Completion(status).
|
6. Return Completion(status).
|
||||||
|
|
||||||
- **`global`** - a reference to the global object on which `$262` was initially defined
|
- **`global`** - a reference to the global object on which `$262` was initially defined
|
||||||
|
- **`uncallableAndIsHTMLDDA`** - a function that returns an object *`obj`* for
|
||||||
|
which [Call](https://tc39.github.io/ecma262/#sec-call)(*`obj`*, *any value*, «»)
|
||||||
|
throws a `TypeError`. (The value of [IsCallable]()(*`obj`*) is unspecified:
|
||||||
|
a callable *`obj`* that throws a `TypeError` or an uncallable *`obj`* works
|
||||||
|
equally well.) In hosts supporting the
|
||||||
|
[IsHTMLDDA](https://tc39.github.io/ecma262/#sec-IsHTMLDDA-internal-slot)
|
||||||
|
internal slot, *`obj`* must also have such a slot. (These highly specific
|
||||||
|
behaviors are entirely motivated by the very few tests that use this. Read
|
||||||
|
them for an explanation.) Tests that use this function should be marked as
|
||||||
|
using the `uncallableAndIsHTMLDDA` feature.
|
||||||
- **`agent`** - an ordinary object with the following properties:
|
- **`agent`** - an ordinary object with the following properties:
|
||||||
- **`start`** - a function that takes a script source string and runs
|
- **`start`** - a function that takes a script source string and runs
|
||||||
the script in a concurrent agent. Will block until that agent is
|
the script in a concurrent agent. Will block until that agent is
|
||||||
|
|
|
@ -117,3 +117,11 @@ u180e
|
||||||
Uint8Array
|
Uint8Array
|
||||||
WeakMap
|
WeakMap
|
||||||
WeakSet
|
WeakSet
|
||||||
|
|
||||||
|
# Test-harness features requiring host environment/test runner support
|
||||||
|
#
|
||||||
|
# The rare cases where testing language functionality requires non-standard
|
||||||
|
# language features, exposed through global-environment functions on the $262
|
||||||
|
# object, go here.
|
||||||
|
|
||||||
|
uncallableAndIsHTMLDDA
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
es6id: sec-generator-function-definitions-runtime-semantics-evaluation
|
||||||
|
description: >
|
||||||
|
If <iterator>.return is an object emulating `undefined` (e.g. `document.all`
|
||||||
|
in browsers), it shouldn't be treated as if it were actually `undefined` by
|
||||||
|
the yield* operator.
|
||||||
|
features: [generators, uncallableAndIsHTMLDDA]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var iter = {
|
||||||
|
[Symbol.iterator]() { return this; },
|
||||||
|
next() { return {}; },
|
||||||
|
return: $262.uncallableAndIsHTMLDDA(),
|
||||||
|
};
|
||||||
|
|
||||||
|
var outer = (function*() { yield* iter; })();
|
||||||
|
|
||||||
|
outer.next();
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
// This code is expected to throw a TypeError because `iter.return` throws a
|
||||||
|
// TypeError when invoked with `iter` as `this` and no arguments provided.
|
||||||
|
// It's irrelevant that in hosts that support the [[IsHTMLDDA]] internal slot,
|
||||||
|
// this object has that slot: `<iterator>.return` behavior is skipped only if
|
||||||
|
// that property is exactly the value `undefined`, not a value loosely equal
|
||||||
|
// to it.
|
||||||
|
outer.return();
|
||||||
|
});
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
es6id: sec-iteratorclose
|
||||||
|
description: >
|
||||||
|
If <iterator>.return is an object emulating `undefined` (e.g. `document.all`
|
||||||
|
in browsers), it shouldn't be treated as if it were actually `undefined`.
|
||||||
|
features: [generators, uncallableAndIsHTMLDDA]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var iter = {
|
||||||
|
[Symbol.iterator]() { return this; },
|
||||||
|
next() { return {}; },
|
||||||
|
return: $262.uncallableAndIsHTMLDDA(),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
// This code is expected to throw a TypeError because `iter.return` throws a
|
||||||
|
// TypeError when invoked with `iter` as `this` and no arguments provided.
|
||||||
|
// It's irrelevant that in hosts that support the [[IsHTMLDDA]] internal slot,
|
||||||
|
// this object has that slot: `<iterator>.return` behavior is skipped only if
|
||||||
|
// that property is exactly the value `undefined`, not a value loosely equal
|
||||||
|
// to it.
|
||||||
|
for (var x of iter)
|
||||||
|
break;
|
||||||
|
});
|
Loading…
Reference in New Issue