Skip to content

Commit 4632203

Browse files
galpeterhaesik
authored andcommitted
Fix the repl example (#1920)
The REPL example was unable to use the 'require' call. IoT.js-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
1 parent 1534b2a commit 4632203

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/repl.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ stdin.prototype.readline = function(callback) {
7676
function REPL() {
7777
this.input = new stdin();
7878
this._prompt_msg = new Buffer('> ');
79-
this._repl_context = {};
8079
};
8180

8281
REPL.prototype.print_prompt = function() {
@@ -87,7 +86,8 @@ REPL.prototype.print_prompt = function() {
8786
REPL.prototype.run_code = function(line) {
8887
var result;
8988
try {
90-
result = eval.call(this._repl_context, line);
89+
/* Doing indirect eval to force everything into the global object. */
90+
result = eval.call(undefined, line);
9191
console.log(result);
9292
} catch (ex) {
9393
console.error(ex);
@@ -100,6 +100,11 @@ REPL.prototype.process_line = function(line) {
100100
};
101101

102102
REPL.prototype.start = function() {
103+
/* Expose the "require" method for the global object.
104+
* This way the "eval" call can access it correctly.
105+
*/
106+
global.require = require;
107+
103108
this.print_prompt();
104109
this.input.start();
105110
this.input.readline(this.process_line.bind(this));

0 commit comments

Comments
 (0)