Bug 10686

Summary: event instanceof MouseEvent throws exception
Product: WebKit Reporter: Eric Seidel (no email) <eric>
Component: JavaScriptCoreAssignee: Sam Weinig <sam>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, ggaren, mitz, sam
Priority: P2    
Version: 420+   
Hardware: Mac   
OS: OS X 10.4   
URL: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Special_Operators:instanceof_Operator
Attachments:
Description Flags
A few different instanceof tests
none
Correct testcase.
none
patch oliver: review+

Description Eric Seidel (no email) 2006-09-01 22:44:50 PDT
myDiv instanceof Element returns false!

Firefox (correctly) returns true.

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Special_Operators:instanceof_Operator
Comment 1 C Snover 2006-12-09 07:40:34 PST
Created attachment 11787 [details]
A few different instanceof tests

instanceof is a bit more broken than just Element.

I've attached a very simple testcase for instanceof. All six tests should return TRUE, but only the Object test returns TRUE; the others either return FALSE or error.
Comment 2 C Snover 2006-12-09 07:41:45 PST
Comment on attachment 11787 [details]
A few different instanceof tests

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>instanceof test</title>
		<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/>
	</head>
	<script type="text/javascript">
	// <![CDATA[
		window.addEventListener('load', function()
		{
			document.getElementById('clickme').addEventListener('click', function(evt)
			{
				try { alert("Object: "     + (evt instanceof Object));     } catch(e) { errstr(e); }
				try { alert("Event: "      + (evt instanceof Event));      } catch(e) { errstr(e); }
				try { alert("MouseEvent: " + (evt instanceof MouseEvent)); } catch(e) { errstr(e); }
				try { alert("Element: "        + (evt.target instanceof Element));        } catch(e) { errstr(e); }
				try { alert("HTMLElement: "    + (evt.target instanceof HTMLElement));    } catch(e) { errstr(e); }
				try { alert("HTMLDivElement: " + (evt.target instanceof HTMLDivElement)); } catch(e) { errstr(e); }
			}, false);
		}, false);
		
		function errstr(e)
		{
			var errstr = "";
			for(var i in e)
			{
				errstr += i + " = " + e[i] + "\n";
			}
			alert(errstr);
		};
	// ]]>
	</script>
<body>
	<div id="clickme">Click here to test instanceof Object, Event, MouseEvent, Element, HTMLElement, and HTMLDivElement (one alert per test)</div>
</body>
</html>
Comment 3 C Snover 2006-12-09 07:45:13 PST
Created attachment 11788 [details]
Correct testcase.

Whoops. That button did not do what I thought it was going to do. Sorry about the spam.
Comment 4 Geoffrey Garen 2006-12-11 23:49:14 PST
This is because the global constructors don't have .prototype properties.
Comment 5 David Kilzer (:ddkilzer) 2007-03-06 18:52:16 PST
See also Bug 12686 Comment #6.

Comment 6 Kevin McCullough 2007-03-07 14:17:47 PST
fixed in r19993.  However we still get an error for instanceof MouseEvent because MouseEvent is not a constructor.
Comment 7 David Kilzer (:ddkilzer) 2007-12-30 09:39:01 PST
(In reply to comment #6)
> fixed in r19993.  However we still get an error for instanceof MouseEvent
> because MouseEvent is not a constructor.

Same issue still occurs with r29032.

Comment 8 Sam Weinig 2007-12-30 14:12:08 PST
Created attachment 18197 [details]
patch
Comment 9 Sam Weinig 2007-12-30 14:26:34 PST
Fix landed in r29041.