Rework module linking (#4632)

The module linking process from jerry_parse is moved out into
a new jerry_module_link function, and jerry_parse is limited to
create unlinked modules.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-03-30 15:40:09 +02:00
committed by GitHub
parent 874a6a49d5
commit 6c484f3529
22 changed files with 1574 additions and 789 deletions
+32 -36
View File
@@ -85,12 +85,10 @@ void jerry_port_print_char (char c);
### Jerry Module system
The port API provides functions that can be used by the module system to open
and close source files, and normalize file paths.
The `jerry_port_get_native_module` port function can be used to provide native
modules to the engine. This function will be called when an import/export
statement is encountered with an unknown module specifier, which embedders can
use to supply native module objects based on the module name argument.
The port API provides optional functions that can be used by the
user application to resolve modules. If no callback is provided
to `jerry_module_link`, the `jerry_port_module_resolve` function
is used for resolving modules.
```c
/**
@@ -115,40 +113,38 @@ jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
} /* jerry_port_release_source */
/**
* Normalize a file path
* Default module resolver.
*
* @return length of the path written to the output buffer
*/
size_t
jerry_port_normalize_path (const char *in_path_p, /**< input file path */
char *out_buf_p, /**< output buffer */
size_t out_buf_size, /**< size of output buffer */
char *base_file_p) /**< base file path */
{
// normalize in_path_p by expanding relative paths etc.
// if base_file_p is not NULL, in_path_p is relative to that file
// write to out_buf_p the normalized path
// return length of written path
} /* jerry_port_normalize_path */
/**
* Get the module object of a native module.
*
* Note:
* This port function is called by jerry-core when JERRY_MODULE_SYSTEM
* is enabled.
*
* @param name String value of the module specifier.
*
* @return Undefined, if 'name' is not a native module
* jerry_value_t containing the module object, otherwise
* @return a module object if resolving is successful, an error otherwise
*/
jerry_value_t
jerry_port_get_native_module (jerry_value_t name) /**< module specifier */
jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier string */
const jerry_value_t referrer, /**< parent module */
void *user_p) /**< user data */
{
(void) name;
return jerry_create_undefined ();
}
// Resolves a module using the specifier string. If a referrer is a module,
// and specifier is a relative path, the base path should be the directory
// part extracted from the path of the referrer module.
// The callback function of jerry_module_link may call this function
// if it cannot resolve a module. Furthermore if the callback is NULL,
// this function is used for resolving modules.
// The default implementation only resolves ECMAScript modules, and does
// not (currently) use the user data.
} /* jerry_port_module_resolve */
/**
* Release known modules.
*/
void
jerry_port_module_release (const jerry_value_t realm) /**< if this argument is object, release only those modules,
* which realm value is equal to this argument. */
{
// This function releases the known modules, forcing their reload
// when resolved again later. The released modules can be filtered
// by realms. This function is only called by user applications.
} /* jerry_port_module_release */
```
## Date