From aca10842a2b02184e1f88a899882c1d9389c42a8 Mon Sep 17 00:00:00 2001 From: chicoxyzzy Date: Wed, 27 Nov 2019 16:36:09 +0300 Subject: [PATCH] Add context tests --- test/built-ins/Promise/any/ctx-ctor-throws.js | 24 +++++++++++++ test/built-ins/Promise/any/ctx-ctor.js | 34 ++++++++++++++++++ test/built-ins/Promise/any/ctx-non-ctor.js | 20 +++++++++++ test/built-ins/Promise/any/ctx-non-object.js | 36 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 test/built-ins/Promise/any/ctx-ctor-throws.js create mode 100644 test/built-ins/Promise/any/ctx-ctor.js create mode 100644 test/built-ins/Promise/any/ctx-non-ctor.js create mode 100644 test/built-ins/Promise/any/ctx-non-object.js diff --git a/test/built-ins/Promise/any/ctx-ctor-throws.js b/test/built-ins/Promise/any/ctx-ctor-throws.js new file mode 100644 index 0000000000..b3e567acb5 --- /dev/null +++ b/test/built-ins/Promise/any/ctx-ctor-throws.js @@ -0,0 +1,24 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Promise.any invoked on a constructor value that throws an error +esid: sec-promise.any +info: | + 2. Let promiseCapability be ? NewPromiseCapability(C). + + NewPromiseCapability + + ... + 7. Let promise be ? Construct(C, « executor »). +features: [Promise.any] +---*/ + +var CustomPromise = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + Promise.any.call(CustomPromise); +}); diff --git a/test/built-ins/Promise/any/ctx-ctor.js b/test/built-ins/Promise/any/ctx-ctor.js new file mode 100644 index 0000000000..e9b9461656 --- /dev/null +++ b/test/built-ins/Promise/any/ctx-ctor.js @@ -0,0 +1,34 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Promise.any invoked on a constructor value +esid: sec-promise.any +info: | + 2. Let promiseCapability be ? NewPromiseCapability(C). + ... + 5. Let result be PerformPromiseany(iteratorRecord, C, promiseCapability). + ... + 7. Return Completion(result). +features: [Promise.any, class] +---*/ + +var executor = null; +var callCount = 0; + +class SubPromise extends Promise { + constructor(a) { + super(a); + executor = a; + callCount += 1; + } +} + +var instance = Promise.any.call(SubPromise, []); + +assert.sameValue(instance.constructor, SubPromise); +assert.sameValue(instance instanceof SubPromise, true); + +assert.sameValue(callCount, 1); +assert.sameValue(typeof executor, 'function'); diff --git a/test/built-ins/Promise/any/ctx-non-ctor.js b/test/built-ins/Promise/any/ctx-non-ctor.js new file mode 100644 index 0000000000..f9de14efcd --- /dev/null +++ b/test/built-ins/Promise/any/ctx-non-ctor.js @@ -0,0 +1,20 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Promise.any invoked on a non-constructor value +esid: sec-promise.any +info: | + ... + 2. Let promiseCapability be ? NewPromiseCapability(C). + + NewPromiseCapability ( C ) + + 1. If IsConstructor(C) is false, throw a TypeError exception. +features: [Promise.any] +---*/ + +assert.throws(TypeError, function() { + Promise.any.call(eval); +}); diff --git a/test/built-ins/Promise/any/ctx-non-object.js b/test/built-ins/Promise/any/ctx-non-object.js new file mode 100644 index 0000000000..1031e25728 --- /dev/null +++ b/test/built-ins/Promise/any/ctx-non-object.js @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Sergey Rubanov. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Promise.any invoked on a non-object value +esid: sec-promise.any +info: | + 1. Let C be the this value. + 2. If Type(C) is not Object, throw a TypeError exception. +features: [Promise.any, Symbol] +---*/ + +assert.throws(TypeError, function() { + Promise.any.call(undefined, []); +}); + +assert.throws(TypeError, function() { + Promise.any.call(null, []); +}); + +assert.throws(TypeError, function() { + Promise.any.call(86, []); +}); + +assert.throws(TypeError, function() { + Promise.any.call('string', []); +}); + +assert.throws(TypeError, function() { + Promise.any.call(true, []); +}); + +assert.throws(TypeError, function() { + Promise.any.call(Symbol(), []); +});