This is a proposal for the inclusion of an additional primordial variable to all ECMAScript contexts.
- There MUST be a primordial function
Module(text, fileName, lineNo)
text
MUST be parsed the body of a strict-mode FunctionModule
MAY throw aSyntaxError
fileName
is an optional name for the text, for debuggerslineNo
defaults to 1, is coerced toNumber
internally, and represents the line number corresponding to the beginning of the text within the file indicated byfileName
Module
MAY be called as a constructor or as a function. Its behavior must be identical in either case.Module
returns aFunction
(for illustration:module(scope)
)scope
is internally coerced to anObject
- when module is called
- the function described in
text
is run in a lexical scope that contains- the primordials (Non normatively, these include
Array
andObject
but not legacy, embedding-specific values likewindow
; a citation to a comprehensive list in the specification is needed here) - preceding the primordials, a variable corresponding to each owned property of
scope
- such that any free variable in
text
that is neither mentioned in thescope
object or is a primordial throws aReferenceError
at the point it is used.
- the primordials (Non normatively, these include
- the module returns the value returned by the function
- the function described in
- the
Module
instance MUST own arequirements
propertyrequirements
are anArray
requirements
must contain the string corresponding to each occurrence of the free variablerequire
that exists intext
in whichrequire
is called as a function with theString
as its argument
- the
Module
instance MUST own thefileName
property corresponding to thefileName
given to theModule
constructor. - the
Module
instance MUST own thelineNo
property corresponding to thelineNo
given to theModule
constructor.
@erights, Is the intention that primordials be included on the scope object? This implies that anyone using a module would need to explicitly provide such an object. From the usability perspective, I think I prefer that properties owned by the global scope be implicitly communicated, and anything else fall through at run time with a ReferenceError.