-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: Consistify prose for intrinsic functions #2592
Conversation
There's another inconsistency that might be within the scope of this PR, but I didn't do anything about it because I'm not sure how to resolve it. When a function definition includes a prose summary, it's sometimes a For example,
It looks like the summaries-as-Notes arose in ES6. The old ecmascript.org wiki says:
My guess is that this was written by @allenwb, and refers to the summaries-as-notes we see in String.p.* and Array.p.*. Here are some possible actions:
There's a related oddity that sometimes a summary-as-Note appears after the We could easily move these up, but it's maybe not worth it until we have a solution to the Note-vs-p problem. |
What about the Promise statics? |
spec.html
Outdated
@@ -13480,13 +13480,15 @@ <h1> | |||
|
|||
<emu-clause id="sec-%throwtypeerror%"> | |||
<h1>%ThrowTypeError% ( )</h1> | |||
<p>The <dfn>%ThrowTypeError%</dfn> intrinsic is an anonymous built-in function object that is defined once for each realm. When %ThrowTypeError% is called it performs the following steps:</p> | |||
<p>This function is the <dfn>%ThrowTypeError%</dfn> intrinsic object.</p> |
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.
“intrinsic object” seems redundant here; the % syntax already conveys that.
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.
So would you prefer
This function is <dfn>%ThrowTypeError%</dfn>.
? And likewise for the other function properties of the global object?
The words "intrinsic object" are certainly redundant, but they might be useful. Imagine someone is browsing the spec, and they don't know about intrinsic objects, but they come across one of these percent-thingies, so they click on it and land at a clause that says "This function is %foo%." Well, that's something, but it doesn't explain what a percent-thingy is. However, saying "This function is the %foo% intrinsic object" would give them a phrase that they could then look up. (It would be better if "intrinsic object" were an auto-linked phrase.)
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.
Yes, that’d be what i expect.
% syntax should ideally link to the section describing it, yes.
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.
% syntax should ideally link to the section describing it, yes.
Are you saying that uses of the % syntax (e.g. %Foo%) should link to 6.1.7.4 Well-Known Intrinsic Objects rather than the clause where the particular %Foo% is defined?
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.
Hmm - I’m just saying that the syntax should link somewhere; i don’t have a strong opinion as to where.
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.
Okay, well:
- Every use of a well-known intrinsic already auto-links to the clause that defines it.
- Ditto for the bulk of the not-well-known (NWK) intrinsics that the spec actually references (e.g.
%Object.prototype%
and%Function.prototype%
). - I count 15 in-spec references to 11 NWK intrinsics that don't get auto-linked (e.g., 3 uses of
%Array.prototype.values%
). So there's room for improvement. - And then there are scads of NWK intrinsics that wouldn't get auto-linked if they were referenced, but the spec never does (e.g.
%String.prototype.at%
).
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.
ok, so maybe usage should link to definition, but the definition site should link to the section explaining the syntax?
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.
So, e.g.,
This function is the <dfn>%ThrowTypeError%</dfn> intrinsic object.
could retain the redundant "intrinsic object", but that phrase could auto-link to 6.1.7.4.
If the editors agree they should be referred to as 'methods', I'll make that change. |
I think we should extend structured headers to also support built‑in function objects. |
The general approach for structured headers has been to first decide on a regular form for the prose and only then support generating it from a structured header. |
I'm not sure that intrinsic functions have enough commonality (factorable stuff) to make structured headers worthwhile. (At least, not in the way that abstract operations have them.) One thing we could do (that's roughly in that direction) would be to identify things that can appear in the defining clause of an intrinsic function, and then say how and in what order they should appear. E.g., here are some things in a possible order (note that I'm not saying much about their form):
It's possible that the ecmarkup tool could recognize these things and enforce their order + form, but I kind of doubt that it will be reading a structured header and generating boilerplate. |
1c01a56
to
22c324a
Compare
(force-pushed to resolve merge conflicts) |
I'd be willing to modify intrinsics prose as suggested above, but it would need some direction from editors. I'm not saying such changes would need to be incorporated into this PR, this is just where the idea came up. |
22c324a
to
c66bdd8
Compare
c66bdd8
to
eb573c5
Compare
eb573c5
to
37c392b
Compare
(force-pushed to resolve merge conflicts) |
37c392b
to
8156427
Compare
(force-pushed to resolve merge conflicts) |
@@ -31148,14 +31164,15 @@ <h1>Number.prototype.toFixed ( _fractionDigits_ )</h1> | |||
|
|||
<emu-clause id="sec-number.prototype.tolocalestring"> | |||
<h1>Number.prototype.toLocaleString ( [ _reserved1_ [ , _reserved2_ ] ] )</h1> | |||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the `Number.prototype.toLocaleString` method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the `toLocaleString` method is used.</p> | |||
<p>Produces a String value that represents this Number value formatted according to the conventions of the host environment's current locale. This function is implementation-defined, and it is permissible, but not encouraged, for it to return the same thing as `toString`.</p> | |||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> |
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.
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> | |
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:</p> |
Maybe? The original lacked this as well, but I think the wording tweak makes it a little less clear, and the colon makes it more clear.
@@ -31329,8 +31346,8 @@ <h1>BigInt.prototype.constructor</h1> | |||
|
|||
<emu-clause id="sec-bigint.prototype.tolocalestring"> | |||
<h1>BigInt.prototype.toLocaleString ( [ _reserved1_ [ , _reserved2_ ] ] )</h1> | |||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the `BigInt.prototype.toLocaleString` method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the `toLocaleString` method is used.</p> | |||
<p>Produces a String value that represents this BigInt value formatted according to the conventions of the host environment's current locale. This function is implementation-defined, and it is permissible, but not encouraged, for it to return the same thing as `toString`.</p> | |||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> |
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.
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> | |
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:</p> |
as above.
@@ -31610,7 +31627,7 @@ <h1>Math.ceil ( _x_ )</h1> | |||
|
|||
<emu-clause id="sec-math.clz32"> | |||
<h1>Math.clz32 ( _x_ )</h1> |
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'm amused that almost all of the math functions get descriptions but clz32
does not, as if readers might need an explanation for what sqrt
means but can be expected to understand clz32
without elaboration. Doesn't need to be changed now, though.
<emu-note> | ||
<p>If _sec_ is not present, this method behaves as if _sec_ was present with the value `getUTCSeconds()`. If _ms_ is not present, it function behaves as if _ms_ was present with the value return by `getUTCMilliseconds()`.</p> |
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.
That typo goes back to es2015, geeze.
<p>The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.</p> | ||
</emu-clause> | ||
|
||
<emu-clause id="sec-date.prototype.tolocaletimestring"> | ||
<h1>Date.prototype.toLocaleTimeString ( [ _reserved1_ [ , _reserved2_ ] ] )</h1> | ||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the `Date.prototype.toLocaleTimeString` method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the `toLocaleTimeString` method is used.</p> | ||
<p>This function returns a String value. The contents of the String are implementation-defined, but are intended to represent the “time” portion of the Date in the current time zone in a convenient, human-readable form that corresponds to the conventions of the host environment's current locale.</p> | ||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> |
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.
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> | |
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:</p> |
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the `localeCompare` method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the `localeCompare` method is used.</p> | ||
<p>When the `localeCompare` method is called with argument _that_, it returns a Number other than *NaN* representing the result of an implementation-defined locale-sensitive String comparison of the *this* value (converted to a String _S_) with _that_ (converted to a String _thatValue_). The result is intended to correspond with a sort order of String values according to conventions of the host environment's current locale, and will be negative when _S_ is ordered before _thatValue_, positive when _S_ is ordered after _thatValue_, and zero in all other cases (representing no relative ordering between _S_ and _thatValue_).</p> | ||
<p>Before performing the comparisons, the following steps are performed to prepare the Strings:</p> | ||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> |
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.
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> | |
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:</p> |
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the `toLocaleLowerCase` method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the `toLocaleLowerCase` method is used.</p> | ||
<p>This function interprets a String value as a sequence of UTF-16 encoded code points, as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>.</p> | ||
<p>This function works exactly the same as `toLowerCase` except that it is intended to yield a locale-sensitive result corresponding with conventions of the host environment's current locale. There will only be a difference in the few cases (such as Turkish) where the rules for that language conflict with the regular Unicode case mappings.</p> | ||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> |
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.
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> | |
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:</p> |
@@ -37953,9 +37977,9 @@ <h1> | |||
<emu-clause id="sec-array.prototype.splice"> | |||
<h1>Array.prototype.splice ( _start_, _deleteCount_, ..._items_ )</h1> | |||
<emu-note> | |||
<p>The _deleteCount_ elements of the array starting at integer index _start_ are replaced by the elements of _items_. An Array containing the deleted elements (if any) is returned.</p> | |||
<p>This method deletes the _deleteCount_ elements of the array starting at integer index _start_, and replaces them with the elements of _items_. It returns an Array containing the deleted elements (if any).</p> |
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.
<p>This method deletes the _deleteCount_ elements of the array starting at integer index _start_, and replaces them with the elements of _items_. It returns an Array containing the deleted elements (if any).</p> | |
<p>This method deletes the _deleteCount_ elements of the array starting at integer index _start_ and replaces them with the elements of _items_. It returns an Array containing the deleted elements (if any).</p> |
spec.html
Outdated
</emu-note> | ||
</emu-clause> | ||
|
||
<emu-clause id="sec-array.prototype.tolocalestring"> | ||
<h1>Array.prototype.toLocaleString ( [ _reserved1_ [ , _reserved2_ ] ] )</h1> | ||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the `Array.prototype.toLocaleString` method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the `toLocaleString` method is used.</p> | ||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> |
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.
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p> | |
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:</p> |
After @bakkot's review is addressed, this will be ready to merge. |
Preserving commit messages before the big squash: commit a2eb2acb2aaa825c60a6d902edda3d2c83b6d9cf
commit e7a0ed13f4814ab3fe6dd6679610b3f842a19350
commit 2279fcf3a95f8655ca6f62e9de9b27fdd2bfa810
commit acd77713ea0a47e43e7786819b3466ad94566313
commit 28ce2022af9c757fe11152a4eb7496fa1775b8ed
commit 8b6bf1a064695864731fea9fd78fcda9c2030193
commit daedb3d1c10b3756476847245517fadd8c548aee
commit b5bc598ccb1c0e62d82631dbb5eaeb5b94718dd8
commit 6847aec7d0e74a6dd2294dcc88b65a8ef9325d21
commit 37bffb9d75ff0eb1209a15e8df276af1aa7c3081
commit dee880f788f93786874b1d2f02b6e84364e872c1
commit f8e6fd7ebe456e057da38cc6699b65dbe4e11cfe
commit e3f37437238f0e80ab030381518771ceedffce2d
|
Function.prototype[@@hasInstance]: Delete "of an object _F_". Saying "the `@@hasInstance` method of an object _F_" suggests that `_F_` is the object whose `@@hasInstance` property is this method. But step 1 of the algorithm sets `_F_` to the *this* value, which needn't be that object, so the phrase is misleading. It looks like about a dozen phrases of this form came and went during the working drafts of ES6, but this particular occurrence survived. Number.prototype.toExponential and Number.prototype.toPrecision: Convert imperative to indicative. When describing functions (or operations, for that matter), the spec almost always uses the indicative mood, making statements about the function. (E.g., "This function does X.") But rarely it uses the imperative mood, telling the function how to behave. (E.g., "Do X.") This commit changes the preambles for these 2 functions from imperative to indicative. %TypedArray%.prototype.set: Rearrange the preamble. %TypedArray%.prototype.set used to be defined by two overloads, which caused some oddness in its preamble. When I converted it to have a single definition, I should have given it a more normal preamble. So this is a belated follow-up to PR tc39#2176. %TypedArray%.prototype.slice: Eliminate repetition. The preamble has both "The following steps are taken:" and "When the `slice` method is called, the following steps are taken:" Delete the former, for consistency with other %TypedArray% methods.
force-pushed to:
@bakkot: You should probably check the fixup commit. I did the period-to-colon change in 3 places that you didn't suggest:
because the context seemed the same, and I also didn't do it one place you did suggest:
because the paragraph is followed by a Note, so ending the paragraph with colon seemed odd. |
Function.prototype[@@hasInstance]: Delete "of an object _F_". Saying "the `@@hasInstance` method of an object _F_" suggests that `_F_` is the object whose `@@hasInstance` property is this method. But step 1 of the algorithm sets `_F_` to the *this* value, which needn't be that object, so the phrase is misleading. It looks like about a dozen phrases of this form came and went during the working drafts of ES6, but this particular occurrence survived. Number.prototype.toExponential and Number.prototype.toPrecision: Convert imperative to indicative. When describing functions (or operations, for that matter), the spec almost always uses the indicative mood, making statements about the function. (E.g., "This function does X.") But rarely it uses the imperative mood, telling the function how to behave. (E.g., "Do X.") This commit changes the preambles for these 2 functions from imperative to indicative. %TypedArray%.prototype.set: Rearrange the preamble. %TypedArray%.prototype.set used to be defined by two overloads, which caused some oddness in its preamble. When I converted it to have a single definition, I should have given it a more normal preamble. So this is a belated follow-up to PR tc39#2176. %TypedArray%.prototype.slice: Eliminate repetition. The preamble has both "The following steps are taken:" and "When the `slice` method is called, the following steps are taken:" Delete the former, for consistency with other %TypedArray% methods.
f77b46a
to
2d3ecad
Compare
(Make it consistent with PR tc39#2592.)
(Make it consistent with PR tc39#2592.)
(Make it consistent with PR tc39#2592.)
(Make it consistent with PR tc39#2592)
(Make it consistent with PR tc39#2592)
Issue #2576 didn't get very far, so I created this PR to spur discussion/decisions.
The first 4 commits perform small spot fixes.
The next 2 commits normalize the use of "method" vs "function". I started with the rule that a method is a function that is the value of a property of a prototype object, because it's easy for me to detect automatically, but then added special cases for [Typed]Array.{from,of}. I made each 'direction' (method-to-function vs function-to-method) a separate commit, because I think it's easier to review the changes that way, but they could probably be squashed later.
The remaining 12 commits perform various widespread normalizations on intrinsic function prose. I've left them as distinct commits in case you want me to back out particular changes. It might also help with review. Anyhow, they could probably be squashed too.
Resolves #2304 (at least to some extent: it depends on how broadly you interpret #2304)