summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/String/prototype/split/separator-undef-limit-zero.js
blob: 972816493d2bea1d57432b5108c99b7ce2878c92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (C) 2020 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-string.prototype.split
description: Separator is undefined, limit is zero, return a new empty array
info: |
  ...
  3. Let S be ? ToString(O).
  4. Let A be ! ArrayCreate(0).
  ...
  6. If limit is undefined, let lim be 2**32 - 1; else let lim be ? ToUint32(limit).
  7. Let R be ? ToString(separator).
  8. If lim = 0, return A.

  ToUint32 ( argument )

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, +0, -0, +∞, or -∞, return +0.
  3. Let int be the Number value that is the same sign as number and whose magnitude is floor(abs(number)).
  4. Let int32bit be int modulo 2**32.
  5. Return int32bit.
---*/

var str = 'undefined is not a function';

var result = str.split(undefined, 0);

assert.sameValue(Array.isArray(result), true, 'result is array');
assert.sameValue(result.length, 0, 'result.length');

result = str.split(undefined, false);

assert.sameValue(Array.isArray(result), true, 'boolean, result is array');
assert.sameValue(result.length, 0, 'boolean, result.length');

result = str.split(undefined, null);

assert.sameValue(Array.isArray(result), true, 'null, result is array');
assert.sameValue(result.length, 0, 'null, result.length');

result = str.split(undefined, {valueOf() { return undefined; }});

assert.sameValue(Array.isArray(result), true, 'obj > undefined, result is array');
assert.sameValue(result.length, 0, 'obj > undefined, result.length');

result = str.split(undefined, {valueOf() { return 0; }});

assert.sameValue(Array.isArray(result), true, 'obj > 0, result is array');
assert.sameValue(result.length, 0, 'obj > 0, result.length');

result = str.split(undefined, NaN);

assert.sameValue(Array.isArray(result), true, 'NaN, result is array');
assert.sameValue(result.length, 0, 'NaN, result.length');

result = str.split(undefined, 2 ** 32);

assert.sameValue(Array.isArray(result), true, '2 ** 32, result is array');
assert.sameValue(result.length, 0, '2 ** 32, result.length');

result = str.split(undefined, 2 ** 33);

assert.sameValue(Array.isArray(result), true, '2 ** 33, result is array');
assert.sameValue(result.length, 0, '2 ** 33, result.length');

reportCompare(0, 0);