mirror of
https://github.com/tc39/test262.git
synced 2025-07-21 13:04:39 +02:00
2 new tests re: foreign thenables
This commit is contained in:
parent
8eb0bd1279
commit
cc18dd2d79
@ -17,10 +17,17 @@ var thenable = {
|
|||||||
sequence.push(3);
|
sequence.push(3);
|
||||||
checkSequence(sequence, "thenable.then called");
|
checkSequence(sequence, "thenable.then called");
|
||||||
|
|
||||||
Promise.resolve().then(function () {
|
assert.sameValue(this, thenable);
|
||||||
|
|
||||||
|
onResolve('resolved');
|
||||||
|
|
||||||
sequence.push(4);
|
sequence.push(4);
|
||||||
checkSequence(sequence, "all done");
|
checkSequence(sequence, "after resolved");
|
||||||
}).then($DONE, $DONE);
|
|
||||||
|
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);
|
sequence.push(2);
|
||||||
checkSequence(sequence, "thenable.then queued but not yet called");
|
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);
|
||||||
|
@ -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);
|
@ -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);
|
Loading…
x
Reference in New Issue
Block a user