[DFG] ToString operation should have fixup for primitives to say this node does not...
[WebKit-https.git] / JSTests / stress / to-string-non-cell-use.js
1 function shouldBe(actual, expected)
2 {
3     if (actual !== expected)
4         throw new Error('bad value: ' + actual);
5 }
6
7 function shouldThrow(func, errorMessage)
8 {
9     var errorThrown = false;
10     var error = null;
11     try {
12         func();
13     } catch (e) {
14         errorThrown = true;
15         error = e;
16     }
17     if (!errorThrown)
18         throw new Error('not thrown');
19     if (String(error) !== errorMessage)
20         throw new Error(`bad error: ${String(error)}`);
21 }
22
23 function toString(value)
24 {
25     return `${value}`;
26 }
27 noInline(toString);
28
29 for (var i = 0; i < 1e4; ++i) {
30     shouldBe(toString(i), i + "");
31     shouldBe(toString(null), "null");
32     shouldBe(toString(undefined), "undefined");
33     shouldBe(toString(10.5), "10.5");
34     shouldBe(toString(-10.5), "-10.5");
35     shouldBe(toString(true), "true");
36     shouldBe(toString(false), "false");
37     shouldBe(toString(0 / 0), "NaN");
38 }
39
40 shouldBe(toString("HELLO"), "HELLO");
41 shouldThrow(() => {
42     toString(Symbol("Cocoa"));
43 }, `TypeError: Cannot convert a symbol to a string`);