SharedStructs are to be declarations, like class declarations, that may appear in module source text.
Instances of a shared struct are JavaScript primitives and, like all other JavaScript primitives, share a per-Realm prototype instance.
So, like 1..toString()
looks up the %NumberPrototype%
intrinsic for the realm in the current execution context in order to call its toString
method,
when we have a struct instance s
, calling s.toString()
will look up the struct’s corresponding prototype on the realm in the current execution context.
The key space for that table closes over the key space of the realm’s module map and also includes the position of the struct declaration.
Consequently, shared struct declarations must instantiate all contained prototypes once per evaluation of a module in the realm’s module map.
I am comfortable with this strategy in anticipation of a suitable intersection semantics for Module Harmony proposa