-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add New spooky.exec("code") method. #43
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5686211
Add in a new spooky.exec(code) method for evaluating code within a Ca…
jeresig 9630747
Add in options argument to the exec method.
jeresig 08a97a8
Add in the ability to specify a file to execute as part of the option…
jeresig d7e35c7
Change the option formatting for 'exec' and add in a test to verify t…
jeresig 1954bcd
Add thenClick method
andresgottlieb d79bd89
Hook phantom.onError in the bootstrap script
98c7e55
Also emit trace when crashing in onError
8dc8ada
Crash if passed an invalid transport
91e242e
Use system.stdin instead of /dev/stdin
10ab181
Throw on invalid JSON input to http/stdio server
e9bc5ae
Refactor FilteredStream to be a readable-stream.Transform
336b1dc
Emit console event payloads as strings, not buffers
9ada7bf
Bump version and cut release
36c48d5
Test that stdio-server crashes if passed invalid JSON
e9ba13b
Move emit to module and provide console methods
c322bfa
Inherit Spooky from EventEmitter correctly
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function emit(event) { | ||
var args = Array.prototype.slice.call(arguments); | ||
|
||
console.log(JSON.stringify({ | ||
jsonrpc: '2.0', | ||
method: 'emit', | ||
params: args | ||
})); | ||
} | ||
|
||
module.exports.emit = emit; | ||
|
||
function getConsoleFn(level) { | ||
var args = ['console']; | ||
|
||
if (level) { | ||
args.push(level); | ||
} | ||
|
||
return function () { | ||
var args = (level ? [level] : []). | ||
concat(Array.prototype.slice.apply(arguments)); | ||
emit('console', args.join(' ')); | ||
}; | ||
} | ||
|
||
module.exports.console = { | ||
debug: getConsoleFn('debug'), | ||
info: getConsoleFn('info'), | ||
log: getConsoleFn(), | ||
warn: getConsoleFn('warn'), | ||
error: getConsoleFn('error') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
var STDIN_POLL_INTERVAL = 10; | ||
var fs = require('fs'); | ||
var stdin = fs.open('/dev/stdin', 'r'); | ||
var line; | ||
var emptyLines = 0; | ||
var start = Date.now(); | ||
var stdin = require('system').stdin; | ||
|
||
// NOTE(jeresig): If the following methods are run then stop attempting to | ||
// readLine and begin intialization. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo, should be 'initialization' |
||
var startMethods = ['run', 'exec']; | ||
|
||
var Stream = require(options.spooky_lib + 'lib/stream'); | ||
var stream = new Stream(); | ||
|
@@ -18,19 +18,24 @@ function timestamp() { | |
} | ||
|
||
function loop() { | ||
stdin.flush(); | ||
|
||
line = stdin.readLine(); | ||
|
||
line = line.replace(/\0/g, ''); | ||
|
||
if (JSON.parse(line).method !== 'run') { | ||
setTimeout(loop, STDIN_POLL_INTERVAL); | ||
} | ||
|
||
if (line !== '') { | ||
stream.emit('data', line); | ||
} | ||
var line = stdin.readLine(); | ||
|
||
try { | ||
var method = JSON.parse(line).method; | ||
|
||
// NOTE(jeresig): Only attempt to read another line of input if one of | ||
// the startMethods has not been detected. | ||
if (startMethods.indexOf(method) < 0) { | ||
setTimeout(loop, STDIN_POLL_INTERVAL); | ||
} | ||
|
||
if (line !== '') { | ||
stream.emit('data', line); | ||
} | ||
// NOTE(jeresig): Ignore malformed JSON strings | ||
} catch(e) { | ||
throw new Error('Could not parse "' + line + '" as JSON'); | ||
} | ||
} | ||
|
||
var StreamServer = require(options.spooky_lib + | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will evaluate
code
in the local scope, giving it access to the internals ofbootstrap/casper
, which is probably not desirable.Did you consider using
createFunction
here instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single quotes, please.