Skip to content

Commit 7c99170

Browse files
committed
Fix assertion in print method.
ICE: Assertion 'args_number == 1' failed at Jerry/jerry-core/vm/opcodes-native-call.cpp(opfunc_native_call):55. Error: ERR_FAILED_INTERNAL_ASSERTION Test case: print('a', 'a'); Print all of the arguments separated by space. JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
1 parent 1f5a4f2 commit 7c99170

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

jerry-core/vm/opcodes-native-call.cpp

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
2+
* Copyright 2015 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -67,39 +68,49 @@ opfunc_native_call (opcode_t opdata, /**< operation data */
6768

6869
case OPCODE_NATIVE_CALL_PRINT:
6970
{
70-
JERRY_ASSERT (args_number == 1);
71-
72-
ECMA_TRY_CATCH (str_value,
73-
ecma_op_to_string (arg_values[0]),
74-
ret_value);
71+
for (ecma_length_t arg_index = 0;
72+
arg_index < args_read;
73+
arg_index++)
74+
{
75+
ECMA_TRY_CATCH (str_value,
76+
ecma_op_to_string (arg_values[arg_index]),
77+
ret_value);
7578

76-
ecma_string_t *str_p = ecma_get_string_from_value (str_value);
79+
ecma_string_t *str_p = ecma_get_string_from_value (str_value);
7780

78-
int32_t chars = ecma_string_get_length (str_p);
79-
JERRY_ASSERT (chars >= 0);
81+
int32_t chars = ecma_string_get_length (str_p);
82+
JERRY_ASSERT (chars >= 0);
8083

81-
ssize_t zt_str_size = (ssize_t) sizeof (ecma_char_t) * (chars + 1);
82-
ecma_char_t *zt_str_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) zt_str_size,
83-
MEM_HEAP_ALLOC_SHORT_TERM);
84-
if (zt_str_p == NULL)
85-
{
86-
jerry_fatal (ERR_OUT_OF_MEMORY);
87-
}
84+
ssize_t zt_str_size = (ssize_t) sizeof (ecma_char_t) * (chars + 1);
85+
ecma_char_t *zt_str_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) zt_str_size,
86+
MEM_HEAP_ALLOC_SHORT_TERM);
87+
if (zt_str_p == NULL)
88+
{
89+
jerry_fatal (ERR_OUT_OF_MEMORY);
90+
}
8891

89-
ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size);
92+
ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size);
9093

9194
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
92-
printf ("%s\n", (char*) zt_str_p);
95+
if (arg_index < args_read - 1)
96+
{
97+
printf ("%s ", (char*) zt_str_p);
98+
}
99+
else
100+
{
101+
printf ("%s", (char*) zt_str_p);
102+
}
93103
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
94-
JERRY_UNIMPLEMENTED ("UTF-16 support is not implemented.");
104+
JERRY_UNIMPLEMENTED ("UTF-16 support is not implemented.");
95105
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
96106

97-
mem_heap_free_block (zt_str_p);
98-
99-
ret_value = ecma_make_empty_completion_value ();
107+
mem_heap_free_block (zt_str_p);
100108

101-
ECMA_FINALIZE (str_value);
109+
ret_value = ecma_make_empty_completion_value ();
102110

111+
ECMA_FINALIZE (str_value);
112+
}
113+
printf ("\n");
103114
break;
104115
}
105116

0 commit comments

Comments
 (0)