Skip to content

Commit 37a8a54

Browse files
domenicrvagg
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 <fedor@indutny.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent d4ee390 commit 37a8a54

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;
@@ -406,10 +407,15 @@ class ContextifyContext {
406407
Local<Object> proxy_global = PersistentToLocal(isolate,
407408
ctx->proxy_global_);
408409

409-
bool in_sandbox = sandbox->GetRealNamedProperty(property).IsEmpty();
410-
bool in_proxy_global =
411-
proxy_global->GetRealNamedProperty(property).IsEmpty();
412-
if (!in_sandbox || !in_proxy_global) {
410+
if (sandbox->HasRealNamedProperty(property)) {
411+
PropertyAttribute propAttr =
412+
sandbox->GetRealNamedPropertyAttributes(property).FromJust();
413+
args.GetReturnValue().Set(propAttr);
414+
} else if (proxy_global->HasRealNamedProperty(property)) {
415+
PropertyAttribute propAttr =
416+
proxy_global->GetRealNamedPropertyAttributes(property).FromJust();
417+
args.GetReturnValue().Set(propAttr);
418+
} else {
413419
args.GetReturnValue().Set(None);
414420
}
415421
}
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)