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

Editorial: "a function object" -> "an ECMAScript function object" #3144

Merged
merged 1 commit into from
Aug 16, 2023

Conversation

jmdyck
Copy link
Collaborator

@jmdyck jmdyck commented Aug 9, 2023

This PR narrows "a function object" to "an ECMAScript function object" where appropriate.

(This is an expansion of #3138 (comment).)

I've split it into 2 commits to make it a bit easier to follow the propagation of narrowing, but they can probably be squashed for merging.


commit 1: Creating an ECMAScript function object

OrdinaryFunctionCreate returns an ECMAScript function object (EFO).

(1)
So, every operation that returns the result of OrdinaryFunctionCreate (i.e., every operation that creates a function for a FunctionBody or similar) also returns an EFO:

  • InstantiateOrdinaryFunctionObject
  • InstantiateOrdinaryFunctionExpression
  • InstantiateArrowFunctionExpression
  • DefineMethod
  • InstantiateGeneratorFunctionObject
  • InstantiateGeneratorFunctionExpression
  • InstantiateAsyncGeneratorFunctionObject
  • InstantiateAsyncGeneratorFunctionExpression
  • InstantiateAsyncFunctionObject
  • InstantiateAsyncFunctionExpression
  • InstantiateAsyncArrowFunctionExpression
  • CreateDynamicFunction

and, going one further level up,

  • InstantiateFunctionObject

(2)
A Record field that only ever holds the result of OrdinaryFunctionCreate holds an EFO:

  • ClassFieldDefinition Record's [[Initializer]] field
  • ClassStaticBlockDefinition Record's [[BodyFunction]] field

commit 2: Calling an ECMAScript function object

By definition, 10.2.1 [[Call]] and 10.2.2 [[Construct]] only operate on EFOs.

From this, we know the following are only invoked on EFOs:

  • PrepareForOrdinaryCall
  • OrdinaryCallBindThis
  • OrdinaryCallEvaluateBody

And, from the last,

  • EvaluateBody

And from that,

  • EvaluateFunctionBody
  • EvaluateConciseBody
  • EvaluateGeneratorBody
  • EvaluateAsyncGeneratorBody
  • EvaluateAsyncFunctionBody
  • EvaluateAsyncConciseBody
  • EvaluateClassStaticBlockBody

And from those,

  • FunctionDeclarationInstantiation

Downstream specs: The only downstream reference to any of these things is HTML's use of OrdinaryFunctionCreate, and it doesn't care that we're narrowing the declared return type.

Copy link
Member

@michaelficarra michaelficarra left a comment

Choose a reason for hiding this comment

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

We have so many kinds of functions!

@bakkot bakkot added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Aug 16, 2023
@ljharb ljharb force-pushed the ECMAScript_function_object branch 2 times, most recently from 9a75782 to ab8a1c1 Compare August 16, 2023 22:36
@jmdyck jmdyck force-pushed the ECMAScript_function_object branch from ab8a1c1 to 42305c6 Compare August 16, 2023 23:06
…c39#3144)

... in the declared type of parameters, returns, and record fields,
where appropriate.
@ljharb ljharb force-pushed the ECMAScript_function_object branch from 42305c6 to 0802e7d Compare August 16, 2023 23:07
@ljharb ljharb merged commit 0802e7d into tc39:main Aug 16, 2023
@jmdyck jmdyck deleted the ECMAScript_function_object branch August 17, 2023 15:51
zhangenming pushed a commit to zhangenming/ecma262 that referenced this pull request Dec 22, 2023
…c39#3144)

... in the declared type of parameters, returns, and record fields,
where appropriate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial change ready to merge Editors believe this PR needs no further reviews, and is ready to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants