mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
vm: mark global proxy as side-effect-free
Fixes: https://github.com/nodejs/node/issues/27518 PR-URL: https://github.com/nodejs/node/pull/27523 Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
ddbaddcce1
commit
815b3aa833
@ -61,6 +61,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;
|
||||
@ -149,13 +150,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,
|
||||
@ -164,7 +167,8 @@ MaybeLocal<Context> ContextifyContext::CreateV8Context(
|
||||
IndexedPropertyDeleterCallback,
|
||||
PropertyEnumeratorCallback,
|
||||
IndexedPropertyDefinerCallback,
|
||||
data_wrapper);
|
||||
data_wrapper,
|
||||
PropertyHandlerFlags::kHasNoSideEffect);
|
||||
|
||||
object_template->SetHandler(config);
|
||||
object_template->SetHandler(indexed_config);
|
||||
|
@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
common.skipIfInspectorDisabled();
|
||||
|
||||
// Test that if there is a side effect in a getter invoked through the vm
|
||||
// global proxy, Runtime.evaluate recognizes that.
|
||||
|
||||
const assert = require('assert');
|
||||
const inspector = require('inspector');
|
||||
const vm = require('vm');
|
||||
|
||||
const session = new inspector.Session();
|
||||
session.connect();
|
||||
|
||||
const context = vm.createContext({
|
||||
get a() {
|
||||
global.foo = '1';
|
||||
return 100;
|
||||
}
|
||||
});
|
||||
|
||||
session.post('Runtime.evaluate', {
|
||||
expression: 'a',
|
||||
throwOnSideEffect: true,
|
||||
contextId: 2 // context's id
|
||||
}, (error, res) => {
|
||||
assert.ifError(error);
|
||||
const { exception } = res.exceptionDetails;
|
||||
assert.strictEqual(exception.className, 'EvalError');
|
||||
assert(/Possible side-effect/.test(exception.description));
|
||||
|
||||
assert(context); // Keep 'context' alive and make linter happy.
|
||||
});
|
@ -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'
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user