Skip to content

Commit f9927b8

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 50ef3eb commit f9927b8

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
@@ -656,6 +656,8 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
656656

657657
opcode_call_flags_t call_flags = OPCODE_CALL_FLAGS__EMPTY;
658658

659+
JERRY_ASSERT (!int_data->is_call_in_direct_eval_form);
660+
659661
opcode_t next_opcode = vm_get_opcode (int_data->opcodes_p, int_data->pos);
660662
if (next_opcode.op_idx == __op__idx_meta
661663
&& next_opcode.data.meta.type == OPCODE_META_TYPE_CALL_SITE_INFO)
@@ -666,6 +668,8 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
666668
{
667669
this_arg_var_idx = next_opcode.data.meta.data_2;
668670
JERRY_ASSERT (is_reg_variable (int_data, this_arg_var_idx));
671+
672+
JERRY_ASSERT ((call_flags & OPCODE_CALL_FLAGS_DIRECT_CALL_TO_EVAL_FORM) == 0);
669673
}
670674

671675
int_data->pos++;
@@ -703,6 +707,11 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
703707
}
704708
else
705709
{
710+
if (call_flags & OPCODE_CALL_FLAGS_DIRECT_CALL_TO_EVAL_FORM)
711+
{
712+
int_data->is_call_in_direct_eval_form = true;
713+
}
714+
706715
ecma_object_t *func_obj_p = ecma_get_object_from_value (func_value);
707716

708717
ECMA_TRY_CATCH (call_ret_value,
@@ -718,6 +727,15 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
718727

719728
ECMA_FINALIZE (call_ret_value);
720729

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

723741
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
@@ -544,6 +544,7 @@ vm_run_from_pos (const opcode_t *opcodes_p, /**< byte-code array */
544544
int_data.lex_env_p = lex_env_p;
545545
int_data.is_strict = is_strict;
546546
int_data.is_eval_code = is_eval_code;
547+
int_data.is_call_in_direct_eval_form = false;
547548
int_data.min_reg_num = min_reg_num;
548549
int_data.max_reg_num = max_reg_num;
549550
int_data.tmp_num_p = ecma_alloc_number ();
@@ -603,6 +604,49 @@ vm_get_scope_flags (const opcode_t *opcodes_p, /**< byte-code array */
603604
return (opcode_scope_code_flags_t) flags_opcode.data.meta.data_1;
604605
} /* vm_get_scope_flags */
605606

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

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)