Skip to content

Commit

Permalink
Fix the repl example (jerryscript-project#1920)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
galpeter authored and haesik committed Jul 16, 2019
1 parent 1534b2a commit 4632203
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tools/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ stdin.prototype.readline = function(callback) {
function REPL() {
this.input = new stdin();
this._prompt_msg = new Buffer('> ');
this._repl_context = {};
};

REPL.prototype.print_prompt = function() {
Expand All @@ -87,7 +86,8 @@ REPL.prototype.print_prompt = function() {
REPL.prototype.run_code = function(line) {
var result;
try {
result = eval.call(this._repl_context, line);
/* Doing indirect eval to force everything into the global object. */
result = eval.call(undefined, line);
console.log(result);
} catch (ex) {
console.error(ex);
Expand All @@ -100,6 +100,11 @@ REPL.prototype.process_line = function(line) {
};

REPL.prototype.start = function() {
/* Expose the "require" method for the global object.
* This way the "eval" call can access it correctly.
*/
global.require = require;

this.print_prompt();
this.input.start();
this.input.readline(this.process_line.bind(this));
Expand Down

0 comments on commit 4632203

Please sign in to comment.