Skip to content

Commit 06000b5

Browse files
rerobikadbatyai
authored andcommitted
Fix the repeat count checking in String.prototype.repeat (#2959)
This patch fixes #2948 Co-authored-by: Gabor Loki loki@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
1 parent 788fdc6 commit 06000b5

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ ecma_builtin_string_prototype_object_repeat (ecma_value_t this_arg, /**< this ar
21982198
bool isNan = ecma_number_is_nan (length_number);
21992199

22002200
/* 6, 7 */
2201-
if (length < 0 || (!isNan && ecma_number_is_infinity (length_number)))
2201+
if (length_number < 0 || (!isNan && ecma_number_is_infinity (length_number)))
22022202
{
22032203
ecma_deref_ecma_string (original_string_p);
22042204
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid count value"));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 {
16+
new (new Object()).constructor().constructor('abcdefghi').repeat(-4956799914495204378)
17+
assert (false);
18+
} catch (e) {
19+
assert (e instanceof RangeError);
20+
}

0 commit comments

Comments
 (0)