diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index e2b5f763df7dd9..9044cd1f525d57 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -273,6 +273,7 @@ const { ArrayPrototypePushApply, ArrayPrototypeSlice, FinalizationRegistry, + FunctionPrototypeBind, FunctionPrototypeCall, Map, ObjectDefineProperties, @@ -435,6 +436,12 @@ const SafePromise = makeSafe( class SafePromise extends Promise {}, ); +{ + // eslint-disable-next-line node-core/prefer-primordials + const OriginalPromiseTry = Promise.try; + primordials.BindPromiseTry = (fn) => FunctionPrototypeBind(OriginalPromiseTry, Promise, fn); +} + /** * Attaches a callback that is invoked when the Promise is settled (fulfilled or * rejected). The resolved value cannot be modified from the callback. diff --git a/lib/internal/webstreams/util.js b/lib/internal/webstreams/util.js index 81e65815eabe6b..dabb1de6047616 100644 --- a/lib/internal/webstreams/util.js +++ b/lib/internal/webstreams/util.js @@ -7,10 +7,11 @@ const { ArrayPrototypePush, ArrayPrototypeShift, AsyncIteratorPrototype, + BindPromiseTry, + FunctionPrototypeBind, MathMax, NumberIsNaN, PromisePrototypeThen, - ReflectApply, ReflectGet, Symbol, Uint8Array, @@ -164,7 +165,7 @@ function enqueueValueWithSize(controller, value, size) { function createPromiseCallback(name, fn, thisArg) { validateFunction(fn, name); - return async (...args) => ReflectApply(fn, thisArg, args); + return BindPromiseTry(thisArg === undefined ? fn : FunctionPrototypeBind(fn, thisArg)); } function isPromisePending(promise) {