-
Notifications
You must be signed in to change notification settings - Fork 864
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
Support ES2019 Array.prototype.flat #1313
Conversation
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.
Thanks for your pull request.
Rhino uses Test262 to test ECMAScript specifications. Could you test the specifications by following these steps?
- Install Test262
- Delete the following line
"Array.prototype.flat", - Updating the test262.properties file
@@ -151,6 +151,7 @@ protected void fillConstructorProperties(IdFunctionObject ctor) { | |||
addIdFunctionProperty(ctor, ARRAY_TAG, ConstructorId_findIndex, "findIndex", 1); | |||
addIdFunctionProperty(ctor, ARRAY_TAG, ConstructorId_reduce, "reduce", 1); | |||
addIdFunctionProperty(ctor, ARRAY_TAG, ConstructorId_reduceRight, "reduceRight", 1); | |||
addIdFunctionProperty(ctor, ARRAY_TAG, ConstructorId_flat, "flat", 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.
This code adds the method to the constructor(Array.flat
), not the prototype(Array.prototype.flat
).
It is an old specification called Array generic methods.
https://lia.disi.unibo.it/materiale/JS/developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array.html#Array_generic_methods
I do not think this is necessary as it is not in latest ECMA262 specification.
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.
Right, I just added these because I saw other functions doing this -- e.g. Array.reduceRight
doesn't exist either, just Array.prototype.reduceRight
.
I've removed ConstructorId_flat
entirely.
By other code looks like the Rhino version context is just ES6.
Thanks, I've updated. Some of the failing spec tests seem to be failing on something unrelated to
so either I've failed to wire something up correctly, or there's something wrong with a different bit of Rhino. |
Hi @midgleyc, Can you please do
Thanks a lot for providing this |
Sure, no problem. As you have merged this already (thanks for this!) I will make those changes in another PR. |
sorry, doing it right no. No need for changes. |
Thanks for the PR. |
Closes #948.
I'm not sure whether the implementation of the various ids are correct: I just copied the surrounding code.
I took the harmony test from https://github.com/v8/v8/blob/main/test/mjsunit/harmony/array-flat.js, added
load("testsrc/assert.js");
to the start and"success";
to the end, and then made adjustments as Rhino doesn't supported redeclaredconst
s in blocks or theProxy
object.The language version in the test I have set to ES6, but as
flat
is part of ES2019, perhaps there should be a new version? Perhaps not, and I should just remove the comment?By spec, we should throw a
TypeError
if the indexj
passed todefineElem
is greater than 253 - 1. I have reused the messagemsg.arraylength.too.big
here, but let me know if you'd like me to do something different.