2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-09-28 00:31:36 +02:00
|
|
|
require('../common');
|
2016-12-31 00:38:06 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const vm = require('vm');
|
|
|
|
const spawn = require('child_process').spawn;
|
2014-06-13 00:40:28 +02:00
|
|
|
|
|
|
|
if (process.argv[2] === 'child') {
|
2017-01-08 14:19:00 +01:00
|
|
|
const code = 'let j = 0;\n' +
|
|
|
|
'for (let i = 0; i < 1000000; i++) j += add(i, i + 1);\n' +
|
|
|
|
'j;';
|
2014-06-13 00:40:28 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const ctx = vm.createContext({
|
2014-06-13 00:40:28 +02:00
|
|
|
add: function(x, y) {
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.runInContext(code, ctx, { timeout: 1 });
|
|
|
|
} else {
|
2017-01-08 14:19:00 +01:00
|
|
|
const proc = spawn(process.execPath, process.argv.slice(1).concat('child'));
|
|
|
|
let err = '';
|
2014-06-13 00:40:28 +02:00
|
|
|
proc.stderr.on('data', function(data) {
|
|
|
|
err += data;
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.ok(/Script execution timed out/.test(err));
|
|
|
|
});
|
|
|
|
}
|