tostring.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function write(v) { WScript.Echo(v + ""); }
  6. var errorCount = 0;
  7. // global
  8. var globalList = [
  9. ["eval",1],
  10. ["parseInt",2],
  11. ["parseFloat",1],
  12. ["isNaN",1],
  13. ["isFinite",1],
  14. ["decodeURI",1],
  15. ["encodeURI",1],
  16. ["decodeURIComponent",1],
  17. ["encodeURIComponent",1],
  18. ["Object",0],
  19. ["Function",1],
  20. ["Array",1],
  21. ["String",1],
  22. ["Boolean",1],
  23. ["Number",1],
  24. ["Date",7],
  25. ["RegExp",2],
  26. ["Error",1],
  27. ["EvalError",1],
  28. ["RangeError",1],
  29. ["ReferenceError",1],
  30. ["SyntaxError",1],
  31. ["TypeError",1],
  32. ["URIError",1]
  33. ]
  34. // Object
  35. var objList = [
  36. //TODO ["constructor",0],
  37. ["toString",0],
  38. ["toLocaleString",0],
  39. ["valueOf",0],
  40. ["hasOwnProperty",1] ,
  41. ["isPrototypeOf",1] ,
  42. ["propertyIsEnumerable",1]
  43. ]
  44. // Function
  45. var funcList = [
  46. ["constructor",1],
  47. ["toString",0],
  48. ["apply",2 ],
  49. ["call", 1]
  50. ]
  51. // Array
  52. var arrList = [
  53. // FuncName, length
  54. ["constructor",1],
  55. ["toString",0],
  56. ["toLocaleString", 0],
  57. ["concat", 1],
  58. ["join",1],
  59. ["pop",0],
  60. ["push",1],
  61. ["reverse",0],
  62. ["shift",0],
  63. ["slice",2],
  64. ["sort",1],
  65. ["splice",2],
  66. ["unshift",1]
  67. ];
  68. // String
  69. var stringList = [
  70. ["constructor",1],
  71. ["toString",0],
  72. ["valueOf",0],
  73. ["charAt",1],
  74. ["charCodeAt",1],
  75. ["concat",1],
  76. ["indexOf",2],
  77. ["lastIndexOf",2],
  78. ["localeCompare",1],
  79. ["match",1],
  80. ["replace",1],
  81. ["search",0],
  82. ["slice",0],
  83. ["split",2],
  84. ["substring",2],
  85. ["toLowerCase",0],
  86. ["toLocaleLowerCase",0],
  87. ["toUpperCase",0],
  88. ["toLocaleUpperCase",0],
  89. // not in ECMA spec
  90. ["anchor",1],
  91. ["big",0],
  92. ["blink",0],
  93. ["bold",0],
  94. ["fixed",0],
  95. ["fontcolor",1],
  96. ["fontsize",1],
  97. ["italics",0],
  98. ["link",1],
  99. ["small",0],
  100. ["strike",0],
  101. ["sub",0],
  102. ["sup",0],
  103. ["substr",2]
  104. ]
  105. var stringList2 = [
  106. ["fromCharCode", 0]
  107. ];
  108. // Boolean
  109. var boolList = [
  110. ["constructor",1],
  111. ["toString",0],
  112. ["valueOf",0]
  113. ]
  114. //Number
  115. var numberList = [
  116. ["constructor",1],
  117. ["toString",1],
  118. ["toLocaleString",0],
  119. ["valueOf",0],
  120. ["toFixed",1],
  121. ["toExponential",1],
  122. ["toPrecision",1]
  123. ]
  124. // Math object is a single object - 18
  125. var mathList = [
  126. ["abs",1],
  127. ["acos",1],
  128. ["asin",1],
  129. ["atan",1],
  130. ["atan2",2],
  131. ["ceil",1],
  132. ["cos",1],
  133. ["exp",1],
  134. ["floor",1],
  135. ["log",1],
  136. ["max",2],
  137. ["min",2],
  138. ["pow",2],
  139. ["random",0],
  140. ["round",1],
  141. ["sin",1],
  142. ["sqrt",1],
  143. ["tan",1]
  144. ]
  145. // Date Prototype object
  146. var dateList = [
  147. ["constructor",7],
  148. ["toString",0],
  149. ["toDateString",0],
  150. ["toTimeString",0],
  151. ["toLocaleString",0],
  152. ["toLocaleDateString",0],
  153. ["valueOf",0],
  154. ["getTime",0],
  155. ["getFullYear",0],
  156. ["getUTCFullYear",0],
  157. ["getMonth",0],
  158. ["getUTCMonth",0],
  159. ["getDate",0],
  160. ["getUTCDate",0],
  161. ["getDay",0],
  162. ["getUTCDay",0],
  163. ["getHours",0],
  164. ["getUTCHours",0],
  165. ["getMinutes",0],
  166. ["getUTCMinutes",0],
  167. ["getSeconds",0],
  168. ["getUTCSeconds",0],
  169. ["getMilliseconds",0],
  170. ["getUTCMilliseconds",0],
  171. ["getTimezoneOffset",0],
  172. ["setTime",1],
  173. ["setMilliseconds",1],
  174. ["setUTCMilliseconds",1],
  175. ["setSeconds",2],
  176. ["setUTCSeconds",2],
  177. ["setMinutes",3],
  178. ["setUTCMinutes",3],
  179. ["setHours",4],
  180. ["setUTCHours",4],
  181. ["setDate",1],
  182. ["setUTCDate",1],
  183. ["setMonth",2],
  184. ["setUTCMonth",2],
  185. ["setFullYear",3],
  186. ["setUTCFullYear",3],
  187. ["toUTCString",0],
  188. ["toGMTString",0],
  189. ["toLocaleTimeString",0 ],
  190. ["toUTCString",0],
  191. ["setYear",1],
  192. ["getYear",0]
  193. ]
  194. // static date functions
  195. var dateList2 = [
  196. ["parse",1],
  197. ["UTC",7]
  198. ]
  199. // RegExp object
  200. var regxpList = [
  201. ["constructor",2],
  202. ["exec",1],
  203. ["test",1],
  204. ["toString",0] //,
  205. // not in ECMA spec
  206. // TODO ["compile",2]
  207. ]
  208. // Error object
  209. var errorList = [
  210. ["constructor",1],
  211. ["name",5],
  212. ["message",0],
  213. ["toString",0]
  214. ]
  215. function doEval(scen) {
  216. try {
  217. var res = eval(scen);
  218. write(res);
  219. } catch (e) {
  220. write(" Exception: " + scen + ". :: " + e.message);
  221. }
  222. }
  223. var somevar = 0;
  224. function TestToString(list, str) {
  225. for (var i=0; i<list.length; i++) {
  226. var fname = list[i][0];
  227. var fullStr = str+fname+".toString()";
  228. doEval(fullStr);
  229. }
  230. }
  231. TestToString(globalList,"");
  232. TestToString(objList, "Object.prototype.");
  233. TestToString(funcList, "Function.prototype.");
  234. TestToString(arrList, "Array.prototype.");
  235. TestToString(stringList, "String.prototype.");
  236. TestToString(stringList2, "String.");
  237. TestToString(boolList, "Boolean.prototype.");
  238. TestToString(numberList, "Number.prototype.");
  239. TestToString(mathList, "Math.");
  240. TestToString(dateList, "Date.prototype.");
  241. TestToString(dateList2,"Date.");
  242. TestToString(regxpList, "RegExp.prototype.");
  243. TestToString(errorList, "Error.prototype.");
  244. if ( errorCount > 0 ) {
  245. throw Error(errorCount + " Test(s) Failed");
  246. }