-
Notifications
You must be signed in to change notification settings - Fork 850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected result with isNaN method #368
Comments
Yep. Right now For the curious, it's |
Ok, some more details:
|
In general --
We can be a little bit more aggressive with more recent versions. So if you
want to change this to match the latest ES specs but not break existing
code, then it'd be safest to make the change only if:
Context.getLanguageVersion() > Context.VERSION_ES6
In addition, it'd be great to re-use some tests from the ES6 test suite --
either:
- look at "test262.properties" and enable some related tests that might
currently be disabled
- or, copy a test suite from the v8 project and put it in
testsrc/jstests/es6 or testsrc/jstests/harmony (depending on where you got
it in V8) with a corresponding test class in
org.mozilla.javascript.tests.{whatever you picked}
That way we're using a "known" test suite that accounts for the tons of
corner cases that come with every single thing about JavaScript ;-)
…On Thu, Dec 21, 2017 at 10:08 AM, Ivan Vyshnevskyi ***@***.*** > wrote:
Ok, some more details:
- stringToNumber() supposed to work only with integers; it starts from
given position and doesn't “consume” anything but chars that are expected
to be part of a number. When it finds something else, it just returns what
it got at that point (if it's at the beginning of the string, it will
return NaN)
- this behavior is fine for the parseInt() because it supposed to work
this way (see step 11
<https://tc39.github.io/ecma262/#sec-parseint-string-radix>)
- it's also fine for the TokenStream.getToken(), because there
stringToNumber() is called on the previously collected characters of
the number and only when it's an integer, so nothing else is in the string
- toNumber() passes its input string to stringToNumber() with a start
position adjusted (whitespace and 0x prefix are “consumed”) when it
sees a 0x prefix (note that 010 is *not* an octal number for toNumber()),
but it doesn't check that the whole string was “consumed” ← the problem
As far as I can tell, this behavior was there since at least 2001, so
changing it could be considered a breaking change. If I tried to fix this
and a couple of other things around it, what would be the best way to
proceed?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#368 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAf0ayHiDBGpnnrdDqwxf1qzLB-lMgG_ks5tCp6WgaJpZM4RJlYH>
.
|
Sure, will go with this.
Yeah, well, I went to test262 first and they don't seem to have cases covering this. I'll probably try to submit some, based on the spec, so I'm more or less sure that I got it right before doing fix here. (Even did a first step. 🙂 )
Again, I can't seem to find anything interesting. All of the
|
Sorry -- I meant ">= Context.VERSION_ES6." Otherwise your code will never
be executed ;-)
And yeah, it's probably worth a careful reading of the ECMAScript spec to
make sure that we're following the spec and not just what we observe in
Chrome or wherever.
…On Thu, Dec 21, 2017 at 11:06 AM, Ivan Vyshnevskyi ***@***.*** > wrote:
Context.getLanguageVersion() > Context.VERSION_ES6
Sure, will go with this.
- look at "test262.properties" and enable some related tests that
might currently be disabled
Yeah, well, I went to test262 first and they don't seem to have cases
covering this. I'll probably try to submit some, based on the spec, so I'm
more or less sure that I got it right before doing fix here. (Even did a
first step. <tc39/test262#1378> 🙂 )
- or, copy a test suite from the v8 project and put it in
testsrc/jstests/es6 or testsrc/jstests/harmony (depending on where you got
it in V8) with a corresponding test class in org.mozilla.javascript.tests.{whatever
you picked}
Again, I can't seem to find anything interesting. All of the isNaN uses
GitHub's search finds, except for weird regressions tests, are for checking
that other things return NaNs correctly. 😕
I'm cloning v8 right now to look more thoroughly with grep, but it is
slooow.
SpiderMonkey has basic tests
<https://searchfox.org/mozilla-central/source/js/src/tests/ecma/GlobalObject/15.1.2.6.js>
and I'll definitely borrow some.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#368 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAf0a6TuNB-ttpYANnIzLQu53MAvw1geks5tCqw8gaJpZM4RJlYH>
.
|
Oh, no worries, I didn't even notice the lack of Progress update: I've submitted PR adding this case to test262, but since it's holidays I don't expect it will be merged in or even looked at this week/year. In the meantime, I'll prepare the patch based on my current understanding. |
I wrote a patch in the Update: One of the test262 maintainers just merged my PR. 🎉 Update 2: I've updated #372 to include latest test262 master at the moment. |
I have problems with
The only thing works for now is parseInt ... is that expected? |
Yes, @CaledoniaProject, that's how |
I'm using Mozilla Rhino engine version 1.7.7.2 with OpenRASP project.
The following statement returns expected result
false
At lease in Chrome console, it returns
true
Can you verify that?
The text was updated successfully, but these errors were encountered: