Skip to content

Commit bb7abed

Browse files
committed
Add support for loading goog.modules in node.
1 parent 5f00124 commit bb7abed

File tree

1 file changed

+16
-2
lines changed
  • javascript/node/selenium-webdriver

1 file changed

+16
-2
lines changed

javascript/node/selenium-webdriver/_base.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,12 @@ function Context(opt_configureForTesting) {
9393
Buffer: Buffer,
9494
Error: Error,
9595
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+
}
98102
return true;
99103
},
100104
CLOSURE_NO_DEPS: !isDevMode(),
@@ -114,6 +118,16 @@ function Context(opt_configureForTesting) {
114118
loadScript(CLOSURE_BASE_FILE_PATH);
115119
loadScript(DEPS_FILE_PATH);
116120

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+
117131
/**
118132
* Synchronously loads a script into the protected Closure context.
119133
* @param {string} src Path to the file to load.

0 commit comments

Comments
 (0)