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)
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]
Updated•26 years ago
|
Assignee: mccabe → rogerl
Comment 1•26 years ago
|
||
Reassigning to Roger.
It's my code, but you'll likely be touching it soon :)
| Assignee | ||
Updated•26 years ago
|
Status: NEW → ASSIGNED
| Assignee | ||
Comment 2•26 years ago
|
||
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?
| Assignee | ||
Updated•26 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 26 years ago
Resolution: --- → FIXED
| Assignee | ||
Comment 3•26 years ago
|
||
Bug turned out to be the result of the embedding re-initializing the standard
objects before each function invocation.
| Comment hidden (collapsed) |
You need to log in
before you can comment on or make changes to this bug.
Description
•