Skip to content

Commit bbd56d8

Browse files
bnoordhuisindutny
authored andcommitted
vm: don't copy Proxy object from parent context
Make vm.runInContext() and vm.runInNewContext() stop copying the Proxy object from the parent context into the new context when --harmony or --harmony_proxies is in effect because it overwrites the new context's native Proxy object. This commit also adds a regression test for Harmony symbols. They work okay in the current implementation and the test should ensure it stays that way.
1 parent 2b6e078 commit bbd56d8

4 files changed

Lines changed: 87 additions & 0 deletions

File tree

src/node_contextify.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class ContextifyContext {
157157
if (clone_property_method.IsEmpty()) {
158158
Local<String> code = FIXED_ONE_BYTE_STRING(node_isolate,
159159
"(function cloneProperty(source, key, target) {\n"
160+
" if (key === 'Proxy') return;\n"
160161
" try {\n"
161162
" var desc = Object.getOwnPropertyDescriptor(source, key);\n"
162163
" if (desc.value === source) desc.value = target;\n"

test/common.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ if (global.ArrayBuffer) {
139139
knownGlobals.push(DataView);
140140
}
141141

142+
// Harmony features.
143+
if (global.Proxy) {
144+
knownGlobals.push(Proxy);
145+
}
146+
147+
if (global.Symbol) {
148+
knownGlobals.push(Symbol);
149+
}
150+
142151
function leakedGlobals() {
143152
var leaked = [];
144153

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
// Flags: --harmony_proxies
23+
24+
var common = require('../common');
25+
var assert = require('assert');
26+
var vm = require('vm');
27+
28+
// src/node_contextify.cc filters out the Proxy object from the parent
29+
// context. Make sure that the new context has a Proxy object of its own.
30+
var sandbox = {};
31+
var result = vm.runInNewContext('this.Proxy = Proxy', sandbox);
32+
assert(typeof sandbox.Proxy === 'object');
33+
assert(sandbox.Proxy !== Proxy);
34+
35+
// Unless we copy the Proxy object explicitly, of course.
36+
var sandbox = { Proxy: Proxy };
37+
var result = vm.runInNewContext('this.Proxy = Proxy', sandbox);
38+
assert(typeof sandbox.Proxy === 'object');
39+
assert(sandbox.Proxy === Proxy);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
// Flags: --harmony_symbols
23+
24+
var common = require('../common');
25+
var assert = require('assert');
26+
var vm = require('vm');
27+
28+
// The sandbox should have its own Symbol constructor.
29+
var sandbox = {};
30+
var result = vm.runInNewContext('this.Symbol = Symbol', sandbox);
31+
assert(typeof sandbox.Symbol === 'function');
32+
assert(sandbox.Symbol !== Symbol);
33+
34+
// Unless we copy the Symbol constructor explicitly, of course.
35+
var sandbox = { Symbol: Symbol };
36+
var result = vm.runInNewContext('this.Symbol = Symbol', sandbox);
37+
assert(typeof sandbox.Symbol === 'function');
38+
assert(sandbox.Symbol === Symbol);

0 commit comments

Comments
 (0)