edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
From: Kevin Carhart <kevin@carhart.net>
To: edbrowse-dev@lists.the-brannons.com
Subject: [edbrowse-dev] $bp
Date: Sat, 1 Jun 2019 11:52:47 -0700 (PDT)	[thread overview]
Message-ID: <alpine.DEB.2.21.1906011151540.169627@carhart.net> (raw)


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


             reply	other threads:[~2019-06-01 19:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-01 18:52 Kevin Carhart [this message]
2019-06-01 22:06 ` Karl Dahlke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.21.1906011151540.169627@carhart.net \
    --to=kevin@carhart.net \
    --cc=edbrowse-dev@lists.the-brannons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).