MCPcopy Index your code
hub / github.com/nodejs/node / checkLinking

Function checkLinking

test/parallel/test-vm-module-errors.js:114–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

112
113// Check link() fails when the returned module is not valid.
114async function checkLinking() {
115 await assert.rejects(async () => {
116 const m = new SourceTextModule('import "foo";');
117 try {
118 await m.link(common.mustCall(() => ({})));
119 } catch (err) {
120 assert.strictEqual(m.status, 'errored');
121 throw err;
122 }
123 }, {
124 code: 'ERR_VM_MODULE_NOT_MODULE'
125 });
126
127 await assert.rejects(async () => {
128 const c = createContext({ a: 1 });
129 const foo = new SourceTextModule('', { context: c });
130 await foo.link(common.mustNotCall());
131 const bar = new SourceTextModule('import "foo";');
132 try {
133 await bar.link(common.mustCall(() => foo));
134 } catch (err) {
135 assert.strictEqual(bar.status, 'errored');
136 throw err;
137 }
138 }, {
139 code: 'ERR_VM_MODULE_DIFFERENT_CONTEXT'
140 });
141
142 const error = new Error();
143 await assert.rejects(async () => {
144 globalThis.error = error;
145 const erroredModule = new SourceTextModule('throw error;');
146 await erroredModule.link(common.mustNotCall());
147 try {
148 await erroredModule.evaluate();
149 } catch {
150 // ignored
151 }
152 delete globalThis.error;
153
154 assert.strictEqual(erroredModule.status, 'errored');
155
156 const rootModule = new SourceTextModule('import "errored";');
157 await rootModule.link(common.mustCall(() => erroredModule));
158 }, {
159 code: 'ERR_VM_MODULE_LINK_FAILURE',
160 cause: error,
161 });
162}
163
164assert.throws(() => {
165 new SourceTextModule('', {

Callers 1

Calls 3

createContextFunction · 0.85
linkMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…