8.5 初始化宿主环境定义的作用域

其操作步骤如下:

  1. realm = CreateRealm().
  2. newContext 为新的执行上下文.
  3. newContext.Function = null.
  4. newContext.Realm = realm.
  5. newContext.ScriptOrModule = null.
  6. newContext 入栈, newContext 为 running execution context.
  7. 如果宿主环境需要一个exotic 对象作为realm的全局对象, 让定义的global 作为这么个对象. 否则, 使global 为 undefined, 指明 需要一个普通对象作为global
  8. 如果宿主环境要求this绑定返回一个对象,那么让thisValue 为那么个对象,否则让thisValue为undefined,指明全局环境的this绑定为global object
  9. 执行 SetRealmGlobalObject(realm, global, thisValue).
  10. globalObj = SetDefaultGlobalBindings(realm).
  11. 创建任何定义在globalObj中的全局对象.
  12. 在一个实现依赖机制中, 包含ECMAScript源代码(详见第10章) 和任意和0个或多个ECMAScript脚本或者模块相关联的宿主定义的值,那么,针对每一个源代码或者宿主定义的值
    • 如果sourceText是脚本的源代码, 那么
      • 执行 EnqueueJob(“ScriptJobs”, ScriptEvaluationJob, « sourceText, hostDefined »).
    • 否则sourceText是模块的源代码, 那么
      • 执行 EnqueueJob(“ScriptJobs”, TopLevelModuleEvaluationJob, « sourceText, hostDefined »).
  13. NextJob NormalCompletion(undefined).