Bug 142061

Summary: Web Inspector: Save Console Evaluations into Command Line variables $1-$99 ($n)
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: Web InspectorAssignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: graouts, joepeck, jonowells, mattbaker, nvasilyev, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
[PATCH] Proposed Fix
timothy: review+
[IMAGE] Basic $n in console
none
[IMAGE] UI in Preview / Tree and Property Path tooltips
none
[IMAGE] Looping, after $99 reuse $1... none

Description Joseph Pecoraro 2015-02-26 15:11:33 PST
* SUMMARY
Save Console Evaluations into Command Line variables $1-$99 ($n).

Currently:
- $0 is special (often the selected node in the DOM tree, or potentially other uses for the item in context within the frontend).
- $1-$4 mean "the previous $0 values" pushed into this list. They are not useful or commonly used.

Proposal:
- $0 remains the same
- $1-$99 assign to unique non-null/non-undefined console evaluations

For example:

  js> 10 + 15 // new value, stashed in $n
  <-  25 = $1

  js> "hello" + "world" // new value, stashed in $n
  <-  "helloworld" = $2

  js> [$1, $2] // new value, stashed in $n
  <-  [25, "helloworld"] = $3

  js> null // not a useful value, do not stash
  <-  null

  js> 100 - 75 // value already stashed (strict equality existing values), show the existing $n
  <-  25 = $1
Comment 1 Radar WebKit Bug Importer 2015-02-26 15:11:52 PST
<rdar://problem/19976979>
Comment 2 Joseph Pecoraro 2015-02-26 16:06:14 PST
Created attachment 247459 [details]
[PATCH] Proposed Fix
Comment 3 Joseph Pecoraro 2015-02-26 16:06:49 PST
Created attachment 247460 [details]
[IMAGE] Basic $n in console
Comment 4 Joseph Pecoraro 2015-02-26 16:07:44 PST
Created attachment 247461 [details]
[IMAGE] UI in Preview / Tree and Property Path tooltips
Comment 5 Joseph Pecoraro 2015-02-26 16:08:28 PST
Created attachment 247462 [details]
[IMAGE] Looping, after $99 reuse $1...
Comment 6 Timothy Hatcher 2015-02-26 16:26:14 PST
Comment on attachment 247459 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=247459&action=review

> Source/JavaScriptCore/inspector/InjectedScriptSource.js:841
> +        for (var i = 1; i < this._savedResults.length; ++i) {
> +            if (this._savedResults[i] === result) {
> +                this._savedResultIndex = i;
> +                return;
> +            }
> +        }

var existingIndex = this._savedResults.indexOf(result);
if (existingIndex != -1) {
    this._savedResultIndex = existingIndex;
    return;
}

> Source/JavaScriptCore/inspector/InjectedScriptSource.js:1189
> +        this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));

Slick.

> Source/WebCore/inspector/CommandLineAPIModuleSource.js:127
> +        this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));

Why do we need this twice again?

> Source/WebInspectorUI/UserInterface/Views/ConsoleMessageImpl.js:334
> +        if (!this.savedResultIndex)
> +            return null;

What will this display as?
Comment 7 Joseph Pecoraro 2015-02-26 16:37:57 PST
(In reply to comment #6)
> Comment on attachment 247459 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=247459&action=review
> 
> > Source/JavaScriptCore/inspector/InjectedScriptSource.js:841
> > +        for (var i = 1; i < this._savedResults.length; ++i) {
> > +            if (this._savedResults[i] === result) {
> > +                this._savedResultIndex = i;
> > +                return;
> > +            }
> > +        }
> 
> var existingIndex = this._savedResults.indexOf(result);
> if (existingIndex != -1) {
>     this._savedResultIndex = existingIndex;
>     return;
> }

Nice!


> > Source/JavaScriptCore/inspector/InjectedScriptSource.js:1189
> > +        this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));
> 
> Slick.
> 
> > Source/WebCore/inspector/CommandLineAPIModuleSource.js:127
> > +        this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));
> 
> Why do we need this twice again?

We have BasicCommandLineAPI (JSContext) and CommandLineAPI (Web Page / DOM aware).

Someday I will try to merge the two to prevent duplication. Already JSContext inspection lacks command line api basics like "keys", "values", "dir", "log", etc. However we provide a few basics with no outside knowledge. See <rdar://problem/19184801> for even more thoughts on this.


> > Source/WebInspectorUI/UserInterface/Views/ConsoleMessageImpl.js:334
> > +        if (!this.savedResultIndex)
> > +            return null;
> 
> What will this display as?

The default root property path in ObjectTreeView will be "obj":

    this._propertyPath = propertyPath || new WebInspector.PropertyPath(this._object, "obj");

Suggestions welcome.
Comment 8 Joseph Pecoraro 2015-02-26 16:45:36 PST
> > > Source/WebInspectorUI/UserInterface/Views/ConsoleMessageImpl.js:334
> > > +        if (!this.savedResultIndex)
> > > +            return null;
> > 
> > What will this display as?
> 
> The default root property path in ObjectTreeView will be "obj":
> 
>     this._propertyPath = propertyPath || new
> WebInspector.PropertyPath(this._object, "obj");
> 
> Suggestions welcome.

Changing to "this" per IRC discussion.
Comment 9 Joseph Pecoraro 2015-02-26 17:17:18 PST
http://trac.webkit.org/changeset/180715
Comment 10 Joseph Pecoraro 2015-05-05 21:07:46 PDT
*** Bug 140864 has been marked as a duplicate of this bug. ***