From 149bbb78752cdd84b7c7fd9c720f566cf48aced9 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Mon, 15 Jan 2024 14:29:21 +0000 Subject: [PATCH] Throw Exception when a Promise tries to resolve with another Promise (#2450) --- ChangeLog | 1 + src/jswrap_promise.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index ccec89e437..24a86161c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ 2v21 : nRF52: free up 800b more flash by removing vector table padding + Throw Exception when a Promise tries to resolve with another Promise (#2450) 2v20 : Ensure String.charCodeAt returns NaN for out of bounds chars Bangle.js2: When rendering overlays, *do not* use the current FG/BG color for 1 bit overlays diff --git a/src/jswrap_promise.c b/src/jswrap_promise.c index aa3ce23c83..9429796db5 100644 --- a/src/jswrap_promise.c +++ b/src/jswrap_promise.c @@ -108,6 +108,10 @@ void _jswrap_promise_resolve_or_reject(JsVar *promise, JsVar *data, JsVar *fn) { } void _jswrap_promise_resolve_or_reject_chain(JsVar *promise, JsVar *data, bool resolve) { const char *eventName = resolve ? JS_PROMISE_THEN_NAME : JS_PROMISE_CATCH_NAME; + if (_jswrap_promise_is_promise(data)) { + jsExceptionHere(JSET_ERROR, "Resolving a Promise with a value that is a Promise is not currently supported"); + return; + } // if we didn't have a catch, traverse the chain looking for one JsVar *fn = jsvObjectGetChildIfExists(promise, eventName); if (!fn) {