Skip to content

Commit b801873

Browse files
dubzzzdanielleadams
authored andcommitted
vm: properly support symbols on globals
A regression has been introduced in node 18.2.0, it makes the following snippet fails while it used to work in the past: ``` 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)); ``` Regression introduced by: #42963. So I basically attempted to start understanding what it changed to make it fix the initial issue while not breaking the symbol related one. Fixes: #45983 PR-URL: #46458 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 97ad72f commit b801873

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/node_contextify.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,9 @@ void ContextifyContext::PropertySetterCallback(
530530
return;
531531

532532
USE(ctx->sandbox()->Set(context, property, value));
533-
args.GetReturnValue().Set(value);
533+
if (is_contextual_store || is_function) {
534+
args.GetReturnValue().Set(value);
535+
}
534536
}
535537

536538
// static
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const vm = require('vm');
5+
6+
const global = vm.runInContext('this', vm.createContext());
7+
const totoSymbol = Symbol.for('toto');
8+
Object.defineProperty(global, totoSymbol, {
9+
enumerable: true,
10+
writable: true,
11+
value: 4,
12+
configurable: true,
13+
});
14+
assert.strictEqual(global[totoSymbol], 4);
15+
assert.ok(Object.getOwnPropertySymbols(global).includes(totoSymbol));

0 commit comments

Comments
 (0)