Bug 139655

Summary: Web Inspector: functions and accessors not shown when debugger paused in constructor
Product: WebKit Reporter: Brian Burg <burg>
Component: Web InspectorAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: graouts, joepeck, timothy, webkit-bug-importer
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Better test case none

Description Brian Burg 2014-12-15 14:56:27 PST
As I understand it, the new operator creates an empty object, sets the prototype field, then calls the constructor. However, functions from the prototype do not show up in autocomplete or the details sidebar when the debugger pauses within a constructor.

Test case:

Foo = new function() {
    this._luckyNumber = 3;
    debugger;
}

Foo.prototype = {
    get luck() { return this._luckyNumber; },
    set luck(v) { this._luckyNumber = v; },
    toString: function() { return "" + this._luckyNumber; }
}
    
var f = new Foo();
f.luck = 4;
f.luck;
f.toString();
Comment 1 Joseph Pecoraro 2014-12-15 15:04:23 PST
> Foo = new function() {
>     this._luckyNumber = 3;
>     debugger;
> }
>
> [snip]
> 
> var f = new Foo();

As written, this causes an exception. Since you are doing "Foo = new function" up above and then "new Foo".

    [Error] TypeError: Object is not a constructor (evaluating 'new Foo()')

Things behave as expected when you create the constructor:

    function Foo() {
        this._luckyNumber = 3;
        debugger;
    }

Is there still an issue here?
Comment 2 Joseph Pecoraro 2014-12-15 15:05:50 PST
(In reply to comment #0)
> As I understand it, the new operator creates an empty object, sets the
> prototype field, then calls the constructor. However, functions from the
> prototype do not show up in autocomplete or the details sidebar when the
> debugger pauses within a constructor.
> 
> Test case:
> 
> Foo = new function() {
>     this._luckyNumber = 3;
>     debugger;
> }
> 
> Foo.prototype = {
>     get luck() { return this._luckyNumber; },
>     set luck(v) { this._luckyNumber = v; },
>     toString: function() { return "" + this._luckyNumber; }
> }

Also, as written the debugger pauses inside the "new function" without having assigned the prototype yet. So the debugger was behaving correctly then.
Comment 3 Brian Burg 2014-12-15 15:12:47 PST
Created attachment 243313 [details]
Better test case
Comment 4 Joseph Pecoraro 2014-12-16 11:16:20 PST
The test case behaves as expected right now, but can be improved. The console autocompletes prototype properties, and expanding this -> proto -> you see luck getter / setters.

We are looking to improve the object display (Object Properties tree) in:
<https://webkit.org/b/137306> Web Inspector: Expanding event objects in console shows undefined for most values, it should have real values

Specifically:
https://bugs.webkit.org/show_bug.cgi?id=137306#c3

Lets dup?

*** This bug has been marked as a duplicate of bug 137306 ***