node/test/parallel/test-worker-vm-context-terminate.js
Anna Henningsen 0896fbedf8
vm: do not overwrite error when creating context
An empty `Local<>` already indicates that an exception is pending,
so there is no need to throw an exception. In the case of Workers,
this could override a `.terminate()` call.

PR-URL: https://github.com/nodejs/node/pull/26112
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-02-17 17:47:16 +01:00

20 lines
605 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const vm = require('vm');
const { Worker } = require('worker_threads');
// Do not use isMainThread so that this test itself can be run inside a Worker.
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
const w = new Worker(__filename);
w.on('online', common.mustCall(() => {
setTimeout(() => w.terminate(), 50);
}));
w.on('error', common.mustNotCall());
w.on('exit', common.mustCall((code) => assert.strictEqual(code, 1)));
} else {
while (true)
vm.runInNewContext('');
}