mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
7 years ago
18 changed files with 191 additions and 0 deletions
@ -0,0 +1,27 @@ |
|||
/*--- |
|||
{ |
|||
"skip": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
done |
|||
fulfill |
|||
object |
|||
[object Array] |
|||
0 |
|||
===*/ |
|||
|
|||
// Empty list is an important corner case, and also exercises the specific
|
|||
// .all() path where an immediate completion is checked for.
|
|||
|
|||
Promise.all([]).then(function (v) { |
|||
print('fulfill'); |
|||
print(typeof v); |
|||
print(Object.prototype.toString.call(v)); |
|||
print(v.length); |
|||
}, function (e) { |
|||
print('reject:', e); |
|||
}); |
|||
|
|||
print('done'); |
@ -0,0 +1,29 @@ |
|||
/*--- |
|||
{ |
|||
"skip": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
done |
|||
O1.then |
|||
O2.then |
|||
Promise.all then |
|||
2 123 234 |
|||
===*/ |
|||
|
|||
var O1CB, O2CB; |
|||
var O1 = { then: function (cb) { print('O1.then'); O1CB = cb; } }; |
|||
var O2 = { then: function (cb) { print('O2.then'); O2CB = cb; } }; |
|||
var P = Promise.all([ O1, O2 ]); |
|||
P.then(function (v) { |
|||
print('Promise.all then'); |
|||
print(v.length, v[0], v[1]); |
|||
}); |
|||
|
|||
Promise.resolve().then(function () { |
|||
O1CB(123); |
|||
O2CB(234); |
|||
}); |
|||
|
|||
print('done'); |
@ -0,0 +1,32 @@ |
|||
/*--- |
|||
{ |
|||
"skip": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
done |
|||
fulfill, values match true |
|||
2 undefined undefined |
|||
===*/ |
|||
|
|||
// Missing argument and void 0 are handled the same.
|
|||
|
|||
var P = Promise.reject(); |
|||
var Q = Promise.reject(void 0); |
|||
|
|||
var T1 = P.catch(function (e) { |
|||
return e; |
|||
}); |
|||
var T2 = Q.catch(function (e) { |
|||
return e; |
|||
}); |
|||
|
|||
Promise.all([ T1, T2 ]).then(function (v) { |
|||
print('fulfill, values match', v[0] === v[1]); |
|||
print(v.length, v[0], v[1]); |
|||
}, function (e) { |
|||
print('reject:', e); |
|||
}); |
|||
|
|||
print('done'); |
@ -0,0 +1,25 @@ |
|||
/*--- |
|||
{ |
|||
"skip": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
done |
|||
fulfill, values match true |
|||
2 undefined undefined |
|||
===*/ |
|||
|
|||
// Missing argument and void 0 are handled the same.
|
|||
|
|||
var P = Promise.resolve(); |
|||
var Q = Promise.resolve(void 0); |
|||
|
|||
Promise.all([ P, Q ]).then(function (v) { |
|||
print('fulfill, values match', v[0] === v[1]); |
|||
print(v.length, v[0], v[1]); |
|||
}, function (e) { |
|||
print('reject:', e); |
|||
}); |
|||
|
|||
print('done'); |
@ -0,0 +1,39 @@ |
|||
/*--- |
|||
{ |
|||
"skip": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
done |
|||
Q fulfill: 321 |
|||
===*/ |
|||
|
|||
// Promise executor return value has no effect on promise value.
|
|||
|
|||
var resolveP, rejectP; |
|||
var resolveQ, rejectQ; |
|||
var P = new Promise(function (resolve, reject) { |
|||
resolveP = resolve; |
|||
rejectP = reject; |
|||
return 123; // return value won't resolve P
|
|||
}); |
|||
P.then(function (v) { |
|||
print('P fulfill:', v); |
|||
}, function (e) { |
|||
print('P reject:', e); |
|||
}); |
|||
var Q = new Promise(function (resolve, reject) { |
|||
resolveQ = resolve; |
|||
rejectQ = reject; |
|||
return 123; |
|||
}); |
|||
Q.then(function (v) { |
|||
print('Q fulfill:', v); |
|||
}, function (e) { |
|||
print('Q reject:', e); |
|||
}); |
|||
|
|||
resolveQ(321); |
|||
|
|||
print('done'); |
@ -0,0 +1,34 @@ |
|||
/*--- |
|||
{ |
|||
"skip": true |
|||
} |
|||
---*/ |
|||
|
|||
/*=== |
|||
ignored |
|||
done |
|||
fulfill: 123 |
|||
===*/ |
|||
|
|||
var resolveFn; |
|||
var P = new Promise(function (resolve, reject) { |
|||
resolveFn = resolve; |
|||
}); |
|||
|
|||
P.then(function (v) { |
|||
print('fulfill:', v); |
|||
}, function (e) { |
|||
print('reject:', e.name); |
|||
}); |
|||
|
|||
resolveFn(123); |
|||
|
|||
// Self resolution after already being settled is a no-op.
|
|||
try { |
|||
resolveFn(P); |
|||
print('ignored'); |
|||
} catch (e) { |
|||
print('should not happen:', e); |
|||
} |
|||
|
|||
print('done'); |
Loading…
Reference in new issue