0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/known_issues/test-vm-ownpropertynames.js
Michaël Zasso 363091dea5 test: add failing vm tests to known_issues
Currently, `Reflect.ownKeys(this)`, `Object.getOwnPropertyNames(this)`
and `Object.getOwnPropertySymbols(this)` when run in a sandbox, fails
to retrieve Symbol and non-enumerable values.

PR-URL: https://github.com/nodejs/node/pull/16410
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-10-27 10:27:14 +02:00

29 lines
967 B
JavaScript

'use strict';
require('../common');
const vm = require('vm');
const assert = require('assert');
const sym1 = Symbol('1');
const sym2 = Symbol('2');
const sandbox = {
a: true,
[sym1]: true
};
Object.defineProperty(sandbox, 'b', { value: true });
Object.defineProperty(sandbox, sym2, { value: true });
const ctx = vm.createContext(sandbox);
// Sanity check
// Please uncomment these when the test is no longer broken
// assert.deepStrictEqual(Reflect.ownKeys(sandbox), ['a', 'b', sym1, sym2]);
// assert.deepStrictEqual(Object.getOwnPropertyNames(sandbox), ['a', 'b']);
// assert.deepStrictEqual(Object.getOwnPropertySymbols(sandbox), [sym1, sym2]);
const nativeNames = vm.runInNewContext('Object.getOwnPropertyNames(this);');
const ownNames = vm.runInContext('Object.getOwnPropertyNames(this);', ctx);
const restNames = ownNames.filter((name) => !nativeNames.includes(name));
// this should not fail
assert.deepStrictEqual(Array.from(restNames), ['a', 'b']);