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
+7
View File
@@ -261,6 +261,13 @@ jerry_value_t jerry_object_get_property_names (const jerry_value_t obj_val, jerr
jerry_value_t jerry_from_property_descriptor (const jerry_property_descriptor_t *src_prop_desc_p);
jerry_value_t jerry_to_property_descriptor (jerry_value_t obj_value, jerry_property_descriptor_t *out_prop_desc_p);
/**
* Module functions.
*/
jerry_value_t jerry_module_link (const jerry_value_t module_val,
jerry_module_resolve_callback_t callback_p, void *user_p);
/**
* Promise functions.
*/
+16 -22
View File
@@ -217,39 +217,33 @@ uint8_t *jerry_port_read_source (const char *file_name_p, size_t *out_size_p);
void jerry_port_release_source (uint8_t *buffer_p);
/**
* Normalize a file path string.
* Default module resolver.
*
* Note:
* This port function is called by jerry-core when JERRY_MODULE_SYSTEM
* is enabled. The normalized path is used to uniquely identify modules.
* This port function is only used when JERRY_MODULE_SYSTEM is enabled.
*
* @param in_path_p Input path as a zero terminated string.
* @param out_buf_p Pointer to the output buffer where the normalized path should be written.
* @param out_buf_size Size of the output buffer.
* @param base_file_p A file path that 'in_path_p' is relative to, usually the current module file.
* A NULL value represents that 'in_path_p' is relative to the current working directory.
* @param specifier Module specifier string.
* @param referrer Parent module.
* @param user_p An unused pointer.
*
* @return length of the string written to the output buffer
* zero, if the buffer was not sufficient or an error occured
* @return A module object if resolving is successful, an error otherwise.
*/
size_t jerry_port_normalize_path (const char *in_path_p,
char *out_buf_p,
size_t out_buf_size,
char *base_file_p);
jerry_value_t
jerry_port_module_resolve (const jerry_value_t specifier,
const jerry_value_t referrer,
void *user_p);
/**
* Get the module object of a native module.
* Release known modules.
*
* Note:
* This port function is called by jerry-core when JERRY_MODULE_SYSTEM
* is enabled.
* This port function should be called by the user application when
* the module database is no longer needed.
*
* @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
* @param realm If this argument is object, release only those modules,
* which realm value is equal to this argument.
*/
jerry_value_t jerry_port_get_native_module (jerry_value_t name);
void jerry_port_module_release (const jerry_value_t realm);
/**
* @}
+8
View File
@@ -288,6 +288,13 @@ typedef void (*jerry_object_native_free_callback_t) (void *native_p);
*/
typedef void (*jerry_error_object_created_callback_t) (const jerry_value_t error_object, void *user_p);
/**
* Callback which is called by jerry_module_link to get the referenced module.
*/
typedef jerry_value_t (*jerry_module_resolve_callback_t) (const jerry_value_t specifier,
const jerry_value_t referrer,
void *user_p);
/**
* Callback which tells whether the ECMAScript execution should be stopped.
*
@@ -307,6 +314,7 @@ typedef jerry_value_t (*jerry_vm_exec_stop_callback_t) (void *user_p);
typedef bool (*jerry_object_property_foreach_t) (const jerry_value_t property_name,
const jerry_value_t property_value,
void *user_data_p);
/**
* Function type applied for each object in the engine.
*/