diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Promise/reject | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Promise/reject')
17 files changed, 536 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Promise/reject/S25.4.4.4_A1.1_T1.js b/js/src/tests/test262/built-ins/Promise/reject/S25.4.4.4_A1.1_T1.js new file mode 100644 index 0000000000..999e0db577 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/S25.4.4.4_A1.1_T1.js @@ -0,0 +1,17 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Promise.reject +es6id: S25.4.4.4_A1.1_T1 +author: Sam Mikes +description: Promise.reject is a function +---*/ +assert.sameValue( + typeof Promise.reject, + "function", + 'The value of `typeof Promise.reject` is expected to be "function"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/S25.4.4.4_A2.1_T1.js b/js/src/tests/test262/built-ins/Promise/reject/S25.4.4.4_A2.1_T1.js new file mode 100644 index 0000000000..101f184caf --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/S25.4.4.4_A2.1_T1.js @@ -0,0 +1,28 @@ +// |reftest| async +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + [...] + 5. Let rejectResult be Call(promiseCapability.[[Reject]], undefined, «r»). + [...] + + 25.4.1.3.1 Promise Reject Functions + [...] + 6. Return RejectPromise(promise, reason). +es6id: 25.4.4.4 +author: Sam Mikes +description: Promise.reject creates a new settled promise +flags: [async] +---*/ + +var p = Promise.reject(3); + +assert(!!(p instanceof Promise), 'The value of !!(p instanceof Promise) is expected to be true'); + +p.then(function() { + throw new Test262Error("Promise should not be fulfilled."); +}, function(result) { + assert.sameValue(result, 3, 'The value of result is expected to be 3'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Promise/reject/S25.4.4.4_A3.1_T1.js b/js/src/tests/test262/built-ins/Promise/reject/S25.4.4.4_A3.1_T1.js new file mode 100644 index 0000000000..a3dfbbea03 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/S25.4.4.4_A3.1_T1.js @@ -0,0 +1,18 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Promise.reject +es6id: S25.4.4.4_A3.1_T1 +author: Sam Mikes +description: Promise.reject throws TypeError for bad 'this' +---*/ + +function ZeroArgConstructor() {} + +assert.throws(TypeError, function() { + Promise.reject.call(ZeroArgConstructor, 4); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/browser.js b/js/src/tests/test262/built-ins/Promise/reject/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/browser.js diff --git a/js/src/tests/test262/built-ins/Promise/reject/capability-executor-called-twice.js b/js/src/tests/test262/built-ins/Promise/reject/capability-executor-called-twice.js new file mode 100644 index 0000000000..17a661de34 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/capability-executor-called-twice.js @@ -0,0 +1,81 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 25.4.4.4 +description: > + Throws a TypeError if capabilities executor already called with non-undefined values. +info: | + Promise.reject ( r ) + + ... + 3. Let promiseCapability be NewPromiseCapability(C). + 4. ReturnIfAbrupt(promiseCapability). + ... + + 25.4.1.5.1 GetCapabilitiesExecutor Functions + ... + 3. If promiseCapability.[[Resolve]] is not undefined, throw a TypeError exception. + 4. If promiseCapability.[[Reject]] is not undefined, throw a TypeError exception. + 5. Set promiseCapability.[[Resolve]] to resolve. + 6. Set promiseCapability.[[Reject]] to reject. + ... +---*/ + +var checkPoint = ""; +Promise.reject.call(function(executor) { + checkPoint += "a"; + executor(); + checkPoint += "b"; + executor(function() {}, function() {}); + checkPoint += "c"; +}, {}); +assert.sameValue(checkPoint, "abc", "executor initially called with no arguments"); + +var checkPoint = ""; +Promise.reject.call(function(executor) { + checkPoint += "a"; + executor(undefined, undefined); + checkPoint += "b"; + executor(function() {}, function() {}); + checkPoint += "c"; +}, {}); +assert.sameValue(checkPoint, "abc", "executor initially called with (undefined, undefined)"); + +var checkPoint = ""; +assert.throws(TypeError, function() { + Promise.reject.call(function(executor) { + checkPoint += "a"; + executor(undefined, function() {}); + checkPoint += "b"; + executor(function() {}, function() {}); + checkPoint += "c"; + }, {}); +}, "executor initially called with (undefined, function)"); +assert.sameValue(checkPoint, "ab", "executor initially called with (undefined, function)"); + +var checkPoint = ""; +assert.throws(TypeError, function() { + Promise.reject.call(function(executor) { + checkPoint += "a"; + executor(function() {}, undefined); + checkPoint += "b"; + executor(function() {}, function() {}); + checkPoint += "c"; + }, {}); +}, "executor initially called with (function, undefined)"); +assert.sameValue(checkPoint, "ab", "executor initially called with (function, undefined)"); + +var checkPoint = ""; +assert.throws(TypeError, function() { + Promise.reject.call(function(executor) { + checkPoint += "a"; + executor("invalid value", 123); + checkPoint += "b"; + executor(function() {}, function() {}); + checkPoint += "c"; + }, {}); +}, "executor initially called with (String, Number)"); +assert.sameValue(checkPoint, "ab", "executor initially called with (String, Number)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/capability-executor-not-callable.js b/js/src/tests/test262/built-ins/Promise/reject/capability-executor-not-callable.js new file mode 100644 index 0000000000..0002838ef8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/capability-executor-not-callable.js @@ -0,0 +1,85 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 25.4.4.4 +description: > + Throws a TypeError if either resolve or reject capability is not callable. +info: | + Promise.reject ( r ) + + ... + 3. Let promiseCapability be NewPromiseCapability(C). + 4. ReturnIfAbrupt(promiseCapability). + ... + + 25.4.1.5 NewPromiseCapability ( C ) + ... + 4. Let executor be a new built-in function object as defined in GetCapabilitiesExecutor Functions (25.4.1.5.1). + 5. Set the [[Capability]] internal slot of executor to promiseCapability. + 6. Let promise be Construct(C, «executor»). + 7. ReturnIfAbrupt(promise). + 8. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception. + 9. If IsCallable(promiseCapability.[[Reject]]) is false, throw a TypeError exception. + ... +---*/ + +var checkPoint = ""; +assert.throws(TypeError, function() { + Promise.reject.call(function(executor) { + checkPoint += "a"; + }, {}); +}, "executor not called at all"); +assert.sameValue(checkPoint, "a", "executor not called at all"); + +var checkPoint = ""; +assert.throws(TypeError, function() { + Promise.reject.call(function(executor) { + checkPoint += "a"; + executor(); + checkPoint += "b"; + }, {}); +}, "executor called with no arguments"); +assert.sameValue(checkPoint, "ab", "executor called with no arguments"); + +var checkPoint = ""; +assert.throws(TypeError, function() { + Promise.reject.call(function(executor) { + checkPoint += "a"; + executor(undefined, undefined); + checkPoint += "b"; + }, {}); +}, "executor called with (undefined, undefined)"); +assert.sameValue(checkPoint, "ab", "executor called with (undefined, undefined)"); + +var checkPoint = ""; +assert.throws(TypeError, function() { + Promise.reject.call(function(executor) { + checkPoint += "a"; + executor(undefined, function() {}); + checkPoint += "b"; + }, {}); +}, "executor called with (undefined, function)"); +assert.sameValue(checkPoint, "ab", "executor called with (undefined, function)"); + +var checkPoint = ""; +assert.throws(TypeError, function() { + Promise.reject.call(function(executor) { + checkPoint += "a"; + executor(function() {}, undefined); + checkPoint += "b"; + }, {}); +}, "executor called with (function, undefined)"); +assert.sameValue(checkPoint, "ab", "executor called with (function, undefined)"); + +var checkPoint = ""; +assert.throws(TypeError, function() { + Promise.reject.call(function(executor) { + checkPoint += "a"; + executor(123, "invalid value"); + checkPoint += "b"; + }, {}); +}, "executor called with (Number, String)"); +assert.sameValue(checkPoint, "ab", "executor called with (Number, String)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/capability-invocation-error.js b/js/src/tests/test262/built-ins/Promise/reject/capability-invocation-error.js new file mode 100644 index 0000000000..2eaac3fac3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/capability-invocation-error.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Abrupt completion returned by "reject" capability +esid: sec-promise.reject +info: | + 1. Let C be the this value. + [...] + 3. Let promiseCapability be ? NewPromiseCapability(C). + 4. Perform ? Call(promiseCapability.[[Reject]], undefined, « r »). + + 25.4.1.5 NewPromiseCapability + [...] + 6. Let promise be Construct(C, «executor»). + 7. ReturnIfAbrupt(promise). +---*/ + +var P = function(executor) { + return new Promise(function() { + executor( + function() {}, + function() { + throw new Test262Error(); + } + ); + }); +}; + +assert.throws(Test262Error, function() { + Promise.reject.call(P); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/capability-invocation.js b/js/src/tests/test262/built-ins/Promise/reject/capability-invocation.js new file mode 100644 index 0000000000..c263608cf3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/capability-invocation.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Invocation of "reject" capability +esid: sec-promise.reject +info: | + 1. Let C be the this value. + [...] + 3. Let promiseCapability be ? NewPromiseCapability(C). + 4. Perform ? Call(promiseCapability.[[Reject]], undefined, « r »). + [...] + + 25.4.1.5 NewPromiseCapability + [...] + 6. Let promise be Construct(C, «executor»). + 7. ReturnIfAbrupt(promise). +---*/ + +var expectedThis = (function() { + return this; +})(); +var resolveCount = 0; +var thisValue, args; +var P = function(executor) { + return new Promise(function() { + executor( + function() { + resolveCount += 1; + }, + function() { + thisValue = this; + args = arguments; + } + ); + }); +}; + +Promise.reject.call(P, 24601); + +assert.sameValue(resolveCount, 0); + +assert.sameValue(thisValue, expectedThis); +assert.sameValue(typeof args, 'object'); +assert.sameValue(args.length, 1); +assert.sameValue(args[0], 24601); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/ctx-ctor-throws.js b/js/src/tests/test262/built-ins/Promise/reject/ctx-ctor-throws.js new file mode 100644 index 0000000000..85be5895f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/ctx-ctor-throws.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Promise.reject` invoked on a constructor value that throws an error +es6id: 25.4.4.4 +info: | + 1. Let C be the this value. + [...] + 3. Let promiseCapability be NewPromiseCapability(C). + 4. ReturnIfAbrupt(promiseCapability). + + 25.4.1.5 NewPromiseCapability + [...] + 6. Let promise be Construct(C, «executor»). + 7. ReturnIfAbrupt(promise). +---*/ + +var CustomPromise = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + Promise.reject.call(CustomPromise); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/ctx-ctor.js b/js/src/tests/test262/built-ins/Promise/reject/ctx-ctor.js new file mode 100644 index 0000000000..7b18f71152 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/ctx-ctor.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Promise.reject` invoked on a constructor value +es6id: 25.4.4.5 +info: | + 1. Let C be the this value. + [...] + 3. Let promiseCapability be NewPromiseCapability(C). + [...] + 7. Return promiseCapability.[[Promise]]. +features: [class] +---*/ + +var executor = null; +var callCount = 0; + +class SubPromise extends Promise { + constructor(a) { + super(a); + executor = a; + callCount += 1; + } +} + +var instance = Promise.reject.call(SubPromise); + +assert.sameValue(instance.constructor, SubPromise); +assert.sameValue(instance instanceof SubPromise, true); + +assert.sameValue(callCount, 1); +assert.sameValue(typeof executor, 'function'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/ctx-non-ctor.js b/js/src/tests/test262/built-ins/Promise/reject/ctx-non-ctor.js new file mode 100644 index 0000000000..7a2a41ce6b --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/ctx-non-ctor.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Promise.reject` invoked on a non-constructor value +es6id: 25.4.4.4 +info: | + [...] + 3. Let promiseCapability be NewPromiseCapability(C). + 4. ReturnIfAbrupt(promiseCapability). +---*/ + +assert.throws(TypeError, function() { + Promise.reject.call(eval); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/ctx-non-object.js b/js/src/tests/test262/built-ins/Promise/reject/ctx-non-object.js new file mode 100644 index 0000000000..16141bbd71 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/ctx-non-object.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `Promise.resolve` invoked on a non-object value +es6id: 25.4.4.4 +info: | + 1. Let C be the this value. + 2. If Type(C) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + Promise.reject.call(undefined, []); +}); + +assert.throws(TypeError, function() { + Promise.reject.call(null, []); +}); + +assert.throws(TypeError, function() { + Promise.reject.call(86, []); +}); + +assert.throws(TypeError, function() { + Promise.reject.call('string', []); +}); + +assert.throws(TypeError, function() { + Promise.reject.call(true, []); +}); + +assert.throws(TypeError, function() { + Promise.reject.call(Symbol(), []); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/length.js b/js/src/tests/test262/built-ins/Promise/reject/length.js new file mode 100644 index 0000000000..1773dfca57 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/length.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.4.4.4 +description: Promise.reject `length` property +info: | + ES6 Section 17: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Promise.reject.length, 1); + +verifyNotEnumerable(Promise.reject, 'length'); +verifyNotWritable(Promise.reject, 'length'); +verifyConfigurable(Promise.reject, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/name.js b/js/src/tests/test262/built-ins/Promise/reject/name.js new file mode 100644 index 0000000000..eb0e4c630f --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.4.4.4 +description: Promise.reject `name` property +info: | + ES6 Section 17: + + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. Unless otherwise specified, this value is the name that is given to + the function in this specification. + + [...] + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Promise.reject.name, 'reject'); + +verifyNotEnumerable(Promise.reject, 'name'); +verifyNotWritable(Promise.reject, 'name'); +verifyConfigurable(Promise.reject, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/not-a-constructor.js b/js/src/tests/test262/built-ins/Promise/reject/not-a-constructor.js new file mode 100644 index 0000000000..1fa8864edb --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Promise.reject does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(Promise.reject), false, 'isConstructor(Promise.reject) must return false'); + +assert.throws(TypeError, () => { + new Promise.reject(); +}, '`new Promise.reject()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/prop-desc.js b/js/src/tests/test262/built-ins/Promise/reject/prop-desc.js new file mode 100644 index 0000000000..d93864db99 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/prop-desc.js @@ -0,0 +1,21 @@ +// Copyright 2015 Jordan Harband. All rights reserved. +// See LICENSE for details. + +/*--- +es6id: 25.4.4.4_A1.2_T1 +author: Jordan Harband +description: Promise.reject property descriptor +info: | + ES6 Section 17 + + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Promise, 'reject'); +verifyWritable(Promise, 'reject'); +verifyConfigurable(Promise, 'reject'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/reject/shell.js b/js/src/tests/test262/built-ins/Promise/reject/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/reject/shell.js |