Skip to content

vm.runInThisContext fails with top-level await #40898

Closed
@n-riesco

Description

@n-riesco

Version

v16.13.0

Platform

Linux 176bea3b1763 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 GNU/Linux

Subsystem

vm

What steps will reproduce the bug?

$ node
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> vm.runInThisContext("await 42")
evalmachine.<anonymous>:1
await 42
^^^^^

Uncaught:
SyntaxError: await is only valid in async functions and the top level bodies of modules
> 

How often does it reproduce? Is there a required condition?

always

What is the expected behavior?

Some output as running await 42.

What do you see instead?

$ node
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> await 42
42
> 

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions