Skip to content

vm triggers multiple setters #41053

@Tidyzq

Description

@Tidyzq

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions