Home | History | Annotate | Download | only in mjsunit
      1 // Copyright 2010 the V8 project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 var except = "exception";
     29 
     30 var correct_answer_index = 0;
     31 var correct_answers = [
     32  false,  false,   true,   true,  false,  false,   true,   true,
     33   true,  false,  false,   true,   true,  false,  false,   true,
     34  false,   true,   true,  false,  false,   true,   true,  false,
     35   true,   true,  false,  false,   true,   true,  false,  false,
     36 except, except,   true,   true, except, except,   true,   true,
     37 except, except,  false,   true, except, except,  false,   true,
     38 except, except,   true,  false, except, except,   true,  false,
     39 except, except,  false,  false, except, except,  false,  false,
     40  false,  false, except, except,  false,  false, except, except,
     41   true,  false, except, except,   true,  false, except, except,
     42  false,   true, except, except,  false,   true, except, except,
     43   true,   true, except, except,   true,   true, except, except,
     44 except, except, except, except, except, except, except, except,
     45 except, except, except, except, except, except, except, except,
     46 except, except, except, except, except, except, except, except,
     47 except, except, except, except, except, except, except, except,
     48  false,  false,   true,   true,  false,  false,   true,   true,
     49   true,  false,  false,   true,  false,  false,   true,   true,
     50  false,   true,   true,  false,  false,   true,   true,  false,
     51   true,   true,  false,  false,  false,   true,   true,  false,
     52 except, except,   true,   true, except, except,   true,   true,
     53 except, except,  false,   true, except, except,   true,   true,
     54 except, except,   true,  false, except, except,   true,  false,
     55 except, except,  false,  false, except, except,   true,  false,
     56  false,  false, except, except,  false,  false, except, except,
     57   true,  false, except, except,   true,  false, except, except,
     58  false,   true, except, except,  false,   true, except, except,
     59   true,   true, except, except,   true,   true, except, except,
     60 except, except, except, except, except, except, except, except,
     61 except, except, except, except, except, except, except, except,
     62 except, except, except, except, except, except, except, except,
     63 except, except, except, except, except, except, except, except,
     64  false,  false,   true,   true,  false,   true,   true,  false,
     65   true,  false,  false,   true,   true,   true,  false,  false,
     66  false,   true,   true,  false,  false,   true,   true,  false,
     67   true,   true,  false,  false,   true,   true,  false,  false,
     68 except, except,   true,   true, except, except,   true,   true,
     69 except, except,  false,   true, except, except,  false,   true,
     70 except, except,   true,  false, except, except,   true,  false,
     71 except, except,  false,  false, except, except,  false,  false,
     72  false,  false, except, except,  false,   true, except, except,
     73   true,  false, except, except,   true,   true, except, except,
     74  false,   true, except, except,  false,   true, except, except,
     75   true,   true, except, except,   true,   true, except, except,
     76 except, except, except, except, except, except, except, except,
     77 except, except, except, except, except, except, except, except,
     78 except, except, except, except, except, except, except, except,
     79 except, except, except, except, except, except, except, except,
     80  false,  false,   true,   true,  false,   true,   true,  false,
     81   true,  false,  false,   true,  false,   true,   true,  false,
     82  false,   true,   true,  false,  false,   true,   true,  false,
     83   true,   true,  false,  false,  false,   true,   true,  false,
     84 except, except,   true,   true, except, except,   true,   true,
     85 except, except,  false,   true, except, except,   true,   true,
     86 except, except,   true,  false, except, except,   true,  false,
     87 except, except,  false,  false, except, except,   true,  false,
     88  false,  false, except, except,  false,   true, except, except,
     89   true,  false, except, except,   true,   true, except, except,
     90  false,   true, except, except,  false,   true, except, except,
     91   true,   true, except, except,   true,   true, except, except,
     92 except, except, except, except, except, except, except, except,
     93 except, except, except, except, except, except, except, except,
     94 except, except, except, except, except, except, except, except,
     95 except, except, except, except, except, except, except, except,
     96  false,  false,   true,   true,  false,  false,   true,   true,
     97   true,  false,  false,   true,  false,  false,   true,   true,
     98  false,   true,   true,  false,   true,   true,  false,  false,
     99   true,   true,  false,  false,   true,   true,  false,  false,
    100 except, except,   true,   true, except, except,   true,   true,
    101 except, except,  false,   true, except, except,   true,   true,
    102 except, except,   true,  false, except, except,  false,  false,
    103 except, except,  false,  false, except, except,  false,  false,
    104  false,  false, except, except,  false,  false, except, except,
    105   true,  false, except, except,  false,  false, except, except,
    106  false,   true, except, except,   true,   true, except, except,
    107   true,   true, except, except,   true,   true, except, except,
    108 except, except, except, except, except, except, except, except,
    109 except, except, except, except, except, except, except, except,
    110 except, except, except, except, except, except, except, except,
    111 except, except, except, except, except, except, except, except,
    112  false,  false,   true,   true,  false,  false,   true,   true,
    113   true,  false,  false,   true,  false,  false,   true,   true,
    114  false,   true,   true,  false,   true,   true,  false,  false,
    115   true,   true,  false,  false,   true,   true,  false,  false,
    116 except, except,   true,   true, except, except,   true,   true,
    117 except, except,  false,   true, except, except,   true,   true,
    118 except, except,   true,  false, except, except,  false,  false,
    119 except, except,  false,  false, except, except,  false,  false,
    120  false,  false, except, except,  false,  false, except, except,
    121   true,  false, except, except,  false,  false, except, except,
    122  false,   true, except, except,   true,   true, except, except,
    123   true,   true, except, except,   true,   true, except, except,
    124 except, except, except, except, except, except, except, except,
    125 except, except, except, except, except, except, except, except,
    126 except, except, except, except, except, except, except, except,
    127 except, except, except, except, except, except, except, except,
    128  false,  false,   true,   true,   true,   true,  false,  false,
    129   true,  false,  false,   true,   true,   true,  false,  false,
    130  false,   true,   true,  false,   true,   true,  false,  false,
    131   true,   true,  false,  false,   true,   true,  false,  false,
    132 except, except,   true,   true, except, except,   true,   true,
    133 except, except,  false,   true, except, except,   true,   true,
    134 except, except,   true,  false, except, except,  false,  false,
    135 except, except,  false,  false, except, except,  false,  false,
    136  false,  false, except, except,   true,   true, except, except,
    137   true,  false, except, except,   true,   true, except, except,
    138  false,   true, except, except,   true,   true, except, except,
    139   true,   true, except, except,   true,   true, except, except,
    140 except, except, except, except, except, except, except, except,
    141 except, except, except, except, except, except, except, except,
    142 except, except, except, except, except, except, except, except,
    143 except, except, except, except, except, except, except, except,
    144  false,  false,   true,   true,   true,   true,  false,  false,
    145   true,  false,  false,   true,   true,   true,  false,  false,
    146  false,   true,   true,  false,   true,   true,  false,  false,
    147   true,   true,  false,  false,   true,   true,  false,  false,
    148 except, except,   true,   true, except, except,   true,   true,
    149 except, except,  false,   true, except, except,   true,   true,
    150 except, except,   true,  false, except, except,  false,  false,
    151 except, except,  false,  false, except, except,  false,  false,
    152  false,  false, except, except,   true,   true, except, except,
    153   true,  false, except, except,   true,   true, except, except,
    154  false,   true, except, except,   true,   true, except, except,
    155   true,   true, except, except,   true,   true, except, except,
    156 except, except, except, except, except, except, except, except,
    157 except, except, except, except, except, except, except, except,
    158 except, except, except, except, except, except, except, except,
    159 except, except, except, except, except, except, except, except,
    160  false,  false,   true,   true,  false,  false,   true,   true,
    161   true,  false,  false,   true,   true,   true,  false,  false,
    162  false,   true,   true,  false,  false,  false,   true,   true,
    163   true,   true,  false,  false,   true,   true,  false,  false,
    164 except, except,   true,   true, except, except,   true,   true,
    165 except, except,  false,   true, except, except,  false,  false,
    166 except, except,   true,  false, except, except,   true,   true,
    167 except, except,  false,  false, except, except,  false,  false,
    168  false,  false, except, except,  false,  false, except, except,
    169   true,  false, except, except,   true,   true, except, except,
    170  false,   true, except, except,  false,  false, except, except,
    171   true,   true, except, except,   true,   true, except, except,
    172 except, except, except, except, except, except, except, except,
    173 except, except, except, except, except, except, except, except,
    174 except, except, except, except, except, except, except, except,
    175 except, except, except, except, except, except, except, except,
    176  false,  false,   true,   true,  false,  false,   true,   true,
    177   true,  false,  false,   true,  false,  false,   true,   true,
    178  false,   true,   true,  false,  false,  false,   true,   true,
    179   true,   true,  false,  false,  false,  false,   true,   true,
    180 except, except,   true,   true, except, except,   true,   true,
    181 except, except,  false,   true, except, except,   true,   true,
    182 except, except,   true,  false, except, except,   true,   true,
    183 except, except,  false,  false, except, except,   true,   true,
    184  false,  false, except, except,  false,  false, except, except,
    185   true,  false, except, except,   true,   true, except, except,
    186  false,   true, except, except,  false,  false, except, except,
    187   true,   true, except, except,   true,   true, except, except,
    188 except, except, except, except, except, except, except, except,
    189 except, except, except, except, except, except, except, except,
    190 except, except, except, except, except, except, except, except,
    191 except, except, except, except, except, except, except, except,
    192  false,  false,   true,   true,  false,  false,   true,   true,
    193   true,  false,  false,   true,   true,   true,  false,  false,
    194  false,   true,   true,  false,  false,  false,   true,   true,
    195   true,   true,  false,  false,   true,   true,  false,  false,
    196 except, except,   true,   true, except, except,   true,   true,
    197 except, except,  false,   true, except, except,  false,  false,
    198 except, except,   true,  false, except, except,   true,   true,
    199 except, except,  false,  false, except, except,  false,  false,
    200  false,  false, except, except,  false,  false, except, except,
    201   true,  false, except, except,   true,   true, except, except,
    202  false,   true, except, except,  false,  false, except, except,
    203   true,   true, except, except,   true,   true, except, except,
    204 except, except, except, except, except, except, except, except,
    205 except, except, except, except, except, except, except, except,
    206 except, except, except, except, except, except, except, except,
    207 except, except, except, except, except, except, except, except,
    208  false,  false,   true,   true,  false,  false,   true,   true,
    209   true,  false,  false,   true,  false,  false,   true,   true,
    210  false,   true,   true,  false,  false,  false,   true,   true,
    211   true,   true,  false,  false,  false,  false,   true,   true,
    212 except, except,   true,   true, except, except,   true,   true,
    213 except, except,  false,   true, except, except,   true,   true,
    214 except, except,   true,  false, except, except,   true,   true,
    215 except, except,  false,  false, except, except,   true,   true,
    216  false,  false, except, except,  false,  false, except, except,
    217   true,  false, except, except,   true,   true, except, except,
    218  false,   true, except, except,  false,  false, except, except,
    219   true,   true, except, except,   true,   true, except, except,
    220 except, except, except, except, except, except, except, except,
    221 except, except, except, except, except, except, except, except,
    222 except, except, except, except, except, except, except, except,
    223 except, except, except, except, except, except, except, except,
    224  false,  false,   true,   true,  false,  false,   true,   true,
    225   true,  false,  false,   true,  false,  false,   true,   true,
    226  false,   true,   true,  false,   true,   true,  false,  false,
    227   true,   true,  false,  false,   true,   true,  false,  false,
    228 except, except,   true,   true, except, except,   true,   true,
    229 except, except,  false,   true, except, except,   true,   true,
    230 except, except,   true,  false, except, except,  false,  false,
    231 except, except,  false,  false, except, except,  false,  false,
    232  false,  false, except, except,  false,  false, except, except,
    233   true,  false, except, except,  false,  false, except, except,
    234  false,   true, except, except,   true,   true, except, except,
    235   true,   true, except, except,   true,   true, except, except,
    236 except, except, except, except, except, except, except, except,
    237 except, except, except, except, except, except, except, except,
    238 except, except, except, except, except, except, except, except,
    239 except, except, except, except, except, except, except, except,
    240  false,  false,   true,   true,  false,  false,   true,   true,
    241   true,  false,  false,   true,  false,  false,   true,   true,
    242  false,   true,   true,  false,   true,   true,  false,  false,
    243   true,   true,  false,  false,   true,   true,  false,  false,
    244 except, except,   true,   true, except, except,   true,   true,
    245 except, except,  false,   true, except, except,   true,   true,
    246 except, except,   true,  false, except, except,  false,  false,
    247 except, except,  false,  false, except, except,  false,  false,
    248  false,  false, except, except,  false,  false, except, except,
    249   true,  false, except, except,  false,  false, except, except,
    250  false,   true, except, except,   true,   true, except, except,
    251   true,   true, except, except,   true,   true, except, except,
    252 except, except, except, except, except, except, except, except,
    253 except, except, except, except, except, except, except, except,
    254 except, except, except, except, except, except, except, except,
    255 except, except, except, except, except, except, except, except,
    256  false,  false,   true,   true,   true,   true,  false,  false,
    257   true,  false,  false,   true,   true,   true,  false,  false,
    258  false,   true,   true,  false,   true,   true,  false,  false,
    259   true,   true,  false,  false,   true,   true,  false,  false,
    260 except, except,   true,   true, except, except,   true,   true,
    261 except, except,  false,   true, except, except,   true,   true,
    262 except, except,   true,  false, except, except,  false,  false,
    263 except, except,  false,  false, except, except,  false,  false,
    264  false,  false, except, except,   true,   true, except, except,
    265   true,  false, except, except,   true,   true, except, except,
    266  false,   true, except, except,   true,   true, except, except,
    267   true,   true, except, except,   true,   true, except, except,
    268 except, except, except, except, except, except, except, except,
    269 except, except, except, except, except, except, except, except,
    270 except, except, except, except, except, except, except, except,
    271 except, except, except, except, except, except, except, except,
    272  false,  false,   true,   true,   true,   true,  false,  false,
    273   true,  false,  false,   true,   true,   true,  false,  false,
    274  false,   true,   true,  false,   true,   true,  false,  false,
    275   true,   true,  false,  false,   true,   true,  false,  false,
    276 except, except,   true,   true, except, except,   true,   true,
    277 except, except,  false,   true, except, except,   true,   true,
    278 except, except,   true,  false, except, except,  false,  false,
    279 except, except,  false,  false, except, except,  false,  false,
    280  false,  false, except, except,   true,   true, except, except,
    281   true,  false, except, except,   true,   true, except, except,
    282  false,   true, except, except,   true,   true, except, except,
    283   true,   true, except, except,   true,   true, except, except,
    284 except, except, except, except, except, except, except, except,
    285 except, except, except, except, except, except, except, except,
    286 except, except, except, except, except, except, except, except,
    287 except, except, except, except, except, except, except, except];
    288 
    289 for (var i = 0; i < 256; i++) {
    290   Test(i & 1, i & 2, i & 4, i & 8, i & 0x10, i & 0x20, i & 0x40, i & 0x80);
    291 }
    292 
    293 
    294 function InstanceTest(x, func) {
    295   try {
    296     var answer = (x instanceof func);
    297     assertEquals(correct_answers[correct_answer_index], answer);
    298   } catch (e) {
    299     assertTrue(/prototype/.test(e));
    300     assertEquals(correct_answers[correct_answer_index], except);
    301   }
    302   correct_answer_index++;
    303 }
    304 
    305 
    306 function Test(a, b, c, d, e, f, g, h) {
    307   var Foo = function() { }
    308   var Bar = function() { }
    309 
    310   if (c) Foo.prototype = 12;
    311   if (d) Bar.prototype = 13;
    312   var x = a ? new Foo() : new Bar();
    313   var y = b ? new Foo() : new Bar();
    314   InstanceTest(x, Foo);
    315   InstanceTest(y, Foo);
    316   InstanceTest(x, Bar);
    317   InstanceTest(y, Bar);
    318   if (e) x.__proto__ = Bar.prototype;
    319   if (f) y.__proto__ = Foo.prototype;
    320   if (g) {
    321     x.__proto__ = y;
    322   } else {
    323     if (h) y.__proto__ = x
    324   }
    325   InstanceTest(x, Foo);
    326   InstanceTest(y, Foo);
    327   InstanceTest(x, Bar);
    328   InstanceTest(y, Bar);
    329 }
    330