@@ -34,17 +34,11 @@ Script.prototype.runInContext = function(contextifiedSandbox, options) {
3434} ;
3535
3636Script . prototype . runInNewContext = function ( sandbox , options ) {
37- var context = exports . createContext ( sandbox ) ;
37+ var context = createContext ( sandbox ) ;
3838 return this . runInContext ( context , options ) ;
3939} ;
4040
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 ) {
4842 if ( sandbox === undefined ) {
4943 sandbox = { } ;
5044 } else if ( binding . isContext ( sandbox ) ) {
@@ -53,28 +47,11 @@ exports.createContext = function(sandbox) {
5347
5448 binding . makeContext ( sandbox ) ;
5549 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+ }
7651
77- exports . isContext = binding . isContext ;
52+ function createScript ( code , options ) {
53+ return new Script ( code , options ) ;
54+ }
7855
7956// Remove all SIGINT listeners and re-attach them after the wrapped function
8057// has executed, so that caught SIGINT are handled by the listeners again.
@@ -100,3 +77,31 @@ function sigintHandlersWrap(fn, thisArg, argsArray) {
10077 }
10178 }
10279}
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