Skip to content

Commit c047127

Browse files
committed
contextify: throw timeout error properly
fix nodejs#7509
1 parent d519876 commit c047127

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

src/node_contextify.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ class ContextifyScript : public BaseObject {
655655
if (try_catch.HasCaught() && try_catch.HasTerminated()) {
656656
V8::CancelTerminateExecution(env->isolate());
657657
env->ThrowError("Script execution timed out.");
658+
try_catch.ReThrow();
658659
return false;
659660
}
660661

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
var assert = require('assert');
23+
var vm = require('vm');
24+
var spawn = require('child_process').spawn;
25+
26+
if (process.argv[2] === 'child') {
27+
var code = 'var j = 0;\n' +
28+
'for (var i = 0; i < 1000000; i++) j += add(i, i + 1);\n'
29+
'j;';
30+
31+
var ctx = vm.createContext({
32+
add: function(x, y) {
33+
return x + y;
34+
}
35+
});
36+
37+
vm.runInContext(code, ctx, { timeout: 1 });
38+
} else {
39+
var proc = spawn(process.execPath, process.argv.slice(1).concat('child'));
40+
var err = '';
41+
proc.stderr.on('data', function(data) {
42+
err += data;
43+
});
44+
45+
process.on('exit', function() {
46+
assert.ok(/Script execution timed out/.test(err));
47+
});
48+
}

0 commit comments

Comments
 (0)