summaryrefslogtreecommitdiff
path: root/test/built-ins
diff options
context:
space:
mode:
authorMike Pennisi <mike@mikepennisi.com>2015-12-30 14:15:01 -0500
committerGorkem Yakin <goyakin@microsoft.com>2016-01-19 16:32:36 -0800
commitb1b4f04494fa15ecca154805c9422a42c447b1c4 (patch)
tree4247d471b8b47143d90ebf2546c7eb60f6e9a087 /test/built-ins
parenta5bf19486a6e5a58193580c088fb715baa57f90e (diff)
downloadqtdeclarative-testsuites-b1b4f04494fa15ecca154805c9422a42c447b1c4.tar.gz
Add tests for Promise Resolve Functions
Remove files that tested both PerformPromiseThen and PromiseResolveFunction in favor of new tests that test PromiseResolveFunction more directly and completely.
Diffstat (limited to 'test/built-ins')
-rw-r--r--test/built-ins/Promise/all/resolve-non-thenable.js74
-rw-r--r--test/built-ins/Promise/all/resolve-poisoned-then.js70
-rw-r--r--test/built-ins/Promise/all/resolve-thenable.js72
-rw-r--r--test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-fulfilled.js70
-rw-r--r--test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-pending-to-fulfilled.js84
-rw-r--r--test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-pending-to-rejected.js84
-rw-r--r--test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-rejected.js70
-rw-r--r--test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-thenable.js70
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-non-obj.js42
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-non-thenable.js48
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-poisoned-then.js50
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-self.js49
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-thenable.js51
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-rejected-non-obj.js43
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-rejected-non-thenable.js49
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-rejected-poisoned-then.js51
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-rejected-self.js50
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-pending-rejected-thenable.js52
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-non-obj.js46
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-non-thenable.js52
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-poisoned-then.js54
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-self.js53
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-thenable.js55
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-rejected-non-obj.js46
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-rejected-non-thenable.js52
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-rejected-poisoned-then.js54
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-rejected-self.js53
-rw-r--r--test/built-ins/Promise/prototype/then/resolve-settled-rejected-thenable.js55
-rw-r--r--test/built-ins/Promise/race/resolve-non-obj.js40
-rw-r--r--test/built-ins/Promise/race/resolve-non-thenable.js45
-rw-r--r--test/built-ins/Promise/race/resolve-poisoned-then.js46
-rw-r--r--test/built-ins/Promise/race/resolve-self.js54
-rw-r--r--test/built-ins/Promise/race/resolve-thenable.js52
-rw-r--r--test/built-ins/Promise/resolve-non-obj-deferred.js34
-rw-r--r--test/built-ins/Promise/resolve-non-obj-immed.js30
-rw-r--r--test/built-ins/Promise/resolve-non-thenable-deferred.js40
-rw-r--r--test/built-ins/Promise/resolve-non-thenable-immed.js37
-rw-r--r--test/built-ins/Promise/resolve-poisoned-then-deferred.js41
-rw-r--r--test/built-ins/Promise/resolve-poisoned-then-immed.js38
-rw-r--r--test/built-ins/Promise/resolve-self.js40
-rw-r--r--test/built-ins/Promise/resolve-thenable-deferred.js44
-rw-r--r--test/built-ins/Promise/resolve-thenable-immed.js40
-rw-r--r--test/built-ins/Promise/resolve/resolve-non-obj.js27
-rw-r--r--test/built-ins/Promise/resolve/resolve-non-thenable.js33
-rw-r--r--test/built-ins/Promise/resolve/resolve-poisoned-then.js36
-rw-r--r--test/built-ins/Promise/resolve/resolve-self.js46
-rw-r--r--test/built-ins/Promise/resolve/resolve-thenable.js40
47 files changed, 1984 insertions, 378 deletions
diff --git a/test/built-ins/Promise/all/resolve-non-thenable.js b/test/built-ins/Promise/all/resolve-non-thenable.js
new file mode 100644
index 000000000..659e10a21
--- /dev/null
+++ b/test/built-ins/Promise/all/resolve-non-thenable.js
@@ -0,0 +1,74 @@
+// 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.1
+info: >
+ [...]
+ 6. Let promiseCapability be NewPromiseCapability(C).
+ [...]
+ 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
+ [...]
+
+ 25.4.4.1.1 Runtime Semantics: PerformPromiseAll
+ [...]
+ 6. Repeat
+ [...]
+ d. If next is false,
+ [...]
+ iii. If remainingElementsCount.[[value]] is 0,
+ 1. Let valuesArray be CreateArrayFromList(values).
+ 2. Let resolveResult be Call(resultCapability.[[Resolve]],
+ undefined, «valuesArray»).
+ 3. ReturnIfAbrupt(resolveResult)
+ iv. Return resultCapability.[[Promise]].
+
+ 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).
+---*/
+
+var v1 = {};
+var v2 = {};
+var v3 = {};
+
+Promise.all([v1, v2, v3])
+ .then(function(values) {
+ if (!values) {
+ $DONE('The promise should be resolved with a value.');
+ return;
+ }
+ if (values.constructor !== Array) {
+ $DONE('The promise should be resolved with an Array instance.');
+ return;
+ }
+
+ if (values.length !== 3) {
+ $DONE('The promise should be resolved with an array of proper length.');
+ return;
+ }
+
+ if (values[0] !== v1) {
+ $DONE('The promise should be resolved with the correct element values (#1)');
+ return;
+ }
+
+ if (values[1] !== v2) {
+ $DONE('The promise should be resolved with the correct element values (#2)');
+ return;
+ }
+
+ if (values[2] !== v3) {
+ $DONE('The promise should be resolved with the correct element values (#3)');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/all/resolve-poisoned-then.js b/test/built-ins/Promise/all/resolve-poisoned-then.js
new file mode 100644
index 000000000..b8a17cf4f
--- /dev/null
+++ b/test/built-ins/Promise/all/resolve-poisoned-then.js
@@ -0,0 +1,70 @@
+// 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.1
+info: >
+ [...]
+ 6. Let promiseCapability be NewPromiseCapability(C).
+ [...]
+ 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
+ [...]
+
+ 25.4.4.1.1 Runtime Semantics: PerformPromiseAll
+ [...]
+ 6. Repeat
+ [...]
+ d. If next is false,
+ [...]
+ iii. If remainingElementsCount.[[value]] is 0,
+ 1. Let valuesArray be CreateArrayFromList(values).
+ 2. Let resolveResult be Call(resultCapability.[[Resolve]],
+ undefined, «valuesArray»).
+ 3. ReturnIfAbrupt(resolveResult)
+ iv. Return resultCapability.[[Promise]].
+
+ 7.3.16 CreateArrayFromList (elements)
+ [...]
+ 2. Let array be ArrayCreate(0) (see 9.4.2.2).
+
+ 9.4.2.2 ArrayCreate(length, proto)
+ [...]
+ 4. If the proto argument was not passed, let proto be the intrinsic object
+ %ArrayPrototype%.
+ 5. Let A be a newly created Array exotic object.
+ [...]
+ 8. Set the [[Prototype]] internal slot of A to proto.
+
+ 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]]).
+---*/
+
+var value = {};
+var promise;
+
+try {
+ Object.defineProperty(Array.prototype, 'then', {
+ get: function() {
+ throw value;
+ },
+ configurable: true
+ });
+
+ promise = Promise.all([]);
+} finally {
+ delete Array.prototype.then;
+}
+
+promise.then(function() {
+ $DONE('The promise should not be fulfilled.');
+ }, function(val) {
+ if (val !== value) {
+ $DONE('The promise should be rejected with the expected value.');
+ return;
+ }
+
+ $DONE();
+ });
diff --git a/test/built-ins/Promise/all/resolve-thenable.js b/test/built-ins/Promise/all/resolve-thenable.js
new file mode 100644
index 000000000..99b32585d
--- /dev/null
+++ b/test/built-ins/Promise/all/resolve-thenable.js
@@ -0,0 +1,72 @@
+// 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.1
+info: >
+ [...]
+ 6. Let promiseCapability be NewPromiseCapability(C).
+ [...]
+ 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
+ [...]
+
+ 25.4.4.1.1 Runtime Semantics: PerformPromiseAll
+ [...]
+ 6. Repeat
+ [...]
+ d. If next is false,
+ [...]
+ iii. If remainingElementsCount.[[value]] is 0,
+ 1. Let valuesArray be CreateArrayFromList(values).
+ 2. Let resolveResult be Call(resultCapability.[[Resolve]],
+ undefined, «valuesArray»).
+ 3. ReturnIfAbrupt(resolveResult)
+ iv. Return resultCapability.[[Promise]].
+
+ 7.3.16 CreateArrayFromList (elements)
+ [...]
+ 2. Let array be ArrayCreate(0) (see 9.4.2.2).
+
+ 9.4.2.2 ArrayCreate(length, proto)
+ [...]
+ 4. If the proto argument was not passed, let proto be the intrinsic object
+ %ArrayPrototype%.
+ 5. Let A be a newly created Array exotic object.
+ [...]
+ 8. Set the [[Prototype]] internal slot of A to proto.
+
+ 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 promise;
+
+try {
+ Array.prototype.then = function(resolve) {
+ resolve(value);
+ };
+
+ promise = Promise.all([]);
+} finally {
+ delete Array.prototype.then;
+}
+
+promise.then(function(val) {
+ if (val !== value) {
+ $DONE('The promise should be resolved with the expected value.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-fulfilled.js b/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-fulfilled.js
deleted file mode 100644
index 4e63f8502..000000000
--- a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-fulfilled.js
+++ /dev/null
@@ -1,70 +0,0 @@
-// 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.5.3
-description: The return value of the `onFulfilled` method is a fulfilled promise
-info: >
- 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
- resultCapability).
-
- 25.4.5.3.1 PerformPromiseThen
-
- [...]
- 8. Else if the value of promise's [[PromiseState]] internal slot is
- "fulfilled",
- a. Let value be the value of promise's [[PromiseResult]] internal slot.
- b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
- «fulfillReaction, value»).
-
- 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]]).
- 10. Let thenAction be then.[[value]].
- 11. If IsCallable(thenAction) is false, then
- a. Return FulfillPromise(promise, resolution).
- 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, «promise,
- resolution, thenAction»)
- 13. Return undefined.
----*/
-
-var executor1Counter = 0;
-var thenCounter = 0;
-var executor2Counter = 0;
-var promise = new Promise(function(resolve) {
- resolve();
-
- assert.sameValue(executor1Counter, 0);
- assert.sameValue(thenCounter, 0);
- assert.sameValue(executor2Counter, 0);
-
- executor1Counter += 1;
- });
-
-promise.then(function() {
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(thenCounter, 0);
- assert.sameValue(executor2Counter, 0);
-
- thenCounter += 1;
-
- return new Promise(function(resolve) {
- resolve();
-
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(thenCounter, 1);
- assert.sameValue(executor2Counter, 0);
-
- executor2Counter += 1;
- });
- }).then(function() {
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(thenCounter, 1);
- assert.sameValue(executor2Counter, 1);
-
- $DONE();
- }, function() {
- $DONE('The promise should not be rejected');
- });
diff --git a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-pending-to-fulfilled.js b/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-pending-to-fulfilled.js
deleted file mode 100644
index ff0791c5e..000000000
--- a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-pending-to-fulfilled.js
+++ /dev/null
@@ -1,84 +0,0 @@
-// 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.5.3
-description: The return value of the `onFulfilled` method is a pending promise
-info: >
- 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
- resultCapability).
-
- 25.4.5.3.1 PerformPromiseThen
-
- [...]
- 8. Else if the value of promise's [[PromiseState]] internal slot is
- "fulfilled",
- a. Let value be the value of promise's [[PromiseResult]] internal slot.
- b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
- «fulfillReaction, value»).
-
- 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]]).
- 10. Let thenAction be then.[[value]].
- 11. If IsCallable(thenAction) is false, then
- a. Return FulfillPromise(promise, resolution).
- 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, «promise,
- resolution, thenAction»)
- 13. Return undefined.
----*/
-
-var executor1Counter = 0;
-var then1Counter = 0;
-var executor2Counter = 0;
-var then2Counter = 0;
-var promise = new Promise(function(resolve) {
- resolve();
-
- assert.sameValue(executor1Counter, 0);
- assert.sameValue(then1Counter, 0);
- assert.sameValue(executor2Counter, 0);
- assert.sameValue(then2Counter, 0);
-
- executor1Counter += 1;
- });
-
-promise.then(function() {
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(then1Counter, 0);
- assert.sameValue(executor2Counter, 0);
- assert.sameValue(then2Counter, 0);
-
- then1Counter += 1;
-
- return new Promise(function(resolve) {
- promise.then(function() {
- resolve();
-
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(then1Counter, 1);
- assert.sameValue(executor2Counter, 1);
- assert.sameValue(then2Counter, 0);
-
- then2Counter += 1;
- });
-
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(then1Counter, 1);
- assert.sameValue(executor2Counter, 0);
- assert.sameValue(then2Counter, 0);
-
- executor2Counter += 1;
- });
- }).then(function() {
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(then1Counter, 1);
- assert.sameValue(executor2Counter, 1);
- assert.sameValue(then2Counter, 1);
-
- $DONE();
- }, function() {
- $DONE('The promise should not be rejected');
- });
diff --git a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-pending-to-rejected.js b/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-pending-to-rejected.js
deleted file mode 100644
index 2b3613c7b..000000000
--- a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-pending-to-rejected.js
+++ /dev/null
@@ -1,84 +0,0 @@
-// 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.5.3
-description: The return value of the `onFulfilled` method is a pending promise
-info: >
- 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
- resultCapability).
-
- 25.4.5.3.1 PerformPromiseThen
-
- [...]
- 8. Else if the value of promise's [[PromiseState]] internal slot is
- "fulfilled",
- a. Let value be the value of promise's [[PromiseResult]] internal slot.
- b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
- «fulfillReaction, value»).
-
- 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]]).
- 10. Let thenAction be then.[[value]].
- 11. If IsCallable(thenAction) is false, then
- a. Return FulfillPromise(promise, resolution).
- 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, «promise,
- resolution, thenAction»)
- 13. Return undefined.
----*/
-
-var executor1Counter = 0;
-var then1Counter = 0;
-var executor2Counter = 0;
-var then2Counter = 0;
-var promise = new Promise(function(resolve) {
- resolve();
-
- assert.sameValue(executor1Counter, 0);
- assert.sameValue(then1Counter, 0);
- assert.sameValue(executor2Counter, 0);
- assert.sameValue(then2Counter, 0);
-
- executor1Counter += 1;
- });
-
-promise.then(function() {
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(then1Counter, 0);
- assert.sameValue(executor2Counter, 0);
- assert.sameValue(then2Counter, 0);
-
- then1Counter += 1;
-
- return new Promise(function(_, reject) {
- promise.then(function() {
- reject();
-
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(then1Counter, 1);
- assert.sameValue(executor2Counter, 1);
- assert.sameValue(then2Counter, 0);
-
- then2Counter += 1;
- });
-
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(then1Counter, 1);
- assert.sameValue(executor2Counter, 0);
- assert.sameValue(then2Counter, 0);
-
- executor2Counter += 1;
- });
- }).then(function() {
- $DONE('The promise should not be fulfilled');
- }, function() {
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(then1Counter, 1);
- assert.sameValue(executor2Counter, 1);
- assert.sameValue(then2Counter, 1);
-
- $DONE();
- });
diff --git a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-rejected.js b/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-rejected.js
deleted file mode 100644
index 47948dc48..000000000
--- a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-prms-rejected.js
+++ /dev/null
@@ -1,70 +0,0 @@
-// 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.5.3
-description: The return value of the `onFulfilled` method is a rejected promise
-info: >
- 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
- resultCapability).
-
- 25.4.5.3.1 PerformPromiseThen
-
- [...]
- 8. Else if the value of promise's [[PromiseState]] internal slot is
- "fulfilled",
- a. Let value be the value of promise's [[PromiseResult]] internal slot.
- b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
- «fulfillReaction, value»).
-
- 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]]).
- 10. Let thenAction be then.[[value]].
- 11. If IsCallable(thenAction) is false, then
- a. Return FulfillPromise(promise, resolution).
- 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, «promise,
- resolution, thenAction»)
- 13. Return undefined.
----*/
-
-var executor1Counter = 0;
-var thenCounter = 0;
-var executor2Counter = 0;
-var promise = new Promise(function(resolve) {
- resolve();
-
- assert.sameValue(executor1Counter, 0);
- assert.sameValue(thenCounter, 0);
- assert.sameValue(executor2Counter, 0);
-
- executor1Counter += 1;
- });
-
-promise.then(function() {
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(thenCounter, 0);
- assert.sameValue(executor2Counter, 0);
-
- thenCounter += 1;
-
- return new Promise(function(_, reject) {
- reject();
-
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(thenCounter, 1);
- assert.sameValue(executor2Counter, 0);
-
- executor2Counter += 1;
- });
- }).then(function() {
- $DONE('The promise should not be fulfilled');
- }, function() {
- assert.sameValue(executor1Counter, 1);
- assert.sameValue(thenCounter, 1);
- assert.sameValue(executor2Counter, 1);
-
- $DONE();
- });
diff --git a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-thenable.js b/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-thenable.js
deleted file mode 100644
index 1a7974b71..000000000
--- a/test/built-ins/Promise/prototype/then/prfm-when-fulfilled-return-thenable.js
+++ /dev/null
@@ -1,70 +0,0 @@
-// 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.5.3
-description: The return value of the `onFulfilled` method is a "thenable" object
-info: >
- 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
- resultCapability).
-
- 25.4.5.3.1 PerformPromiseThen
-
- [...]
- 8. Else if the value of promise's [[PromiseState]] internal slot is
- "fulfilled",
- a. Let value be the value of promise's [[PromiseResult]] internal slot.
- b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
- «fulfillReaction, value»).
-
- 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]]).
- 10. Let thenAction be then.[[value]].
- 11. If IsCallable(thenAction) is false, then
- a. Return FulfillPromise(promise, resolution).
- 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, «promise,
- resolution, thenAction»)
- 13. Return undefined.
----*/
-
-var callCount = 0;
-var promise = new Promise(function(resolve) {
- resolve();
-});
-
-var thenable = {
- then: function(resolve, reject) {
- assert.sameValue(
- this, thenable, 'method invoked with correct `this` value'
- );
- assert.sameValue(typeof resolve, 'function', 'type of first argument');
- assert.sameValue(
- resolve.length,
- 1,
- 'ES6 25.4.1.3.2: The length property of a promise resolve function is 1.'
- );
- assert.sameValue(typeof reject, 'function', 'type of second argument');
- assert.sameValue(
- reject.length,
- 1,
- 'ES6 25.4.1.3.1: The length property of a promise reject function is 1.'
- );
- assert.sameValue(arguments.length, 2, 'total number of arguments');
- resolve();
-
- callCount += 1;
- }
-};
-
-promise.then(function() {
- return thenable;
-}).then(function() {
- assert.sameValue(callCount, 1);
-
- $DONE();
-}, function() {
- $DONE('This promise should not be rejected');
-});
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-non-obj.js b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-non-obj.js
new file mode 100644
index 000000000..65f95ba0b
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-non-obj.js
@@ -0,0 +1,42 @@
+// 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 from a pending promise that is later fulfilled
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ a. Append fulfillReaction as the last element of the List that is the
+ value of promise's [[PromiseFulfillReactions]] internal slot.
+ [...]
+
+ 25.4.1.3.2 Promise Resolve Functions
+ 7. If Type(resolution) is not Object, then
+ a. Return FulfillPromise(promise, resolution).
+---*/
+
+var resolve;
+var p1 = new Promise(function(_resolve) { resolve = _resolve; });
+var p2;
+
+p2 = p1.then(function() {
+ return 23;
+ });
+
+p2.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.');
+ });
+
+resolve();
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-non-thenable.js b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-non-thenable.js
new file mode 100644
index 000000000..8012d94a7
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-non-thenable.js
@@ -0,0 +1,48 @@
+// 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 from a pending promise that is later fulfilled
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ a. Append fulfillReaction as the last element of the List that is the
+ value of promise's [[PromiseFulfillReactions]] internal slot.
+ [...]
+
+ 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).
+---*/
+
+var nonThenable = { then: null };
+var resolve;
+var p1 = new Promise(function(_resolve) { resolve = _resolve; });
+var p2;
+
+p2 = p1.then(function() {
+ return nonThenable;
+ });
+
+p2.then(function(value) {
+ if (value !== nonThenable) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
+
+resolve();
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-poisoned-then.js b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-poisoned-then.js
new file mode 100644
index 000000000..9abf9511e
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-poisoned-then.js
@@ -0,0 +1,50 @@
+// 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 from a pending promise that is later fulfilled
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ a. Append fulfillReaction as the last element of the List that is the
+ value of promise's [[PromiseFulfillReactions]] internal slot.
+ [...]
+
+ 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]]).
+---*/
+
+var value = {};
+var resolve;
+var poisonedThen = Object.defineProperty({}, 'then', {
+ get: function() {
+ throw value;
+ }
+});
+var p1 = new Promise(function(_resolve) { resolve = _resolve; });
+var p2;
+
+p2 = p1.then(function() {
+ return poisonedThen;
+ });
+
+p2.then(function(x) {
+ $DONE('The promise should not be fulfilled.');
+ }, function(x) {
+ if (x !== value) {
+ $DONE('The promise should be rejected with the thrown exception.');
+ return;
+ }
+
+ $DONE();
+ });
+
+resolve();
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-self.js b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-self.js
new file mode 100644
index 000000000..9a2f1da69
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-self.js
@@ -0,0 +1,49 @@
+// 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 from a pending promise that is later fulfilled
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ a. Append fulfillReaction as the last element of the List that is the
+ value of promise's [[PromiseFulfillReactions]] internal slot.
+ [...]
+
+ 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).
+---*/
+
+var resolve;
+var p1 = new Promise(function(_resolve) { resolve = _resolve; });
+var p2;
+
+p2 = p1.then(function() {
+ return p2;
+ });
+
+p2.then(function() {
+ $DONE('The promise should not be fulfilled.');
+ }, function(reason) {
+ if (!reason) {
+ $DONE('The promise should be rejected with a value.');
+ return;
+ }
+
+ if (reason.constructor !== TypeError) {
+ $DONE('The promise should be rejected with a TypeError instance.');
+ return;
+ }
+
+ $DONE();
+ });
+
+resolve();
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-thenable.js b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-thenable.js
new file mode 100644
index 000000000..a6153bc8f
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-fulfilled-thenable.js
@@ -0,0 +1,51 @@
+// 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 from a pending promise that is later fulfilled
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ a. Append fulfillReaction as the last element of the List that is the
+ value of promise's [[PromiseFulfillReactions]] internal slot.
+ [...]
+
+ 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 resolve;
+var thenable = new Promise(function(resolve) { resolve(value); });
+var p1 = new Promise(function(_resolve) { resolve = _resolve; });
+var p2;
+
+p2 = p1.then(function() {
+ return thenable;
+ });
+
+p2.then(function(x) {
+ if (x !== value) {
+ $DONE('The promise should be fulfilled with the resolution value of the provided promise.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
+
+resolve();
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-rejected-non-obj.js b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-non-obj.js
new file mode 100644
index 000000000..576cdf006
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-non-obj.js
@@ -0,0 +1,43 @@
+// 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 from a pending promise that is later rejected
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ [...]
+ b. Append rejectReaction as the last element of the List that is the
+ value of promise's [[PromiseRejectReactions]] internal slot.
+ [...]
+
+ 25.4.1.3.2 Promise Resolve Functions
+ 7. If Type(resolution) is not Object, then
+ a. Return FulfillPromise(promise, resolution).
+---*/
+
+var reject;
+var p1 = new Promise(function(_, _reject) { reject = _reject; });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return 23;
+ });
+
+p2.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.');
+ });
+
+reject();
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-rejected-non-thenable.js b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-non-thenable.js
new file mode 100644
index 000000000..95191b0b8
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-non-thenable.js
@@ -0,0 +1,49 @@
+// 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 from a pending promise that is later rejected
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ [...]
+ b. Append rejectReaction as the last element of the List that is the
+ value of promise's [[PromiseRejectReactions]] internal slot.
+ [...]
+
+ 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).
+---*/
+
+var nonThenable = { then: null };
+var reject;
+var p1 = new Promise(function(_, _reject) { reject = _reject; });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return nonThenable;
+ });
+
+p2.then(function(value) {
+ if (value !== nonThenable) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
+
+reject();
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-rejected-poisoned-then.js b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-poisoned-then.js
new file mode 100644
index 000000000..f7808d038
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-poisoned-then.js
@@ -0,0 +1,51 @@
+// 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 from a pending promise that is later rejected
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ [...]
+ b. Append rejectReaction as the last element of the List that is the
+ value of promise's [[PromiseRejectReactions]] internal slot.
+ [...]
+
+ 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]]).
+---*/
+
+var value = {};
+var reject;
+var poisonedThen = Object.defineProperty({}, 'then', {
+ get: function() {
+ throw value;
+ }
+});
+var p1 = new Promise(function(_, _reject) { reject = _reject; });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return poisonedThen;
+ });
+
+p2.then(function(x) {
+ $DONE('The promise should not be fulfilled.');
+ }, function(x) {
+ if (x !== value) {
+ $DONE('The promise should be rejected with the thrown exception.');
+ return;
+ }
+
+ $DONE();
+ });
+
+reject();
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-rejected-self.js b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-self.js
new file mode 100644
index 000000000..87937e398
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-self.js
@@ -0,0 +1,50 @@
+// 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 from a pending promise that is later rejected
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ [...]
+ b. Append rejectReaction as the last element of the List that is the
+ value of promise's [[PromiseRejectReactions]] internal slot.
+ [...]
+
+ 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).
+---*/
+
+var reject;
+var p1 = new Promise(function(_, _reject) { reject = _reject; });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return p2;
+ });
+
+p2.then(function() {
+ $DONE('The promise should not be fulfilled.');
+ }, function(reason) {
+ if (!reason) {
+ $DONE('The promise should be rejected with a value.');
+ return;
+ }
+
+ if (reason.constructor !== TypeError) {
+ $DONE('The promise should be rejected with a TypeError instance.');
+ return;
+ }
+
+ $DONE();
+ });
+
+reject();
diff --git a/test/built-ins/Promise/prototype/then/resolve-pending-rejected-thenable.js b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-thenable.js
new file mode 100644
index 000000000..bb33553bd
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-pending-rejected-thenable.js
@@ -0,0 +1,52 @@
+// 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 from a pending promise that is later rejected
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 7. If the value of promise's [[PromiseState]] internal slot is "pending",
+ [...]
+ b. Append rejectReaction as the last element of the List that is the
+ value of promise's [[PromiseRejectReactions]] internal slot.
+ [...]
+
+ 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 reject;
+var thenable = new Promise(function(resolve) { resolve(value); });
+var p1 = new Promise(function(_, _reject) { reject = _reject; });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return thenable;
+ });
+
+p2.then(function(x) {
+ if (x !== value) {
+ $DONE('The promise should be fulfilled with the resolution value of the provided promise.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
+
+reject();
diff --git a/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-non-obj.js b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-non-obj.js
new file mode 100644
index 000000000..35e9e3f7f
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-non-obj.js
@@ -0,0 +1,46 @@
+// 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 from a fulfilled promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 8. Else if the value of promise's [[PromiseState]] internal slot is
+ "fulfilled",
+ a. Let value be the value of promise's [[PromiseResult]] internal slot.
+ b. EnqueueJob("PromiseJobs", PromiseReactionJob, «fulfillReaction,
+ value»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 25.4.1.3.2 Promise Resolve Functions
+ 7. If Type(resolution) is not Object, then
+ a. Return FulfillPromise(promise, resolution).
+---*/
+
+var p1 = new Promise(function(resolve) { resolve(); });
+var p2;
+
+p2 = p1.then(function() {
+ return 23;
+ });
+
+p2.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/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-non-thenable.js b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-non-thenable.js
new file mode 100644
index 000000000..07c40145a
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-non-thenable.js
@@ -0,0 +1,52 @@
+// 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 from a fulfilled promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 8. Else if the value of promise's [[PromiseState]] internal slot is
+ "fulfilled",
+ a. Let value be the value of promise's [[PromiseResult]] internal slot.
+ b. EnqueueJob("PromiseJobs", PromiseReactionJob, «fulfillReaction,
+ value»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 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).
+---*/
+
+var nonThenable = { then: null };
+var p1 = new Promise(function(resolve) { resolve(); });
+var p2;
+
+p2 = p1.then(function() {
+ return nonThenable;
+ });
+
+p2.then(function(value) {
+ if (value !== nonThenable) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-poisoned-then.js b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-poisoned-then.js
new file mode 100644
index 000000000..ef5a9e083
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-poisoned-then.js
@@ -0,0 +1,54 @@
+// 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 from a fulfilled promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 8. Else if the value of promise's [[PromiseState]] internal slot is
+ "fulfilled",
+ a. Let value be the value of promise's [[PromiseResult]] internal slot.
+ b. EnqueueJob("PromiseJobs", PromiseReactionJob, «fulfillReaction,
+ value»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 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]]).
+---*/
+
+var value = {};
+var poisonedThen = Object.defineProperty({}, 'then', {
+ get: function() {
+ throw value;
+ }
+});
+var p1 = new Promise(function(resolve) { resolve(); });
+var p2;
+
+p2 = p1.then(function() {
+ return poisonedThen;
+ });
+
+p2.then(function(x) {
+ $DONE('The promise should not be fulfilled.');
+ }, function(x) {
+ if (x !== value) {
+ $DONE('The promise should be rejected with the thrown exception.');
+ return;
+ }
+
+ $DONE();
+ });
diff --git a/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-self.js b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-self.js
new file mode 100644
index 000000000..d97a348c2
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-self.js
@@ -0,0 +1,53 @@
+// 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 from a fulfilled promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 8. Else if the value of promise's [[PromiseState]] internal slot is
+ "fulfilled",
+ a. Let value be the value of promise's [[PromiseResult]] internal slot.
+ b. EnqueueJob("PromiseJobs", PromiseReactionJob, «fulfillReaction,
+ value»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 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).
+---*/
+
+var p1 = new Promise(function(resolve) { resolve(); });
+var p2;
+
+p2 = p1.then(function() {
+ return p2;
+ });
+
+p2.then(function() {
+ $DONE('The promise should not be fulfilled.');
+ }, function(reason) {
+ if (!reason) {
+ $DONE('The promise should be rejected with a value.');
+ return;
+ }
+
+ if (reason.constructor !== TypeError) {
+ $DONE('The promise should be rejected with a TypeError instance.');
+ return;
+ }
+
+ $DONE();
+ });
diff --git a/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-thenable.js b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-thenable.js
new file mode 100644
index 000000000..86691de55
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-fulfilled-thenable.js
@@ -0,0 +1,55 @@
+// 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 from a fulfilled promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 8. Else if the value of promise's [[PromiseState]] internal slot is
+ "fulfilled",
+ a. Let value be the value of promise's [[PromiseResult]] internal slot.
+ b. EnqueueJob("PromiseJobs", PromiseReactionJob, «fulfillReaction,
+ value»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 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 thenable = new Promise(function(resolve) { resolve(value); });
+var p1 = new Promise(function(resolve) { resolve(); });
+var p2;
+
+p2 = p1.then(function() {
+ return thenable;
+ });
+
+p2.then(function(x) {
+ if (x !== value) {
+ $DONE('The promise should be fulfilled with the resolution value of the provided promise.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/prototype/then/resolve-settled-rejected-non-obj.js b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-non-obj.js
new file mode 100644
index 000000000..f9151850d
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-non-obj.js
@@ -0,0 +1,46 @@
+// 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 from a rejected promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 9. Else if the value of promise's [[PromiseState]] internal slot is
+ "rejected",
+ a. Let reason be the value of promise's [[PromiseResult]] internal slot.
+ b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
+ «rejectReaction, reason»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 25.4.1.3.2 Promise Resolve Functions
+ 7. If Type(resolution) is not Object, then
+ a. Return FulfillPromise(promise, resolution).
+---*/
+
+var p1 = new Promise(function(_, reject) { reject(); });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return 23;
+ });
+
+p2.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/test/built-ins/Promise/prototype/then/resolve-settled-rejected-non-thenable.js b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-non-thenable.js
new file mode 100644
index 000000000..421376088
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-non-thenable.js
@@ -0,0 +1,52 @@
+// 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 from a rejected promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 9. Else if the value of promise's [[PromiseState]] internal slot is
+ "rejected",
+ a. Let reason be the value of promise's [[PromiseResult]] internal slot.
+ b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
+ «rejectReaction, reason»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 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).
+---*/
+
+var nonThenable = { then: null };
+var p1 = new Promise(function(_, reject) { reject(); });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return nonThenable;
+ });
+
+p2.then(function(value) {
+ if (value !== nonThenable) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/prototype/then/resolve-settled-rejected-poisoned-then.js b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-poisoned-then.js
new file mode 100644
index 000000000..785f557b7
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-poisoned-then.js
@@ -0,0 +1,54 @@
+// 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 from a rejected promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 9. Else if the value of promise's [[PromiseState]] internal slot is
+ "rejected",
+ a. Let reason be the value of promise's [[PromiseResult]] internal slot.
+ b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
+ «rejectReaction, reason»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 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]]).
+---*/
+
+var value = {};
+var poisonedThen = Object.defineProperty({}, 'then', {
+ get: function() {
+ throw value;
+ }
+});
+var p1 = new Promise(function(_, reject) { reject(); });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return poisonedThen;
+ });
+
+p2.then(function(x) {
+ $DONE('The promise should not be fulfilled.');
+ }, function(x) {
+ if (x !== value) {
+ $DONE('The promise should be rejected with the thrown exception.');
+ return;
+ }
+
+ $DONE();
+ });
diff --git a/test/built-ins/Promise/prototype/then/resolve-settled-rejected-self.js b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-self.js
new file mode 100644
index 000000000..cfdf3e4b0
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-self.js
@@ -0,0 +1,53 @@
+// 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 from a rejected promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 9. Else if the value of promise's [[PromiseState]] internal slot is
+ "rejected",
+ a. Let reason be the value of promise's [[PromiseResult]] internal slot.
+ b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
+ «rejectReaction, reason»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 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).
+---*/
+
+var p1 = new Promise(function(_, reject) { reject(); });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return p2;
+ });
+
+p2.then(function() {
+ $DONE('The promise should not be fulfilled.');
+ }, function(reason) {
+ if (!reason) {
+ $DONE('The promise should be rejected with a value.');
+ return;
+ }
+
+ if (reason.constructor !== TypeError) {
+ $DONE('The promise should be rejected with a TypeError instance.');
+ return;
+ }
+
+ $DONE();
+ });
diff --git a/test/built-ins/Promise/prototype/then/resolve-settled-rejected-thenable.js b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-thenable.js
new file mode 100644
index 000000000..9d1ee3f62
--- /dev/null
+++ b/test/built-ins/Promise/prototype/then/resolve-settled-rejected-thenable.js
@@ -0,0 +1,55 @@
+// 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 from a rejected promise
+es6id: 25.4.5.3
+info: >
+ [...]
+ 7. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ resultCapability).
+
+ 25.4.5.3.1 PerformPromiseThen
+ [...]
+ 9. Else if the value of promise's [[PromiseState]] internal slot is
+ "rejected",
+ a. Let reason be the value of promise's [[PromiseResult]] internal slot.
+ b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob,
+ «rejectReaction, reason»).
+
+ 25.4.2.1 PromiseReactionJob
+ [...]
+ 8. Let status be Call(promiseCapability.[[Resolve]], undefined,
+ «handlerResult.[[value]]»).
+ [...]
+
+ 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 thenable = new Promise(function(resolve) { resolve(value); });
+var p1 = new Promise(function(_, reject) { reject(); });
+var p2;
+
+p2 = p1.then(function() {}, function() {
+ return thenable;
+ });
+
+p2.then(function(x) {
+ if (x !== value) {
+ $DONE('The promise should be fulfilled with the resolution value of the provided promise.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/race/resolve-non-obj.js b/test/built-ins/Promise/race/resolve-non-obj.js
new file mode 100644
index 000000000..6dfd31a9c
--- /dev/null
+++ b/test/built-ins/Promise/race/resolve-non-obj.js
@@ -0,0 +1,40 @@
+// 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.3
+info: >
+ [...]
+ 6. Let promiseCapability be NewPromiseCapability(C).
+ [...]
+ 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
+ [...]
+
+ 25.4.4.3.1 Runtime Semantics: PerformPromiseRace
+ 1. Repeat
+ [...]
+ j. Let result be Invoke(nextPromise, "then",
+ «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
+
+ 25.4.1.3.2 Promise Resolve Functions
+ [...]
+ 7. If Type(resolution) is not Object, then
+ a. Return FulfillPromise(promise, resolution).
+---*/
+
+var thenable = {
+ then: function(resolve) {
+ resolve(23);
+ }
+};
+
+Promise.race([thenable])
+ .then(function(value) {
+ if (value !== 23) {
+ $DONE('The promise should be resolved with the correct value.');
+ return;
+ }
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/race/resolve-non-thenable.js b/test/built-ins/Promise/race/resolve-non-thenable.js
new file mode 100644
index 000000000..179ab4344
--- /dev/null
+++ b/test/built-ins/Promise/race/resolve-non-thenable.js
@@ -0,0 +1,45 @@
+// 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.3
+info: >
+ [...]
+ 6. Let promiseCapability be NewPromiseCapability(C).
+ [...]
+ 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
+ [...]
+
+ 25.4.4.3.1 Runtime Semantics: PerformPromiseRace
+ 1. Repeat
+ [...]
+ j. Let result be Invoke(nextPromise, "then",
+ «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
+
+ 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).
+---*/
+
+var value = {};
+var thenable = {
+ then: function(resolve) {
+ resolve(value);
+ }
+};
+
+Promise.race([thenable])
+ .then(function(val) {
+ if (val !== value) {
+ $DONE('The promise should be resolved with the correct value.');
+ return;
+ }
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/race/resolve-poisoned-then.js b/test/built-ins/Promise/race/resolve-poisoned-then.js
new file mode 100644
index 000000000..c25563dad
--- /dev/null
+++ b/test/built-ins/Promise/race/resolve-poisoned-then.js
@@ -0,0 +1,46 @@
+// 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.3
+info: >
+ [...]
+ 6. Let promiseCapability be NewPromiseCapability(C).
+ [...]
+ 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
+ [...]
+
+ 25.4.4.3.1 Runtime Semantics: PerformPromiseRace
+ 1. Repeat
+ [...]
+ j. Let result be Invoke(nextPromise, "then",
+ «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
+
+ 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]]).
+---*/
+
+var value = {};
+var poisonedThen = Object.defineProperty({}, 'then', {
+ get: function() {
+ throw value;
+ }
+});
+var thenable = {
+ then: function(resolve) {
+ resolve(poisonedThen);
+ }
+};
+
+Promise.race([thenable])
+ .then(function() {
+ $DONE('The promise should not be fulfilled.');
+ }, function(val) {
+ if (val !== value) {
+ $DONE('The promise should be rejected with the correct value.');
+ return;
+ }
+ $DONE();
+ });
diff --git a/test/built-ins/Promise/race/resolve-self.js b/test/built-ins/Promise/race/resolve-self.js
new file mode 100644
index 000000000..511a03200
--- /dev/null
+++ b/test/built-ins/Promise/race/resolve-self.js
@@ -0,0 +1,54 @@
+// 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.3
+info: >
+ [...]
+ 6. Let promiseCapability be NewPromiseCapability(C).
+ [...]
+ 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
+ [...]
+
+ 25.4.4.3.1 Runtime Semantics: PerformPromiseRace
+ 1. Repeat
+ [...]
+ j. Let result be Invoke(nextPromise, "then",
+ «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
+
+ 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).
+---*/
+
+var self, resolve;
+var builtinResolve = Promise.resolve;
+var thenable = {
+ then: function(r) {
+ resolve = r;
+ }
+};
+
+try {
+ Promise.resolve = function(v) { return v; };
+ self = Promise.race([thenable]);
+} finally {
+ Promise.resolve = builtinResolve;
+}
+
+resolve(self);
+
+self.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/test/built-ins/Promise/race/resolve-thenable.js b/test/built-ins/Promise/race/resolve-thenable.js
new file mode 100644
index 000000000..8eb3f059c
--- /dev/null
+++ b/test/built-ins/Promise/race/resolve-thenable.js
@@ -0,0 +1,52 @@
+// 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.3
+info: >
+ [...]
+ 6. Let promiseCapability be NewPromiseCapability(C).
+ [...]
+ 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
+ [...]
+
+ 25.4.4.3.1 Runtime Semantics: PerformPromiseRace
+ 1. Repeat
+ [...]
+ j. Let result be Invoke(nextPromise, "then",
+ «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
+
+ 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 thenableValue = {
+ then: function(resolve) {
+ resolve(value);
+ }
+};
+var thenable = {
+ then: function(resolve) {
+ resolve(thenableValue);
+ }
+};
+
+Promise.race([thenable])
+ .then(function(val) {
+ if (val !== value) {
+ $DONE('The promise should be resolved with the correct value.');
+ return;
+ }
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/resolve-non-obj-deferred.js b/test/built-ins/Promise/resolve-non-obj-deferred.js
new file mode 100644
index 000000000..2516dbd41
--- /dev/null
+++ b/test/built-ins/Promise/resolve-non-obj-deferred.js
@@ -0,0 +1,34 @@
+// 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 after invocation of the executor function
+es6id: 25.4.3.1
+info: >
+ [...]
+ 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
+ 9. Let completion be Call(executor, undefined,
+ «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
+
+ 25.4.1.3.2 Promise Resolve Functions
+ 7. If Type(resolution) is not Object, then
+ a. Return FulfillPromise(promise, resolution).
+---*/
+
+var resolve;
+var promise = new Promise(function(_resolve) {
+ resolve = _resolve;
+});
+
+promise.then(function(value) {
+ if (value !== 45) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
+
+resolve(45);
diff --git a/test/built-ins/Promise/resolve-non-obj-immed.js b/test/built-ins/Promise/resolve-non-obj-immed.js
new file mode 100644
index 000000000..163a1938f
--- /dev/null
+++ b/test/built-ins/Promise/resolve-non-obj-immed.js
@@ -0,0 +1,30 @@
+// 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 from within the executor function
+es6id: 25.4.3.1
+info: >
+ [...]
+ 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
+ 9. Let completion be Call(executor, undefined,
+ «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
+
+ 25.4.1.3.2 Promise Resolve Functions
+ 7. If Type(resolution) is not Object, then
+ a. Return FulfillPromise(promise, resolution).
+---*/
+
+var promise = new Promise(function(resolve) {
+ resolve(45);
+});
+
+promise.then(function(value) {
+ if (value !== 45) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/resolve-non-thenable-deferred.js b/test/built-ins/Promise/resolve-non-thenable-deferred.js
new file mode 100644
index 000000000..a6ed85242
--- /dev/null
+++ b/test/built-ins/Promise/resolve-non-thenable-deferred.js
@@ -0,0 +1,40 @@
+// 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 after invocation of the executor function
+es6id: 25.4.3.1
+info: >
+ [...]
+ 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
+ 9. Let completion be Call(executor, undefined,
+ «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
+
+ 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).
+---*/
+
+var nonThenable = { then: null };
+var resolve;
+var promise = new Promise(function(_resolve) {
+ resolve = _resolve;
+});
+
+promise.then(function(value) {
+ if (value !== nonThenable) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
+
+resolve(nonThenable);
diff --git a/test/built-ins/Promise/resolve-non-thenable-immed.js b/test/built-ins/Promise/resolve-non-thenable-immed.js
new file mode 100644
index 000000000..ae0236140
--- /dev/null
+++ b/test/built-ins/Promise/resolve-non-thenable-immed.js
@@ -0,0 +1,37 @@
+// 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 from within the executor function
+es6id: 25.4.3.1
+info: >
+ [...]
+ 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
+ 9. Let completion be Call(executor, undefined,
+ «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
+
+ 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).
+---*/
+
+var nonThenable = { then: null };
+var promise = new Promise(function(resolve) {
+ resolve(nonThenable);
+});
+
+promise.then(function(value) {
+ if (value !== nonThenable) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ }, function() {
+ $DONE('The promise should not be rejected.');
+ });
diff --git a/test/built-ins/Promise/resolve-poisoned-then-deferred.js b/test/built-ins/Promise/resolve-poisoned-then-deferred.js
new file mode 100644
index 000000000..33c2b7846
--- /dev/null
+++ b/test/built-ins/Promise/resolve-poisoned-then-deferred.js
@@ -0,0 +1,41 @@
+// 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 after invocation
+ of the executor function
+es6id: 25.4.3.1
+info: >
+ [...]
+ 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
+ 9. Let completion be Call(executor, undefined,
+ «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
+
+ 25.4.1.3.2 Promise Resolve Functions
+ 7. If Type(resolution) is not Object, then
+ a. Return FulfillPromise(promise, resolution).
+---*/
+
+var value = {};
+var resolve;
+var poisonedThen = Object.defineProperty({}, 'then', {
+ get: function() {
+ throw value;
+ }
+});
+var promise = new Promise(function(_resolve) {
+ resolve = _resolve;
+});
+
+promise.then(function() {
+ $DONE('The promise should not be fulfilled.');
+ }, function(val) {
+ if (val !== value) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ });
+
+resolve(poisonedThen);
diff --git a/test/built-ins/Promise/resolve-poisoned-then-immed.js b/test/built-ins/Promise/resolve-poisoned-then-immed.js
new file mode 100644
index 000000000..ec806a235
--- /dev/null
+++ b/test/built-ins/Promise/resolve-poisoned-then-immed.js
@@ -0,0 +1,38 @@
+// 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 from within the
+ executor function
+es6id: 25.4.3.1
+info: >
+ [...]
+ 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
+ 9. Let completion be Call(executor, undefined,
+ «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
+
+ 25.4.1.3.2 Promise Resolve Functions
+ 7. If Type(resolution) is not Object, then
+ a. Return FulfillPromise(promise, resolution).
+---*/
+
+var value = {};
+var poisonedThen = Object.defineProperty({}, 'then', {
+ get: function() {
+ throw value;
+ }
+});
+var promise = new Promise(function(resolve) {
+ resolve(poisonedThen);
+});
+
+promise.then(function() {
+ $DONE('The promise should not be fulfilled.');
+ }, function(val) {
+ if (val !== value) {
+ $DONE('The promise should be fulfilled with the provided value.');
+ return;
+ }
+
+ $DONE();
+ });
diff --git a/test/built-ins/Promise/resolve-self.js b/test/built-ins/Promise/resolve-self.js
new file mode 100644
index 000000000..9425d42b5
--- /dev/null
+++ b/test/built-ins/Promise/resolve-self.js
@@ -0,0 +1,40 @@
+// 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.3.1
+info: >
+ [...]
+ 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
+ 9. Let completion be Call(executor, undefined,
+ «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
+
+ 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).
+---*/
+
+var resolve;
+var promise = new Promise(function(_resolve) {
+ resolve = _resolve;
+});
+
+promise.then(function() {
+ $DONE('The promise should not be fulfilled.');
+ }, function(reason) {
+ if (!reason) {
+ $DONE('The promise should be rejected with a value.');
+ return;
+ }
+
+ if (reason.constructor !== TypeError) {
+ $DONE('The promise should be rejected with a TypeError instance.');
+ return;
+ }
+
+ $DONE();
+ });
+
+resolve(promise);
diff --git a/test/built-ins/Promise/resolve-thenable-deferred.js b/test/built-ins/Promise/resolve-thenable-deferred.js
new file mode 100644
index 000000000..93dfab0e5
--- /dev/null
+++ b/test/built-ins/Promise/resolve-thenable-deferred.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 thenable object value after execution of the executor
+ function
+es6id: 25.4.3.1
+info: >
+ [...]
+ 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
+ 9. Let completion be Call(executor, undefined,
+ «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
+
+ 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 resolve;
+var thenable = new Promise(function(resolve) { resolve(value); });
+var promise = new Promise(function(_resolve) {
+ resolve = _resolve;
+});
+
+promise.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.');
+ });
+
+resolve(thenable);
diff --git a/test/built-ins/Promise/resolve-thenable-immed.js b/test/built-ins/Promise/resolve-thenable-immed.js
new file mode 100644
index 000000000..c39f9aff6
--- /dev/null
+++ b/test/built-ins/Promise/resolve-thenable-immed.js
@@ -0,0 +1,40 @@
+// 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 from within the executor function
+es6id: 25.4.3.1
+info: >
+ [...]
+ 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
+ 9. Let completion be Call(executor, undefined,
+ «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
+
+ 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 thenable = new Promise(function(resolve) { resolve(value); });
+var promise = new Promise(function(resolve) {
+ resolve(thenable);
+});
+
+promise.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/test/built-ins/Promise/resolve/resolve-non-obj.js b/test/built-ins/Promise/resolve/resolve-non-obj.js
new file mode 100644
index 000000000..9a99e4d1f
--- /dev/null
+++ b/test/built-ins/Promise/resolve/resolve-non-obj.js
@@ -0,0 +1,27 @@
+// 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).
+---*/
+
+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/test/built-ins/Promise/resolve/resolve-non-thenable.js b/test/built-ins/Promise/resolve/resolve-non-thenable.js
new file mode 100644
index 000000000..446f0f992
--- /dev/null
+++ b/test/built-ins/Promise/resolve/resolve-non-thenable.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: 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).
+---*/
+
+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/test/built-ins/Promise/resolve/resolve-poisoned-then.js b/test/built-ins/Promise/resolve/resolve-poisoned-then.js
new file mode 100644
index 000000000..8ada16e33
--- /dev/null
+++ b/test/built-ins/Promise/resolve/resolve-poisoned-then.js
@@ -0,0 +1,36 @@
+// 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]]).
+---*/
+
+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/test/built-ins/Promise/resolve/resolve-self.js b/test/built-ins/Promise/resolve/resolve-self.js
new file mode 100644
index 000000000..a9b9b73c4
--- /dev/null
+++ b/test/built-ins/Promise/resolve/resolve-self.js
@@ -0,0 +1,46 @@
+// 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).
+---*/
+
+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/test/built-ins/Promise/resolve/resolve-thenable.js b/test/built-ins/Promise/resolve/resolve-thenable.js
new file mode 100644
index 000000000..62b061b2e
--- /dev/null
+++ b/test/built-ins/Promise/resolve/resolve-thenable.js
@@ -0,0 +1,40 @@
+// 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»)
+---*/
+
+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.');
+ });