@@ -37,17 +37,11 @@ Script.prototype.runInContext = function(contextifiedSandbox, options) {
37
37
} ;
38
38
39
39
Script . prototype . runInNewContext = function ( sandbox , options ) {
40
- var context = exports . createContext ( sandbox ) ;
40
+ var context = createContext ( sandbox ) ;
41
41
return this . runInContext ( context , options ) ;
42
42
} ;
43
43
44
- exports . Script = Script ;
45
-
46
- exports . createScript = function ( code , options ) {
47
- return new Script ( code , options ) ;
48
- } ;
49
-
50
- exports . createContext = function ( sandbox ) {
44
+ function createContext ( sandbox ) {
51
45
if ( sandbox === undefined ) {
52
46
sandbox = { } ;
53
47
} else if ( binding . isContext ( sandbox ) ) {
@@ -56,28 +50,11 @@ exports.createContext = function(sandbox) {
56
50
57
51
binding . makeContext ( sandbox ) ;
58
52
return sandbox ;
59
- } ;
60
-
61
- exports . runInDebugContext = function ( code ) {
62
- return binding . runInDebugContext ( code ) ;
63
- } ;
64
-
65
- exports . runInContext = function ( code , contextifiedSandbox , options ) {
66
- var script = new Script ( code , options ) ;
67
- return script . runInContext ( contextifiedSandbox , options ) ;
68
- } ;
69
-
70
- exports . runInNewContext = function ( code , sandbox , options ) {
71
- var script = new Script ( code , options ) ;
72
- return script . runInNewContext ( sandbox , options ) ;
73
- } ;
74
-
75
- exports . runInThisContext = function ( code , options ) {
76
- var script = new Script ( code , options ) ;
77
- return script . runInThisContext ( options ) ;
78
- } ;
53
+ }
79
54
80
- exports . isContext = binding . isContext ;
55
+ function createScript ( code , options ) {
56
+ return new Script ( code , options ) ;
57
+ }
81
58
82
59
// Remove all SIGINT listeners and re-attach them after the wrapped function
83
60
// has executed, so that caught SIGINT are handled by the listeners again.
@@ -102,3 +79,31 @@ function sigintHandlersWrap(fn) {
102
79
}
103
80
}
104
81
}
82
+
83
+ function runInDebugContext ( code ) {
84
+ return binding . runInDebugContext ( code ) ;
85
+ }
86
+
87
+ function runInContext ( code , contextifiedSandbox , options ) {
88
+ return createScript ( code , options )
89
+ . runInContext ( contextifiedSandbox , options ) ;
90
+ }
91
+
92
+ function runInNewContext ( code , sandbox , options ) {
93
+ return createScript ( code , options ) . runInNewContext ( sandbox , options ) ;
94
+ }
95
+
96
+ function runInThisContext ( code , options ) {
97
+ return createScript ( code , options ) . runInThisContext ( options ) ;
98
+ }
99
+
100
+ module . exports = {
101
+ Script,
102
+ createContext,
103
+ createScript,
104
+ runInDebugContext,
105
+ runInContext,
106
+ runInNewContext,
107
+ runInThisContext,
108
+ isContext : binding . isContext
109
+ } ;
0 commit comments