All users were logged out of Bugzilla on October 13th, 2018

Testing object with instanceof against its type returns false if type defined within a namespace.

RESOLVED WORKSFORME

Status

()

RESOLVED WORKSFORME
9 years ago
5 years ago

People

(Reporter: andorsalga, Unassigned)

Tracking

Trunk
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [WFM?])

Attachments

(2 attachments)

(Reporter)

Description

9 years ago
User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.3a1pre) Gecko/20091006 Minefield/3.7a1pre

Creating an instance of a class which is in a 'namespace' and then testing it with instanceof returns false in Minefield 3.7a1pre.

If the class isn't in a namespace, the conditional returns true.

Reproducible: Always

Steps to Reproduce:
1. create a namespace
var ns = {};

2. create a class within that namespace.
ns.test = function(){}

3. create an instance of that class
var iTest = new ns.test();

4. test if instance instanceof type
if(iTest instanceof ns.test)
{
 // will not run
} 
Actual Results:  
instanceof return false

Expected Results:  
instanceof should return true

instanceof returns true if the class isn't in a namespace.
(Reporter)

Comment 1

9 years ago
Created attachment 406894 [details]
test prints 2 lines. Both should be positive. 

Script has 2 tests. first test check if object is instanceof type. 
Other test checks if object is instanceof type within a namespace. Second test fails.
(Reporter)

Updated

9 years ago
Summary: Testing object with instanceof against its class returns false if class is in a namespace. → Testing object with instanceof against its type returns false if type defined within a namespace.
(Reporter)

Updated

9 years ago
Version: unspecified → Trunk
This WFM in Fx3 and 3.5 (1.9.4). Any add-ons? Anyone able to confirm? The shell testcase:

var ns = {};
ns.test = function(){};
var iTest = new ns.test();
print(iTest instanceof ns.test);

prints true as well, tm and m-c shells.

/be
(Reporter)

Comment 3

9 years ago
It works fine in FF3.5, but not in FF 3.7a1pre.

I had a JavaScript Debugger. I uninstalled it, but I get the same result.
(Reporter)

Comment 4

9 years ago
I ran this code in the error console:

var ns = {}; ns.test = function(){}; var iTest = new ns.test(); if(iTest instanceof ns.test){alert('PASS');}

and it strangely returned true.
(Reporter)

Comment 5

9 years ago
Created attachment 406914 [details]
only tests class in namespace. Prints either PASS or FAIL

Same as first test, but simply prints either PASS or FAIL.
(Reporter)

Comment 6

9 years ago
Please disregard comment #4, I was running this in 3.5 by mistake.  The test fails in 3.7a1pre when running it in the error console as well as the JavaScript shell.

I did an hg pull and did a full build, but I still have the same problem.
This appears to pass for me in
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.3a1pre) Gecko/20091016 Minefield/3.7a1pre

Comment 8

9 years ago
I tested with steps from comment 4 and it passes for me too:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.3a4pre) Gecko/20100403 Minefield/3.7a4pre

Andor, does it work for you now?
Whiteboard: [WFM?]
Still works.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.