Opened 16 years ago

Closed 15 years ago

Last modified 15 years ago

#900 closed defect (wontfix)

Rhino and instanceof

Reported by: [email protected] Owned by: jkuhnert
Priority: high Milestone:
Component: General Version: 0.3
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by dylan)

When using Rhino I have found that instanceof operates differently here than under any of the other Javascript engines: it will throw an exception when used on an undefined value.

For example,

var args = { }; var b = argsblah? instanceof Object;

Under Rhino, this throws an exception, but in the browser and under Spidermonkey 'b' is simply set to false. Unfortunately, many parts of dojo use instanceof against values that can be undefined expecting it to return false. This seems to mostly come from calling the dojo.lang.isFunction(), etc functions.

So, what I am wondering, is should we expect people to know that they shouldn't call dojo.lang.isFunction(), etc against possibly undefined values, or should we change the definition of these functions from (for example):

dojo.lang.isFunction = function (wh) {

return (wh instanceof Function
typeof wh == "function");


... to:

dojo.lang.isFunction = function (wh) {

return wh && (wh instanceof Function
typeof wh == "function");


Changing dojo.lang would remove most of the problems like this, and would certainly save from constantly testing and changing code to accomidate Rhino. But is that the right thing to do?

Change History (9)

comment:1 Changed 16 years ago by James Burke

It seems like it wouldn't hurt to apply to dojo.lang. What if instead of just seeing wh evaluates to true, do something that returns a true/false value:

return ((typeof wh != "undefined") && (instanceof Function
typeof wh == "function"));

I suppose it is not much of a difference, but I like the more explicit check.

Also, was this triaged as a 0.3.1 bug, or just a guess on the milestone? If it has been triaged as a 0.3.1 bug, I am willing to apply the change to use a typeof check for undefined for the dojo.lang functions.

comment:2 Changed 16 years ago by James Burke

Just talked with Alex on IRC: he said Adam Peller might be looking at this one.

comment:3 Changed 16 years ago by [email protected]



As far as we can tell, this isn't a problem on Rhino 1.6R2, which is what the Dojo test harness currently uses (but it is a problem on older versions) Perhaps this was a fixed bug in Rhino?

What version of Rhino are you using, and does 1.6R2 solve your problem? If so, do you think there's a need for this patch?

comment:4 Changed 16 years ago by [email protected]

I use Rhino 1.5R5 and 1.6R1 because they are provided by the default vendor packages on debian-testing and Gentoo respectively. I just tested 1.6R2, and you are right, it no longer does this. I have no problem personally upgrading to 1.6R2.

Not changing dojo would simply make dojo require the newest Rhino, which is not an unreasonable requirement --- considering that Javascript is the same, so why wouldn't you want the newest Rhino version? Anyway, its your (the "royal your", as in the sum of all the dojo developers) call on just how portable you want dojo to be.

comment:5 Changed 16 years ago by [email protected]

This seems to explain all of the other issues that keep coming up with people not having correct rhino versions in their classpaths...

I think I know how to fix all of the rhino problems in general, as suggested in ticket #900...but don't want to create another patch that is ignored.

comment:6 Changed 16 years ago by [email protected]

Oops...meant to say ticket #972.

comment:7 Changed 15 years ago by dylan

Description: modified (diff)
Owner: changed from anonymous to jkuhnert

comment:8 Changed 15 years ago by jkuhnert

Resolution: wontfix
Status: newclosed

As this particular issue shouldn't come up even with conflicting jars on the classpath I'm going to close this one out. (Dojo does a -jar when running unit tests.)

comment:9 Changed 15 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.