@@ -93,8 +93,12 @@ function Context(opt_configureForTesting) {
93
93
Buffer : Buffer ,
94
94
Error : Error ,
95
95
CLOSURE_BASE_PATH : path . dirname ( CLOSURE_BASE_FILE_PATH ) + '/' ,
96
- CLOSURE_IMPORT_SCRIPT : function ( src ) {
97
- loadScript ( src ) ;
96
+ CLOSURE_IMPORT_SCRIPT : function ( src , opt_srcText ) {
97
+ if ( opt_srcText !== undefined ) {
98
+ vm . runInContext ( opt_srcText , closure , src ) ;
99
+ } else {
100
+ loadScript ( src ) ;
101
+ }
98
102
return true ;
99
103
} ,
100
104
CLOSURE_NO_DEPS : ! isDevMode ( ) ,
@@ -114,6 +118,16 @@ function Context(opt_configureForTesting) {
114
118
loadScript ( CLOSURE_BASE_FILE_PATH ) ;
115
119
loadScript ( DEPS_FILE_PATH ) ;
116
120
121
+ // Redefine retrieveAndExecModule_ to load modules. Closure's version
122
+ // assumes XMLHttpRequest is defined (and by extension that scripts
123
+ // are being loaded from a server).
124
+ closure . goog . retrieveAndExecModule_ = function ( src ) {
125
+ var normalizedSrc = path . normalize ( src ) ;
126
+ var contents = fs . readFileSync ( normalizedSrc , 'utf8' ) ;
127
+ contents = closure . goog . wrapModule_ ( src , contents ) ;
128
+ vm . runInContext ( contents , closure , normalizedSrc ) ;
129
+ } ;
130
+
117
131
/**
118
132
* Synchronously loads a script into the protected Closure context.
119
133
* @param {string } src Path to the file to load.
0 commit comments