Closed Bug 231870 Opened 21 years ago Closed 21 years ago

instanceof Event (well, any dom object) is broken - throws instead of returning false

Categories

(Core :: DOM: Core & HTML, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla1.7alpha

People

(Reporter: timeless, Assigned: peterv)

References

()

Details

Attachments

(1 file)

Steps: 1. start writing something which is supposed to analyze objects and write: function analyze(o){ if (o instanceof Event){ return "something"; } return o; } /*then call it*/ analyze("test","case"); expected result: analyze returns "test" (actual code is slightly more complicated) actual result: Error: uncaught exception: null another example from venkman: 0001: "String" instanceof Node Caught exception: “null” -- <peterv> just file a bug <Neil> nah, none of the primitives work <Neil> eww, not even [] or {} work <peterv> timeless: does it happen with other DOM classes? <peterv> well, it seems to do the same with Node <peterv> any one <Neil> and element <Neil> you can do (dom object) instanceof (dom type) <peterv> so it's in my hasinstance code <peterv> file it in DOM Other or whatever <peterv> assign it directly to me
Attached patch FixSplinter Review
Status: UNCONFIRMED → ASSIGNED
Component: DOM: Core → DOM
Ever confirmed: true
OS: Windows XP → All
Priority: -- → P3
Hardware: PC → All
Target Milestone: --- → mozilla1.7alpha
Attachment #139691 - Flags: superreview?(jst)
Attachment #139691 - Flags: review?(jst)
Comment on attachment 139691 [details] [diff] [review] Fix + if (JSVAL_IS_PRIMITIVE(v) || JSVAL_IS_VOID(v)) { + return JS_TRUE; } undefined is a primitive, so JSVAL_IS_PRIMITIVE(v) will be true if v is undefined. No need to check if JSVAL_IS_VOID(v). + JSObject *dom_obj = JSVAL_TO_OBJECT(v); if (!dom_obj) { - return JS_TRUE; + NS_ERROR("DOMJSClass_HasInstance couldn't get object"); + nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED); + + return JS_FALSE; Not necessary, if v is null, it's primitive, so you'll never get here. If you want to assert, that's fine, but no need to check. r+sr=jst with that fixed.
Attachment #139691 - Flags: superreview?(jst)
Attachment #139691 - Flags: superreview+
Attachment #139691 - Flags: review?(jst)
Attachment #139691 - Flags: review+
Checked in.
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: