Skip to content

Commit 848a985

Browse files
szilagyiadamrerobika
authored andcommitted
Add missing value release in typedArray toLocaleString (#3200)
Fixes #3162 JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
1 parent 7dc2d1d commit 848a985

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "ecma-globals.h"
2828
#include "ecma-helpers.h"
2929
#include "ecma-iterator-object.h"
30+
#include "ecma-number-object.h"
3031
#include "ecma-objects.h"
3132
#include "ecma-try-catch-macro.h"
3233
#include "ecma-typedarray-object.h"
@@ -1985,13 +1986,11 @@ ecma_builtin_typedarray_prototype_to_locale_string_helper (ecma_object_t *this_o
19851986
ecma_number_t element_num = ecma_get_typedarray_element (typedarray_buffer_p + index, class_id);
19861987
ecma_value_t element_value = ecma_make_number_value (element_num);
19871988

1988-
ecma_value_t element_obj = ecma_op_to_object (element_value);
1989+
ecma_value_t element_obj = ecma_op_create_number_object (element_value);
19891990

1990-
if (ECMA_IS_VALUE_ERROR (element_obj))
1991-
{
1992-
ecma_free_value (element_value);
1993-
return element_obj;
1994-
}
1991+
ecma_free_value (element_value);
1992+
1993+
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (element_obj));
19951994

19961995
ecma_object_t *element_obj_p = ecma_get_object_from_value (element_obj);
19971996

@@ -2000,7 +1999,6 @@ ecma_builtin_typedarray_prototype_to_locale_string_helper (ecma_object_t *this_o
20001999

20012000
if (ECMA_IS_VALUE_ERROR (func_value))
20022001
{
2003-
ecma_free_value (element_value);
20042002
ecma_deref_object (element_obj_p);
20052003
return func_value;
20062004
}
@@ -2017,12 +2015,12 @@ ecma_builtin_typedarray_prototype_to_locale_string_helper (ecma_object_t *this_o
20172015

20182016
if (ECMA_IS_VALUE_ERROR (call_value))
20192017
{
2020-
ecma_free_value (element_value);
20212018
ecma_deref_object (element_obj_p);
20222019
return call_value;
20232020
}
20242021

20252022
ret_value = ecma_op_to_string (call_value);
2023+
ecma_free_value (call_value);
20262024
}
20272025
else
20282026
{
@@ -2031,7 +2029,6 @@ ecma_builtin_typedarray_prototype_to_locale_string_helper (ecma_object_t *this_o
20312029
}
20322030

20332031
ecma_deref_object (element_obj_p);
2034-
ecma_free_value (element_value);
20352032

20362033
return ret_value;
20372034
} /* ecma_builtin_typedarray_prototype_to_locale_string_helper */
@@ -2078,7 +2075,7 @@ ecma_builtin_typedarray_prototype_to_locale_string (ecma_value_t this_arg) /**<
20782075

20792076
if (ECMA_IS_VALUE_ERROR (next_element))
20802077
{
2081-
ecma_free_value (first_element);
2078+
ecma_deref_ecma_string (return_string_p);
20822079
return next_element;
20832080
}
20842081

@@ -2087,8 +2084,6 @@ ecma_builtin_typedarray_prototype_to_locale_string (ecma_value_t this_arg) /**<
20872084
ecma_deref_ecma_string (next_element_p);
20882085
}
20892086

2090-
ecma_free_value (first_element);
2091-
20922087
return ecma_make_string_value (return_string_p);
20932088
} /* ecma_builtin_typedarray_prototype_to_locale_string */
20942089

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
try { v0 = this.toString( )} catch ( $ ) { }
16+
try { v1 = this.toLocaleString( ).localeCompare( )} catch ( $ ) { }
17+
try { var v14 = Int8Array.from(((Array)(v0.length))) } catch ( $ ) { }
18+
try { v14(v14.fill(v1)) } catch ( $ ) { }
19+
try { v0(v14.toLocaleString( )) } catch ( $ ) { }

0 commit comments

Comments
 (0)