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