Home | History | Annotate | Download | only in webkit
      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 
     24 description('Test the JavaScript ToNumber operation.')
     25 
     26 var nullCharacter = String.fromCharCode(0);
     27 var nonASCIICharacter = String.fromCharCode(0x100);
     28 var nonASCIINonSpaceCharacter = String.fromCharCode(0x13A0);
     29 var illegalUTF16Sequence = String.fromCharCode(0xD800);
     30 
     31 var tab = String.fromCharCode(9);
     32 var nbsp = String.fromCharCode(0xA0);
     33 var ff = String.fromCharCode(0xC);
     34 var vt = String.fromCharCode(0xB);
     35 var cr = String.fromCharCode(0xD);
     36 var lf = String.fromCharCode(0xA);
     37 var ls = String.fromCharCode(0x2028);
     38 var ps = String.fromCharCode(0x2029);
     39 
     40 var oghamSpaceMark = String.fromCharCode(0x1680);
     41 var mongolianVowelSeparator = String.fromCharCode(0x180E);
     42 var enQuad = String.fromCharCode(0x2000);
     43 var emQuad = String.fromCharCode(0x2001);
     44 var enSpace = String.fromCharCode(0x2002);
     45 var emSpace = String.fromCharCode(0x2003);
     46 var threePerEmSpace = String.fromCharCode(0x2004);
     47 var fourPerEmSpace = String.fromCharCode(0x2005);
     48 var sixPerEmSpace = String.fromCharCode(0x2006);
     49 var figureSpace = String.fromCharCode(0x2007);
     50 var punctuationSpace = String.fromCharCode(0x2008);
     51 var thinSpace = String.fromCharCode(0x2009);
     52 var hairSpace = String.fromCharCode(0x200A);
     53 var narrowNoBreakSpace = String.fromCharCode(0x202F);
     54 var mediumMathematicalSpace = String.fromCharCode(0x205F);
     55 var ideographicSpace = String.fromCharCode(0x3000);
     56 
     57 shouldBe("+undefined", "NaN");
     58 shouldBe("+null", "0");
     59 shouldBe("+false", "0");
     60 shouldBe("+true", "1");
     61 shouldBe("+2", "2");
     62 shouldBe("+''", "0");
     63 shouldBe("+' '", "0");
     64 shouldBe("+' 1'", "1");
     65 shouldBe("+'1 '", "1");
     66 shouldBe("+'x1'", "NaN");
     67 shouldBe("+'1x'", "NaN");
     68 shouldBe("+'0x1'", "1");
     69 shouldBe("+'1x0'", "NaN");
     70 shouldBe("+(nullCharacter + '1')", "NaN");
     71 shouldBe("+('1' + nullCharacter)", "NaN");
     72 shouldBe("+('1' + nullCharacter + '1')", "NaN");
     73 shouldBe("+(nonASCIICharacter + '1')", "NaN");
     74 shouldBe("+('1' + nonASCIICharacter)", "NaN");
     75 shouldBe("+('1' + nonASCIICharacter + '1')", "NaN");
     76 shouldBe("+('1' + nonASCIINonSpaceCharacter)", "NaN");
     77 shouldBe("+(nonASCIINonSpaceCharacter + '1')", "NaN");
     78 shouldBe("+('1' + nonASCIINonSpaceCharacter + '1')", "NaN");
     79 shouldBe("+(illegalUTF16Sequence + '1')", "NaN");
     80 shouldBe("+('1' + illegalUTF16Sequence)", "NaN");
     81 shouldBe("+('1' + illegalUTF16Sequence + '1')", "NaN");
     82 shouldBe("+'inf'", "NaN");
     83 shouldBe("+'infinity'", "NaN");
     84 shouldBe("+'Inf'", "NaN");
     85 shouldBe("+'+inf'", "NaN");
     86 shouldBe("+'+infinity'", "NaN");
     87 shouldBe("+'+Inf'", "NaN");
     88 shouldBe("+'-inf'", "NaN");
     89 shouldBe("+'-infinity'", "NaN");
     90 shouldBe("+'-Inf'", "NaN");
     91 shouldBe("+'Infinity'", "Infinity");
     92 shouldBe("+'+Infinity'", "Infinity");
     93 shouldBe("+'-Infinity'", "-Infinity");
     94 shouldBe("+'++1'", "NaN");
     95 shouldBe("+'AB'", "NaN");
     96 shouldBe("+'0xAB'", "171");
     97 shouldBe("+'1e1'", "10");
     98 shouldBe("+'1E1'", "10");
     99 shouldBe("+tab", "0");
    100 shouldBe("+nbsp", "0");
    101 shouldBe("+ff", "0");
    102 shouldBe("+vt", "0");
    103 shouldBe("+cr", "0");
    104 shouldBe("+lf", "0");
    105 shouldBe("+ls", "0");
    106 shouldBe("+ps", "0");
    107 shouldBe("+oghamSpaceMark", "0");
    108 shouldBe("+mongolianVowelSeparator", "0");
    109 shouldBe("+enQuad", "0");
    110 shouldBe("+emQuad", "0");
    111 shouldBe("+enSpace", "0");
    112 shouldBe("+emSpace", "0");
    113 shouldBe("+threePerEmSpace", "0");
    114 shouldBe("+fourPerEmSpace", "0");
    115 shouldBe("+sixPerEmSpace", "0");
    116 shouldBe("+figureSpace", "0");
    117 shouldBe("+punctuationSpace", "0");
    118 shouldBe("+thinSpace", "0");
    119 shouldBe("+hairSpace", "0");
    120 shouldBe("+narrowNoBreakSpace", "0");
    121 shouldBe("+mediumMathematicalSpace", "0");
    122 shouldBe("+ideographicSpace", "0");
    123 shouldBe("+(tab + '1')", "1");
    124 shouldBe("+(nbsp + '1')", "1");
    125 shouldBe("+(ff + '1')", "1");
    126 shouldBe("+(vt + '1')", "1");
    127 shouldBe("+(cr + '1')", "1");
    128 shouldBe("+(lf + '1')", "1");
    129 shouldBe("+(ls + '1')", "1");
    130 shouldBe("+(ps + '1')", "1");
    131 shouldBe("+(oghamSpaceMark + '1')", "1");
    132 shouldBe("+(mongolianVowelSeparator + '1')", "1");
    133 shouldBe("+(enQuad + '1')", "1");
    134 shouldBe("+(emQuad + '1')", "1");
    135 shouldBe("+(enSpace + '1')", "1");
    136 shouldBe("+(emSpace + '1')", "1");
    137 shouldBe("+(threePerEmSpace + '1')", "1");
    138 shouldBe("+(fourPerEmSpace + '1')", "1");
    139 shouldBe("+(sixPerEmSpace + '1')", "1");
    140 shouldBe("+(figureSpace + '1')", "1");
    141 shouldBe("+(punctuationSpace + '1')", "1");
    142 shouldBe("+(thinSpace + '1')", "1");
    143 shouldBe("+(hairSpace + '1')", "1");
    144 shouldBe("+(narrowNoBreakSpace + '1')", "1");
    145 shouldBe("+(mediumMathematicalSpace + '1')", "1");
    146 shouldBe("+(ideographicSpace + '1')", "1");
    147 shouldBe("+('1' + tab)", "1");
    148 shouldBe("+('1' + nbsp)", "1");
    149 shouldBe("+('1' + ff)", "1");
    150 shouldBe("+('1' + vt)", "1");
    151 shouldBe("+('1' + cr)", "1");
    152 shouldBe("+('1' + lf)", "1");
    153 shouldBe("+('1' + ls)", "1");
    154 shouldBe("+('1' + ps)", "1");
    155 shouldBe("+('1' + oghamSpaceMark)", "1");
    156 shouldBe("+('1' + mongolianVowelSeparator)", "1");
    157 shouldBe("+('1' + enQuad)", "1");
    158 shouldBe("+('1' + emQuad)", "1");
    159 shouldBe("+('1' + enSpace)", "1");
    160 shouldBe("+('1' + emSpace)", "1");
    161 shouldBe("+('1' + threePerEmSpace)", "1");
    162 shouldBe("+('1' + fourPerEmSpace)", "1");
    163 shouldBe("+('1' + sixPerEmSpace)", "1");
    164 shouldBe("+('1' + figureSpace)", "1");
    165 shouldBe("+('1' + punctuationSpace)", "1");
    166 shouldBe("+('1' + thinSpace)", "1");
    167 shouldBe("+('1' + hairSpace)", "1");
    168 shouldBe("+('1' + narrowNoBreakSpace)", "1");
    169 shouldBe("+('1' + mediumMathematicalSpace)", "1");
    170 shouldBe("+('1' + ideographicSpace)", "1");
    171 shouldBe("+('1' + tab + '1')", "NaN");
    172 shouldBe("+('1' + nbsp + '1')", "NaN");
    173 shouldBe("+('1' + ff + '1')", "NaN");
    174 shouldBe("+('1' + vt + '1')", "NaN");
    175 shouldBe("+('1' + cr + '1')", "NaN");
    176 shouldBe("+('1' + lf + '1')", "NaN");
    177 shouldBe("+('1' + ls + '1')", "NaN");
    178 shouldBe("+('1' + ps + '1')", "NaN");
    179 shouldBe("+('1' + oghamSpaceMark + '1')", "NaN");
    180 shouldBe("+('1' + mongolianVowelSeparator + '1')", "NaN");
    181 shouldBe("+('1' + enQuad + '1')", "NaN");
    182 shouldBe("+('1' + emQuad + '1')", "NaN");
    183 shouldBe("+('1' + enSpace + '1')", "NaN");
    184 shouldBe("+('1' + emSpace + '1')", "NaN");
    185 shouldBe("+('1' + threePerEmSpace + '1')", "NaN");
    186 shouldBe("+('1' + fourPerEmSpace + '1')", "NaN");
    187 shouldBe("+('1' + sixPerEmSpace + '1')", "NaN");
    188 shouldBe("+('1' + figureSpace + '1')", "NaN");
    189 shouldBe("+('1' + punctuationSpace + '1')", "NaN");
    190 shouldBe("+('1' + thinSpace + '1')", "NaN");
    191 shouldBe("+('1' + hairSpace + '1')", "NaN");
    192 shouldBe("+('1' + narrowNoBreakSpace + '1')", "NaN");
    193 shouldBe("+('1' + mediumMathematicalSpace + '1')", "NaN");
    194 shouldBe("+('1' + ideographicSpace + '1')", "NaN");
    195