Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,13 @@ Intercepted ContextifyContext::PropertyQueryCallback(

PropertyAttribute attr;

Maybe<bool> maybe_has = sandbox->HasRealNamedProperty(context, property);
Maybe<bool> maybe_has = sandbox->HasOwnProperty(context, property);
if (maybe_has.IsNothing()) {
return Intercepted::kNo;
} else if (maybe_has.FromJust()) {
Maybe<PropertyAttribute> maybe_attr =
sandbox->GetRealNamedPropertyAttributes(context, property);
if (!maybe_attr.To(&attr)) {
Maybe<bool> maybe_attr =
sandbox->GetPropertyAttributes(context, property, &attr);
if (!maybe_attr.FromMaybe(false)) {
return Intercepted::kNo;
}
args.GetReturnValue().Set(attr);
Expand Down
74 changes: 74 additions & 0 deletions test/parallel/test-vm-proxy-sandbox-property-query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

require('../common');
const assert = require('node:assert');
const vm = require('node:vm');

// This test ensures that Proxy-backed vm sandboxes report own properties
// consistently across descriptor and membership queries.

const sandbox = new Proxy({}, {});
const ctx = vm.createContext(sandbox);

vm.runInContext(`
Object.defineProperty(this, 'foo', {
value: 42,
writable: true,
enumerable: true,
configurable: true,
});
Object.defineProperty(this, 'hidden', {
value: 1,
enumerable: false,
configurable: true,
});
Object.defineProperty(this, 'readonly', {
value: 2,
writable: false,
enumerable: true,
configurable: true,
});
`, ctx);

const result = vm.runInContext(`({
value: foo,
descriptor: Object.getOwnPropertyDescriptor(globalThis, 'foo'),
ownNamesIncludes: Object.getOwnPropertyNames(globalThis).includes('foo'),
hasOwnProperty:
Object.prototype.hasOwnProperty.call(globalThis, 'foo'),
objectHasOwn: Object.hasOwn(globalThis, 'foo'),
inGlobalThis: 'foo' in globalThis,
reflectHas: Reflect.has(globalThis, 'foo'),
keysIncludesFoo: Object.keys(globalThis).includes('foo'),
keysIncludesHidden: Object.keys(globalThis).includes('hidden'),
hiddenIsEnumerable:
Object.prototype.propertyIsEnumerable.call(globalThis, 'hidden'),
readonlyDescriptor:
Object.getOwnPropertyDescriptor(globalThis, 'readonly'),
hasOwnToString: Object.hasOwn(globalThis, 'toString'),
toStringInGlobalThis: 'toString' in globalThis,
})`, ctx);

assert.strictEqual(result.value, 42);
assert.deepStrictEqual({ ...result.descriptor }, {
value: 42,
writable: true,
enumerable: true,
configurable: true,
});
assert.strictEqual(result.ownNamesIncludes, true);
assert.strictEqual(result.hasOwnProperty, true);
assert.strictEqual(result.objectHasOwn, true);
assert.strictEqual(result.inGlobalThis, true);
assert.strictEqual(result.reflectHas, true);
assert.strictEqual(result.keysIncludesFoo, true);
assert.strictEqual(result.keysIncludesHidden, false);
assert.strictEqual(result.hiddenIsEnumerable, false);
assert.deepStrictEqual({ ...result.readonlyDescriptor }, {
value: 2,
writable: false,
enumerable: true,
configurable: true,
});
assert.strictEqual(result.hasOwnToString, false);
assert.strictEqual(result.toStringInGlobalThis, true);
Loading