Skip to content

Commit 759faf8

Browse files
committed
Simplify String.repeat shim
1 parent 3e94cfd commit 759faf8

File tree

2 files changed

+0
-44
lines changed

2 files changed

+0
-44
lines changed

internal/assert/assertion_error.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,10 @@ function endsWith(str, search, this_len) {
1818

1919
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
2020
function repeat(str, count) {
21-
if (str == null)
22-
throw new TypeError('can\'t convert ' + this + ' to object');
23-
24-
str = '' + str;
25-
// To convert string to integer.
26-
count = +count;
27-
// Check NaN
28-
if (count != count)
29-
count = 0;
30-
31-
if (count < 0)
32-
throw new RangeError('repeat count must be non-negative');
33-
34-
if (count == Infinity)
35-
throw new RangeError('repeat count must be less than infinity');
36-
3721
count = Math.floor(count);
3822
if (str.length == 0 || count == 0)
3923
return '';
4024

41-
// Ensuring count is a 31-bit integer allows us to heavily optimize the
42-
// main part. But anyway, most current (August 2014) browsers can't handle
43-
// strings 1 << 28 chars or longer, so:
44-
if (str.length * count >= 1 << 28)
45-
throw new RangeError('repeat count must not overflow maximum string size');
46-
4725
var maxCount = str.length * count;
4826
count = Math.floor(Math.log(count) / Math.log(2));
4927
while (count) {

test/common/index.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,10 @@ const objectEntries = Object.entries
1010

1111
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
1212
function repeat(str, count) {
13-
if (str == null)
14-
throw new TypeError('can\'t convert ' + this + ' to object');
15-
16-
str = '' + str;
17-
// To convert string to integer.
18-
count = +count;
19-
// Check NaN
20-
if (count != count)
21-
count = 0;
22-
23-
if (count < 0)
24-
throw new RangeError('repeat count must be non-negative');
25-
26-
if (count == Infinity)
27-
throw new RangeError('repeat count must be less than infinity');
28-
2913
count = Math.floor(count);
3014
if (str.length == 0 || count == 0)
3115
return '';
3216

33-
// Ensuring count is a 31-bit integer allows us to heavily optimize the
34-
// main part. But anyway, most current (August 2014) browsers can't handle
35-
// strings 1 << 28 chars or longer, so:
36-
if (str.length * count >= 1 << 28)
37-
throw new RangeError('repeat count must not overflow maximum string size');
38-
3917
var maxCount = str.length * count;
4018
count = Math.floor(Math.log(count) / Math.log(2));
4119
while (count) {

0 commit comments

Comments
 (0)