From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../built-ins/Promise/resolve/S25.4.4.5_A1.1_T1.js | 17 +++++ .../built-ins/Promise/resolve/S25.4.4.5_A2.1_T1.js | 15 ++++ .../built-ins/Promise/resolve/S25.4.4.5_A2.2_T1.js | 25 +++++++ .../built-ins/Promise/resolve/S25.4.4.5_A2.3_T1.js | 27 +++++++ .../built-ins/Promise/resolve/S25.4.4.5_A3.1_T1.js | 56 ++++++++++++++ .../built-ins/Promise/resolve/S25.4.4.5_A4.1_T1.js | 25 +++++++ .../S25.Promise_resolve_foreign_thenable_1.js | 24 ++++++ .../S25.Promise_resolve_foreign_thenable_2.js | 46 ++++++++++++ .../built-ins/Promise/resolve/arg-non-thenable.js | 31 ++++++++ .../built-ins/Promise/resolve/arg-poisoned-then.js | 37 ++++++++++ .../built-ins/Promise/resolve/arg-uniq-ctor.js | 29 ++++++++ .../test262/built-ins/Promise/resolve/browser.js | 0 .../resolve/capability-executor-called-twice.js | 81 +++++++++++++++++++++ .../resolve/capability-executor-not-callable.js | 85 ++++++++++++++++++++++ .../Promise/resolve/capability-invocation-error.js | 33 +++++++++ .../resolve/context-non-object-with-promise.js | 50 +++++++++++++ .../built-ins/Promise/resolve/ctx-ctor-throws.js | 28 +++++++ .../test262/built-ins/Promise/resolve/ctx-ctor.js | 36 +++++++++ .../built-ins/Promise/resolve/ctx-non-ctor.js | 18 +++++ .../built-ins/Promise/resolve/ctx-non-object.js | 38 ++++++++++ .../test262/built-ins/Promise/resolve/length.js | 27 +++++++ .../test262/built-ins/Promise/resolve/name.js | 28 +++++++ .../built-ins/Promise/resolve/not-a-constructor.js | 31 ++++++++ .../test262/built-ins/Promise/resolve/prop-desc.js | 21 ++++++ .../resolve/resolve-from-promise-capability.js | 42 +++++++++++ .../built-ins/Promise/resolve/resolve-non-obj.js | 29 ++++++++ .../Promise/resolve/resolve-non-thenable.js | 35 +++++++++ .../Promise/resolve/resolve-poisoned-then.js | 38 ++++++++++ .../Promise/resolve/resolve-prms-cstm-then.js | 44 +++++++++++ .../built-ins/Promise/resolve/resolve-self.js | 48 ++++++++++++ .../built-ins/Promise/resolve/resolve-thenable.js | 42 +++++++++++ .../test262/built-ins/Promise/resolve/shell.js | 0 32 files changed, 1086 insertions(+) create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A1.1_T1.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.1_T1.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.2_T1.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.3_T1.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A3.1_T1.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A4.1_T1.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_1.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_2.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/arg-non-thenable.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/arg-poisoned-then.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/arg-uniq-ctor.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/browser.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/capability-executor-called-twice.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/capability-executor-not-callable.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/capability-invocation-error.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/context-non-object-with-promise.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/ctx-ctor-throws.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/ctx-ctor.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/ctx-non-ctor.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/ctx-non-object.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/length.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/name.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/resolve-from-promise-capability.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/resolve-non-obj.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/resolve-non-thenable.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/resolve-poisoned-then.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/resolve-prms-cstm-then.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/resolve-self.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/resolve-thenable.js create mode 100644 js/src/tests/test262/built-ins/Promise/resolve/shell.js (limited to 'js/src/tests/test262/built-ins/Promise/resolve') diff --git a/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A1.1_T1.js b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A1.1_T1.js new file mode 100644 index 0000000000..ba9e815a66 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A1.1_T1.js @@ -0,0 +1,17 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Promise.resolve +es6id: S25.4.4.5_A1.1_T1 +author: Sam Mikes +description: Promise.resolve is a function +---*/ +assert.sameValue( + typeof Promise.resolve, + "function", + 'The value of `typeof Promise.resolve` is expected to be "function"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.1_T1.js b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.1_T1.js new file mode 100644 index 0000000000..4277dcbbd5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.1_T1.js @@ -0,0 +1,15 @@ +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +es6id: S25.4.4.5_A2.1_T1 +author: Sam Mikes +description: Promise.resolve passes through a promise w/ same Constructor +---*/ + +var p1 = Promise.resolve(1), + p2 = Promise.resolve(p1); + +assert.sameValue(p1, p2, 'The value of p1 is expected to equal the value of p2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.2_T1.js b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.2_T1.js new file mode 100644 index 0000000000..1445d3a242 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.2_T1.js @@ -0,0 +1,25 @@ +// |reftest| async +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +es6id: S25.4.4.5_A2.2_T1 +author: Sam Mikes +description: Promise.resolve passes through an unsettled promise w/ same Constructor +flags: [async] +---*/ + +var resolveP1, + p1 = new Promise(function(resolve) { + resolveP1 = resolve; + }), + p2 = Promise.resolve(p1), + arg = {}; + +assert.sameValue(p1, p2, 'The value of p1 is expected to equal the value of p2'); + +p2.then(function(result) { + assert.sameValue(result, arg, 'The value of result is expected to equal the value of arg'); +}).then($DONE, $DONE); + +resolveP1(arg); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.3_T1.js b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.3_T1.js new file mode 100644 index 0000000000..e028c21cba --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A2.3_T1.js @@ -0,0 +1,27 @@ +// |reftest| async +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +es6id: S25.4.4.5_A2.3_T1 +author: Sam Mikes +description: Promise.resolve passes through an unsettled promise w/ same Constructor +flags: [async] +---*/ + +var rejectP1, + p1 = new Promise(function(resolve, reject) { + rejectP1 = reject; + }), + p2 = Promise.resolve(p1), + arg = {}; + +assert.sameValue(p1, p2, 'The value of p1 is expected to equal the value of p2'); + +p2.then(function() { + throw new Test262Error("Expected p2 to be rejected, not fulfilled."); +}, function(result) { + assert.sameValue(result, arg, 'The value of result is expected to equal the value of arg'); +}).then($DONE, $DONE); + +rejectP1(arg); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A3.1_T1.js b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A3.1_T1.js new file mode 100644 index 0000000000..78b95b93a7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A3.1_T1.js @@ -0,0 +1,56 @@ +// |reftest| async +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Promise.resolve +es6id: S25.4.4.5_A3.1_T1 +author: Sam Mikes +description: Promise.resolve delegates to foreign thenable +includes: [promiseHelper.js] +flags: [async] +---*/ + +var sequence = []; + +var thenable = { + then: function(onResolve, onReject) { + sequence.push(3); + assert.sameValue(sequence.length, 3); + checkSequence(sequence, "thenable.then called"); + + assert.sameValue(this, thenable); + + onResolve('resolved'); + + sequence.push(4); + assert.sameValue(sequence.length, 4); + checkSequence(sequence, "after resolved"); + + throw new Error('interrupt flow'); + + sequence.push(4); + assert.sameValue(sequence.length, 4); + checkSequence(sequence, "duplicate sequence point not pushed"); + } +}; + +sequence.push(1); +assert.sameValue(sequence.length, 1); +checkSequence(sequence, "no async calls yet"); + +var p1 = Promise.resolve(thenable); + +sequence.push(2); +assert.sameValue(sequence.length, 2); +checkSequence(sequence, "thenable.then queued but not yet called"); + +p1.then(function(q) { + sequence.push(5); + assert.sameValue(sequence.length, 5); + checkSequence(sequence, "all done"); + + assert.sameValue(q, 'resolved'); + +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A4.1_T1.js b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A4.1_T1.js new file mode 100644 index 0000000000..25b8acf3a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/S25.4.4.5_A4.1_T1.js @@ -0,0 +1,25 @@ +// |reftest| async +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Section 25.4.1.4.2 +es6id: S25.4.4.5_A3.1_T1 +author: Sam Mikes +description: self-resolved Promise throws TypeError +flags: [async] +---*/ + +var resolveP, + p = new Promise(function(resolve) { + resolveP = resolve; + }); + +resolveP(p); + +p.then(function() { + throw new Test262Error("Should not fulfill: should reject with TypeError."); +}, function(err) { + assert(!!(err instanceof TypeError), 'The value of !!(err instanceof TypeError) is expected to be true'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_1.js b/js/src/tests/test262/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_1.js new file mode 100644 index 0000000000..629b94b509 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_1.js @@ -0,0 +1,24 @@ +// |reftest| async +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Promise.resolve +es6id: S25.4.4.5 +author: Sam Mikes +description: Promise.resolve delegates to foreign thenable +flags: [async] +---*/ + +var thenable = { + then: function(onResolve, onReject) { + return onResolve('resolved'); + } +}; + +var p = Promise.resolve(thenable); + +p.then(function(r) { + assert.sameValue(r, 'resolved'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_2.js b/js/src/tests/test262/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_2.js new file mode 100644 index 0000000000..bc748bf8fe --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_2.js @@ -0,0 +1,46 @@ +// |reftest| async +// Copyright 2014 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Promise.resolve +es6id: S25.4.4.5 +author: Sam Mikes +description: Promise.resolve delegates to foreign thenable +includes: [promiseHelper.js] +flags: [async] +---*/ + +var sequence = []; + +var thenable = { + then: function(onResolve, onReject) { + + sequence.push(3); + assert.sameValue(sequence.length, 3); + checkSequence(sequence, "thenable.then called"); + + assert.sameValue(this, thenable, "thenable.then called with `thenable` as `this`"); + + return onResolve('resolved'); + } +}; + +sequence.push(1); +assert.sameValue(sequence.length, 1); +checkSequence(sequence, "no async calls yet"); + +var p = Promise.resolve(thenable); + +sequence.push(2); +assert.sameValue(sequence.length, 2); +checkSequence(sequence, "thenable.then queued but not yet called"); + +p.then(function(r) { + sequence.push(4); + assert.sameValue(sequence.length, 4); + checkSequence(sequence, "all done"); + + assert.sameValue(r, 'resolved'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/arg-non-thenable.js b/js/src/tests/test262/built-ins/Promise/resolve/arg-non-thenable.js new file mode 100644 index 0000000000..1f941e050b --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/arg-non-thenable.js @@ -0,0 +1,31 @@ +// |reftest| async +// 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 with an object whose `then` property is not callable +es6id: 25.4.4.5 +info: | + 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, + «x»). + + [...] + + 25.4.1.3.2 Promise Resolve Functions + + 11. If IsCallable(thenAction) is false, then + a. Return FulfillPromise(promise, resolution). + 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, + «promise, resolution, thenAction») + 13. Return undefined. +flags: [async] +---*/ + +var nonThenable = { + then: null +}; + +Promise.resolve(nonThenable).then(function(value) { + assert.sameValue(value, nonThenable); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/arg-poisoned-then.js b/js/src/tests/test262/built-ins/Promise/resolve/arg-poisoned-then.js new file mode 100644 index 0000000000..6adc9372a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/arg-poisoned-then.js @@ -0,0 +1,37 @@ +// |reftest| async +// 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 with an object with a "poisoned" `then` property +es6id: 25.4.4.5 +info: | + 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, + «x»). + + [...] + + 25.4.1.3.2 Promise Resolve Functions + + 8. Let then be Get(resolution, "then"). + 9. If then is an abrupt completion, then + a. Return RejectPromise(promise, then.[[value]]). +flags: [async] +---*/ + +var poisonedThen = {}; +var err = new Test262Error(); +Object.defineProperty(poisonedThen, 'then', { + get: function() { + throw err; + } +}); + +Promise.resolve(poisonedThen).then(function() { + throw new Test262Error( + 'Promise should be rejected when retrieving `then` property throws an error' + ); +}, function(reason) { + assert.sameValue(reason, err); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/arg-uniq-ctor.js b/js/src/tests/test262/built-ins/Promise/resolve/arg-uniq-ctor.js new file mode 100644 index 0000000000..d3f268f0a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/arg-uniq-ctor.js @@ -0,0 +1,29 @@ +// 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 with a Promise with a unique constructor +es6id: 25.4.4.5 +info: | + 1. Let C be the this value. + [...] + 3. If IsPromise(x) is true, + a. Let xConstructor be Get(x, "constructor"). + b. ReturnIfAbrupt(xConstructor). + c. If SameValue(xConstructor, C) is true, return x. + 4. Let promiseCapability be NewPromiseCapability(C). + [...] + 8. Return promiseCapability.[[Promise]]. +---*/ + +var promise1 = new Promise(function() {}); +var promise2; + +promise1.constructor = null; + +promise2 = Promise.resolve(promise1); + +assert.sameValue(promise1 === promise2, false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/browser.js b/js/src/tests/test262/built-ins/Promise/resolve/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/Promise/resolve/capability-executor-called-twice.js b/js/src/tests/test262/built-ins/Promise/resolve/capability-executor-called-twice.js new file mode 100644 index 0000000000..3a5375dd79 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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.5 +description: > + Throws a TypeError if capabilities executor already called with non-undefined values. +info: | + Promise.resolve ( x ) + + ... + 4. Let promiseCapability be NewPromiseCapability(C). + 5. 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.resolve.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.resolve.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.resolve.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.resolve.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.resolve.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/resolve/capability-executor-not-callable.js b/js/src/tests/test262/built-ins/Promise/resolve/capability-executor-not-callable.js new file mode 100644 index 0000000000..09ed28476b --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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.5 +description: > + Throws a TypeError if either resolve or reject capability is not callable. +info: | + Promise.resolve ( x ) + + ... + 4. Let promiseCapability be NewPromiseCapability(C). + 5. 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.resolve.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.resolve.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.resolve.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.resolve.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.resolve.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.resolve.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/resolve/capability-invocation-error.js b/js/src/tests/test262/built-ins/Promise/resolve/capability-invocation-error.js new file mode 100644 index 0000000000..6302336b1c --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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 "resolve" capability +esid: sec-promise.resolve +info: | + 1. Let C be the this value. + [...] + 4. Let promiseCapability be ? NewPromiseCapability(C). + 5. Perform ? Call(promiseCapability.[[Resolve]], undefined, « x »). + + 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() { + throw new Test262Error(); + }, + function() {} + ); + }); +}; + +assert.throws(Test262Error, function() { + Promise.resolve.call(P); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/context-non-object-with-promise.js b/js/src/tests/test262/built-ins/Promise/resolve/context-non-object-with-promise.js new file mode 100644 index 0000000000..be4934f14e --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/context-non-object-with-promise.js @@ -0,0 +1,50 @@ +// 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.5 +description: > + Throws a TypeError if `this` is not an Object. +info: | + Promise.resolve ( x ) + + 1. Let C be the this value. + 2. If Type(C) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var promise = new Promise(function() {}); + +promise.constructor = undefined; +assert.throws(TypeError, function() { + Promise.resolve.call(undefined, promise); +}, "`this` value is undefined"); + +promise.constructor = null; +assert.throws(TypeError, function() { + Promise.resolve.call(null, promise); +}, "`this` value is null"); + +promise.constructor = true; +assert.throws(TypeError, function() { + Promise.resolve.call(true, promise); +}, "`this` value is a Boolean"); + +promise.constructor = 1; +assert.throws(TypeError, function() { + Promise.resolve.call(1, promise); +}, "`this` value is a Number"); + +promise.constructor = ""; +assert.throws(TypeError, function() { + Promise.resolve.call("", promise); +}, "`this` value is a String"); + +var symbol = Symbol(); +promise.constructor = symbol; +assert.throws(TypeError, function() { + Promise.resolve.call(symbol, promise); +}, "`this` value is a Symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/ctx-ctor-throws.js b/js/src/tests/test262/built-ins/Promise/resolve/ctx-ctor-throws.js new file mode 100644 index 0000000000..f73047169d --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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.resolve` invoked on a constructor value that throws an error +es6id: 25.4.4.5 +info: | + 1. Let C be the this value. + [...] + 4. Let promiseCapability be NewPromiseCapability(C). + 5. 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.resolve.call(CustomPromise); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/ctx-ctor.js b/js/src/tests/test262/built-ins/Promise/resolve/ctx-ctor.js new file mode 100644 index 0000000000..ea39cb7559 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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.resolve` invoked on a constructor value +es6id: 25.4.4.5 +info: | + 1. Let C be the this value. + [...] + 4. Let promiseCapability be NewPromiseCapability(C). + [...] + 8. 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.resolve.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/resolve/ctx-non-ctor.js b/js/src/tests/test262/built-ins/Promise/resolve/ctx-non-ctor.js new file mode 100644 index 0000000000..03bfe89783 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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.resolve` invoked on a non-constructor value +es6id: 25.4.4.5 +info: | + [...] + 4. Let promiseCapability be NewPromiseCapability(C). + 5. ReturnIfAbrupt(promiseCapability). +---*/ + +assert.throws(TypeError, function() { + Promise.resolve.call(eval); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/ctx-non-object.js b/js/src/tests/test262/built-ins/Promise/resolve/ctx-non-object.js new file mode 100644 index 0000000000..9f7b8f9e7e --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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.5 +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.resolve.call(undefined, []); +}); + +assert.throws(TypeError, function() { + Promise.resolve.call(null, []); +}); + +assert.throws(TypeError, function() { + Promise.resolve.call(86, []); +}); + +assert.throws(TypeError, function() { + Promise.resolve.call('string', []); +}); + +assert.throws(TypeError, function() { + Promise.resolve.call(true, []); +}); + +assert.throws(TypeError, function() { + Promise.resolve.call(Symbol(), []); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/length.js b/js/src/tests/test262/built-ins/Promise/resolve/length.js new file mode 100644 index 0000000000..a73283a4b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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.5 +description: Promise.resolve `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.resolve.length, 1); + +verifyNotEnumerable(Promise.resolve, 'length'); +verifyNotWritable(Promise.resolve, 'length'); +verifyConfigurable(Promise.resolve, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/name.js b/js/src/tests/test262/built-ins/Promise/resolve/name.js new file mode 100644 index 0000000000..b9644562b6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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.5 +description: Promise.resolve `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.resolve.name, 'resolve'); + +verifyNotEnumerable(Promise.resolve, 'name'); +verifyNotWritable(Promise.resolve, 'name'); +verifyConfigurable(Promise.resolve, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/not-a-constructor.js b/js/src/tests/test262/built-ins/Promise/resolve/not-a-constructor.js new file mode 100644 index 0000000000..e455743938 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/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.resolve 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.resolve), false, 'isConstructor(Promise.resolve) must return false'); + +assert.throws(TypeError, () => { + new Promise.resolve(); +}, '`new Promise.resolve()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/prop-desc.js b/js/src/tests/test262/built-ins/Promise/resolve/prop-desc.js new file mode 100644 index 0000000000..ecbf48f185 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/prop-desc.js @@ -0,0 +1,21 @@ +// Copyright 2015 Jordan Harband. All rights reserved. +// See LICENSE for details. + +/*--- +es6id: 25.4.4.5_A1.2_T1 +author: Jordan Harband +description: Promise.resolve should be non-enumerable +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, 'resolve'); +verifyWritable(Promise, 'resolve'); +verifyConfigurable(Promise, 'resolve'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/resolve-from-promise-capability.js b/js/src/tests/test262/built-ins/Promise/resolve/resolve-from-promise-capability.js new file mode 100644 index 0000000000..910f3791e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/resolve-from-promise-capability.js @@ -0,0 +1,42 @@ +// 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.5 +description: > + Resolve function is called after Promise constructor returns. +info: | + Promise.resolve ( x ) + + ... + 4. Let promiseCapability be NewPromiseCapability(C). + 5. ReturnIfAbrupt(promiseCapability). + 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, «x»). + 7. ReturnIfAbrupt(resolveResult). + ... +---*/ + +var expectedThisValue = (function() { + return this; +}()); +var callCount = 0; +var object = {}; +var thisValue, args; + +Promise.resolve.call(function(executor) { + function resolve(v) { + callCount += 1; + thisValue = this; + args = arguments; + } + executor(resolve, Test262Error.thrower); + assert.sameValue(callCount, 0, "callCount before returning from constructor"); +}, object); + +assert.sameValue(callCount, 1, "callCount after call to resolve()"); +assert.sameValue(typeof args, "object"); +assert.sameValue(args.length, 1); +assert.sameValue(args[0], object); +assert.sameValue(thisValue, expectedThisValue); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/resolve-non-obj.js b/js/src/tests/test262/built-ins/Promise/resolve/resolve-non-obj.js new file mode 100644 index 0000000000..a26ef53ca9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/resolve-non-obj.js @@ -0,0 +1,29 @@ +// |reftest| async +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Resolving with a non-object value +es6id: 25.4.4.5 +info: | + [...] + 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, + «x»). + [...] + + 25.4.1.3.2 Promise Resolve Functions + [...] + 7. If Type(resolution) is not Object, then + a. Return FulfillPromise(promise, resolution). +flags: [async] +---*/ + +Promise.resolve(23).then(function(value) { + if (value !== 23) { + $DONE('The promise should be fulfilled with the provided value.'); + return; + } + + $DONE(); +}, function() { + $DONE('The promise should not be rejected.'); +}); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/resolve-non-thenable.js b/js/src/tests/test262/built-ins/Promise/resolve/resolve-non-thenable.js new file mode 100644 index 0000000000..0ed1dd2541 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/resolve-non-thenable.js @@ -0,0 +1,35 @@ +// |reftest| async +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Resolving with a non-thenable object value +es6id: 25.4.4.5 +info: | + [...] + 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, + «x»). + [...] + + 25.4.1.3.2 Promise Resolve Functions + [...] + 8. Let then be Get(resolution, "then"). + 9. If then is an abrupt completion, then + [...] + 10. Let thenAction be then.[[value]]. + 11. If IsCallable(thenAction) is false, then + a. Return FulfillPromise(promise, resolution). +flags: [async] +---*/ + +var value = {}; + +Promise.resolve(value).then(function(value) { + if (value !== value) { + $DONE('The promise should be fulfilled with the provided value.'); + return; + } + + $DONE(); +}, function() { + $DONE('The promise should not be rejected.'); +}); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/resolve-poisoned-then.js b/js/src/tests/test262/built-ins/Promise/resolve/resolve-poisoned-then.js new file mode 100644 index 0000000000..330c890b42 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/resolve-poisoned-then.js @@ -0,0 +1,38 @@ +// |reftest| async +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Resolving with an object with a "poisoned" then property +es6id: 25.4.4.5 +info: | + [...] + 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, + «x»). + [...] + + 25.4.1.3.2 Promise Resolve Functions + [...] + 8. Let then be Get(resolution, "then"). + 9. If then is an abrupt completion, then + a. Return RejectPromise(promise, then.[[value]]). +flags: [async] +---*/ + +var value = {}; +var resolve; +var poisonedThen = Object.defineProperty({}, 'then', { + get: function() { + throw value; + } +}); + +Promise.resolve(poisonedThen).then(function() { + $DONE('The promise should not be fulfilled.'); +}, function(val) { + if (val !== value) { + $DONE('The promise should be rejected with the provided value.'); + return; + } + + $DONE(); +}); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/resolve-prms-cstm-then.js b/js/src/tests/test262/built-ins/Promise/resolve/resolve-prms-cstm-then.js new file mode 100644 index 0000000000..fe95c71f84 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/resolve-prms-cstm-then.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Resolving with a resolved Promise instance whose `then` method has been overridden +es6id: 25.4.4.5 +info: | + [...] + 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, + «x»). + [...] + + 25.4.1.3.2 Promise Resolve Functions + [...] + 8. Let then be Get(resolution, "then"). + 9. If then is an abrupt completion, then + [...] + 10. Let thenAction be then.[[value]]. + 11. If IsCallable(thenAction) is false, then + [...] + 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, + «promise, resolution, thenAction») +---*/ + +var value = {}; +var rejectCallCount = 0; +var thenable = new Promise(function(resolve) { + resolve(); +}); +var resolvedValue; + +thenable.then = function(resolve) { + resolve(value); +}; + +Promise.resolve(thenable).then(function(val) { + resolvedValue = val; +}, function() { + rejectCallCount += 1; +}); + +assert.sameValue(resolvedValue, value); +assert.sameValue(rejectCallCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/resolve-self.js b/js/src/tests/test262/built-ins/Promise/resolve/resolve-self.js new file mode 100644 index 0000000000..03d14879eb --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/resolve-self.js @@ -0,0 +1,48 @@ +// |reftest| async +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Resolving with a reference to the promise itself +es6id: 25.4.4.5 +info: | + 1. Let C be the this value. + [...] + 4. Let promiseCapability be NewPromiseCapability(C). + [...] + 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, + «x»). + [...] + + 25.4.1.3.2 Promise Resolve Functions + [...] + 6. If SameValue(resolution, promise) is true, then + a. Let selfResolutionError be a newly created TypeError object. + b. Return RejectPromise(promise, selfResolutionError). +flags: [async] +---*/ + +var resolve, reject; +var promise = new Promise(function(_resolve, _reject) { + resolve = _resolve; + reject = _reject; +}); +var P = function(executor) { + executor(resolve, reject); + return promise; +}; + +Promise.resolve.call(P, promise) + .then(function() { + $DONE('The promise should not be fulfilled.'); + }, function(value) { + if (!value) { + $DONE('The promise should be rejected with a value.'); + return; + } + if (value.constructor !== TypeError) { + $DONE('The promise should be rejected with a TypeError instance.'); + return; + } + + $DONE(); + }); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/resolve-thenable.js b/js/src/tests/test262/built-ins/Promise/resolve/resolve-thenable.js new file mode 100644 index 0000000000..1934ede551 --- /dev/null +++ b/js/src/tests/test262/built-ins/Promise/resolve/resolve-thenable.js @@ -0,0 +1,42 @@ +// |reftest| async +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Resolving with a thenable object value +es6id: 25.4.4.5 +info: | + [...] + 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, + «x»). + [...] + + 25.4.1.3.2 Promise Resolve Functions + [...] + 8. Let then be Get(resolution, "then"). + 9. If then is an abrupt completion, then + [...] + 10. Let thenAction be then.[[value]]. + 11. If IsCallable(thenAction) is false, then + [...] + 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, + «promise, resolution, thenAction») +flags: [async] +---*/ + +var value = {}; +var thenable = { + then: function(resolve) { + resolve(value); + } +}; + +Promise.resolve(thenable).then(function(val) { + if (val !== value) { + $DONE('The promise should be fulfilled with the provided value.'); + return; + } + + $DONE(); +}, function() { + $DONE('The promise should not be rejected.'); +}); diff --git a/js/src/tests/test262/built-ins/Promise/resolve/shell.js b/js/src/tests/test262/built-ins/Promise/resolve/shell.js new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3