mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Fix handling of return of rejected promise within a promise
This commit is contained in:
parent
0b1dd85687
commit
8191ca4164
@ -1,4 +1,5 @@
|
||||
1v91 : Fix recent regression if no Boot Code defined at startup
|
||||
Fix handling of return of rejected promise within a promise
|
||||
|
||||
1v90 : Fixes for Promise.all (passing in non-promises, pre-resolved, and ordering) (fix #976)
|
||||
Fix arrow function bug when parsing multiple arguments
|
||||
|
||||
@ -80,12 +80,15 @@ void _jswrap_promise_resolve_or_reject(JsVar *promise, JsVar *data, JsVar *fn) {
|
||||
if (chainedPromise) {
|
||||
if (_jswrap_promise_is_promise(result)) {
|
||||
// if we were given a promise, loop its 'then' in here
|
||||
JsVar *fn = jsvNewNativeFunction((void (*)(void))_jswrap_promise_queueresolve, JSWAT_VOID|JSWAT_THIS_ARG|(JSWAT_JSVAR<<JSWAT_BITS));
|
||||
if (fn) {
|
||||
jsvObjectSetChild(fn, JSPARSE_FUNCTION_THIS_NAME, chainedPromise);
|
||||
_jswrap_promise_add(result, fn, true);
|
||||
jsvUnLock(fn);
|
||||
JsVar *fnres = jsvNewNativeFunction((void (*)(void))_jswrap_promise_queueresolve, JSWAT_VOID|JSWAT_THIS_ARG|(JSWAT_JSVAR<<JSWAT_BITS));
|
||||
JsVar *fnrej = jsvNewNativeFunction((void (*)(void))_jswrap_promise_queuereject, JSWAT_VOID|JSWAT_THIS_ARG|(JSWAT_JSVAR<<JSWAT_BITS));
|
||||
if (fnres && fnrej) {
|
||||
jsvObjectSetChild(fnres, JSPARSE_FUNCTION_THIS_NAME, chainedPromise);
|
||||
jsvObjectSetChild(fnrej, JSPARSE_FUNCTION_THIS_NAME, chainedPromise);
|
||||
_jswrap_promise_add(result, fnres, true);
|
||||
_jswrap_promise_add(result, fnrej, false);
|
||||
}
|
||||
jsvUnLock2(fnres,fnrej);
|
||||
} else {
|
||||
_jswrap_promise_queueresolve(chainedPromise, result);
|
||||
}
|
||||
|
||||
9
tests/test_promise7.js
Normal file
9
tests/test_promise7.js
Normal file
@ -0,0 +1,9 @@
|
||||
//http://forum.espruino.com/conversations/297505/#comment13375674
|
||||
new Promise((x,y)=>x()).then(dev=>{
|
||||
return new Promise((x,y)=>y("Uh-oh"));
|
||||
}).then(s=>{
|
||||
console.log("ok", s);
|
||||
}).catch(e=>{
|
||||
console.log("expected error", e);
|
||||
result = e == "Uh-oh";
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user