11.2 Types of Source Code
There are four types of ECMAScript code:
-
Global code is source text that is treated as an ECMAScript
Script . The global code of a particularScript does not include any source text that is parsed as part of aFunctionDeclaration ,FunctionExpression ,GeneratorDeclaration ,GeneratorExpression ,AsyncFunctionDeclaration ,AsyncFunctionExpression ,AsyncGeneratorDeclaration ,AsyncGeneratorExpression ,MethodDefinition ,ArrowFunction ,AsyncArrowFunction ,ClassDeclaration , orClassExpression . -
Eval code is the source text supplied to the built-in
eval
function. More precisely, if the parameter to the built-ineval
functionis a String , it is treated as an ECMAScriptScript . The eval code for a particular invocation ofeval
is the global code portion of thatScript . -
Function code is source text that is parsed to supply the value of the [[ECMAScriptCode]] and [[FormalParameters]] internal slots (see
10.2 ) of an ECMAScriptfunction object . The function code of a particular ECMAScript function does not include any source text that is parsed as the function code of a nestedFunctionDeclaration ,FunctionExpression ,GeneratorDeclaration ,GeneratorExpression ,AsyncFunctionDeclaration ,AsyncFunctionExpression ,AsyncGeneratorDeclaration ,AsyncGeneratorExpression ,MethodDefinition ,ArrowFunction ,AsyncArrowFunction ,ClassDeclaration , orClassExpression .In addition, if the source text referred to above is parsed as:
- the
FormalParameters andFunctionBody of aFunctionDeclaration orFunctionExpression , - the
FormalParameters andGeneratorBody of aGeneratorDeclaration orGeneratorExpression , - the
FormalParameters andAsyncFunctionBody of anAsyncFunctionDeclaration orAsyncFunctionExpression , or - the
FormalParameters andAsyncGeneratorBody of anAsyncGeneratorDeclaration orAsyncGeneratorExpression ,
then the
source text matched by theBindingIdentifier (if any) of that declaration or expression is also included in the function code of the corresponding function. - the
-
Module code is source text that is code that is provided as a
ModuleBody . It is the code that is directly evaluated when a module is initialized. The module code of a particular module does not include any source text that is parsed as part of a nestedFunctionDeclaration ,FunctionExpression ,GeneratorDeclaration ,GeneratorExpression ,AsyncFunctionDeclaration ,AsyncFunctionExpression ,AsyncGeneratorDeclaration ,AsyncGeneratorExpression ,MethodDefinition ,ArrowFunction ,AsyncArrowFunction ,ClassDeclaration , orClassExpression .
Function code is generally provided as the bodies of Function Definitions (
The practical effect of including the
11.2.1 Directive Prologues and the Use Strict Directive
A Directive Prologue is the longest sequence of
A Use Strict Directive is an "use strict"
or 'use strict'
. A
A
The
11.2.2 Strict Mode Code
An ECMAScript syntactic unit may be processed using either unrestricted or strict mode syntax and semantics (
-
Global code is strict mode code if it begins with aDirective Prologue that contains aUse Strict Directive . -
Module code is always strict mode code. -
All parts of a
ClassDeclaration or aClassExpression are strict mode code. -
Eval code is strict mode code if it begins with aDirective Prologue that contains aUse Strict Directive or if the call toeval
is adirect eval that is contained in strict mode code. -
Function code is strict mode code if the associatedFunctionDeclaration ,FunctionExpression ,GeneratorDeclaration ,GeneratorExpression ,AsyncFunctionDeclaration ,AsyncFunctionExpression ,AsyncGeneratorDeclaration ,AsyncGeneratorExpression ,MethodDefinition ,ArrowFunction , orAsyncArrowFunction is contained in strict mode code or if the code that produces the value of the function's [[ECMAScriptCode]] internal slot begins with aDirective Prologue that contains aUse Strict Directive . -
Function code that is supplied as the arguments to the built-in Function, Generator, AsyncFunction, and AsyncGeneratorconstructors is strict mode code if the last argumentis a String that when processed is aFunctionBody that begins with aDirective Prologue that contains aUse Strict Directive .
ECMAScript code that is not strict mode code is called non-strict code.
11.2.3 Non-ECMAScript Functions
An ECMAScript implementation may support the evaluation of function