ServerJS/Modules/Environment: Difference between revisions

m
Reorganized. Added mention of loader.extensions.
m (→‎The Environment Function/Object: reserved additional terms for the environment)
m (Reorganized. Added mention of loader.extensions.)
Line 3: Line 3:
== The Require Function/Object ==
== The Require Function/Object ==


* id: the "require" object may have an "id" member that must be the normalized identifier of the current module
* id: the "require" object MAY have an "id" member that must be the normalized identifier of the current module
* loader: the "require" object may have a "loader" member that is an interface to the object used by "require" to acquire module factory functions.  Tampering with this variable must not alter the behavior of "require".
* loader: the "require" object MAY have a "loader" member that is an interface to the object used by "require" to acquire module factory functions.  Tampering with this variable must not alter the behavior of "require".
** load: the "loader" object, if present, must have a "load" method that returns a module factory function.
 
*** a module factory function must accept "require", "exports", and "environment" as its first arguments.
*** a module factory function may accept additional optional arguments.
** fetch: a module loader, if present, must provide a "fetch" method that returns the text of a module for a given normalized, fully-qualified, absolute module identifier.
** evaluate: a module loader, if present, must provide an "evaluate" method that accepts a module text and returns a module factory function
*** a module text must be a string that conforms to a JavaScript "program" construction.
** resolve: a module loader, if present, must provide a "resolve" method that accepts a module identifier (that may be a relative module identifier) and optionally a base module identifier (that must be an absolute module identifier) and returns the corresponding absolute identifier of the former.
** normalize: a module loader, if present, must provide a "normalize" method that accepts an absolute module identifier and returns that identifier in its canonical form.  Normalize may be an identity relation.
** path: a module loader, if present, may provide a path member that must be an Array.  The contents of each element of the array are implementation-specific.


== The Environment Function/Object ==
== The Environment Function/Object ==
Line 19: Line 11:
A module receives an "environment" variable that is an Object.
A module receives an "environment" variable that is an Object.


* print: The "environment" may have a "print" function that accepts a "message" and an optional "label" String.  
* print: The "environment" MAY have a "print" function that accepts a "message" and an optional "label" String.  
** The label may be one of "log", "warn", "error", "pass", "fail".
** The label MAY be one of "log", "warn", "error", "pass", "fail".
** Any other, unspecified label must be in lower-case and begin with "x" and a vendor-specific label like "x-v8cgi-database".
** Any other, unspecified label MUST be in lower-case and begin with "x" and a vendor-specific label like "x-v8cgi-database".
* is: any member that has "is" as its first term is reserved for vendor and platform checks like "isRhino", "isJavaScriptCore", "isSpidermonkey", "isBrowser", &c.
* is: any member that has "is" as its first term is reserved for vendor and platform checks like "isRhino", "isJavaScriptCore", "isSpidermonkey", "isBrowser", &c.
* window: the "environment" may contain the global "window" object in permissive browser environments
* window: the "environment" MAY contain the global "window" object in permissive browser environments
* global: the "environment" may contain a reference to the global object in permissive environments
* global: the "environment" MAY contain a reference to the global object in permissive environments
* posix: reserved for a posix subsystem interface
* posix: reserved for a posix subsystem interface
* fs: reserved for a securable file system interface
* fs: reserved for a securable file system interface
* dom: reserved for a securable dom interface
* dom: reserved for a securable dom interface
== A Loader Object ==
* load: the "loader" object, if present, MUST have a "load" method that returns a module factory function.
** a module factory function MUST accept "require", "exports", and "environment" as its first arguments.
** a module factory function MAY accept additional optional arguments.
* fetch: a module loader, if present, must provide a "fetch" method that returns the text of a module for a given normalized, fully-qualified, absolute module identifier.
* evaluate: a module loader, if present, must provide an "evaluate" method that accepts a module text and returns a module factory function
** a module text MUST be a string that conforms to a JavaScript "program" construction.
* resolve: a module loader, if present, MUST provide a "resolve" method that accepts a module identifier (that may be a relative module identifier) and optionally a base module identifier (that must be an absolute module identifier) and returns the corresponding absolute identifier of the former.
* normalize: a module loader, if present, MUST provide a "normalize" method that accepts an absolute module identifier and returns that identifier in its canonical form.  Normalize MAY be an identity relation.
* path: a module loader, if present, MAY provide a path member that must be an Array.  The contents of each element of the array are implementation-specific.
* extensions: a module loader, if present, MAY provide an array of file extensions that the loader must accept (in order of priority from highest to lowest) for JavaScript module files.
171

edits