summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Number/prototype/toFixed/S15.7.4.5_A1.4_T01.js
blob: c5e9de87a7b9f3abacb6a0d97be7934a59567d90 (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
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2009 the Sputnik authors.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
info: "Step 9: If x >= 10^21, let m = ToString(x)"
es5id: 15.7.4.5_A1.4_T01
description: x is 10^21
---*/
assert.sameValue(
  (new Number(1e21)).toFixed(),
  String(1e21),
  '(new Number(1e21)).toFixed() must return the same value returned by String(1e21)'
);

assert.sameValue(
  (new Number(1e21)).toFixed(0),
  String(1e21),
  '(new Number(1e21)).toFixed(0) must return the same value returned by String(1e21)'
);

assert.sameValue(
  (new Number(1e21)).toFixed(1),
  String(1e21),
  '(new Number(1e21)).toFixed(1) must return the same value returned by String(1e21)'
);

assert.sameValue(
  (new Number(1e21)).toFixed(1.1),
  String(1e21),
  '(new Number(1e21)).toFixed(1.1) must return the same value returned by String(1e21)'
);

assert.sameValue(
  (new Number(1e21)).toFixed(0.9),
  String(1e21),
  '(new Number(1e21)).toFixed(0.9) must return the same value returned by String(1e21)'
);

assert.sameValue(
  (new Number(1e21)).toFixed("1"),
  String(1e21),
  '(new Number(1e21)).toFixed("1") must return the same value returned by String(1e21)'
);

assert.sameValue(
  (new Number(1e21)).toFixed("1.1"),
  String(1e21),
  '(new Number(1e21)).toFixed("1.1") must return the same value returned by String(1e21)'
);

assert.sameValue(
  (new Number(1e21)).toFixed("0.9"),
  String(1e21),
  '(new Number(1e21)).toFixed("0.9") must return the same value returned by String(1e21)'
);

assert.sameValue(
  (new Number(1e21)).toFixed(Number.NaN),
  String(1e21),
  '(new Number(1e21)).toFixed(Number.NaN) must return the same value returned by String(1e21)'
);

assert.sameValue(
  (new Number(1e21)).toFixed("some string"),
  String(1e21),
  '(new Number(1e21)).toFixed("some string") must return the same value returned by String(1e21)'
);

try {
  s = (new Number(1e21)).toFixed(Number.POSITIVE_INFINITY);
  throw new Test262Error('#10: (new Number(1e21)).toFixed(Number.POSITIVE_INFINITY) should throw RangeError, not return NaN');
}
catch (e) {
  assert(e instanceof RangeError, 'The result of evaluating (e instanceof RangeError) is expected to be true');
}

reportCompare(0, 0);