Skip to content

Commit ed116dc

Browse files
committed
test: fix test for inherited properties on vm
The known issue is fixed with #16293. The text needs to call `Object.hasOwnProperty(this)` instead of `this.hasOwnProperty()`, otherwise `this` is from the wrong context is used. Add a second test case taken verbatim from issue #5350 PR-URL: #16411 Fixes: #5350 Ref: #16293 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 9c6f6b0 commit ed116dc

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

test/known_issues/test-vm-inherited_properties.js

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const vm = require('vm');
6+
const assert = require('assert');
7+
8+
let base = {
9+
propBase: 1
10+
};
11+
12+
let sandbox = Object.create(base, {
13+
propSandbox: { value: 3 }
14+
});
15+
16+
const context = vm.createContext(sandbox);
17+
18+
let result = vm.runInContext('Object.hasOwnProperty(this, "propBase");',
19+
context);
20+
21+
assert.strictEqual(result, false);
22+
23+
// Ref: https://github.com/nodejs/node/issues/5350
24+
base = Object.create(null);
25+
base.x = 1;
26+
base.y = 2;
27+
28+
sandbox = Object.create(base);
29+
sandbox.z = 3;
30+
31+
assert.deepStrictEqual(Object.keys(sandbox), ['z']);
32+
33+
const code = 'x = 0; z = 4;';
34+
result = vm.runInNewContext(code, sandbox);
35+
assert.strictEqual(result, 4);
36+
37+
// Check that y is not an own property.
38+
assert.deepStrictEqual(Object.keys(sandbox), ['z', 'x']);

0 commit comments

Comments
 (0)