doc: fix import.meta example for vm.SourceTextModule · nodejs/node@2a2effa · GitHub
Skip to content

Commit 2a2effa

Browse files
zeeshan56656aduh95
authored andcommitted
doc: fix import.meta example for vm.SourceTextModule
The import.meta example for new vm.SourceTextModule() in vm.md does not run as written. It fails in two separate ways. First, the constructor is missing the context: contextifiedObject option, so the module evaluates in the top context where secret is not defined, and the snippet throws ReferenceError: secret is not defined. Second, the trailing note suggests replacing meta.prop = {} with vm.runInContext('{}', contextifiedObject), but '{}' is parsed as an empty block and evaluates to undefined. That makes the following Object.getPrototypeOf(import.meta.prop) throw TypeError. Wrapping it as '({})' returns an object, which is what the note intends. This adds the context option and corrects the suggested replacement to '({})' in both the mjs and cjs variants. Fixes: #64076 Signed-off-by: Muhammad Zeeshan <61280174+zeeshan56656@users.noreply.github.com> PR-URL: #64112 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent c879f91 commit 2a2effa

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

doc/api/vm.md

Lines changed: 4 additions & 2 deletions

0 commit comments

Comments
 (0)