Skip to content

Commit 517d2ed

Browse files
Introducing interpreter context flag, indicating if there is call of 'Direct call to eval' form in process, and interfaces for accessing the flag and 'strict mode' flag.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
1 parent 4f26de3 commit 517d2ed

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

jerry-core/vm/opcodes.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
657657

658658
opcode_call_flags_t call_flags = OPCODE_CALL_FLAGS__EMPTY;
659659

660+
JERRY_ASSERT (!int_data->is_call_in_direct_eval_form);
661+
660662
opcode_t next_opcode = vm_get_opcode (int_data->opcodes_p, int_data->pos);
661663
if (next_opcode.op_idx == __op__idx_meta
662664
&& next_opcode.data.meta.type == OPCODE_META_TYPE_CALL_SITE_INFO)
@@ -667,6 +669,8 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
667669
{
668670
this_arg_var_idx = next_opcode.data.meta.data_2;
669671
JERRY_ASSERT (is_reg_variable (int_data, this_arg_var_idx));
672+
673+
JERRY_ASSERT ((call_flags & OPCODE_CALL_FLAGS_DIRECT_CALL_TO_EVAL_FORM) == 0);
670674
}
671675

672676
int_data->pos++;
@@ -704,6 +708,11 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
704708
}
705709
else
706710
{
711+
if (call_flags & OPCODE_CALL_FLAGS_DIRECT_CALL_TO_EVAL_FORM)
712+
{
713+
int_data->is_call_in_direct_eval_form = true;
714+
}
715+
707716
ecma_object_t *func_obj_p = ecma_get_object_from_value (func_value);
708717

709718
ECMA_TRY_CATCH (call_ret_value,
@@ -719,6 +728,15 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
719728

720729
ECMA_FINALIZE (call_ret_value);
721730

731+
if (call_flags & OPCODE_CALL_FLAGS_DIRECT_CALL_TO_EVAL_FORM)
732+
{
733+
JERRY_ASSERT (int_data->is_call_in_direct_eval_form);
734+
int_data->is_call_in_direct_eval_form = false;
735+
}
736+
else
737+
{
738+
JERRY_ASSERT (!int_data->is_call_in_direct_eval_form);
739+
}
722740
}
723741

724742
ecma_free_completion_value (get_this_completion_value);

jerry-core/vm/opcodes.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ typedef enum : idx_t
8383
OPCODE_CALL_FLAGS_DIRECT_CALL_TO_EVAL_FORM = (1u << 1) /**< flag, indicating that call is performed
8484
* in form 'eval (...)', i.e. through 'eval' string
8585
* without object base (i.e. with lexical environment
86-
* as base), so it can be a direct call to eval */
86+
* as base), so it can be a direct call to eval
87+
* See also: ECMA-262 v5, 15.1.2.1.1
88+
*/
8789
} opcode_call_flags_t;
8890

8991
/**
@@ -115,6 +117,8 @@ typedef struct
115117
ecma_object_t *lex_env_p; /**< current lexical environment */
116118
bool is_strict; /**< is current code execution mode strict? */
117119
bool is_eval_code; /**< is current code executed with eval */
120+
bool is_call_in_direct_eval_form; /** flag, indicating if there is call of 'Direct call to eval' form in
121+
* process (see also: OPCODE_CALL_FLAGS_DIRECT_CALL_TO_EVAL_FORM) */
118122
idx_t min_reg_num; /**< minimum idx used for register identification */
119123
idx_t max_reg_num; /**< maximum idx used for register identification */
120124
ecma_number_t* tmp_num_p; /**< an allocated number (to reduce temporary allocations) */

jerry-core/vm/vm.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ vm_run_from_pos (const opcode_t *opcodes_p, /**< byte-code array */
545545
int_data.lex_env_p = lex_env_p;
546546
int_data.is_strict = is_strict;
547547
int_data.is_eval_code = is_eval_code;
548+
int_data.is_call_in_direct_eval_form = false;
548549
int_data.min_reg_num = min_reg_num;
549550
int_data.max_reg_num = max_reg_num;
550551
int_data.tmp_num_p = ecma_alloc_number ();
@@ -604,6 +605,49 @@ vm_get_scope_flags (const opcode_t *opcodes_p, /**< byte-code array */
604605
return (opcode_scope_code_flags_t) flags_opcode.data.meta.data_1;
605606
} /* vm_get_scope_flags */
606607

608+
/**
609+
* Check whether currently executed code is strict mode code
610+
*
611+
* @return true - current code is executed in strict mode,
612+
* false - otherwise.
613+
*/
614+
bool
615+
vm_is_strict_mode (void)
616+
{
617+
JERRY_ASSERT (vm_top_context_p != NULL);
618+
619+
return vm_top_context_p->is_strict;
620+
} /* vm_is_strict_mode */
621+
622+
/**
623+
* Check whether currently performed call (on top of call-stack) is performed in form,
624+
* meeting conditions of 'Direct Call to Eval' (see also: ECMA-262 v5, 15.1.2.1.1)
625+
*
626+
* Warning:
627+
* the function should only be called from implementation
628+
* of built-in 'eval' routine of Global object
629+
*
630+
* @return true - currently performed call is performed through 'eval' identifier,
631+
* without 'this' argument,
632+
* false - otherwise.
633+
*/
634+
bool
635+
vm_is_direct_eval_form_call (void)
636+
{
637+
if (vm_top_context_p != NULL)
638+
{
639+
return vm_top_context_p->is_call_in_direct_eval_form;
640+
}
641+
else
642+
{
643+
/*
644+
* There is no any interpreter context, so call is performed not from a script.
645+
* This implies that the call is indirect.
646+
*/
647+
return false;
648+
}
649+
} /* vm_is_direct_eval_form_call */
650+
607651
/**
608652
* Get this binding of current execution context
609653
*

jerry-core/vm/vm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ extern ecma_completion_value_t vm_run_from_pos (const opcode_t *opcodes_p,
3434
extern opcode_t vm_get_opcode (const opcode_t*, opcode_counter_t counter);
3535
extern opcode_scope_code_flags_t vm_get_scope_flags (const opcode_t*, opcode_counter_t counter);
3636

37+
extern bool vm_is_strict_mode (void);
38+
extern bool vm_is_direct_eval_form_call (void);
39+
3740
extern ecma_value_t vm_get_this_binding (void);
3841
extern ecma_object_t* vm_get_lex_env (void);
3942

0 commit comments

Comments
 (0)