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: allow host exotic objects to reject private fields #2807

Merged
merged 2 commits into from
Aug 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -6816,6 +6816,8 @@ <h1>
<dl class="header">
</dl>
<emu-alg>
1. If the host is a web browser, then
1. Perform ? HostEnsureCanAddPrivateElement(_O_).
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the first time that I see something like this in an algo step, I have mix feelings about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@phoddie requested that this be Annex B only, so that non-browser hosts wouldn't have to read it at all. But I really do not want to put any more things in Annex B. So this was the compromise.

Copy link
Member

Choose a reason for hiding this comment

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

While I do think it seems weird, and I think it's far more appropriate to have the check inside the host hook, this is "fine" imo - and I believe this represents pushback from @phoddie (who may want to clarify)

Copy link
Contributor

Choose a reason for hiding this comment

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

I must agreed that having this in the algos rather than in a separate sections that nobody looks at is a lot better, I was just hesitant because this is the first time I have seen this condition in the spec.

1. Let _entry_ be PrivateElementFind(_O_, _P_).
1. If _entry_ is not ~empty~, throw a *TypeError* exception.
1. Append PrivateElement { [[Key]]: _P_, [[Kind]]: ~field~, [[Value]]: _value_ } to _O_.[[PrivateElements]].
Expand All @@ -6834,6 +6836,8 @@ <h1>
</dl>
<emu-alg>
1. Assert: _method_.[[Kind]] is either ~method~ or ~accessor~.
1. If the host is a web browser, then
1. Perform ? HostEnsureCanAddPrivateElement(_O_).
1. Let _entry_ be PrivateElementFind(_O_, _method_.[[Key]]).
1. If _entry_ is not ~empty~, throw a *TypeError* exception.
1. Append _method_ to _O_.[[PrivateElements]].
Expand All @@ -6844,6 +6848,25 @@ <h1>
</emu-note>
</emu-clause>

<emu-clause id="sec-hostensurecanaddprivateelement" type="host-defined abstract operation">
<h1>
HostEnsureCanAddPrivateElement (
_O_: an Object,
): either a normal completion containing ~unused~ or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It allows host environments to prevent the addition of private elements to particular host-defined exotic objects.</dd>
</dl>
<p>An implementation of HostEnsureCanAddPrivateElement must conform to the following requirements:</p>
<ul>
<li>If _O_ is not a host-defined exotic object, this abstract operation must return NormalCompletion(~unused~) and perform no other steps.</li>
<li>Any two calls of this abstract operation with the same argument must return the same kind of Completion Record.</li>
</ul>
<p>The default implementation of HostEnsureCanAddPrivateElement is to return NormalCompletion(~unused~).</p>
<p>This abstract operation is only invoked by ECMAScript hosts that are web browsers.</p>
</emu-clause>

<emu-clause id="sec-privateget" type="abstract operation">
<h1>
PrivateGet (
Expand Down Expand Up @@ -48146,6 +48169,16 @@ <h1>Changes to the `typeof` Operator</h1>
</emu-alg>
</emu-annex>
</emu-annex>

<emu-annex id="sec-web-compat-host-make-job-callback">
<h1>Non-default behaviour in HostMakeJobCallback</h1>
<p>The HostMakeJobCallback abstract operation allows hosts which are web browsers to specify non-default behaviour.</p>
</emu-annex>

<emu-annex id="sec-web-compat-host-ensure-can-add-private-field">
<h1>Non-default behaviour in HostEnsureCanAddPrivateElement</h1>
<p>The HostEnsureCanAddPrivateElement abstract operation allows hosts which are web browsers to specify non-default behaviour.</p>
</emu-annex>
</emu-annex>
</emu-annex>

Expand Down