Reflect: Implement Reflect.ownKeys() - #595
Conversation
|
Hi @duonglaiquang, |
|
Looks like i can do a (more or less complete) impl in Rhino... hopefully i can finish it over the weekend. |
|
fyi, we're looking into an issue where |
|
Will add at least your testcase to the HtmlUnit test suite after the Impl is in Rhino/core-js. Hope then we are on the save side |
|
Step 1: mozilla/rhino#1324 |
|
Reflect impl is now in core-js (will be moved later to Rhino)
Next step: provide PR for Rhino for negative index handling (have already some working code) |
|
HtmlUnit/htmlunit-rhino-fork@e6c4c79 Because i fear there is no chance for this in Rhino (is a bit of a hack and not backward compatible) i did it only here |
Overview
This PR does the following:
Proposes an implementation for
Reflect.ownKeys()WARNING: DO NOT MERGE. DOES NOT COMPILE. See following point.
For this implementation to compile, Rhino's
ScriptableObject.javaneeds a new method (e.g.getAllIdsIncludingSymbols()) that allows retrieval of all properties (enumerable or not not) including both strings and symbols:Test case
(This test case is also implemented in
ReflectTest.java.)Points of note
About the javadoc
The javadoc for
ownKeys()is very basic because:Regarding the ordering of property keys returned
Notice
-1is in the wrong place.:[ "0", "6", "8", "55", "773", "str", "-1", "str2", Symbol("foo"), Symbol("bar") ][ "-1", "0", "6", "8", "55", "773", "str", "str2", "Symbol(foo)", "Symbol(bar)" ]The specs for
Reflect.ownKeys()provide clear description for the ordering of these:We cannot accommodate this for
-1and other negative integers because Rhino does not preserve the property creation order of negative integer keys. This appears to be a bug in Rhino:0 <= i <= F[1][1] https://262.ecma-international.org/13.0/#sec-object-type
Regarding the initialization of the test case
HtmlUnit throws
invalid property iderror on the[Symbol.for('foo')]part which is a computed property name. The object is instead initialized inReflectTest.javaas such: