Skip to content

Fix a bug in ArrayBuffer #1479

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
Dec 9, 2016
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions jerry-core/ecma/operations/ecma-arraybuffer-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

#include "ecma-arraybuffer-object.h"
#include "ecma-conversion.h"
#include "ecma-try-catch-macro.h"
#include "ecma-objects.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
Expand Down Expand Up @@ -50,12 +50,22 @@ ecma_op_create_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< li

if (arguments_list_len > 0)
{
ecma_number_t num = ecma_get_number_from_value (ecma_op_to_number (arguments_list_p[0]));
ecma_value_t ret = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);

ECMA_OP_TO_NUMBER_TRY_CATCH (num, arguments_list_p[0], ret);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a newline before ECMA_OP_TO_NUMBER_TRY_CATCH.

length = ecma_number_to_uint32 (num);

if (num != ((ecma_number_t) length))
{
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid ArrayBuffer length."));
}

ECMA_OP_TO_NUMBER_FINALIZE (num);

if (!ecma_is_value_empty (ret))
{
return ret;
}
}

ecma_object_t *object_p = ecma_arraybuffer_new_object (length);
Expand Down
27 changes: 27 additions & 0 deletions tests/jerry-test-suite/es2015/24/24.01/24.01.02/24.01.02-006.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* 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 name = "";

try
{
var a = new ArrayBuffer(5.5);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be another case with:

var a = new ArrayBuffer("a string");

Or something non-number.

}
catch (e)
{
name = e.name;
}

assert(name === "RangeError");
27 changes: 27 additions & 0 deletions tests/jerry-test-suite/es2015/24/24.01/24.01.02/24.01.02-007.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* 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 name = "";

try
{
var a = new ArrayBuffer("string");
}
catch (e)
{
name = e.name;
}

assert(name === "RangeError");
27 changes: 27 additions & 0 deletions tests/jerry-test-suite/es2015/24/24.01/24.01.02/24.01.02-008.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* 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 name = "";
var obj = {};
try
{
var a = new ArrayBuffer(obj);
}
catch (e)
{
name = e.name;
}

assert(name === "RangeError");