-
Notifications
You must be signed in to change notification settings - Fork 45
Module namespaces as thenables: Add non-normative spec text #48
Description
The conclusion to #47 was that it is indeed intentional that the promise instance's final [[PromiseResult]] returned from import():
- May not always be the module's namespace object
- ...in the case where it has been "overridden" by an export named "then"
- May vary on each call to
import()for a given specifier- ...in the case where the "then"-named export is not idempotent
- May not be accessible via the existing non-dynamic
importsyntax
Whilst this is well-specified intentional behavior, reviewers have seemed surprised by this discovery. The capabilities it allows were not mentioned in the original motivations or use-cases. Public educational pieces written on this proposal have not mentioned this capability. The spec wording for Runtime Semantics: HostImportModuleDynamically talks only about consistent results:
if the host environment takes the success path once for a given referencingScriptOrModule, specifier pair, it must always do so, and the same for the failure path"
To increase awareness of this behavior, I'd like to request a spec note be added to emphasize the fact that FinishDynamicImport's step 2.f means the caller of import() does not have the subjectively-intuitive equivalent guarantees of consistency.
As I am new to spec contributions, I will proposal some loosely suggested wording at the end of Runtime Semantics: HostImportModuleDynamically that I hope others may massively refine and reword:
NOTE 1: Even if the success path is consistently taken for a given referencingScriptOrModule, specifier pair, the module can still arbitrarily override the final
[[PromiseState]]and[[PromiseResult]]of the promise instance returned by eachimport()call if the module exports a Promise executor function named "then". This is a natural consequence ofFinishDynamicImportcalling promiseCapability.[[Resolve]]with the module's[[Namespace]].
Please say if there is some existing policy on the conditions under which we allow/desire non-normative text to be added to the spec.