Firefox incorrectly reporting TypeError for JavaScript constructor followed immediately by cascading method calls

RESOLVED INVALID

Status

()

Firefox
Untriaged
RESOLVED INVALID
a year ago
a year ago

People

(Reporter: nadams, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 1 obsolete attachment)

162 bytes, text/html
Details
2.66 KB, application/javascript
Details
(Reporter)

Description

a year ago
Created attachment 8831261 [details]
validconstructor.js

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0
Build ID: 20161209095719

Steps to reproduce:

Load the HTML below and view the developer tools (Tools --> Web Developer --> Toggle Tools).

<html>
    <head>
        <title>Cascading constructor bug</title>
    </head>
    <body>
        <script src="validconstructor.js"></script>
    </body>
</html>



Actual results:

The associated JavaScript fails on line 111 of the attached js file.


Expected results:

Firefox should have recognized Cat2 as a constructor.

See lines 109-110 in the attached JavaScript file for more details.
(Reporter)

Comment 1

a year ago
Created attachment 8831262 [details]
constructorbug.html
(Reporter)

Comment 2

a year ago
Created attachment 8831263 [details]
validconstructor.js
Attachment #8831261 - Attachment is obsolete: true
Cat2 is undefined because Function.prototype.method returns undefined.

>     Function.prototype.method = function (name, func) {
>         if(!this.prototype[name]) {
>             this.prototype[name] = func;
>             return this;
>         }
>     };

method('get_name', ...) doesn't define "get_name" method, but does nothing and returns undefined,
since this.prototype[name] returns the following function:

> Mammal.prototype.get_name = function ( ) {
>     return this.name;
> };
Status: UNCONFIRMED → RESOLVED
Last Resolved: a year ago
Resolution: --- → INVALID
Version: 50 Branch → unspecified
(Reporter)

Comment 4

a year ago
Please excuse my confusion, but if that be the case, then why do those functions work as expected by simply not cascading the method calls (replaces lines 91-92 with lines 93-94)?

Like so:

Replace:

}
    .inherits(Mammal)
//};
//Cat2.inherits(Mammal)

With:

//}
//    .inherits(Mammal)
};
Cat2.inherits(Mammal)
when you do |x = obj.f1().f2()|, x becomes the return value of f2,
when you do |x = obj; x.f1().f2()|, x becomes obj.
they're totally different code.

x becomes same thing only if f2 returns obj, but it doesn't on your case.
You need to log in before you can comment on or make changes to this bug.