On Jan 21, 9:41 pm, "[email protected]" <[email protected]>
wrote:
> 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

Trying the examples above in the Rhino shell I get the following:

js> throw Object.blah
js: "<stdin>", line 2: exception from uncaught JavaScript throw:
undefined
        at <stdin>:2

js> throw 1.0
js: "<stdin>", line 3: exception from uncaught JavaScript throw: 1
        at <stdin>:3

js> throw undefined
js: "<stdin>", line 4: exception from uncaught JavaScript throw:
undefined
        at <stdin>:4

js> throw 1
js: "<stdin>", line 5: exception from uncaught JavaScript throw: 1
        at <stdin>:5

js> throw "an error message"
js: "<stdin>", line 6: exception from uncaught JavaScript throw: an
error messag
e
        at <stdin>:6

js> throw null
js: "<stdin>", line 7: exception from uncaught JavaScript throw: null
        at <stdin>:7

This looks to be the same behavior as SpiderMonkey, and doesn't match
the failures you're seeing. Do you have some changes to your Rhino
environment that could be causing the different behavior?

--Norris
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to