Inspector should support $(id) in the command line for Firebug parity.
Putting the code below into Console._evalInInspectedWindow kind of works. I'll investigate a better way though. expression = "(function () { \ var $ = $ || function(id) { return document.getElementById(id); }; \ var $$ = $$ || function(cl) { return document.getElementsByClassName(cl); }; \ var $x = $x || function(xpath, context) { \ var nodes = []; \ try { \ var doc = context || document; \ var results = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null); \ var node; \ while (node = results.iterateNext()) nodes.push(node); \ } catch (e) {} \ return nodes; \ }; \ var keys = keys || function(o) { var a = []; for (k in o) a.push(k); return a; }; \ var values = values || function(o) { var a = []; for (k in o) a.push(o[k]); return a; }; \ return (" + expression + ")})();";
Just a comment about $$. It should be a wrapper for document.querySelectorAll instead of document.getElementsByClassName.
Sorry, thats a mistake.
I realized this is horribly wrong. I can't even do for loops.
Created attachment 22127 [details] patch I used "with" and it works fairly well.
Comment on attachment 22127 [details] patch + expression = "with (testAPI) { " + expression + " }"; I think using with like this will change the meaning of "this" in the user's expression. It should be pretty easy to test this. We definitely don't want to change "this"! It looks like Firebug uses window.__scope__, which I assume is a Mozilla-specific extension. Maybe Geoff Garen would have some ideas about how best to accomplish this.
<rdar://problem/6070209>
(In reply to comment #6) > (From update of attachment 22127 [details] [edit]) > + expression = "with (testAPI) { " + expression + " }"; > > I think using with like this will change the meaning of "this" in the user's > expression. It should be pretty easy to test this. We definitely don't want to > change "this"! Keishi tells me that I was wrong and this approach does not modify the value of "this". That's great! Geoff, would you mind commenting on the approach here?
Comment on attachment 22127 [details] patch Putting back to r? and marking Geoff as a potential reviewer.
Created attachment 22695 [details] test if "this" changes I ran these commands in the command line and this is what I got. I don't think "this" changes. $("gbar"); $$("p"); $x("/html/body/div"); keys(console); values(console); window===this this
Comment on attachment 22127 [details] patch You should rename testAPI to be more unique. Like __inspectorConsoleAPI. Also it might be better to explicitly assign __inspectorConsoleAPI t the window instead f using var. So: window. __inspectorConsoleAPI = ...
Created attachment 22727 [details] patch I've added profile/profileEnd but they don't work quite well. It picks up the anonymous function that it's wrapped with. Also the result doesn't get updated. Maybe profile not getting updated should be a bug on it's own.
Comment on attachment 22727 [details] patch + if (!inspectedWindow._inspectorCommandLineAPI) You should put braces around that if block, since it is multiple lines. Also you should improve the ChangeLog to call out what functions you are changing and add more description before the Reviewed by line. The < > and commas aren't needed for the bug list. Just put one per line. Please file a bug about the profiler issues you mentioned.
Landed in r35676.