@@ -15,7 +15,6 @@ const {
1515 ObjectDefineProperty,
1616 ObjectSetPrototypeOf,
1717 PromiseAll,
18- ReflectApply,
1918 RegExpPrototypeExec,
2019 SafeArrayIterator,
2120 SafeWeakMap,
@@ -148,29 +147,22 @@ function nextHookFactory(chain, meta, { validateArgs, validateOutput }) {
148147 }
149148
150149 return ObjectDefineProperty (
151- async ( ... args ) => {
150+ async ( arg0 = undefined , context ) => {
152151 // Update only when hook is invoked to avoid fingering the wrong filePath
153152 meta . hookErrIdentifier = `${ hookFilePath } '${ hookName } '` ;
154153
155- validateArgs ( `${ meta . hookErrIdentifier } hook's ${ nextHookName } ()` , args ) ;
154+ validateArgs ( `${ meta . hookErrIdentifier } hook's ${ nextHookName } ()` , arg0 , context ) ;
156155
157156 const outputErrIdentifier = `${ chain [ generatedHookIndex ] . url } '${ hookName } ' hook's ${ nextHookName } ()` ;
158157
159158 // Set when next<HookName> is actually called, not just generated.
160159 if ( generatedHookIndex === 0 ) { meta . chainFinished = true ; }
161160
162- // `context` is an optional argument that only needs to be passed when changed
163- switch ( args . length ) {
164- case 1 : // It was omitted, so supply the cached value
165- ArrayPrototypePush ( args , meta . context ) ;
166- break ;
167- case 2 : // Overrides were supplied, so update cached value
168- ObjectAssign ( meta . context , args [ 1 ] ) ;
169- break ;
161+ if ( context ) { // `context` has already been validated, so no fancy check needed.
162+ ObjectAssign ( meta . context , context ) ;
170163 }
171164
172- ArrayPrototypePush ( args , nextNextHook ) ;
173- const output = await ReflectApply ( hook , undefined , args ) ;
165+ const output = await hook ( arg0 , meta . context , nextNextHook ) ;
174166
175167 validateOutput ( outputErrIdentifier , output ) ;
176168
@@ -575,7 +567,7 @@ class ESMLoader {
575567 shortCircuited : false ,
576568 } ;
577569
578- const validateArgs = ( hookErrIdentifier , { 0 : nextUrl , 1 : ctx } ) => {
570+ const validateArgs = ( hookErrIdentifier , nextUrl , ctx ) => {
579571 if ( typeof nextUrl !== 'string' ) {
580572 // non-strings can be coerced to a url string
581573 // validateString() throws a less-specific error
@@ -829,7 +821,7 @@ class ESMLoader {
829821 shortCircuited : false ,
830822 } ;
831823
832- const validateArgs = ( hookErrIdentifier , { 0 : suppliedSpecifier , 1 : ctx } ) => {
824+ const validateArgs = ( hookErrIdentifier , suppliedSpecifier , ctx ) => {
833825 validateString (
834826 suppliedSpecifier ,
835827 `${ hookErrIdentifier } specifier` ,
0 commit comments