Home | History | Annotate | Download | only in mjsunit
      1 // Copyright 2008 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 
     29 function TestFunctionNames(object, names) {
     30   for (var i = 0; i < names.length; i++) {
     31     assertEquals(names[i], object[names[i]].name);
     32   }
     33 }
     34 
     35 
     36 // Array.prototype functions.
     37 var arrayPrototypeFunctions = [
     38     "toString", "toLocaleString", "join", "pop", "push", "concat", "reverse",
     39     "shift", "unshift", "slice", "splice", "sort", "filter", "forEach",
     40     "some", "every", "map", "indexOf", "lastIndexOf"];
     41 
     42 TestFunctionNames(Array.prototype, arrayPrototypeFunctions);
     43 
     44 
     45 // Boolean prototype functions.
     46 var booleanPrototypeFunctions = [ "toString", "valueOf" ];
     47 
     48 TestFunctionNames(Boolean.prototype, booleanPrototypeFunctions);
     49 
     50 
     51 // Date functions.
     52 var dateFunctions = ["UTC", "parse", "now"];
     53 
     54 TestFunctionNames(Date, dateFunctions);
     55 
     56 
     57 // Date.prototype functions.
     58 var datePrototypeFunctions = [
     59     "toString", "toDateString", "toTimeString", "toLocaleString",
     60     "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime",
     61     "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth",
     62     "getDate", "getUTCDate", "getDay", "getUTCDay", "getHours",
     63     "getUTCHours", "getMinutes", "getUTCMinutes", "getSeconds",
     64     "getUTCSeconds", "getMilliseconds", "getUTCMilliseconds",
     65     "getTimezoneOffset", "setTime", "setMilliseconds",
     66     "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes",
     67     "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate",
     68     "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "toGMTString",
     69     "toUTCString", "getYear", "setYear"];
     70 
     71 TestFunctionNames(Date.prototype, datePrototypeFunctions);
     72 
     73 
     74 // Function.prototype functions.
     75 var functionPrototypeFunctions = [ "toString", "apply", "call" ];
     76 
     77 TestFunctionNames(Function.prototype, functionPrototypeFunctions);
     78 
     79 // Math functions.
     80 var mathFunctions = [
     81     "random", "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor",
     82     "log", "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min"];
     83 
     84 TestFunctionNames(Math, mathFunctions);
     85 
     86 
     87 // Number.prototype functions.
     88 var numberPrototypeFunctions = [
     89     "toString", "toLocaleString", "valueOf", "toFixed", "toExponential",
     90     "toPrecision"];
     91 
     92 TestFunctionNames(Number.prototype, numberPrototypeFunctions);
     93 
     94 // Object.prototype functions.
     95 var objectPrototypeFunctions = [
     96     "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf",
     97     "propertyIsEnumerable", "__defineGetter__", "__lookupGetter__",
     98     "__defineSetter__", "__lookupSetter__"];
     99 
    100 TestFunctionNames(Object.prototype, objectPrototypeFunctions);
    101 
    102 // RegExp.prototype functions.
    103 var regExpPrototypeFunctions = ["exec", "test", "toString", "compile"];
    104 
    105 TestFunctionNames(RegExp.prototype, regExpPrototypeFunctions);
    106 
    107 // String functions.
    108 var stringFunctions = ["fromCharCode"];
    109 
    110 TestFunctionNames(String, stringFunctions);
    111 
    112 
    113 // String.prototype functions.
    114 var stringPrototypeFunctions = [
    115     "toString", "valueOf", "charAt", "charCodeAt", "concat", "indexOf",
    116     "lastIndexOf", "localeCompare", "match", "replace", "search", "slice",
    117     "split", "substring", "substr", "toLowerCase", "toLocaleLowerCase",
    118     "toUpperCase", "toLocaleUpperCase", "link", "anchor", "fontcolor",
    119     "fontsize", "big", "blink", "bold", "fixed", "italics", "small",
    120     "strike", "sub", "sup"];
    121 
    122 TestFunctionNames(String.prototype, stringPrototypeFunctions);
    123 
    124 
    125 // Global functions.
    126 var globalFunctions = [
    127     "escape", "unescape", "decodeURI", "decodeURIComponent",
    128     "encodeURI", "encodeURIComponent", "Error", "TypeError",
    129     "RangeError", "SyntaxError", "ReferenceError", "EvalError",
    130     "URIError", "isNaN", "isFinite", "parseInt", "parseFloat",
    131     "eval"];
    132 
    133 TestFunctionNames(this, globalFunctions);
    134