Support shared user data for scripts (#4710)
The same data is returned for the script and all of its functions, including those which are created by an eval call. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -50,9 +50,6 @@ snapshot_get_global_flags (bool has_regex, /**< regex literal is present */
|
||||
#if JERRY_ESNEXT
|
||||
flags |= (has_class ? JERRY_SNAPSHOT_HAS_CLASS_LITERAL : 0);
|
||||
#endif /* JERRY_ESNEXT */
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
flags |= JERRY_SNAPSHOT_HAS_REALM_VALUE;
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
|
||||
return flags;
|
||||
} /* snapshot_get_global_flags */
|
||||
@@ -71,9 +68,6 @@ snapshot_check_global_flags (uint32_t global_flags) /**< global flags */
|
||||
#if JERRY_ESNEXT
|
||||
global_flags &= (uint32_t) ~JERRY_SNAPSHOT_HAS_CLASS_LITERAL;
|
||||
#endif /* JERRY_ESNEXT */
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
global_flags |= JERRY_SNAPSHOT_HAS_REALM_VALUE;
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
|
||||
return global_flags == snapshot_get_global_flags (false, false);
|
||||
} /* snapshot_check_global_flags */
|
||||
@@ -395,9 +389,7 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
|
||||
literal_end = (uint32_t) (args_p->literal_end - args_p->register_end);
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
args_p->realm_value = JMEM_CP_NULL;
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
args_p->script_value = JMEM_CP_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -407,9 +399,7 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
|
||||
literal_end = (uint32_t) (args_p->literal_end - args_p->register_end);
|
||||
const_literal_end = (uint32_t) (args_p->const_literal_end - args_p->register_end);
|
||||
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
args_p->realm_value = JMEM_CP_NULL;
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
args_p->script_value = JMEM_CP_NULL;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < const_literal_end; i++)
|
||||
@@ -569,6 +559,7 @@ static ecma_compiled_code_t *
|
||||
snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of the
|
||||
* current primary function */
|
||||
const uint8_t *literal_base_p, /**< literal start */
|
||||
cbc_script_t *script_p, /**< script */
|
||||
bool copy_bytecode) /**< byte code should be copied to memory */
|
||||
{
|
||||
ecma_compiled_code_t *bytecode_p = (ecma_compiled_code_t *) base_addr_p;
|
||||
@@ -598,6 +589,14 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
uint32_t const_literal_end;
|
||||
uint32_t literal_end;
|
||||
|
||||
if (JERRY_UNLIKELY (script_p->refs_and_type >= CBC_SCRIPT_REF_MAX))
|
||||
{
|
||||
/* This is probably never happens in practice. */
|
||||
jerry_fatal (ERR_REF_COUNT_LIMIT);
|
||||
}
|
||||
|
||||
script_p->refs_and_type += CBC_SCRIPT_REF_ONE;
|
||||
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
{
|
||||
uint8_t *byte_p = (uint8_t *) bytecode_p;
|
||||
@@ -608,9 +607,7 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
literal_end = (uint32_t) (args_p->literal_end - args_p->register_end);
|
||||
header_size = sizeof (cbc_uint16_arguments_t);
|
||||
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (args_p->realm_value, ecma_builtin_get_global ());
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (args_p->script_value, script_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -622,9 +619,7 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
literal_end = (uint32_t) (args_p->literal_end - args_p->register_end);
|
||||
header_size = sizeof (cbc_uint8_arguments_t);
|
||||
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (args_p->realm_value, ecma_builtin_get_global ());
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (args_p->script_value, script_p);
|
||||
}
|
||||
|
||||
if (copy_bytecode
|
||||
@@ -729,6 +724,7 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
ecma_compiled_code_t *literal_bytecode_p;
|
||||
literal_bytecode_p = snapshot_load_compiled_code (base_addr_p + literal_offset,
|
||||
literal_base_p,
|
||||
script_p,
|
||||
copy_bytecode);
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (literal_start_p[i],
|
||||
@@ -930,14 +926,18 @@ jerry_value_t
|
||||
jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
|
||||
size_t snapshot_size, /**< size of snapshot */
|
||||
size_t func_index, /**< index of primary function */
|
||||
uint32_t exec_snapshot_opts) /**< jerry_exec_snapshot_opts_t option bits */
|
||||
uint32_t exec_snapshot_opts, /**< jerry_exec_snapshot_opts_t option bits */
|
||||
const jerry_exec_snapshot_option_values_t *option_values_p) /**< additional option values,
|
||||
* can be NULL if not used */
|
||||
{
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
JERRY_ASSERT (snapshot_p != NULL);
|
||||
|
||||
uint32_t allowed_opts = (JERRY_SNAPSHOT_EXEC_COPY_DATA
|
||||
| JERRY_SNAPSHOT_EXEC_ALLOW_STATIC
|
||||
| JERRY_SNAPSHOT_EXEC_LOAD_AS_FUNCTION);
|
||||
| JERRY_SNAPSHOT_EXEC_LOAD_AS_FUNCTION
|
||||
| JERRY_SNAPSHOT_EXEC_HAS_RESOURCE
|
||||
| JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE);
|
||||
|
||||
if ((exec_snapshot_opts & ~(allowed_opts)) != 0)
|
||||
{
|
||||
@@ -998,16 +998,58 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_value_t user_value = ECMA_VALUE_EMPTY;
|
||||
|
||||
if ((exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_HAS_USER_VALUE)
|
||||
&& option_values_p != NULL)
|
||||
{
|
||||
user_value = option_values_p->user_value;
|
||||
}
|
||||
|
||||
uint32_t script_size = (user_value != ECMA_VALUE_EMPTY ? sizeof (cbc_script_user_t)
|
||||
: sizeof (cbc_script_t));
|
||||
cbc_script_t *script_p = jmem_heap_alloc_block (script_size);
|
||||
|
||||
CBC_SCRIPT_SET_TYPE (script_p, user_value, CBC_SCRIPT_REF_ONE);
|
||||
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
script_p->realm_p = (ecma_object_t *) JERRY_CONTEXT (global_object_p);
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
if ((exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_HAS_RESOURCE)
|
||||
&& option_values_p != NULL
|
||||
&& option_values_p->resource_name_length > 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);
|
||||
}
|
||||
|
||||
script_p->resource_name = resource_name;
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
|
||||
const uint8_t *literal_base_p = snapshot_data_p + header_p->lit_table_offset;
|
||||
|
||||
bytecode_p = snapshot_load_compiled_code ((const uint8_t *) bytecode_p,
|
||||
literal_base_p,
|
||||
script_p,
|
||||
(exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_COPY_DATA) != 0);
|
||||
|
||||
if (bytecode_p == NULL)
|
||||
{
|
||||
JERRY_ASSERT (script_p->refs_and_type >= CBC_SCRIPT_REF_ONE);
|
||||
jmem_heap_free_block (script_p, script_size);
|
||||
return ecma_raise_type_error (invalid_format_error_p);
|
||||
}
|
||||
|
||||
script_p->refs_and_type -= CBC_SCRIPT_REF_ONE;
|
||||
|
||||
if (user_value != ECMA_VALUE_EMPTY)
|
||||
{
|
||||
((cbc_script_user_t *) script_p)->user_value = ecma_copy_value_if_not_object (user_value);
|
||||
}
|
||||
}
|
||||
|
||||
#if JERRY_PARSER_DUMP_BYTE_CODE
|
||||
@@ -1063,6 +1105,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
|
||||
JERRY_UNUSED (snapshot_size);
|
||||
JERRY_UNUSED (func_index);
|
||||
JERRY_UNUSED (exec_snapshot_opts);
|
||||
JERRY_UNUSED (option_values_p);
|
||||
|
||||
return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) "Snapshot execution is not supported");
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
|
||||
@@ -45,8 +45,7 @@ typedef enum
|
||||
{
|
||||
/* 8 bits are reserved for dynamic features */
|
||||
JERRY_SNAPSHOT_HAS_REGEX_LITERAL = (1u << 0), /**< byte code has regex literal */
|
||||
JERRY_SNAPSHOT_HAS_REALM_VALUE = (1u << 1), /**< byte code has realm value */
|
||||
JERRY_SNAPSHOT_HAS_CLASS_LITERAL = (1u << 2), /**< byte code has class literal */
|
||||
JERRY_SNAPSHOT_HAS_CLASS_LITERAL = (1u << 1), /**< byte code has class literal */
|
||||
/* 24 bits are reserved for compile time features */
|
||||
JERRY_SNAPSHOT_FOUR_BYTE_CPOINTER = (1u << 8) /**< deprecated, an unused placeholder now */
|
||||
} jerry_snapshot_global_flags_t;
|
||||
|
||||
+34
-2
@@ -393,7 +393,8 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */
|
||||
uint32_t allowed_parse_options = (JERRY_PARSE_STRICT_MODE
|
||||
| JERRY_PARSE_MODULE
|
||||
| JERRY_PARSE_HAS_RESOURCE
|
||||
| JERRY_PARSE_HAS_START);
|
||||
| JERRY_PARSE_HAS_START
|
||||
| JERRY_PARSE_HAS_USER_VALUE);
|
||||
|
||||
if (options_p != NULL && (options_p->options & ~allowed_parse_options) != 0)
|
||||
{
|
||||
@@ -493,7 +494,8 @@ jerry_parse_function (const jerry_char_t *arg_list_p, /**< script source */
|
||||
|
||||
uint32_t allowed_parse_options = (JERRY_PARSE_STRICT_MODE
|
||||
| JERRY_PARSE_HAS_RESOURCE
|
||||
| JERRY_PARSE_HAS_START);
|
||||
| JERRY_PARSE_HAS_START
|
||||
| JERRY_PARSE_HAS_USER_VALUE);
|
||||
|
||||
if (options_p != NULL && (options_p->options & ~allowed_parse_options) != 0)
|
||||
{
|
||||
@@ -5381,6 +5383,36 @@ jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */
|
||||
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
} /* jerry_get_resource_name */
|
||||
|
||||
/**
|
||||
* Returns the user value assigned to a script / module / function.
|
||||
*
|
||||
* Note:
|
||||
* This value is usually set by the parser when
|
||||
* the JERRY_PARSE_HAS_USER_VALUE flag is passed.
|
||||
*
|
||||
* @return user value
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_get_user_value (const jerry_value_t value) /**< jerry api value */
|
||||
{
|
||||
const ecma_compiled_code_t *bytecode_p = ecma_bytecode_get_from_value (value);
|
||||
|
||||
if (bytecode_p == NULL)
|
||||
{
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value;
|
||||
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
|
||||
|
||||
if (CBC_SCRIPT_GET_TYPE (script_p) == CBC_SCRIPT_GENERIC)
|
||||
{
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
return ecma_copy_value (((cbc_script_user_t *) script_p)->user_value);
|
||||
} /* jerry_get_user_value */
|
||||
|
||||
/**
|
||||
* Replaces the currently active realm with another realm.
|
||||
*
|
||||
|
||||
@@ -1068,9 +1068,7 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
ecma_gc_set_object_visited (ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t,
|
||||
ext_func_p->u.function.scope_cp));
|
||||
|
||||
#if JERRY_ESNEXT || JERRY_BUILTIN_REALMS
|
||||
const ecma_compiled_code_t *byte_code_p = ecma_op_function_get_compiled_code (ext_func_p);
|
||||
#endif /* JERRY_ESNEXT || JERRY_BUILTIN_REALMS */
|
||||
|
||||
#if JERRY_ESNEXT
|
||||
if (CBC_FUNCTION_IS_ARROW (byte_code_p->status_flags))
|
||||
@@ -1089,29 +1087,27 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
|
||||
}
|
||||
#endif /* JERRY_ESNEXT */
|
||||
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
if (ext_func_p->u.function.bytecode_cp == JMEM_CP_NULL)
|
||||
if (JERRY_UNLIKELY (byte_code_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
|
||||
{
|
||||
/* Static snapshot functions have a global realm */
|
||||
break;
|
||||
}
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
|
||||
ecma_object_t *realm_p;
|
||||
ecma_value_t script_value = ((cbc_uint8_arguments_t *) byte_code_p)->script_value;
|
||||
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
|
||||
|
||||
if (byte_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
if (CBC_SCRIPT_GET_TYPE (script_p) == CBC_SCRIPT_USER_OBJECT)
|
||||
{
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) byte_code_p;
|
||||
realm_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, args_p->realm_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) byte_code_p;
|
||||
realm_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t, args_p->realm_value);
|
||||
cbc_script_user_t *script_user_p = (cbc_script_user_t *) script_p;
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_object (script_user_p->user_value));
|
||||
ecma_gc_set_object_visited (ecma_get_object_from_value (script_user_p->user_value));
|
||||
}
|
||||
|
||||
ecma_gc_set_object_visited (realm_p);
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ecma_gc_set_object_visited (script_p->realm_p);
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
@@ -1514,6 +1515,32 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
|
||||
}
|
||||
}
|
||||
|
||||
ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value;
|
||||
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
|
||||
script_p->refs_and_type -= CBC_SCRIPT_REF_ONE;
|
||||
|
||||
if (script_p->refs_and_type < CBC_SCRIPT_REF_ONE)
|
||||
{
|
||||
size_t script_size = sizeof (cbc_script_t);
|
||||
|
||||
uint32_t type = CBC_SCRIPT_GET_TYPE (script_p);
|
||||
|
||||
if (type != CBC_SCRIPT_GENERIC)
|
||||
{
|
||||
script_size = sizeof (cbc_script_user_t);
|
||||
|
||||
if (type == CBC_SCRIPT_USER_VALUE)
|
||||
{
|
||||
cbc_script_user_t *script_user_p = (cbc_script_user_t *) script_p;
|
||||
|
||||
JERRY_ASSERT (!ecma_is_value_object (script_user_p->user_value));
|
||||
ecma_free_value (script_user_p->user_value);
|
||||
}
|
||||
}
|
||||
|
||||
jmem_heap_free_block (script_p, script_size);
|
||||
}
|
||||
|
||||
#if JERRY_ESNEXT
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS)
|
||||
{
|
||||
@@ -1584,6 +1611,72 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
|
||||
((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG);
|
||||
} /* ecma_bytecode_deref */
|
||||
|
||||
/**
|
||||
* Gets the byte code asigned to a script / module / function
|
||||
*
|
||||
* @return byte code - if available, NULL - otherwise
|
||||
*/
|
||||
const ecma_compiled_code_t *
|
||||
ecma_bytecode_get_from_value (ecma_value_t value) /**< compiled code */
|
||||
{
|
||||
if (!ecma_is_value_object (value))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecma_object_t *object_p = ecma_get_object_from_value (value);
|
||||
|
||||
while (true)
|
||||
{
|
||||
switch (ecma_get_object_type (object_p))
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_CLASS:
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_SCRIPT)
|
||||
{
|
||||
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
|
||||
ext_object_p->u.cls.u3.value);
|
||||
}
|
||||
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
if (ext_object_p->u.cls.type == ECMA_OBJECT_CLASS_MODULE)
|
||||
{
|
||||
ecma_module_t *module_p = (ecma_module_t *) object_p;
|
||||
|
||||
if (!(module_p->header.u.cls.u2.module_flags & ECMA_MODULE_IS_NATIVE))
|
||||
{
|
||||
return module_p->u.compiled_code_p;
|
||||
}
|
||||
}
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
return NULL;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
{
|
||||
if (!ecma_get_object_is_builtin (object_p))
|
||||
{
|
||||
return ecma_op_function_get_compiled_code ((ecma_extended_object_t *) object_p);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
{
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
object_p = ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG (ecma_object_t,
|
||||
ext_object_p->u.bound_function.target_function);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* ecma_bytecode_get_from_value */
|
||||
|
||||
/**
|
||||
* Resolve the position of the arguments list start of the compiled code
|
||||
*
|
||||
@@ -1711,16 +1804,15 @@ ecma_value_t
|
||||
ecma_get_resource_name (const ecma_compiled_code_t *bytecode_p) /**< compiled code */
|
||||
{
|
||||
#if JERRY_RESOURCE_NAME
|
||||
if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
if (JERRY_UNLIKELY (bytecode_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
|
||||
{
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_p;
|
||||
ecma_value_t *lit_pool_p = (ecma_value_t *) ((uint8_t *) bytecode_p + sizeof (cbc_uint16_arguments_t));
|
||||
return lit_pool_p[args_p->const_literal_end - args_p->register_end - 1];
|
||||
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
}
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
|
||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_p;
|
||||
ecma_value_t *lit_pool_p = (ecma_value_t *) ((uint8_t *) bytecode_p + sizeof (cbc_uint8_arguments_t));
|
||||
return lit_pool_p[args_p->const_literal_end - args_p->register_end - 1];
|
||||
ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value;
|
||||
return ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value)->resource_name;
|
||||
#else /* !JERRY_RESOURCE_NAME */
|
||||
JERRY_UNUSED (bytecode_p);
|
||||
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
@@ -532,6 +532,7 @@ void ecma_raise_error_from_error_reference (ecma_value_t value);
|
||||
|
||||
void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p);
|
||||
void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
|
||||
const ecma_compiled_code_t *ecma_bytecode_get_from_value (ecma_value_t value);
|
||||
ecma_value_t *ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p);
|
||||
#if JERRY_ESNEXT
|
||||
ecma_value_t *ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p);
|
||||
|
||||
@@ -759,29 +759,17 @@ ecma_op_function_get_compiled_code (ecma_extended_object_t *function_p) /**< fun
|
||||
extern inline ecma_global_object_t * JERRY_ATTR_ALWAYS_INLINE
|
||||
ecma_op_function_get_realm (const ecma_compiled_code_t *bytecode_header_p) /**< byte code header */
|
||||
{
|
||||
ecma_value_t realm_value;
|
||||
|
||||
if (bytecode_header_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
|
||||
{
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_header_p;
|
||||
realm_value = args_p->realm_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_header_p;
|
||||
realm_value = args_p->realm_value;
|
||||
}
|
||||
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
if (JERRY_LIKELY (realm_value != JMEM_CP_NULL))
|
||||
if (JERRY_UNLIKELY (bytecode_header_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION))
|
||||
{
|
||||
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, realm_value);
|
||||
return (ecma_global_object_t *) ecma_builtin_get_global ();
|
||||
}
|
||||
|
||||
return (ecma_global_object_t *) ecma_builtin_get_global ();
|
||||
#else /* !JERRY_SNAPSHOT_EXEC */
|
||||
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_global_object_t, realm_value);
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
|
||||
ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_header_p)->script_value;
|
||||
cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
|
||||
|
||||
return (ecma_global_object_t *) script_p->realm_p;
|
||||
} /* ecma_op_function_get_realm */
|
||||
|
||||
/**
|
||||
|
||||
@@ -360,6 +360,7 @@ bool jerry_backtrace_is_strict (jerry_backtrace_frame_t *frame_p);
|
||||
*/
|
||||
void jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb, void *user_p, uint32_t frequency);
|
||||
jerry_value_t jerry_get_resource_name (const jerry_value_t value);
|
||||
jerry_value_t jerry_get_user_value (const jerry_value_t value);
|
||||
|
||||
/**
|
||||
* Array buffer components.
|
||||
|
||||
@@ -41,15 +41,33 @@ typedef enum
|
||||
} jerry_generate_snapshot_opts_t;
|
||||
|
||||
/**
|
||||
* Flags for jerry_exec_snapshot_at and jerry_load_function_snapshot_at.
|
||||
* Flags for jerry_exec_snapshot.
|
||||
*/
|
||||
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
|
||||
* 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 */
|
||||
} jerry_exec_snapshot_opts_t;
|
||||
|
||||
/**
|
||||
* Various configuration options for jerry_exec_snapshot.
|
||||
*/
|
||||
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 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 */
|
||||
} jerry_exec_snapshot_option_values_t;
|
||||
|
||||
/**
|
||||
* Snapshot functions.
|
||||
*/
|
||||
@@ -63,7 +81,8 @@ jerry_value_t jerry_generate_function_snapshot (const jerry_char_t *source_p, si
|
||||
uint32_t *buffer_p, size_t buffer_size);
|
||||
|
||||
jerry_value_t jerry_exec_snapshot (const uint32_t *snapshot_p, size_t snapshot_size,
|
||||
size_t func_index, uint32_t exec_snapshot_opts);
|
||||
size_t func_index, uint32_t exec_snapshot_opts,
|
||||
const jerry_exec_snapshot_option_values_t *options_values_p);
|
||||
|
||||
size_t jerry_merge_snapshots (const uint32_t **inp_buffers_p, size_t *inp_buffer_sizes_p, size_t number_of_snapshots,
|
||||
uint32_t *out_buffer_p, size_t out_buffer_size, const char **error_p);
|
||||
|
||||
@@ -168,6 +168,7 @@ typedef enum
|
||||
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_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;
|
||||
|
||||
/**
|
||||
@@ -182,6 +183,8 @@ typedef struct
|
||||
* if JERRY_PARSE_HAS_RESOURCE is set in options */
|
||||
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
|
||||
* calls executed by the script if JERRY_PARSE_HAS_USER_VALUE is set in options */
|
||||
} jerry_parse_options_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,11 +15,15 @@
|
||||
|
||||
#include "js-parser-internal.h"
|
||||
|
||||
JERRY_STATIC_ASSERT ((sizeof (cbc_uint8_arguments_t) % sizeof (jmem_cpointer_t)) == 0,
|
||||
sizeof_cbc_uint8_arguments_t_must_be_divisible_by_sizeof_jmem_cpointer_t);
|
||||
/* These two checks only checks the compiler, they have no effect on the code. */
|
||||
JERRY_STATIC_ASSERT (sizeof (cbc_uint8_arguments_t) == 16,
|
||||
sizeof_cbc_uint8_arguments_t_must_be_16_byte_long);
|
||||
|
||||
JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) % sizeof (jmem_cpointer_t)) == 0,
|
||||
sizeof_cbc_uint16_arguments_t_must_be_divisible_by_sizeof_jmem_cpointer_t);
|
||||
JERRY_STATIC_ASSERT (sizeof (cbc_uint16_arguments_t) == 24,
|
||||
sizeof_cbc_uint16_arguments_t_must_be_24_byte_long);
|
||||
|
||||
JERRY_STATIC_ASSERT (offsetof (cbc_uint8_arguments_t, script_value) == offsetof (cbc_uint16_arguments_t, script_value),
|
||||
script_value_in_cbc_uint8_arguments_and_cbc_uint16_arguments_must_be_in_the_same_offset);
|
||||
|
||||
/**
|
||||
* The reason of these two static asserts to notify the developer to increase the JERRY_SNAPSHOT_VERSION
|
||||
|
||||
@@ -848,13 +848,11 @@ typedef struct
|
||||
ecma_compiled_code_t header; /**< compiled code header */
|
||||
uint8_t stack_limit; /**< maximum number of values stored on the stack */
|
||||
uint8_t argument_end; /**< number of arguments expected by the function */
|
||||
ecma_value_t script_value; /**< script value */
|
||||
uint8_t register_end; /**< end position of the register group */
|
||||
uint8_t ident_end; /**< end position of the identifier group */
|
||||
uint8_t const_literal_end; /**< end position of the const literal group */
|
||||
uint8_t literal_end; /**< end position of the literal group */
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ecma_value_t realm_value; /**< realm value */
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
} cbc_uint8_arguments_t;
|
||||
|
||||
/**
|
||||
@@ -864,15 +862,13 @@ typedef struct
|
||||
{
|
||||
ecma_compiled_code_t header; /**< compiled code header */
|
||||
uint16_t stack_limit; /**< maximum number of values stored on the stack */
|
||||
ecma_value_t script_value; /**< script value */
|
||||
uint16_t argument_end; /**< number of arguments expected by the function */
|
||||
uint16_t register_end; /**< end position of the register group */
|
||||
uint16_t ident_end; /**< end position of the identifier group */
|
||||
uint16_t const_literal_end; /**< end position of the const literal group */
|
||||
uint16_t literal_end; /**< end position of the literal group */
|
||||
uint16_t padding; /**< an unused value */
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ecma_value_t realm_value; /**< realm value */
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
} cbc_uint16_arguments_t;
|
||||
|
||||
/**
|
||||
@@ -968,6 +964,69 @@ typedef enum
|
||||
*/
|
||||
#define CBC_EXTENDED_INFO_GET_LENGTH(extended_info) (extended_info)
|
||||
|
||||
/**
|
||||
* Shared script data.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CBC_SCRIPT_GENERIC, /**< script without user specific data */
|
||||
CBC_SCRIPT_USER_OBJECT, /**< script with a user object */
|
||||
CBC_SCRIPT_USER_VALUE, /**< script with a non-object user value */
|
||||
} cbc_script_type;
|
||||
|
||||
/**
|
||||
* Value for increasing or decreasing the script reference counter.
|
||||
*/
|
||||
#define CBC_SCRIPT_REF_ONE 0x4
|
||||
|
||||
/**
|
||||
* Get the type of a script.
|
||||
*/
|
||||
#define CBC_SCRIPT_GET_TYPE(script_p) ((script_p)->refs_and_type & (CBC_SCRIPT_REF_ONE - 1))
|
||||
|
||||
/**
|
||||
* Maximum value of script reference counter.
|
||||
*/
|
||||
#define CBC_SCRIPT_REF_MAX (UINT32_MAX - CBC_SCRIPT_REF_ONE + 1)
|
||||
|
||||
/**
|
||||
* Sets the type of a script using the user_value.
|
||||
*/
|
||||
#define CBC_SCRIPT_SET_TYPE(script_p, user_value, ref_count) \
|
||||
do \
|
||||
{ \
|
||||
(script_p)->refs_and_type = ((ref_count) | CBC_SCRIPT_GENERIC); \
|
||||
if ((user_value) != ECMA_VALUE_EMPTY) \
|
||||
{ \
|
||||
(script_p)->refs_and_type = (ecma_is_value_object (user_value) ? ((ref_count) | CBC_SCRIPT_USER_OBJECT) \
|
||||
: ((ref_count) | CBC_SCRIPT_USER_VALUE)); \
|
||||
} \
|
||||
} \
|
||||
while (false)
|
||||
|
||||
/**
|
||||
* Shared script data.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ecma_object_t *realm_p; /**< realm object */
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
uint32_t refs_and_type; /**< reference counter and type of the function */
|
||||
#if JERRY_RESOURCE_NAME
|
||||
ecma_value_t resource_name; /**< resource name */
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
} cbc_script_t;
|
||||
|
||||
/**
|
||||
* Script data with user value.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
cbc_script_t header; /**< script header */
|
||||
ecma_value_t user_value; /**< user value */
|
||||
} cbc_script_user_t;
|
||||
|
||||
#define CBC_OPCODE(arg1, arg2, arg3, arg4) arg1,
|
||||
|
||||
/**
|
||||
|
||||
@@ -563,9 +563,12 @@ typedef struct
|
||||
uint32_t global_status_flags; /**< global status flags */
|
||||
uint16_t stack_depth; /**< current stack depth */
|
||||
uint16_t stack_limit; /**< maximum stack depth */
|
||||
const jerry_parse_options_t *options_p; /**< parse options */
|
||||
const jerry_parse_options_t *options_p; /**< parse options */
|
||||
parser_saved_context_t *last_context_p; /**< last saved context */
|
||||
parser_stack_iterator_t last_statement; /**< last statement position */
|
||||
cbc_script_t *script_p; /**< current script */
|
||||
ecma_value_t script_value; /**< current script as value */
|
||||
ecma_value_t user_value; /**< current user value */
|
||||
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ecma_module_names_t *module_names_p; /**< import / export names that is being processed */
|
||||
@@ -630,10 +633,6 @@ typedef struct
|
||||
parser_line_counter_t last_breakpoint_line; /**< last line where breakpoint has been inserted */
|
||||
#endif /* JERRY_DEBUGGER */
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
ecma_value_t resource_name; /**< resource name */
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
|
||||
#if JERRY_LINE_INFO
|
||||
parser_line_info_data_t line_info; /**< line info data */
|
||||
parser_line_counter_t last_line_info_line; /**< last line where line info has been inserted */
|
||||
|
||||
@@ -62,17 +62,6 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */
|
||||
uint16_t ident_count = 0;
|
||||
uint16_t const_literal_count = 0;
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
/* Resource name will be stored as the last const literal. */
|
||||
if (JERRY_UNLIKELY (context_p->literal_count >= PARSER_MAXIMUM_NUMBER_OF_LITERALS))
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED);
|
||||
}
|
||||
|
||||
const_literal_count++;
|
||||
context_p->literal_count++;
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
|
||||
uint16_t ident_index;
|
||||
uint16_t const_literal_index;
|
||||
uint16_t literal_index;
|
||||
@@ -198,11 +187,6 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
}
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
/* Resource name will be stored as the last const literal. */
|
||||
const_literal_index++;
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
|
||||
JERRY_ASSERT (ident_index == context_p->register_count + ident_count);
|
||||
JERRY_ASSERT (const_literal_index == ident_index + const_literal_count);
|
||||
JERRY_ASSERT (literal_index <= context_p->register_count + context_p->literal_count);
|
||||
@@ -663,6 +647,14 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
parser_raise_error (context_p, PARSER_ERR_STACK_LIMIT_REACHED);
|
||||
}
|
||||
|
||||
if (JERRY_UNLIKELY (context_p->script_p->refs_and_type >= CBC_SCRIPT_REF_MAX))
|
||||
{
|
||||
/* This is probably never happens in practice. */
|
||||
jerry_fatal (ERR_REF_COUNT_LIMIT);
|
||||
}
|
||||
|
||||
context_p->script_p->refs_and_type += CBC_SCRIPT_REF_ONE;
|
||||
|
||||
JERRY_ASSERT (context_p->literal_count <= PARSER_MAXIMUM_NUMBER_OF_LITERALS);
|
||||
|
||||
#if JERRY_DEBUGGER
|
||||
@@ -963,14 +955,12 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p;
|
||||
|
||||
args_p->stack_limit = context_p->stack_limit;
|
||||
args_p->script_value = context_p->script_value;
|
||||
args_p->argument_end = context_p->argument_count;
|
||||
args_p->register_end = context_p->register_count;
|
||||
args_p->ident_end = ident_end;
|
||||
args_p->const_literal_end = const_literal_end;
|
||||
args_p->literal_end = context_p->literal_count;
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (args_p->realm_value, JERRY_CONTEXT (global_object_p));
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
|
||||
compiled_code_p->status_flags |= CBC_CODE_FLAGS_UINT16_ARGUMENTS;
|
||||
byte_code_p += sizeof (cbc_uint16_arguments_t);
|
||||
@@ -981,13 +971,11 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
|
||||
args_p->stack_limit = (uint8_t) context_p->stack_limit;
|
||||
args_p->argument_end = (uint8_t) context_p->argument_count;
|
||||
args_p->script_value = context_p->script_value;
|
||||
args_p->register_end = (uint8_t) context_p->register_count;
|
||||
args_p->ident_end = (uint8_t) ident_end;
|
||||
args_p->const_literal_end = (uint8_t) const_literal_end;
|
||||
args_p->literal_end = (uint8_t) context_p->literal_count;
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (args_p->realm_value, JERRY_CONTEXT (global_object_p));
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
|
||||
byte_code_p += sizeof (cbc_uint8_arguments_t);
|
||||
}
|
||||
@@ -1088,10 +1076,6 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
|
||||
parser_init_literal_pool (context_p, literal_pool_p);
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
literal_pool_p[const_literal_end - 1] = context_p->resource_name;
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
|
||||
page_p = context_p->byte_code.first_p;
|
||||
offset = 0;
|
||||
real_offset = 0;
|
||||
@@ -1828,14 +1812,55 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
context.token.flags = 0;
|
||||
lexer_init_line_info (&context);
|
||||
|
||||
context.user_value = ECMA_VALUE_EMPTY;
|
||||
|
||||
if ((context.global_status_flags & ECMA_PARSE_EVAL)
|
||||
&& JERRY_CONTEXT (vm_top_context_p) != NULL)
|
||||
{
|
||||
const ecma_compiled_code_t *bytecode_header_p = JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p;
|
||||
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
if (JERRY_LIKELY (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_STATIC_FUNCTION)))
|
||||
{
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
ecma_value_t parent_script_value = ((cbc_uint8_arguments_t *) bytecode_header_p)->script_value;;
|
||||
cbc_script_t *parent_script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, parent_script_value);
|
||||
|
||||
if (CBC_SCRIPT_GET_TYPE (parent_script_p) != CBC_SCRIPT_GENERIC)
|
||||
{
|
||||
context.user_value = ((cbc_script_user_t *) parent_script_p)->user_value;
|
||||
}
|
||||
#if JERRY_SNAPSHOT_EXEC
|
||||
}
|
||||
#endif /* JERRY_SNAPSHOT_EXEC */
|
||||
}
|
||||
else if (context.options_p != NULL
|
||||
&& (context.options_p->options & JERRY_PARSE_HAS_USER_VALUE))
|
||||
{
|
||||
context.user_value = context.options_p->user_value;
|
||||
}
|
||||
|
||||
uint32_t script_size = (context.user_value != ECMA_VALUE_EMPTY ? sizeof (cbc_script_user_t)
|
||||
: sizeof (cbc_script_t));
|
||||
context.script_p = jmem_heap_alloc_block_null_on_error (script_size);
|
||||
|
||||
if (JERRY_UNLIKELY (context.script_p == NULL))
|
||||
{
|
||||
/* It is unlikely that memory can be allocated in an out-of-memory
|
||||
* situation. However, a simple value can still be thrown. */
|
||||
jcontext_raise_exception (ECMA_VALUE_NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBC_SCRIPT_SET_TYPE (context.script_p, context.user_value, CBC_SCRIPT_REF_ONE);
|
||||
|
||||
#if JERRY_BUILTIN_REALMS
|
||||
context.script_p->realm_p = (ecma_object_t *) JERRY_CONTEXT (global_object_p);
|
||||
#endif /* JERRY_BUILTIN_REALMS */
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
if (context.global_status_flags & ECMA_PARSE_EVAL)
|
||||
{
|
||||
resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_EVAL);
|
||||
}
|
||||
|
||||
if (context.options_p != NULL
|
||||
&& (context.options_p->options & JERRY_PARSE_HAS_RESOURCE)
|
||||
&& context.options_p->resource_name_length > 0)
|
||||
@@ -1843,9 +1868,15 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
resource_name = ecma_find_or_create_literal_string (context.options_p->resource_name_p,
|
||||
(lit_utf8_size_t) context.options_p->resource_name_length);
|
||||
}
|
||||
else if (context.global_status_flags & ECMA_PARSE_EVAL)
|
||||
{
|
||||
resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_EVAL);
|
||||
}
|
||||
|
||||
context.resource_name = resource_name;
|
||||
#endif /* !JERRY_RESOURCE_NAME */
|
||||
context.script_p->resource_name = resource_name;
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (context.script_value, context.script_p);
|
||||
|
||||
scanner_info_t scanner_info_end;
|
||||
scanner_info_end.next_p = NULL;
|
||||
@@ -2030,6 +2061,13 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
|
||||
JERRY_ASSERT (arg_list_p != NULL || !(context.status_flags & PARSER_ARGUMENTS_NEEDED));
|
||||
|
||||
context.script_p->refs_and_type -= CBC_SCRIPT_REF_ONE;
|
||||
|
||||
if (context.user_value != ECMA_VALUE_EMPTY)
|
||||
{
|
||||
((cbc_script_user_t *) context.script_p)->user_value = ecma_copy_value_if_not_object (context.user_value);
|
||||
}
|
||||
|
||||
#if JERRY_PARSER_DUMP_BYTE_CODE
|
||||
if (context.is_show_opcodes)
|
||||
{
|
||||
@@ -2061,6 +2099,9 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
compiled_code_p = NULL;
|
||||
parser_free_literals (&context.literal_pool);
|
||||
parser_cbc_stream_free (&context.byte_code);
|
||||
|
||||
JERRY_ASSERT (context.script_p->refs_and_type >= CBC_SCRIPT_REF_ONE);
|
||||
jmem_heap_free_block (context.script_p, script_size);
|
||||
}
|
||||
PARSER_TRY_END
|
||||
|
||||
@@ -2130,7 +2171,7 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
ecma_raise_standard_error_with_format (JERRY_ERROR_SYNTAX,
|
||||
"% [%:%:%]",
|
||||
err_str_val,
|
||||
context.resource_name,
|
||||
resource_name,
|
||||
line_str_val,
|
||||
col_str_val);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ typedef enum
|
||||
PARSER_ERR_INVALID_NUMBER, /**< invalid number literal */
|
||||
PARSER_ERR_MISSING_EXPONENT, /**< missing exponent */
|
||||
PARSER_ERR_IDENTIFIER_AFTER_NUMBER, /**< identifier start after number */
|
||||
PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER, /**< invalid use of underscore in number */
|
||||
PARSER_ERR_INVALID_UNDERSCORE_IN_NUMBER, /**< invalid use of underscore in number */
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
PARSER_ERR_INVALID_BIGINT, /**< number is not a valid BigInt */
|
||||
#endif /* JERRY_BUILTIN_BIGINT */
|
||||
|
||||
Reference in New Issue
Block a user