From 7daa3966fa01ce4d46799f1f7ca3c0a98aa2fcc9 Mon Sep 17 00:00:00 2001 From: Dmitriy Mozgovoy Date: Tue, 13 Apr 2021 21:06:00 +0300 Subject: [PATCH] Fixed a bug with `_objectToCPromise` that happens if the `thing` has nullable value; --- lib/c-promise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/c-promise.js b/lib/c-promise.js index 46ab8b8..d2bf72a 100644 --- a/lib/c-promise.js +++ b/lib/c-promise.js @@ -1290,6 +1290,8 @@ class CPromise extends Promise { } static [_objectToCPromise](thing) { + if(!thing) return null; + const convertMethod = thing[_toCPromise]; if (typeof convertMethod === 'function') { @@ -1308,7 +1310,7 @@ class CPromise extends Promise { return returnedValue; } - if (thing && typeof thing.then === 'function') { + if (typeof thing.then === 'function') { return new this((resolve, reject, {onCancel}) => { if (typeof thing.cancel === 'function') { onCancel(reason => {