| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent de3231c commit 02afdbc
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -117,7 +117,7 @@ const contextifiedSandbox = vm.createContext({ secret: 42 }); | |||
| 117 | 117 | // "foo" module every time it is called. In a full-fledged module system, a | |
| 118 | 118 | // cache would probably be used to avoid duplicated modules. | |
| 119 | 119 | ||
| 120 | - async function linker(referencingModule, specifier) { | ||
| 120 | + async function linker(specifier, referencingModule) { | ||
| 121 | 121 | if (specifier === 'foo') { | |
| 122 | 122 | return new vm.Module(` | |
| 123 | 123 | // The "secret" variable refers to the global variable we added to | |
@@ -319,14 +319,13 @@ can only be called once per module. | |||
| 319 | 319 | ||
| 320 | 320 | Two parameters will be passed to the `linker` function: | |
| 321 | 321 | ||
| 322 | - - `referencingModule` The `Module` object `link()` is called on. | ||
| 323 | 322 | - `specifier` The specifier of the requested module: | |
| 324 | - | ||
| 325 | 323 | <!-- eslint-skip --> | |
| 326 | 324 | ```js | |
| 327 | 325 | import foo from 'foo'; | |
| 328 | 326 | // ^^^^^ the module specifier | |
| 329 | 327 | ``` | |
| 328 | + - `referencingModule` The `Module` object `link()` is called on. | ||
| 330 | 329 | ||
| 331 | 330 | The function is expected to return a `Module` object or a `Promise` that | |
| 332 | 331 | eventually resolves to a `Module` object. The returned `Module` must satisfy the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -135,7 +135,7 @@ class Module { | |||
| 135 | 135 | const promises = []; | |
| 136 | 136 | wrap.link((specifier) => { | |
| 137 | 137 | const p = (async () => { | |
| 138 | - const m = await linker(this, specifier); | ||
| 138 | + const m = await linker(specifier, this); | ||
| 139 | 139 | if (!m || !wrapMap.has(m)) | |
| 140 | 140 | throw new errors.Error('ERR_VM_MODULE_NOT_MODULE'); | |
| 141 | 141 | if (m.context !== this.context) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -109,7 +109,7 @@ async function checkModuleState() { | |||
| 109 | 109 | ||
| 110 | 110 | { | |
| 111 | 111 | const m = new Module('import "foo";'); | |
| 112 | - await m.link(common.mustCall(async (module, specifier) => { | ||
| 112 | + await m.link(common.mustCall(async (specifier, module) => { | ||
| 113 | 113 | assert.strictEqual(module, m); | |
| 114 | 114 | assert.strictEqual(specifier, 'foo'); | |
| 115 | 115 | assert.strictEqual(m.linkingStatus, 'linking'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ async function simple() { | |||
| 18 | 18 | ||
| 19 | 19 | assert.deepStrictEqual(bar.dependencySpecifiers, ['foo']); | |
| 20 | 20 | ||
| 21 | - await bar.link(common.mustCall((module, specifier) => { | ||
| 21 | + await bar.link(common.mustCall((specifier, module) => { | ||
| 22 | 22 | assert.strictEqual(module, bar); | |
| 23 | 23 | assert.strictEqual(specifier, 'foo'); | |
| 24 | 24 | return foo; | |
@@ -38,7 +38,7 @@ async function depth() { | |||
| 38 | 38 | import ${parentName} from '${parentName}'; | |
| 39 | 39 | export default ${parentName}; | |
| 40 | 40 | `); | |
| 41 | - await mod.link(common.mustCall((module, specifier) => { | ||
| 41 | + await mod.link(common.mustCall((specifier, module) => { | ||
| 42 | 42 | assert.strictEqual(module, mod); | |
| 43 | 43 | assert.strictEqual(specifier, parentName); | |
| 44 | 44 | return parentModule; | |
@@ -68,10 +68,10 @@ async function circular() { | |||
| 68 | 68 | return foo; | |
| 69 | 69 | } | |
| 70 | 70 | `); | |
| 71 | - await foo.link(common.mustCall(async (fooModule, fooSpecifier) => { | ||
| 71 | + await foo.link(common.mustCall(async (fooSpecifier, fooModule) => { | ||
| 72 | 72 | assert.strictEqual(fooModule, foo); | |
| 73 | 73 | assert.strictEqual(fooSpecifier, 'bar'); | |
| 74 | - await bar.link(common.mustCall((barModule, barSpecifier) => { | ||
| 74 | + await bar.link(common.mustCall((barSpecifier, barModule) => { | ||
| 75 | 75 | assert.strictEqual(barModule, bar); | |
| 76 | 76 | assert.strictEqual(barSpecifier, 'foo'); | |
| 77 | 77 | assert.strictEqual(foo.linkingStatus, 'linking'); | |
@@ -111,7 +111,7 @@ async function circular2() { | |||
| 111 | 111 | }; | |
| 112 | 112 | const moduleMap = new Map(); | |
| 113 | 113 | const rootModule = new Module(sourceMap.root, { url: 'vm:root' }); | |
| 114 | - async function link(referencingModule, specifier) { | ||
| 114 | + async function link(specifier, referencingModule) { | ||
| 115 | 115 | if (moduleMap.has(specifier)) { | |
| 116 | 116 | return moduleMap.get(specifier); | |
| 117 | 117 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments