Skip to content

Commit 7e05ce3

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 [email protected]
1 parent fb2edd8 commit 7e05ce3

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
#include "ecma-arraybuffer-object.h"
17-
#include "ecma-conversion.h"
17+
#include "ecma-try-catch-macro.h"
1818
#include "ecma-objects.h"
1919
#include "ecma-builtins.h"
2020
#include "ecma-exceptions.h"
@@ -50,12 +50,21 @@ 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 ret = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
54+
ECMA_OP_TO_NUMBER_TRY_CATCH (num, arguments_list_p[0], ret);
5455
length = ecma_number_to_uint32 (num);
56+
5557
if (num != ((ecma_number_t) length))
5658
{
5759
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid ArrayBuffer length."));
5860
}
61+
62+
ECMA_OP_TO_NUMBER_FINALIZE (num);
63+
64+
if (!ecma_is_value_empty (ret))
65+
{
66+
return ret;
67+
}
5968
}
6069

6170
ecma_object_t *object_p = ecma_arraybuffer_new_object (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");
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("string");
21+
}
22+
catch (e)
23+
{
24+
name = e.name;
25+
}
26+
27+
assert(name === "RangeError");
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+
var obj = {};
18+
try
19+
{
20+
var a = new ArrayBuffer(obj);
21+
}
22+
catch (e)
23+
{
24+
name = e.name;
25+
}
26+
27+
assert(name === "RangeError");

0 commit comments

Comments
 (0)