11 ECMAScript 언어: Source Text

11.1 Source Text

Syntax

SourceCharacter :: any Unicode code point

ECMAScript source text는 Unicode code point의 sequence입니다. surrogate code point를 포함하여 U+0000부터 U+10FFFF까지의 모든 Unicode code point value는 ECMAScript grammar가 허용하는 곳에서 ECMAScript source text에 occur할 수 있습니다. ECMAScript source text를 store하고 interchange하는 데 사용되는 actual encoding은 이 명세와 관련이 없습니다. external source text encoding과 관계없이, conforming ECMAScript implementation은 source text를 equivalent한 SourceCharacter value의 sequence인 것처럼 process하며, 각 SourceCharacter는 Unicode code point입니다. Conforming ECMAScript implementation은 source text의 normalization을 수행하거나, source text의 normalization을 수행하는 것처럼 behave할 필요가 없습니다.

combining character sequence의 component는 user가 전체 sequence를 single character로 생각할 수 있더라도 individual Unicode code point로 treated됩니다.

Note

string literal, regular expression literal, template literal 및 identifier 안에서는 어떤 Unicode code point든 code point의 numeric value를 explicitly express하는 Unicode escape sequence를 사용하여 표현할 수도 있습니다. comment 안에서는 그러한 escape sequence가 comment의 part로 effectively ignored됩니다.

ECMAScript는 Unicode escape sequence의 behaviour에서 Java programming language와 다릅니다. Java program에서는 예를 들어 Unicode escape sequence \u000A가 single-line comment 안에 occur하면, line terminator(Unicode code point U+000A는 LINE FEED (LF))로 interpreted되므로 다음 code point는 comment의 part가 아닙니다. 마찬가지로 Unicode escape sequence \u000A가 Java program의 string literal 안에 occur하면, 역시 line terminator로 interpreted되며, 이는 string literal 안에서 allowed되지 않습니다 — string literal의 value의 part로 LINE FEED (LF)를 cause하려면 \u000A 대신 \n을 써야 합니다. ECMAScript program에서는 comment 안에 occur하는 Unicode escape sequence가 never interpreted되므로 comment의 termination에 contribute할 수 없습니다. 마찬가지로 ECMAScript program의 string literal 안에 occur하는 Unicode escape sequence는 항상 literal에 contribute하며 line terminator로 또는 string literal을 terminate할 수 있는 code point로 never interpreted되지 않습니다.

11.1.1 Static Semantics: UTF16EncodeCodePoint ( codePoint )

The abstract operation UTF16EncodeCodePoint takes argument codePoint (a Unicode code point) and returns a String. It performs the following steps when called:

  1. Assert: 0 ≤ codePoint ≤ 0x10FFFF.
  2. codePoint ≤ 0xFFFF이면, numeric value가 codePoint인 code unit으로 구성된 String value를 반환한다.
  3. cu1을 numeric value가 floor((codePoint - 0x10000) / 0x400) + 0xD800인 code unit으로 둔다.
  4. cu2를 numeric value가 ((codePoint - 0x10000) modulo 0x400) + 0xDC00인 code unit으로 둔다.
  5. cu1cu2string-concatenation을 반환한다.

11.1.2 Static Semantics: CodePointsToString ( text )

The abstract operation CodePointsToString takes argument text (a sequence of Unicode code points) and returns a String. 6.1.4에 described된 대로 text를 String value로 convert합니다. It performs the following steps when called:

  1. result를 empty String으로 둔다.
  2. text의 각 code point codePoint에 대해, 다음을 수행한다.
    1. resultresultUTF16EncodeCodePoint(codePoint)의 string-concatenation으로 설정한다.
  3. result를 반환한다.

11.1.3 Static Semantics: UTF16SurrogatePairToCodePoint ( lead, trail )

The abstract operation UTF16SurrogatePairToCodePoint takes arguments lead (a code unit) and trail (a code unit) and returns a code point. UTF-16 surrogate pair를 form하는 두 code unit이 code point로 converted됩니다. It performs the following steps when called:

  1. Assert: leadleading surrogate이고 trailtrailing surrogate이다.
  2. codePoint를 (lead - 0xD800) × 0x400 + (trail - 0xDC00) + 0x10000으로 둔다.
  3. code point codePoint를 반환한다.

11.1.4 Static Semantics: CodePointAt ( string, position )

The abstract operation CodePointAt takes arguments string (a String) and position (a non-negative integer) and returns a Record with fields [[CodePoint]] (a code point), [[CodeUnitCount]] (a positive integer), and [[IsUnpairedSurrogate]] (a Boolean). 6.1.4에 described된 대로 string을 UTF-16 encoded code point의 sequence로 interpret하고, index position의 code unit부터 시작하여 single code point를 read합니다. It performs the following steps when called:

  1. sizestring의 length로 둔다.
  2. Assert: position ≥ 0이고 position < size이다.
  3. firststring 안의 index position에 있는 code unit으로 둔다.
  4. codePoint를 numeric value가 first의 numeric value인 code point로 둔다.
  5. firstleading surrogatetrailing surrogate도 아니면, 다음을 수행한다.
    1. Record { [[CodePoint]]: codePoint, [[CodeUnitCount]]: 1, [[IsUnpairedSurrogate]]: false }를 반환한다.
  6. firsttrailing surrogate이거나 position + 1 = size이면, 다음을 수행한다.
    1. Record { [[CodePoint]]: codePoint, [[CodeUnitCount]]: 1, [[IsUnpairedSurrogate]]: true }를 반환한다.
  7. secondstring 안의 index position + 1에 있는 code unit으로 둔다.
  8. secondtrailing surrogate가 아니면, 다음을 수행한다.
    1. Record { [[CodePoint]]: codePoint, [[CodeUnitCount]]: 1, [[IsUnpairedSurrogate]]: true }를 반환한다.
  9. codePointUTF16SurrogatePairToCodePoint(first, second)로 설정한다.
  10. Record { [[CodePoint]]: codePoint, [[CodeUnitCount]]: 2, [[IsUnpairedSurrogate]]: false }를 반환한다.

11.1.5 Static Semantics: StringToCodePoints ( string )

The abstract operation StringToCodePoints takes argument string (a String) and returns a List of code points. 6.1.4에 described된 대로 string을 UTF-16 encoded Unicode text로 interpreting한 결과인 Unicode code point의 sequence를 반환합니다. It performs the following steps when called:

  1. codePoints를 새 empty List로 둔다.
  2. sizestring의 length로 둔다.
  3. position을 0으로 둔다.
  4. position < size인 동안 Repeat,
    1. codePointCodePointAt(string, position)으로 둔다.
    2. codePoint.[[CodePoint]]codePoints에 append한다.
    3. positionposition + codePoint.[[CodeUnitCount]]로 설정한다.
  5. codePoints를 반환한다.

11.1.6 Static Semantics: ParseText ( sourceText, goalSymbol )

The abstract operation ParseText takes arguments sourceText (a String or a sequence of Unicode code points) and goalSymbol (a nonterminal in one of the ECMAScript grammars) and returns a Parse Node or a non-empty List of SyntaxError objects. It performs the following steps when called:

  1. sourceText가 String이면, sourceTextStringToCodePoints(sourceText)로 설정한다.
  2. goalSymbolgoal symbol로 사용하여 sourceText를 parse하려고 attempt하고, parse result를 early error condition이 있는지 analyse한다. Parsing과 early error detection은 implementation-defined manner로 interleaved될 수 있다.
  3. parse가 succeeded하고 early error가 발견되지 않았으면, parse의 result로 생긴 parse tree의 root에 있는 Parse Node(goalSymbol의 instance)를 반환한다.
  4. parsing error 및/또는 early error를 represent하는 하나 이상의 SyntaxError object의 List를 반환한다. 둘 이상의 parsing error 또는 early error가 present하면, list 안의 error object의 number와 ordering은 implementation-defined이지만, 적어도 하나는 present해야 한다.
Note 1

particular point에 early error가 있고, later point에도 syntax error가 있는 text를 consider하십시오. parse pass 뒤에 early errors pass를 수행하는 implementation은 syntax error를 report하고 early errors pass로 proceed하지 않을 수 있습니다. 두 activity를 interleave하는 implementation은 early error를 report하고 syntax error를 찾기 위해 proceed하지 않을 수 있습니다. 세 번째 implementation은 두 error를 모두 report할 수 있습니다. 이 모든 behaviour는 conformant입니다.

Note 2

clause 17도 참조하십시오.

11.2 Source Code의 Types

ECMAScript code에는 네 가지 type이 있습니다:

Note 1

Function code는 일반적으로 Function Definitions(15.2), Arrow Function Definitions(15.3), Method Definitions(15.4), Generator Function Definitions(15.5), Async Function Definitions(15.8), Async Generator Function Definitions(15.6), Async Arrow Functions(15.9)의 body로 provided됩니다. Function code는 Function constructor(20.2.1.1), GeneratorFunction constructor(27.6.1.1), AsyncFunction constructor(27.10.1.1), AsyncGeneratorFunction constructor(27.7.1.1)에 대한 argument로부터도 derived됩니다.

Note 2

function code에 BindingIdentifier를 포함하는 practical effect는, surrounding code가 strict mode code가 아니더라도, strict mode code의 Early Error가 body가 Use Strict Directive를 contain하는 function의 name인 BindingIdentifier에 applied된다는 것입니다.

11.2.1 Directive Prologues와 Use Strict Directive

Directive PrologueFunctionBody, ScriptBody 또는 ModuleBody의 initial StatementListItem 또는 ModuleItem로 occurring하는 ExpressionStatement의 longest sequence이며, 그 sequence 안의 각 ExpressionStatement는 전적으로 StringLiteral token과 그 뒤의 semicolon으로 구성됩니다. semicolon은 explicitly 나타날 수도 있고 automatic semicolon insertion(12.10)에 의해 inserted될 수도 있습니다. Directive Prologue는 empty sequence일 수 있습니다.

Use Strict DirectiveDirective Prologue 안의 ExpressionStatement 중 그 StringLiteral이 exact code point sequence "use strict" 또는 'use strict'인 것입니다. Use Strict DirectiveEscapeSequence 또는 LineContinuation을 contain할 수 없습니다.

Directive Prologue는 둘 이상의 Use Strict Directive를 contain할 수 있습니다. 그러나 이런 일이 발생하면 implementation은 warning을 issue할 수 있습니다.

Note

Directive PrologueExpressionStatement는 containing production의 evaluation 중에 normally evaluated됩니다. Implementation은 Use Strict Directive가 아니며 Directive Prologue 안에 occur하는 ExpressionStatement에 대해 implementation specific meaning을 define할 수 있습니다. appropriate notification mechanism이 존재하면, implementation은 Directive Prologue 안에서 Use Strict Directive가 아니며 implementation에 의해 정의된 meaning을 가지지 않는 ExpressionStatement를 encounter할 때 warning을 issue해야 합니다.

11.2.2 Strict Mode Code

ECMAScript syntactic unit은 unrestricted 또는 strict mode syntax and semantics(4.3.2)를 사용하여 processed될 수 있습니다. Code는 다음 situation에서 strict mode code로 interpreted됩니다:

strict mode code가 아닌 ECMAScript code를 non-strict code라고 합니다.

11.2.2.1 Static Semantics: IsStrict ( parseNode )

The abstract operation IsStrict takes argument parseNode (a Parse Node) and returns a Boolean. It performs the following steps when called:

  1. parseNode에 matched된 source text가 strict mode code이면, true를 반환한다.
  2. false를 반환한다.

11.2.3 Non-ECMAScript Functions

ECMAScript implementation은 evaluative behaviour가 ECMAScript source text가 아닌 host-defined form의 executable code로 expressed되는 function exotic object의 evaluation을 support할 수 있습니다. function object가 ECMAScript code 안에서 defined되었는지 또는 built-in function인지 여부는 그러한 function object를 call하거나 그러한 function object에 의해 called되는 ECMAScript code의 perspective에서는 observable하지 않습니다.