Closed Bug 522924 Opened 15 years ago Closed 11 years ago

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

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: andorsalga, Unassigned)

Details

(Whiteboard: [WFM?])

Attachments

(2 files)

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.
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.
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.
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
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.
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.
Same as first test, but simply prints either PASS or FAIL.
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
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
Closed: 11 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: