@@ -4,13 +4,12 @@ const {
44 ArrayPrototypePush,
55 ArrayPrototypeShift,
66 AsyncIteratorPrototype,
7+ FunctionPrototypeCall,
78 MathMax,
89 NumberIsNaN,
910 PromisePrototypeThen,
1011 PromiseReject,
1112 PromiseResolve,
12- ReflectGet,
13- ReflectApply,
1413 Symbol,
1514} = primordials ;
1615
@@ -147,9 +146,25 @@ function enqueueValueWithSize(controller, value, size) {
147146 controller [ kState ] . queueTotalSize += size ;
148147}
149148
150- function createPromiseCallback ( name , fn , thisArg ) {
149+ // Arity-specialized variants of the promise-callback wrapper. The generic
150+ // rest-parameter + ReflectApply form allocated an arguments array on every
151+ // invocation; these run on per-chunk hot paths (pull/write/transform), so
152+ // each known call-site arity gets its own wrapper. The exact number of
153+ // arguments passed through to the user callback is observable and must be
154+ // preserved.
155+ function createPromiseCallbackNoParams ( name , fn , thisArg ) {
151156 validateFunction ( fn , name ) ;
152- return async ( ...args ) => ReflectApply ( fn , thisArg , args ) ;
157+ return async ( ) => FunctionPrototypeCall ( fn , thisArg ) ;
158+ }
159+
160+ function createPromiseCallback1Param ( name , fn , thisArg ) {
161+ validateFunction ( fn , name ) ;
162+ return async ( arg ) => FunctionPrototypeCall ( fn , thisArg , arg ) ;
163+ }
164+
165+ function createPromiseCallback2Params ( name , fn , thisArg ) {
166+ validateFunction ( fn , name ) ;
167+ return async ( arg1 , arg2 ) => FunctionPrototypeCall ( fn , thisArg , arg1 , arg2 ) ;
153168}
154169
155170function isPromisePending ( promise ) {
@@ -208,7 +223,9 @@ module.exports = {
208223 canCopyArrayBuffer,
209224 cloneAsUint8Array,
210225 copyArrayBuffer,
211- createPromiseCallback,
226+ createPromiseCallbackNoParams,
227+ createPromiseCallback1Param,
228+ createPromiseCallback2Params,
212229 customInspect,
213230 defaultSizeAlgorithm,
214231 dequeueValue,
0 commit comments