Resolve module paths relative to the current module (#2976)
The current module implementation resolves module paths relative to the current working directory, but paths should be resolved relative to the currently evaluated module/source. This requires a change in the jerry_port_normalize_path port API function, so that it also takes the current module path as an argument. On the engine side, we now also create a module object for the main script, so that we can properly identify the base path for other modules. Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu> JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
+3
-1
@@ -118,9 +118,11 @@ jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
|
||||
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 */
|
||||
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 */
|
||||
|
||||
@@ -402,7 +402,7 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
|
||||
#if ENABLED (JERRY_PARSER)
|
||||
jerry_assert_api_available ();
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES)
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
if (resource_name_length == 0)
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
@@ -412,7 +412,7 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
|
||||
JERRY_CONTEXT (resource_name) = ecma_find_or_create_literal_string (resource_name_p,
|
||||
(lit_utf8_size_t) resource_name_length);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) */
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
ecma_compiled_code_t *bytecode_data_p;
|
||||
ecma_value_t parse_status;
|
||||
@@ -481,7 +481,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
|
||||
ecma_compiled_code_t *bytecode_data_p;
|
||||
ecma_value_t parse_status;
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES)
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
if (resource_name_length == 0)
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
@@ -491,7 +491,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
|
||||
JERRY_CONTEXT (resource_name) = ecma_find_or_create_literal_string (resource_name_p,
|
||||
(lit_utf8_size_t) resource_name_length);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) */
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
if (arg_list_p == NULL)
|
||||
{
|
||||
|
||||
@@ -41,32 +41,57 @@ ecma_module_create_normalized_path (const uint8_t *char_p, /**< module specifier
|
||||
prop_length_t size) /**< size of module specifier */
|
||||
{
|
||||
JERRY_ASSERT (size > 0);
|
||||
ecma_string_t *ret_p;
|
||||
ecma_string_t *ret_p = NULL;
|
||||
|
||||
/* Zero terminate the string. */
|
||||
uint8_t *temp_p = (uint8_t *) jmem_heap_alloc_block (size + 1u);
|
||||
memcpy (temp_p, char_p, size);
|
||||
temp_p[size] = LIT_CHAR_NULL;
|
||||
/* The module specifier is cesu8 encoded, we need to convert is to utf8, and zero terminate it,
|
||||
* so that OS level functions can handle it. */
|
||||
lit_utf8_byte_t *path_p = (lit_utf8_byte_t *) jmem_heap_alloc_block (size + 1u);
|
||||
|
||||
uint8_t *normalized_p = (uint8_t *) jmem_heap_alloc_block (ECMA_MODULE_MAX_PATH);
|
||||
size_t new_size = jerry_port_normalize_path ((const char *) temp_p,
|
||||
(char *) normalized_p,
|
||||
ECMA_MODULE_MAX_PATH);
|
||||
lit_utf8_size_t utf8_size;
|
||||
utf8_size = lit_convert_cesu8_string_to_utf8_string (char_p,
|
||||
size,
|
||||
path_p,
|
||||
size);
|
||||
path_p[utf8_size] = LIT_CHAR_NULL;
|
||||
|
||||
lit_utf8_byte_t *module_path_p = NULL;
|
||||
lit_utf8_size_t module_path_size = 0;
|
||||
|
||||
if (new_size == 0)
|
||||
/* Check if we have a current module, and use its path as the base path. */
|
||||
JERRY_ASSERT (JERRY_CONTEXT (module_top_context_p) != NULL);
|
||||
if (JERRY_CONTEXT (module_top_context_p)->module_p != NULL)
|
||||
{
|
||||
/* Failed to normalize path, use original. */
|
||||
ret_p = ecma_new_ecma_string_from_utf8 (temp_p, (lit_utf8_size_t) (size + 1u));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Copy the trailing \0 into the string as well, to make it more convenient to use later. */
|
||||
ret_p = ecma_new_ecma_string_from_utf8 (normalized_p, (lit_utf8_size_t) (new_size + 1u));
|
||||
JERRY_ASSERT (JERRY_CONTEXT (module_top_context_p)->module_p->path_p != NULL);
|
||||
module_path_size = ecma_string_get_size (JERRY_CONTEXT (module_top_context_p)->module_p->path_p);
|
||||
module_path_p = (lit_utf8_byte_t *) jmem_heap_alloc_block (module_path_size + 1);
|
||||
|
||||
lit_utf8_size_t module_utf8_size;
|
||||
module_utf8_size = ecma_string_copy_to_utf8_buffer (JERRY_CONTEXT (module_top_context_p)->module_p->path_p,
|
||||
module_path_p,
|
||||
module_path_size);
|
||||
|
||||
module_path_p[module_utf8_size] = LIT_CHAR_NULL;
|
||||
}
|
||||
|
||||
jmem_heap_free_block (temp_p, size + 1u);
|
||||
jmem_heap_free_block (normalized_p, ECMA_MODULE_MAX_PATH);
|
||||
lit_utf8_byte_t *normalized_out_p = (lit_utf8_byte_t *) jmem_heap_alloc_block (ECMA_MODULE_MAX_PATH);
|
||||
size_t normalized_size = jerry_port_normalize_path ((const char *) path_p,
|
||||
(char *) normalized_out_p,
|
||||
ECMA_MODULE_MAX_PATH,
|
||||
(char *) module_path_p);
|
||||
|
||||
|
||||
if (normalized_size > 0)
|
||||
{
|
||||
/* Convert the normalized path to cesu8. */
|
||||
ret_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (normalized_out_p, (lit_utf8_size_t) (normalized_size));
|
||||
}
|
||||
|
||||
jmem_heap_free_block (path_p, size + 1u);
|
||||
jmem_heap_free_block (normalized_out_p, ECMA_MODULE_MAX_PATH);
|
||||
if (module_path_p != NULL)
|
||||
{
|
||||
jmem_heap_free_block (module_path_p, module_path_size + 1);
|
||||
}
|
||||
|
||||
return ret_p;
|
||||
} /* ecma_module_create_normalized_path */
|
||||
@@ -573,17 +598,7 @@ ecma_module_connect_imports (void)
|
||||
{
|
||||
ecma_module_context_t *current_context_p = JERRY_CONTEXT (module_top_context_p);
|
||||
|
||||
ecma_object_t *local_env_p;
|
||||
|
||||
if (current_context_p->module_p != NULL)
|
||||
{
|
||||
local_env_p = current_context_p->module_p->scope_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is the root context. */
|
||||
local_env_p = ecma_get_global_environment ();
|
||||
}
|
||||
ecma_object_t *local_env_p = current_context_p->module_p->scope_p;
|
||||
JERRY_ASSERT (ecma_is_lexical_environment (local_env_p));
|
||||
|
||||
ecma_module_node_t *import_node_p = current_context_p->imports_p;
|
||||
@@ -677,14 +692,18 @@ ecma_module_parse (ecma_module_t *module_p) /**< module */
|
||||
module_p->state = ECMA_MODULE_STATE_PARSING;
|
||||
module_p->context_p = ecma_module_create_module_context ();
|
||||
|
||||
lit_utf8_size_t script_path_size;
|
||||
uint8_t flags = ECMA_STRING_FLAG_EMPTY;
|
||||
const lit_utf8_byte_t *script_path_p = ecma_string_get_chars (module_p->path_p,
|
||||
&script_path_size,
|
||||
&flags);
|
||||
lit_utf8_size_t module_path_size = ecma_string_get_size (module_p->path_p);
|
||||
lit_utf8_byte_t *module_path_p = (lit_utf8_byte_t *) jmem_heap_alloc_block (module_path_size + 1);
|
||||
|
||||
lit_utf8_size_t module_path_utf8_size;
|
||||
module_path_utf8_size = ecma_string_copy_to_utf8_buffer (module_p->path_p,
|
||||
module_path_p,
|
||||
module_path_size);
|
||||
module_path_p[module_path_utf8_size] = LIT_CHAR_NULL;
|
||||
|
||||
size_t source_size = 0;
|
||||
uint8_t *source_p = jerry_port_read_source ((const char *) script_path_p, &source_size);
|
||||
uint8_t *source_p = jerry_port_read_source ((const char *) module_path_p, &source_size);
|
||||
jmem_heap_free_block (module_path_p, module_path_size + 1);
|
||||
|
||||
if (source_p == NULL)
|
||||
{
|
||||
@@ -700,15 +719,12 @@ ecma_module_parse (ecma_module_t *module_p) /**< module */
|
||||
{
|
||||
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME,
|
||||
JERRY_DEBUGGER_NO_SUBTYPE,
|
||||
script_path_p,
|
||||
script_path_size - 1);
|
||||
module_path_p,
|
||||
module_path_size - 1);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_DEBUGGER) && ENABLED (JERRY_PARSER) */
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES)
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_string_value (ecma_new_ecma_string_from_utf8 (script_path_p,
|
||||
script_path_size - 1));
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) */
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_string_value (module_p->path_p);
|
||||
|
||||
ecma_compiled_code_t *bytecode_data_p;
|
||||
ecma_value_t ret_value = parser_parse_script (NULL,
|
||||
@@ -900,7 +916,6 @@ ecma_module_cleanup (void)
|
||||
current_p = next_p;
|
||||
}
|
||||
|
||||
ecma_module_release_module_context (JERRY_CONTEXT (module_top_context_p));
|
||||
JERRY_CONTEXT (module_top_context_p) = NULL;
|
||||
} /* ecma_module_cleanup */
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
#include "js-parser.h"
|
||||
#include "lit-magic-strings.h"
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES)
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
#include "jcontext.h"
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) */
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
@@ -159,9 +159,9 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
|
||||
ECMA_STRING_TO_UTF8_STRING (arguments_str_p, arguments_buffer_p, arguments_buffer_size);
|
||||
ECMA_STRING_TO_UTF8_STRING (function_body_str_p, function_body_buffer_p, function_body_buffer_size);
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES)
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) */
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
ecma_compiled_code_t *bytecode_data_p = NULL;
|
||||
|
||||
|
||||
@@ -225,11 +225,16 @@ void jerry_port_release_source (uint8_t *buffer_p);
|
||||
* @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.
|
||||
*
|
||||
* @return length of the string written to the output buffer
|
||||
* zero, if the buffer was not sufficient or an error occured
|
||||
*/
|
||||
size_t jerry_port_normalize_path (const char *in_path_p, char *out_buf_p, size_t out_buf_size);
|
||||
size_t jerry_port_normalize_path (const char *in_path_p,
|
||||
char *out_buf_p,
|
||||
size_t out_buf_size,
|
||||
char *base_file_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -190,9 +190,9 @@ struct jerry_context_t
|
||||
uint8_t debugger_max_receive_size; /**< maximum amount of data that can be received */
|
||||
#endif /* ENABLED (JERRY_DEBUGGER) */
|
||||
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES)
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
ecma_value_t resource_name; /**< resource name (usually a file name) */
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) */
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
#if ENABLED (JERRY_MEM_STATS)
|
||||
jmem_heap_stats_t jmem_heap_stats; /**< heap's memory usage statistics */
|
||||
|
||||
@@ -575,7 +575,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_DATE_UL, "setUTCDate")
|
||||
#if ENABLED (JERRY_BUILTIN_STRING) && ENABLED (JERRY_ES2015_BUILTIN)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_STARTS_WITH, "startsWith")
|
||||
#endif
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES)
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RESOURCE_ANON, "<anonymous>")
|
||||
#endif
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW) \
|
||||
@@ -797,7 +797,7 @@ LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_CHAR_CODE_AT_UL)
|
||||
#else
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_ENUMERABLE)
|
||||
#endif
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES)
|
||||
#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ERROR_MESSAGES) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (11, LIT_MAGIC_STRING_RESOURCE_ANON)
|
||||
#elif ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW) \
|
||||
|| ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
|
||||
|
||||
@@ -572,7 +572,7 @@ extern const lexer_lit_location_t lexer_default_literal;
|
||||
void parser_module_add_export_node_to_context (parser_context_t *context_p);
|
||||
void parser_module_add_import_node_to_context (parser_context_t *context_p);
|
||||
void parser_module_check_request_place (parser_context_t *context_p);
|
||||
void parser_module_context_init (parser_context_t *context_p);
|
||||
void parser_module_context_init (void);
|
||||
void parser_module_handle_module_specifier (parser_context_t *context_p);
|
||||
void parser_module_handle_requests (parser_context_t *context_p);
|
||||
void parser_module_parse_export_clause (parser_context_t *context_p);
|
||||
|
||||
@@ -259,16 +259,45 @@ parser_module_add_names_to_node (parser_context_t *context_p, /**< parser contex
|
||||
* Create module context if needed.
|
||||
*/
|
||||
void
|
||||
parser_module_context_init (parser_context_t *context_p) /**< parser context */
|
||||
parser_module_context_init (void)
|
||||
{
|
||||
if (JERRY_CONTEXT (module_top_context_p) == NULL)
|
||||
{
|
||||
ecma_module_context_t *module_context_p;
|
||||
module_context_p = (ecma_module_context_t *) parser_malloc (context_p,
|
||||
sizeof (ecma_module_context_t));
|
||||
|
||||
module_context_p = (ecma_module_context_t *) jmem_heap_alloc_block (sizeof (ecma_module_context_t));
|
||||
memset (module_context_p, 0, sizeof (ecma_module_context_t));
|
||||
JERRY_CONTEXT (module_top_context_p) = module_context_p;
|
||||
|
||||
ecma_string_t *path_str_p = ecma_get_string_from_value (JERRY_CONTEXT (resource_name));
|
||||
|
||||
lit_utf8_size_t path_str_size;
|
||||
uint8_t flags = ECMA_STRING_FLAG_EMPTY;
|
||||
|
||||
const lit_utf8_byte_t *path_str_chars_p = ecma_string_get_chars (path_str_p,
|
||||
&path_str_size,
|
||||
&flags);
|
||||
|
||||
ecma_string_t *path_p = ecma_module_create_normalized_path (path_str_chars_p,
|
||||
(prop_length_t) path_str_size);
|
||||
|
||||
if (path_p == NULL)
|
||||
{
|
||||
path_p = path_str_p;
|
||||
}
|
||||
|
||||
ecma_module_t *module_p = ecma_module_find_or_create_module (path_p);
|
||||
|
||||
if (path_p != path_str_p)
|
||||
{
|
||||
ecma_deref_ecma_string (path_p);
|
||||
}
|
||||
|
||||
module_p->state = ECMA_MODULE_STATE_EVALUATED;
|
||||
module_p->scope_p = ecma_get_global_environment ();
|
||||
ecma_ref_object (module_p->scope_p);
|
||||
|
||||
module_p->context_p = module_context_p;
|
||||
module_context_p->module_p = module_p;
|
||||
}
|
||||
} /* parser_module_context_init */
|
||||
|
||||
@@ -518,6 +547,11 @@ parser_module_handle_module_specifier (parser_context_t *context_p) /**< parser
|
||||
ecma_string_t *path_p = ecma_module_create_normalized_path (context_p->lit_object.literal_p->u.char_p,
|
||||
context_p->lit_object.literal_p->prop.length);
|
||||
|
||||
if (path_p == NULL)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_FILE_NOT_FOUND);
|
||||
}
|
||||
|
||||
ecma_module_t *module_p = ecma_module_find_or_create_module (path_p);
|
||||
ecma_deref_ecma_string (path_p);
|
||||
|
||||
|
||||
@@ -1843,7 +1843,7 @@ parser_parse_import_statement (parser_context_t *context_p) /**< parser context
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_IMPORT);
|
||||
|
||||
parser_module_check_request_place (context_p);
|
||||
parser_module_context_init (context_p);
|
||||
parser_module_context_init ();
|
||||
|
||||
ecma_module_node_t module_node;
|
||||
memset (&module_node, 0, sizeof (ecma_module_node_t));
|
||||
@@ -1964,7 +1964,7 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_EXPORT);
|
||||
|
||||
parser_module_check_request_place (context_p);
|
||||
parser_module_context_init (context_p);
|
||||
parser_module_context_init ();
|
||||
|
||||
ecma_module_node_t module_node;
|
||||
memset (&module_node, 0, sizeof (ecma_module_node_t));
|
||||
|
||||
@@ -151,7 +151,7 @@ print_unhandled_exception (jerry_value_t error_value) /**< error value */
|
||||
}
|
||||
else
|
||||
{
|
||||
jerry_size_t string_end = jerry_string_to_char_buffer (err_str_val, err_str_buf, err_str_size);
|
||||
jerry_size_t string_end = jerry_string_to_utf8_char_buffer (err_str_val, err_str_buf, err_str_size);
|
||||
assert (string_end == err_str_size);
|
||||
err_str_buf[string_end] = 0;
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if !defined (WIN32)
|
||||
#include <libgen.h>
|
||||
#endif /* !defined (WIN32) */
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
@@ -203,22 +206,58 @@ jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
|
||||
* @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 */
|
||||
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 */
|
||||
{
|
||||
size_t ret = 0;
|
||||
|
||||
#if defined (WIN32)
|
||||
char *norm_p = _fullpath (out_buf_p, in_path_p, out_buf_size);
|
||||
char drive[_MAX_DRIVE];
|
||||
char *dir_p = (char *) malloc (_MAX_DIR);
|
||||
|
||||
char *path_p = (char *) malloc (_MAX_PATH * 2);
|
||||
*path_p = '\0';
|
||||
|
||||
if (base_file_p != NULL)
|
||||
{
|
||||
_splitpath_s (base_file_p,
|
||||
&drive,
|
||||
_MAX_DRIVE,
|
||||
dir_p,
|
||||
_MAX_DIR,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
0);
|
||||
strncat (path_p, &drive, _MAX_DRIVE);
|
||||
strncat (path_p, dir_p, _MAX_DIR);
|
||||
}
|
||||
|
||||
strncat (path_p, in_path_p, _MAX_PATH);
|
||||
|
||||
char *norm_p = _fullpath (out_buf_p, path_p, out_buf_size);
|
||||
|
||||
free (path_p);
|
||||
free (dir_p);
|
||||
|
||||
if (norm_p != NULL)
|
||||
{
|
||||
ret = strnlen (norm_p, out_buf_size);
|
||||
}
|
||||
#elif defined (__unix__) || defined (__APPLE__)
|
||||
char *temp_p = (char *) malloc (PATH_MAX);
|
||||
char *norm_p = realpath (in_path_p, temp_p);
|
||||
#define MAX_JERRY_PATH_SIZE 256
|
||||
char *buffer_p = (char *) malloc (PATH_MAX);
|
||||
char *path_p = (char *) malloc (PATH_MAX);
|
||||
|
||||
char *base_p = dirname (base_file_p);
|
||||
strncpy (path_p, base_p, MAX_JERRY_PATH_SIZE);
|
||||
strncat (path_p, "/", 1);
|
||||
strncat (path_p, in_path_p, MAX_JERRY_PATH_SIZE);
|
||||
|
||||
char *norm_p = realpath (path_p, buffer_p);
|
||||
free (path_p);
|
||||
|
||||
if (norm_p != NULL)
|
||||
{
|
||||
@@ -230,9 +269,12 @@ jerry_port_normalize_path (const char *in_path_p, /**< input file path */
|
||||
}
|
||||
}
|
||||
|
||||
free (temp_p);
|
||||
free (buffer_p);
|
||||
#undef MAX_JERRY_PATH_SIZE
|
||||
#else
|
||||
/* Do nothing. */
|
||||
(void) base_file_p;
|
||||
|
||||
/* Do nothing, just copy the input. */
|
||||
const size_t len = strnlen (in_path_p, out_buf_size);
|
||||
if (len < out_buf_size)
|
||||
{
|
||||
|
||||
@@ -173,7 +173,7 @@ print_unhandled_exception (jerry_value_t error_value) /**< error value */
|
||||
}
|
||||
else
|
||||
{
|
||||
jerry_size_t sz = jerry_string_to_char_buffer (err_str_val, err_str_buf, err_str_size);
|
||||
jerry_size_t sz = jerry_string_to_utf8_char_buffer (err_str_val, err_str_buf, err_str_size);
|
||||
assert (sz == err_str_size);
|
||||
err_str_buf[err_str_size] = 0;
|
||||
|
||||
|
||||
@@ -132,10 +132,13 @@ jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
|
||||
* @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 */
|
||||
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 */
|
||||
{
|
||||
(void) base_file_p;
|
||||
|
||||
size_t len = strlen (in_path_p);
|
||||
if (len + 1 > out_buf_size)
|
||||
{
|
||||
|
||||
@@ -145,7 +145,7 @@ print_unhandled_exception (jerry_value_t error_value) /**< error value */
|
||||
}
|
||||
else
|
||||
{
|
||||
jerry_size_t sz = jerry_string_to_char_buffer (err_str_val, err_str_buf, err_str_size);
|
||||
jerry_size_t sz = jerry_string_to_utf8_char_buffer (err_str_val, err_str_buf, err_str_size);
|
||||
assert (sz == err_str_size);
|
||||
err_str_buf[err_str_size] = 0;
|
||||
|
||||
@@ -575,10 +575,13 @@ jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
|
||||
* @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 */
|
||||
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 */
|
||||
{
|
||||
(void) base_file_p;
|
||||
|
||||
size_t len = strlen (in_path_p);
|
||||
if (len + 1 > out_buf_size)
|
||||
{
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {} from "tests/jerry/es2015/module-export-01.js";
|
||||
export {aa,} from "tests/jerry/es2015/module-export-01.js";
|
||||
export {bb as b_, cc as c_} from "tests/jerry/es2015/module-export-01.js";
|
||||
export * from "tests/jerry/es2015/module-export-01.js";
|
||||
export {} from "module-export-01.js";
|
||||
export {aa,} from "module-export-01.js";
|
||||
export {bb as b_, cc as c_} from "module-export-01.js";
|
||||
export * from "module-export-01.js";
|
||||
export default function () {return "default"};
|
||||
|
||||
@@ -23,4 +23,4 @@ export default class {
|
||||
}
|
||||
}
|
||||
|
||||
export * from "tests/jerry/es2015/module-export-02.js"
|
||||
export * from "module-export-02.js"
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from "tests/jerry/es2015/module-export-01.js";
|
||||
export * from "tests/jerry/es2015/module-export-04.js";
|
||||
export * from "module-export-01.js";
|
||||
export * from "module-export-04.js";
|
||||
export default a = "str"
|
||||
|
||||
@@ -14,6 +14,6 @@
|
||||
*/
|
||||
|
||||
export {}
|
||||
export {} from "tests/jerry/es2015/module-export-01.js";
|
||||
export {} from "module-export-01.js";
|
||||
export {};
|
||||
export {} from "tests/jerry/es2015/module-export-04.js"
|
||||
export {} from "module-export-04.js"
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import "tests/jerry/es2015/module-export-01.js";
|
||||
import def from "tests/jerry/es2015/module-export-01.js";
|
||||
import {} from "tests/jerry/es2015/module-export-01.js";
|
||||
import {aa as a,} from "tests/jerry/es2015/module-export-01.js";
|
||||
import {bb as b, cc as c} from "tests/jerry/es2015/module-export-01.js";
|
||||
import {x} from "tests/jerry/es2015/module-export-01.js";
|
||||
import * as mod from "tests/jerry/es2015/module-export-01.js";
|
||||
import "./module-export-01.js";
|
||||
import def from "module-export-01.js";
|
||||
import {} from "module-export-01.js";
|
||||
import {aa as a,} from "module-export-01.js";
|
||||
import {bb as b, cc as c} from "module-export-01.js";
|
||||
import {x} from "module-export-01.js";
|
||||
import * as mod from "module-export-01.js";
|
||||
|
||||
assert (def === "default");
|
||||
assert (a === "a");
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import def, * as mod from "tests/jerry/es2015/module-export-02.js";
|
||||
import {b_, c_,} from "tests/jerry/es2015/module-export-02.js";
|
||||
import def, * as mod from "module-export-02.js";
|
||||
import {b_, c_,} from "module-export-02.js";
|
||||
|
||||
assert (def() === "default")
|
||||
assert (mod.aa === "a")
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import incrementer, {aa, c_, x,} from "tests/jerry/es2015/module-export-03.js"
|
||||
import incrementer, {aa, c_, x,} from "module-export-03.js"
|
||||
var i = new incrementer(3);
|
||||
assert(i.incr() === 4);
|
||||
assert(i.incr() === 5);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import "tests/jerry/es2015/module-import-01.js"
|
||||
import "tests/jerry/es2015/module-export-05.js"
|
||||
import "tests/jerry/es2015/module-export-06.js"
|
||||
import "tests/jerry/es2015/module-export-07.js"
|
||||
import "module-import-01.js";
|
||||
import "module-export-05.js";
|
||||
import "module-export-06.js";
|
||||
import "module-export-07.js";
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
// File does not exist.
|
||||
import b from "tests/jerry/fail/module-exports.js"
|
||||
import b from "module-exports.js"
|
||||
|
||||
@@ -13,4 +13,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { , as b } from "tests/jerry/es2015/module-export-01.js";
|
||||
import { , as b } from "../es2015/module-export-01.js";
|
||||
|
||||
@@ -13,4 +13,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import , as b from "tests/jerry/es2015/module-export-01.js";
|
||||
import , as b from "../es2015/module-export-01.js";
|
||||
|
||||
@@ -13,4 +13,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { b as , } from "tests/jerry/es2015/module-export-01.js";
|
||||
import { b as , } from "../es2015/module-export-01.js";
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Named imports must be in a NamedImports block. */
|
||||
import b as , from "tests/jerry/es2015/module-export-01.js";
|
||||
import b as , from "../es2015/module-export-01.js";
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Module requests must always be evaluated. */
|
||||
import "tests/jerry/fail/module-sideeffect.js"
|
||||
import "./module-sideeffect.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Can't have duplicate local bindings */
|
||||
import { c as a, d as a } from "tests/jerry/es2015/module-export-01.js";
|
||||
import { c as a, d as a } from "../es2015/module-export-01.js";
|
||||
|
||||
@@ -15,5 +15,5 @@
|
||||
|
||||
/* Import/export statements must be in the global scope. */
|
||||
if (true) {
|
||||
import { c } from "tests/jerry/es2015/module-export-01.js";
|
||||
import { c } from "../es2015/module-export-01.js";
|
||||
}
|
||||
|
||||
@@ -15,5 +15,5 @@
|
||||
|
||||
/* Import/export statements must be in the global scope. */
|
||||
function someFunction() {
|
||||
import { c } from "tests/jerry/es2015/module-export-01.js";
|
||||
import { c } from "../es2015/module-export-01.js";
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Import/export statements must be in the global scope. */
|
||||
eval ('import { c } from "tests/jerry/es2015/module-export-01.js";');
|
||||
eval ('import { c } from "../es2015/module-export-01.js";');
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* NamedImports must always be followed by a FromClause. */
|
||||
import { b }, from "tests/jerry/es2015/module-export-01.js"
|
||||
import { b }, from "../es2015/module-export-01.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* An import statement can have either a NameSpaceImport or NamedIpmorts */
|
||||
import * as mod, { b } from "tests/jerry/es2015/module-export-01.js"
|
||||
import * as mod, { b } from "../es2015/module-export-01.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* '*' is not valid inside NamedImports. */
|
||||
import { *, d } from "tests/jerry/es2015/module-imported-01.js"
|
||||
import { *, d } from "../es2015/module-imported-01.js"
|
||||
|
||||
@@ -14,5 +14,5 @@
|
||||
*/
|
||||
|
||||
/* Can't have duplicated local bindings. */
|
||||
import { b } from "tests/jerry/es2015/module-export-01.js"
|
||||
import { b } from "tests/jerry/es2015/module-export-02.js"
|
||||
import { b } from "../es2015/module-export-01.js"
|
||||
import { b } from "../es2015/module-export-02.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* FromClause must follow an ImportClause. */
|
||||
import from "tests/jerry/es2015/module-export-02.js"
|
||||
import from "../es2015/module-export-02.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Namespace imports must have a local name. */
|
||||
import * from "tests/jerry/es2015/module-export-01.js"
|
||||
import * from "../es2015/module-export-01.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Star exports can't have an export name. */
|
||||
export * as star from "tests/jerry/es2015/module-export-01.js"
|
||||
export * as star from "../es2015/module-export-01.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Indirect exports must be checked if they are resolvable. */
|
||||
export { l } from "tests/jerry/es2015/module-export-01.js"
|
||||
export { l } from "../es2015/module-export-01.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Can't have circular imports/exports. */
|
||||
export { b } from "tests/jerry/fail/module-027.js"
|
||||
export { b } from "./module-027.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Can't have circular imports/exports. */
|
||||
export { b } from "tests/jerry/fail/module-026.js"
|
||||
export { b } from "./module-026.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Ambiguous import */
|
||||
import { x } from "tests/jerry/es2015/module-export-05.js"
|
||||
import { x } from "../es2015/module-export-05.js"
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* Import/export statements must be in the global scope. */
|
||||
Function('','import { c } from "tests/jerry/es2015/module-export-01.js";')
|
||||
Function('','import { c } from "../es2015/module-export-01.js";')
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
*/
|
||||
|
||||
/* No default export found. */
|
||||
import def from "tests/jerry/es2015/module-export-06.js"
|
||||
import def from "../es2015/module-export-06.js"
|
||||
|
||||
@@ -13,4 +13,4 @@
|
||||
// limitations under the License.
|
||||
|
||||
export {} from "dummy.js";
|
||||
export {} from "tests/jerry/es2015/module-export-04.js";
|
||||
export {} from "../es2015/module-export-04.js";
|
||||
|
||||
Reference in New Issue
Block a user