Skip to content

Commit

Permalink
Fix problem with promise
Browse files Browse the repository at this point in the history
  • Loading branch information
XmiliaH committed Oct 12, 2021
1 parent 1eabc2a commit 4675e51
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/fixasync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 4675e51

Please sign in to comment.