Change resource name to a string. (#4724)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-07-27 13:40:19 +02:00
committed by GitHub
parent d99905aca6
commit 951044c036
17 changed files with 105 additions and 106 deletions
+3 -3
View File
@@ -1021,10 +1021,10 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
if ((exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_HAS_RESOURCE)
&& option_values_p != NULL
&& option_values_p->resource_name_length > 0)
&& ecma_is_value_string (option_values_p->resource_name) > 0)
{
resource_name = ecma_find_or_create_literal_string (option_values_p->resource_name_p,
(lit_utf8_size_t) option_values_p->resource_name_length);
ecma_ref_ecma_string (ecma_get_string_from_value (option_values_p->resource_name));
resource_name = option_values_p->resource_name;
}
script_p->resource_name = resource_name;
+14 -6
View File
@@ -407,12 +407,16 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
&& options_p != NULL
&& (options_p->options & JERRY_PARSE_HAS_RESOURCE)
&& options_p->resource_name_length > 0)
&& ecma_is_value_string (options_p->resource_name))
{
ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (options_p->resource_name),
resource_name_start_p,
resource_name_size);
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME,
JERRY_DEBUGGER_NO_SUBTYPE,
options_p->resource_name_p,
options_p->resource_name_length);
resource_name_start_p,
resource_name_size);
ECMA_FINALIZE_UTF8_STRING (resource_name_start_p, resource_name_size);
}
#endif /* JERRY_DEBUGGER && JERRY_PARSER */
@@ -508,12 +512,16 @@ jerry_parse_function (const jerry_char_t *arg_list_p, /**< script source */
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
&& options_p != NULL
&& (options_p->options & JERRY_PARSE_HAS_RESOURCE)
&& options_p->resource_name_length > 0)
&& ecma_is_value_string (options_p->resource_name))
{
ECMA_STRING_TO_UTF8_STRING (ecma_get_string_from_value (options_p->resource_name),
resource_name_start_p,
resource_name_size);
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME,
JERRY_DEBUGGER_NO_SUBTYPE,
options_p->resource_name_p,
options_p->resource_name_length);
resource_name_start_p,
resource_name_size);
ECMA_FINALIZE_UTF8_STRING (resource_name_start_p, resource_name_size);
}
#endif /* JERRY_DEBUGGER && JERRY_PARSER */
+4
View File
@@ -1538,6 +1538,10 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
}
}
#if JERRY_RESOURCE_NAME
ecma_deref_ecma_string (ecma_get_string_from_value (script_p->resource_name));
#endif /* JERRY_RESOURCE_NAME */
jmem_heap_free_block (script_p, script_size);
}
+4 -5
View File
@@ -48,7 +48,7 @@ typedef enum
JERRY_SNAPSHOT_EXEC_COPY_DATA = (1u << 0), /**< copy snashot data */
JERRY_SNAPSHOT_EXEC_ALLOW_STATIC = (1u << 1), /**< static snapshots allowed */
JERRY_SNAPSHOT_EXEC_LOAD_AS_FUNCTION = (1u << 2), /**< load snapshot as function instead of executing it */
JERRY_SNAPSHOT_EXEC_HAS_RESOURCE = (1u << 3), /**< resource_name_p and resource_name_length fields are valid
JERRY_SNAPSHOT_EXEC_HAS_RESOURCE = (1u << 3), /**< resource_name field is valid
* in jerry_exec_snapshot_option_values_t */
JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE = (1u << 4), /**< user_value field is valid
* in jerry_exec_snapshot_option_values_t */
@@ -59,10 +59,9 @@ typedef enum
*/
typedef struct
{
const jerry_char_t *resource_name_p; /**< resource name (usually a file name)
* if JERRY_SNAPSHOT_EXEC_HAS_RESOURCE is set in exec_snapshot_opts */
size_t resource_name_length; /**< length of resource name
* if JERRY_SNAPSHOT_EXEC_HAS_RESOURCE is set in exec_snapshot_opts */
jerry_value_t resource_name; /**< resource name string (usually a file name)
* if JERRY_SNAPSHOT_EXEC_HAS_RESOURCE is set in exec_snapshot_opts
* Note: non-string values are ignored */
jerry_value_t user_value; /**< user value assigned to all functions created by this script including
* eval calls executed by the script if JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE
* is set in exec_snapshot_opts */
+4 -5
View File
@@ -166,7 +166,7 @@ typedef enum
JERRY_PARSE_NO_OPTS = 0, /**< no options passed */
JERRY_PARSE_STRICT_MODE = (1 << 0), /**< enable strict mode */
JERRY_PARSE_MODULE = (1 << 1), /**< parse source as an ECMAScript module */
JERRY_PARSE_HAS_RESOURCE = (1 << 2), /**< resource_name_p and resource_name_length fields are valid */
JERRY_PARSE_HAS_RESOURCE = (1 << 2), /**< resource_name field is valid */
JERRY_PARSE_HAS_START = (1 << 3), /**< start_line and start_column fields are valid */
JERRY_PARSE_HAS_USER_VALUE = (1 << 4), /**< user_value field is valid */
} jerry_parse_option_enable_feature_t;
@@ -177,10 +177,9 @@ typedef enum
typedef struct
{
uint32_t options; /**< combination of jerry_parse_option_enable_feature_t values */
const jerry_char_t *resource_name_p; /**< resource name (usually a file name)
* if JERRY_PARSE_HAS_RESOURCE is set in options */
size_t resource_name_length; /**< length of resource name
* if JERRY_PARSE_HAS_RESOURCE is set in options */
jerry_value_t resource_name; /**< resource name string (usually a file name)
* if JERRY_PARSE_HAS_RESOURCE is set in options
* Note: non-string values are ignored */
uint32_t start_line; /**< start line of the source code if JERRY_PARSE_HAS_START is set in options */
uint32_t start_column; /**< start column of the source code if JERRY_PARSE_HAS_START is set in options */
jerry_value_t user_value; /**< user value assigned to all functions created by this script including eval
+7 -3
View File
@@ -1863,10 +1863,10 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
if (context.options_p != NULL
&& (context.options_p->options & JERRY_PARSE_HAS_RESOURCE)
&& context.options_p->resource_name_length > 0)
&& ecma_is_value_string (context.options_p->resource_name))
{
resource_name = ecma_find_or_create_literal_string (context.options_p->resource_name_p,
(lit_utf8_size_t) context.options_p->resource_name_length);
ecma_ref_ecma_string (ecma_get_string_from_value (context.options_p->resource_name));
resource_name = context.options_p->resource_name;
}
else if (context.global_status_flags & ECMA_PARSE_EVAL)
{
@@ -2100,6 +2100,10 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
parser_free_literals (&context.literal_pool);
parser_cbc_stream_free (&context.byte_code);
#if JERRY_RESOURCE_NAME
ecma_deref_ecma_string (ecma_get_string_from_value (context.script_p->resource_name));
#endif /* JERRY_RESOURCE_NAME */
JERRY_ASSERT (context.script_p->refs_and_type >= CBC_SCRIPT_REF_ONE);
jmem_heap_free_block (context.script_p, script_size);
}