Class SoftCachingModuleScriptProvider
java.lang.Object
org.mozilla.javascript.commonjs.module.provider.CachingModuleScriptProviderBase
org.mozilla.javascript.commonjs.module.provider.SoftCachingModuleScriptProvider
- All Implemented Interfaces:
Serializable
,ModuleScriptProvider
A module script provider that uses a module source provider to load modules
and caches the loaded modules. It softly references the loaded modules'
Rhino
Script
objects, thus a module once loaded can become eligible
for garbage collection if it is otherwise unused under memory pressure.
Instances of this class are thread safe.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.mozilla.javascript.commonjs.module.provider.CachingModuleScriptProviderBase
CachingModuleScriptProviderBase.CachedModuleScript
-
Constructor Summary
ConstructorsConstructorDescriptionSoftCachingModuleScriptProvider
(ModuleSourceProvider moduleSourceProvider) Creates a new module provider with the specified module source provider. -
Method Summary
Modifier and TypeMethodDescriptiongetModuleScript
(Context cx, String moduleId, URI uri, URI base, Scriptable paths) Returns a module script.
-
Constructor Details
-
SoftCachingModuleScriptProvider
Creates a new module provider with the specified module source provider.- Parameters:
moduleSourceProvider
- provider for modules' source code
-
-
Method Details
-
getModuleScript
public ModuleScript getModuleScript(Context cx, String moduleId, URI uri, URI base, Scriptable paths) throws Exception Description copied from interface:ModuleScriptProvider
Returns a module script. It should attempt to load the module script if it is not already available to it, or return an already loaded module script instance if it is available to it.- Specified by:
getModuleScript
in interfaceModuleScriptProvider
- Overrides:
getModuleScript
in classCachingModuleScriptProviderBase
- Parameters:
cx
- current context. Can be used to compile module scripts.moduleId
- the ID of the module. An implementation must only accept an absolute ID, starting with a term.uri
- the URI of the module. If this is not null, resolution ofmoduleId
is bypassed and the script is directly loaded frommoduleUri
base
- the module path base URI from whichmoduleUri
was derived.paths
- the value of the require() function's "paths" attribute. If the require() function is sandboxed, it will be null, otherwise it will be a JavaScript Array object. It is up to the provider implementation whether and how it wants to honor the contents of the array.- Returns:
- a module script representing the compiled code of the module. Null should be returned if the script could not found.
- Throws:
Exception
- if there was an unrecoverable problem obtaining the script
-