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

Normative: Restriction on [[Prototype]] of the global object #1967

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jhnaldo
Copy link
Contributor

@jhnaldo jhnaldo commented Apr 24, 2020

According to the issue in Test262 repository, Test262 provides the following tests that assume that the global object is an instance of the built-in Object constructor:

@ljharb said in the comment:

That seems somewhat like a spec issue to me than a test issue;
web reality is that the global inherits from Object.prototype,
so at least web browsers (Annex B) would have to have that be true.

Thus, I added one restriction to the global object which is "the global object should be an instance of the standard built-in Object constructor.

@@ -24800,6 +24800,7 @@ <h1>The Global Object</h1>
<li>does not have a [[Construct]] internal method; it cannot be used as a constructor with the `new` operator.</li>
<li>does not have a [[Call]] internal method; it cannot be invoked as a function.</li>
<li>has a [[Prototype]] internal slot whose value is implementation-dependent.</li>
<li>is an instance of the standard built-in Object constructor.</li>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is “is an instance of the standard built-in Object constructor” an observable status / a defined concept?

I’m guessing the intention here is to say that the [[Prototype]] chain (initially? permanently?) includes %Object.prototype%, which is not the same thing as being an instance of a given constructor as this phrase is used elsewhere. For example,

[A Boolean Object is] a member of the Object type that is an instance of the standard built-in Boolean constructor.

It’s observable (indirectly) that an object is a Boolean Object because the [[BooleanData]] slot is obtained uniquely through creation with the Boolean constructor. It’s incidental that such an object likely has %Boolean.prototype% as its [[Prototype]], and it may not — Object.setPrototypeOf(new Boolean, null) is still a Boolean Object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with your opinion. The sentence "is instance of the the standard built-in Object constructor" does not clearly imply that the prototype chain includes %Object.prototype%. Thus, I just directly wrote that the prototype chain include %Object.prototype% and updated the pull request.

@devsnek
Copy link
Member

devsnek commented Apr 24, 2020

this is normative, not editorial.

@jhnaldo jhnaldo changed the title Editorial: Restriction on [[Prototype]] of the global object Apr 24, 2020
@jhnaldo
Copy link
Contributor Author

jhnaldo commented Apr 24, 2020

this is normative, not editorial.

Thank you for the correction, I revised the name of the pull request.

@@ -24799,7 +24799,7 @@ <h1>The Global Object</h1>
<li>is created before control enters any execution context.</li>
<li>does not have a [[Construct]] internal method; it cannot be used as a constructor with the `new` operator.</li>
<li>does not have a [[Call]] internal method; it cannot be invoked as a function.</li>
<li>has a [[Prototype]] internal slot whose value is implementation-dependent.</li>
<li>has a [[Prototype]] internal slot whose value is implementation-dependent but the prototype chain includes %Object.prototype%.</li>
Copy link
Member

Choose a reason for hiding this comment

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

One of the challenges here might be that %Object.prototype% is a Realm-specific value, but i believe the WindowProxy causes the current realm's Object.prototype to report as being in the prototype chain.

Copy link
Contributor

@ExE-Boss ExE-Boss May 1, 2020

Choose a reason for hiding this comment

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

WindowProxy.[[GetPrototypeOf]]() returns null for cross‑origin calls, which are a subset of cross‑realm calls.

Copy link
Member

Choose a reason for hiding this comment

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

Right - and null doesn't have Object.prototype in its prototype chain.

@michaelficarra michaelficarra added needs consensus This needs committee consensus before it can be eligible to be merged. normative change Affects behavior required to correctly evaluate some ECMAScript source text labels Apr 24, 2020
@littledan
Copy link
Member

Good catch! If it's not possible to make this assertion about all JS environments, another way to go about ensuring the accuracy of the tests would be to make a piece of metadata in the test262 tests indicating, "these tests are valid for environments where Object.prototype is in the prototype chain of the global object".

@ExE-Boss
Copy link
Contributor

ExE-Boss commented May 2, 2020

Well, within the realm of the global object, the global object’s prototype will always include %Object.prototype% in its prototype chain, it’s only for cross‑origin calls, which are a subset of cross‑realm calls that the WindowProxy will hide the prototype.

@littledan
Copy link
Member

littledan commented May 2, 2020

It's not really clear to me what an assertion like "the prototype chain includes" means when the prototype chain is queried by [[GetPrototypeOf]]().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs consensus This needs committee consensus before it can be eligible to be merged. normative change Affects behavior required to correctly evaluate some ECMAScript source text
7 participants