1// Copyright 2013 the V8 project authors. All rights reserved.
2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions
6// are met:
7// 1.  Redistributions of source code must retain the above copyright
8//     notice, this list of conditions and the following disclaimer.
9// 2.  Redistributions in binary form must reproduce the above copyright
10//     notice, this list of conditions and the following disclaimer in the
11//     documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24description('Test the JavaScript ToNumber operation.')
25
26var nullCharacter = String.fromCharCode(0);
27var nonASCIICharacter = String.fromCharCode(0x100);
28var nonASCIINonSpaceCharacter = String.fromCharCode(0x13A0);
29var illegalUTF16Sequence = String.fromCharCode(0xD800);
30
31var tab = String.fromCharCode(9);
32var nbsp = String.fromCharCode(0xA0);
33var ff = String.fromCharCode(0xC);
34var vt = String.fromCharCode(0xB);
35var cr = String.fromCharCode(0xD);
36var lf = String.fromCharCode(0xA);
37var ls = String.fromCharCode(0x2028);
38var ps = String.fromCharCode(0x2029);
39
40var oghamSpaceMark = String.fromCharCode(0x1680);
41var mongolianVowelSeparator = String.fromCharCode(0x180E);
42var enQuad = String.fromCharCode(0x2000);
43var emQuad = String.fromCharCode(0x2001);
44var enSpace = String.fromCharCode(0x2002);
45var emSpace = String.fromCharCode(0x2003);
46var threePerEmSpace = String.fromCharCode(0x2004);
47var fourPerEmSpace = String.fromCharCode(0x2005);
48var sixPerEmSpace = String.fromCharCode(0x2006);
49var figureSpace = String.fromCharCode(0x2007);
50var punctuationSpace = String.fromCharCode(0x2008);
51var thinSpace = String.fromCharCode(0x2009);
52var hairSpace = String.fromCharCode(0x200A);
53var narrowNoBreakSpace = String.fromCharCode(0x202F);
54var mediumMathematicalSpace = String.fromCharCode(0x205F);
55var ideographicSpace = String.fromCharCode(0x3000);
56
57shouldBe("+undefined", "NaN");
58shouldBe("+null", "0");
59shouldBe("+false", "0");
60shouldBe("+true", "1");
61shouldBe("+2", "2");
62shouldBe("+''", "0");
63shouldBe("+' '", "0");
64shouldBe("+' 1'", "1");
65shouldBe("+'1 '", "1");
66shouldBe("+'x1'", "NaN");
67shouldBe("+'1x'", "NaN");
68shouldBe("+'0x1'", "1");
69shouldBe("+'1x0'", "NaN");
70shouldBe("+(nullCharacter + '1')", "NaN");
71shouldBe("+('1' + nullCharacter)", "NaN");
72shouldBe("+('1' + nullCharacter + '1')", "NaN");
73shouldBe("+(nonASCIICharacter + '1')", "NaN");
74shouldBe("+('1' + nonASCIICharacter)", "NaN");
75shouldBe("+('1' + nonASCIICharacter + '1')", "NaN");
76shouldBe("+('1' + nonASCIINonSpaceCharacter)", "NaN");
77shouldBe("+(nonASCIINonSpaceCharacter + '1')", "NaN");
78shouldBe("+('1' + nonASCIINonSpaceCharacter + '1')", "NaN");
79shouldBe("+(illegalUTF16Sequence + '1')", "NaN");
80shouldBe("+('1' + illegalUTF16Sequence)", "NaN");
81shouldBe("+('1' + illegalUTF16Sequence + '1')", "NaN");
82shouldBe("+'inf'", "NaN");
83shouldBe("+'infinity'", "NaN");
84shouldBe("+'Inf'", "NaN");
85shouldBe("+'+inf'", "NaN");
86shouldBe("+'+infinity'", "NaN");
87shouldBe("+'+Inf'", "NaN");
88shouldBe("+'-inf'", "NaN");
89shouldBe("+'-infinity'", "NaN");
90shouldBe("+'-Inf'", "NaN");
91shouldBe("+'Infinity'", "Infinity");
92shouldBe("+'+Infinity'", "Infinity");
93shouldBe("+'-Infinity'", "-Infinity");
94shouldBe("+'++1'", "NaN");
95shouldBe("+'AB'", "NaN");
96shouldBe("+'0xAB'", "171");
97shouldBe("+'1e1'", "10");
98shouldBe("+'1E1'", "10");
99shouldBe("+tab", "0");
100shouldBe("+nbsp", "0");
101shouldBe("+ff", "0");
102shouldBe("+vt", "0");
103shouldBe("+cr", "0");
104shouldBe("+lf", "0");
105shouldBe("+ls", "0");
106shouldBe("+ps", "0");
107shouldBe("+oghamSpaceMark", "0");
108shouldBe("+mongolianVowelSeparator", "0");
109shouldBe("+enQuad", "0");
110shouldBe("+emQuad", "0");
111shouldBe("+enSpace", "0");
112shouldBe("+emSpace", "0");
113shouldBe("+threePerEmSpace", "0");
114shouldBe("+fourPerEmSpace", "0");
115shouldBe("+sixPerEmSpace", "0");
116shouldBe("+figureSpace", "0");
117shouldBe("+punctuationSpace", "0");
118shouldBe("+thinSpace", "0");
119shouldBe("+hairSpace", "0");
120shouldBe("+narrowNoBreakSpace", "0");
121shouldBe("+mediumMathematicalSpace", "0");
122shouldBe("+ideographicSpace", "0");
123shouldBe("+(tab + '1')", "1");
124shouldBe("+(nbsp + '1')", "1");
125shouldBe("+(ff + '1')", "1");
126shouldBe("+(vt + '1')", "1");
127shouldBe("+(cr + '1')", "1");
128shouldBe("+(lf + '1')", "1");
129shouldBe("+(ls + '1')", "1");
130shouldBe("+(ps + '1')", "1");
131shouldBe("+(oghamSpaceMark + '1')", "1");
132shouldBe("+(mongolianVowelSeparator + '1')", "1");
133shouldBe("+(enQuad + '1')", "1");
134shouldBe("+(emQuad + '1')", "1");
135shouldBe("+(enSpace + '1')", "1");
136shouldBe("+(emSpace + '1')", "1");
137shouldBe("+(threePerEmSpace + '1')", "1");
138shouldBe("+(fourPerEmSpace + '1')", "1");
139shouldBe("+(sixPerEmSpace + '1')", "1");
140shouldBe("+(figureSpace + '1')", "1");
141shouldBe("+(punctuationSpace + '1')", "1");
142shouldBe("+(thinSpace + '1')", "1");
143shouldBe("+(hairSpace + '1')", "1");
144shouldBe("+(narrowNoBreakSpace + '1')", "1");
145shouldBe("+(mediumMathematicalSpace + '1')", "1");
146shouldBe("+(ideographicSpace + '1')", "1");
147shouldBe("+('1' + tab)", "1");
148shouldBe("+('1' + nbsp)", "1");
149shouldBe("+('1' + ff)", "1");
150shouldBe("+('1' + vt)", "1");
151shouldBe("+('1' + cr)", "1");
152shouldBe("+('1' + lf)", "1");
153shouldBe("+('1' + ls)", "1");
154shouldBe("+('1' + ps)", "1");
155shouldBe("+('1' + oghamSpaceMark)", "1");
156shouldBe("+('1' + mongolianVowelSeparator)", "1");
157shouldBe("+('1' + enQuad)", "1");
158shouldBe("+('1' + emQuad)", "1");
159shouldBe("+('1' + enSpace)", "1");
160shouldBe("+('1' + emSpace)", "1");
161shouldBe("+('1' + threePerEmSpace)", "1");
162shouldBe("+('1' + fourPerEmSpace)", "1");
163shouldBe("+('1' + sixPerEmSpace)", "1");
164shouldBe("+('1' + figureSpace)", "1");
165shouldBe("+('1' + punctuationSpace)", "1");
166shouldBe("+('1' + thinSpace)", "1");
167shouldBe("+('1' + hairSpace)", "1");
168shouldBe("+('1' + narrowNoBreakSpace)", "1");
169shouldBe("+('1' + mediumMathematicalSpace)", "1");
170shouldBe("+('1' + ideographicSpace)", "1");
171shouldBe("+('1' + tab + '1')", "NaN");
172shouldBe("+('1' + nbsp + '1')", "NaN");
173shouldBe("+('1' + ff + '1')", "NaN");
174shouldBe("+('1' + vt + '1')", "NaN");
175shouldBe("+('1' + cr + '1')", "NaN");
176shouldBe("+('1' + lf + '1')", "NaN");
177shouldBe("+('1' + ls + '1')", "NaN");
178shouldBe("+('1' + ps + '1')", "NaN");
179shouldBe("+('1' + oghamSpaceMark + '1')", "NaN");
180shouldBe("+('1' + mongolianVowelSeparator + '1')", "NaN");
181shouldBe("+('1' + enQuad + '1')", "NaN");
182shouldBe("+('1' + emQuad + '1')", "NaN");
183shouldBe("+('1' + enSpace + '1')", "NaN");
184shouldBe("+('1' + emSpace + '1')", "NaN");
185shouldBe("+('1' + threePerEmSpace + '1')", "NaN");
186shouldBe("+('1' + fourPerEmSpace + '1')", "NaN");
187shouldBe("+('1' + sixPerEmSpace + '1')", "NaN");
188shouldBe("+('1' + figureSpace + '1')", "NaN");
189shouldBe("+('1' + punctuationSpace + '1')", "NaN");
190shouldBe("+('1' + thinSpace + '1')", "NaN");
191shouldBe("+('1' + hairSpace + '1')", "NaN");
192shouldBe("+('1' + narrowNoBreakSpace + '1')", "NaN");
193shouldBe("+('1' + mediumMathematicalSpace + '1')", "NaN");
194shouldBe("+('1' + ideographicSpace + '1')", "NaN");
195