From 2dfd002a7c2360abfb1270abe927960faa8aa232 Mon Sep 17 00:00:00 2001 From: smikes Date: Wed, 18 Feb 2015 14:24:36 -0700 Subject: [PATCH] vm: pass attributes from sandbox GlobalPropertyQueryCallback() was returning `None` as attributes for all properties, without regard to actual properties settings. This patch looks up attributes for sandbox-defined properties and returns them. Partial fix for gh-864 Add test for gh-864, non-default settings of object properties (e.g., `enumerable: false`) are not visible when object is used as a sandbox --- src/node_contextify.cc | 12 +++++++---- test/parallel/test-vm-preserves-property.js | 24 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 test/parallel/test-vm-preserves-property.js diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 6985a33982d749..95df6eba7b274a 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -387,11 +387,15 @@ class ContextifyContext { Local proxy_global = PersistentToLocal(isolate, ctx->proxy_global_); - bool in_sandbox = sandbox->GetRealNamedProperty(property).IsEmpty(); + bool in_sandbox = !(sandbox->GetRealNamedProperty(property).IsEmpty()); bool in_proxy_global = - proxy_global->GetRealNamedProperty(property).IsEmpty(); - if (!in_sandbox || !in_proxy_global) { - args.GetReturnValue().Set(None); + !(proxy_global->GetRealNamedProperty(property).IsEmpty()); + if (in_sandbox || in_proxy_global) { + v8::PropertyAttribute attr = None; + if (in_sandbox) { + attr = sandbox->GetPropertyAttributes(property); + } + args.GetReturnValue().Set(attr); } } diff --git a/test/parallel/test-vm-preserves-property.js b/test/parallel/test-vm-preserves-property.js new file mode 100644 index 00000000000000..f6c50315680f23 --- /dev/null +++ b/test/parallel/test-vm-preserves-property.js @@ -0,0 +1,24 @@ +var common = require('../common'); +var assert = require('assert'); + +var vm = require('vm'); + +var code = 'Object.getOwnPropertyDescriptor(this, "prop")'; + +var x = {}; +Object.defineProperty(x, "prop", { + configurable: false, + enumerable: false, + writable: false, + value: "val" +}); +var o = vm.createContext(x); + +var res = vm.runInContext(code, o, 'test'); + +assert(res); +assert.equal(typeof res, 'object'); +assert.equal(res.value, "val"); +assert.equal(res.configurable, false, "should not be configurable"); +assert.equal(res.enumerable, false, "should not be enumerable"); +assert.equal(res.writable, false, "should not be writable");