js method fails (throws exception?), which firebug does not report
The following js method does not return, yet firebug reports no exception:
function test_contains_doesNotBailWithoutException() {
$.contains(document.getElementById('navlinks', undefined));
// This line should be reached, or you should get an exception message in Firebug.
return true;
}
where navlinks is something that exists on the page, and $ is from jquery 1.5.1. The method exits (throws, I assume) while calling the contains method, in line 4639 of jquery1.5.1:
return !!(a.c开发者_高级运维ompareDocumentPosition(b) & 16);
where a is the navlinks div and b is undefined. Shouldn't firebug report an exception in the console?
To be sure, running the following in the firebug console yields neither an error message nor a return result:
return document.getElementById('navlinks').compareDocumentPosition(undefined);
EDIT: I'm using Firefox 4.0.1 and Firebug 1.7.1.
Yes, there should be an exception; I certainly get one with either the JavaScript version:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOM3Node.compareDocumentPosition]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: javascript:alert(document.body.compareDocumentPosition(undefined)) :: <TOP_LEVEL> :: line 1" data: no]
or the same thing from the jQuery version (which has a bracket in the wrong place in your example... not that it matters since the missing argument will naturally get filled in with undefined
anyway):
Error: uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOM3Node.compareDocumentPosition]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js :: <TOP_LEVEL> :: line 16" data: no]
精彩评论