Skip to content

Commit

Permalink
driver: Check for stderr for slimerjs compatibility
Browse files Browse the repository at this point in the history
re: #229
  • Loading branch information
chfoo committed Jan 26, 2015
1 parent 5fe9337 commit 5e459ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 14 additions & 4 deletions wpull/driver/PhantomJS.hx
Expand Up @@ -28,6 +28,14 @@ class PhantomJS {
app.run();
}

function logStderrLine(message:String) {
if (system.stderr != null) {
return system.stderr.writeLine(message);
} else {
return system.stdout.writeLine(message);
}
}

/**
* Do the entire process pipeline.
*/
Expand All @@ -44,7 +52,7 @@ class PhantomJS {
*/
function setUpErrorHandler() {
phantom.onError = function (message:String, traceArray:Array<Dynamic>) {
system.stderr.writeLine(message);
logStderrLine(message);

for (traceLine in traceArray) {
var source:String;
Expand All @@ -60,7 +68,7 @@ class PhantomJS {
functionName = Reflect.field(traceLine, "function");
}

system.stderr.writeLine(' $source:${traceLine.line} $functionName');
logStderrLine(' $source:${traceLine.line} $functionName');
}
}
}
Expand Down Expand Up @@ -243,7 +251,8 @@ class PhantomJS {
event: eventName,
value: eventData
});
eventLogFile.writeLine(line);
eventLogFile.write(line);
eventLogFile.write('\n');
}

/**
Expand All @@ -259,7 +268,8 @@ class PhantomJS {
event: eventName,
value: eventData
});
actionLogFile.writeLine(line);
actionLogFile.write(line);
actionLogFile.write('\n');
}

/**
Expand Down
15 changes: 10 additions & 5 deletions wpull/driver/phantomjs.js
Expand Up @@ -24,7 +24,10 @@ PhantomJS.main = function() {
app.run();
};
PhantomJS.prototype = {
run: function() {
logStderrLine: function(message) {
if(this.system.stderr != null) return this.system.stderr.writeLine(message); else return this.system.stdout.writeLine(message);
}
,run: function() {
this.setUpErrorHandler();
this.loadConfig();
this.createPage();
Expand All @@ -34,7 +37,7 @@ PhantomJS.prototype = {
,setUpErrorHandler: function() {
var _g = this;
this.phantom.onError = function(message,traceArray) {
_g.system.stderr.writeLine(message);
_g.logStderrLine(message);
var _g1 = 0;
while(_g1 < traceArray.length) {
var traceLine = traceArray[_g1];
Expand All @@ -43,7 +46,7 @@ PhantomJS.prototype = {
var functionName = "";
if(traceLine.file != null) source = traceLine.file; else source = traceLine.sourceURL;
if(Reflect.field(traceLine,"function") != null) functionName = Reflect.field(traceLine,"function");
_g.system.stderr.writeLine(" " + source + ":" + Std.string(traceLine.line) + " " + functionName);
_g.logStderrLine(" " + source + ":" + Std.string(traceLine.line) + " " + functionName);
}
};
}
Expand Down Expand Up @@ -142,12 +145,14 @@ PhantomJS.prototype = {
,logEvent: function(eventName,eventData) {
if(this.eventLogFile == null) return;
var line = JSON.stringify({ timestamp : new Date().getTime() / 1000.0, event : eventName, value : eventData});
this.eventLogFile.writeLine(line);
this.eventLogFile.write(line);
this.eventLogFile.write("\n");
}
,logAction: function(eventName,eventData) {
if(this.actionLogFile == null) return;
var line = JSON.stringify({ timestamp : new Date().getTime() / 1000.0, event : eventName, value : eventData});
this.actionLogFile.writeLine(line);
this.actionLogFile.write(line);
this.actionLogFile.write("\n");
}
,loadUrl: function() {
var _g = this;
Expand Down

0 comments on commit 5e459ba

Please sign in to comment.