{"id":625,"date":"2010-08-19T20:54:07","date_gmt":"2010-08-20T02:54:07","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=625"},"modified":"2010-08-19T20:54:07","modified_gmt":"2010-08-20T02:54:07","slug":"namespace-collisions-ns_error_xpc_cant_convert_wn_to_fun-and-gwt","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/625","title":{"rendered":"Namespace Collisions, NS_ERROR_XPC_CANT_CONVERT_WN_TO_FUN and GWT"},"content":{"rendered":"<p>So, the abstraction layer provided by <a href=\"http:\/\/code.google.com\/webtoolkit\/\">GWT<\/a> <a href=\"www.joelonsoftware.com\/articles\/LeakyAbstractions.html\">just leaked<\/a>&#8211;well, more of a flood than a leak.<\/p>\n<p>I am working on a site that is pulling in an html fragment which included some javascript code via an XML HttpRequest.\u00a0 This new code will make paging the results of a search quicker, hopefully leading to happier users.\u00a0 For reasons too obscure to go into, I was creating a variable named &#8216;r1&#8217; which I was then adding to the DOM.\u00a0 The name was completely arbitrary, and was due to laziness (hey, why type 3 characters when you can type 2?).<\/p>\n<p>Fast forward to today, when we&#8217;re getting ready to launch the update.\u00a0 Occasionally, but not often, code that GWT was executing was throwing an exception.\u00a0 One of the other developers found it because some functionality was disabled.\u00a0 Here&#8217;s what that exception looked like:<\/p>\n<p><code>exception: (NS_ERROR_XPC_CANT_CONVERT_WN_TO_FUN): Cannot convert WrappedNative to function<br \/>\nQueryInterface: function QueryInterface() {<br \/>\n[native code]<br \/>\n}<br \/>\nresult: 2153185293<br \/>\nfilename: http:\/\/stageserver\/gwt\/2B17113CD349EDFD95DC846F38AB0857.cache.html<br \/>\nlineNumber: 4268<br \/>\ncolumnNumber: 0<br \/>\ninner: null<br \/>\ndata: null<br \/>\ninitialize: function initialize() {<br \/>\n[native code]<br \/>\n}<\/code><\/p>\n<p>Now, usually, the first thing I do when I see an exception is to recompile the GWT with <code>-style DETAILED<\/code> instead of <code>-style OBF<\/code> and see where the error occurs.\u00a0 However, when I did that, I didn&#8217;t see the error message any more.<\/p>\n<p>OK, I added more debugging.\u00a0 If I added a certain number of alert statements, the error message was nowhere to be found.\u00a0 OK, go back to the previous code.\u00a0 Try different pages, different browsers.\u00a0 Sometimes the exception reared its head, other times it didn&#8217;t.\u00a0 It appeared on some browsers and not others. Sprinkled alerts throughout the code, found the exact line where the exception was being thrown.\u00a0 All that line did was create a click listener.<\/p>\n<p>Nothing really clear on google; however, this post was<a href=\"http:\/\/objectmix.com\/javascript\/75636-exception-when-creating-another-object.html\"> useful in pointing to the error message being a collision between a function name and a DOM element<\/a>.\u00a0 Searching the <a href=\"http:\/\/groups.google.com\/group\/Google-Web-Toolkit\/\">GWT google group<\/a> was not helpful.\u00a0\u00a0 I tried using the Firebug debugger, but on obfuscated source, it was not helpful to me.<\/p>\n<p>These kind of bugs make me want to tear out my hair.\u00a0 Hardly reproducible bugs are no fun.  However, I finally found the issue (if I hadn&#8217;t, I&#8217;d still be working and wouldn&#8217;t be posting, that&#8217;s for sure).<\/p>\n<p>How I finally solved it:\u00a0 I was getting a line number.\u00a0 I finally edited the generated GWT .cache.html file and added some newlines.\u00a0 This would let me find out exactly which function was really causing the issue.<\/p>\n<p>And, lo and behold, <strong>the problematic function was named &#8216;r1&#8217;<\/strong>.<\/p>\n<p>Changing the name of the DOM element fixed this issue. Beware short named javascript DOM elements when working with GWT.<\/p>\n<p>Hope this helps you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, the abstraction layer provided by GWT just leaked&#8211;well, more of a flood than a leak. I am working on a site that is pulling in an html fragment which [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,20],"tags":[],"class_list":["post-625","post","type-post","status-publish","format-standard","hentry","category-gwt","category-web-applications"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=625"}],"version-history":[{"count":4,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/625\/revisions"}],"predecessor-version":[{"id":629,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/625\/revisions\/629"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}