GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — module: add changes that should have been in 18394 by devsnek · Pull Request #18509 · nodejs/node

module: add changes that should have been in 18394 #18509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
devsnek wants to merge 1 commit into nodejs:master from devsnek:fix/module-linking

Uh oh!

There was an error while loading. Please reload this page.

Closed

module: add changes that should have been in 18394 #18509

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
35a175a
module: add changes that should have been in 18394
devsnek Feb 1, 2018
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

5 changes: 5 additions & 0 deletions 5 lib/internal/loader/ModuleWrap.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

// exposes ModuleWrap for testing

module.exports = internalBinding('module_wrap').ModuleWrap;
36 changes: 18 additions & 18 deletions 36 lib/internal/vm/Module.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
getConstructorOf,
customInspectSymbol,
} = require('internal/util');
const { SafePromise } = require('internal/safe_globals');

const {
ModuleWrap,
Expand Down Expand Up @@ -131,27 +132,26 @@ class Module {
const wrap = wrapMap.get(this);
if (wrap.getStatus() !== kUninstantiated)
throw new errors.Error('ERR_VM_MODULE_STATUS', 'must be uninstantiated');

linkingStatusMap.set(this, 'linking');
const promises = [];
wrap.link((specifier) => {
const p = (async () => {
const m = await linker(specifier, this);
if (!m || !wrapMap.has(m))
throw new errors.Error('ERR_VM_MODULE_NOT_MODULE');
if (m.context !== this.context)
throw new errors.Error('ERR_VM_MODULE_DIFFERENT_CONTEXT');
const childLinkingStatus = linkingStatusMap.get(m);
if (childLinkingStatus === 'errored')
throw new errors.Error('ERR_VM_MODULE_LINKING_ERRORED');
if (childLinkingStatus === 'unlinked')
await m.link(linker);
return wrapMap.get(m);
})();
promises.push(p);
return p;

const promises = wrap.link(async (specifier) => {
const m = await linker(specifier, this);
if (!m || !wrapMap.has(m))
throw new errors.Error('ERR_VM_MODULE_NOT_MODULE');
if (m.context !== this.context)
throw new errors.Error('ERR_VM_MODULE_DIFFERENT_CONTEXT');
const childLinkingStatus = linkingStatusMap.get(m);
if (childLinkingStatus === 'errored')
throw new errors.Error('ERR_VM_MODULE_LINKING_ERRORED');
if (childLinkingStatus === 'unlinked')
await m.link(linker);
return wrapMap.get(m);
});

try {
await Promise.all(promises);
if (promises !== undefined)
await SafePromise.all(promises);
linkingStatusMap.set(this, 'linked');
} catch (err) {
linkingStatusMap.set(this, 'errored');
Expand Down
1 change: 1 addition & 0 deletions 1 node.gyp
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
'lib/internal/loader/DefaultResolve.js',
'lib/internal/loader/ModuleJob.js',
'lib/internal/loader/ModuleMap.js',
'lib/internal/loader/ModuleWrap.js',
'lib/internal/loader/Translators.js',
'lib/internal/safe_globals.js',
'lib/internal/net.js',
Expand Down
2 changes: 1 addition & 1 deletion 2 src/module_wrap.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {
Local<Promise> resolve_promise = resolve_return_value.As<Promise>();
obj->resolve_cache_[specifier_std].Reset(env->isolate(), resolve_promise);

promises->Set(mod_context, specifier, resolve_promise).FromJust();
promises->Set(mod_context, i, resolve_promise).FromJust();
}

args.GetReturnValue().Set(promises);
Expand Down
29 changes: 29 additions & 0 deletions 29 test/parallel/test-internal-module-wrap.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

// Flags: --expose-internals

const common = require('../common');
common.crashOnUnhandledRejection();
const assert = require('assert');

const ModuleWrap = require('internal/loader/ModuleWrap');
const { getPromiseDetails, isPromise } = process.binding('util');
const setTimeoutAsync = require('util').promisify(setTimeout);

const foo = new ModuleWrap('export * from "bar"; 6;', 'foo');
const bar = new ModuleWrap('export const five = 5', 'bar');

(async () => {
const promises = foo.link(() => setTimeoutAsync(1000).then(() => bar));
assert.strictEqual(promises.length, 1);
assert(isPromise(promises[0]));

await Promise.all(promises);

assert.strictEqual(getPromiseDetails(promises[0])[1], bar);

foo.instantiate();

assert.strictEqual(await foo.evaluate(), 6);
assert.strictEqual(foo.namespace().five, 5);
})();
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.