diff --git a/test/built-ins/Promise/resolve/S25.4.4.5_A3.1_T1.js b/test/built-ins/Promise/resolve/S25.4.4.5_A3.1_T1.js index 7c57636f195a81c882a1b3d5819a2652b54c1a34..8fbc2befb1abde784dcc00327faaf48274892add 100644 --- a/test/built-ins/Promise/resolve/S25.4.4.5_A3.1_T1.js +++ b/test/built-ins/Promise/resolve/S25.4.4.5_A3.1_T1.js @@ -17,10 +17,17 @@ var thenable = { sequence.push(3); checkSequence(sequence, "thenable.then called"); - Promise.resolve().then(function () { - sequence.push(4); - checkSequence(sequence, "all done"); - }).then($DONE, $DONE); + assert.sameValue(this, thenable); + + onResolve('resolved'); + + sequence.push(4); + checkSequence(sequence, "after resolved"); + + throw new Error('interrupt flow'); + + sequence.push(4); + checkSequence(sequence, "duplicate sequence point not pushed"); } }; @@ -31,3 +38,11 @@ var p1 = Promise.resolve(thenable); sequence.push(2); checkSequence(sequence, "thenable.then queued but not yet called"); + +p1.then(function (q) { + sequence.push(5); + checkSequence(sequence, "all done"); + + assert.sameValue(q, 'resolved'); + +}).then($DONE, $DONE); diff --git a/test/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_1.js b/test/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_1.js new file mode 100644 index 0000000000000000000000000000000000000000..aa00db6890e00bb60009e8c04bce824b08185866 --- /dev/null +++ b/test/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_1.js @@ -0,0 +1,25 @@ +// 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] +---*/ + +var sequence = []; + +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/test/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_2.js b/test/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_2.js new file mode 100644 index 0000000000000000000000000000000000000000..074d0aaca1453dcb2392ff5768128033f4db7d37 --- /dev/null +++ b/test/built-ins/Promise/resolve/S25.Promise_resolve_foreign_thenable_2.js @@ -0,0 +1,40 @@ +// 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] +---*/ + +var sequence = []; + +var thenable = { + then: function(onResolve, onReject) { + + sequence.push(3); + checkSequence(sequence, "thenable.then called"); + + assert.sameValue(this, thenable, "thenable.then called with `thenable` as `this`"); + + return onResolve('resolved'); + } +}; + +sequence.push(1); +checkSequence(sequence, "no async calls yet"); + +var p = Promise.resolve(thenable); + +sequence.push(2); +checkSequence(sequence, "thenable.then queued but not yet called"); + +p.then(function (r) { + sequence.push(4); + checkSequence(sequence, "all done"); + + assert.sameValue(r, 'resolved'); +}).then($DONE, $DONE);