vm module regression in node 18.2.0: failing to list properties of an object

Version

18.2.0

Platform

Linux codespaces-828c09 5.4.0-1094-azure #100~18.04.1-Ubuntu SMP Mon Oct 17 11:44:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

While trying to understand a bug in Jest (see jestjs/jest#13338) that started to appear on node 18.2.0 (worked on node 18.1.0), I fall onto the issue #42962 and its fix #42963.

So I played a bit with vm and it turns out that the code below worked in node 18.1.0 while it started to fail on node 18.2.0. This code is close to what Jest does internally so it might explain the issue observed on Jest's side (see code in Jest https://github.com/facebook/jest/blob/fb2de8a10f8e808b080af67aa771f67b5ea537ce/packages/jest-environment-node/src/index.ts#L72).

const assert = require('assert');
const vm = require('vm');
const global = vm.runInContext('this', vm.createContext());
const totoSymbol = Symbol.for('toto');
Object.defineProperty(global, totoSymbol, {
  enumerable: true,
  writable: true,
  value: 4,
  configurable: true,
});
assert(Object.getOwnPropertySymbols(global).includes(totoSymbol));

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

Always

What is the expected behavior?

The code should pass.

What do you see instead?

The code crashes.

Additional information

Just ran some additional manual tries:

// after the defineProperty
console.log(Object.getOwnPropertySymbols(myglobal)); // []
console.log(myglobal[totoSymbol]); // 4