-
Notifications
You must be signed in to change notification settings - Fork 683
Fix new ArrayBuffer(length) for various input #1959
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
Fix new ArrayBuffer(length) for various input #1959
Conversation
@jiangzidong Could you review this patch? |
@glistening I dont think ES2015 allow the length could be NaN, undefined, negative number, floating point. http://www.ecma-international.org/ecma-262/6.0/#sec-arraybuffer-length see step 5
If the length is NaN, undefined, negative number, floating point. they will fail the But interesting part is V8 supports NaN, undefined, negative number (-1, 0), floating point. I don't know why. Correct me if I miss sth in the spec. |
@jiangzidong Yes, it is hidden in step 3. Please see |
@glistening Yes, I know that ToInteger will turn "negative number, NaN and floating number" into non-negative integer. But then it will fail the step5.
the
the
I don't know why test262/v8/spidermonkey don't follow it. |
@jiangzidong Thank you for correcting me. ES2015 says it should throw. Test262 and major engines (v8, spidermonkey and JavaScriptCore) seems to follow ES2017, not ES2015. ES2017 uses ToIndex to describe the expected behaviour of
I will raise this as Issue to get opinion. |
@glistening Wow, I didn't notice that it's ES2017. Thanks for pointing out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(I wouldn't create subsets for such differences, just use the latest standard) |
@@ -24,4 +24,5 @@ catch (e) | |||
name = e.name; | |||
} | |||
|
|||
assert(name === "RangeError"); | |||
assert(name === ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is no expection, we dont need to check the name. just
var a = new ArrayBuffer(5.5);
assert(a.byteLength === 5);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jiangzidong I've simplified 24.01.02-006.js ~24.01.02-012.js.
|
||
try | ||
{ | ||
var a = new ArrayBuffer(-0.9); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also give a case where the length is float and below -1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jiangzidong Now, 24.01.02-012.js
covers two more cases that the length is float and below -1.
assert(a.byteLength === 0); | ||
|
||
var b = new ArrayBuffer(-1.9); | ||
assert(b.byteLength === 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1.9
and -2.2
should throw error, see ToIndex 2.b
b. If integerIndex < 0, throw a RangeError exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jiangzidong Oh, You're right. I will fix right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jiangzidong I've updated PR.
Currently new ArrayBuffer(length) does not conform to ES2017. Major JS implementations follow ES2017 for ArrayBuffer(length). For example, new ArrayBuffer(length) should not throw RangeError for length = NaN, undefined, negative number, floating point, and so on. JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee [email protected]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Currently new ArrayBuffer(length) does not conform to ES2015.
For example, new ArrayBuffer(length) should not throw RangeError
for length = NaN, undefined, negative number, floating point, and so on.
JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee [email protected]