Skip to content

Conversation

@mfdebian
Copy link
Contributor

This PR adds the missing ESM and CJS examples to their respective counterparts for the VM documentation.

For the SyntheticModule example I added the linking part just to showcase the new default.

For the vm.measureMemory([options]) example I updated the format being shown, it used to be:

{
  total: {
    jsMemoryEstimate: 2418479,
    jsMemoryRange: [2418479, 2745799],
  },
}

And now it's:

{
  total: { jsMemoryEstimate: 1601828, jsMemoryRange: [1601828, 5275288] },
  WebAssembly: { code: 0, metadata: 33962 },
}

For the example in What does it mean to "contextify" an object? I changed the error printing so we only show the expected TypeError: Cannot freeze instead of the whole error stack so now instead of seeing this:

evalmachine.<anonymous>:1
Object.freeze(globalThis);
       ^

TypeError: Cannot freeze
    at Object.freeze (<anonymous>)
    at evalmachine.<anonymous>:1:8
    at Script.runInContext (node:vm:149:12)
    at runInContext (node:vm:301:6)
    at Object.<anonymous> (/home/alpi/Documents/prjct/node/esm-vm/12globalContextify.js:8:3)
    at Module._compile (node:internal/modules/cjs/loader:1760:14)
    at Object..js (node:internal/modules/cjs/loader:1892:10)
    at Module.load (node:internal/modules/cjs/loader:1480:32)
    at Module._load (node:internal/modules/cjs/loader:1299:12)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14)

We see this:

TypeError: Cannot freeze

I did the same for the vm.constants.DONT_CONTEXTIFY examples.

Also, I believe there was a typo in the code snippet for the When microtaskMode is 'afterEvaluate', beware sharing Promises between Contexts, we where using context when in reality it should've been inner_context, I have fixed that. For that one I'm adding it's CJS counterpart.

I've tested all examples included in this PR and they all work/behave as expected now.

Thanks again for everything!

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. vm Issues and PRs related to the vm subsystem. labels Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Issues and PRs related to the documentations. vm Issues and PRs related to the vm subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants