From 4675e5166c0cb84c586e9fc2f6d218ebd6f3438c Mon Sep 17 00:00:00 2001 From: XmiliaH Date: Tue, 12 Oct 2021 21:56:39 +0200 Subject: [PATCH] Fix problem with promise --- lib/fixasync.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/fixasync.js b/lib/fixasync.js index e0f409d..d4e474b 100644 --- a/lib/fixasync.js +++ b/lib/fixasync.js @@ -66,15 +66,18 @@ global.eval = new host.Proxy(eval_, makeCheckFunction('eval')); if (Promise) { Promise.prototype.then = new host.Proxy(Promise.prototype.then, makeCheckFunction('promise_then')); - Contextify.connect(host.Promise.prototype.then, Promise.prototype.then); + // This seems not to work, and will produce + // UnhandledPromiseRejectionWarning: TypeError: Method Promise.prototype.then called on incompatible receiver [object Object]. + // This is likely caused since the host.Promise.prototype.then cannot use the VM Proxy object. + // Contextify.connect(host.Promise.prototype.then, Promise.prototype.then); if (Promise.prototype.finally) { Promise.prototype.finally = new host.Proxy(Promise.prototype.finally, makeCheckFunction('promise_finally')); - Contextify.connect(host.Promise.prototype.finally, Promise.prototype.finally); + // Contextify.connect(host.Promise.prototype.finally, Promise.prototype.finally); } if (Promise.prototype.catch) { Promise.prototype.catch = new host.Proxy(Promise.prototype.catch, makeCheckFunction('promise_catch')); - Contextify.connect(host.Promise.prototype.catch, Promise.prototype.catch); + // Contextify.connect(host.Promise.prototype.catch, Promise.prototype.catch); } }