2018-01-13 23:35:51 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Flags: --experimental-vm-modules
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2018-07-27 21:21:30 -05:00
|
|
|
const { SourceTextModule, createContext } = require('vm');
|
2018-01-13 23:35:51 -08:00
|
|
|
|
|
|
|
(async function test1() {
|
|
|
|
const context = createContext({
|
|
|
|
foo: 'bar',
|
|
|
|
baz: undefined,
|
|
|
|
typeofProcess: undefined,
|
|
|
|
});
|
2018-07-27 21:21:30 -05:00
|
|
|
const m = new SourceTextModule(
|
2018-01-13 23:35:51 -08:00
|
|
|
'baz = foo; typeofProcess = typeof process; typeof Object;',
|
|
|
|
{ context }
|
|
|
|
);
|
|
|
|
assert.strictEqual(m.status, 'uninstantiated');
|
|
|
|
await m.link(common.mustNotCall());
|
|
|
|
m.instantiate();
|
|
|
|
assert.strictEqual(m.status, 'instantiated');
|
|
|
|
const result = await m.evaluate();
|
|
|
|
assert.strictEqual(m.status, 'evaluated');
|
|
|
|
assert.strictEqual(Object.getPrototypeOf(result), null);
|
|
|
|
assert.deepStrictEqual(context, {
|
|
|
|
foo: 'bar',
|
|
|
|
baz: 'bar',
|
|
|
|
typeofProcess: 'undefined'
|
|
|
|
});
|
|
|
|
assert.strictEqual(result.result, 'function');
|
|
|
|
}());
|
|
|
|
|
|
|
|
(async () => {
|
2018-07-27 21:21:30 -05:00
|
|
|
const m = new SourceTextModule(
|
2018-01-13 23:35:51 -08:00
|
|
|
'global.vmResult = "foo"; Object.prototype.toString.call(process);'
|
|
|
|
);
|
|
|
|
await m.link(common.mustNotCall());
|
|
|
|
m.instantiate();
|
|
|
|
const { result } = await m.evaluate();
|
|
|
|
assert.strictEqual(global.vmResult, 'foo');
|
|
|
|
assert.strictEqual(result, '[object process]');
|
|
|
|
delete global.vmResult;
|
|
|
|
})();
|
|
|
|
|
|
|
|
(async () => {
|
2018-07-27 21:21:30 -05:00
|
|
|
const m = new SourceTextModule('while (true) {}');
|
2018-01-13 23:35:51 -08:00
|
|
|
await m.link(common.mustNotCall());
|
|
|
|
m.instantiate();
|
|
|
|
await m.evaluate({ timeout: 500 })
|
|
|
|
.then(() => assert(false), () => {});
|
|
|
|
})();
|