Skip to content

Commit 84c58a3

Browse files
domenicchrisdickinson
authored andcommitted
vm: fix property descriptors of sandbox properties
The GlobalPropertyQueryCallback was changed in 2010 to return an integer instead of a boolean: https://groups.google.com/forum/#!topic/v8-users/OOjHJrix-cU This integer communicates the property descriptors of the property, instead of just its presence or absence. However, the original contextify code was probably written before this change, and it was not updated when porting to Node.js. Credit to @smikes for the test and the original PR of #885. Fixes: #864 Fixes: #885 PR-URL: #1773 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 53f8549 commit 84c58a3

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/node_contextify.cc

+10-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ using v8::None;
3030
using v8::Object;
3131
using v8::ObjectTemplate;
3232
using v8::Persistent;
33+
using v8::PropertyAttribute;
3334
using v8::PropertyCallbackInfo;
3435
using v8::Script;
3536
using v8::ScriptCompiler;
@@ -409,10 +410,15 @@ class ContextifyContext {
409410
Local<Object> proxy_global = PersistentToLocal(isolate,
410411
ctx->proxy_global_);
411412

412-
bool in_sandbox = sandbox->GetRealNamedProperty(property).IsEmpty();
413-
bool in_proxy_global =
414-
proxy_global->GetRealNamedProperty(property).IsEmpty();
415-
if (!in_sandbox || !in_proxy_global) {
413+
if (sandbox->HasRealNamedProperty(property)) {
414+
PropertyAttribute propAttr =
415+
sandbox->GetRealNamedPropertyAttributes(property).FromJust();
416+
args.GetReturnValue().Set(propAttr);
417+
} else if (proxy_global->HasRealNamedProperty(property)) {
418+
PropertyAttribute propAttr =
419+
proxy_global->GetRealNamedPropertyAttributes(property).FromJust();
420+
args.GetReturnValue().Set(propAttr);
421+
} else {
416422
args.GetReturnValue().Set(None);
417423
}
418424
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
var common = require('../common');
4+
var assert = require('assert');
5+
6+
var vm = require('vm');
7+
8+
var x = {};
9+
Object.defineProperty(x, 'prop', {
10+
configurable: false,
11+
enumerable: false,
12+
writable: false,
13+
value: 'val'
14+
});
15+
var o = vm.createContext(x);
16+
17+
var code = 'Object.getOwnPropertyDescriptor(this, "prop")';
18+
var res = vm.runInContext(code, o, 'test');
19+
20+
assert(res);
21+
assert.equal(typeof res, 'object');
22+
assert.equal(res.value, 'val');
23+
assert.equal(res.configurable, false, 'should not be configurable');
24+
assert.equal(res.enumerable, false, 'should not be enumerable');
25+
assert.equal(res.writable, false, 'should not be writable');

0 commit comments

Comments
 (0)