| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -145,7 +145,9 @@ class ModuleJobBase { | |||
| 145 | 145 | */ | |
| 146 | 146 | syncLink(requestType) { | |
| 147 | 147 | // Store itself into the cache first before linking in case there are circular | |
| 148 | - // references in the linking. | ||
| 148 | + // references in the linking. Track whether we're overwriting an existing entry | ||
| 149 | + // so we know whether to remove the temporary entry in the finally block. | ||
| 150 | + const hadPreviousEntry = this.loader.loadCache.get(this.url, this.type) !== undefined; | ||
| 149 | 151 | this.loader.loadCache.set(this.url, this.type, this); | |
| 150 | 152 | const moduleRequests = this.module.getModuleRequests(); | |
| 151 | 153 | // Modules should be aligned with the moduleRequests array in order. | |
@@ -169,9 +171,14 @@ class ModuleJobBase { | |||
| 169 | 171 | } | |
| 170 | 172 | this.module.link(modules); | |
| 171 | 173 | } finally { | |
| 172 | - // Restore it - if it succeeds, we'll reset in the caller; Otherwise it's | ||
| 173 | - // not cached and if the error is caught, subsequent attempt would still fail. | ||
| 174 | - this.loader.loadCache.delete(this.url, this.type); | ||
| 174 | + if (!hadPreviousEntry) { | ||
| 175 | + // Remove the temporary entry. On failure this ensures subsequent attempts | ||
| 176 | + // don't return a broken job. On success the caller | ||
| 177 | + // (#getOrCreateModuleJobAfterResolve) will re-insert under the correct key. | ||
| 178 | + this.loader.loadCache.delete(this.url, this.type); | ||
| 179 | + } | ||
| 180 | + // If there was a previous entry (ensurePhase() path), leave this in cache - | ||
| 181 | + // it is the upgraded job and the caller will not re-insert. | ||
| 175 | 182 | } | |
| 176 | 183 | ||
| 177 | 184 | return evaluationDepJobs; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + // Regression test for source phase import identity with mixed eval/source | ||
| 2 | + // phase imports of the same module in one parent. | ||
| 3 | + import '../common/index.mjs'; | ||
| 4 | + import { spawnSyncAndAssert } from '../common/child_process.js'; | ||
| 5 | + import * as fixtures from '../common/fixtures.mjs'; | ||
| 6 | + | ||
| 7 | + spawnSyncAndAssert( | ||
| 8 | + process.execPath, | ||
| 9 | + ['--no-warnings', fixtures.path('es-modules/test-wasm-source-phase-identity.mjs')], | ||
| 10 | + { stdout: '', stderr: '', trim: true } | ||
| 11 | + ); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + import * as mod1 from './simple.wasm'; | ||
| 2 | + import * as mod2 from './simple.wasm'; | ||
| 3 | + import source mod3 from './simple.wasm'; | ||
| 4 | + import source mod4 from './simple.wasm'; | ||
| 5 | + | ||
| 6 | + export { mod1, mod2, mod3, mod4 }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,14 @@ | |||
| 1 | + import { strictEqual } from 'node:assert'; | ||
| 2 | + | ||
| 3 | + // Pre-load simple.wasm at kSourcePhase to prime the loadCache. | ||
| 4 | + const preloaded = await import.source('./simple.wasm'); | ||
| 5 | + strictEqual(preloaded instanceof WebAssembly.Module, true); | ||
| 6 | + | ||
| 7 | + // Import a parent that has both eval-phase and source-phase imports of the | ||
| 8 | + // same wasm file, which triggers ensurePhase(kEvaluationPhase) on the cached | ||
| 9 | + // job and exposes the loadCache eviction bug. | ||
| 10 | + const { mod1, mod2, mod3, mod4 } = | ||
| 11 | + await import('./test-wasm-source-phase-identity-parent.mjs'); | ||
| 12 | + | ||
| 13 | + strictEqual(mod1, mod2, 'two eval-phase imports of the same wasm must be identical'); | ||
| 14 | + strictEqual(mod3, mod4, 'two source-phase imports of the same wasm must be identical'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments