> -----Original Message----- > From: Garrett Smith [mailto:[EMAIL PROTECTED] > Sent: 20. mars 2008 21:40 > To: Lars Hansen > Cc: es4-discuss Discuss > Subject: Re: ES4 draft: Error classes > > On Tue, Mar 18, 2008 at 12:05 PM, Lars Hansen > <[EMAIL PROTECTED]> wrote: > > > -----Original Message----- > > > From: Garrett Smith [mailto:[EMAIL PROTECTED] > Sent: 18. > > mars 2008 11:57 > To: Lars Hansen > Cc: es4-discuss Discuss > > > Subject: Re: ES4 draft: Error classes > > > > > > > > On Mon, Mar 17, 2008 at 12:11 PM, Lars Hansen > > > <[EMAIL PROTECTED]> wrote: > > > > (Didn't know who to follow up to so lamely following up to > > myself.) > > > > What does this have to do with getting a stack trace? > > > I see. > > var color = el.style.color > > where el is null, a ReferenceError would be thrown. It would > be useful to have a backwards-compatible way to get that > stack trace.
How is the mechanism not backward compatible? Either context and backTrace are available on the error object, or they are not, but this particular aspect does not depend on whether 'assert' is available or not. > How can - assert - be detected? Since 'assert' is a new keyword it would only have special meaning in scripts that are loaded with "application/ecmascript;version=4", so detection would in that sense be implicit. Since we're just hacking among friends then the following works in both ES3 and ES4, I believe, it makes sure that 'assert' is defined globally and throws an error if the condition is false, and it uses the ES4 assert if available: if (window.__ECMASCRIPT_VERSION__ >= 4) window.assert = global.eval("function (x) { assert(x) }", 4); else window.assert = function (x) { if (!x) throw new Error("ASSERTION FAILED") } ES3 code and ES4 code would both just do eg assert(limit >= 0); Clearly the optional second parameter can't be accomodated with the same semantics as in ES4. > What about libraries that already have an assert() function? They would presumably be loaded in the ES3 syntax compatibility mode and there would not be a conflict. > "assert"in window? Ditto (counterexamples or more elaborate questions welcome). --lars _______________________________________________ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss