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)textMUST be parsed the body of a strict-mode FunctionModuleMAY throw aSyntaxErrorfileNameis an optional name for the text, for debuggerslineNodefaults to 1, is coerced toNumberinternally, and represents the line number corresponding to the beginning of the text within the file indicated byfileNameModuleMAY be called as a constructor or as a function. Its behavior must be identical in either case.Modulereturns aFunction(for illustration:module(scope))scopeis internally coerced to anObject- when module is called
- the function described in
textis run in a lexical scope that contains- the primordials (Non normatively, these include
ArrayandObjectbut 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
textthat is neither mentioned in thescopeobject or is a primordial throws aReferenceErrorat 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
Moduleinstance MUST own arequirementspropertyrequirementsare anArrayrequirementsmust contain the string corresponding to each occurrence of the free variablerequirethat exists intextin whichrequireis called as a function with theStringas its argument
- the
Moduleinstance MUST own thefileNameproperty corresponding to thefileNamegiven to theModuleconstructor. - the
Moduleinstance MUST own thelineNoproperty corresponding to thelineNogiven to theModuleconstructor.
(1) By your proposal, if the
textinModule(text)containsrequire('foo')then:(2) What are the properties regarding the primordials (
Array,Object, ...)? Are these simply inherited from the calling context verbatim (this being a proposal to reduce boilerplate, if the programmer is worried, they can just ES5freezethem)?