Implement eval check for ECMAScript code (#4788)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-10-15 22:25:20 +02:00
committed by GitHub
parent fe3a5c08b2
commit b52c114423
7 changed files with 196 additions and 2 deletions
+22
View File
@@ -5565,6 +5565,28 @@ jerry_get_user_value (const jerry_value_t value) /**< jerry api value */
return ecma_copy_value (CBC_SCRIPT_GET_USER_VALUE (script_p));
} /* jerry_get_user_value */
/**
* Checks whether an ECMAScript code is compiled by eval
* like (eval, new Function, jerry_eval, etc.) command.
*
* @return true, if code is compiled by eval like command
* false, otherwise
*/
bool
jerry_is_eval_code (const jerry_value_t value) /**< jerry api value */
{
ecma_value_t script_value = ecma_script_get_from_value (value);
if (script_value == JMEM_CP_NULL)
{
return false;
}
const cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);
return (script_p->refs_and_type & CBC_SCRIPT_IS_EVAL_CODE) != 0;
} /* jerry_is_eval_code */
/**
* Returns a newly created source info structure corresponding to the passed script/module/function.
*
+1
View File
@@ -364,6 +364,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);
bool jerry_is_eval_code (const jerry_value_t value);
jerry_source_info_t *jerry_get_source_info (const jerry_value_t value);
void jerry_free_source_info (jerry_source_info_t *source_info_p);
+2 -1
View File
@@ -1004,12 +1004,13 @@ typedef enum
CBC_SCRIPT_USER_VALUE_IS_OBJECT = (1 << 1), /**< user value is object */
CBC_SCRIPT_HAS_FUNCTION_ARGUMENTS = (1 << 2), /**< script is a function with arguments source code */
CBC_SCRIPT_HAS_IMPORT_META = (1 << 3), /**< script is a module with import.meta object */
CBC_SCRIPT_IS_EVAL_CODE = (1 << 4), /**< script is compiled by eval like (eval, new Function, etc.) expression */
} cbc_script_type;
/**
* Value for increasing or decreasing the script reference counter.
*/
#define CBC_SCRIPT_REF_ONE 0x10
#define CBC_SCRIPT_REF_ONE 0x20
/**
* Maximum value of script reference counter.
+5
View File
@@ -2108,6 +2108,11 @@ parser_parse_source (void *source_p, /**< source code */
CBC_SCRIPT_SET_TYPE (context.script_p, context.user_value, CBC_SCRIPT_REF_ONE);
if (context.global_status_flags & (ECMA_PARSE_EVAL | ECMA_PARSE_HAS_ARGUMENT_LIST_VALUE))
{
context.script_p->refs_and_type |= CBC_SCRIPT_IS_EVAL_CODE;
}
#if JERRY_BUILTIN_REALMS
context.script_p->realm_p = (ecma_object_t *) JERRY_CONTEXT (global_object_p);
#endif /* JERRY_BUILTIN_REALMS */