Making debugged JS files editable.

RESOLVED DUPLICATE of bug 771339

Status

()

Firefox
Developer Tools: Debugger
P4
normal
RESOLVED DUPLICATE of bug 771339
6 years ago
5 years ago

People

(Reporter: espadrine, Unassigned)

Tracking

15 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
A nifty feature that Google Chrome has is the ability to modify downloaded JS files
while debugging them.
That feature is called LiveEdit in Chrome.
It reloads the JS file on-the-fly and runs it.

We already do have an editor in the debugger.
We could enable editing in a similar fashion to that of the Style editor.
Unlike the Style editor, however, we should have a way to indicate that
we are done editing the JS file, and that we want to run it.
That could be mapped to CTRL+S.
I agree this is something very valuable, but I hadn't filed a bug so far because I can't see how we could implement this.

For scripts loaded from script tags, I can imagine us maybe regenerating a data-url script with the new contents, but how can we invalidate the old? Maybe there is a way to stick a modified script in the bfcache (but what about non-cacheable scripts?) so that the script URL is the same, but does sticking a new DOM node make the new script override the previously loaded one?

Is there any way around this, short of a new SpiderMonkey API?

Comment 2

6 years ago
There are some dragons here. Jim and I spoke about this briefly in London. I think v8 must have a special API for it, because it basically swaps out function objects even in the middle of closures. It doesn't behave at all like it's rerunning the script. For example:

(function() {
  var message = "hi";

  $("button#foo").click(function() {
    alert(message);
  }
})();

Clicking on #foo will show the message. IIRC, changing message and then clicking #foo won't actually change what is displayed. Changing the alert line to:

alert("a new message");

*will* change what is displayed when you click the button.

BTW, I'm not saying we need to emulate Chrome's behavior. I'm just saying that re-running the script is probably not the behavior we want. We wouldn't want to keep adding additional click handlers after each change, for example.
(Reporter)

Comment 3

6 years ago
I am pretty sure we can't get away with a hack. V8 obviously does have an API for that [1].
This isn't an easy problem, and Chrome's behavior is surprisingly sane considering the
counter-intuitive nature of live edit.

This does need a SpiderMonkey API. It needs to re-parse the whole file, it needs to
update the bytecode, it needs to drop stack frames according to script modifications, ...

Do you know someone from the JS team with which we could talk about this?
If not, I'll just ask David Mandelin.

  [1] http://v8.googlecode.com/svn/trunk/src/liveedit.cc
Priority: -- → P4
We have plans for this over in bug 771339.
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 771339
You need to log in before you can comment on or make changes to this bug.