Skip to content

Commit e5fe063

Browse files
committed
vm: enable interception on global restricted properties
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
1 parent 82bdd58 commit e5fe063

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

src/node_contextify.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,18 @@ void ContextifyContext::InitializeGlobalTemplates(IsolateData* isolate_data) {
170170
Local<ObjectTemplate> global_object_template =
171171
global_func_template->InstanceTemplate();
172172

173-
NamedPropertyHandlerConfiguration config(
174-
PropertyGetterCallback,
175-
PropertySetterCallback,
176-
PropertyQueryCallback,
177-
PropertyDeleterCallback,
178-
PropertyEnumeratorCallback,
179-
PropertyDefinerCallback,
180-
PropertyDescriptorCallback,
181-
{},
182-
PropertyHandlerFlags::kHasNoSideEffect);
173+
PropertyHandlerFlags flags = static_cast<PropertyHandlerFlags>(
174+
static_cast<int>(PropertyHandlerFlags::kHasNoSideEffect) |
175+
static_cast<int>(PropertyHandlerFlags::kHasDontDeleteProperty));
176+
NamedPropertyHandlerConfiguration config(PropertyGetterCallback,
177+
PropertySetterCallback,
178+
PropertyQueryCallback,
179+
PropertyDeleterCallback,
180+
PropertyEnumeratorCallback,
181+
PropertyDefinerCallback,
182+
PropertyDescriptorCallback,
183+
{},
184+
flags);
183185

184186
IndexedPropertyHandlerConfiguration indexed_config(
185187
IndexedPropertyGetterCallback,
@@ -190,7 +192,7 @@ void ContextifyContext::InitializeGlobalTemplates(IsolateData* isolate_data) {
190192
IndexedPropertyDefinerCallback,
191193
IndexedPropertyDescriptorCallback,
192194
{},
193-
PropertyHandlerFlags::kHasNoSideEffect);
195+
flags);
194196

195197
global_object_template->SetHandler(config);
196198
global_object_template->SetHandler(indexed_config);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
5+
const vm = require('vm');
6+
7+
const ctx = vm.createContext({});
8+
9+
// Define a non-configurable ("restricted") property on the context global.
10+
vm.runInContext(
11+
"Object.defineProperty(this, 'foo', { value: 1, configurable: false });",
12+
ctx
13+
);
14+
15+
// https://tc39.es/ecma262/#sec-globaldeclarationinstantiation 3.d:
16+
// If hasRestrictedGlobal is true, throw a SyntaxError exception.
17+
assert.throws(
18+
() => vm.runInContext('let foo = 2;', ctx),
19+
vm.runInContext('SyntaxError', ctx),
20+
);

0 commit comments

Comments
 (0)