From 9552727c4118228280d6fb68de126b333f2f41ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 27 Mar 2024 17:49:51 +0100 Subject: [PATCH] Make `ns.foo` trigger evaluation also for non-existing properties (#33) --- index.html | 4 ++-- spec.emu | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 1fe371c..f0cd255 100644 --- a/index.html +++ b/index.html @@ -2628,7 +2628,7 @@

Stage 2 Draft / March 22, 2024

Deferred Imports Evaluation

+

Stage 2 Draft / March 27, 2024

Deferred Imports Evaluation

10 Ordinary and Exotic Objects Behaviours

@@ -2683,7 +2683,7 @@

10.4.6 Module Namespace Exotic Objects

10.4.6.8 [[Get]] ( P, Receiver )

The [[Get]] internal method of a module namespace exotic object O takes arguments P (a property key) and Receiver (an ECMAScript language value) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

-
  1. If P is a Symbol, then
    1. Return ! OrdinaryGet(O, P, Receiver).
  2. Let exports be O.[[Exports]].
  3. If exports does not contain P, return undefined.
  4. Let m be O.[[Module]].
  5. If m is not a Cyclic Module Record, or both m.[[Status]] is linked and AnyDependencyNeedsAsyncEvaluation(m) is false, then
    1. Perform ? EvaluateSync(m).
  6. Let binding be m.ResolveExport(P).
  7. Assert: binding is a ResolvedBinding Record.
  8. Let targetModule be binding.[[Module]].
  9. Assert: targetModule is not undefined.
  10. If binding.[[BindingName]] is namespace, then
    1. Return GetModuleNamespace(targetModule).
  11. Let targetEnv be targetModule.[[Environment]].
  12. If targetEnv is empty, throw a ReferenceError exception.
  13. Return ? targetEnv.GetBindingValue(binding.[[BindingName]], true).
+
  1. If P is a Symbol, then
    1. Return ! OrdinaryGet(O, P, Receiver).
  2. Let m be O.[[Module]].
  3. If m is not a Cyclic Module Record, or both m.[[Status]] is linked and AnyDependencyNeedsAsyncEvaluation(m) is false, then
    1. Perform ? EvaluateSync(m).
  4. Let exports be O.[[Exports]].
  5. If exports does not contain P, return undefined.
  6. Let m be O.[[Module]].
  7. Let binding be m.ResolveExport(P).
  8. Assert: binding is a ResolvedBinding Record.
  9. Let targetModule be binding.[[Module]].
  10. Assert: targetModule is not undefined.
  11. If binding.[[BindingName]] is namespace, then
    1. Return GetModuleNamespace(targetModule).
  12. Let targetEnv be targetModule.[[Environment]].
  13. If targetEnv is empty, throw a ReferenceError exception.
  14. Return ? targetEnv.GetBindingValue(binding.[[BindingName]], true).
Note 1

ResolveExport is side-effect free. Each time this operation is called with a specific exportName, resolveSet pair as arguments it must return the same result. An implementation might choose to pre-compute or cache the ResolveExport results for the [[Exports]] of each module namespace exotic object.

diff --git a/spec.emu b/spec.emu index c27ca3f..8416df1 100644 --- a/spec.emu +++ b/spec.emu @@ -73,11 +73,12 @@ contributors: Nicolò Ribaudo 1. If _P_ is a Symbol, then 1. Return ! OrdinaryGet(_O_, _P_, _Receiver_). - 1. Let _exports_ be _O_.[[Exports]]. - 1. If _exports_ does not contain _P_, return *undefined*. - 1. Let _m_ be _O_.[[Module]]. + 1. Let _m_ be _O_.[[Module]]. 1. If _m_ is not a Cyclic Module Record, or both _m_.[[Status]] is ~linked~ and AnyDependencyNeedsAsyncEvaluation(_m_) is *false*, then 1. Perform ? EvaluateSync(_m_). + 1. Let _exports_ be _O_.[[Exports]]. + 1. If _exports_ does not contain _P_, return *undefined*. + 1. Let _m_ be _O_.[[Module]]. 1. Let _binding_ be _m_.ResolveExport(_P_). 1. Assert: _binding_ is a ResolvedBinding Record. 1. Let _targetModule_ be _binding_.[[Module]].