node icon indicating copy to clipboard operation
node copied to clipboard

fix: harden check for non-module in vm.modules linker

Open MikeRalphson opened this issue 1 year ago • 9 comments

(node:528088) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/vm/module:306
        if (module[kWrap] === undefined) {
                  ^

TypeError: Cannot read properties of undefined (reading 'Symbol(kWrap)')
    at ModuleWrap.<anonymous> (node:internal/vm/module:306:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v19.9.0

Repro case:

const vm = require('node:vm');

async function main() {
  const myObj = { myProp: '' };
  const context = vm.createContext(myObj);
  const module = new vm.SourceTextModule('import * as bug from "bug";', { identifier: 'bug', context });
  await module.link(function(a,b,c){return});
}

main();

MikeRalphson avatar Apr 16 '23 16:04 MikeRalphson

Should we add a test?

Also, cc @nodejs/vm.

RaisinTen avatar Apr 17 '23 05:04 RaisinTen

@RaisinTen should that be a simple test of the exception type?

MikeRalphson avatar Apr 17 '23 06:04 MikeRalphson

I think so, yes.

RaisinTen avatar Apr 17 '23 06:04 RaisinTen

Have found the relevant test file and am working up the new test function.

MikeRalphson avatar Apr 18 '23 19:04 MikeRalphson

Is there a way to run just one of, or a subset of, the tests?

MikeRalphson avatar Apr 19 '23 07:04 MikeRalphson

Yea, you can run ./node test/parallel/test-rest-of-the-file-name.js to run an individual test

RaisinTen avatar Apr 19 '23 07:04 RaisinTen

Thanks @RaisinTen!

MikeRalphson avatar Apr 19 '23 14:04 MikeRalphson

You can also use tools/test.py test/parallel/test-rest-of-the-file-name.js or e.g. tools/test.py test/parallel/test-repl-* if you wanted to run all the REPL tests.

aduh95 avatar Apr 19 '23 14:04 aduh95

@MikeRalphson are you still working on the regression test or can somebody else pick this up?

fhinkel avatar Feb 03 '24 11:02 fhinkel

Landed in https://github.com/nodejs/node/commit/d1d5da22e4e699a8e32f3fa2a28f53a296eaec40.

legendecas avatar Mar 22 '24 09:03 legendecas