Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1878 from brendandahl/shell-perf
Make node shell performance match chrome performance.
  • Loading branch information
brendandahl committed Jan 6, 2017
2 parents 7db6285 + ce8d73b commit 46ee3e7
Showing 1 changed file with 32 additions and 46 deletions.
78 changes: 32 additions & 46 deletions shell/pluot.js
Expand Up @@ -32,52 +32,38 @@ if (inSpiderMonkey) {
}
} else {
var vm = require("vm"),
fs = require("fs");
fs = require("fs");

var sandbox = vm.createContext({
scriptArgs: Array.prototype.slice.call(process.argv, 2),
evalScript: function () {
for (var i = 0; i < arguments.length; i++) {
var path = arguments[i];
var code = fs.readFileSync(path).toString();
vm.runInContext(code, sandbox, path);
}
},
dateNow: Date.now,
pc2line: function () {

},
snarf: function (path, type) {
var buffer = fs.readFileSync(path);
return type !== 'binary' ? buffer.toString() : new Uint8Array(buffer);
},
printErr: function (msg) {
console.log(msg);
},
putstr: function (s) {
process.stdout.write(s);
},
print: function (msg) {
console.log(msg);
},
help: function () {
// simulating SpiderMonkey interface
},
quit: function (code) {
process.exit(code);
},
Uint8Array: Uint8Array,
Uint16Array: Uint16Array,
Uint32Array: Uint32Array,
Int8Array: Int8Array,
Int16Array: Int16Array,
Int32Array: Int32Array,
Float32Array: Float32Array,
Float64Array: Float64Array,
Uint8ClampedArray: Uint8ClampedArray,
ArrayBuffer: ArrayBuffer,
DataView: DataView
});
function evalScript() {
for (var i = 0; i < arguments.length; i++) {
var path = arguments[i];
var code = fs.readFileSync(path).toString();
vm.runInThisContext(code, {filename: path});
}
}
global.evalScript = evalScript;
global.dateNow = Date.now;
global.scriptArgs = Array.prototype.slice.call(process.argv, 2);
global.pc2line = function () {};
global.snarf = function (path, type) {
var buffer = fs.readFileSync(path);
return type !== 'binary' ? buffer.toString() : new Uint8Array(buffer);
};
global.printErr = function (msg) {
console.log(msg);
};
global.putstr = function (s) {
process.stdout.write(s);
};
global.print = function (msg) {
console.log(msg);
};
global.help = function () {
// simulating SpiderMonkey interface
};
global.quit = function (code) {
process.exit(code);
};

vm.runInContext('evalScript("' + startScript + '");', sandbox);
evalScript(startScript);
}

0 comments on commit 46ee3e7

Please sign in to comment.