Closed Bug 12010 Opened 26 years ago Closed 26 years ago

Rhino: instanceof does not appear to work properly with Date

Categories

(Core :: JavaScript Engine, defect, P3)

x86
Other
defect

Tracking

()

RESOLVED FIXED

People

(Reporter: david_gennaco, Assigned: rogerl)

Details

The function function CheckDate(d) { return (d instanceof Date); } returns false when called with the returned value of the following function function GetDate() { return new Date(); } (I use call to execute the function and then use the Java Object returned to make the CheckDate call) I traced a debug version of the Rhino API and found this in the underlying code at the end (the Object.equals() method causes the return to be false): Thread-6[1] step Thread-6[1] Step completed: thread="Thread-6", org.mozilla.javascript.ScriptRuntime.jsDelega tesTo(), line=1725, bci=0 1725 Scriptable proto = lhs.getPrototype(); 1721 * 1722 * @return true iff rhs appears in lhs' proto chain 1723 */ 1724 protected static boolean jsDelegatesTo(Scriptable lhs, Scriptable rhs) { 1725 => Scriptable proto = lhs.getPrototype(); 1726 1727 while (proto != null) { 1728 if (proto.equals(rhs)) return true; 1729 proto = proto.getPrototype(); 1730 } Thread-6[1] Thread-6[1] eval lhs.getPrototype() lhs.getPrototype() = instance of org.mozilla.javascript.NativeDate(id=1001) Thread-6[1] eval rhs rhs = instance of org.mozilla.javascript.NativeDate(id=1000) Thread-6[1]
Assignee: mccabe → rogerl
Reassigning to Roger. It's my code, but you'll likely be touching it soon :)
Status: NEW → ASSIGNED
Taken as is, I can't find a problem, the script: function CheckDate(d) { return (d instanceof Date); } function GetDate() { return new Date(); } CheckDate(GetDate()); returns 'true'. I suspect there's more going on than thi,s though? Can you provide a test case or describe the runtime environment more?
Status: ASSIGNED → RESOLVED
Closed: 26 years ago
Resolution: --- → FIXED
Bug turned out to be the result of the embedding re-initializing the standard objects before each function invocation.
You need to log in before you can comment on or make changes to this bug.