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

vm triggers multiple setters #41053

Closed
Tidyzq opened this issue Dec 2, 2021 · 1 comment
Closed

vm triggers multiple setters #41053

Tidyzq opened this issue Dec 2, 2021 · 1 comment
Labels
vm Issues and PRs related to the vm subsystem.

Comments

@Tidyzq
Copy link

Tidyzq commented Dec 2, 2021

Version

v17.2.0

Platform

Darwin tidyzq 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

const vm = require('vm')

vm.runInNewContext(`
  Object.defineProperty(globalThis, 'foo', {
    get: () => undefined,
    set(v) {
      console.log('setter', this === globalThis, this instanceof Object)
    }
  })
  globalThis.foo = 1
`, { console })

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

always reproduce.

What is the expected behavior?

We expect the above code to output:

setter true true

What do you see instead?

node v17.2.0 got the following output:

setter false false
setter true true

Additional information

Only reproduced if a setter is added to globalThis in vm. Adding setter on plain object or run outside vm got the expected output.

Reproduced in node v10.24.1, v16.5.0, v17.2.0, both in repl mode and execution mode.
Not sure about version lower than v10.

@Mesteery Mesteery added the vm Issues and PRs related to the vm subsystem. label Dec 2, 2021
@legendecas
Copy link
Member

Fixed in #42963 that the setter will be called only once.

However, the receiver of the setter is the sandbox object but not the globalThis inside the vm, which is expected bahavior, and the code snippet will print:

setter false false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants