2017-10-23 13:40:04 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('../common');
|
|
|
|
const vm = require('vm');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
const sym1 = Symbol('1');
|
|
|
|
const sym2 = Symbol('2');
|
|
|
|
const sandbox = {
|
|
|
|
a: true,
|
2023-02-01 09:46:55 +00:00
|
|
|
[sym1]: true,
|
2017-10-23 13:40:04 +00:00
|
|
|
};
|
|
|
|
Object.defineProperty(sandbox, 'b', { value: true });
|
|
|
|
Object.defineProperty(sandbox, sym2, { value: true });
|
|
|
|
|
|
|
|
const ctx = vm.createContext(sandbox);
|
|
|
|
|
2024-08-30 11:22:58 +00:00
|
|
|
assert.deepStrictEqual(Reflect.ownKeys(sandbox), ['a', 'b', sym1, sym2]);
|
|
|
|
assert.deepStrictEqual(Object.getOwnPropertyNames(sandbox), ['a', 'b']);
|
|
|
|
assert.deepStrictEqual(Object.getOwnPropertySymbols(sandbox), [sym1, sym2]);
|
2017-10-23 13:40:04 +00:00
|
|
|
|
|
|
|
const nativeNames = vm.runInNewContext('Object.getOwnPropertyNames(this);');
|
|
|
|
const ownNames = vm.runInContext('Object.getOwnPropertyNames(this);', ctx);
|
|
|
|
const restNames = ownNames.filter((name) => !nativeNames.includes(name));
|
2019-03-22 02:44:26 +00:00
|
|
|
// This should not fail
|
2017-10-23 13:40:04 +00:00
|
|
|
assert.deepStrictEqual(Array.from(restNames), ['a', 'b']);
|