diff --git a/jerry-core/ecma/operations/ecma-eval.cpp b/jerry-core/ecma/operations/ecma-eval.cpp index 06c41f11a..05d8d6fa4 100644 --- a/jerry-core/ecma/operations/ecma-eval.cpp +++ b/jerry-core/ecma/operations/ecma-eval.cpp @@ -31,9 +31,10 @@ */ /** - * eval + * Perform 'eval' with code stored in ecma-string * * See also: + * ecma_op_eval_chars_buffer * ECMA-262 v5, 15.1.2.1 * * @return completion value @@ -43,7 +44,7 @@ ecma_op_eval (ecma_string_t *code_p, /**< code string */ bool is_direct, /**< is eval called directly (ECMA-262 v5, 15.1.2.1.1) */ bool is_called_from_strict_mode_code) /**< is eval is called from strict mode code */ { - ecma_completion_value_t completion; + ecma_completion_value_t ret_value; int32_t chars_num = ecma_string_get_length (code_p); MEM_DEFINE_LOCAL_ARRAY (code_zt_buffer_p, @@ -56,8 +57,37 @@ ecma_op_eval (ecma_string_t *code_p, /**< code string */ buf_size); JERRY_ASSERT (buffer_size_req == buf_size); + ret_value = ecma_op_eval_chars_buffer (code_zt_buffer_p, + (size_t) buf_size, + is_direct, + is_called_from_strict_mode_code); + + MEM_FINALIZE_LOCAL_ARRAY (code_zt_buffer_p); + + return ret_value; +} /* ecma_op_eval */ + +/** + * Perform 'eval' with code stored in continuous character buffer + * + * See also: + * ecma_op_eval + * ECMA-262 v5, 15.1.2.1 + * + * @return completion value + */ +ecma_completion_value_t +ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffer */ + size_t code_buffer_size, /**< size of the buffer */ + bool is_direct, /**< is eval called directly (ECMA-262 v5, 15.1.2.1.1) */ + bool is_called_from_strict_mode_code) /**< is eval is called from strict mode code */ +{ + JERRY_ASSERT (code_p != NULL); + + ecma_completion_value_t completion; + parser_init (); - bool is_syntax_correct = parser_parse_eval ((const char *) code_p, (size_t) buf_size); + bool is_syntax_correct = parser_parse_eval ((const char *) code_p, code_buffer_size); const opcode_t* opcodes_p = (const opcode_t*) serializer_get_bytecode (); serializer_print_opcodes (); parser_free (); @@ -115,11 +145,8 @@ ecma_op_eval (ecma_string_t *code_p, /**< code string */ ecma_free_value (this_binding, true); } - - MEM_FINALIZE_LOCAL_ARRAY (code_zt_buffer_p); - return completion; -} /* ecma_op_eval */ +} /* ecma_op_eval_chars_buffer */ /** * @} diff --git a/jerry-core/ecma/operations/ecma-eval.h b/jerry-core/ecma/operations/ecma-eval.h index 31ac125c1..f1fdd3a66 100644 --- a/jerry-core/ecma/operations/ecma-eval.h +++ b/jerry-core/ecma/operations/ecma-eval.h @@ -29,6 +29,12 @@ ecma_op_eval (ecma_string_t *code_p, bool is_direct, bool is_called_from_strict_mode_code); +extern ecma_completion_value_t +ecma_op_eval_chars_buffer (const ecma_char_t *code_p, + size_t code_buffer_size, + bool is_direct, + bool is_called_from_strict_mode_code); + /** * @} * @} diff --git a/jerry-core/jerry.cpp b/jerry-core/jerry.cpp index 4b47e1c9f..0cc2e37ca 100644 --- a/jerry-core/jerry.cpp +++ b/jerry-core/jerry.cpp @@ -1071,12 +1071,12 @@ jerry_api_eval (const char *source_p, /**< source code */ { jerry_assert_api_available (); - ecma_string_t *code_p = ecma_new_ecma_string ((const ecma_char_t*) source_p); - (void) source_size; - jerry_completion_code_t status; - ecma_completion_value_t completion = ecma_op_eval (code_p, is_direct, is_strict); + ecma_completion_value_t completion = ecma_op_eval_chars_buffer ((const ecma_char_t*) source_p, + source_size, + is_direct, + is_strict); if (ecma_is_completion_value_normal (completion)) { @@ -1108,7 +1108,7 @@ jerry_api_eval (const char *source_p, /**< source code */ } } - ecma_deref_ecma_string (code_p); + ecma_free_completion_value (completion); return status; } /* jerry_api_eval */