| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6582b19 commit 4cc4195
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -378,7 +378,7 @@ class ModuleLoader { | |||
| 378 | 378 | throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename); | |
| 379 | 379 | } | |
| 380 | 380 | const status = job.module.getStatus(); | |
| 381 | - debug('Module status', filename, status); | ||
| 381 | + debug('Module status', job, status); | ||
| 382 | 382 | if (status === kEvaluated) { | |
| 383 | 383 | return { wrap: job.module, namespace: job.module.getNamespaceSync(filename, parentFilename) }; | |
| 384 | 384 | } else if (status === kInstantiated) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,14 @@ let debug = require('internal/util/debuglog').debuglog('esm', (fn) => { | |||
| 22 | 22 | debug = fn; | |
| 23 | 23 | }); | |
| 24 | 24 | ||
| 25 | - const { ModuleWrap, kEvaluationPhase, kInstantiated } = internalBinding('module_wrap'); | ||
| 25 | + const { | ||
| 26 | + ModuleWrap, | ||
| 27 | + kErrored, | ||
| 28 | + kEvaluated, | ||
| 29 | + kEvaluationPhase, | ||
| 30 | + kInstantiated, | ||
| 31 | + kUninstantiated, | ||
| 32 | + } = internalBinding('module_wrap'); | ||
| 26 | 33 | const { | |
| 27 | 34 | privateSymbols: { | |
| 28 | 35 | entry_point_module_private_symbol, | |
@@ -280,17 +287,34 @@ class ModuleJob extends ModuleJobBase { | |||
| 280 | 287 | runSync(parent) { | |
| 281 | 288 | assert(this.phase === kEvaluationPhase); | |
| 282 | 289 | assert(this.module instanceof ModuleWrap); | |
| 283 | - if (this.instantiated !== undefined) { | ||
| 284 | - return { __proto__: null, module: this.module }; | ||
| 290 | + let status = this.module.getStatus(); | ||
| 291 | + | ||
| 292 | + debug('ModuleJob.runSync', this.module); | ||
| 293 | + // FIXME(joyeecheung): this cannot fully handle < kInstantiated. Make the linking | ||
| 294 | + // fully synchronous instead. | ||
| 295 | + if (status === kUninstantiated) { | ||
| 296 | + this.module.async = this.module.instantiateSync(); | ||
| 297 | + status = this.module.getStatus(); | ||
| 285 | 298 | } | |
| 299 | + if (status === kInstantiated || status === kErrored) { | ||
| 300 | + const filename = urlToFilename(this.url); | ||
| 301 | + const parentFilename = urlToFilename(parent?.filename); | ||
| 302 | + this.module.async ??= this.module.isGraphAsync(); | ||
| 286 | 303 | ||
| 287 | - this.module.instantiate(); | ||
| 288 | - this.instantiated = PromiseResolve(); | ||
| 289 | - setHasStartedUserESMExecution(); | ||
| 290 | - const filename = urlToFilename(this.url); | ||
| 291 | - const parentFilename = urlToFilename(parent?.filename); | ||
| 292 | - const namespace = this.module.evaluateSync(filename, parentFilename); | ||
| 293 | - return { __proto__: null, module: this.module, namespace }; | ||
| 304 | + if (this.module.async && !getOptionValue('--experimental-print-required-tla')) { | ||
| 305 | + throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename); | ||
| 306 | + } | ||
| 307 | + if (status === kInstantiated) { | ||
| 308 | + setHasStartedUserESMExecution(); | ||
| 309 | + const namespace = this.module.evaluateSync(filename, parentFilename); | ||
| 310 | + return { __proto__: null, module: this.module, namespace }; | ||
| 311 | + } | ||
| 312 | + throw this.module.getError(); | ||
| 313 | + | ||
| 314 | + } else if (status === kEvaluated) { | ||
| 315 | + return { __proto__: null, module: this.module, namespace: this.module.getNamespaceSync() }; | ||
| 316 | + } | ||
| 317 | + assert.fail(`Unexpected module status ${status}.`); | ||
| 294 | 318 | } | |
| 295 | 319 | ||
| 296 | 320 | async run(isEntryPoint = false) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,6 +52,7 @@ void NODE_EXTERN_PRIVATE FWrite(FILE* file, const std::string& str); | |||
| 52 | 52 | V(NGTCP2_DEBUG) \ | |
| 53 | 53 | V(SEA) \ | |
| 54 | 54 | V(WASI) \ | |
| 55 | + V(MODULE) \ | ||
| 55 | 56 | V(MKSNAPSHOT) \ | |
| 56 | 57 | V(SNAPSHOT_SERDES) \ | |
| 57 | 58 | V(PERMISSION_MODEL) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -815,6 +815,16 @@ void ModuleWrap::GetStatus(const FunctionCallbackInfo<Value>& args) { | |||
| 815 | 815 | args.GetReturnValue().Set(module->GetStatus()); | |
| 816 | 816 | } | |
| 817 | 817 | ||
| 818 | + void ModuleWrap::IsGraphAsync(const FunctionCallbackInfo<Value>& args) { | ||
| 819 | + Isolate* isolate = args.GetIsolate(); | ||
| 820 | + ModuleWrap* obj; | ||
| 821 | + ASSIGN_OR_RETURN_UNWRAP(&obj, args.This()); | ||
| 822 | + | ||
| 823 | + Local<Module> module = obj->module_.Get(isolate); | ||
| 824 | + | ||
| 825 | + args.GetReturnValue().Set(module->IsGraphAsync()); | ||
| 826 | + } | ||
| 827 | + | ||
| 818 | 828 | void ModuleWrap::GetError(const FunctionCallbackInfo<Value>& args) { | |
| 819 | 829 | Isolate* isolate = args.GetIsolate(); | |
| 820 | 830 | ModuleWrap* obj; | |
@@ -1171,6 +1181,7 @@ void ModuleWrap::CreatePerIsolateProperties(IsolateData* isolate_data, | |||
| 1171 | 1181 | isolate, tpl, "createCachedData", CreateCachedData); | |
| 1172 | 1182 | SetProtoMethodNoSideEffect(isolate, tpl, "getNamespace", GetNamespace); | |
| 1173 | 1183 | SetProtoMethodNoSideEffect(isolate, tpl, "getStatus", GetStatus); | |
| 1184 | + SetProtoMethodNoSideEffect(isolate, tpl, "isGraphAsync", IsGraphAsync); | ||
| 1174 | 1185 | SetProtoMethodNoSideEffect(isolate, tpl, "getError", GetError); | |
| 1175 | 1186 | SetConstructorFunction(isolate, target, "ModuleWrap", tpl); | |
| 1176 | 1187 | isolate_data->set_module_wrap_constructor_template(tpl); | |
@@ -1227,6 +1238,7 @@ void ModuleWrap::RegisterExternalReferences( | |||
| 1227 | 1238 | registry->Register(GetNamespace); | |
| 1228 | 1239 | registry->Register(GetStatus); | |
| 1229 | 1240 | registry->Register(GetError); | |
| 1241 | + registry->Register(IsGraphAsync); | ||
| 1230 | 1242 | ||
| 1231 | 1243 | registry->Register(CreateRequiredModuleFacade); | |
| 1232 | 1244 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,6 +111,7 @@ class ModuleWrap : public BaseObject { | |||
| 111 | 111 | static void Instantiate(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 112 | 112 | static void Evaluate(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 113 | 113 | static void GetNamespace(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 114 | + static void IsGraphAsync(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 114 | 115 | static void GetStatus(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 115 | 116 | static void GetError(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 116 | 117 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + import '../common/index.mjs'; | ||
| 2 | + import assert from 'node:assert'; | ||
| 3 | + import { b, c } from '../fixtures/es-modules/require-module-instantiated/a.mjs'; | ||
| 4 | + assert.strictEqual(b, c); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + export { default as b } from './b.cjs'; | ||
| 2 | + export { default as c } from './c.mjs'; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + module.exports = require('./c.mjs'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + const foo = 1; | ||
| 2 | + export default foo; | ||
| 3 | + export { foo as 'module.exports' }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments