Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behavior of node:vm.runInThisContext() #17853

Closed
BerndAmend opened this issue Jan 28, 2023 · 0 comments · Fixed by #18767
Closed

Incorrect behavior of node:vm.runInThisContext() #17853

BerndAmend opened this issue Jan 28, 2023 · 0 comments · Fixed by #18767
Labels
bug Something isn't working correctly needs triage node compat

Comments

@BerndAmend
Copy link

BerndAmend commented Jan 28, 2023

Describe the bug

The node:vm.runInThisContext() function doesn't behave correctly on deno.

Node:
vm.runInThisContext("let p = 12"); console.log(p)
12

Deno:
vm.runInThisContext("let p = 12"); console.log(p)
Uncaught ReferenceError: p is not defined
at :3:13

On deno this function is implemented as return eval.call(globalThis, this.code); (https://github.com/denoland/deno_std/blob/main/node/vm.ts#L14).
It is not possible with eval to define local variables (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval).

In the past this didn't cause any issues for me since Deno.core.evalContext() provided an equivalent API.
Sadly this API was dropped in deno version 1.30.

const _tmp_err = Deno.core.evalContext(code)[1]; if (_tmp_err !== null) throw _tmp_err.thrown;

The behavior of the function should be implemented using Deno.core.evalContext().

Steps to Reproduce

Start deno

import * as vm from "node:vm";
vm.runInThisContext("let p = 12"); console.log(p)

Expected behavior

12 should be printed to the console.

Environment

  • OS: Archlinux
  • deno version: 1.30
  • std version: 0.174.0
@BerndAmend BerndAmend added bug Something isn't working correctly needs triage labels Jan 28, 2023
@BerndAmend BerndAmend changed the title Incorrect behavior of vm.runInThisContext() Incorrect behavior of node:vm.runInThisContext() Jan 28, 2023
@kt3k kt3k mentioned this issue Feb 21, 2023
14 tasks
@kt3k kt3k transferred this issue from denoland/std Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly needs triage node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants