Repository navigation
Editorial Conventions
- use consistent phrasing as much as possible
- without loss of readability, minimise the number of foundational concepts in the spec
- consider how each change will affect the full variety of potential spec consumers
- so that fragment links continue to bring the visitor to the most relevant position in the current document, preserve old IDs (using the
oldidsattribute if necessary) - AO summaries are normative, so every claim they contain should be correct without further qualification. However, they can (and are expected to) omit some details so as to be more easily understandable. Additionally, AO summaries may provide relevant context that makes no claims about the behaviour of the AO.
Ecma maintains a "standard for standards", TOOLS-011, available on the Ecma documents server, which outlines many rules for presentation and text conventions for Ecma documents. Make a best effort to follow these rules, with the following exceptions:
-
6.2.14: Decimal fractions and large numbers
We use a
.(FULL STOP) for the decimal mark and a,(COMMA) for digit grouping, as this is the common convention for other web technology specifications, despite the broad recommendation across standards-setting organisations. -
6.2.15: Names of graphic characters and control functions
We use Unicode for representation of text, not any of the listed Ecma standards for text encoding. Because of that, we follow Unicode conventions for character naming and code point references.
-
5.2: Subdivision of text: clauses
We allow clauses to be arbitrarily subdivided whenever doing so would improve the experience for a consumer.
Ecma officially follows ISO/IEC directives. The editors of ECMA-262 have made no effort to follow these guidelines but are not opposed to adopting them where they can improve the readability or usability of the document for our considered consumers.
- use
%notation to refer to intrinsic objects, not "the initial value of" - test for presence of a field using
_record_ has a/an [[X]] field, not_record_.[[X]] is present - use
a/an/a newfor creating and referencing values with identity; usethefor referencing values without identity- prefer
the empty Stringover*""*
- prefer
- in an SDO invocation, use "the" before the SDO name iff all of the following hold:
- the SDO name is a noun phrase
- the SDO does not return a completion record
- the SDO invocation does not occur within the argument list of another AO invocation
- a grammar production "matches" some source text, and source text "is matched by" some grammar production; never the other way around
- don't unnecessarily qualify object types with the word "object";
_x_ is an Array, not_x_ is an Array object, with the following exceptions:- when referring to an exotic object in a context which emphasizes its exotic nature, use
an X exotic object - "Set object", to distinguish from the spec-internal type of the same name
- "Error object" and variants, to make it clear it's talking about a value rather than an exceptional condition
- "RegExp object", to distinguish it from RegExp literals
- "Proxy object" because it reads a little better
- when referring to an exotic object in a context which emphasizes its exotic nature, use
- don't say
the value of _a_; just use_a_ - don't say "value" after the name of a spec type when following a determiner: prefer "a String" over "a String value"
- don't use demonstrative determiners as type assertions (
the String _v_whenvis already aString) when an assertion step can be used instead - don't use increment/decrement, increase/decrease, or add/subtract; instead, use the regular facilities, as in
set _x_ to _x_ + 1 - to create an untagged union of types,
- If all types are singletons, use
A(for 1 type),either A or B(for 2), orone of A, B, or C(for 3+) - Else, use
an A(for 1 type),either an A or a B(for 2), oreither an A, a B, or a C(for 3+) where all singleton types appear last
- If all types are singletons, use
- use
a new empty Listto construct an empty List outside of AO argument lists and record initializers - inside AO argument lists and record initializers, construct Lists using double angle brackets («»).
- use
the list-concatenation ofto construct a List from some other Lists; see list-concatenation - append or prepend a value to a List using
append _x_ to _list_orprepend _x_ to _list_, respectively - to test whether a List is empty, use
_list_ is emptyor_list_ is not empty - to access the first element of a List whose length is known to be 1, use
the sole element of _list_ - to get the length of a List, use
the number of elements in _list_
- when comparing an alias/AO result/etc. against a single value or multiple options, it should be on the left and literal value(s) should be on the right
- when comparing for equality against a single value, the preferred form depends upon the type of that value:
-
_x_ = …or_x_ ≠ …for a bigint, mathematical value, or extended mathematical value -
SameValue(_x_, …) is *true*for an object, symbol (except well-known), or ECMAScript language value that has not been narrowed to a single type -
_x_ is …or_x_ is not …for anything else (boolean, number, string, well-known symbol, null, undefined, spec enum, etc.); don't use "is the same as" or "is different from"
-
- when comparing for equality against multiple options,
- preserve explicit pairwise
=/≠/SameValue(e.g.,_x_ = _option1_ or _x_ = _option2_ or _x_ = …) - consolidate
is/is notusingeither…or/neither…norfor a pair of options (e.g.,_x_ is neither _option1_ nor _option2_) - consolidate
is/is notusingone offor more than two options (e.g.,_x_ is not one of _option1_, _option2_, or _option3_)
- preserve explicit pairwise
- when comparing a value against a type, a union of types, or a union of types and values, use union-of-types phrasing that treats each individual value as an ad-hoc singleton type (e.g.,
_x_ is either a String, +∞, or -∞)- when negating such a comparison, the requirement for singleton types to appear last is relaxed (e.g.,
_x_ is not one of *+∞<sub>𝔽</sub>*, *-∞<sub>𝔽</sub>*, or an integral Numberis acceptable)
- when negating such a comparison, the requirement for singleton types to appear last is relaxed (e.g.,
- when making a relative comparison against a number, bigint, mathematical value, or extended mathematical value, use
<,≤,>, or≥ - presence in a List is tested with
_list_ contains _element_or_list_ does not contain _element_, not_element_ is an element of _list_or_element_ is in _list_ - prefer
whose … is …overwhose … is that of … - when comparing a value against both
undefinedandnull, prefer the orderis either *undefined* or *null*overis either *null* or *undefined*for consistency
- assertion steps should not be necessary to understand an algorithm; a reader should interpret it the same if they are removed
- don't use demonstrative determiners as a hand-wavey way to perform a conversion (
the String _v_whenvis not aString) - prefer "if a or b" over "if a or if b"; prefer "if a and b" over "if a and if b"
- in algorithm steps, each alias should only be introduced (such as with "Let") at most once for any possible trace through the algorithm
- in an if/else or if/else-if/else, either all branches are given substeps or all branches are collapsed (have no substeps)
- in a single-line if/else, all branches should "do the same thing", e.g. set the same alias, return, perform, etc.
- if an early-exiting if/else has just two branches (i.e. not an if-else cascade like in some Math functions), and the two branches are substantially similar and short, prefer a single step
- if an early-exiting if/else has more than two branches (i.e. is an if-else cascade), prefer multi-step, without a leading
Else,on successive branches - if an early-exiting if/else has just two branches but the complexity of the two branches differs greatly (e.g. one branch has more steps than the other), prefer multi-step without a leading
Else,on the else branch - invoke AOs that return
~unused~only from the top level of a step, using the verb "perform" - prefer spec enums over sentinel values like -1
- do not re-use the same spec enum value in unrelated places (excepting
~unused~) - avoid unnecessarily dynamic things such as:
- embedding algorithm steps or AO names in table cells to be used as a makeshift virtual dispatch table
- constructing the name of an AO to invoke it (or internal slot to access it)
- aliasing AOs or internal slots
- coordinating through ambiently-available state instead of explicitly passed values
- etc.
- do not mutate Completion Records
- when returning a constant after comparing it to an alias, return the constant, not the alias:
If _x_ is *null*, return *null*. - prefer "is a throw completion", "is a normal completion", etc. shorthands over comparing against the
[[Type]]slot of a Completion Record - prefer
throwshorthand overreturn ThrowCompletion(...) - lead with validation steps that early exit, then follow the happy path
- algorithm steps should do only 1 thing, don't try to do in 1 step what could be done in 2 or more
- all calls which produce Completion Records should be annotated as
? Foo(),! Foo(), orCompletion(Foo())(except for theNormalCompletionAO and friends) - algorithms should either always produce a Completion Record or never produce a Completion Record
- captured aliases in ACs should not be written to, even if the write is only observed within the AC
- aliases that are captured by an AC should not be written to outside the AC after their capture
-
prefer descriptive, multi-word alias names over single-word names, especially for longer-lived aliases
-
the following words (including their plural forms) must always be abbreviated in alias names as the prescribed abbreviation; no other words may be abbreviated in alias names
root word chosen abbreviation argumentargasynchronousasyncattributeattrbooleanboolcharactercharconstructorctordeclarationdecldeclarativedecldescriptordescenvironmentenvexpressionexprfunctionfuncgeneratorgenintegerintobjectobjparameterparamprototypeprotoreferencerefregularExpressionregexpstatementstmtsynchronoussynctimeValuetvtypedArraytaNote that the above table should be kept consistent with the CSV used by CI to automatically validate this convention.
NOTE: ecmarkup enforces many typographic conventions, most of which are not listed here
- include Oxford commas
- denote all characters literally, using HTML entities only as required by HTML syntax
- use this spacing for Records:
{ [[key1]]: value1, [[key2]]: value2 } - use this spacing for Lists:
« value1, value2 » - use “typographic double quotes” (U+201C and U+201D) in prose, not "straight quotes"
- always indicate the sign of floating point zeroes using either +0𝔽 or -0𝔽; never use 0𝔽