• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
29function 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.
37var arrayPrototypeFunctions = [
38    "toString", "toLocaleString", "join", "pop", "push", "concat", "reverse",
39    "shift", "unshift", "slice", "splice", "sort", "filter", "forEach",
40    "some", "every", "map", "indexOf", "lastIndexOf"];
41
42TestFunctionNames(Array.prototype, arrayPrototypeFunctions);
43
44
45// Boolean prototype functions.
46var booleanPrototypeFunctions = [ "toString", "valueOf" ];
47
48TestFunctionNames(Boolean.prototype, booleanPrototypeFunctions);
49
50
51// Date functions.
52var dateFunctions = ["UTC", "parse", "now"];
53
54TestFunctionNames(Date, dateFunctions);
55
56
57// Date.prototype functions.
58var 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",
69    "toUTCString", "getYear", "setYear"];
70
71TestFunctionNames(Date.prototype, datePrototypeFunctions);
72assertEquals(Date.prototype.toGMTString, Date.prototype.toUTCString);
73
74
75// Function.prototype functions.
76var functionPrototypeFunctions = [ "toString", "apply", "call" ];
77
78TestFunctionNames(Function.prototype, functionPrototypeFunctions);
79
80// Math functions.
81var mathFunctions = [
82    "random", "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor",
83    "log", "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min"];
84
85TestFunctionNames(Math, mathFunctions);
86
87
88// Number.prototype functions.
89var numberPrototypeFunctions = [
90    "toString", "toLocaleString", "valueOf", "toFixed", "toExponential",
91    "toPrecision"];
92
93TestFunctionNames(Number.prototype, numberPrototypeFunctions);
94
95// Object.prototype functions.
96var objectPrototypeFunctions = [
97    "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf",
98    "propertyIsEnumerable", "__defineGetter__", "__lookupGetter__",
99    "__defineSetter__", "__lookupSetter__"];
100
101TestFunctionNames(Object.prototype, objectPrototypeFunctions);
102
103// RegExp.prototype functions.
104var regExpPrototypeFunctions = ["exec", "test", "toString", "compile"];
105
106TestFunctionNames(RegExp.prototype, regExpPrototypeFunctions);
107
108// String functions.
109var stringFunctions = ["fromCharCode"];
110
111TestFunctionNames(String, stringFunctions);
112
113
114// String.prototype functions.
115var stringPrototypeFunctions = [
116    "toString", "valueOf", "charAt", "charCodeAt", "concat", "indexOf",
117    "lastIndexOf", "localeCompare", "match", "replace", "search", "slice",
118    "split", "substring", "substr", "toLowerCase", "toLocaleLowerCase",
119    "toUpperCase", "toLocaleUpperCase", "link", "anchor", "fontcolor",
120    "fontsize", "big", "blink", "bold", "fixed", "italics", "small",
121    "strike", "sub", "sup"];
122
123TestFunctionNames(String.prototype, stringPrototypeFunctions);
124
125
126// Global functions.
127var globalFunctions = [
128    "escape", "unescape", "decodeURI", "decodeURIComponent",
129    "encodeURI", "encodeURIComponent", "Error", "TypeError",
130    "RangeError", "SyntaxError", "ReferenceError", "EvalError",
131    "URIError", "isNaN", "isFinite", "parseInt", "parseFloat",
132    "eval"];
133
134TestFunctionNames(this, globalFunctions);
135