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