From 76c1a8fa3a0c03a740b32329bd8a9231da8e3a99 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Mon, 16 Oct 2017 15:46:59 -0700 Subject: [PATCH] Add tests for the case of .return, as used in the iteration protocol, being an object that's uncallable and compares equal to `undefined`. --- INTERPRETING.md | 10 ++++++ features.txt | 8 +++++ ...n-emulates-undefined-throws-when-called.js | 31 +++++++++++++++++++ ...n-emulates-undefined-throws-when-called.js | 27 ++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 test/annexB/language/expressions/yield/star-iterable-return-emulates-undefined-throws-when-called.js create mode 100644 test/annexB/language/statements/for-of/iterator-close-return-emulates-undefined-throws-when-called.js diff --git a/INTERPRETING.md b/INTERPRETING.md index 20181314fd..7904eb7109 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 92cce17a1b..ce2e3b4595 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 0000000000..04aa29987a --- /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 .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: `.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 0000000000..a7fc382be4 --- /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 .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: `.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; +});