Skip to content

Commit 3953fee

Browse files
dbatyaifbmrk
authored andcommitted
Correctly propagate errors when parsing modules (#2907)
Fixes #2896. Co-authored-by: Marko Fabo <[email protected]> JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]
1 parent 351acdf commit 3953fee

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

jerry-core/ecma/base/ecma-module.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ ecma_module_evaluate (ecma_module_t *module_p) /**< module */
545545
JERRY_CONTEXT (module_top_context_p) = module_p->context_p;
546546

547547
ecma_value_t ret_value;
548-
ret_value = vm_run_module (ecma_op_function_get_compiled_code ((ecma_extended_object_t *) module_p->compiled_code_p),
548+
ret_value = vm_run_module (module_p->compiled_code_p,
549549
module_p->scope_p);
550550

551551
if (!ECMA_IS_VALUE_ERROR (ret_value))
@@ -556,7 +556,7 @@ ecma_module_evaluate (ecma_module_t *module_p) /**< module */
556556

557557
JERRY_CONTEXT (module_top_context_p) = module_p->context_p->parent_p;
558558

559-
ecma_deref_object (module_p->compiled_code_p);
559+
ecma_bytecode_deref (module_p->compiled_code_p);
560560
module_p->state = ECMA_MODULE_STATE_EVALUATED;
561561

562562
return ret_value;
@@ -695,11 +695,13 @@ ecma_module_parse (ecma_module_t *module_p) /**< module */
695695
module_p->context_p->parent_p = JERRY_CONTEXT (module_top_context_p);
696696
JERRY_CONTEXT (module_top_context_p) = module_p->context_p;
697697

698-
ecma_value_t ret_value = jerry_parse ((jerry_char_t *) script_path_p,
699-
script_path_size,
700-
(jerry_char_t *) source_p,
701-
source_size,
702-
JERRY_PARSE_NO_OPTS);
698+
ecma_compiled_code_t *bytecode_data_p;
699+
ecma_value_t ret_value = parser_parse_script (NULL,
700+
0,
701+
(jerry_char_t *) source_p,
702+
source_size,
703+
JERRY_PARSE_NO_OPTS,
704+
&bytecode_data_p);
703705

704706
JERRY_CONTEXT (module_top_context_p) = module_p->context_p->parent_p;
705707

@@ -710,7 +712,9 @@ ecma_module_parse (ecma_module_t *module_p) /**< module */
710712
return ret_value;
711713
}
712714

713-
module_p->compiled_code_p = ecma_get_object_from_value (ret_value);
715+
ecma_free_value (ret_value);
716+
717+
module_p->compiled_code_p = bytecode_data_p;
714718
module_p->state = ECMA_MODULE_STATE_PARSED;
715719

716720
return ECMA_VALUE_EMPTY;
@@ -851,7 +855,7 @@ ecma_module_release_module (ecma_module_t *module_p) /**< module */
851855
if (module_p->state >= ECMA_MODULE_STATE_PARSED
852856
&& module_p->state < ECMA_MODULE_STATE_EVALUATED)
853857
{
854-
ecma_deref_object (module_p->compiled_code_p);
858+
ecma_bytecode_deref (module_p->compiled_code_p);
855859
}
856860

857861
if (module_p->namespace_object_p != NULL)

jerry-core/ecma/base/ecma-module.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ typedef enum
7777
*/
7878
struct ecma_module
7979
{
80-
struct ecma_module *next_p; /**< next linked list node */
81-
ecma_module_state_t state; /**< state of the mode */
82-
ecma_string_t *path_p; /**< path of the module */
83-
ecma_module_context_t *context_p; /**< module context of the module */
84-
ecma_object_t *compiled_code_p; /**< compiled code of the module */
85-
ecma_object_t *scope_p; /**< lexica lenvironment of the module */
86-
ecma_object_t *namespace_object_p; /**< namespace import object of the module */
80+
struct ecma_module *next_p; /**< next linked list node */
81+
ecma_module_state_t state; /**< state of the mode */
82+
ecma_string_t *path_p; /**< path of the module */
83+
ecma_module_context_t *context_p; /**< module context of the module */
84+
ecma_compiled_code_t *compiled_code_p; /**< compiled code of the module */
85+
ecma_object_t *scope_p; /**< lexica lenvironment of the module */
86+
ecma_object_t *namespace_object_p; /**< namespace import object of the module */
8787
};
8888

8989
/**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
export {} from "dummy.js";
16+
export {} from "tests/jerry/es2015/module-export-04.js";

0 commit comments

Comments
 (0)