forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-new-vm-context.js
More file actions
42 lines (38 loc) · 943 Bytes
/
test-new-vm-context.js
File metadata and controls
42 lines (38 loc) · 943 Bytes
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
'use strict';
const common = require('../common');
const assert = require('assert');
const { Context, Script } = require('vm');
[
true, 0, null, '', 'hi',
Symbol('symbol'),
{ name: 0 },
{ origin: 0 },
{ codeGeneration: 0 },
{ codeGeneration: { strings: 0 } },
{ codeGeneration: { wasm: 0 } },
].forEach((v) => {
assert.throws(() => {
new Context(v);
}, {
code: 'ERR_INVALID_ARG_TYPE',
});
});
{
const ctx = new Context();
ctx.global.a = 1;
const script = new Script('this');
assert.strictEqual(script.runInContext(ctx), ctx.global);
}
// https://github.com/nodejs/node/issues/31808
{
const ctx = new Context();
Object.defineProperty(ctx.global, 'x', {
enumerable: true,
configurable: true,
get: common.mustNotCall(),
set: common.mustNotCall(),
});
const script = new Script('function x() {}');
script.runInContext(ctx);
assert.strictEqual(typeof ctx.global.x, 'function');
}