mozilla / rhino

Rhino is an open-source implementation of JavaScript written entirely in Java
https://rhino.github.io
Other
4.11k stars 846 forks source link

Undefined or not initialized variables with strange behavior #1458

Open EduFrazao opened 5 months ago

EduFrazao commented 5 months ago

Hi. Undefined or not initialized variables presents a strange behavior in version 1.7.14

Like this code:


var x = undefined;

if (!x) {
    // Never enters here
}

Not initialized variables also reports its types as strings

var x;
print(typeof x)

This codes prints: "string"

Is this somehow expected?

Edit note: With 1.7.13 works fine.

zozo-yasuda commented 4 months ago

I tested in the current 1.7.15 snapshot, indeed:

var x = undefined;
if(x) print(x)  //yields nothing
if(!x) print(x) //prints "undefined"

I also checked Boolean(undefined). This evaluates to false as it should, so maybe there's something wrong with the if logic. For the second issue, mine printed undefined so this was probably fixed.

I'll add these as test cases when I familiarize myself more with the repo.

EduFrazao commented 4 months ago

I tested in the current 1.7.15 snapshot, indeed:

var x = undefined;
if(x) print(x)  //yields nothing
if(!x) print(x) //prints "undefined"

I also checked Boolean(undefined). This evaluates to false as it should, so maybe there's something wrong with the if logic. For the second issue, mine printed undefined so this was probably fixed.

I'll add these as test cases when I familiarize myself more with the repo.

Hi. Thanks for testing. Did you test the output of "typeof x" after set it as undefined?

p-bakker commented 2 months ago

@EduFrazao Rhino 1.7.15 had been released.

Could you validate if the issue you had in 1.7.14 is still present our not?

p-bakker commented 2 months ago

If this issue is still present in 1.7.15, it would be great if you could try it before and after the merging of https://github.com/mozilla/rhino/pull/979, which is a merged PR that made changes in the area of undefined handling

p-bakker commented 1 week ago

@gbrail any chance this regression might be due to the changes you made in #979?

p-bakker commented 3 days ago

@gbrail quick ping in case this fell off the bottom of the list 🙂

gbrail commented 3 days ago

I tried this on the master branch and I didn't see the original behavior described, so I'd want to understand what exactly the original poster did to get this result.

On Wed, Aug 21, 2024 at 9:48 AM Paul Bakker @.***> wrote:

@gbrail https://github.com/gbrail quick ping in case this fell off the bottom of the list 🙂

— Reply to this email directly, view it on GitHub https://github.com/mozilla/rhino/issues/1458#issuecomment-2302538132, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7I226Q6OJIPQRMCYPCZDZSTAEJAVCNFSM6AAAAABFCEVCUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBSGUZTQMJTGI . You are receiving this because you were mentioned.Message ID: @.***>

p-bakker commented 3 days ago

My bad, I misread the second comment in that I thought it confirmed the bug, but it did the opposite

@EduFrazao please provide more details on how to reproduce or at least how you interact with Rhino/execute your JS code, because we cannot reproduce the behaviour your reporting, neither in master not with the 1.7.14 release

Without a way to reproduce the issue, there's not much we can do with this case