mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 21:31:46 +00:00
62 lines
15 KiB
HTML
62 lines
15 KiB
HTML
<!DOCTYPE html><html lang="en-GB-oxendict"><head><meta name="viewport" content="width=device-width, initial-scale=1"><meta charset="utf-8"><meta property="og:image" content="https://tc39.es/ecmarkup/ecma-logo.png"><meta property="og:title" content="ECMAScript® 2026 Language Specification"><meta property="og:description" content="Introduction
|
|
This Ecma Standard defines the ECMAScript 2026 Language. It is the seventeenth edition of the ECMAScript Language Specification. ECMAScript is based on several originating technologies, the most well-known being JavaScript (Netscape) and JScript (Microsoft). The language was invent">
|
|
<link rel="icon" href="../img/favicon.ico">
|
|
<link rel="stylesheet" href="../assets/css/ecmarkup.css"><link rel="stylesheet" href="../assets/css/print.css" media="print">
|
|
|
|
<title>ECMAScript® 2026 Language Specification</title><script src="../assets/js/multipage.js?cache=Wu2V1pj2" defer=""></script><script src="../assets/js/ecmarkup.js?cache=BPFBckdu" defer=""></script><link rel="canonical" href="../#sec-error-handling-and-language-extensions"></head>
|
|
<body><div id="spec-container"><emu-clause id="sec-error-handling-and-language-extensions">
|
|
<h1><span class="secnum">17</span> Error Handling and Language Extensions</h1>
|
|
<p>An implementation must report most errors at the time the relevant ECMAScript language construct is evaluated. An <dfn id="early-error" variants="early errors" tabindex="-1">early error</dfn> is an error that can be detected and reported prior to the evaluation of any construct in the <emu-nt id="_ref_23761"><a href="ecmascript-language-scripts-and-modules.html#prod-Script">Script</a></emu-nt> containing the error. The presence of an <emu-xref href="#early-error" id="_ref_9452"><a href="error-handling-and-language-extensions.html#early-error">early error</a></emu-xref> prevents the evaluation of the construct. An implementation must report <emu-xref href="#early-error" id="_ref_9453"><a href="error-handling-and-language-extensions.html#early-error">early errors</a></emu-xref> in a <emu-nt id="_ref_23762"><a href="ecmascript-language-scripts-and-modules.html#prod-Script">Script</a></emu-nt> as part of parsing that <emu-nt id="_ref_23763"><a href="ecmascript-language-scripts-and-modules.html#prod-Script">Script</a></emu-nt> in <emu-xref aoid="ParseScript" id="_ref_9454"><a href="ecmascript-language-scripts-and-modules.html#sec-parse-script">ParseScript</a></emu-xref>. <emu-xref href="#early-error" id="_ref_9455"><a href="error-handling-and-language-extensions.html#early-error">Early errors</a></emu-xref> in a <emu-nt id="_ref_23764"><a href="ecmascript-language-scripts-and-modules.html#prod-Module">Module</a></emu-nt> are reported at the point when the <emu-nt id="_ref_23765"><a href="ecmascript-language-scripts-and-modules.html#prod-Module">Module</a></emu-nt> would be evaluated and the <emu-nt id="_ref_23766"><a href="ecmascript-language-scripts-and-modules.html#prod-Module">Module</a></emu-nt> is never initialized. <emu-xref href="#early-error" id="_ref_9456"><a href="error-handling-and-language-extensions.html#early-error">Early errors</a></emu-xref> in <b>eval</b> code are reported at the time <code>eval</code> is called and prevent evaluation of the <b>eval</b> code. All errors that are not <emu-xref href="#early-error" id="_ref_9457"><a href="error-handling-and-language-extensions.html#early-error">early errors</a></emu-xref> are runtime errors.</p>
|
|
<p>An implementation must report as an <emu-xref href="#early-error" id="_ref_9458"><a href="error-handling-and-language-extensions.html#early-error">early error</a></emu-xref> any occurrence of a condition that is listed in a “Static Semantics: Early Errors” subclause of this specification.</p>
|
|
<p>An implementation shall not treat other kinds of errors as <emu-xref href="#early-error" id="_ref_9459"><a href="error-handling-and-language-extensions.html#early-error">early errors</a></emu-xref> even if the compiler can prove that a construct cannot execute without error under any circumstances. An implementation may issue an early warning in such a case, but it should not report the error until the relevant construct is actually executed.</p>
|
|
<p>An implementation shall report all errors as specified, except for the following:</p>
|
|
<ul>
|
|
<li>
|
|
Except as restricted in <emu-xref href="#sec-forbidden-extensions" id="_ref_515"><a href="error-handling-and-language-extensions.html#sec-forbidden-extensions">17.1</a></emu-xref>, a <emu-xref href="#host" id="_ref_9460"><a href="overview.html#host">host</a></emu-xref> or implementation may extend <emu-nt id="_ref_23767"><a href="ecmascript-language-scripts-and-modules.html#prod-Script">Script</a></emu-nt> syntax, <emu-nt id="_ref_23768"><a href="ecmascript-language-scripts-and-modules.html#prod-Module">Module</a></emu-nt> syntax, and regular expression pattern or flag syntax. To permit this, all operations (such as calling <code>eval</code>, using a regular expression literal, or using the Function or RegExp <emu-xref href="#constructor" id="_ref_9461"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>) that are allowed to throw <emu-val>SyntaxError</emu-val> are permitted to exhibit <emu-xref href="#host-defined" id="_ref_9462"><a href="overview.html#host-defined">host-defined</a></emu-xref> behaviour instead of throwing <emu-val>SyntaxError</emu-val> when they encounter a <emu-xref href="#host-defined" id="_ref_9463"><a href="overview.html#host-defined">host-defined</a></emu-xref> extension to the script syntax or regular expression pattern or flag syntax.
|
|
</li>
|
|
<li>
|
|
Except as restricted in <emu-xref href="#sec-forbidden-extensions" id="_ref_516"><a href="error-handling-and-language-extensions.html#sec-forbidden-extensions">17.1</a></emu-xref>, a <emu-xref href="#host" id="_ref_9464"><a href="overview.html#host">host</a></emu-xref> or implementation may provide additional types, values, objects, properties, and functions beyond those described in this specification. This may cause constructs (such as looking up a variable in the global scope) to have <emu-xref href="#host-defined" id="_ref_9465"><a href="overview.html#host-defined">host-defined</a></emu-xref> behaviour instead of throwing an error (such as <emu-val>ReferenceError</emu-val>).
|
|
</li>
|
|
</ul>
|
|
|
|
<emu-clause id="sec-forbidden-extensions">
|
|
<h1><span class="secnum">17.1</span> Forbidden Extensions</h1>
|
|
<p>An implementation must not extend this specification in the following ways:</p>
|
|
<ul>
|
|
<li>
|
|
ECMAScript <emu-xref href="#function-object" id="_ref_9466"><a href="ecmascript-data-types-and-values.html#function-object">function objects</a></emu-xref> defined using syntactic <emu-xref href="#constructor" id="_ref_9467"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> in <emu-xref href="#sec-strict-mode-code" id="_ref_9468"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref> must not be created with own properties named <emu-val>"caller"</emu-val> or <emu-val>"arguments"</emu-val>. Such own properties also must not be created for <emu-xref href="#function-object" id="_ref_9469"><a href="ecmascript-data-types-and-values.html#function-object">function objects</a></emu-xref> defined using an <emu-nt id="_ref_23769"><a href="ecmascript-language-functions-and-classes.html#prod-ArrowFunction">ArrowFunction</a></emu-nt>, <emu-nt id="_ref_23770"><a href="ecmascript-language-functions-and-classes.html#prod-MethodDefinition">MethodDefinition</a></emu-nt>, <emu-nt id="_ref_23771"><a href="ecmascript-language-functions-and-classes.html#prod-GeneratorDeclaration">GeneratorDeclaration</a></emu-nt>, <emu-nt id="_ref_23772"><a href="ecmascript-language-functions-and-classes.html#prod-GeneratorExpression">GeneratorExpression</a></emu-nt>, <emu-nt id="_ref_23773"><a href="ecmascript-language-functions-and-classes.html#prod-AsyncGeneratorDeclaration">AsyncGeneratorDeclaration</a></emu-nt>, <emu-nt id="_ref_23774"><a href="ecmascript-language-functions-and-classes.html#prod-AsyncGeneratorExpression">AsyncGeneratorExpression</a></emu-nt>, <emu-nt id="_ref_23775"><a href="ecmascript-language-functions-and-classes.html#prod-ClassDeclaration">ClassDeclaration</a></emu-nt>, <emu-nt id="_ref_23776"><a href="ecmascript-language-functions-and-classes.html#prod-ClassExpression">ClassExpression</a></emu-nt>, <emu-nt id="_ref_23777"><a href="ecmascript-language-functions-and-classes.html#prod-AsyncFunctionDeclaration">AsyncFunctionDeclaration</a></emu-nt>, <emu-nt id="_ref_23778"><a href="ecmascript-language-functions-and-classes.html#prod-AsyncFunctionExpression">AsyncFunctionExpression</a></emu-nt>, or <emu-nt id="_ref_23779"><a href="ecmascript-language-functions-and-classes.html#prod-AsyncArrowFunction">AsyncArrowFunction</a></emu-nt> regardless of whether the definition is contained in <emu-xref href="#sec-strict-mode-code" id="_ref_9470"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>. Built-in functions, <emu-xref href="#strict-function" id="_ref_9471"><a href="ordinary-and-exotic-objects-behaviours.html#strict-function">strict functions</a></emu-xref> created using the Function <emu-xref href="#constructor" id="_ref_9472"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>, generator functions created using the Generator <emu-xref href="#constructor" id="_ref_9473"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>, async functions created using the AsyncFunction <emu-xref href="#constructor" id="_ref_9474"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>, and functions created using the <code>bind</code> method also must not be created with such own properties.
|
|
</li>
|
|
<li>
|
|
If an implementation extends any <emu-xref href="#function-object" id="_ref_9475"><a href="ecmascript-data-types-and-values.html#function-object">function object</a></emu-xref> with an own property named <emu-val>"caller"</emu-val> the value of that property, as observed using <var class="field">[[Get]]</var> or <var class="field">[[GetOwnProperty]]</var>, must not be a <emu-xref href="#strict-function" id="_ref_9476"><a href="ordinary-and-exotic-objects-behaviours.html#strict-function">strict function</a></emu-xref> object. If it is an <emu-xref href="#sec-object-type" id="_ref_9477"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref>, the function that is the value of the property's <var class="field">[[Get]]</var> attribute must never return a <emu-xref href="#strict-function" id="_ref_9478"><a href="ordinary-and-exotic-objects-behaviours.html#strict-function">strict function</a></emu-xref> when called.
|
|
</li>
|
|
<li>
|
|
Neither mapped nor unmapped arguments objects may be created with an own property named <emu-val>"caller"</emu-val>.
|
|
</li>
|
|
<li>
|
|
The behaviour of built-in methods which are specified in ECMA-402, such as those named <code>toLocaleString</code>, must not be extended except as specified in ECMA-402.
|
|
</li>
|
|
<li>
|
|
The RegExp pattern grammars in <emu-xref href="#sec-patterns" id="_ref_517"><a href="text-processing.html#sec-patterns">22.2.1</a></emu-xref> and <emu-xref href="#sec-regular-expressions-patterns" id="_ref_518"><a href="additional-ecmascript-features-for-web-browsers.html#sec-regular-expressions-patterns">B.1.2</a></emu-xref> must not be extended to recognize any of the source characters A-Z or a-z as <emu-nt params="+UnicodeMode" id="_ref_23780"><a href="text-processing.html#prod-IdentityEscape">IdentityEscape</a><emu-mods><emu-params>[+UnicodeMode]</emu-params></emu-mods></emu-nt> when the <sub>[UnicodeMode]</sub> grammar parameter is present.
|
|
</li>
|
|
<li>
|
|
The Syntactic Grammar must not be extended in any manner that allows the token <code>:</code> to immediately follow source text that is matched by the <emu-nt id="_ref_23781"><a href="ecmascript-language-expressions.html#prod-BindingIdentifier">BindingIdentifier</a></emu-nt> nonterminal symbol.
|
|
</li>
|
|
<li>
|
|
When processing <emu-xref href="#sec-strict-mode-code" id="_ref_9479"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>, an implementation must not relax the <emu-xref href="#early-error" id="_ref_9480"><a href="error-handling-and-language-extensions.html#early-error">early error</a></emu-xref> rules of <emu-xref href="#sec-numeric-literals-early-errors" id="_ref_519"><a href="ecmascript-language-lexical-grammar.html#sec-numeric-literals-early-errors">12.9.3.1</a></emu-xref>.
|
|
</li>
|
|
<li>
|
|
<emu-nt id="_ref_23782"><a href="ecmascript-language-lexical-grammar.html#prod-TemplateEscapeSequence">TemplateEscapeSequence</a></emu-nt> must not be extended to include <emu-nt id="_ref_23783"><a href="ecmascript-language-lexical-grammar.html#prod-LegacyOctalEscapeSequence">LegacyOctalEscapeSequence</a></emu-nt> or <emu-nt id="_ref_23784"><a href="ecmascript-language-lexical-grammar.html#prod-NonOctalDecimalEscapeSequence">NonOctalDecimalEscapeSequence</a></emu-nt> as defined in <emu-xref href="#sec-literals-string-literals" id="_ref_520"><a href="ecmascript-language-lexical-grammar.html#sec-literals-string-literals">12.9.4</a></emu-xref>.
|
|
</li>
|
|
<li>
|
|
When processing <emu-xref href="#sec-strict-mode-code" id="_ref_9481"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>, the extensions defined in <emu-xref href="#sec-labelled-function-declarations" id="_ref_521"><a href="additional-ecmascript-features-for-web-browsers.html#sec-labelled-function-declarations">B.3.1</a></emu-xref>, <emu-xref href="#sec-block-level-function-declarations-web-legacy-compatibility-semantics" id="_ref_522"><a href="additional-ecmascript-features-for-web-browsers.html#sec-block-level-function-declarations-web-legacy-compatibility-semantics">B.3.2</a></emu-xref>, <emu-xref href="#sec-functiondeclarations-in-ifstatement-statement-clauses" id="_ref_523"><a href="additional-ecmascript-features-for-web-browsers.html#sec-functiondeclarations-in-ifstatement-statement-clauses">B.3.3</a></emu-xref>, and <emu-xref href="#sec-initializers-in-forin-statement-heads" id="_ref_524"><a href="additional-ecmascript-features-for-web-browsers.html#sec-initializers-in-forin-statement-heads">B.3.5</a></emu-xref> must not be supported.
|
|
</li>
|
|
<li>
|
|
When parsing for the <emu-nt id="_ref_23785"><a href="ecmascript-language-scripts-and-modules.html#prod-Module">Module</a></emu-nt> <emu-xref href="#sec-context-free-grammars" id="_ref_9482"><a href="notational-conventions.html#sec-context-free-grammars">goal symbol</a></emu-xref>, the lexical grammar extensions defined in <emu-xref href="#sec-html-like-comments" id="_ref_525"><a href="additional-ecmascript-features-for-web-browsers.html#sec-html-like-comments">B.1.1</a></emu-xref> must not be supported.
|
|
</li>
|
|
<!-- The following is so that in the future we can potentially add new arguments or support ArgumentList. -->
|
|
<li>
|
|
<emu-nt id="_ref_23786"><a href="ecmascript-language-expressions.html#prod-ImportCall">ImportCall</a></emu-nt> must not be extended.
|
|
</li>
|
|
</ul>
|
|
</emu-clause>
|
|
</emu-clause></div></body></html> |