Skip to content

Fix assertion in print method. #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions jerry-core/vm/opcodes-native-call.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
* Copyright 2015 University of Szeged.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,39 +68,49 @@ opfunc_native_call (opcode_t opdata, /**< operation data */

case OPCODE_NATIVE_CALL_PRINT:
{
JERRY_ASSERT (args_number == 1);

ECMA_TRY_CATCH (str_value,
ecma_op_to_string (arg_values[0]),
ret_value);
for (ecma_length_t arg_index = 0;
arg_index < args_read;
arg_index++)
{
ECMA_TRY_CATCH (str_value,
ecma_op_to_string (arg_values[arg_index]),
ret_value);

ecma_string_t *str_p = ecma_get_string_from_value (str_value);
ecma_string_t *str_p = ecma_get_string_from_value (str_value);

int32_t chars = ecma_string_get_length (str_p);
JERRY_ASSERT (chars >= 0);
int32_t chars = ecma_string_get_length (str_p);
JERRY_ASSERT (chars >= 0);

ssize_t zt_str_size = (ssize_t) sizeof (ecma_char_t) * (chars + 1);
ecma_char_t *zt_str_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) zt_str_size,
MEM_HEAP_ALLOC_SHORT_TERM);
if (zt_str_p == NULL)
{
jerry_fatal (ERR_OUT_OF_MEMORY);
}
ssize_t zt_str_size = (ssize_t) sizeof (ecma_char_t) * (chars + 1);
ecma_char_t *zt_str_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) zt_str_size,
MEM_HEAP_ALLOC_SHORT_TERM);
if (zt_str_p == NULL)
{
jerry_fatal (ERR_OUT_OF_MEMORY);
}

ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size);
ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size);

#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
printf ("%s\n", (char*) zt_str_p);
if (arg_index < args_read - 1)
{
printf ("%s ", (char*) zt_str_p);
}
else
{
printf ("%s", (char*) zt_str_p);
}
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
JERRY_UNIMPLEMENTED ("UTF-16 support is not implemented.");
JERRY_UNIMPLEMENTED ("UTF-16 support is not implemented.");
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */

mem_heap_free_block (zt_str_p);

ret_value = ecma_make_empty_completion_value ();
mem_heap_free_block (zt_str_p);

ECMA_FINALIZE (str_value);
ret_value = ecma_make_empty_completion_value ();

ECMA_FINALIZE (str_value);
}
printf ("\n");
break;
}

Expand Down