forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-vm-global-property-enumerator.js
More file actions
101 lines (95 loc) · 2.56 KB
/
Copy pathtest-vm-global-property-enumerator.js
File metadata and controls
101 lines (95 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'use strict';
require('../common');
const globalNames = require('../common/globals');
const vm = require('vm');
const assert = require('assert');
// Regression of https://github.com/nodejs/node/issues/53346
const cases = [
{
get key() {
return 'value';
},
},
{
// Intentionally single setter.
// eslint-disable-next-line accessor-pairs
set key(value) {},
},
{},
{
key: 'value',
},
(new class GetterObject {
get key() {
return 'value';
}
}()),
(new class SetterObject {
// Intentionally single setter.
// eslint-disable-next-line accessor-pairs
set key(value) {
// noop
}
}()),
[],
[['key', 'value']],
{
__proto__: {
key: 'value',
},
},
(() => {
const obj = {
__proto__: {
[Symbol.toStringTag]: 'proto',
},
};
Object.defineProperty(obj, '1', {
value: 'value',
enumerable: false,
configurable: true,
});
Object.defineProperty(obj, 'key', {
value: 'value',
enumerable: false,
configurable: true,
});
Object.defineProperty(obj, Symbol('symbol'), {
value: 'value',
enumerable: false,
configurable: true,
});
Object.defineProperty(obj, Symbol('symbol-enumerable'), {
value: 'value',
enumerable: true,
configurable: true,
});
return obj;
})(),
];
for (const [idx, obj] of cases.entries()) {
const ctx = vm.createContext(obj);
const globalObj = vm.runInContext('this', ctx);
assert.deepStrictEqual(Object.keys(globalObj), Object.keys(obj), `Case ${idx} failed: Object.keys`);
const ownPropertyNamesInner = difference(Object.getOwnPropertyNames(globalObj), globalNames.intrinsics);
const ownPropertyNamesOuter = Object.getOwnPropertyNames(obj);
assert.deepStrictEqual(
ownPropertyNamesInner,
ownPropertyNamesOuter,
`Case ${idx} failed: Object.getOwnPropertyNames`
);
// FIXME(legendecas): globalThis[@@toStringTag] is unconditionally
// initialized to the sandbox's constructor name, even if it does not exist
// on the sandbox object. This may incorrectly initialize the prototype
// @@toStringTag on the globalThis as an own property, like
// Window.prototype[@@toStringTag] should be a property on the prototype.
assert.deepStrictEqual(
Object.getOwnPropertySymbols(globalObj).filter((it) => it !== Symbol.toStringTag),
Object.getOwnPropertySymbols(obj),
`Case ${idx} failed: Object.getOwnPropertySymbols`
);
}
function difference(arrA, arrB) {
const setB = new Set(arrB);
return arrA.filter((x) => !setB.has(x));
};