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

Suggestion in IteratorClose #335

Closed
h2oche opened this issue Aug 13, 2020 · 1 comment
Closed

Suggestion in IteratorClose #335

h2oche opened this issue Aug 13, 2020 · 1 comment
Assignees

Comments

@h2oche
Copy link

h2oche commented Aug 13, 2020

OS : macOS ver 10.15.3
Version: GraalVM JavaScript (GraalVM CE Native 20.1.0)

When following JavaScript code is executed, GraalJS throws TypeError exception.

"use strict";
var x = {

};
x[Symbol.iterator] = function() {
  return {
    next: function() {
      return { done: false, value: null };
    },
    return: 'str'
  };
};
for (var y of x) throw 42;

However, according to latest ECMA-262 specification(https://tc39.es/ecma262/), correct behavior of script above is to throw exception in for - of body.

In "7.4.6 IteratorClose",

  • This algorithm is invoked by step 6.k.iv.2 in "13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation" with status which is abrupt completion of type throw.
  • in step 4, GetMethod throws TypeError and stored in innerResult
  • in step 6, type of completion is throw, so completion is returned instead of innerResult which contains TypeError.

Although current behavior of GraalJS conforms to ES2020, this was reported as specification bug and patched in latest ECMAScript(related PR: tc39/ecma262#1408).

Furthermore, all the other engines like QuickJS or V8 follow latest ECMAScript.
Test262 also added this behavior in their conformance test suite, so I guess it would be better to follow latest specification rather than ES2020.

Related Test262 test cases :

  • language/statements/for-of/iterator-close-throw-get-method-abrupt.js
  • language/statements/for-of/iterator-close-throw-get-method-non-callable.js
@iamstolis
Copy link
Member

GraalVM 20.1.0 (that was used to reproduce this issue) was following the old version of the specification. We adopted the mentioned specification change since then (by 4fc16de) and we pass the mentioned test-case and the related Test262 by now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants