tc39 / ecma262

Status, process, and documents for ECMA-262

Home Page:https://tc39.es/ecma262/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unclear semantics for ScriptEvaluation when scriptRecord.[[Realm]] is undefined

shicks opened this issue · comments

In section 16.1.5 the abstract operation ParseScript is defined as accepting a realm parameter, which may be either a Realm Record or undefined, and is assigned directly into the [[Realm]] field of the resulting record. 16.1.4 reinforces that [[Realm]] may be undefined if "if not yet assigned" (this is in contrast with the following section on Module Records, where [[Realm]] is never undefined). Later, 16.1.6 defines the first step of ScriptEvaluation as

  1. Let globalEnv be scriptRecord.[[Realm]].[[GlobalEnv]].

This implicitly assumes scriptRecord.[[Realm]] is defined, but I don't see anything in the spec to establish this guarantee - not even an Assert. If it's required to have a defined realm, then ParseScript should be updated to no longer accept undefined. On the other hand, if it's allowed to be undefined, then the undefined case should be handled in ScriptEvaluation (presumably either via CreateRealm, or else returning a throw completion).

Pretty sure this cannot in fact be undefined. 698819c introduced that field, and prior to that commit the [[Realm]] of a Module Record could briefly be undefined if not yet assigned, so our best guess is that this was a refactoring issue during the authoring of that commit.

We'll update the type of that argument and field.