We recently discovered some interesting issues with throw for certain
classes of objects:
// These are OK:
//throw; // OK - Unhandled exception
//throw {}; // OK - JS exception
//throw function() {}; // OK
//throw throw; // OK - syntax error
//throw +; // OK
//throw Error("bye"); // OK
//throw new Error("bye"); // OK
// Failures:
//throw acre.missing_obj; // 500 - org.mozilla.javascript.Undefined
cannot be cast to org.mozilla.javascript.Scriptable
//throw 1.0; // 500 - java.lang.Double cannot be cast to
org.mozilla.javascript.Scriptable
//throw undefined; // 500 - org.mozilla.javascript.Undefined cannot be
cast to org.mozilla.javascript.Scriptable
//throw 1; // 500 - java.lang.Double cannot be cast to
org.mozilla.javascript.Scriptable
//throw "an error message"; // 500 - java.lang.String cannot be cast
to org.mozilla.javascript.Scriptable
//throw null; // 500 - java.lang.NullPointerException
Looking at the ECMA standard, a throw statement should call the
GetValue algorithm on the object (which will return the primitive for
a primitive), and then throw that value. SpiderMonkey also handles
these cases correctly:
[18:39] a...@temperantia: ~> js
js> throw Object.blah
uncaught exception: undefined
js> throw 1.0
uncaught exception: 1
js> throw undefined
uncaught exception: undefined
js> throw 1
uncaught exception: 1
js> throw "an error message"
uncaught exception: an error message
js> throw null
uncaught exception: null
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino