-
Notifications
You must be signed in to change notification settings - Fork 107
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: Restrict the use of PrivateNames in class decorators #136
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,11 +438,12 @@ <h1>%PrivateName% ( )</h1> | |
</emu-clause> | ||
|
||
<emu-clause id="sec-private-name-object" aoid=PrivateNameObject> | ||
<h1>PrivateNameObject ( _name_ )</h1> | ||
<h1>PrivateNameObject ( _name_, _restricted_ )</h1> | ||
<p>When PrivateNameObject is called with Private Name _name_, the following steps are taken:</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<emu-alg> | ||
1. Let _O_ be ? ObjectCreate(%PrivateNamePrototype%, « [[PrivateName]] »). | ||
1. Let _O_ be ? ObjectCreate(%PrivateNamePrototype%, « [[PrivateNameData]], [[PrivateNameRestricted]] »). | ||
1. Set _O_.[[PrivateNameData]] to _name_. | ||
1. Set _O_.[[PrivateNameRestricted]] to _restricted_. | ||
1. Perform ! SetIntegrityLevel(_O_, `"frozen"`). | ||
1. Return _O_. | ||
</emu-alg> | ||
|
@@ -464,6 +465,7 @@ <h1>%PrivateName%.prototype.get ( _object_ )</h1> | |
<emu-alg> | ||
1. Let _O_ be the *this* value. | ||
1. Let _pn_ be ? GetPrivateName(_O_). | ||
1. If _pn_.[[PrivateNameRestricted]] is *true*, throw a *TypeError* exception. | ||
1. If Type(_object_) is not Object, throw a *TypeError* exception. | ||
1. Return ? PrivateFieldGet(_pn_, _object_). | ||
</emu-alg> | ||
|
@@ -475,6 +477,7 @@ <h1>%PrivateName%.prototype.set ( _object_, _value_ )</h1> | |
<emu-alg> | ||
1. Let _O_ be the *this* value. | ||
1. Let _pn_ be ? GetPrivateName(_O_). | ||
1. If _pn_.[[PrivateNameRestricted]] is *true*, throw a *TypeError* exception. | ||
1. If Type(_object_) is not Object, throw a *TypeError* exception. | ||
1. Return ? PrivateFieldSet(_pn_, _object_, _value_). | ||
</emu-alg> | ||
|
@@ -521,7 +524,7 @@ <h1>GetPrivateName ( _O_ )</h1> | |
|
||
<emu-clause id="sec-properties-of-private-name-instances"> | ||
<h1>Properties of PrivateName Instances</h1> | ||
<p>PrivateName instances are ordinary objects that inherit properties from the PrivateName prototype object. PrivateName instances have a [[PrivateNameData]] internal slot. The [[PrivateNameData]] internal slot is the Private Name value represented by this Private Name object.</p> | ||
<p>PrivateName instances are ordinary objects that inherit properties from the PrivateName prototype object. PrivateName instances have [[PrivateNameData]] and [[PrivateNameRestricted]] internal slots. The [[PrivateNameData]] internal slot is the Private Name value represented by this Private Name object. [[PrivateNameRestricted]] is a boolean, indicating whether `get` and `set` operations are permitted. </p> | ||
</emu-clause> | ||
</emu-clause> | ||
</emu-clause> | ||
|
@@ -657,7 +660,7 @@ <h1>DecorateElement ( _element_, _placements_ )</h1> | |
1. Let _finishers_ be a new empty List. | ||
1. For each _decorator_ in _element_.[[Decorators]], in reverse list order do | ||
1. Perform RemoveElementPlacement(_element_, _placements_). | ||
1. Let _elementObject_ be ? FromElementDescriptor(_element_). | ||
1. Let _elementObject_ be ? FromElementDescriptor(_element_, *false*). | ||
1. Let _elementFinisherExtrasObject_ be ? Call(_decorator_, *undefined*, « _elementObject_ »). | ||
1. If _elementFinisherExtrasObject_ is *undefined*, | ||
1. Let _elementFinisherExtrasObject_ be _elementObject_. | ||
|
@@ -731,21 +734,21 @@ <h1>FromElementDescriptors ( _elements_ )</h1> | |
1. Assert: _elements_ is a List of ElementDescriptor Records. | ||
1. Let _elementObjects_ be a new empty List. | ||
1. For each _element_ in _elements_, do | ||
1. Append ! FromElementDescriptor(_element_) to _elementObjects_. | ||
1. Append ! FromElementDescriptor(_element_, *true*) to _elementObjects_. | ||
1. Return ! CreateArrayFromList(_elementObjects_). | ||
</emu-alg> | ||
</emu-clause> | ||
|
||
<emu-clause id=sec-from-element-descriptor aoid=FromElementDescriptor> | ||
<h1>FromElementDescriptor ( _element_ )</h1> | ||
<h1>FromElementDescriptor ( _element_, _restricted_ )</h1> | ||
<emu-alg> | ||
1. Assert: _element_ is an ElementDescriptor Record. | ||
1. Let _obj_ be ! ObjectCreate(%ObjectPrototype%). | ||
1. Let _desc_ be PropertyDescriptor{ [[Value]]: `"Descriptor"`, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }. | ||
1. Perform ! DefinePropertyOrThrow(_obj_, @@toStringTag, _desc_). | ||
1. Perform ! CreateDataPropertyOrThrow(_obj_, `"kind"`, _element_.[[Kind]]). | ||
1. Let _key_ be _element_.[[Key]]. | ||
1. If _key_ is a Private Name, set _key_ to ? PrivateNameObject(_key_). | ||
1. If _key_ is a Private Name, set _key_ to ? PrivateNameObject(_key_, _restricted_). | ||
1. Perform ! CreateDataPropertyOrThrow(_obj_, `"key"`, _key_). | ||
1. Perform ! CreateDataPropertyOrThrow(_obj_, `"placement"`, _element_.[[Placement]]). | ||
1. Perform ! CreateDataPropertyOrThrow(_obj_, `"descriptor"`, ! FromPropertyDescriptor(_element_.[[Descriptor]])). | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it might be better to name this "privileged" instead of "restricted", so that behavior can default to the safe thing instead of to the unsafe thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting a change in runtime semantics, or just an editorial change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An editorial change, to invert the default from "privileged" to "restricted".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The design guideline used in ES5 when designing property descriptors:
Applying that guideline to this API the second parameter might be called readWriteAllowed and should default to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, there is no public API proposed in this patch; we are talking about names for what goes on when decorators expose private fields.
How about getSetAllowed? Read/write would be sort of new terms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that it isn't a public API, but it is still an API used by spec. writers and readers.
I don't really care what name you chose as long as it describes what setting it to true enables.