Skip to content

Commit 0644c5c

Browse files
Adding interpreter invocation to ecma_op_eval_chars_buffer.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
1 parent 8b4f121 commit 0644c5c

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

jerry-core/ecma/operations/ecma-eval.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,16 @@ ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffe
9292
serializer_print_opcodes ();
9393
parser_free ();
9494

95-
// FIXME:
95+
opcode_counter_t first_opcode_index = 0u;
9696
bool is_strict_prologue = false;
97-
(void) is_strict_prologue;
97+
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (opcodes_p,
98+
first_opcode_index++);
99+
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
100+
{
101+
is_strict_prologue = true;
102+
}
103+
104+
bool is_strict = (is_strict_prologue || (is_direct && is_called_from_strict_mode_code));
98105

99106
if (!is_syntax_correct)
100107
{
@@ -117,19 +124,20 @@ ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffe
117124
lex_env_p = ecma_get_global_environment ();
118125
}
119126

120-
if (is_strict_prologue
121-
|| (is_direct && is_called_from_strict_mode_code))
127+
if (is_strict)
122128
{
123129
ecma_object_t *strict_lex_env_p = ecma_create_decl_lex_env (lex_env_p);
124130
ecma_deref_object (lex_env_p);
125131

126132
lex_env_p = strict_lex_env_p;
127133
}
128134

129-
// FIXME: Call interpreter
130-
(void) opcodes_p;
131-
completion = ecma_make_return_completion_value (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
132-
JERRY_UNIMPLEMENTED ("eval operation is not implemented");
135+
completion = vm_run_from_pos (opcodes_p,
136+
first_opcode_index,
137+
this_binding,
138+
lex_env_p,
139+
is_strict,
140+
true);
133141

134142
if (ecma_is_completion_value_return (completion))
135143
{

tests/unit/test_api.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,26 @@ main (void)
438438
jerry_api_release_value (&val_t);
439439
jerry_api_release_value (&res);
440440

441+
const char *eval_code_src_p = "(function () { return 123; })";
442+
jerry_completion_code_t status = jerry_api_eval (eval_code_src_p,
443+
strlen (eval_code_src_p),
444+
false,
445+
true,
446+
&val_t);
447+
assert (status == JERRY_COMPLETION_CODE_OK);
448+
assert (val_t.type == JERRY_API_DATA_TYPE_OBJECT);
449+
assert (jerry_api_is_function (val_t.v_object));
450+
451+
is_ok = jerry_api_call_function (val_t.v_object,
452+
NULL,
453+
&res,
454+
NULL, 0);
455+
assert (is_ok);
456+
assert (res.type == JERRY_API_DATA_TYPE_FLOAT64
457+
&& res.v_float64 == 123.0);
458+
jerry_api_release_value (&res);
459+
460+
jerry_api_release_value (&val_t);
441461

442462
// cleanup.
443463
jerry_api_release_object (global_obj_p);

0 commit comments

Comments
 (0)