Matthew Haddock
2007-Sep-20 20:15 UTC
Element.addMethods functions swallowing exceptions (IE6 + 7)
IE6 and IE7 are not correctly handling the ''throw'' command for functions attached to Element via Element.addMethods. Firefox and Safari are fine. See the example below. For IE6: functions called with no attributes (ie: funcName()) correctly handle thrown errors. Funcions called with attributes (ie: funcName("foo")) will respond to the throw command and pass execution back to the calling function, but the calling function is not notified of the error and the catch block is not exectuted. For IE7: The failure occurs regardless of attributes/no attributes Has anyone else seen this, or have any suggestions? <html> <head> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript"> Element.addMethods({ throwException: function() { if (arguments.length > 1) { var message = arguments[1]; } else { var message = "default message"; } alert("Element: about to throw exception"); throw new Error(message); alert("this should not be executed"); } }); var genericObject = { throwException: function() { if (arguments.length > 0) { var message = arguments[0]; } else { var message = "default message"; } alert("generic Object: about to throw exception"); throw new Error(message); alert("this should not be executed"); } } </script> </head> <body> <h1 id="myElement">throw exception from Element.addMethods function</ h1> <script type="text/javascript"> // throw from Element.addMethods try { $("myElement").throwException(); alert("throw failed! You''re probably using IE7"); // this line should not be reached } catch(e) { alert(e); } try { $("myElement").throwException("custom error message"); alert("throw failed! You''re probably using IE6 or IE7"); // this line should not be reached } catch(e) { alert(e); } // throw from generic Object try { genericObject.throwException(); alert("throw failed!"); } catch(e) { alert(e); } try { genericObject.throwException("custom error message"); alert("throw failed!"); } catch(e) { alert(e); } </script> </body> </html> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Haddock
2007-Sep-20 20:18 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
This problem exists for prototype 1.5, 1.5.1.1, and 1.6.0_rc0 On Sep 20, 3:15 pm, Matthew Haddock <matthew.hadd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> IE6 and IE7 are not correctly handling the ''throw'' command for > functions attached to Element via Element.addMethods. Firefox and > Safari are fine. > > See the example below. > > For IE6: functions called with no attributes (ie: funcName()) > correctly handle thrown errors. Funcions called with attributes (ie: > funcName("foo")) will respond to the throw command and pass execution > back to the calling function, but the calling function is not notified > of the error and the catch block is not exectuted. > > For IE7: The failure occurs regardless of attributes/no attributes > > Has anyone else seen this, or have any suggestions? > > <html> > <head> > <script type="text/javascript" src="prototype.js"></script> > <script type="text/javascript"> > Element.addMethods({ > throwException: function() { > if (arguments.length > 1) { > var message = arguments[1]; > } else { > var message = "default message"; > } > alert("Element: about to throw exception"); > throw new Error(message); > alert("this should not be executed"); > } > }); > > var genericObject = { > throwException: function() { > if (arguments.length > 0) { > var message = arguments[0]; > } else { > var message = "default message"; > } > alert("generic Object: about to throw exception"); > throw new Error(message); > alert("this should not be executed"); > } > } > </script> > </head> > <body> > <h1 id="myElement">throw exception from Element.addMethods function</ > h1> > <script type="text/javascript"> > // throw from Element.addMethods > try { > $("myElement").throwException(); > alert("throw failed! You''re probably using IE7"); // this line > should not be reached > } catch(e) { > alert(e); > } > > try { > $("myElement").throwException("custom error message"); > alert("throw failed! You''re probably using IE6 or IE7"); // this > line should not be reached > } catch(e) { > alert(e); > } > > // throw from generic Object > try { > genericObject.throwException(); > alert("throw failed!"); > } catch(e) { > alert(e); > } > > try { > genericObject.throwException("custom error message"); > alert("throw failed!"); > } catch(e) { > alert(e); > } > > </script> > </body> > </html>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tobie Langel
2007-Sep-20 23:28 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
The methods passed to Element.addMethods expect element as their first argument. Hence your issues. Regards, Tobie On Sep 20, 10:18 pm, Matthew Haddock <matthew.hadd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This problem exists for prototype 1.5, 1.5.1.1, and 1.6.0_rc0 > > On Sep 20, 3:15 pm, Matthew Haddock <matthew.hadd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > IE6 and IE7 are not correctly handling the ''throw'' command for > > functions attached to Element via Element.addMethods. Firefox and > > Safari are fine. > > > See the example below. > > > For IE6: functions called with no attributes (ie: funcName()) > > correctly handle thrown errors. Funcions called with attributes (ie: > > funcName("foo")) will respond to the throw command and pass execution > > back to the calling function, but the calling function is not notified > > of the error and the catch block is not exectuted. > > > For IE7: The failure occurs regardless of attributes/no attributes > > > Has anyone else seen this, or have any suggestions? > > > <html> > > <head> > > <script type="text/javascript" src="prototype.js"></script> > > <script type="text/javascript"> > > Element.addMethods({ > > throwException: function() { > > if (arguments.length > 1) { > > var message = arguments[1]; > > } else { > > var message = "default message"; > > } > > alert("Element: about to throw exception"); > > throw new Error(message); > > alert("this should not be executed"); > > } > > }); > > > var genericObject = { > > throwException: function() { > > if (arguments.length > 0) { > > var message = arguments[0]; > > } else { > > var message = "default message"; > > } > > alert("generic Object: about to throw exception"); > > throw new Error(message); > > alert("this should not be executed"); > > } > > } > > </script> > > </head> > > <body> > > <h1 id="myElement">throw exception from Element.addMethods function</ > > h1> > > <script type="text/javascript"> > > // throw from Element.addMethods > > try { > > $("myElement").throwException(); > > alert("throw failed! You''re probably using IE7"); // this line > > should not be reached > > } catch(e) { > > alert(e); > > } > > > try { > > $("myElement").throwException("custom error message"); > > alert("throw failed! You''re probably using IE6 or IE7"); // this > > line should not be reached > > } catch(e) { > > alert(e); > > } > > > // throw from generic Object > > try { > > genericObject.throwException(); > > alert("throw failed!"); > > } catch(e) { > > alert(e); > > } > > > try { > > genericObject.throwException("custom error message"); > > alert("throw failed!"); > > } catch(e) { > > alert(e); > > } > > > </script> > > </body> > > </html>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Haddock
2007-Sep-21 06:52 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
Actually, since I''m calling the functions as $ ("myElement").functionName() I don''t need to add element as the first argument. Prototype takes care of that for you and is one of the benefits of using addMethods() to extend Element. $("myElement") is automatically added as argument[0]. You''ll notice that I''m referencing arguments[1] to get at the string I''ve passed and not arguments[0]. That also wouldn''t explain why my code works flawlessly in Firefox and Safari. On Sep 20, 6:28 pm, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The methods passed to Element.addMethods expect element as their first > argument. Hence your issues. > > Regards, > > Tobie > > On Sep 20, 10:18 pm, Matthew Haddock <matthew.hadd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > This problem exists for prototype 1.5, 1.5.1.1, and 1.6.0_rc0 > > > On Sep 20, 3:15 pm, Matthew Haddock <matthew.hadd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > IE6 and IE7 are not correctly handling the ''throw'' command for > > > functions attached to Element via Element.addMethods. Firefox and > > > Safari are fine. > > > > See the example below. > > > > For IE6: functions called with no attributes (ie: funcName()) > > > correctly handle thrown errors. Funcions called with attributes (ie: > > > funcName("foo")) will respond to the throw command and pass execution > > > back to the calling function, but the calling function is not notified > > > of the error and the catch block is not exectuted. > > > > For IE7: The failure occurs regardless of attributes/no attributes > > > > Has anyone else seen this, or have any suggestions? > > > > <html> > > > <head> > > > <script type="text/javascript" src="prototype.js"></script> > > > <script type="text/javascript"> > > > Element.addMethods({ > > > throwException: function() { > > > if (arguments.length > 1) { > > > var message = arguments[1]; > > > } else { > > > var message = "default message"; > > > } > > > alert("Element: about to throw exception"); > > > throw new Error(message); > > > alert("this should not be executed"); > > > } > > > }); > > > > var genericObject = { > > > throwException: function() { > > > if (arguments.length > 0) { > > > var message = arguments[0]; > > > } else { > > > var message = "default message"; > > > } > > > alert("generic Object: about to throw exception"); > > > throw new Error(message); > > > alert("this should not be executed"); > > > } > > > } > > > </script> > > > </head> > > > <body> > > > <h1 id="myElement">throw exception from Element.addMethods function</ > > > h1> > > > <script type="text/javascript"> > > > // throw from Element.addMethods > > > try { > > > $("myElement").throwException(); > > > alert("throw failed! You''re probably using IE7"); // this line > > > should not be reached > > > } catch(e) { > > > alert(e); > > > } > > > > try { > > > $("myElement").throwException("custom error message"); > > > alert("throw failed! You''re probably using IE6 or IE7"); // this > > > line should not be reached > > > } catch(e) { > > > alert(e); > > > } > > > > // throw from generic Object > > > try { > > > genericObject.throwException(); > > > alert("throw failed!"); > > > } catch(e) { > > > alert(e); > > > } > > > > try { > > > genericObject.throwException("custom error message"); > > > alert("throw failed!"); > > > } catch(e) { > > > alert(e); > > > } > > > > </script> > > > </body> > > > </html>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Haddock
2007-Sep-21 07:07 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
Or perhaps I''m missing your point? There is some magical, mysterious stuff going on under the covers with how Element is extended and addMethods() in particular. At least it''s a bit beyond my grasp at the moment. On Sep 20, 6:28 pm, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The methods passed to Element.addMethods expect element as their first > argument. Hence your issues. > > Regards, > > Tobie > > On Sep 20, 10:18 pm, Matthew Haddock <matthew.hadd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > This problem exists for prototype 1.5, 1.5.1.1, and 1.6.0_rc0 > > > On Sep 20, 3:15 pm, Matthew Haddock <matthew.hadd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > IE6 and IE7 are not correctly handling the ''throw'' command for > > > functions attached to Element via Element.addMethods. Firefox and > > > Safari are fine. > > > > See the example below. > > > > For IE6: functions called with no attributes (ie: funcName()) > > > correctly handle thrown errors. Funcions called with attributes (ie: > > > funcName("foo")) will respond to the throw command and pass execution > > > back to the calling function, but the calling function is not notified > > > of the error and the catch block is not exectuted. > > > > For IE7: The failure occurs regardless of attributes/no attributes > > > > Has anyone else seen this, or have any suggestions? > > > > <html> > > > <head> > > > <script type="text/javascript" src="prototype.js"></script> > > > <script type="text/javascript"> > > > Element.addMethods({ > > > throwException: function() { > > > if (arguments.length > 1) { > > > var message = arguments[1]; > > > } else { > > > var message = "default message"; > > > } > > > alert("Element: about to throw exception"); > > > throw new Error(message); > > > alert("this should not be executed"); > > > } > > > }); > > > > var genericObject = { > > > throwException: function() { > > > if (arguments.length > 0) { > > > var message = arguments[0]; > > > } else { > > > var message = "default message"; > > > } > > > alert("generic Object: about to throw exception"); > > > throw new Error(message); > > > alert("this should not be executed"); > > > } > > > } > > > </script> > > > </head> > > > <body> > > > <h1 id="myElement">throw exception from Element.addMethods function</ > > > h1> > > > <script type="text/javascript"> > > > // throw from Element.addMethods > > > try { > > > $("myElement").throwException(); > > > alert("throw failed! You''re probably using IE7"); // this line > > > should not be reached > > > } catch(e) { > > > alert(e); > > > } > > > > try { > > > $("myElement").throwException("custom error message"); > > > alert("throw failed! You''re probably using IE6 or IE7"); // this > > > line should not be reached > > > } catch(e) { > > > alert(e); > > > } > > > > // throw from generic Object > > > try { > > > genericObject.throwException(); > > > alert("throw failed!"); > > > } catch(e) { > > > alert(e); > > > } > > > > try { > > > genericObject.throwException("custom error message"); > > > alert("throw failed!"); > > > } catch(e) { > > > alert(e); > > > } > > > > </script> > > > </body> > > > </html>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
jdalton
2007-Sep-21 14:52 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
Hello Matthew, What you are experiencing is NOT caused by Prototype: http://pastie.caboo.se/99406 In this example I did not use Prototype and got the same error. The first myElement.throwException() works and the rest fail to behave correctly in IE. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Haddock
2007-Sep-21 18:16 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
You''re right! Thanks for looking into that. I''ve updated my test case to include your example. I would have preferred this were a prototype issue, then their might be a glimmer of hope this could be corrected. But alas... Thanks again for your help! Here is my updated test case demonstrating this IE6 + 7 bug (for posterity). <html> <head> <script type="text/javascript"> window.onload = function(){ // Element var myElement = document.getElementById("myElement"); myElement.throwException = function(message) { message = message || "default message"; alert("Element: about to throw exception"); throw new Error(message); alert("this should not be executed"); }; try { myElement.throwException(); alert("throw failed! You''re probably using IE7"); // this line should not be reached } catch(e) { alert(e); } try { myElement.throwException("custom error message"); alert("throw failed! You''re probably using IE6 or IE7"); // this line should not be reached } catch(e) { alert(e); } // Object var genericObject = new Object(); genericObject.throwException = function(message) { message = message || "default message"; alert("Element: about to throw exception"); throw new Error(message); alert("this should not be executed"); }; try { genericObject.throwException(); alert("throw failed!"); } catch(e) { alert(e); } try { genericObject.throwException("custom error message"); alert("throw failed!"); } catch(e) { alert(e); } }; </script> </head> <body> <p id="myElement">throw exception from Element function (no prototype.js)</p> </body> </html> On Sep 21, 9:52 am, jdalton <jdalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Matthew, > > What you are experiencing is NOT caused by Prototype:http://pastie.caboo.se/99406 > > In this example I did not use Prototype and got the same error. > The first myElement.throwException() works and the rest fail to behave > correctly in IE.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
jdalton
2007-Sep-21 18:37 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
http://msdn2.microsoft.com/en-us/library/w4e7h3yz.aspx more info on what IE does --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
jdalton
2007-Sep-21 18:40 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
if you replace your alert with a window.status. you will notice it doesnt get executed... so maybe its just a bug with alert(); window.status = "throw failed! You''re probably using IE7"; // this line should not be reached --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Haddock
2007-Sep-21 23:25 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
There was a little confusion in my office on whether ''throw'' was required to be inside of a ''try/catch''. The link you mentioned kind of implies this, and Orielly DHTML Ref ed. 2 flat out says that a ''throw'' must be enclosed in a ''try''. I think this is incorrect. A throw must be inside of a try/catch to prevent it from reaching the user, but strictly speaking this is not illegal. And the try/catch block need not be in the same function or even the same js file. Exceptions are supposed to bubble up to the nearest try/catch in the execution chain, and if a try/catch is not found, an ''uncaught exception'' should be reported to the user. Oreilly Javascript Def. Guide ed. 5 describes this behavior correctly I believe. On Sep 21, 1:37 pm, jdalton <jdalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> http://msdn2.microsoft.com/en-us/library/w4e7h3yz.aspx > > more info on what IE does--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Haddock
2007-Sep-21 23:29 UTC
Re: Element.addMethods functions swallowing exceptions (IE6 + 7)
I think javascript access to window.status is blocked by default in IE7 and maybe partially in IE6 (to prevent spoofing I guess). This is probably causing your code to behave differently. I rewrote my test cases to display their status messages via innerHTML so as to avoid alert() and I got the same behavior as before. On Sep 21, 1:40 pm, jdalton <jdalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> if you replace your alert with a window.status. > you will notice it doesnt get executed... so maybe its just a bug with > alert(); > > window.status = "throw failed! You''re probably using IE7"; // this > line should not be reached--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- Adding my own extensions with Elements.addMethods()
- Element.focusFirstElement() causing issue with Element.addMethods()
- Element.addMethods() is not a function after upgrade to 1.7.0
- Extending Element with getTop, getWidth, getLeft problem
- Element.addMethods vs extending prototype.