19 全局对象

下列为 全局对象

19.1 全局对象的值属性

19.1.1 globalThis

Realm 记录 realm全局对象"globalThis" 属性的初始值为 realm.[[GlobalEnv]].[[GlobalThisValue]].

该属性具有属性 { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }。

19.1.2 Infinity

Infinity 的值为 +∞𝔽(参见 6.1.6.1)。该属性具有属性 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }。

19.1.3 NaN

NaN 的值为 NaN(参见 6.1.6.1)。该属性具有属性 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }。

19.1.4 undefined

undefined 的值为 undefined(参见 6.1.1)。该属性具有属性 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }。

19.2 全局对象的函数属性

19.2.1 eval ( source )

该函数为 %eval% 内在对象。

调用时执行下列步骤:

  1. 返回 ? PerformEval(source, false, false)。

19.2.1.1 PerformEval ( source, strictCaller, direct )

The abstract operation PerformEval takes arguments source (an ECMAScript language value), strictCaller (a Boolean), and direct (a Boolean) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. 断言:如果 directfalse,则 strictCaller 也为 false
  2. 如果 source 不是一个 String,返回 source
  3. evalRealm 为当前的 Realm 记录。
  4. 注意:在直接 eval 的情况下,evalRealm 是 eval 函数的调用者和 eval 函数本身的 realm
  5. 执行 ? HostEnsureCanCompileStrings(evalRealm, « », source, direct)。
  6. inFunctionfalse
  7. inMethodfalse
  8. inDerivedConstructorfalse
  9. inClassFieldInitializerfalse
  10. 如果 directtrue,则
    1. thisEnvRecGetThisEnvironment()。
    2. 如果 thisEnvRec 是一个 Function Environment Record,则
      1. functhisEnvRec.[[FunctionObject]]
      2. inFunction 设为 true
      3. inMethod 设为 thisEnvRec.HasSuperBinding()。
      4. 如果 func.[[ConstructorKind]]derived,将 inDerivedConstructor 设为 true
      5. classFieldInitializerNamefunc.[[ClassFieldInitializerName]]
      6. 如果 classFieldInitializerNameempty,将 inClassFieldInitializer 设为 true
  11. 实现定义的顺序执行下列子步骤,可能交错进行解析与错误检测:
    1. scriptParseText(source, Script)。
    2. 如果 script 是一个错误列表,则抛出 SyntaxError 异常。
    3. 如果 script.Contains ScriptBodyfalse,返回 undefined
    4. bodyscriptScriptBody
    5. 如果 inFunctionfalsebody.Contains NewTarget,抛出 SyntaxError 异常。
    6. 如果 inMethodfalsebody.Contains SuperProperty,抛出 SyntaxError 异常。
    7. 如果 inDerivedConstructorfalsebody.Contains SuperCall,抛出 SyntaxError 异常。
    8. 如果 inClassFieldInitializertrueContainsArguments(body) 为 true,抛出 SyntaxError 异常。
  12. 如果 strictCallertrue,令 strictEvaltrue
  13. 否则,令 strictEvalScriptIsStrict(script)。
  14. runningContext正在运行的执行上下文
  15. 注意:如果 directtruerunningContext 将是执行直接 eval执行上下文。如果 directfalserunningContext 将是调用 eval 函数的执行上下文
  16. 如果 directtrue,则
    1. lexEnvNewDeclarativeEnvironment(runningContext's LexicalEnvironment)。
    2. varEnvrunningContext 的 VariableEnvironment。
    3. privateEnvrunningContext 的 PrivateEnvironment。
  17. 否则,
    1. lexEnvNewDeclarativeEnvironment(evalRealm.[[GlobalEnv]])。
    2. varEnvevalRealm.[[GlobalEnv]]
    3. privateEnvnull
  18. 如果 strictEvaltrue,将 varEnv 设为 lexEnv
  19. 如果 runningContext 尚未被挂起,则挂起 runningContext
  20. evalContext 为新的 ECMAScript 代码执行上下文
  21. evalContext 的 Function 设为 null
  22. evalContextRealm 设为 evalRealm
  23. evalContext 的 ScriptOrModule 设为 runningContext 的 ScriptOrModule。
  24. evalContext 的 VariableEnvironment 设为 varEnv
  25. evalContext 的 LexicalEnvironment 设为 lexEnv
  26. evalContext 的 PrivateEnvironment 设为 privateEnv
  27. evalContext 推入执行上下文栈evalContext 现在为正在运行的执行上下文
  28. resultCompletion(EvalDeclarationInstantiation(body, varEnv, lexEnv, privateEnv, strictEval)) 的结果。
  29. 如果 result 为普通完成,则
    1. result 设为 Completion(Evaluation of body) 的结果。
  30. 如果 result 为普通完成且 result.[[Value]]empty,则
    1. result 设为 NormalCompletion(undefined)。
  31. 挂起 evalContext 并将其从执行上下文栈中移除。
  32. 恢复当前栈顶的上下文为正在运行的执行上下文
  33. 返回 ? result
Note

如果调用 eval 的上下文代码或 eval 代码为严格模式代码,eval 代码不能在调用上下文的变量环境中实例化变量或函数绑定。相反,这些绑定在仅对 eval 代码可见的新 VariableEnvironment 中实例化。由 letconstclass 声明引入的绑定总是实例化在新的 LexicalEnvironment 中。

19.2.1.2 HostEnsureCanCompileStrings ( calleeRealm, parameterStrings, bodyString, direct )

The host-defined abstract operation HostEnsureCanCompileStrings takes arguments calleeRealm (a Realm Record), parameterStrings (a List of Strings), bodyString (a String), and direct (a Boolean) and returns either a normal completion containing unused or a throw completion. 允许宿主环境阻止某些 ECMAScript 函数,这些函数允许开发者将字符串解释并作为 ECMAScript 代码求值。

parameterStrings 表示在使用函数构造器时会被串联以构建参数列表的字符串。bodyString 表示函数体或传递给 eval 调用的字符串。 direct 表示该求值是否为直接 eval

HostEnsureCanCompileStrings 的默认实现是返回 NormalCompletion(unused)。

19.2.1.3 EvalDeclarationInstantiation ( body, varEnv, lexEnv, privateEnv, strict )

The abstract operation EvalDeclarationInstantiation takes arguments body (a ScriptBody Parse Node), varEnv (an Environment Record), lexEnv (a Declarative Environment Record), privateEnv (a PrivateEnvironment Record or null), and strict (a Boolean) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. varNamesbodyVarDeclaredNames
  2. varDeclarationsbodyVarScopedDeclarations
  3. 如果 strictfalse,则
    1. 如果 varEnvGlobal Environment Record,则
      1. varNames 的每个元素 name 执行
        1. 如果 HasLexicalDeclaration(varEnv, name) 为 true,抛出 SyntaxError 异常。
        2. 注:如果有全局词法声明,eval 将不会创建会被该全局词法声明遮蔽的全局 var 声明。
    2. thisEnvlexEnv
    3. 断言:以下循环将终止。
    4. 重复,当 thisEnvvarEnv 不是同一 Environment Record 时,
      1. 如果 thisEnv 不是 Object Environment Record,则
        1. 注:with 语句的环境不能包含任何词法声明,因此不需要检查 var/let 抛出冲突。
        2. varNames 的每个元素 name 执行
          1. 如果 ! thisEnv.HasBinding(name) 为 true,则
            1. Normative Optional
              如果宿主为 Web 浏览器或以其他方式支持 Catch 块中的 VariableStatement,则
              1. 如果 thisEnv 不是 Catch 子句的 Environment Record,抛出 SyntaxError 异常。
            2. 否则,
              1. 抛出 SyntaxError 异常。
          2. 注:直接 eval 不会将 var 声明提升至同名的词法声明之上。
      2. thisEnv 设为 thisEnv.[[OuterEnv]]
  4. privateIdentifiers 为新的空列表。
  5. pointerprivateEnv
  6. 重复,直到 pointernull
    1. pointer.[[Names]] 的每个 Private Name binding 执行
      1. 如果 privateIdentifiers 不包含 binding.[[Description]],则将 binding.[[Description]] 附加到 privateIdentifiers
    2. pointer 设为 pointer.[[OuterPrivateEnvironment]]
  7. 如果 AllPrivateIdentifiersValid of body 以参数 privateIdentifiers 为假,抛出 SyntaxError 异常。
  8. functionsToInitialize 为新的空列表。
  9. declaredFunctionNames 为新的空列表。
  10. 以逆序对 varDeclarations 的每个元素 d 执行
    1. 如果 d 既不是 VariableDeclaration、也不是 ForBinding、也不是 BindingIdentifier,则
      1. 断言:dFunctionDeclarationGeneratorDeclarationAsyncFunctionDeclarationAsyncGeneratorDeclaration 之一。
      2. 注:如果存在同名的多个函数声明,使用最后一个声明。
      3. fndBoundNames 的唯一元素。
      4. 如果 declaredFunctionNames 不包含 fn,则
        1. 如果 varEnvGlobal Environment Record,则
          1. fnDefinable 为 ? CanDeclareGlobalFunction(varEnv, fn)。
          2. 如果 fnDefinablefalse,抛出 TypeError 异常。
        2. fn 附加到 declaredFunctionNames
        3. d 插入为 functionsToInitialize 的第一个元素。
  11. declaredVarNames 为新的空列表。
  12. varDeclarations 的每个元素 d 执行
    1. 如果 dVariableDeclarationForBindingBindingIdentifier 之一,则
      1. dBoundNames 的每个字符串 vn 执行
        1. 如果 declaredFunctionNames 不包含 vn,则
          1. 如果 varEnvGlobal Environment Record,则
            1. vnDefinable 为 ? CanDeclareGlobalVar(varEnv, vn)。
            2. 如果 vnDefinablefalse,抛出 TypeError 异常。
          2. 如果 declaredVarNames 不包含 vn,则
            1. vn 附加到 declaredVarNames
  13. Normative Optional
    如果 strictfalse宿主为 Web 浏览器或以其他方式支持 块级函数声明的 Web 遗留兼容性语义,则
    1. declaredFunctionOrVarNamesdeclaredFunctionNamesdeclaredVarNames 的串联列表。
    2. 对任意 BlockCaseClauseDefaultClause x 中直接包含于其 StatementListbody.Contains xtrue 的每个 FunctionDeclaration f 执行
      1. funcNamefBindingIdentifierStringValue
      2. 如果将 FunctionDeclaration f 替换为一个具有 funcName 作为 BindingIdentifierVariableStatement 不会为 body 产生任何早期错误,则
        1. bindingExistsfalse
        2. thisEnv 设为 lexEnv
        3. 断言:以下循环将终止。
        4. 重复,直到 thisEnvvarEnv,
          1. 如果 thisEnv 不是 Object Environment Record,则
            1. 如果 ! thisEnv.HasBinding(funcName) 为 true,则
              1. Normative Optional
                如果宿主为 Web 浏览器或以其他方式支持 Catch 块中的 VariableStatement,则
                1. 如果 thisEnv 不是 Catch 子句的 Environment Record,设 bindingExiststrue
              2. 否则,
                1. bindingExiststrue
          2. thisEnv 设为 thisEnv.[[OuterEnv]]
        5. 如果 bindingExistsfalsevarEnvGlobal Environment Record,则
          1. 如果 HasLexicalDeclaration(varEnv, funcName) 为 false,则
            1. fnDefinable 为 ? CanDeclareGlobalVar(varEnv, funcName)。
          2. 否则,
            1. fnDefinablefalse
        6. 否则,
          1. fnDefinabletrue
        7. 如果 bindingExistsfalsefnDefinabletrue,则
          1. 如果 declaredFunctionOrVarNames 不包含 funcName,则
            1. 如果 varEnvGlobal Environment Record,则
              1. 执行 ? CreateGlobalVarBinding(varEnv, funcName, true)。
            2. 否则,
              1. bindingExists 为 ! varEnv.HasBinding(funcName)。
              2. 如果 bindingExistsfalse,则
                1. 执行 ! varEnv.CreateMutableBinding(funcName, true)。
                2. 执行 ! varEnv.InitializeBinding(funcName, undefined)。
            3. funcName 附加到 declaredFunctionOrVarNames
          2. FunctionDeclaration f 被求值时,替代 15.2.6 中提供的 FunctionDeclaration 求值算法执行下列步骤:
            1. gEnv正在运行的执行上下文的 VariableEnvironment。
            2. bEnv正在运行的执行上下文的 LexicalEnvironment。
            3. fObj 为 ! bEnv.GetBindingValue(funcName, false)。
            4. 执行 ? gEnv.SetMutableBinding(funcName, fObj, false)
            5. 返回 unused
  14. 注:除非 varEnvGlobal Environment Record全局对象为 Proxy 异常对象,否则在本算法步骤后不会发生异常终止。
  15. lexDeclarationsbodyLexicallyScopedDeclarations
  16. lexDeclarations 的每个元素 d 执行
    1. 注:词法声明的名字仅在此处被实例化但不被初始化。
    2. dBoundNames 的每个元素 dn 执行
      1. 如果 IsConstantDeclaration(d) 为 true,则
        1. 执行 ? lexEnv.CreateImmutableBinding(dn, true)。
      2. 否则,
        1. 执行 ? lexEnv.CreateMutableBinding(dn, false)。
  17. functionsToInitialize 的每个 Parse Node f 执行
    1. fnfBoundNames 的唯一元素。
    2. foInstantiateFunctionObject(f, lexEnv, privateEnv)。
    3. 如果 varEnvGlobal Environment Record,则
      1. 执行 ? CreateGlobalFunctionBinding(varEnv, fn, fo, true)。
    4. 否则,
      1. bindingExists 为 ! varEnv.HasBinding(fn)。
      2. 如果 bindingExistsfalse,则
        1. 注:由于在 14 之前已进行验证,因此以下调用不会返回异常完成。
        2. 执行 ! varEnv.CreateMutableBinding(fn, true)。
        3. 执行 ! varEnv.InitializeBinding(fn, fo)。
      3. 否则,
        1. 执行 ! varEnv.SetMutableBinding(fn, fo, false)。
  18. declaredVarNames 的每个字符串 vn 执行
    1. 如果 varEnvGlobal Environment Record,则
      1. 执行 ? CreateGlobalVarBinding(varEnv, vn, true)。
    2. 否则,
      1. bindingExists 为 ! varEnv.HasBinding(vn)。
      2. 如果 bindingExistsfalse,则
        1. 注:由于在 14 之前已进行验证,因此以下调用不会返回异常完成。
        2. 执行 ! varEnv.CreateMutableBinding(vn, true)。
        3. 执行 ! varEnv.InitializeBinding(vn, undefined)。
  19. 返回 unused

19.2.2 isFinite ( number )

该函数为 %isFinite% 内在对象。

调用时执行下列步骤:

  1. num 为 ? ToNumber(number)。
  2. 如果 num有限值,返回 true
  3. 返回 false

19.2.3 isNaN ( number )

该函数为 %isNaN% 内在对象。

调用时执行下列步骤:

  1. num 为 ? ToNumber(number)。
  2. 如果 numNaN,返回 true
  3. 返回 false
Note

在 ECMAScript 代码中检测值 X 是否为 NaN 的一种可靠方法是使用表达式 X !== X。当且仅当 XNaN 时,该表达式结果为 true

19.2.4 parseFloat ( string )

该函数根据将 string 参数的内容解释为十进制字面量来产生一个 Number 值

它是 %parseFloat% 内在对象。

调用时执行下列步骤:

  1. inputString 为 ? ToString(string)。
  2. trimmedString 为 ! TrimString(inputString, start)。
  3. trimmedStringToCodePoints(trimmedString)。
  4. trimmedPrefix 为满足 StrDecimalLiteral 语法的 trimmed 的最长前缀,该前缀可能就是 trimmed 本身。如果没有这样的前缀,返回 NaN
  5. parsedNumberParseText(trimmedPrefix, StrDecimalLiteral)。
  6. 断言:parsedNumber 为一个 Parse Node。
  7. 返回 parsedNumberStringNumericValue
Note

该函数可能仅将 string 的前导部分解释为 Number 值;它忽略任何不能被解释为十进制字面量记法部分的代码单元,且不提示任何此类代码单元被忽略。

19.2.5 parseInt ( string, radix )

该函数根据指定的 radix 解释 string 的内容来产生一个整数 Number。忽略 string 的前导空白。如果 radix 被强制转换为 0(例如当其为 undefined 时),则假定为 10,除非数字表示以 "0x""0X" 开头,在这种情况下假定为 16。如果 radix 为 16,则数字表示可以可选地以 "0x""0X" 开头。

它是 %parseInt% 内在对象。

调用时执行下列步骤:

  1. inputString 为 ? ToString(string)。
  2. trimmedString 为 ! TrimString(inputString, start)。
  3. sign 为 1。
  4. 如果 trimmedString 非空且其第一个代码单元为代码单元 0x002D (HYPHEN-MINUS),将 sign 设为 -1。
  5. 如果 trimmedString 非空且其第一个代码单元为代码单元 0x002B (PLUS SIGN) 或代码单元 0x002D (HYPHEN-MINUS),将 trimmedString 设为从索引 1 开始的子字符串
  6. radixMV(? ToInt32(radix))。
  7. stripPrefixtrue
  8. 如果 radixMV ≠ 0,则
    1. 如果 radixMV < 2 或 radixMV > 36,返回 NaN
    2. 如果 radixMV ≠ 16,将 stripPrefix 设为 false
  9. 否则,
    1. radixMV 设为 10。
  10. 如果 stripPrefixtrue,则
    1. 如果 trimmedString 的长度 ≥ 2 且其前两个代码单元为 "0x""0X",则
      1. trimmedString 设为从索引 2 开始的子字符串
      2. radixMV 设为 16。
  11. 如果 trimmedString 包含非 radix-radixMV 的代码单元,则令 endtrimmedString 中第一个此类代码单元的索引;否则令 endtrimmedString 的长度。
  12. numberStringtrimmedString 从 0 到 end子字符串
  13. 如果 numberString 为空,返回 NaN
  14. mathInt 为以 radix-radixMV 表示法由 numberString 表示的整数值,使用字母 AZaz 表示值为 10 到 35 的数字。(不过,如果 radixMV = 10 且 numberString 包含超过 20 个有效数字,则实现可以选择在第 20 位之后将每个有效数字替换为 0;并且如果 radixMV 不是 2、4、8、10、16 或 32 之一,则 mathInt 可以是对由 numberString 在 radix-radixMV 表示法所表示整数值的实现近似。)
  15. 如果 mathInt = 0,则
    1. 如果 sign = -1,返回 -0𝔽
    2. 返回 +0𝔽
  16. 返回 𝔽(sign × mathInt)。
Note

该函数可能仅将 string 的前导部分解释为整数值;它忽略任何不能被解释为整数记法部分的代码单元,且不提示任何此类代码单元被忽略。

19.2.6 URI 处理函数

统一资源标识符(URI)是标识资源(例如网页或文件)以及访问这些资源的传输协议(例如 HTTP 或 FTP)的字符串。ECMAScript 语言本身除了本节所述用于编码和解码 URI 的函数之外,不提供任何用于使用 URI 的支持。encodeURIdecodeURI 旨在用于完整的 URI;它们假定任何保留字符具有特殊含义(例如作为分隔符),因此不被编码。encodeURIComponentdecodeURIComponent 旨在用于 URI 的单个组件;它们假定任何保留字符表示文本并且必须被编码,以避免在组件成为完整 URI 的一部分时具有特殊含义。

Note 1

保留字符集合基于 RFC 2396,并未反映更新的 RFC 3986 引入的更改。

Note 2

许多 ECMAScript 实现提供额外的函数和方法来操作网页;这些函数超出本标准的范围。

19.2.6.1 decodeURI ( encodedURI )

该函数计算 URI 的新版本,其中 encodeURI 可能引入的每个转义序列和 UTF-8 编码都被替换为其所表示的代码点的 UTF-16 编码。那些不可能由 encodeURI 引入的转义序列不被替换。

它是 %decodeURI% 内在对象。

调用时执行下列步骤:

  1. uriString 为 ? ToString(encodedURI)。
  2. preserveEscapeSet";/?:@&=+$,#"
  3. 返回 ? Decode(uriString, preserveEscapeSet)。

19.2.6.2 decodeURIComponent ( encodedURIComponent )

该函数计算 URI 的新版本,其中 encodeURIComponent 可能引入的每个转义序列和 UTF-8 编码都被替换为其所表示的代码点的 UTF-16 编码。

它是 %decodeURIComponent% 内在对象。

调用时执行下列步骤:

  1. componentString 为 ? ToString(encodedURIComponent)。
  2. preserveEscapeSet 为空字符串。
  3. 返回 ? Decode(componentString, preserveEscapeSet)。

19.2.6.3 encodeURI ( uri )

该函数计算一个 UTF-16 编码(参见 6.1.4)的 URI 的新版本,其中某些代码点的每个出现都被替换为表示该代码点 UTF-8 编码的一个、两个、三个或四个转义序列。

它是 %encodeURI% 内在对象。

调用时执行下列步骤:

  1. uriString 为 ? ToString(uri)。
  2. extraUnescaped";/?:@&=+$,#"
  3. 返回 ? Encode(uriString, extraUnescaped)。

19.2.6.4 encodeURIComponent ( uriComponent )

该函数计算一个 UTF-16 编码(参见 6.1.4)的 URI 组件的新版本,其中某些代码点的每个出现都被替换为表示该代码点 UTF-8 编码的一个、两个、三个或四个转义序列。

它是 %encodeURIComponent% 内在对象。

调用时执行下列步骤:

  1. componentString 为 ? ToString(uriComponent)。
  2. extraUnescaped 为空字符串。
  3. 返回 ? Encode(componentString, extraUnescaped)。

19.2.6.5 Encode ( string, extraUnescaped )

The abstract operation Encode takes arguments string (a String) and extraUnescaped (a String) and returns either a normal completion containing a String or a throw completion. 对 string 执行 URI 编码与转义,将其视为如 6.1.4 所述的一系列 UTF-16 编码的码点。如果某字符在 RFC 2396 中被识别为未保留字符或出现在 extraUnescaped 中,则不对其转义。 It performs the following steps when called:

  1. lenstring 的长度。
  2. result 为空字符串。
  3. alwaysUnescapedASCII 单词字符"-.!~*'()" 的字符串拼接。
  4. unescapedSetalwaysUnescapedextraUnescaped 的字符串拼接。
  5. k 为 0。
  6. 重复,当 k < len 时,
    1. codeUnitstring 中索引 k 的代码单元。
    2. 如果 unescapedSet 包含 codeUnit,则
      1. k 设为 k + 1。
      2. result 设为 resultcodeUnit 的字符串拼接。
    3. 否则,
      1. cpCodePointAt(string, k)。
      2. 如果 cp.[[IsUnpairedSurrogate]]true,抛出 URIError 异常。
      3. k 设为 k + cp.[[CodeUnitCount]]
      4. octets 为对 cp.[[CodePoint]] 应用 UTF-8 转换所得到的八位元组列表。
      5. octets 的每个元素 octet 执行
        1. hex 为格式为大写十六进制数的 octet 的字符串表示。
        2. result 设为 result"%"StringPad(hex, 2, "0", start) 的字符串拼接。
  7. 返回 result
Note

因为百分号编码用于表示单个八位元组,单个代码点可能被表示为多个连续的转义序列(每个 8 位 UTF-8 代码单元一个)。

19.2.6.6 Decode ( string, preserveEscapeSet )

The abstract operation Decode takes arguments string (a String) and preserveEscapeSet (a String) and returns either a normal completion containing a String or a throw completion. 执行 URI 取消转义与解码,同时保留任何对应于 preserveEscapeSet 中基本拉丁字符的转义序列。 It performs the following steps when called:

  1. lenstring 的长度。
  2. result 为空字符串。
  3. k 为 0。
  4. 重复,当 k < len 时,
    1. codeUnitstring 中索引 k 的代码单元。
    2. segmentcodeUnit
    3. 如果 codeUnit 为代码单元 0x0025 (PERCENT SIGN),则
      1. 如果 k + 3 > len,抛出 URIError 异常。
      2. escapestringkk + 3 的子字符串
      3. firstOctetParseHexOctet(string, k + 1)。
      4. 如果 firstOctet 不是整数,抛出 URIError 异常。
      5. k 设为 k + 2。
      6. nfirstOctet 中领先 1 位的个数。
      7. 如果 n = 0,则
        1. asciiChar 为其数值为 firstOctet 的代码单元。
        2. 如果 preserveEscapeSet 包含 asciiChar,将 segment 设为 escape;否则将 segment 设为 asciiChar
      8. 否则,
        1. 如果 n = 1 或 n > 4,抛出 URIError 异常。
        2. octets 为 « firstOctet »。
        3. j 为 1。
        4. 重复,当 j < n 时,
          1. k 设为 k + 1。
          2. 如果 k + 3 > len,抛出 URIError 异常。
          3. 如果 string 在索引 k 处的代码单元不是代码单元 0x0025 (PERCENT SIGN),抛出 URIError 异常。
          4. continuationByteParseHexOctet(string, k + 1)。
          5. 如果 continuationByte 不是整数,抛出 URIError 异常。
          6. continuationByte 附加到 octets
          7. k 设为 k + 2。
          8. j 设为 j + 1。
        5. 断言:octets 的长度为 n
        6. 如果 octets 不包含有效的 UTF-8 编码的 Unicode 代码点,抛出 URIError 异常。
        7. codePoint 为通过对 octets 应用 UTF-8 变换得到的代码点(即从八位元组列表到 21 位值)。
        8. segment 设为 UTF16EncodeCodePoint(codePoint)。
    4. result 设为 resultsegment 的字符串拼接。
    5. k 设为 k + 1。
  5. 返回 result
Note

RFC 3629 禁止对无效的 UTF-8 八位元组序列进行解码。例如,无效序列 0xC0 0x80 不得解码为代码单元 0x0000。Decode 算法的实现遇到此类无效序列时必须抛出 URIError

19.2.6.7 ParseHexOctet ( string, position )

The abstract operation ParseHexOctet takes arguments string (a String) and position (a non-negative integer) and returns either a non-negative integer or a non-empty List of SyntaxError objects. 解析 string 在指定 position 处的一段两个十六进制字符为无符号 8 位整数。 It performs the following steps when called:

  1. lenstring 的长度。
  2. 断言:position + 2 ≤ len
  3. hexDigitsstringpositionposition + 2 的子字符串
  4. parseResultParseText(hexDigits, HexDigits[~Sep])。
  5. 如果 parseResult 不是 Parse Node,返回 parseResult
  6. nparseResult 的 MV。
  7. 断言:n 在 0 到 255 的包含区间内。
  8. 返回 n

19.3 全局对象的构造器属性

19.3.1 AggregateError ( . . . )

参见 20.5.7.1

19.3.2 Array ( . . . )

参见 23.1.1

19.3.3 ArrayBuffer ( . . . )

参见 25.1.4

19.3.4 BigInt ( . . . )

参见 21.2.1

19.3.5 BigInt64Array ( . . . )

参见 23.2.5

19.3.6 BigUint64Array ( . . . )

参见 23.2.5

19.3.7 Boolean ( . . . )

参见 20.3.1

19.3.8 DataView ( . . . )

参见 25.3.2

19.3.9 Date ( . . . )

参见 21.4.2

19.3.10 Error ( . . . )

参见 20.5.1

19.3.11 EvalError ( . . . )

参见 20.5.5.1

19.3.12 FinalizationRegistry ( . . . )

参见 26.2.1

19.3.13 Float16Array ( . . . )

参见 23.2.5

19.3.14 Float32Array ( . . . )

参见 23.2.5

19.3.15 Float64Array ( . . . )

参见 23.2.5

19.3.16 Function ( . . . )

参见 20.2.1

19.3.17 Int8Array ( . . . )

参见 23.2.5

19.3.18 Int16Array ( . . . )

参见 23.2.5

19.3.19 Int32Array ( . . . )

参见 23.2.5

19.3.20 Iterator ( . . . )

参见 27.1.3.1

19.3.21 Map ( . . . )

参见 24.1.1

19.3.22 Number ( . . . )

参见 21.1.1

19.3.23 Object ( . . . )

参见 20.1.1

19.3.24 Promise ( . . . )

参见 27.2.3

19.3.25 Proxy ( . . . )

参见 28.2.1

19.3.26 RangeError ( . . . )

参见 20.5.5.2

19.3.27 ReferenceError ( . . . )

参见 20.5.5.3

19.3.28 RegExp ( . . . )

参见 22.2.4

19.3.29 Set ( . . . )

参见 24.2.2

19.3.30 SharedArrayBuffer ( . . . )

参见 25.2.3

19.3.31 String ( . . . )

参见 22.1.1

19.3.32 Symbol ( . . . )

参见 20.4.1

19.3.33 SyntaxError ( . . . )

参见 20.5.5.4

19.3.34 TypeError ( . . . )

参见 20.5.5.5

19.3.35 Uint8Array ( . . . )

参见 23.2.5

19.3.36 Uint8ClampedArray ( . . . )

参见 23.2.5

19.3.37 Uint16Array ( . . . )

参见 23.2.5

19.3.38 Uint32Array ( . . . )

参见 23.2.5

19.3.39 URIError ( . . . )

参见 20.5.5.6

19.3.40 WeakMap ( . . . )

参见 24.3.1

19.3.41 WeakRef ( . . . )

参见 26.1.1

19.3.42 WeakSet ( . . . )

参见 24.4

19.4 全局对象的其他属性

19.4.1 Atomics

参见 25.4

19.4.2 JSON

参见 25.5

19.4.3 Math

参见 21.3

19.4.4 Reflect

参见 28.1