diff --git a/jerry-core/ecma/operations/ecma-eval.cpp b/jerry-core/ecma/operations/ecma-eval.cpp index 630c64296..d48c2800d 100644 --- a/jerry-core/ecma/operations/ecma-eval.cpp +++ b/jerry-core/ecma/operations/ecma-eval.cpp @@ -110,63 +110,12 @@ ecma_op_eval_chars_buffer (const jerry_api_char_t *code_p, /**< code characters { JERRY_ASSERT (parse_status == JSP_STATUS_OK); - vm_instr_counter_t first_instr_index = 0u; - bool is_strict_prologue = false; - opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (instrs_p, - first_instr_index++); - if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT) - { - is_strict_prologue = true; - } - - bool is_strict = (is_strict_call || is_strict_prologue); - - ecma_value_t this_binding; - ecma_object_t *lex_env_p; - - /* ECMA-262 v5, 10.4.2 */ - if (is_direct) - { - this_binding = vm_get_this_binding (); - lex_env_p = vm_get_lex_env (); - } - else - { - this_binding = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL)); - lex_env_p = ecma_get_global_environment (); - } - - if (is_strict) - { - ecma_object_t *strict_lex_env_p = ecma_create_decl_lex_env (lex_env_p); - ecma_deref_object (lex_env_p); - - lex_env_p = strict_lex_env_p; - } - - completion = vm_run_from_pos (instrs_p, - first_instr_index, - this_binding, - lex_env_p, - is_strict, - true); - - if (ecma_is_completion_value_return (completion)) - { - completion = ecma_make_normal_completion_value (ecma_get_completion_value_value (completion)); - } - else - { - JERRY_ASSERT (ecma_is_completion_value_throw (completion)); - } + completion = vm_run_eval (instrs_p, is_direct); if (!code_contains_functions) { serializer_remove_instructions (instrs_p); } - - ecma_deref_object (lex_env_p); - ecma_free_value (this_binding, true); } return completion; diff --git a/jerry-core/vm/vm.cpp b/jerry-core/vm/vm.cpp index 9d3bb270b..58b3a0914 100644 --- a/jerry-core/vm/vm.cpp +++ b/jerry-core/vm/vm.cpp @@ -437,6 +437,65 @@ vm_run_global (void) return ret_code; } /* vm_run_global */ +/** + * Run specified eval-mode bytecode + * + * @return completion value + */ +ecma_completion_value_t +vm_run_eval (const vm_instr_t *instrs_p, /**< instructions array */ + bool is_direct) /**< is eval called directly? */ +{ + vm_instr_counter_t first_instr_index = 0u; + opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (instrs_p, + first_instr_index++); + bool is_strict = ((scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT) != 0); + + ecma_value_t this_binding; + ecma_object_t *lex_env_p; + + /* ECMA-262 v5, 10.4.2 */ + if (is_direct) + { + this_binding = vm_get_this_binding (); + lex_env_p = vm_get_lex_env (); + } + else + { + this_binding = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL)); + lex_env_p = ecma_get_global_environment (); + } + + if (is_strict) + { + ecma_object_t *strict_lex_env_p = ecma_create_decl_lex_env (lex_env_p); + ecma_deref_object (lex_env_p); + + lex_env_p = strict_lex_env_p; + } + + ecma_completion_value_t completion = vm_run_from_pos (instrs_p, + first_instr_index, + this_binding, + lex_env_p, + is_strict, + true); + + if (ecma_is_completion_value_return (completion)) + { + completion = ecma_make_normal_completion_value (ecma_get_completion_value_value (completion)); + } + else + { + JERRY_ASSERT (ecma_is_completion_value_throw (completion)); + } + + ecma_deref_object (lex_env_p); + ecma_free_value (this_binding, true); + + return completion; +} /* vm_run_eval */ + /** * Run interpreter loop using specified context * diff --git a/jerry-core/vm/vm.h b/jerry-core/vm/vm.h index 497263b22..c31dc4202 100644 --- a/jerry-core/vm/vm.h +++ b/jerry-core/vm/vm.h @@ -23,6 +23,8 @@ extern void vm_init (const vm_instr_t* program_p, bool dump_mem_stats); extern void vm_finalize (void); extern jerry_completion_code_t vm_run_global (void); +extern ecma_completion_value_t vm_run_eval (const vm_instr_t *instrs_p, + bool is_direct); extern ecma_completion_value_t vm_loop (vm_frame_ctx_t *frame_ctx_p, vm_run_scope_t *run_scope_p); extern ecma_completion_value_t vm_run_from_pos (const vm_instr_t *instrs_p, vm_instr_counter_t start_pos,