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: Drop [[ScriptOrModule]] slot for exotic built-ins #2190

Merged
merged 1 commit into from
Nov 4, 2020

Conversation

jmdyck
Copy link
Collaborator

@jmdyck jmdyck commented Sep 24, 2020

A built-in function that is implemented as an exotic object has no need for a [[ScriptOrModule]] internal slot. It always has the value *null*, and the only place it's used is in the [[Call]] and [[Construct]] methods for exotic built-ins, so we can just inline *null* there.

The remaining 3 appearances of [[ScriptOrModule]] pertain only to ordinary functions.

(Setting [[ScriptOrModule]] for exotic built-ins made more sense when the slot was introduced, because of the way GetActiveScriptOrModule() was written, but PR #556 changed it to basically the current situation.)

spec.html Outdated
@@ -8553,7 +8553,7 @@ <h1>FunctionDeclarationInstantiation ( _func_, _argumentsList_ )</h1>
<emu-clause id="sec-built-in-function-objects">
<h1>Built-in Function Objects</h1>
<p>The built-in function objects defined in this specification may be implemented as either ECMAScript function objects (<emu-xref href="#sec-ecmascript-function-objects"></emu-xref>) whose behaviour is provided using ECMAScript code or as implementation provided function exotic objects whose behaviour is provided in some other manner. In either case, the effect of calling such functions must conform to their specifications. An implementation may also provide additional built-in function objects that are not defined in this specification.</p>
<p>If a built-in function object is implemented as an exotic object it must have the ordinary object behaviour specified in <emu-xref href="#sec-ordinary-object-internal-methods-and-internal-slots"></emu-xref>. All such function exotic objects also have [[Prototype]], [[Extensible]], [[Realm]], and [[ScriptOrModule]] internal slots.</p>
Copy link
Member

Choose a reason for hiding this comment

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

it seems very strange to me that all functions wouldn't all have the same slots, even if it's null for this subset. What's the benefit of dropping it?

Copy link
Member

Choose a reason for hiding this comment

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

exotic objects don't all have the same slots

Copy link
Member

Choose a reason for hiding this comment

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

Surely not, but generally each category of thing shares the same slots, even if the values are different.

Copy link
Member

Choose a reason for hiding this comment

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

You might say all functions have [[Prototype]], [[Extensible]], and [[Realm]], to satisfy the invariants of the language, and [[ScriptOrModule]] is an additional slot on ECMAScript Source Text functions (and not the only one) as they come from a script or module.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it seems very strange to me that all functions wouldn't all have the same slots, even if it's null for this subset.

Table 28 lists 11 internal slots (in addition to [[Prototype]] and [[Extensible]]) that every ordinary function must have. An exotic function isn't required to have any of those, except (e.g.) where it's implementing a built-in, in which case it's currently required to have 4 of those 13 slots. This PR just reduces that 4 to 3. Are you saying that every function object should be required to have all 13?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You might say all functions have [[Prototype]], [[Extensible]], and [[Realm]], to satisfy the invariants of the language,

That would be incorrect.

  • Bound function exotic objects don't have [[Realm]].
  • Proxy function objects don't have any of those (just [[ProxyHandler]] and [[ProxyTarget]]).
  • Non-standard exotic functions aren't required to have any internal slots.

Copy link
Member

Choose a reason for hiding this comment

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

Right sorry I was more trying to say, whatever all objects happen to have is what they share, it's a cyclical definition.

@Jack-Works
Copy link
Member

@jmdyck
Copy link
Collaborator Author

jmdyck commented Sep 24, 2020

Does it related to https://github.com/Jack-Works/proposal-strict-built-in-functions?

I don't think so. That proposal appears to be normative, whereas this PR is editorial.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

I'm not sure it's an improvement, but it's definitely not worse.

@ljharb ljharb requested review from syg, bakkot and a team September 24, 2020 04:26
@ljharb ljharb self-assigned this Sep 24, 2020
A built-in function that is implemented as an exotic object
has no need for a [[ScriptOrModule]] internal slot.
It always has the value `*null*`,
and the only place it's used is in
[the [[Call]] and [[Construct]] methods for exotic built-ins](sec-built-in-function-objects-call-thisargument-argumentslist),
so we can just inline `*null*` there.

The remaining 3 appearances of [[ScriptOrModule]]
pertain only to ordinary functions.

(Setting [[ScriptOrModule]] for exotic built-ins
made more sense when the slot was introduced,
because of the way GetActiveScriptOrModule() was written,
but PR tc39#556 changed it to basically the current situation.)
@ljharb ljharb merged commit 0b3a808 into tc39:master Nov 4, 2020
@jmdyck jmdyck deleted the ScriptOrModule branch November 29, 2020 04:02
jmdyck added a commit to jmdyck/ecma262 that referenced this pull request Jun 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants