GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — vm: fix property descriptors of sandbox properties · nodejs/node@659dadd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_contextify.cc
  • test/parallel
    • test-vm-preserves-property.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+10-4Lines changed: 10 additions & 4 deletions
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
}
Collapse file

‎test/parallel/test-vm-preserves-property.js‎

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
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 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.