Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ const {
ArrayPrototypePushApply,
ArrayPrototypeSlice,
FinalizationRegistry,
FunctionPrototypeBind,
FunctionPrototypeCall,
Map,
ObjectDefineProperties,
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions lib/internal/webstreams/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const {
ArrayPrototypePush,
ArrayPrototypeShift,
AsyncIteratorPrototype,
BindPromiseTry,
FunctionPrototypeBind,
MathMax,
NumberIsNaN,
PromisePrototypeThen,
ReflectApply,
ReflectGet,
Symbol,
Uint8Array,
Expand Down Expand Up @@ -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) {
Expand Down
Loading