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(
     25 "This test checks that toString() round-trip on a function that has a expression of form 4..x does not lose its meaning."
     26 + " The expression accesses the property 'x' from number '4'."
     27 );
     28 
     29 // construct same test-case for different kinds of number literals. the switch is used to avoid
     30 // individual returns getting optimized away (if the interpreter would do dead code elimination)
     31 
     32 // testcase for number literal with decimal point, i.e '4.'
     33 function f1(a) {
     34     switch(a) {
     35     case "member":
     36         return 4..x;
     37     case "arrayget":
     38         return 4.["x"];
     39     case "constr":
     40         return 4.();
     41     case "funccall":
     42         return 4..f();
     43     case "parenfunccall":
     44         return (4..x)();
     45     case "assignment":
     46         return 4..x = 33;
     47     case "assignment2":
     48         return 4..x >>>= 1;
     49     case "prefix":
     50         return ++4..x;
     51     case "postfix":
     52         return 4..x++;
     53    case "delete":
     54         delete 4..x;
     55         return 4..x;
     56     }
     57 
     58     return 0;
     59 }
     60 
     61 // '4. .'
     62 function f2(a) {
     63     switch(a) {
     64     case "member":
     65         return 4. .x;
     66     case "arrayget":
     67         return 4. ["x"];
     68     case "constr":
     69         return 4.();
     70     case "funccall":
     71         return 4. .f();
     72     case "parenfunccall":
     73         return (4. .x)();
     74     case "assignment":
     75         return 4. .x = 33;
     76     case "assignment2":
     77         return 4. .x >>>= 1;
     78     case "prefix":
     79         return ++4. .x;
     80     case "postfix":
     81         return 4. .x++;
     82     case "delete":
     83         delete 4. .x;
     84         return 4. .x;
     85     }
     86 
     87     return 0;
     88 }
     89 
     90 // '4e20'
     91 function f2(a) {
     92     switch(a) {
     93     case "member":
     94         return 4e20.x;
     95     case "arrayget":
     96         return 4e20["x"];
     97     case "constr":
     98         return 4e20();
     99     case "funccall":
    100         return 4e20.f();
    101     case "parenfunccall":
    102         return (4e20.x)();
    103     case "assignment":
    104         return 4e20.x = 33;
    105     case "assignment2":
    106         return 4e20.x >>>= 1;
    107     case "prefix":
    108         return ++4e20.x;
    109     case "postfix":
    110         return 4e20.x++;
    111     case "delete":
    112         delete 4e20.x;
    113         return 4e20.x;
    114     }
    115 
    116     return 0;
    117 }
    118 
    119 // '4.1e-20'
    120 function f3(a) {
    121     switch(a) {
    122     case "member":
    123         return 4.1e-20.x;
    124     case "arrayget":
    125         return 4.1e-20["x"];
    126     case "constr":
    127         return 4.1e-20();
    128     case "funccall":
    129         return 4.1e-20.f();
    130     case "parenfunccall":
    131         return (4.1e-20.x)();
    132     case "assignment":
    133         return 4.1e-20.x = 33;
    134     case "assignment2":
    135         return 4.1e-20.x >>>= 1;
    136     case "prefix":
    137         return ++4.1e-20.x;
    138     case "postfix":
    139         return 4.1e-20.x++;
    140    case "delete":
    141         delete 4.1e-20.x;
    142         return 4.1e-20.x;
    143     }
    144 
    145     return 0;
    146 }
    147 
    148 // '4'
    149 function f4(a) {
    150     switch(a) {
    151     case "member":
    152         return 4 .x;
    153     case "arrayget":
    154         return 4["x"];
    155     case "constr":
    156         return 4();
    157     case "funccall":
    158         return 4 .f();
    159     case "parenfunccall":
    160         return (4 .x)();
    161     case "assignment":
    162         return 4 .x = 33;
    163     case "assignment2":
    164         return 4 .x >>>= 1;
    165     case "prefix":
    166         return ++4 .x;
    167     case "postfix":
    168         return 4 .x++;
    169     case "delete":
    170         delete 4 .x;
    171         return 4 .x;
    172 
    173     }
    174 
    175     return 0;
    176 }
    177 
    178 // '(4)'
    179 function f5(a) {
    180     switch(a) {
    181     case "member":
    182         return (4).x;
    183     case "arrayget":
    184         return (4)["x"];
    185     case "constr":
    186         return (4)();
    187     case "funccall":
    188         return (4).f();
    189     case "parenfunccall":
    190         return ((4).x)();
    191     case "assignment":
    192         return (4).x = 33;
    193     case "assignment2":
    194         return (4).x >>>= 1;
    195     case "prefix":
    196         return ++(4).x;
    197     case "postfix":
    198         return (4).x++;
    199     case "delete":
    200         delete (4).x;
    201         return (4).x;
    202     }
    203 
    204     return 0;
    205 }
    206 unevalf = function(x) { return '(' + x.toString() + ')'; };
    207 
    208 function testToString(fn)
    209 {
    210     shouldBe("unevalf(eval(unevalf(" + fn + ")))", "unevalf(" + fn + ")");
    211 }
    212 
    213 for(var i = 1; i < 6; ++i)
    214     testToString("f" + i);
    215