Skip to content
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 of for-in statement #241

Merged
merged 4 commits into from
Jun 26, 2015
Merged

Support of for-in statement #241

merged 4 commits into from
Jun 26, 2015

Conversation

ruben-ayrapetyan
Copy link
Contributor

Authors: Evgeny Gavrin, Ruben Ayrapetyan

Related issue: #51

@ruben-ayrapetyan ruben-ayrapetyan added normal parser Related to the JavaScript parser interpreter Related to the virtual machine development Feature implementation labels Jun 25, 2015
@ruben-ayrapetyan ruben-ayrapetyan added this to the Core ECMA features milestone Jun 25, 2015
* @return header of constructed strings collection (should be freed with ecma_free_values_collection),
* or NULL - if there are no properties to enumerate in for-in.
*/
static ecma_collection_header_t*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static ecma_collection_header_t *

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@egavrin
Copy link
Contributor

egavrin commented Jun 26, 2015

Good to me.

@LaszloLango
Copy link
Contributor

Please add a test for function calls in for-in, ex:

function a() { var tmp = {a: 1, b: 2,c: 3, d: 4}; return tmp; }
for (var i in a()) { console.log(i);}

&& 'a' in log
&& 'b' in log
&& 'c' in log
&& 'd' in log);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests like
for (a in b in c) {}
for ((a in b);;) { break; }
would be good

@ruben-ayrapetyan
Copy link
Contributor Author

@zherczeg, @LaszloLango, thank you for your test cases. I've added them to for-in.js test. Please, check.

@ruben-ayrapetyan ruben-ayrapetyan assigned galpeter and unassigned egavrin Jun 26, 2015
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The properties are iterated incorrectly with this patch. Take the following js:

var arr = [-1,-2,-3];

for(var i in arr)
{
  print(arr[i]);
}

This will output:

-3
-2
-1

The correct output would be:

-1
-2
-3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the order somehow specified by ECMA-262 v5?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, yeah there is no specification on this. So the order is implementation defined, hopefully there is no such test in the test262 expecting the order.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh by the way, other engines iterates arrays in order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, yeah there is no specification on this. So the order is implementation defined, hopefully there is no such test in the test262 expecting the order.

It seems to me that if some test in test262 asserts conditions that are not required by ECMA-262, then the test is incorrect.

Oh by the way, other engines iterates arrays in order.

We can support this enumeration order also, if it would be necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand there is no 'default' order for iterating over the list of properties. Some engines iterate in order of addition, others enumerate numerical properties first (like in Opera).
So, for now, I don't see the reason to change the behaviour until there will be an issue in test262. Otherwise, I need "recommendation" from trusted source.

BTW, We may ask at test262 community.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that works for me.

@ruben-ayrapetyan
Copy link
Contributor Author

@galpeter, pull request is updated. Please, check.


ecma_string_t *name_p = ecma_get_string_from_value (name_value);

if (ecma_op_object_get_property (obj_p, name_p) != NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ecma_op_object_get_property (obj_p, name_p) == NULL case possible somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, properties of iterated object could be deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, that case didn't occurred to me. BTW, I didn't see such test case, or did I missed something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. The test case should be added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case is added.

@galpeter
Copy link
Contributor

Aside from the 'delete' test case, I've got no other comments, lgtm.

@ruben-ayrapetyan ruben-ayrapetyan force-pushed the for-in_dev branch 2 times, most recently from be56c3d to 6c8025a Compare June 26, 2015 15:39
@ruben-ayrapetyan ruben-ayrapetyan assigned egavrin and unassigned galpeter Jun 26, 2015
@egavrin
Copy link
Contributor

egavrin commented Jun 26, 2015

make push

…ges.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
JerryScript-DCO-1.0-Signed-off-by: Evgeny Gavrin [email protected]
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Feature implementation interpreter Related to the virtual machine normal parser Related to the JavaScript parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants