Bug 17907

Summary: Inspector should support Firebug's magic $0 variable to access inspected node
Product: WebKit Reporter: Adam Roben (:aroben) <aroben>
Component: Web Inspector (Deprecated)Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Enhancement CC: abarth, emacemac7, joepeck, mjs, rik, timothy
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 14355    
Attachments:
Description Flags
not working patch
none
Implements $0, $1, $n
none
set history limit to 5
none
Syntax fixes
none
No more $n timothy: review+

Description Adam Roben (:aroben) 2008-03-17 21:02:18 PDT
Firebug has a magic $1 variable that's available from the Console to access the inspected node. We should support this variable in the Inspector's Console.
Comment 1 Timothy Hatcher 2008-03-17 21:08:40 PDT
Thats a shame that Firebug uses $1. I was considering doing the gdb $n to refer to previous console results. More people might be familiar with Firebug's concept though.
Comment 2 Adam Roben (:aroben) 2008-06-04 08:29:09 PDT
*** Bug 19390 has been marked as a duplicate of this bug. ***
Comment 3 Anthony Ricaud 2008-06-06 08:33:25 PDT
$1 isn't available in Firebug 1.2b2. I don't know if it's a bug or if they abandoned it.

By the way, I've asked other web developers, nobody knew this shortcut.

Maybe you could agreed with Firebug developers on a more standard way to do this.
Comment 4 Adam Roben (:aroben) 2008-07-11 14:06:17 PDT
<rdar://problem/6070208>
Comment 5 Keishi Hattori 2008-08-14 09:19:12 PDT
According to this old documentation, I think $0 is the inspected node.
http://www.joehewitt.com/software/firebug/docs.php
Comment 6 Keishi Hattori 2008-08-14 09:23:28 PDT
Created attachment 22794 [details]
not working patch

$0 seems to receive the appropriate object, but the security seems to block usage. For example, calling "$0" seems OK, but calling "$0.innerHTML" returns undefined. I tried doing wrapCallback on the node but that doesn't work either.
Comment 7 Maciej Stachowiak 2008-10-01 10:07:16 PDT
Maybe this could have a less obscure name, like console.selectedNode or something. With autocomplete the typing is not a big deal and it is more memorable and less likely to conflict than $0.

Comment 8 Adam Roben (:aroben) 2008-10-01 10:23:40 PDT
(In reply to comment #7)
> Maybe this could have a less obscure name, like console.selectedNode or
> something.

Putting it on the console object may not be ideal, since it's unlikely we want web pages to have access to this variable.
Comment 9 Keishi Hattori 2009-07-21 15:33:29 PDT
Created attachment 33221 [details]
Implements $0, $1, $n

I've finally figured this out.

JSInspectorCallbackWrapper wraps the return value with JSInspectorCallbackWrapper::wrapOutgoingValue. It wraps it as a JSInspectorCallbackWrapper, which blocks getProperty, setProperty, deleteProperty, construct, hasInstance, and getPropertyNames.

I think this is overkill for objects from the "inspected window" but a necessary security measure for objects from the "inspector".

$0 - Variable containing the most recently inspected object .
$1 - Variable containing the next most recently inspected object .
$n(n) - Returns the nth most recently inspected object that has been inspected.
Comment 10 Keishi Hattori 2009-07-21 15:48:42 PDT
Created attachment 33223 [details]
set history limit to 5

The history limit seems to be 5 in firebug.
Comment 11 Timothy Hatcher 2009-07-21 16:59:23 PDT
Comment on attachment 33223 [details]
set history limit to 5

> +                profileEnd: function() { return console.profileEnd.apply(console, arguments) }, \
> +                 _inspectedNodes: [], \
> +                _addInspectedNode: function(node) { \

The indentation is one space off for _inspectedNodes.

+                      var _inspectedNodes = _inspectorCommandLineAPI._inspectedNodes; \

The local variable should not have an underscore prefix.

> +                $n: function(n) { return _inspectorCommandLineAPI._inspectedNodes[n] } \

Firebug really adds a $n function? Not just $0, $1, $2, $3 and $4?
Comment 12 Joseph Pecoraro 2009-07-21 18:07:31 PDT
> Firebug really adds a $n function? Not just $0, $1, $2, $3 and $4?

Yah, documentation on this is rather hidden. Its at the bottom of Joe Hewitt's site:
http://joehewitt.com/software/firebug/docs.php
Comment 13 Keishi Hattori 2009-07-21 20:49:53 PDT
Created attachment 33237 [details]
Syntax fixes

$n is pointless. It's only in their old outdated documentation anyway. (The assert* commands seems to have been deprecated) 

I vote to ditch it.
Comment 14 Timothy Hatcher 2009-07-21 20:51:19 PDT
Lets ditch $n.
Comment 15 Keishi Hattori 2009-07-21 21:00:17 PDT
Created attachment 33238 [details]
No more $n
Comment 16 Adam Barth 2009-07-24 01:31:41 PDT
Committing to http://svn.webkit.org/repository/webkit/trunk ...
	M	WebCore/ChangeLog
	M	WebCore/inspector/front-end/Console.js
	M	WebCore/inspector/front-end/ElementsPanel.js
Committed r46338
	M	WebCore/ChangeLog
	M	WebCore/inspector/front-end/ElementsPanel.js
	M	WebCore/inspector/front-end/Console.js
r46338 = 4e1d680f3088d0cdd0b49c04acba4a47421cc311 (trunk)
No changes between current HEAD and refs/remotes/trunk
Resetting to the latest refs/remotes/trunk
http://trac.webkit.org/changeset/46338