Commit b43a012
committed
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>1 parent bfb2fa7 commit b43a012
1 file changed
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
919 | 919 | | |
920 | 920 | | |
921 | 921 | | |
| 922 | + | |
922 | 923 | | |
923 | 924 | | |
924 | 925 | | |
| |||
937 | 938 | | |
938 | 939 | | |
939 | 940 | | |
940 | | - | |
| 941 | + | |
941 | 942 | | |
942 | 943 | | |
943 | 944 | | |
| |||
947 | 948 | | |
948 | 949 | | |
949 | 950 | | |
| 951 | + | |
950 | 952 | | |
951 | 953 | | |
952 | 954 | | |
| |||
964 | 966 | | |
965 | 967 | | |
966 | 968 | | |
967 | | - | |
| 969 | + | |
968 | 970 | | |
969 | 971 | | |
970 | 972 | | |
| |||
0 commit comments