Skip to content

Instantly share code, notes, and snippets.

@pmuellr
Created May 23, 2013 03:15
Show Gist options
  • Select an option

  • Save pmuellr/5632556 to your computer and use it in GitHub Desktop.

Select an option

Save pmuellr/5632556 to your computer and use it in GitHub Desktop.
another silly example of using v8's in-process debugger APIs
#!/usr/bin/env node
// run with `node --expose-debug-as=Debug fileName.js`
//------------------------------------------------------------------------------
// When the function f1 returns true, run function f2.
// f1 will be invoked at every debug step point.
//------------------------------------------------------------------------------
function whenDo(f1, f2) {
//--------------------------------------------------------------------------
function dummyFunc() {}
//--------------------------------------------------------------------------
function listener(event, execState, eventData, data) {
if (event != debug.DebugEvent.Break) return
try {
var result = f1()
if (result) f2()
}
catch (e) {}
execState.prepareStep(debug.StepAction.StepIn)
}
var debug = Debug.Debug
debug.setListener(listener)
debug.setBreakPoint(dummyFunc, 0, 0)
dummyFunc()
}
//------------------------------------------------------------------------------
var i
whenDo(
function(){ return i>=3 && i<=5 },
function(){ console.log("i is between 3 and 5!")}
)
for (var i=0; i<10; i++) {
console.log(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment