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

Missing definitions for "<thing> equivalent to a function that <action>" #1077

Closed
anba opened this issue Jan 26, 2018 · 6 comments · Fixed by #2439
Closed

Missing definitions for "<thing> equivalent to a function that <action>" #1077

anba opened this issue Jan 26, 2018 · 6 comments · Fixed by #2439

Comments

@anba
Copy link
Contributor

anba commented Jan 26, 2018

Added in #1073

@ljharb
Copy link
Member

ljharb commented Apr 1, 2018

This phrase was actually added in ES2015: http://ecma-international.org/ecma-262/6.0/#sec-promisereaction-records

I copied that phrasing in the "finally" spec, but afterwards, I filed #584, which refactored the existing (definitionless) usage to be strings, instead of callbacks, stored in internal slots.

I think it'd be fine to add a definition, but ES2015 didn't seem to need one - what definition would you suggest and where would it go?

@anba
Copy link
Contributor Author

anba commented Apr 12, 2018

That seems like a different case, because in ES2015 it was only used in a non-normative context whereas now it used for normative text.

@ljharb
Copy link
Member

ljharb commented Apr 12, 2018

Fair enough :-) What definition would you suggest and where would it go?

@anba
Copy link
Contributor Author

anba commented Apr 13, 2018

The easiest fix is to create normal built-in functions à la:

Add:


25.6.5.3.1.1 Return Completion Functions

A Return Completion function is an anonymous built-in function that has a [[Completion]] internal slot.

When a Return Completion function F is called, the following steps are taken:

1. Return Completion(F.[[Completion]]). 

The length property of a Return Completion function is 0.


And then replace:


  1. Let valueThunk be equivalent to a function that returns value.

With:


  1. Let stepsReturnCompletion be the algorithm steps defined in Return Completion Functions.
  2. Let valueThunk be CreateBuiltinFunction(stepsReturnCompletion, « [[Completion]] »).
  3. Set valueThunk.[[Completion]] to NormalCompletion(value).

And replace:


  1. Let thrower be equivalent to a function that throws reason.

With:


  1. Let stepsReturnCompletion be the algorithm steps defined in Return Completion Functions.
  2. Let thrower be CreateBuiltinFunction(stepsReturnCompletion, « [[Completion]] »).
  3. Set thrower.[[Completion]] to ThrowCompletion(reason).

And if we don't want to repeat the three steps to create this new function, it's also possible to add a helper like:


25.6.5.3.1.2 MakeReturnCompletionFunction(completionRecord)

The abstract operation MakeReturnCompletionFunction with argument completionRecord performs the following steps:

  1. Let stepsReturnCompletion be the algorithm steps defined in Return Completion Functions.
  2. Let F be CreateBuiltinFunction(stepsReturnCompletion, « [[Completion]] »).
  3. Set F.[[Completion]] to completionRecord.
  4. Return F.

And then use it like:


  1. Let valueThunk be MakeReturnCompletionFunction(NormalCompletion(value)).

  1. Let thrower be MakeReturnCompletionFunction(ThrowCompletion(reason)).

@domenic
Copy link
Member

domenic commented Apr 13, 2018

A more ambitious fix would be to tackle #933.

@arai-a
Copy link
Contributor

arai-a commented Nov 24, 2020

Related to #2222
if the function is passed to Promise.prototype.then ("Then Finally Function"'s case), the function's [[Realm]] slot affects embedding behavior,
so it should be explicit about [[Realm]] slot.

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

Successfully merging a pull request may close this issue.

4 participants