| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aa657f0 commit a3c7a63
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,7 @@ const { | |||
| 26 | 26 | ModuleWrap, | |
| 27 | 27 | kErrored, | |
| 28 | 28 | kEvaluated, | |
| 29 | + kEvaluating, | ||
| 29 | 30 | kEvaluationPhase, | |
| 30 | 31 | kInstantiated, | |
| 31 | 32 | kUninstantiated, | |
@@ -338,8 +339,14 @@ class ModuleJob extends ModuleJobBase { | |||
| 338 | 339 | return { __proto__: null, module: this.module, namespace }; | |
| 339 | 340 | } | |
| 340 | 341 | throw this.module.getError(); | |
| 341 | - | ||
| 342 | - } else if (status === kEvaluated) { | ||
| 342 | + } else if (status === kEvaluating || status === kEvaluated) { | ||
| 343 | + // kEvaluating can show up when this is being used to deal with CJS <-> CJS cycles. | ||
| 344 | + // Allow it for now, since we only need to ban ESM <-> CJS cycles which would be | ||
| 345 | + // detected earlier during the linking phase, though the CJS handling in the ESM | ||
| 346 | + // loader won't be able to emit warnings on pending circular exports like what | ||
| 347 | + // the CJS loader does. | ||
| 348 | + // TODO(joyeecheung): remove the re-invented require() in the ESM loader and | ||
| 349 | + // always handle CJS using the CJS loader to eliminate the quirks. | ||
| 343 | 350 | return { __proto__: null, module: this.module, namespace: this.module.getNamespaceSync() }; | |
| 344 | 351 | } | |
| 345 | 352 | assert.fail(`Unexpected module status ${status}.`); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -783,11 +783,10 @@ void ModuleWrap::GetNamespaceSync(const FunctionCallbackInfo<Value>& args) { | |||
| 783 | 783 | return realm->env()->ThrowError( | |
| 784 | 784 | "Cannot get namespace, module has not been instantiated"); | |
| 785 | 785 | case Module::Status::kInstantiated: | |
| 786 | + case Module::Status::kEvaluating: | ||
| 786 | 787 | case Module::Status::kEvaluated: | |
| 787 | 788 | case Module::Status::kErrored: | |
| 788 | 789 | break; | |
| 789 | - case Module::Status::kEvaluating: | ||
| 790 | - UNREACHABLE(); | ||
| 791 | 790 | } | |
| 792 | 791 | ||
| 793 | 792 | if (module->IsGraphAsync()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,20 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // This tests that --import preload does not break CJS entry points that contains | ||
| 4 | + // require cycles. | ||
| 5 | + | ||
| 6 | + require('../common'); | ||
| 7 | + const fixtures = require('../common/fixtures'); | ||
| 8 | + const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| 9 | + | ||
| 10 | + spawnSyncAndAssert( | ||
| 11 | + process.execPath, | ||
| 12 | + [ | ||
| 13 | + '--import', | ||
| 14 | + fixtures.fileURL('import-require-cycle/preload.mjs'), | ||
| 15 | + fixtures.path('import-require-cycle/c.js'), | ||
| 16 | + ], | ||
| 17 | + { | ||
| 18 | + stdout: /cycle equality true/, | ||
| 19 | + } | ||
| 20 | + ); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + module.exports.b = require('./b.js'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + module.exports.a = require('./a.js'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + const obj = require('./b.js'); | ||
| 2 | + | ||
| 3 | + console.log('cycle equality', obj.a.b === obj); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + import * as mod from "module"; | ||
| 2 | + | ||
| 3 | + mod.registerHooks({ | ||
| 4 | + load(url, context, nextLoad) { | ||
| 5 | + return nextLoad(url, context); | ||
| 6 | + }, | ||
| 7 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments