modules: add ability to clear cache (#2300)

This adds the ability to remove a single module from the cache, or to
clear the entire module cache.

JerryScript-DCO-1.0-Signed-off-by: Gabriel Schulhof gabriel.schulhof@intel.com
This commit is contained in:
Gabriel "_|Nix|_" Schulhof
2018-05-03 21:12:17 -04:00
committed by yichoi
parent 369447aa09
commit 6dc2764a94
4 changed files with 186 additions and 62 deletions
+26 -1
View File
@@ -27,6 +27,11 @@ The purpose of having resolvers is to be able to account for the fact that diffe
differently and thus, for each type of module a module resolver must be supplied at the point where an instance of that
type of module is requested.
Individual modules may be removed from the cache by calling `jerryx_module_clear_cache`. This function behaves
identically to `jerryx_module_resolve` in that it first checks the cache for the requested module, except that it
removes the module if found. Additionally, it clears the entire cache of all modules if called using a JavaScript value
of `undefined` as its first parameter.
Additionally, this extension provides a means of easily defining so-called "native" JerryScript modules which can be
resolved using the native JerryScript module resolver `jerryx_module_native_resolver`, which can be passed to
`jerryx_module_resolve()`. Native modules are registered during application startup and by calling `dlopen()` by means
@@ -56,7 +61,7 @@ to `jerryx_module_resolve` with a module name whose canonical name matches an al
```c
jerry_value_t
jerryx_module_resolve (const jerry_char_t *name,
jerryx_module_resolve (const jerry_value_t name,
const jerryx_module_resolver_t *resolvers_p,
size_t resolver_count);
```
@@ -67,6 +72,26 @@ jerryx_module_resolve (const jerry_char_t *name,
- return value - `jerry_value_t` representing the module that was loaded, or the error that occurred in the process.
## jerryx_module_clear_cache
**Summary**
Remove a module from the current context's cache, or clear the cache entirely.
**Prototype**
```c
void
jerryx_module_clear_cache (const jerry_value_t name,
const jerryx_module_resolver_t *resolvers_p,
size_t resolver_count);
```
- `name` - the name of the module to remove from cache or a JavaScript `undefined` to clear the entire cache
- `resolvers_p` - the list of resolvers to call in sequence
- `resolver_count` - the number of resolvers in `resolvers_p`
## jerryx_module_native_resolver
**Summary**