ECMA-262 Normative: formalize module keying host invariant predicates and variables#59
ECMA-262 Normative: formalize module keying host invariant predicates and variables#59guybedford wants to merge 2 commits intomainfrom
Conversation
0479ac1 to
620109d
Compare
ae5e047 to
6cacca6
Compare
620109d to
9f9c8c9
Compare
8de19d7 to
e454d9a
Compare
604bd28 to
62d30c3
Compare
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Minor comments, but it looks overall good.
| <li>the first _referrer_ is the same as the second _referrer_;</li> | ||
| <li>ModuleRequestsEqual(the first _moduleRequest_, the second _moduleRequest_) is *true*;</li> | ||
| <li><ins>_moduleRequestKey_.[[Phase]] is equal to ~source~ (the lowest possible phase);</ins></li> | ||
| <li><ins>FinishLoadingImportedModule will return the same NormalCompletion(_module_) _result_ for all (_otherReferrer_, _otherModuleRequest_) pairs whose Canonical ModuleRequest Record is also _moduleRequestKey_;</ins></li> |
There was a problem hiding this comment.
Note that two normal completions containing the same module are not "the same", as spec record have identity.
There was a problem hiding this comment.
Do you mean instead here spec records don't have identity?
In this case, how are we able to equate _result_ today in the host invariant at all? What is the suggestion here?
| <ul> | ||
| <li>the first _referrer_ is the same as the second _referrer_;</li> | ||
| <li>ModuleRequestsEqual(the first _moduleRequest_, the second _moduleRequest_) is *true*;</li> | ||
| <li><ins>_moduleRequestKey_.[[Phase]] is equal to ~source~ (the lowest possible phase);</ins></li> |
There was a problem hiding this comment.
IIUC, _moduleRequestKey_.[[Phase]] could be ~evaluation~. What's the reason of this restriction?
There was a problem hiding this comment.
The reason for this is that a canonical key must be independent of the phase - thus we pick a constant phase for canonicalization. And this aligns semantically with the concept that source phases can be used as keys in dynamic import.
Co-authored-by: Nicolò Ribaudo <hello@nicr.dev>
bb9d202 to
fe37af6
Compare
The host hook invariants for module loading are a very important concept in the spec and this specification extends them with support for the source phase module invariants (
import(source)of a ModuleSource object).We require that
import(source)and import(url)` where URL and source point to the same module, to always return the same instance.In order to achieve this we need to define a concept of a module key.
Currently today, the host invariant of ES Modules is not fully defined - in the sense that we do not define that
import('./foo.js')andimport('https://site.com/foo.js')resolve to the same module, since we do not have any concept of a module key.This change now defines, the concept of a Canonical ModuleRequest Record, where all
(referrer, moduleRequest)pairs have a single canonical ModuleRequest Record they can be related to.By defining this as part of the host invariants, we are then able to talk in terms of module keys, laying the groundwork for source phase module keys.
In the process, we define all variables of the constraint explicitly, and then we move all predicates of the condition to the formal predicate list to ensure the explicit wording is as short as possible and this is as close as possible to a mathematical constraint as we can make it.
//cc @nicolo-ribaudo