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 24var posInf = 1/0; 25var negInf = -1/0; 26var nan = 0/0; 27 28shouldBeEqualToString("(0.0).toString(4)", "0"); 29shouldBeEqualToString("(-0.0).toString(4)", "0"); 30shouldBeEqualToString("(0.0).toString()", "0"); 31shouldBeEqualToString("(-0.0).toString()", "0"); 32 33// From http://bugs.webkit.org/show_bug.cgi?id=5258 34shouldBeEqualToString("(1234.567).toString()", "1234.567"); 35shouldThrow("(1234.567).toString(0)"); 36// 0 equivilents 37shouldThrow("(1234.567).toString(null)"); 38shouldThrow("(1234.567).toString(false)"); 39shouldThrow("(1234.567).toString('foo')"); 40shouldThrow("(1234.567).toString(nan)"); // nan is treated like 0 41 42shouldThrow("(1234.567).toString(1)"); 43shouldThrow("(1234.567).toString(true)"); 44shouldThrow("(1234.567).toString('1')"); 45 46// These test for Firefox compatibility, the spec is "implementation defined" 47shouldBeEqualToString("(1234.567).toString(2)", "10011010010.1001000100100110111010010111100011010101"); 48shouldBeEqualToString("(1234.567).toString(3)", "1200201.120022100021001021021002202"); 49shouldBeEqualToString("(1234.567).toString(4)", "103102.21010212322113203111"); 50shouldBeEqualToString("(1234.567).toString(4.9)", "103102.21010212322113203111"); 51shouldBeEqualToString("(1234.567).toString(5)", "14414.240414141414141414"); 52shouldBeEqualToString("(1234.567).toString(6)", "5414.32224554134430233"); 53shouldBeEqualToString("(1234.567).toString(7)", "3412.365323661111653"); 54shouldBeEqualToString("(1234.567).toString(8)", "2322.44223351361524"); 55shouldBeEqualToString("(1234.567).toString(9)", "1621.50830703723265"); 56shouldBeEqualToString("(1234.567).toString(10)", "1234.567"); 57shouldBeEqualToString("(1234.567).toString(11)", "a22.62674a0a5885"); 58shouldBeEqualToString("(1234.567).toString(12)", "86a.697938b17701"); 59shouldBeEqualToString("(1234.567).toString(13)", "73c.74a91191a65"); 60shouldBeEqualToString("(1234.567).toString(14)", "642.7d1bc2caa757"); 61shouldBeEqualToString("(1234.567).toString(15)", "574.87895959596"); 62shouldBeEqualToString("(1234.567).toString(16)", "4d2.9126e978d5"); 63shouldBeEqualToString("(1234.567).toString(17)", "44a.9aeb6faa0da"); 64shouldBeEqualToString("(1234.567).toString(18)", "3ea.a3cd7102ac"); 65shouldBeEqualToString("(1234.567).toString(19)", "37i.aed102a04d"); 66shouldBeEqualToString("(1234.567).toString(20)", "31e.b6g"); 67shouldBeEqualToString("(1234.567).toString(21)", "2gg.bj0kf5cfe9"); 68shouldBeEqualToString("(1234.567).toString(22)", "2c2.ca9937cak"); 69shouldBeEqualToString("(1234.567).toString(23)", "27f.d0lfjb1a7c"); 70shouldBeEqualToString("(1234.567).toString(24)", "23a.dee4nj99j"); 71shouldBeEqualToString("(1234.567).toString(25)", "1o9.e49999999"); 72shouldBeEqualToString("(1234.567).toString(26)", "1lc.ej7fa4pkf"); 73shouldBeEqualToString("(1234.567).toString(27)", "1ij.f8971772k"); 74shouldBeEqualToString("(1234.567).toString(28)", "1g2.foelqia8e"); 75shouldBeEqualToString("(1234.567).toString(29)", "1dg.gcog9e05q"); 76shouldBeEqualToString("(1234.567).toString(30)", "1b4.h09"); 77shouldBeEqualToString("(1234.567).toString(31)", "18p.hhrfcj3t"); 78shouldBeEqualToString("(1234.567).toString(32)", "16i.i4jeiu6l"); 79shouldBeEqualToString("(1234.567).toString(33)", "14d.inf96rdvm"); 80shouldBeEqualToString("(1234.567).toString(34)", "12a.j9fchdtm"); 81shouldBeEqualToString("(1234.567).toString(35)", "109.jtk4d4d4e"); 82shouldBeEqualToString("(1234.567).toString(36)", "ya.kety9sifl"); 83 84shouldThrow("(1234.567).toString(37)"); 85shouldThrow("(1234.567).toString(-1)"); 86shouldThrow("(1234.567).toString(posInf)"); 87shouldThrow("(1234.567).toString(negInf)"); 88 89shouldBeEqualToString("posInf.toString()", "Infinity"); 90shouldBeEqualToString("negInf.toString()", "-Infinity"); 91shouldBeEqualToString("nan.toString()", "NaN"); 92 93shouldBeEqualToString('"" + -0.0', "0"); 94