Implementing opfunc_addition with a string-operand.

This commit is contained in:
Ruben Ayrapetyan 2014-08-26 11:26:44 +04:00
parent c72555d25f
commit 38fdcba69c
2 changed files with 32 additions and 1 deletions

View File

@ -128,7 +128,20 @@ opfunc_addition (opcode_t opdata, /**< operation data */
if (prim_left_value.value.value_type == ECMA_TYPE_STRING
|| prim_right_value.value.value_type == ECMA_TYPE_STRING)
{
JERRY_UNIMPLEMENTED ();
ECMA_TRY_CATCH (str_left_value, ecma_op_to_string (prim_left_value.value), ret_value);
ECMA_TRY_CATCH (str_right_value, ecma_op_to_string (prim_right_value.value), ret_value);
ecma_string_t *string1_p = ECMA_GET_POINTER (str_left_value.value.value);
ecma_string_t *string2_p = ECMA_GET_POINTER (str_right_value.value.value);
ecma_string_t *concat_str_p = ecma_concat_ecma_strings (string1_p, string2_p);
ret_value = set_variable_value (int_data, dst_var_idx, ecma_make_string_value (concat_str_p));
ecma_deref_ecma_string (concat_str_p);
ECMA_FINALIZE (str_right_value);
ECMA_FINALIZE (str_left_value);
}
else
{

18
tests/jerry/string.js Normal file
View File

@ -0,0 +1,18 @@
// Copyright 2014 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var a = 'abcd';
var b = 'dfgh';
c = a + b;