edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
* [edbrowse-dev] $bp
@ 2019-06-01 18:52 Kevin Carhart
  2019-06-01 22:06 ` Karl Dahlke
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Carhart @ 2019-06-01 18:52 UTC (permalink / raw)
  To: edbrowse-dev


Exciting stuff - I'm starting with $bp.  I'm unpacking the bp routine to 
understand it, so if I write up a little paraphrasing here, could you 
remark if I have grasped how it works?

The thing that you inject is eval($bp).
It's legal to call it with or without a line number passed in.  If you 
call it without a line,
it is called as $bp(0).
So now you're inside function(l)
If you passed in a line, it alerts what that line number is.
If l == 0 , it doesn't alert.
while (true) - on its own, this is an idiom for looping forever, right?
So potentially forever, you do a series of things.
Use window.prompt to prompt the user that they're at the breakpoint and 
have a REPL which is
indistinguishable from jdb.  You can run ok(window) or whatever!
The user's response is stored in res.

In case they said nothing, keep going with the infinite while(true) and 
carry on to the
try-catch.
In case they typed ".", break out of while(true) and duktape can keep 
processing JS.

Now if you're still going, you reach the try-catch
On the assumption that res is legal javascript, try to evaluate it.
If it worked, alert the returned value from eval.
If there was an error, alert the error

Now continue to while(true) forever until the user enters "."

So in aggregate, when duktape hits eval($bp), it evaluates $bp, where $bp 
is JS code in its own
right which implements a self-contained REPL.  It is indistinguishable 
from jdb and will
evaluate your JS for as long as you want.  The reason why you can find out 
about things like
transitory private variables with a brief life is simply because you're 
running a REPL at any
moment in time within the JS execution.

Very cool - I had no clue this was possible without needing to understand 
the Duktape C.

Kevin


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-01 22:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-01 18:52 [edbrowse-dev] $bp Kevin Carhart
2019-06-01 22:06 ` Karl Dahlke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).