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

Unclear possibility to return non-Completion Record values from abstract operations #2314

Closed
arhadthedev opened this issue Feb 18, 2021 · 2 comments
Labels
completion records Relates to completion records, and ? / ! notation.

Comments

@arhadthedev
Copy link
Contributor

ReturnIfAbrupt describes ReturnIfAbrupt(argument) as:

1. If argument is an abrupt completion, return argument.
2. Else if argument is a Completion Record, set argument to argument.[[Value]].

Step 2 assumes that argument may be something different from a Completion Record (either normal or abrupt). The same is with other declarations of ReturnIfAbrupt.

However, Implicit Completion Values guarantees that abstract operations always (with undefined edge cases) return a Completion Record:

Unless it is otherwise obvious from the context, an algorithm statement that returns a value that is not a Completion Record, such as:

  1. Return "Infinity".

means the same thing as:

  1. Return NormalCompletion("Infinity").

that makes the assumption probably excessive.

So I propose:

  1. Either (if non-record values really may be returned) add references to cases covered by "Unless it is otherwise obvious" and replace obviousness with formal criteria;

  2. Or (otherwise):

    • remove else if foo is a Completion Record, set foo to foo.[[Value]] steps in ReturnIfAbrupt;

    • rephrase Implicit Completion Values:

      The algorithms of this specification often implicitly return Completion Records whose [[Type]] is normal. Unless it is otherwise obvious from the context, an algorithm statement that returns a value that is not a Completion Record, such as:

      to:

      An algorithm statement that returns a value that is not a Completion Record, such as:

@bakkot bakkot added the completion records Relates to completion records, and ? / ! notation. label Feb 18, 2021
@bakkot
Copy link
Contributor

bakkot commented Feb 18, 2021

The handling of completion records is inconsistent in a number of ways; see this label in the issue tracker. For example, the implicit coercion you quote doesn't actually make sense: abstract operations can return values which are neither ECMAScript language values nor ~empty~, but a normal completion can only hold values of those types.

I intend to deal with this more comprehensively when I have time, including eliminating all implicit wrapping and unwrapping.

@arhadthedev
Copy link
Contributor Author

Thank you, I really missed specification and host types (with examples found in #496). Also, I am happy to hear about planned specification-wide revamping of such incoherencies; I also know that it will require a long time to not break anything and properly update external specifications that refer to ECMAScript abstract operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completion records Relates to completion records, and ? / ! notation.
Projects
None yet
Development

No branches or pull requests

2 participants