Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a6dccc9

Browse filesBrowse files
aduh95ruyadorno
authored andcommitted
esm: do not bind loader hook functions
PR-URL: #44122 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent d09bc54 commit a6dccc9
Copy full SHA for a6dccc9

File tree

Expand file treeCollapse file tree

3 files changed

+24
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-11
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/esm/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/loader.js
+6-11Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const {
88
ArrayIsArray,
99
ArrayPrototypeJoin,
1010
ArrayPrototypePush,
11-
FunctionPrototypeBind,
1211
FunctionPrototypeCall,
1312
ObjectAssign,
1413
ObjectCreate,
@@ -306,16 +305,14 @@ class ESMLoader {
306305
'DeprecationWarning',
307306
);
308307

309-
// Use .bind() to avoid giving access to the Loader instance when called.
310308
if (globalPreload) {
311-
acceptedHooks.globalPreloader =
312-
FunctionPrototypeBind(globalPreload, null);
309+
acceptedHooks.globalPreloader = globalPreload;
313310
}
314311
if (resolve) {
315-
acceptedHooks.resolver = FunctionPrototypeBind(resolve, null);
312+
acceptedHooks.resolver = resolve;
316313
}
317314
if (load) {
318-
acceptedHooks.loader = FunctionPrototypeBind(load, null);
315+
acceptedHooks.loader = load;
319316
}
320317

321318
return acceptedHooks;
@@ -346,7 +343,7 @@ class ESMLoader {
346343
ArrayPrototypePush(
347344
this.#globalPreloaders,
348345
{
349-
fn: FunctionPrototypeBind(globalPreloader), // [1]
346+
fn: globalPreloader,
350347
url,
351348
},
352349
);
@@ -355,7 +352,7 @@ class ESMLoader {
355352
ArrayPrototypePush(
356353
this.#resolvers,
357354
{
358-
fn: FunctionPrototypeBind(resolver), // [1]
355+
fn: resolver,
359356
url,
360357
},
361358
);
@@ -364,15 +361,13 @@ class ESMLoader {
364361
ArrayPrototypePush(
365362
this.#loaders,
366363
{
367-
fn: FunctionPrototypeBind(loader), // [1]
364+
fn: loader,
368365
url,
369366
},
370367
);
371368
}
372369
}
373370

374-
// [1] ensure hook function is not bound to ESMLoader instance
375-
376371
this.preload();
377372
}
378373

Collapse file
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function resolve(url, _, next) {
2+
if (this != null) throw new Error('hook function must not be bound to ESMLoader instance');
3+
return next(url);
4+
}
5+
6+
export function load(url, _, next) {
7+
if (this != null) throw new Error('hook function must not be bound to ESMLoader instance');
8+
return next(url);
9+
}
10+
11+
export function globalPreload() {
12+
if (this != null) throw new Error('hook function must not be bound to ESMLoader instance');
13+
return "";
14+
}
Collapse file
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/loader-this-value-inside-hook-functions.mjs
2+
import '../common/index.mjs';
3+
4+
// Actual test is inside the loader module.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.