@@ -25,35 +25,50 @@ const assert = require('assert');
25
25
const vm = require ( 'vm' ) ;
26
26
27
27
// Timeout of 100ms executing endless loop
28
- assert . throws ( function ( ) {
29
- vm . runInThisContext ( 'while(true) {}' , { timeout : 100 } ) ;
30
- } , / ^ E r r o r : S c r i p t e x e c u t i o n t i m e d o u t \. $ / ) ;
28
+ assert . throws (
29
+ function ( ) {
30
+ vm . runInThisContext ( 'while(true) {}' , { timeout : 100 } ) ;
31
+ } ,
32
+ {
33
+ code : 'ERR_SCRIPT_EXECUTION_TIMEOUT' ,
34
+ message : 'Script execution timed out after 100ms'
35
+ } ) ;
31
36
32
37
// Timeout of 1000ms, script finishes first
33
38
vm . runInThisContext ( '' , { timeout : 1000 } ) ;
34
39
35
40
// Nested vm timeouts, inner timeout propagates out
36
- assert . throws ( function ( ) {
37
- const context = {
38
- log : console . log ,
39
- runInVM : function ( timeout ) {
40
- vm . runInNewContext ( 'while(true) {}' , context , { timeout } ) ;
41
- }
42
- } ;
43
- vm . runInNewContext ( 'runInVM(10)' , context , { timeout : 10000 } ) ;
44
- throw new Error ( 'Test 5 failed' ) ;
45
- } , / S c r i p t e x e c u t i o n t i m e d o u t \. / ) ;
41
+ assert . throws (
42
+ function ( ) {
43
+ const context = {
44
+ log : console . log ,
45
+ runInVM : function ( timeout ) {
46
+ vm . runInNewContext ( 'while(true) {}' , context , { timeout } ) ;
47
+ }
48
+ } ;
49
+ vm . runInNewContext ( 'runInVM(10)' , context , { timeout : 10000 } ) ;
50
+ throw new Error ( 'Test 5 failed' ) ;
51
+ } ,
52
+ {
53
+ code : 'ERR_SCRIPT_EXECUTION_TIMEOUT' ,
54
+ message : 'Script execution timed out after 10ms'
55
+ } ) ;
46
56
47
57
// Nested vm timeouts, outer timeout is shorter and fires first.
48
- assert . throws ( function ( ) {
49
- const context = {
50
- runInVM : function ( timeout ) {
51
- vm . runInNewContext ( 'while(true) {}' , context , { timeout } ) ;
52
- }
53
- } ;
54
- vm . runInNewContext ( 'runInVM(10000)' , context , { timeout : 100 } ) ;
55
- throw new Error ( 'Test 6 failed' ) ;
56
- } , / S c r i p t e x e c u t i o n t i m e d o u t \. / ) ;
58
+ assert . throws (
59
+ function ( ) {
60
+ const context = {
61
+ runInVM : function ( timeout ) {
62
+ vm . runInNewContext ( 'while(true) {}' , context , { timeout } ) ;
63
+ }
64
+ } ;
65
+ vm . runInNewContext ( 'runInVM(10000)' , context , { timeout : 100 } ) ;
66
+ throw new Error ( 'Test 6 failed' ) ;
67
+ } ,
68
+ {
69
+ code : 'ERR_SCRIPT_EXECUTION_TIMEOUT' ,
70
+ message : 'Script execution timed out after 100ms'
71
+ } ) ;
57
72
58
73
// Nested vm timeouts, inner script throws an error.
59
74
assert . throws ( function ( ) {
0 commit comments