summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Number/prototype/toFixed/S15.7.4.5_A1.3_T01.js
blob: 70468a816ae52405cca35f84841c5539c1efb060 (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
// Copyright 2009 the Sputnik authors.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
info: "Step 4: If this number value is NaN, return the string \"NaN\""
es5id: 15.7.4.5_A1.3_T01
description: NaN is computed by new Number("string")
---*/
assert.sameValue((new Number("a")).toFixed(), "NaN", '(new Number("a")).toFixed() must return "NaN"');
assert.sameValue((new Number("a")).toFixed(0), "NaN", '(new Number("a")).toFixed(0) must return "NaN"');
assert.sameValue((new Number("a")).toFixed(1), "NaN", '(new Number("a")).toFixed(1) must return "NaN"');
assert.sameValue((new Number("a")).toFixed(1.1), "NaN", '(new Number("a")).toFixed(1.1) must return "NaN"');
assert.sameValue((new Number("a")).toFixed(0.9), "NaN", '(new Number("a")).toFixed(0.9) must return "NaN"');
assert.sameValue((new Number("a")).toFixed("1"), "NaN", '(new Number("a")).toFixed("1") must return "NaN"');
assert.sameValue((new Number("a")).toFixed("1.1"), "NaN", '(new Number("a")).toFixed("1.1") must return "NaN"');
assert.sameValue((new Number("a")).toFixed("0.9"), "NaN", '(new Number("a")).toFixed("0.9") must return "NaN"');

assert.sameValue(
  (new Number("a")).toFixed(Number.NaN),
  "NaN",
  '(new Number("a")).toFixed(Number.NaN) must return "NaN"'
);

assert.sameValue(
  (new Number("a")).toFixed("some string"),
  "NaN",
  '(new Number("a")).toFixed("some string") must return "NaN"'
);

try {
  s = (new Number("a")).toFixed(Number.POSITIVE_INFINITY);
  throw new Test262Error('#10: (new Number("a")).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);