From 5b2c8eba80405ff39d190b656cd51da338f4a9ab Mon Sep 17 00:00:00 2001 From: Fabio Massaioli Date: Tue, 25 Feb 2025 17:53:18 +0100 Subject: [PATCH] Remove Promise monkey-patching --- .../desktop/@wailsio/runtime/src/cancellable.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/v3/internal/runtime/desktop/@wailsio/runtime/src/cancellable.ts b/v3/internal/runtime/desktop/@wailsio/runtime/src/cancellable.ts index acc8236aa..5a839e211 100644 --- a/v3/internal/runtime/desktop/@wailsio/runtime/src/cancellable.ts +++ b/v3/internal/runtime/desktop/@wailsio/runtime/src/cancellable.ts @@ -386,7 +386,7 @@ export class CancellablePromise extends Promise implements PromiseLike, this[barrierSym] = barrier; return new CancellablePromise((resolve, reject) => { - void promiseThen.call(this, + void super.then( (value) => { if (this[barrierSym] === barrier) { this[barrierSym] = null; } barrier.resolve?.(); @@ -717,7 +717,7 @@ function cancellerFor(promise: CancellablePromiseWithResolvers, state: Can // In theory, a sane underlying implementation at this point // should always reject with our cancellation reason, // hence the handler will never throw. - void promiseThen.call(promise.promise, undefined, (err) => { + void Promise.prototype.then.call(promise.promise, undefined, (err) => { if (err !== reason) { throw err; } @@ -920,16 +920,6 @@ function currentBarrier(promise: CancellablePromise): Promise { return pwr.promise!; } -// Stop sneaky people from breaking the barrier mechanism. -const promiseThen = Promise.prototype.then; -Promise.prototype.then = function(...args) { - if (this instanceof CancellablePromise) { - return this.then(...args); - } else { - return Reflect.apply(promiseThen, this, args); - } -} - // Polyfill Promise.withResolvers. let promiseWithResolvers = Promise.withResolvers; if (promiseWithResolvers && typeof promiseWithResolvers === 'function') {