Skip to content

Commit 178dbb8

Browse files
committed
vm: mark global proxy as side-effect-free
Fixes: #27518
1 parent f8cf9f9 commit 178dbb8

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

src/node_contextify.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ using v8::PrimitiveArray;
6060
using v8::PropertyAttribute;
6161
using v8::PropertyCallbackInfo;
6262
using v8::PropertyDescriptor;
63+
using v8::PropertyHandlerFlags;
6364
using v8::Script;
6465
using v8::ScriptCompiler;
6566
using v8::ScriptOrigin;
@@ -148,13 +149,15 @@ MaybeLocal<Context> ContextifyContext::CreateV8Context(
148149
if (!CreateDataWrapper(env).ToLocal(&data_wrapper))
149150
return MaybeLocal<Context>();
150151

151-
NamedPropertyHandlerConfiguration config(PropertyGetterCallback,
152-
PropertySetterCallback,
153-
PropertyDescriptorCallback,
154-
PropertyDeleterCallback,
155-
PropertyEnumeratorCallback,
156-
PropertyDefinerCallback,
157-
data_wrapper);
152+
NamedPropertyHandlerConfiguration config(
153+
PropertyGetterCallback,
154+
PropertySetterCallback,
155+
PropertyDescriptorCallback,
156+
PropertyDeleterCallback,
157+
PropertyEnumeratorCallback,
158+
PropertyDefinerCallback,
159+
data_wrapper,
160+
PropertyHandlerFlags::kHasNoSideEffect);
158161

159162
IndexedPropertyHandlerConfiguration indexed_config(
160163
IndexedPropertyGetterCallback,
@@ -163,7 +166,8 @@ MaybeLocal<Context> ContextifyContext::CreateV8Context(
163166
IndexedPropertyDeleterCallback,
164167
PropertyEnumeratorCallback,
165168
IndexedPropertyDefinerCallback,
166-
data_wrapper);
169+
data_wrapper,
170+
PropertyHandlerFlags::kHasNoSideEffect);
167171

168172
object_template->SetHandler(config);
169173
object_template->SetHandler(indexed_config);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
const common = require('../common');
3+
common.skipIfInspectorDisabled();
4+
5+
// Regression test for https://github.com/nodejs/node/issues/27518.
6+
7+
const assert = require('assert');
8+
const inspector = require('inspector');
9+
const vm = require('vm');
10+
11+
const session = new inspector.Session();
12+
session.connect();
13+
14+
const context = vm.createContext({
15+
a: 100
16+
});
17+
18+
session.post('Runtime.evaluate', {
19+
expression: 'a',
20+
throwOnSideEffect: true,
21+
contextId: 2 // context's id
22+
}, (error, res) => {
23+
assert.ifError(error),
24+
assert.deepStrictEqual(res, {
25+
result: {
26+
type: 'number',
27+
value: context.a,
28+
description: '100'
29+
}
30+
});
31+
});

0 commit comments

Comments
 (0)