<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>27169</bug_id>
          
          <creation_ts>2009-07-10 18:12:10 -0700</creation_ts>
          <short_desc>typing &quot;document.__proto__&quot; in inspector throws exception</short_desc>
          <delta_ts>2011-05-03 01:54:04 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Inspector (Deprecated)</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>60014</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Eric Seidel (no email)">eric</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>abarth</cc>
    
    <cc>joepeck</cc>
    
    <cc>keishi</cc>
    
    <cc>timothy</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>131035</commentid>
    <comment_count>0</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-07-10 18:12:10 -0700</bug_when>
    <thetext>typing &quot;document.__proto__&quot; in inspector throws exception

&gt; document.__proto__
file:///Users/eseidel/Projects/build/Debug/WebCore.framework/Resources/inspector/utilities.js:843TypeError: Result of expression &apos;this.nodeName&apos; [undefined] is not an object.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>134044</commentid>
    <comment_count>1</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2009-07-22 23:48:47 -0700</bug_when>
    <thetext>After some digging it appears this is a rather weird edge case that can be reduced to this:

&gt; typeof document.__proto__
object

&gt; document.__proto__ instanceof window.Node
true

&gt; document.__proto__.nodeName
undefined

&gt; document.__proto__.nodeType
undefined


So when the formatter actually gets down to formating as a node, jumps into utilities.js&apos;s nodeTitleInfo(), does a switch on obj.nodeType (undefined) which hits the default case and tries obj.nodeName and throws the error.

The Javascript workaround that I feel is the most responsible would be to treat &quot;document.__proto__&quot; as the type it returns via &quot;typeof&quot;, which is &quot;object&quot;, instead of &quot;node&quot;.  To be more general, if something is an &quot;instanceof Node&quot; then to really be sure its a node it should have a &quot;nodeType&quot; property.  Otherwise its lieing!

Maybe the solution is to change something in the Document C++ implementation so document.__proto__ instanceof &quot;Node&quot; returns false instead of true.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>134045</commentid>
    <comment_count>2</comment_count>
      <attachid>33317</attachid>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2009-07-22 23:53:16 -0700</bug_when>
    <thetext>Created attachment 33317
Javascript Workaround

This would be the javascript workaround.  I looked into what Firefox does and they don&apos;t report document.__proto__ as an instanceof Node!  So maybe that would be the better route.

WebKit via Web Inspector:
&gt; document.__proto__ instanceof window.Node
true

Firefox via Firebug:
&gt; document.__proto__ instanceof window.Node
false</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>134081</commentid>
    <comment_count>3</comment_count>
    <who name="Keishi Hattori">keishi</who>
    <bug_when>2009-07-23 04:54:27 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; This would be the javascript workaround.  I looked into what Firefox does and
&gt; they don&apos;t report document.__proto__ as an instanceof Node!  So maybe that
&gt; would be the better route.

Opera returns false too.

But I can&apos;t figure out why.

From my understanding, the implementation of
    FOO instanceof BAR
should be something like this
function instanceof(FOO, BAR) {
    var o = FOO;
    while (o = o.__proto__) {
        if (o === BAR.prototype)
            return true;
    }
    return false;
}
And I think this is written in JSObject::hasInstance which implements [[hasInstance]] from the spec.

WebCore&apos;s prototype chain looks like this
document.__proto__ = HTMLDocumentPrototype
document.__proto__. __proto__ = DocumentPrototype
document.__proto__. __proto__. __proto__ = NodePrototype
document.__proto__. __proto__. __proto__.__proto__ = Object

And 
(Node.prototype === document.__proto__. __proto__. __proto__) is true

So (document.__proto__ instanceof window.Node) returns true.

In Firefox (Node.prototype === document.__proto__. __proto__. __proto__) is also true so I don&apos;t understand why Firefox is returning false for (document.__proto__ instanceof window.Node).

Which is correct?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>134169</commentid>
    <comment_count>4</comment_count>
    <who name="Timothy Hatcher">timothy</who>
    <bug_when>2009-07-23 11:37:42 -0700</bug_when>
    <thetext>obj.nodeType === undefined

would be best written as:

typeof obj.nodeType === &quot;undefined&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>134172</commentid>
    <comment_count>5</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-07-23 11:40:32 -0700</bug_when>
    <thetext>Did we decide there was a real bug here in either WebKit or Firefox?  If so, we should file it...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>134178</commentid>
    <comment_count>6</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2009-07-23 11:49:42 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; Did we decide there was a real bug here in either WebKit or Firefox?  If so, we
&gt; should file it...

Filed.
https://bugs.webkit.org/show_bug.cgi?id=27611</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>134468</commentid>
    <comment_count>7</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2009-07-24 02:14:53 -0700</bug_when>
    <thetext>Committing to http://svn.webkit.org/repository/webkit/trunk ...
	M	WebCore/ChangeLog
	M	WebCore/inspector/front-end/utilities.js
Committed r46345
	M	WebCore/ChangeLog
	M	WebCore/inspector/front-end/utilities.js
r46345 = 1203ffee2d3ca9a82f4ecd7eecf5061b5a6091e0 (trunk)
No changes between current HEAD and refs/remotes/trunk
Resetting to the latest refs/remotes/trunk
http://trac.webkit.org/changeset/46345</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>33317</attachid>
            <date>2009-07-22 23:53:16 -0700</date>
            <delta_ts>2009-07-23 11:27:24 -0700</delta_ts>
            <desc>Javascript Workaround</desc>
            <filename>patch.patch</filename>
            <type>text/plain</type>
            <size>1036</size>
            <attacher name="Joseph Pecoraro">joepeck</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1dlYkNvcmUvQ2hhbmdlTG9nIGIvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXgg
ZmMzODY5Ni4uZWM1M2RhYSAxMDA2NDQKLS0tIGEvV2ViQ29yZS9DaGFuZ2VMb2cKKysrIGIvV2Vi
Q29yZS9DaGFuZ2VMb2cKQEAgLTEsMyArMSwxMyBAQAorMjAwOS0wNy0yMiAgSm9zZXBoIFBlY29y
YXJvICA8am9lcGVjazAyQGdtYWlsLmNvbT4KKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkg
KE9PUFMhKS4KKworICAgICAgICB0eXBpbmcgImRvY3VtZW50Ll9fcHJvdG9fXyIgaW4gaW5zcGVj
dG9yIHRocm93cyBleGNlcHRpb24KKyAgICAgICAgaHR0cHM6Ly9idWdzLndlYmtpdC5vcmcvc2hv
d19idWcuY2dpP2lkPTI3MTY5CisKKyAgICAgICAgKiBpbnNwZWN0b3IvZnJvbnQtZW5kL3V0aWxp
dGllcy5qczoKKyAgICAgICAgKE9iamVjdC50eXBlKToKKwogMjAwOS0wNy0yMiAgUGF1bCBHb2Rh
dmFyaSAgPHBhdWxAY2hyb21pdW0ub3JnPgogCiAgICAgICAgIFJldmlld2VkIGJ5IERhcmluIEZp
c2hlci4KZGlmZiAtLWdpdCBhL1dlYkNvcmUvaW5zcGVjdG9yL2Zyb250LWVuZC91dGlsaXRpZXMu
anMgYi9XZWJDb3JlL2luc3BlY3Rvci9mcm9udC1lbmQvdXRpbGl0aWVzLmpzCmluZGV4IDhmYjUw
ZTIuLjUzZjU5OTUgMTAwNjQ0Ci0tLSBhL1dlYkNvcmUvaW5zcGVjdG9yL2Zyb250LWVuZC91dGls
aXRpZXMuanMKKysrIGIvV2ViQ29yZS9pbnNwZWN0b3IvZnJvbnQtZW5kL3V0aWxpdGllcy5qcwpA
QCAtMzgsNyArMzgsNyBAQCBPYmplY3QudHlwZSA9IGZ1bmN0aW9uKG9iaiwgd2luKQogICAgIHdp
biA9IHdpbiB8fCB3aW5kb3c7CiAKICAgICBpZiAob2JqIGluc3RhbmNlb2Ygd2luLk5vZGUpCi0g
ICAgICAgIHJldHVybiAibm9kZSI7CisgICAgICAgIHJldHVybiAob2JqLm5vZGVUeXBlID09PSB1
bmRlZmluZWQgPyB0eXBlIDogIm5vZGUiKTsKICAgICBpZiAob2JqIGluc3RhbmNlb2Ygd2luLlN0
cmluZykKICAgICAgICAgcmV0dXJuICJzdHJpbmciOwogICAgIGlmIChvYmogaW5zdGFuY2VvZiB3
aW4uQXJyYXkpCg==
</data>
<flag name="review"
          id="17616"
          type_id="1"
          status="+"
          setter="timothy"
    />
          </attachment>
      

    </bug>

</bugzilla>