Improve the evaluate requests (#2583)
Currently it evaluates the given expression in the context of the top most stack frame. The expression should access to any variables and arguments that are in the scope chain. Implement the eval_at request with the level of the scope chain as a further argument. JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
This commit is contained in:
@@ -40,7 +40,7 @@ typedef struct
|
||||
*/
|
||||
JERRY_STATIC_ASSERT (JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT == 32
|
||||
&& JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT == 21
|
||||
&& JERRY_DEBUGGER_VERSION == 7,
|
||||
&& JERRY_DEBUGGER_VERSION == 8,
|
||||
debugger_version_correlates_to_message_type_count);
|
||||
|
||||
/**
|
||||
@@ -529,12 +529,17 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s
|
||||
JERRY_ASSERT (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_VM_IGNORE));
|
||||
|
||||
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_IGNORE);
|
||||
ecma_value_t result = ecma_op_eval_chars_buffer (eval_string_p + 1, eval_string_size - 1, ECMA_PARSE_DIRECT_EVAL);
|
||||
|
||||
uint32_t chain_index;
|
||||
memcpy (&chain_index, eval_string_p, sizeof (uint32_t));
|
||||
uint32_t parse_opts = ECMA_PARSE_DIRECT_EVAL | (chain_index << ECMA_PARSE_CHAIN_INDEX_SHIFT);
|
||||
|
||||
ecma_value_t result = ecma_op_eval_chars_buffer (eval_string_p + 5, eval_string_size - 5, parse_opts);
|
||||
JERRY_DEBUGGER_CLEAR_FLAGS (JERRY_DEBUGGER_VM_IGNORE);
|
||||
|
||||
if (!ECMA_IS_VALUE_ERROR (result))
|
||||
{
|
||||
if (eval_string_p[0] != JERRY_DEBUGGER_EVAL_EVAL)
|
||||
if (eval_string_p[4] != JERRY_DEBUGGER_EVAL_EVAL)
|
||||
{
|
||||
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_EXCEPTION_THROWN);
|
||||
JERRY_CONTEXT (error_value) = result;
|
||||
@@ -543,7 +548,7 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s
|
||||
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_STOP);
|
||||
JERRY_CONTEXT (debugger_stop_context) = NULL;
|
||||
|
||||
if (eval_string_p[0] == JERRY_DEBUGGER_EVAL_THROW)
|
||||
if (eval_string_p[4] == JERRY_DEBUGGER_EVAL_THROW)
|
||||
{
|
||||
JERRY_CONTEXT (status_flags) |= ECMA_STATUS_EXCEPTION;
|
||||
}
|
||||
@@ -918,7 +923,7 @@ jerry_debugger_process_message (const uint8_t *recv_buffer_p, /**< pointer to th
|
||||
|
||||
case JERRY_DEBUGGER_EVAL:
|
||||
{
|
||||
if (message_size < sizeof (jerry_debugger_receive_eval_first_t) + 1)
|
||||
if (message_size < sizeof (jerry_debugger_receive_eval_first_t) + 5)
|
||||
{
|
||||
JERRY_ERROR_MSG ("Invalid message size\n");
|
||||
jerry_debugger_transport_close ();
|
||||
|
||||
@@ -80,10 +80,18 @@ typedef enum
|
||||
ECMA_TYPE___MAX = ECMA_TYPE_ERROR /** highest value for ecma types */
|
||||
} ecma_type_t;
|
||||
|
||||
#ifdef JERRY_DEBUGGER
|
||||
/**
|
||||
* Shift for scope chain index part in ecma_parse_opts
|
||||
*/
|
||||
#define ECMA_PARSE_CHAIN_INDEX_SHIFT 16
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Option flags for script parsing.
|
||||
* Note:
|
||||
* The enum members must be kept in sync with parser_general_flags_t
|
||||
* The last 16 bits are reserved for scope chain index
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ extern "C"
|
||||
/**
|
||||
* JerryScript debugger protocol version.
|
||||
*/
|
||||
#define JERRY_DEBUGGER_VERSION (7)
|
||||
#define JERRY_DEBUGGER_VERSION (8)
|
||||
|
||||
/**
|
||||
* Types for the client source wait and run method.
|
||||
|
||||
@@ -252,6 +252,26 @@ vm_run_eval (ecma_compiled_code_t *bytecode_data_p, /**< byte-code data */
|
||||
{
|
||||
this_binding = ecma_copy_value (JERRY_CONTEXT (vm_top_context_p)->this_binding);
|
||||
lex_env_p = JERRY_CONTEXT (vm_top_context_p)->lex_env_p;
|
||||
|
||||
#ifdef JERRY_DEBUGGER
|
||||
uint32_t chain_index = parse_opts >> ECMA_PARSE_CHAIN_INDEX_SHIFT;
|
||||
|
||||
while (chain_index != 0)
|
||||
{
|
||||
lex_env_p = ecma_get_lex_env_outer_reference (lex_env_p);
|
||||
|
||||
if (JERRY_UNLIKELY (lex_env_p == NULL))
|
||||
{
|
||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid scope chain index for eval"));
|
||||
}
|
||||
|
||||
if ((ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND)
|
||||
|| (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE))
|
||||
{
|
||||
chain_index--;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user