### Development Workflow Setup and Execution
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/build-system.md
Installs dependencies and starts the build process in watch mode for development. Automatically refreshes the browser on file changes.
```bash
# Setup
npm install
# Watch mode (terminal 1)
npm run watch
# Edit spec.html
# Browser automatically refreshes as changes are saved
# When ready to publish
npm run format # Auto-format markup
npm run check-commit # Validate commit messages
npm run build # Final production build
```
--------------------------------
### Clone and Setup Repository
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/quick-reference.md
Clone the ECMAScript repository and install its dependencies to begin development. The 'watch' command provides a live-reload development environment.
```bash
git clone https://github.com/tc39/ecma262.git
cd ecma262
npm install
npm run watch
```
--------------------------------
### Install Node.js on Windows
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Installs Node.js using Chocolatey on Windows.
```bash
# Windows
choco install nodejs
```
--------------------------------
### Install Node.js on Linux
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Installs Node.js and npm using apt-get on Ubuntu/Debian.
```bash
# Linux (Ubuntu/Debian)
sudo apt-get install nodejs npm
```
--------------------------------
### Verify Git Installation
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Checks the installed Git version.
```bash
git --version
```
--------------------------------
### Verify Bibliography Installation
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/biblio-package.md
After installing the @tc39/ecma262-biblio package, verify its installation using npm.
```bash
npm install @tc39/ecma262-biblio
npm ls @tc39/ecma262-biblio # Verify installation
```
--------------------------------
### Clone Repository and Install Dependencies
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/development-tools.md
Clone the ECMA-262 repository, navigate into the directory, install project dependencies using npm, and set up build and watch scripts.
```bash
git clone https://github.com/tc39/ecma262.git
cd ecma262
npm install
npm run build
npm run watch
```
--------------------------------
### Pre-push Hook Script Example
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Example script for a pre-push hook that validates commit messages and builds the project.
```bash
#!/bin/bash
npm run check-commit || exit 1
npm run build || exit 1
```
--------------------------------
### Install Node.js on macOS
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Installs Node.js using Homebrew on macOS.
```bash
# macOS
brew install node
```
--------------------------------
### Verify Node.js Installation
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Checks the installed Node.js version.
```bash
node --version
```
--------------------------------
### Verify npm Installation
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Checks the installed npm version.
```bash
npm --version
```
--------------------------------
### RegExp.prototype.exec() Example with Alternatives
Source: https://github.com/tc39/ecma262/blob/main/spec.html
Demonstrates how the RegExp.prototype.exec() method handles alternatives when a shorter match is found first.
```javascript
/a|ab/.exec("abc")
```
--------------------------------
### Pre-commit Hook Script Example
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Example script for a pre-commit hook that formats code and checks commit messages.
```bash
#!/bin/bash
npm run format
npm run check-commit
```
--------------------------------
### String.prototype.localeCompare Canonical Equivalence Examples
Source: https://github.com/tc39/ecma262/blob/main/spec.html
Demonstrates how String.prototype.localeCompare recognizes and honors canonical equivalence according to the Unicode Standard. These examples show comparisons of characters that may look different but are considered equivalent.
```javascript
"\u212B".localeCompare("A\u030A")
```
```javascript
"\u2126".localeCompare("\u03A9")
```
```javascript
"\u1E69".localeCompare("s\u0307\u0323")
```
```javascript
"\u1E0B\u0323".localeCompare("\u1E0D\u0307")
```
```javascript
"\u1100\u1161".localeCompare("\uAC00")
```
--------------------------------
### Install Prince on macOS
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Installs the Prince HTML to PDF converter on macOS using Homebrew.
```bash
# macOS
brew install prince
```
--------------------------------
### Valid Commit Message Examples
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/workflow.md
Examples of correctly formatted commit messages for various types of changes.
```text
Normative: Fix Array.prototype.splice to handle sparse arrays (#3456)
Editorial: Clarify grammar in 12.2.1 (#3456)
Meta: Add TypeScript definitions to build (#3456)
Markup: Add cross-reference IDs to clause 8.1 (#3456)
Layering: Add ArrayBuffer alignment requirements (#3456)
```
--------------------------------
### Function Constructor Examples
Source: https://github.com/tc39/ecma262/blob/main/spec.html
Demonstrates different ways to invoke the `Function` constructor with varying argument formats for parameters and body.
```javascript
new Function("a", "b", "c", "return a+b+c")
```
```javascript
new Function("a, b, c", "return a+b+c")
```
```javascript
new Function("a,b", "c", "return a+b+c")
```
--------------------------------
### Main Module Example
Source: https://github.com/tc39/ecma262/blob/main/FAQ.md
This is the entry point module that imports and uses the isOdd function, initiating the module loading and evaluation process.
```javascript
import {isOdd} from "./Odd";
isOdd(2);
```
--------------------------------
### RegExp Constructor Initialization Steps
Source: https://github.com/tc39/ecma262/blob/main/spec.html
Outlines the steps performed when the RegExp constructor is called, including handling existing RegExp objects and initializing new ones.
```ecmascript
1. Let _patternIsRegExp_ be ? IsRegExp(_patternOrRegexp_).
2. If NewTarget is *undefined*, then
1. Let _newTarget_ be the active function object.
3. If _patternIsRegExp_ is *true* and _flags_ is *undefined*, then
1. Let _patternCtor_ be ? Get(_patternOrRegexp_, "constructor").
2. If SameValue(_newTarget_, _patternCtor_) is *true*, return _patternOrRegexp_.
4. Else,
1. Let _newTarget_ be NewTarget.
5. If _patternOrRegexp_ is an Object and _patternOrRegexp_ has a [[RegExpMatcher]] internal slot, then
1. Let _patternSource_ be _patternOrRegexp_.[[OriginalSource]].
2. If _flags_ is *undefined*, set _flags_ to _patternOrRegexp_.[[OriginalFlags]].
6. Else if _patternIsRegExp_ is *true*, then
1. Let _patternSource_ be ? Get(_patternOrRegexp_, "source").
2. If _flags_ is *undefined*, then
1. Set _flags_ to ? Get(_patternOrRegexp_, "flags").
7. Else,
1. Let _patternSource_ be _patternOrRegexp_.
8. Let _obj_ be ? RegExpAlloc(_newTarget_).
9. Return ? RegExpInitialize(_obj_, _patternSource_, _flags_).
```
--------------------------------
### Format and Build Specification
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/quick-reference.md
Run these commands to format the specification files and build the output. This is a common step after making editorial or normative changes.
```bash
npm run format
npm run build
```
--------------------------------
### Invalid Commit Message Examples
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/workflow.md
Examples of incorrectly formatted commit messages that would fail validation.
```text
Fix Array.prototype.splice # Missing prefix and PR number
Normative: Fix Array.prototype.splice # Missing PR number
Fix array splice (#3456) # Missing prefix
Normative: Fix Array.prototype.splice (#abc) # PR number not integer
```
--------------------------------
### Expanded '?' Shorthand Example
Source: https://github.com/tc39/ecma262/blob/main/spec.html
Shows the step-by-step expansion of the '?' shorthand when used in conjunction with another operation, demonstrating the unwrapping and propagation logic.
```ecmascript
1. Perform AO(? Other()).
```
--------------------------------
### GitHub Actions Build and Test Job
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/configuration.md
Example commands for building and testing the project in a GitHub Actions workflow.
```bash
npm run build
npm run test
```
--------------------------------
### Built-in Method Description Format
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/specification-format.md
Illustrates the standard format for documenting built-in methods, including their signature, description, notes, algorithm steps, and examples.
```html
When the concat method is called with zero or more arguments... This is a non-normative note explaining the behavior. Example code:Array.prototype.concat ( ...items )
[1,2,3].concat([4,5]) // [1,2,3,4,5]
A Promise is an object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
A Promise is in one of three states:
block. This is for illustrative purposes and not part of the normative specification.
```javascript
const arr = [1, 2, 3];
console.log(arr.concat([4, 5])); // [1, 2, 3, 4, 5]
```
--------------------------------
### String.prototype.substring
Source: https://github.com/tc39/ecma262/blob/main/spec.html
Returns a substring of the string, from the start index up to (but not including) the end index. Handles NaN, negative, and out-of-bounds indices by clamping them to the string's length or zero. If start is greater than end, the arguments are swapped.
```APIDOC
## String.prototype.substring
### Description
Returns a substring of the result of converting this object to a String, starting from index `_start_` and running to, but not including, index `_end_` of the String (or through the end of the String if `_end_` is *undefined*). The result is a String value, not a String object.
If either argument is *NaN* or negative, it is replaced with zero; if either argument is strictly greater than the length of the String, it is replaced with the length of the String.
If `_start_` is strictly greater than `_end_`, they are swapped.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Method
`substring(_start_, _end_)`
### Endpoint
N/A (This is a prototype method)
### Request Example
N/A
### Response
#### Success Response
- **Return Value** (string) - The extracted substring.
#### Response Example
N/A
```
--------------------------------
### Module Execution Steps
Source: https://github.com/tc39/ecma262/blob/main/spec.html
This pseudocode outlines the steps for executing an ECMAScript module, including resolving indirect exports, setting up the module environment, and processing import entries.
```ecmascript
1. For each ExportEntry Record _e_ of _module.[[IndirectExportEntries]], do
1. Assert: _e.[[ExportName]] is not *null*.
1. Let _resolution_ be _module.ResolveExport(_e.[[ExportName]]).
1. If _resolution_ is either *null* or ~ambiguous~, throw a *SyntaxError* exception.
1. Assert: _resolution_ is a ResolvedBinding Record.
1. Assert: All named exports from _module_ are resolvable.
1. Let _realm_ be _module.[[Realm]].
1. Assert: _realm_ is not *undefined*.
1. Let _envRecord_ be NewModuleEnvironment(_realm.[[GlobalEnv]]).
1. Set _module.[[Environment]] to _envRecord_.
1. For each ImportEntry Record _in_ of _module.[[ImportEntries]], do
1. Let _importedModule_ be GetImportedModule(_module, _in.[[ModuleRequest]]).
1. If _in.[[ImportName]] is ~namespace~, then
1. Let _namespace_ be GetModuleNamespace(_importedModule_).
1. Perform ! _envRecord_.CreateImmutableBinding(_in.[[LocalName]], *true*).
1. Perform ! _envRecord_.InitializeBinding(_in.[[LocalName]], _namespace_).
1. Else,
1. Assert: _in.[[ImportName]] is a String.
1. Let _resolution_ be _importedModule_.ResolveExport(_in.[[ImportName]]).
1. If _resolution_ is either *null* or ~ambiguous~, throw a *SyntaxError* exception.
1. If _resolution.[[BindingName]] is ~namespace~, then
1. Let _namespace_ be GetModuleNamespace(_resolution.[[Module]]).
1. Perform ! _envRecord_.CreateImmutableBinding(_in.[[LocalName]], *true*).
1. Perform ! _envRecord_.InitializeBinding(_in.[[LocalName]], _namespace_).
1. Else,
1. Perform CreateImportBinding(_envRecord_, _in.[[LocalName]], _resolution.[[Module]], _resolution.[[BindingName]]).
1. Let _moduleContext_ be a new ECMAScript code execution context.
1. Set the Function of _moduleContext_ to *null*.
1. Assert: _module.[[Realm]] is not *undefined*.
1. Set the Realm of _moduleContext_ to _module.[[Realm]].
1. Set the ScriptOrModule of _moduleContext_ to _module_.
1. Set the VariableEnvironment of _moduleContext_ to _module.[[Environment]].
1. Set the LexicalEnvironment of _moduleContext_ to _module.[[Environment]].
1. Set the PrivateEnvironment of _moduleContext_ to *null*.
1. Set _module.[[Context]] to _moduleContext_.
1. Push _moduleContext_ onto the execution context stack; _moduleContext_ is now the running execution context.
1. Let _code_ be _module.[[ECMAScriptCode]].
1. Let _variableDecls_ be the VarScopedDeclarations of _code_.
1. Let _declaredVariableNames_ be a new empty List.
1. For each element _d_ of _variableDecls_, do
1. For each element _dn_ of the BoundNames of _d_, do
1. If _declaredVariableNames_ does not contain _dn_, then
1. Perform ! _envRecord_.CreateMutableBinding(_dn_, *false*).
1. Perform ! _envRecord_.InitializeBinding(_dn_, *undefined*).
1. Append _dn_ to _declaredVariableNames_.
1. Let _lexicalDecls_ be the LexicallyScopedDeclarations of _code_.
1. Let _privateEnv_ be *null*.
1. For each element _d_ of _lexicalDecls_, do
1. For each element _dn_ of the BoundNames of _d_, do
1. If IsConstantDeclaration of _d_ is *true*, then
1. Perform ! _envRecord_.CreateImmutableBinding(_dn_, *true*).
1. Else,
1. Perform ! _envRecord_.CreateMutableBinding(_dn_, *false*).
1. If _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, an |AsyncFunctionDeclaration|, or an |AsyncGeneratorDeclaration|, then
1. Let _funcObj_ be InstantiateFunctionObject of _d_ with arguments _envRecord_ and _privateEnv_.
1. Perform ! _envRecord_.InitializeBinding(_dn_, _funcObj_).
1. Remove _moduleContext_ from the execution context stack.
1. Return ~unused~.
```
--------------------------------
### Reflect.getPrototypeOf
Source: https://github.com/tc39/ecma262/blob/main/spec.html
Gets the prototype of a specified object.
```APIDOC
## Reflect.getPrototypeOf
### Description
Gets the prototype of a specified object.
### Method
Reflect.getPrototypeOf
### Parameters
- `_target_` (Object) - The object whose prototype to get.
### Returns
The prototype of the specified object.
```
--------------------------------
### Build All Specification Files
Source: https://github.com/tc39/ecma262/blob/main/_autodocs/README.md
Runs the full build process for the ECMAScript specification, including validation. This is a key script for generating the final specification output.
```bash
npm run build
```
--------------------------------
### Reflect.get
Source: https://github.com/tc39/ecma262/blob/main/spec.html
Gets the value of a property of an object.
```APIDOC
## Reflect.get
### Description
Gets the value of a property of an object.
### Method
Reflect.get
### Parameters
- `_target_` (Object) - The object from which to get the property value.
- `_key_` (string | symbol) - The name of the property to retrieve.
- `_receiver_` (Object, optional) - The value to use as `this` when getting the property's value.
### Returns
The value of the specified property. If the property does not exist, `undefined` is returned.
```
--------------------------------
### Lexical Ambiguity Example (Division vs. RegExp)
Source: https://github.com/tc39/ecma262/blob/main/spec.html
Illustrates a scenario where lexical analysis is sensitive to syntactic context, specifically distinguishing between division/division-assignment and regular expression literals. This example shows how ECMAScript avoids semicolon insertion issues.
```javascript
a = b
/hi/g.exec(c).map(d);
```
```javascript
a = b / hi / g.exec(c).map(d);
```