Bug 142061 - Web Inspector: Save Console Evaluations into Command Line variables $1-$99 ($n)
Summary: Web Inspector: Save Console Evaluations into Command Line variables $1-$99 ($n)
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords: InRadar
: 140864 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-02-26 15:11 PST by Joseph Pecoraro
Modified: 2015-05-05 21:07 PDT (History)
7 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (62.27 KB, patch)
2015-02-26 16:06 PST, Joseph Pecoraro
timothy: review+
Details | Formatted Diff | Diff
[IMAGE] Basic $n in console (74.42 KB, image/png)
2015-02-26 16:06 PST, Joseph Pecoraro
no flags Details
[IMAGE] UI in Preview / Tree and Property Path tooltips (65.59 KB, image/png)
2015-02-26 16:07 PST, Joseph Pecoraro
no flags Details
[IMAGE] Looping, after $99 reuse $1... (131.29 KB, image/png)
2015-02-26 16:08 PST, Joseph Pecoraro
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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. ***