On 29/09/09 13:41, Norris Boyd wrote:
> On Sep 29, 12:32 am, Stefan Weiss <[email protected]> wrote:
>> I'm having major problems with the JavaScript engine which comes bundled
>> with Java 6 (version 1.6.0_10 here). After working my way through the
>> rather uncomfortable API provided by the javax.script package, I found
>> that some of the scripts we use were producing errors in unexpected
>> places. I was able to pinpoint the problem to assignments like this:
>>
>>   var x = undefined || 0;
>>
>> This assigns undefined to x, instead of 0. Other, similar assignments
>> are also broken (see test class below). Unfortunately, this is a very
>> frequently used construct. Is (or was) this a known problem, and is
>> there a workaround?
[...]
>> ---------------------------------------------------
>> The test class below produces the following output (for me):
>>
>> input      expected   actual     result
>>
>> false      number     number     0.0
>> undefined  number     undefined  sun.org.j[...].undefi...@e3b895
>> null       number     number     0.0
>> ''         number     string
>> 0          number     number     0.0
>> -0         number     number     0.0
>> true       boolean    boolean    true
>> ' '        string     string
>> 1          number     boolean    true
>> {}         object     object     [object Object]
[...]

> The "undefined || 0" expression is evaluated successfully in
> mozilla.org Rhino. I only checked the latest version but I'd be
> surprised if Rhino ever did the wrong thing here as the functionality
> is so basic. The fact that in the example you cite that undefined is a
> sun.org.j[...].Undefined makes me wonder if there's some problem
> caused by the port of Rhino into the JDK.

It was actually 'sun.org.mozilla.javascript.internal.undefi...@e3b895';
I shortened it before posting to avoid wrapping. This is the first time
I've encountered this bug, and I've used several other Rhino versions
from mozilla.org before. It's pretty bad... if this wasn't caused by any
misconfiguration on my part, I doubt I will trust the JDK version of
Rhino from now on.

> At any rate, I'd recommend using mozilla.org Rhino. If you want to
> keep using the javax.script interface, then you can use the adapter
> mentioned here: https://bugzilla.mozilla.org/show_bug.cgi?id=379385

Actually, I had a working version of our application using an external
Rhino library, but then I discovered the bundled engine and thought I
could remove a dependency. That doesn't appear to be working, and I much
preferred the standard Rhino API, anyway, so I'll revert to my original
version :-/

Thanks for the feedback.


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

Reply via email to