Skip to content

Commit

Permalink
vm: mark global proxy as side-effect-free
Browse files Browse the repository at this point in the history
Fixes: #27518
  • Loading branch information
addaleax committed May 1, 2019
1 parent f8cf9f9 commit 178dbb8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ using v8::PrimitiveArray;
using v8::PropertyAttribute;
using v8::PropertyCallbackInfo;
using v8::PropertyDescriptor;
using v8::PropertyHandlerFlags;
using v8::Script;
using v8::ScriptCompiler;
using v8::ScriptOrigin;
Expand Down Expand Up @@ -148,13 +149,15 @@ MaybeLocal<Context> ContextifyContext::CreateV8Context(
if (!CreateDataWrapper(env).ToLocal(&data_wrapper))
return MaybeLocal<Context>();

NamedPropertyHandlerConfiguration config(PropertyGetterCallback,
PropertySetterCallback,
PropertyDescriptorCallback,
PropertyDeleterCallback,
PropertyEnumeratorCallback,
PropertyDefinerCallback,
data_wrapper);
NamedPropertyHandlerConfiguration config(
PropertyGetterCallback,
PropertySetterCallback,
PropertyDescriptorCallback,
PropertyDeleterCallback,
PropertyEnumeratorCallback,
PropertyDefinerCallback,
data_wrapper,
PropertyHandlerFlags::kHasNoSideEffect);

IndexedPropertyHandlerConfiguration indexed_config(
IndexedPropertyGetterCallback,
Expand All @@ -163,7 +166,8 @@ MaybeLocal<Context> ContextifyContext::CreateV8Context(
IndexedPropertyDeleterCallback,
PropertyEnumeratorCallback,
IndexedPropertyDefinerCallback,
data_wrapper);
data_wrapper,
PropertyHandlerFlags::kHasNoSideEffect);

object_template->SetHandler(config);
object_template->SetHandler(indexed_config);
Expand Down
31 changes: 31 additions & 0 deletions test/parallel/test-inspector-vm-global-accessors-sideeffects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();

// Regression test for https://github.com/nodejs/node/issues/27518.

const assert = require('assert');
const inspector = require('inspector');
const vm = require('vm');

const session = new inspector.Session();
session.connect();

const context = vm.createContext({
a: 100
});

session.post('Runtime.evaluate', {
expression: 'a',
throwOnSideEffect: true,
contextId: 2 // context's id
}, (error, res) => {
assert.ifError(error),
assert.deepStrictEqual(res, {
result: {
type: 'number',
value: context.a,
description: '100'
}
});
});

0 comments on commit 178dbb8

Please sign in to comment.