summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Walden <jwalden@mit.edu>2017-10-16 15:46:59 -0700
committerJeff Walden <jwalden@mit.edu>2017-10-17 12:21:43 -0700
commit76c1a8fa3a0c03a740b32329bd8a9231da8e3a99 (patch)
tree8b44be62cd616563955b2cb28507610e1bc36144
parentd36a1777b4a713627c9fb9bc571c28b7fd2a72c5 (diff)
downloadqtdeclarative-testsuites-76c1a8fa3a0c03a740b32329bd8a9231da8e3a99.tar.gz
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`.
-rw-r--r--INTERPRETING.md10
-rw-r--r--features.txt8
-rw-r--r--test/annexB/language/expressions/yield/star-iterable-return-emulates-undefined-throws-when-called.js31
-rw-r--r--test/annexB/language/statements/for-of/iterator-close-return-emulates-undefined-throws-when-called.js27
4 files changed, 76 insertions, 0 deletions
diff --git a/INTERPRETING.md b/INTERPRETING.md
index 20181314f..7904eb710 100644
--- a/INTERPRETING.md
+++ b/INTERPRETING.md
@@ -64,6 +64,16 @@ properties of the global scope prior to test execution.
6. Return Completion(status).
- **`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:
- **`start`** - a function that takes a script source string and runs
the script in a concurrent agent. Will block until that agent is
diff --git a/features.txt b/features.txt
index 92cce17a1..ce2e3b459 100644
--- a/features.txt
+++ b/features.txt
@@ -117,3 +117,11 @@ u180e
Uint8Array
WeakMap
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
diff --git a/test/annexB/language/expressions/yield/star-iterable-return-emulates-undefined-throws-when-called.js b/test/annexB/language/expressions/yield/star-iterable-return-emulates-undefined-throws-when-called.js
new file mode 100644
index 000000000..04aa29987
--- /dev/null
+++ b/test/annexB/language/expressions/yield/star-iterable-return-emulates-undefined-throws-when-called.js
@@ -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();
+});
diff --git a/test/annexB/language/statements/for-of/iterator-close-return-emulates-undefined-throws-when-called.js b/test/annexB/language/statements/for-of/iterator-close-return-emulates-undefined-throws-when-called.js
new file mode 100644
index 000000000..a7fc382be
--- /dev/null
+++ b/test/annexB/language/statements/for-of/iterator-close-return-emulates-undefined-throws-when-called.js
@@ -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;
+});