Skip to content

Commit d3f5513

Browse files
committed
fix a bug in ArrayBuffer
* free_value after ecma_op_to_number * add related test file JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
1 parent fb2edd8 commit d3f5513

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

jerry-core/ecma/operations/ecma-arraybuffer-object.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ ecma_op_create_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< li
5050

5151
if (arguments_list_len > 0)
5252
{
53-
ecma_number_t num = ecma_get_number_from_value (ecma_op_to_number (arguments_list_p[0]));
53+
ecma_value_t num_value = ecma_op_to_number (arguments_list_p[0]);
54+
ecma_number_t num = ecma_get_number_from_value (num_value);
5455
length = ecma_number_to_uint32 (num);
56+
ecma_free_value (num_value);
57+
5558
if (num != ((ecma_number_t) length))
5659
{
5760
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid ArrayBuffer length."));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
16+
var name = "";
17+
18+
try
19+
{
20+
var a = new ArrayBuffer(5.5);
21+
}
22+
catch (e)
23+
{
24+
name = e.name;
25+
}
26+
27+
assert(name === "RangeError");

0 commit comments

Comments
 (0)