distil 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (552) hide show
  1. data/Rakefile +28 -0
  2. data/VERSION +1 -0
  3. data/bin/distil +45 -0
  4. data/distil.gemspec +586 -0
  5. data/lib/bootstrap-template.js +56 -0
  6. data/lib/configurable.rb +125 -0
  7. data/lib/file-set.rb +42 -0
  8. data/lib/file-types/css-file.rb +75 -0
  9. data/lib/file-types/html-file.rb +11 -0
  10. data/lib/file-types/javascript-file.rb +98 -0
  11. data/lib/file-types/json-file.rb +14 -0
  12. data/lib/file-types/nib-file.rb +9 -0
  13. data/lib/jsdoc.conf +18 -0
  14. data/lib/jsl.conf +121 -0
  15. data/lib/project.rb +96 -0
  16. data/lib/source-file.rb +181 -0
  17. data/lib/target.rb +96 -0
  18. data/lib/task.rb +239 -0
  19. data/lib/tasks/copy-task.rb +21 -0
  20. data/lib/tasks/css-task.rb +18 -0
  21. data/lib/tasks/javascript-task.rb +125 -0
  22. data/lib/tasks/multiple-output-task.rb +134 -0
  23. data/lib/tasks/nib-task.rb +83 -0
  24. data/lib/tasks/output-task.rb +73 -0
  25. data/lib/tasks/single-output-task.rb +83 -0
  26. data/lib/tasks/test-task.rb +280 -0
  27. data/lib/test/HtmlTestReporter.js +127 -0
  28. data/lib/test/Test.js +248 -0
  29. data/lib/test/TestReporter.js +79 -0
  30. data/lib/test/TestRunner.js +132 -0
  31. data/lib/test/browser.rb +97 -0
  32. data/lib/test/scriptwrapper.html +10 -0
  33. data/lib/test/unittest.html +127 -0
  34. data/vendor/Makefile +35 -0
  35. data/vendor/extconf.rb +3 -0
  36. data/vendor/jsdoc-extras/plugins/distil-plugin.js +142 -0
  37. data/vendor/jsdoc-extras/plugins/interface-plugin.js +36 -0
  38. data/vendor/jsdoc-extras/templates/coherent/allclasses.tmpl +17 -0
  39. data/vendor/jsdoc-extras/templates/coherent/allfiles.tmpl +53 -0
  40. data/vendor/jsdoc-extras/templates/coherent/class.tmpl +803 -0
  41. data/vendor/jsdoc-extras/templates/coherent/index.tmpl +37 -0
  42. data/vendor/jsdoc-extras/templates/coherent/publish.js +242 -0
  43. data/vendor/jsdoc-extras/templates/coherent/showdown.js +421 -0
  44. data/vendor/jsdoc-extras/templates/coherent/static/code-footer.html +3 -0
  45. data/vendor/jsdoc-extras/templates/coherent/static/code-header.html +7 -0
  46. data/vendor/jsdoc-extras/templates/coherent/static/default.css +297 -0
  47. data/vendor/jsdoc-extras/templates/coherent/static/header.html +2 -0
  48. data/vendor/jsdoc-extras/templates/coherent/static/index.html +19 -0
  49. data/vendor/jsdoc-extras/templates/coherent/symbol.tmpl +35 -0
  50. data/vendor/jsdoc-toolkit/README.txt +183 -0
  51. data/vendor/jsdoc-toolkit/app/frame/Chain.js +102 -0
  52. data/vendor/jsdoc-toolkit/app/frame/Dumper.js +144 -0
  53. data/vendor/jsdoc-toolkit/app/frame/Hash.js +84 -0
  54. data/vendor/jsdoc-toolkit/app/frame/Link.js +171 -0
  55. data/vendor/jsdoc-toolkit/app/frame/Namespace.js +10 -0
  56. data/vendor/jsdoc-toolkit/app/frame/Opt.js +134 -0
  57. data/vendor/jsdoc-toolkit/app/frame/Reflection.js +26 -0
  58. data/vendor/jsdoc-toolkit/app/frame/String.js +93 -0
  59. data/vendor/jsdoc-toolkit/app/frame/Testrun.js +129 -0
  60. data/vendor/jsdoc-toolkit/app/frame.js +33 -0
  61. data/vendor/jsdoc-toolkit/app/handlers/FOODOC.js +26 -0
  62. data/vendor/jsdoc-toolkit/app/handlers/XMLDOC/DomReader.js +159 -0
  63. data/vendor/jsdoc-toolkit/app/handlers/XMLDOC/XMLDoc.js +16 -0
  64. data/vendor/jsdoc-toolkit/app/handlers/XMLDOC/XMLParse.js +292 -0
  65. data/vendor/jsdoc-toolkit/app/handlers/XMLDOC.js +26 -0
  66. data/vendor/jsdoc-toolkit/app/lib/JSDOC/DocComment.js +204 -0
  67. data/vendor/jsdoc-toolkit/app/lib/JSDOC/DocTag.js +300 -0
  68. data/vendor/jsdoc-toolkit/app/lib/JSDOC/JsDoc.js +126 -0
  69. data/vendor/jsdoc-toolkit/app/lib/JSDOC/JsPlate.js +109 -0
  70. data/vendor/jsdoc-toolkit/app/lib/JSDOC/Lang.js +144 -0
  71. data/vendor/jsdoc-toolkit/app/lib/JSDOC/Parser.js +144 -0
  72. data/vendor/jsdoc-toolkit/app/lib/JSDOC/PluginManager.js +33 -0
  73. data/vendor/jsdoc-toolkit/app/lib/JSDOC/Symbol.js +644 -0
  74. data/vendor/jsdoc-toolkit/app/lib/JSDOC/SymbolSet.js +241 -0
  75. data/vendor/jsdoc-toolkit/app/lib/JSDOC/TextStream.js +41 -0
  76. data/vendor/jsdoc-toolkit/app/lib/JSDOC/Token.js +18 -0
  77. data/vendor/jsdoc-toolkit/app/lib/JSDOC/TokenReader.js +332 -0
  78. data/vendor/jsdoc-toolkit/app/lib/JSDOC/TokenStream.js +133 -0
  79. data/vendor/jsdoc-toolkit/app/lib/JSDOC/Util.js +32 -0
  80. data/vendor/jsdoc-toolkit/app/lib/JSDOC/Walker.js +499 -0
  81. data/vendor/jsdoc-toolkit/app/lib/JSDOC.js +106 -0
  82. data/vendor/jsdoc-toolkit/app/main.js +129 -0
  83. data/vendor/jsdoc-toolkit/app/plugins/commentSrcJson.js +20 -0
  84. data/vendor/jsdoc-toolkit/app/plugins/frameworkPrototype.js +16 -0
  85. data/vendor/jsdoc-toolkit/app/plugins/functionCall.js +10 -0
  86. data/vendor/jsdoc-toolkit/app/plugins/publishSrcHilite.js +54 -0
  87. data/vendor/jsdoc-toolkit/app/plugins/symbolLink.js +10 -0
  88. data/vendor/jsdoc-toolkit/app/plugins/tagParamConfig.js +31 -0
  89. data/vendor/jsdoc-toolkit/app/plugins/tagSynonyms.js +43 -0
  90. data/vendor/jsdoc-toolkit/app/run.js +348 -0
  91. data/vendor/jsdoc-toolkit/app/t/TestDoc.js +144 -0
  92. data/vendor/jsdoc-toolkit/app/t/runner.js +13 -0
  93. data/vendor/jsdoc-toolkit/app/test/addon.js +24 -0
  94. data/vendor/jsdoc-toolkit/app/test/anon_inner.js +14 -0
  95. data/vendor/jsdoc-toolkit/app/test/augments.js +31 -0
  96. data/vendor/jsdoc-toolkit/app/test/augments2.js +26 -0
  97. data/vendor/jsdoc-toolkit/app/test/borrows.js +46 -0
  98. data/vendor/jsdoc-toolkit/app/test/borrows2.js +23 -0
  99. data/vendor/jsdoc-toolkit/app/test/config.js +22 -0
  100. data/vendor/jsdoc-toolkit/app/test/constructs.js +18 -0
  101. data/vendor/jsdoc-toolkit/app/test/encoding.js +10 -0
  102. data/vendor/jsdoc-toolkit/app/test/encoding_other.js +12 -0
  103. data/vendor/jsdoc-toolkit/app/test/event.js +54 -0
  104. data/vendor/jsdoc-toolkit/app/test/exports.js +14 -0
  105. data/vendor/jsdoc-toolkit/app/test/functions_anon.js +39 -0
  106. data/vendor/jsdoc-toolkit/app/test/functions_nested.js +33 -0
  107. data/vendor/jsdoc-toolkit/app/test/global.js +13 -0
  108. data/vendor/jsdoc-toolkit/app/test/globals.js +25 -0
  109. data/vendor/jsdoc-toolkit/app/test/ignore.js +10 -0
  110. data/vendor/jsdoc-toolkit/app/test/inner.js +16 -0
  111. data/vendor/jsdoc-toolkit/app/test/jsdoc_test.js +477 -0
  112. data/vendor/jsdoc-toolkit/app/test/lend.js +33 -0
  113. data/vendor/jsdoc-toolkit/app/test/memberof.js +19 -0
  114. data/vendor/jsdoc-toolkit/app/test/memberof2.js +38 -0
  115. data/vendor/jsdoc-toolkit/app/test/memberof3.js +33 -0
  116. data/vendor/jsdoc-toolkit/app/test/memberof_constructor.js +17 -0
  117. data/vendor/jsdoc-toolkit/app/test/module.js +17 -0
  118. data/vendor/jsdoc-toolkit/app/test/name.js +19 -0
  119. data/vendor/jsdoc-toolkit/app/test/namespace_nested.js +23 -0
  120. data/vendor/jsdoc-toolkit/app/test/nocode.js +13 -0
  121. data/vendor/jsdoc-toolkit/app/test/oblit_anon.js +20 -0
  122. data/vendor/jsdoc-toolkit/app/test/overview.js +20 -0
  123. data/vendor/jsdoc-toolkit/app/test/param_inline.js +37 -0
  124. data/vendor/jsdoc-toolkit/app/test/params_optional.js +8 -0
  125. data/vendor/jsdoc-toolkit/app/test/prototype.js +17 -0
  126. data/vendor/jsdoc-toolkit/app/test/prototype_nested.js +9 -0
  127. data/vendor/jsdoc-toolkit/app/test/prototype_oblit.js +13 -0
  128. data/vendor/jsdoc-toolkit/app/test/prototype_oblit_constructor.js +24 -0
  129. data/vendor/jsdoc-toolkit/app/test/public.js +10 -0
  130. data/vendor/jsdoc-toolkit/app/test/scripts/code.js +5 -0
  131. data/vendor/jsdoc-toolkit/app/test/scripts/notcode.txt +5 -0
  132. data/vendor/jsdoc-toolkit/app/test/shared.js +42 -0
  133. data/vendor/jsdoc-toolkit/app/test/shared2.js +2 -0
  134. data/vendor/jsdoc-toolkit/app/test/shortcuts.js +22 -0
  135. data/vendor/jsdoc-toolkit/app/test/static_this.js +13 -0
  136. data/vendor/jsdoc-toolkit/app/test/synonyms.js +31 -0
  137. data/vendor/jsdoc-toolkit/app/test/tosource.js +23 -0
  138. data/vendor/jsdoc-toolkit/app/test/variable_redefine.js +14 -0
  139. data/vendor/jsdoc-toolkit/app/test.js +342 -0
  140. data/vendor/jsdoc-toolkit/changes.txt +116 -0
  141. data/vendor/jsdoc-toolkit/conf/sample.conf +31 -0
  142. data/vendor/jsdoc-toolkit/java/build.xml +36 -0
  143. data/vendor/jsdoc-toolkit/java/build_1.4.xml +36 -0
  144. data/vendor/jsdoc-toolkit/java/classes/js.jar +0 -0
  145. data/vendor/jsdoc-toolkit/java/src/JsDebugRun.java +21 -0
  146. data/vendor/jsdoc-toolkit/java/src/JsRun.java +21 -0
  147. data/vendor/jsdoc-toolkit/jsdebug.jar +0 -0
  148. data/vendor/jsdoc-toolkit/jsrun.jar +0 -0
  149. data/vendor/jsdoc-toolkit/jsrun.sh +53 -0
  150. data/vendor/jsdoc-toolkit/templates/jsdoc/allclasses.tmpl +17 -0
  151. data/vendor/jsdoc-toolkit/templates/jsdoc/allfiles.tmpl +56 -0
  152. data/vendor/jsdoc-toolkit/templates/jsdoc/class.tmpl +649 -0
  153. data/vendor/jsdoc-toolkit/templates/jsdoc/index.tmpl +39 -0
  154. data/vendor/jsdoc-toolkit/templates/jsdoc/publish.js +201 -0
  155. data/vendor/jsdoc-toolkit/templates/jsdoc/static/code-footer.html +3 -0
  156. data/vendor/jsdoc-toolkit/templates/jsdoc/static/code-header.html +14 -0
  157. data/vendor/jsdoc-toolkit/templates/jsdoc/static/default.css +162 -0
  158. data/vendor/jsdoc-toolkit/templates/jsdoc/static/header.html +2 -0
  159. data/vendor/jsdoc-toolkit/templates/jsdoc/static/index.html +19 -0
  160. data/vendor/jsdoc-toolkit/templates/jsdoc/symbol.tmpl +35 -0
  161. data/vendor/jsl-0.3.0/src/JavaScriptLintAPI.cpp +333 -0
  162. data/vendor/jsl-0.3.0/src/JavaScriptLintAPI.h +86 -0
  163. data/vendor/jsl-0.3.0/src/Makefile.in +375 -0
  164. data/vendor/jsl-0.3.0/src/Makefile.ref +372 -0
  165. data/vendor/jsl-0.3.0/src/README.html +826 -0
  166. data/vendor/jsl-0.3.0/src/SpiderMonkey.rsp +12 -0
  167. data/vendor/jsl-0.3.0/src/_jsl_online.php +223 -0
  168. data/vendor/jsl-0.3.0/src/config/AIX4.1.mk +65 -0
  169. data/vendor/jsl-0.3.0/src/config/AIX4.2.mk +64 -0
  170. data/vendor/jsl-0.3.0/src/config/AIX4.3.mk +65 -0
  171. data/vendor/jsl-0.3.0/src/config/Darwin.mk +81 -0
  172. data/vendor/jsl-0.3.0/src/config/Darwin1.3.mk +81 -0
  173. data/vendor/jsl-0.3.0/src/config/Darwin1.4.mk +41 -0
  174. data/vendor/jsl-0.3.0/src/config/Darwin5.2.mk +81 -0
  175. data/vendor/jsl-0.3.0/src/config/Darwin5.3.mk +81 -0
  176. data/vendor/jsl-0.3.0/src/config/HP-UXB.10.10.mk +77 -0
  177. data/vendor/jsl-0.3.0/src/config/HP-UXB.10.20.mk +77 -0
  178. data/vendor/jsl-0.3.0/src/config/HP-UXB.11.00.mk +80 -0
  179. data/vendor/jsl-0.3.0/src/config/IRIX.mk +87 -0
  180. data/vendor/jsl-0.3.0/src/config/IRIX5.3.mk +44 -0
  181. data/vendor/jsl-0.3.0/src/config/IRIX6.1.mk +44 -0
  182. data/vendor/jsl-0.3.0/src/config/IRIX6.2.mk +44 -0
  183. data/vendor/jsl-0.3.0/src/config/IRIX6.3.mk +44 -0
  184. data/vendor/jsl-0.3.0/src/config/IRIX6.5.mk +44 -0
  185. data/vendor/jsl-0.3.0/src/config/Linux_All.mk +103 -0
  186. data/vendor/jsl-0.3.0/src/config/Mac_OS10.0.mk +82 -0
  187. data/vendor/jsl-0.3.0/src/config/OSF1V4.0.mk +72 -0
  188. data/vendor/jsl-0.3.0/src/config/OSF1V5.0.mk +69 -0
  189. data/vendor/jsl-0.3.0/src/config/SunOS4.1.4.mk +101 -0
  190. data/vendor/jsl-0.3.0/src/config/SunOS5.3.mk +91 -0
  191. data/vendor/jsl-0.3.0/src/config/SunOS5.4.mk +92 -0
  192. data/vendor/jsl-0.3.0/src/config/SunOS5.5.1.mk +44 -0
  193. data/vendor/jsl-0.3.0/src/config/SunOS5.5.mk +87 -0
  194. data/vendor/jsl-0.3.0/src/config/SunOS5.6.mk +89 -0
  195. data/vendor/jsl-0.3.0/src/config/SunOS5.7.mk +44 -0
  196. data/vendor/jsl-0.3.0/src/config/SunOS5.8.mk +44 -0
  197. data/vendor/jsl-0.3.0/src/config/SunOS5.9.mk +44 -0
  198. data/vendor/jsl-0.3.0/src/config/WINNT4.0.mk +112 -0
  199. data/vendor/jsl-0.3.0/src/config/WINNT5.0.mk +112 -0
  200. data/vendor/jsl-0.3.0/src/config/WINNT5.1.mk +112 -0
  201. data/vendor/jsl-0.3.0/src/config/WINNT5.2.mk +112 -0
  202. data/vendor/jsl-0.3.0/src/config/dgux.mk +64 -0
  203. data/vendor/jsl-0.3.0/src/config.mk +166 -0
  204. data/vendor/jsl-0.3.0/src/editline/Makefile.ref +144 -0
  205. data/vendor/jsl-0.3.0/src/editline/README +83 -0
  206. data/vendor/jsl-0.3.0/src/editline/editline.3 +175 -0
  207. data/vendor/jsl-0.3.0/src/editline/editline.c +1369 -0
  208. data/vendor/jsl-0.3.0/src/editline/editline.h +135 -0
  209. data/vendor/jsl-0.3.0/src/editline/sysunix.c +182 -0
  210. data/vendor/jsl-0.3.0/src/editline/unix.h +82 -0
  211. data/vendor/jsl-0.3.0/src/fdlibm/Makefile.in +127 -0
  212. data/vendor/jsl-0.3.0/src/fdlibm/Makefile.ref +192 -0
  213. data/vendor/jsl-0.3.0/src/fdlibm/e_acos.c +147 -0
  214. data/vendor/jsl-0.3.0/src/fdlibm/e_acosh.c +105 -0
  215. data/vendor/jsl-0.3.0/src/fdlibm/e_asin.c +156 -0
  216. data/vendor/jsl-0.3.0/src/fdlibm/e_atan2.c +165 -0
  217. data/vendor/jsl-0.3.0/src/fdlibm/e_atanh.c +110 -0
  218. data/vendor/jsl-0.3.0/src/fdlibm/e_cosh.c +133 -0
  219. data/vendor/jsl-0.3.0/src/fdlibm/e_exp.c +202 -0
  220. data/vendor/jsl-0.3.0/src/fdlibm/e_fmod.c +184 -0
  221. data/vendor/jsl-0.3.0/src/fdlibm/e_gamma.c +71 -0
  222. data/vendor/jsl-0.3.0/src/fdlibm/e_gamma_r.c +70 -0
  223. data/vendor/jsl-0.3.0/src/fdlibm/e_hypot.c +173 -0
  224. data/vendor/jsl-0.3.0/src/fdlibm/e_j0.c +524 -0
  225. data/vendor/jsl-0.3.0/src/fdlibm/e_j1.c +523 -0
  226. data/vendor/jsl-0.3.0/src/fdlibm/e_jn.c +315 -0
  227. data/vendor/jsl-0.3.0/src/fdlibm/e_lgamma.c +71 -0
  228. data/vendor/jsl-0.3.0/src/fdlibm/e_lgamma_r.c +347 -0
  229. data/vendor/jsl-0.3.0/src/fdlibm/e_log.c +184 -0
  230. data/vendor/jsl-0.3.0/src/fdlibm/e_log10.c +134 -0
  231. data/vendor/jsl-0.3.0/src/fdlibm/e_pow.c +386 -0
  232. data/vendor/jsl-0.3.0/src/fdlibm/e_rem_pio2.c +221 -0
  233. data/vendor/jsl-0.3.0/src/fdlibm/e_remainder.c +120 -0
  234. data/vendor/jsl-0.3.0/src/fdlibm/e_scalb.c +89 -0
  235. data/vendor/jsl-0.3.0/src/fdlibm/e_sinh.c +122 -0
  236. data/vendor/jsl-0.3.0/src/fdlibm/e_sqrt.c +497 -0
  237. data/vendor/jsl-0.3.0/src/fdlibm/fdlibm.dsp +160 -0
  238. data/vendor/jsl-0.3.0/src/fdlibm/fdlibm.h +273 -0
  239. data/vendor/jsl-0.3.0/src/fdlibm/fdlibm.mak +1453 -0
  240. data/vendor/jsl-0.3.0/src/fdlibm/fdlibm.mdp +0 -0
  241. data/vendor/jsl-0.3.0/src/fdlibm/k_cos.c +134 -0
  242. data/vendor/jsl-0.3.0/src/fdlibm/k_rem_pio2.c +354 -0
  243. data/vendor/jsl-0.3.0/src/fdlibm/k_sin.c +114 -0
  244. data/vendor/jsl-0.3.0/src/fdlibm/k_standard.c +785 -0
  245. data/vendor/jsl-0.3.0/src/fdlibm/k_tan.c +170 -0
  246. data/vendor/jsl-0.3.0/src/fdlibm/s_asinh.c +101 -0
  247. data/vendor/jsl-0.3.0/src/fdlibm/s_atan.c +175 -0
  248. data/vendor/jsl-0.3.0/src/fdlibm/s_cbrt.c +133 -0
  249. data/vendor/jsl-0.3.0/src/fdlibm/s_ceil.c +120 -0
  250. data/vendor/jsl-0.3.0/src/fdlibm/s_copysign.c +72 -0
  251. data/vendor/jsl-0.3.0/src/fdlibm/s_cos.c +118 -0
  252. data/vendor/jsl-0.3.0/src/fdlibm/s_erf.c +356 -0
  253. data/vendor/jsl-0.3.0/src/fdlibm/s_expm1.c +267 -0
  254. data/vendor/jsl-0.3.0/src/fdlibm/s_fabs.c +70 -0
  255. data/vendor/jsl-0.3.0/src/fdlibm/s_finite.c +71 -0
  256. data/vendor/jsl-0.3.0/src/fdlibm/s_floor.c +121 -0
  257. data/vendor/jsl-0.3.0/src/fdlibm/s_frexp.c +99 -0
  258. data/vendor/jsl-0.3.0/src/fdlibm/s_ilogb.c +85 -0
  259. data/vendor/jsl-0.3.0/src/fdlibm/s_isnan.c +74 -0
  260. data/vendor/jsl-0.3.0/src/fdlibm/s_ldexp.c +66 -0
  261. data/vendor/jsl-0.3.0/src/fdlibm/s_lib_version.c +73 -0
  262. data/vendor/jsl-0.3.0/src/fdlibm/s_log1p.c +211 -0
  263. data/vendor/jsl-0.3.0/src/fdlibm/s_logb.c +79 -0
  264. data/vendor/jsl-0.3.0/src/fdlibm/s_matherr.c +64 -0
  265. data/vendor/jsl-0.3.0/src/fdlibm/s_modf.c +132 -0
  266. data/vendor/jsl-0.3.0/src/fdlibm/s_nextafter.c +124 -0
  267. data/vendor/jsl-0.3.0/src/fdlibm/s_rint.c +131 -0
  268. data/vendor/jsl-0.3.0/src/fdlibm/s_scalbn.c +107 -0
  269. data/vendor/jsl-0.3.0/src/fdlibm/s_signgam.c +40 -0
  270. data/vendor/jsl-0.3.0/src/fdlibm/s_significand.c +68 -0
  271. data/vendor/jsl-0.3.0/src/fdlibm/s_sin.c +118 -0
  272. data/vendor/jsl-0.3.0/src/fdlibm/s_tan.c +112 -0
  273. data/vendor/jsl-0.3.0/src/fdlibm/s_tanh.c +122 -0
  274. data/vendor/jsl-0.3.0/src/fdlibm/w_acos.c +78 -0
  275. data/vendor/jsl-0.3.0/src/fdlibm/w_acosh.c +78 -0
  276. data/vendor/jsl-0.3.0/src/fdlibm/w_asin.c +80 -0
  277. data/vendor/jsl-0.3.0/src/fdlibm/w_atan2.c +79 -0
  278. data/vendor/jsl-0.3.0/src/fdlibm/w_atanh.c +81 -0
  279. data/vendor/jsl-0.3.0/src/fdlibm/w_cosh.c +77 -0
  280. data/vendor/jsl-0.3.0/src/fdlibm/w_exp.c +88 -0
  281. data/vendor/jsl-0.3.0/src/fdlibm/w_fmod.c +78 -0
  282. data/vendor/jsl-0.3.0/src/fdlibm/w_gamma.c +85 -0
  283. data/vendor/jsl-0.3.0/src/fdlibm/w_gamma_r.c +81 -0
  284. data/vendor/jsl-0.3.0/src/fdlibm/w_hypot.c +78 -0
  285. data/vendor/jsl-0.3.0/src/fdlibm/w_j0.c +105 -0
  286. data/vendor/jsl-0.3.0/src/fdlibm/w_j1.c +106 -0
  287. data/vendor/jsl-0.3.0/src/fdlibm/w_jn.c +128 -0
  288. data/vendor/jsl-0.3.0/src/fdlibm/w_lgamma.c +85 -0
  289. data/vendor/jsl-0.3.0/src/fdlibm/w_lgamma_r.c +81 -0
  290. data/vendor/jsl-0.3.0/src/fdlibm/w_log.c +78 -0
  291. data/vendor/jsl-0.3.0/src/fdlibm/w_log10.c +81 -0
  292. data/vendor/jsl-0.3.0/src/fdlibm/w_pow.c +99 -0
  293. data/vendor/jsl-0.3.0/src/fdlibm/w_remainder.c +77 -0
  294. data/vendor/jsl-0.3.0/src/fdlibm/w_scalb.c +95 -0
  295. data/vendor/jsl-0.3.0/src/fdlibm/w_sinh.c +77 -0
  296. data/vendor/jsl-0.3.0/src/fdlibm/w_sqrt.c +77 -0
  297. data/vendor/jsl-0.3.0/src/js.c +2447 -0
  298. data/vendor/jsl-0.3.0/src/js.dsp +420 -0
  299. data/vendor/jsl-0.3.0/src/js.mak +4025 -0
  300. data/vendor/jsl-0.3.0/src/js.mdp +0 -0
  301. data/vendor/jsl-0.3.0/src/js.msg +291 -0
  302. data/vendor/jsl-0.3.0/src/js.pkg +2 -0
  303. data/vendor/jsl-0.3.0/src/js3240.rc +79 -0
  304. data/vendor/jsl-0.3.0/src/jsOS240.def +654 -0
  305. data/vendor/jsl-0.3.0/src/jsapi.c +4405 -0
  306. data/vendor/jsl-0.3.0/src/jsapi.h +1856 -0
  307. data/vendor/jsl-0.3.0/src/jsarena.c +567 -0
  308. data/vendor/jsl-0.3.0/src/jsarena.h +302 -0
  309. data/vendor/jsl-0.3.0/src/jsarray.c +1428 -0
  310. data/vendor/jsl-0.3.0/src/jsarray.h +77 -0
  311. data/vendor/jsl-0.3.0/src/jsatom.c +927 -0
  312. data/vendor/jsl-0.3.0/src/jsatom.h +426 -0
  313. data/vendor/jsl-0.3.0/src/jsbit.h +113 -0
  314. data/vendor/jsl-0.3.0/src/jsbool.c +220 -0
  315. data/vendor/jsl-0.3.0/src/jsbool.h +62 -0
  316. data/vendor/jsl-0.3.0/src/jsclist.h +139 -0
  317. data/vendor/jsl-0.3.0/src/jscntxt.c +1036 -0
  318. data/vendor/jsl-0.3.0/src/jscntxt.h +608 -0
  319. data/vendor/jsl-0.3.0/src/jscompat.h +57 -0
  320. data/vendor/jsl-0.3.0/src/jsconfig.h +489 -0
  321. data/vendor/jsl-0.3.0/src/jsconfig.mk +181 -0
  322. data/vendor/jsl-0.3.0/src/jscpucfg.c +377 -0
  323. data/vendor/jsl-0.3.0/src/jscpucfg.h +204 -0
  324. data/vendor/jsl-0.3.0/src/jsdate.c +2238 -0
  325. data/vendor/jsl-0.3.0/src/jsdate.h +118 -0
  326. data/vendor/jsl-0.3.0/src/jsdbgapi.c +1260 -0
  327. data/vendor/jsl-0.3.0/src/jsdbgapi.h +345 -0
  328. data/vendor/jsl-0.3.0/src/jsdhash.c +763 -0
  329. data/vendor/jsl-0.3.0/src/jsdhash.h +579 -0
  330. data/vendor/jsl-0.3.0/src/jsdtoa.c +3135 -0
  331. data/vendor/jsl-0.3.0/src/jsdtoa.h +130 -0
  332. data/vendor/jsl-0.3.0/src/jsemit.c +4851 -0
  333. data/vendor/jsl-0.3.0/src/jsemit.h +576 -0
  334. data/vendor/jsl-0.3.0/src/jsexn.c +1084 -0
  335. data/vendor/jsl-0.3.0/src/jsexn.h +102 -0
  336. data/vendor/jsl-0.3.0/src/jsfile.c +2610 -0
  337. data/vendor/jsl-0.3.0/src/jsfile.h +50 -0
  338. data/vendor/jsl-0.3.0/src/jsfile.msg +89 -0
  339. data/vendor/jsl-0.3.0/src/jsfun.c +2015 -0
  340. data/vendor/jsl-0.3.0/src/jsfun.h +158 -0
  341. data/vendor/jsl-0.3.0/src/jsgc.c +1441 -0
  342. data/vendor/jsl-0.3.0/src/jsgc.h +230 -0
  343. data/vendor/jsl-0.3.0/src/jshash.c +471 -0
  344. data/vendor/jsl-0.3.0/src/jshash.h +152 -0
  345. data/vendor/jsl-0.3.0/src/jsify.pl +485 -0
  346. data/vendor/jsl-0.3.0/src/jsinterp.c +4797 -0
  347. data/vendor/jsl-0.3.0/src/jsinterp.h +302 -0
  348. data/vendor/jsl-0.3.0/src/jsl-test.js +28 -0
  349. data/vendor/jsl-0.3.0/src/jsl.c +2371 -0
  350. data/vendor/jsl-0.3.0/src/jsl.conf +127 -0
  351. data/vendor/jsl-0.3.0/src/jsl.conf.old +124 -0
  352. data/vendor/jsl-0.3.0/src/jsl.dsp +242 -0
  353. data/vendor/jsl-0.3.0/src/jsl.dsw +59 -0
  354. data/vendor/jsl-0.3.0/src/jslibmath.h +290 -0
  355. data/vendor/jsl-0.3.0/src/jslock.c +1261 -0
  356. data/vendor/jsl-0.3.0/src/jslock.h +289 -0
  357. data/vendor/jsl-0.3.0/src/jslocko.asm +59 -0
  358. data/vendor/jsl-0.3.0/src/jslog2.c +83 -0
  359. data/vendor/jsl-0.3.0/src/jslong.c +281 -0
  360. data/vendor/jsl-0.3.0/src/jslong.h +437 -0
  361. data/vendor/jsl-0.3.0/src/jsmath.c +477 -0
  362. data/vendor/jsl-0.3.0/src/jsmath.h +55 -0
  363. data/vendor/jsl-0.3.0/src/jsnum.c +1148 -0
  364. data/vendor/jsl-0.3.0/src/jsnum.h +257 -0
  365. data/vendor/jsl-0.3.0/src/jsobj.c +4066 -0
  366. data/vendor/jsl-0.3.0/src/jsobj.h +475 -0
  367. data/vendor/jsl-0.3.0/src/jsopcode.c +2730 -0
  368. data/vendor/jsl-0.3.0/src/jsopcode.h +275 -0
  369. data/vendor/jsl-0.3.0/src/jsopcode.tbl +344 -0
  370. data/vendor/jsl-0.3.0/src/jsosdep.h +127 -0
  371. data/vendor/jsl-0.3.0/src/jsotypes.h +211 -0
  372. data/vendor/jsl-0.3.0/src/jsparse.c +4438 -0
  373. data/vendor/jsl-0.3.0/src/jsparse.h +345 -0
  374. data/vendor/jsl-0.3.0/src/jsprf.c +1212 -0
  375. data/vendor/jsl-0.3.0/src/jsprf.h +148 -0
  376. data/vendor/jsl-0.3.0/src/jsprvtd.h +174 -0
  377. data/vendor/jsl-0.3.0/src/jspubtd.h +586 -0
  378. data/vendor/jsl-0.3.0/src/jsregexp.c +3831 -0
  379. data/vendor/jsl-0.3.0/src/jsregexp.h +180 -0
  380. data/vendor/jsl-0.3.0/src/jsscan.c +1814 -0
  381. data/vendor/jsl-0.3.0/src/jsscan.h +267 -0
  382. data/vendor/jsl-0.3.0/src/jsscope.c +1639 -0
  383. data/vendor/jsl-0.3.0/src/jsscope.h +389 -0
  384. data/vendor/jsl-0.3.0/src/jsscript.c +1284 -0
  385. data/vendor/jsl-0.3.0/src/jsscript.h +179 -0
  386. data/vendor/jsl-0.3.0/src/jsshell.msg +50 -0
  387. data/vendor/jsl-0.3.0/src/jsstddef.h +83 -0
  388. data/vendor/jsl-0.3.0/src/jsstr.c +4502 -0
  389. data/vendor/jsl-0.3.0/src/jsstr.h +448 -0
  390. data/vendor/jsl-0.3.0/src/jstypes.h +391 -0
  391. data/vendor/jsl-0.3.0/src/jsutil.c +157 -0
  392. data/vendor/jsl-0.3.0/src/jsutil.h +75 -0
  393. data/vendor/jsl-0.3.0/src/jsxdrapi.c +686 -0
  394. data/vendor/jsl-0.3.0/src/jsxdrapi.h +193 -0
  395. data/vendor/jsl-0.3.0/src/liveconnect/LiveConnect.dsp +157 -0
  396. data/vendor/jsl-0.3.0/src/liveconnect/LiveConnectShell.dsp +120 -0
  397. data/vendor/jsl-0.3.0/src/liveconnect/LiveConnectShell.dsw +44 -0
  398. data/vendor/jsl-0.3.0/src/liveconnect/Makefile.in +106 -0
  399. data/vendor/jsl-0.3.0/src/liveconnect/Makefile.ref +169 -0
  400. data/vendor/jsl-0.3.0/src/liveconnect/README.html +719 -0
  401. data/vendor/jsl-0.3.0/src/liveconnect/_jni/netscape_javascript_JSException.h +14 -0
  402. data/vendor/jsl-0.3.0/src/liveconnect/_jni/netscape_javascript_JSObject.h +155 -0
  403. data/vendor/jsl-0.3.0/src/liveconnect/classes/Makefile.in +89 -0
  404. data/vendor/jsl-0.3.0/src/liveconnect/classes/Makefile.ref +57 -0
  405. data/vendor/jsl-0.3.0/src/liveconnect/classes/netscape/Makefile.ref +47 -0
  406. data/vendor/jsl-0.3.0/src/liveconnect/classes/netscape/javascript/JSException.java +140 -0
  407. data/vendor/jsl-0.3.0/src/liveconnect/classes/netscape/javascript/JSObject.java +183 -0
  408. data/vendor/jsl-0.3.0/src/liveconnect/classes/netscape/javascript/JSProxy.java +58 -0
  409. data/vendor/jsl-0.3.0/src/liveconnect/classes/netscape/javascript/JSRunnable.java +70 -0
  410. data/vendor/jsl-0.3.0/src/liveconnect/classes/netscape/javascript/JSUtil.java +59 -0
  411. data/vendor/jsl-0.3.0/src/liveconnect/classes/netscape/javascript/Makefile.ref +53 -0
  412. data/vendor/jsl-0.3.0/src/liveconnect/config/AIX4.1.mk +45 -0
  413. data/vendor/jsl-0.3.0/src/liveconnect/config/AIX4.2.mk +45 -0
  414. data/vendor/jsl-0.3.0/src/liveconnect/config/AIX4.3.mk +50 -0
  415. data/vendor/jsl-0.3.0/src/liveconnect/config/HP-UXB.10.10.mk +43 -0
  416. data/vendor/jsl-0.3.0/src/liveconnect/config/HP-UXB.10.20.mk +43 -0
  417. data/vendor/jsl-0.3.0/src/liveconnect/config/HP-UXB.11.00.mk +43 -0
  418. data/vendor/jsl-0.3.0/src/liveconnect/config/IRIX6.2.mk +43 -0
  419. data/vendor/jsl-0.3.0/src/liveconnect/config/IRIX6.3.mk +43 -0
  420. data/vendor/jsl-0.3.0/src/liveconnect/config/IRIX6.5.mk +43 -0
  421. data/vendor/jsl-0.3.0/src/liveconnect/config/Linux_All.mk +73 -0
  422. data/vendor/jsl-0.3.0/src/liveconnect/config/OSF1V4.0.mk +65 -0
  423. data/vendor/jsl-0.3.0/src/liveconnect/config/OSF1V5.0.mk +62 -0
  424. data/vendor/jsl-0.3.0/src/liveconnect/config/SunOS5.5.1.mk +55 -0
  425. data/vendor/jsl-0.3.0/src/liveconnect/config/SunOS5.6.mk +39 -0
  426. data/vendor/jsl-0.3.0/src/liveconnect/config/SunOS5.7.mk +39 -0
  427. data/vendor/jsl-0.3.0/src/liveconnect/config/SunOS5.8.mk +39 -0
  428. data/vendor/jsl-0.3.0/src/liveconnect/config/WINNT4.0.mk +53 -0
  429. data/vendor/jsl-0.3.0/src/liveconnect/jsj.c +884 -0
  430. data/vendor/jsl-0.3.0/src/liveconnect/jsj.msg +98 -0
  431. data/vendor/jsl-0.3.0/src/liveconnect/jsj_JSObject.c +1379 -0
  432. data/vendor/jsl-0.3.0/src/liveconnect/jsj_JavaArray.c +481 -0
  433. data/vendor/jsl-0.3.0/src/liveconnect/jsj_JavaClass.c +749 -0
  434. data/vendor/jsl-0.3.0/src/liveconnect/jsj_JavaMember.c +186 -0
  435. data/vendor/jsl-0.3.0/src/liveconnect/jsj_JavaObject.c +1099 -0
  436. data/vendor/jsl-0.3.0/src/liveconnect/jsj_JavaPackage.c +548 -0
  437. data/vendor/jsl-0.3.0/src/liveconnect/jsj_array.c +207 -0
  438. data/vendor/jsl-0.3.0/src/liveconnect/jsj_class.c +765 -0
  439. data/vendor/jsl-0.3.0/src/liveconnect/jsj_convert.c +954 -0
  440. data/vendor/jsl-0.3.0/src/liveconnect/jsj_field.c +421 -0
  441. data/vendor/jsl-0.3.0/src/liveconnect/jsj_hash.c +504 -0
  442. data/vendor/jsl-0.3.0/src/liveconnect/jsj_hash.h +161 -0
  443. data/vendor/jsl-0.3.0/src/liveconnect/jsj_method.c +1823 -0
  444. data/vendor/jsl-0.3.0/src/liveconnect/jsj_nodl.c +1 -0
  445. data/vendor/jsl-0.3.0/src/liveconnect/jsj_private.h +689 -0
  446. data/vendor/jsl-0.3.0/src/liveconnect/jsj_simpleapi.c +219 -0
  447. data/vendor/jsl-0.3.0/src/liveconnect/jsj_utils.c +513 -0
  448. data/vendor/jsl-0.3.0/src/liveconnect/jsjava.h +313 -0
  449. data/vendor/jsl-0.3.0/src/liveconnect/liveconnect.pkg +3 -0
  450. data/vendor/jsl-0.3.0/src/liveconnect/netscape_javascript_JSObject.h +155 -0
  451. data/vendor/jsl-0.3.0/src/liveconnect/nsCLiveconnect.cpp +785 -0
  452. data/vendor/jsl-0.3.0/src/liveconnect/nsCLiveconnect.h +197 -0
  453. data/vendor/jsl-0.3.0/src/liveconnect/nsCLiveconnectFactory.cpp +163 -0
  454. data/vendor/jsl-0.3.0/src/liveconnect/nsCLiveconnectFactory.h +76 -0
  455. data/vendor/jsl-0.3.0/src/liveconnect/nsILiveconnect.h +195 -0
  456. data/vendor/jsl-0.3.0/src/liveconnect/nsISecureLiveconnect.h +84 -0
  457. data/vendor/jsl-0.3.0/src/liveconnect/nsISecurityContext.h +135 -0
  458. data/vendor/jsl-0.3.0/src/liveconnect/win32.order +6 -0
  459. data/vendor/jsl-0.3.0/src/lock_SunOS.s +114 -0
  460. data/vendor/jsl-0.3.0/src/perfect.js +39 -0
  461. data/vendor/jsl-0.3.0/src/perlconnect/JS.def +6 -0
  462. data/vendor/jsl-0.3.0/src/perlconnect/JS.dsp +107 -0
  463. data/vendor/jsl-0.3.0/src/perlconnect/JS.pm +318 -0
  464. data/vendor/jsl-0.3.0/src/perlconnect/JS.xs +1050 -0
  465. data/vendor/jsl-0.3.0/src/perlconnect/Makefile.PL +67 -0
  466. data/vendor/jsl-0.3.0/src/perlconnect/Makefile.ref +152 -0
  467. data/vendor/jsl-0.3.0/src/perlconnect/PerlConnect.dsp +103 -0
  468. data/vendor/jsl-0.3.0/src/perlconnect/PerlConnect.dsw +59 -0
  469. data/vendor/jsl-0.3.0/src/perlconnect/PerlConnect.pm +126 -0
  470. data/vendor/jsl-0.3.0/src/perlconnect/PerlConnectShell.dsp +89 -0
  471. data/vendor/jsl-0.3.0/src/perlconnect/README.html +345 -0
  472. data/vendor/jsl-0.3.0/src/perlconnect/bg.jpg +0 -0
  473. data/vendor/jsl-0.3.0/src/perlconnect/jsperl.c +1100 -0
  474. data/vendor/jsl-0.3.0/src/perlconnect/jsperl.h +52 -0
  475. data/vendor/jsl-0.3.0/src/perlconnect/jsperlbuild.pl +81 -0
  476. data/vendor/jsl-0.3.0/src/perlconnect/jsperlpvt.h +57 -0
  477. data/vendor/jsl-0.3.0/src/perlconnect/test.js +73 -0
  478. data/vendor/jsl-0.3.0/src/perlconnect/test.pl +244 -0
  479. data/vendor/jsl-0.3.0/src/perlconnect/typemap +121 -0
  480. data/vendor/jsl-0.3.0/src/plify_jsdhash.sed +31 -0
  481. data/vendor/jsl-0.3.0/src/prmjtime.c +646 -0
  482. data/vendor/jsl-0.3.0/src/prmjtime.h +95 -0
  483. data/vendor/jsl-0.3.0/src/resource.h +15 -0
  484. data/vendor/jsl-0.3.0/src/rules.mk +193 -0
  485. data/vendor/jsl-0.3.0/src/win32.order +391 -0
  486. data/vendor/jsl-0.3.0/tests/conf/always_use_option_explicit.js +4 -0
  487. data/vendor/jsl-0.3.0/tests/conf/define.js +8 -0
  488. data/vendor/jsl-0.3.0/tests/conf/jscript_function_extensions-1.js +7 -0
  489. data/vendor/jsl-0.3.0/tests/conf/jscript_function_extensions-2.js +8 -0
  490. data/vendor/jsl-0.3.0/tests/conf/jscript_function_extensions-3.js +27 -0
  491. data/vendor/jsl-0.3.0/tests/conf/jscript_function_extensions-4.js +4 -0
  492. data/vendor/jsl-0.3.0/tests/conf/lambda_assign_requires_semicolon.js +24 -0
  493. data/vendor/jsl-0.3.0/tests/conf/legacy_control_comments.js +8 -0
  494. data/vendor/jsl-0.3.0/tests/control_comments/control_comments.js +33 -0
  495. data/vendor/jsl-0.3.0/tests/control_comments/declare.js +26 -0
  496. data/vendor/jsl-0.3.0/tests/control_comments/import-overflow.js +9 -0
  497. data/vendor/jsl-0.3.0/tests/control_comments/import.js +5 -0
  498. data/vendor/jsl-0.3.0/tests/control_comments/import2.js +2 -0
  499. data/vendor/jsl-0.3.0/tests/control_comments/invalid_fallthru.js +13 -0
  500. data/vendor/jsl-0.3.0/tests/control_comments/option_explicit-with.js +12 -0
  501. data/vendor/jsl-0.3.0/tests/control_comments/option_explicit.js +64 -0
  502. data/vendor/jsl-0.3.0/tests/errors/unterminated_comment.js +8 -0
  503. data/vendor/jsl-0.3.0/tests/html/script_tag_in_js_literal.html +14 -0
  504. data/vendor/jsl-0.3.0/tests/run_tests.pl +71 -0
  505. data/vendor/jsl-0.3.0/tests/warnings/ambiguous_else_stmt.js +21 -0
  506. data/vendor/jsl-0.3.0/tests/warnings/ambiguous_nested_stmt.js +66 -0
  507. data/vendor/jsl-0.3.0/tests/warnings/ambiguous_newline.js +261 -0
  508. data/vendor/jsl-0.3.0/tests/warnings/anon_no_return_value.js +26 -0
  509. data/vendor/jsl-0.3.0/tests/warnings/assign_to_function_call.js +16 -0
  510. data/vendor/jsl-0.3.0/tests/warnings/block_without_braces.js +13 -0
  511. data/vendor/jsl-0.3.0/tests/warnings/comma_separated_stmts.js +17 -0
  512. data/vendor/jsl-0.3.0/tests/warnings/comparison_type_conv.js +44 -0
  513. data/vendor/jsl-0.3.0/tests/warnings/default_not_at_end.js +15 -0
  514. data/vendor/jsl-0.3.0/tests/warnings/dup_option_explicit.js +5 -0
  515. data/vendor/jsl-0.3.0/tests/warnings/duplicate_case_in_switch.js +62 -0
  516. data/vendor/jsl-0.3.0/tests/warnings/duplicate_formal.js +5 -0
  517. data/vendor/jsl-0.3.0/tests/warnings/empty_statement.js +29 -0
  518. data/vendor/jsl-0.3.0/tests/warnings/equal_as_assign.js +7 -0
  519. data/vendor/jsl-0.3.0/tests/warnings/inc_dec_within_stmt-ignore.js +21 -0
  520. data/vendor/jsl-0.3.0/tests/warnings/inc_dec_within_stmt.js +63 -0
  521. data/vendor/jsl-0.3.0/tests/warnings/jsl_cc_not_understood.js +5 -0
  522. data/vendor/jsl-0.3.0/tests/warnings/leading_decimal_point.js +7 -0
  523. data/vendor/jsl-0.3.0/tests/warnings/legacy_cc_not_understood.js +9 -0
  524. data/vendor/jsl-0.3.0/tests/warnings/meaningless_block.js +12 -0
  525. data/vendor/jsl-0.3.0/tests/warnings/misplaced_regex.js +20 -0
  526. data/vendor/jsl-0.3.0/tests/warnings/missing_break.js +87 -0
  527. data/vendor/jsl-0.3.0/tests/warnings/missing_break_for_last_case.js +19 -0
  528. data/vendor/jsl-0.3.0/tests/warnings/missing_default_case.js +51 -0
  529. data/vendor/jsl-0.3.0/tests/warnings/missing_option_explicit.js +5 -0
  530. data/vendor/jsl-0.3.0/tests/warnings/missing_semicolon.js +19 -0
  531. data/vendor/jsl-0.3.0/tests/warnings/multiple_plus_minus.js +10 -0
  532. data/vendor/jsl-0.3.0/tests/warnings/nested_comment.js +6 -0
  533. data/vendor/jsl-0.3.0/tests/warnings/no_return_value.js +25 -0
  534. data/vendor/jsl-0.3.0/tests/warnings/octal_number.js +5 -0
  535. data/vendor/jsl-0.3.0/tests/warnings/parseint_missing_radix.js +15 -0
  536. data/vendor/jsl-0.3.0/tests/warnings/partial_option_explicit.js +5 -0
  537. data/vendor/jsl-0.3.0/tests/warnings/redeclared_var.js +10 -0
  538. data/vendor/jsl-0.3.0/tests/warnings/spidermonkey/bad_backref.js +5 -0
  539. data/vendor/jsl-0.3.0/tests/warnings/spidermonkey/deprecated_usage.js +11 -0
  540. data/vendor/jsl-0.3.0/tests/warnings/spidermonkey/invalid_backref.js +5 -0
  541. data/vendor/jsl-0.3.0/tests/warnings/spidermonkey/trailing_comma.js +5 -0
  542. data/vendor/jsl-0.3.0/tests/warnings/trailing_comma_in_array.js +8 -0
  543. data/vendor/jsl-0.3.0/tests/warnings/trailing_decimal_point.js +7 -0
  544. data/vendor/jsl-0.3.0/tests/warnings/unreachable_code.js +29 -0
  545. data/vendor/jsl-0.3.0/tests/warnings/use_of_label.js +19 -0
  546. data/vendor/jsl-0.3.0/tests/warnings/useless_assign.js +20 -0
  547. data/vendor/jsl-0.3.0/tests/warnings/useless_comparison.js +55 -0
  548. data/vendor/jsl-0.3.0/tests/warnings/useless_void.js +6 -0
  549. data/vendor/jsl-0.3.0/tests/warnings/var_hides_arg.js +4 -0
  550. data/vendor/jsl-0.3.0/tests/warnings/with_statement.js +7 -0
  551. data/vendor/yuicompressor-2.4.2.jar +0 -0
  552. metadata +605 -0
@@ -0,0 +1,2371 @@
1
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ *
3
+ * ***** BEGIN LICENSE BLOCK *****
4
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
+ *
6
+ * The contents of this file are subject to the Mozilla Public License Version
7
+ * 1.1 (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ * http://www.mozilla.org/MPL/
10
+ *
11
+ * Software distributed under the License is distributed on an "AS IS" basis,
12
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
+ * for the specific language governing rights and limitations under the
14
+ * License.
15
+ *
16
+ * The Original Code is Mozilla Communicator client code, released
17
+ * March 31, 1998.
18
+ *
19
+ * The Initial Developer of the Original Code is
20
+ * Netscape Communications Corporation.
21
+ * Portions created by the Initial Developer are Copyright (C) 1998
22
+ * the Initial Developer. All Rights Reserved.
23
+ *
24
+ * Contributor(s):
25
+ *
26
+ * Alternatively, the contents of this file may be used under the terms of
27
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
28
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
+ * in which case the provisions of the GPL or the LGPL are applicable instead
30
+ * of those above. If you wish to allow use of your version of this file only
31
+ * under the terms of either the GPL or the LGPL, and not to allow others to
32
+ * use your version of this file under the terms of the MPL, indicate your
33
+ * decision by deleting the provisions above and replace them with the notice
34
+ * and other provisions required by the GPL or the LGPL. If you do not delete
35
+ * the provisions above, a recipient may use your version of this file under
36
+ * the terms of any one of the MPL, the GPL or the LGPL.
37
+ *
38
+ * ***** END LICENSE BLOCK ***** */
39
+
40
+ /*
41
+ * JavaScript lint.
42
+ */
43
+ #include "jsstddef.h"
44
+ #include <errno.h>
45
+ #include <stdio.h>
46
+ #include <stdlib.h>
47
+ #include <string.h>
48
+ #include "jstypes.h"
49
+ #include "jsarena.h"
50
+ #include "jsutil.h"
51
+ #include "jsprf.h"
52
+ #include "jsapi.h"
53
+ #include "jsatom.h"
54
+ #include "jscntxt.h"
55
+ #include "jsdbgapi.h"
56
+ #include "jsemit.h"
57
+ #include "jsfun.h"
58
+ #include "jsgc.h"
59
+ #include "jslock.h"
60
+ #include "jsobj.h"
61
+ #include "jsparse.h"
62
+ #include "jsscope.h"
63
+ #include "jsscript.h"
64
+ #include "jsstr.h"
65
+
66
+ #ifdef XP_UNIX
67
+ #include <unistd.h>
68
+ #include <sys/types.h>
69
+ #include <dirent.h>
70
+ #include <sys/wait.h>
71
+ #include <sys/stat.h>
72
+ #endif
73
+
74
+ #if defined(XP_WIN) || defined(XP_OS2)
75
+ #include <io.h> /* for isatty() */
76
+ #endif
77
+
78
+ #ifdef WIN32
79
+ #include <windows.h> /*to find files*/
80
+ #include <direct.h>
81
+ #include <conio.h>
82
+ #endif
83
+
84
+ #define JSL_VERSION "0.3.0"
85
+ #define JSL_DEVELOPED_BY "Developed by Matthias Miller (http://www.JavaScriptLint.com)"
86
+
87
+ /* exit code values */
88
+ #define EXITCODE_JS_WARNING 1
89
+ #define EXITCODE_USAGE_OR_CONFIGERR 2
90
+ #define EXITCODE_JS_ERROR 3
91
+ #define EXITCODE_FILE_ERROR 4
92
+
93
+ /* file constants */
94
+ #define MAXPATHLEN 1024
95
+
96
+ #ifdef WIN32
97
+ #define DEFAULT_DIRECTORY_SEPARATOR '\\'
98
+ #else
99
+ #define DEFAULT_DIRECTORY_SEPARATOR '/'
100
+ #endif
101
+
102
+ #ifdef WIN32
103
+ #ifndef INVALID_FILE_ATTRIBUTES
104
+ #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
105
+ #endif
106
+ #endif
107
+
108
+ const char gUTF8BOM[] = {'\xEF', '\xBB', '\xBF'};
109
+
110
+ /* configuration constants */
111
+ #define MAX_CONF_LINE 500
112
+
113
+ typedef enum {
114
+ JSL_PLACEHOLDER_FILE,
115
+ JSL_PLACEHOLDER_FILENAME,
116
+ JSL_PLACEHOLDER_LINE,
117
+ JSL_PLACEHOLDER_COL,
118
+ JSL_PLACEHOLDER_ERROR,
119
+ JSL_PLACEHOLDER_ERROR_NAME,
120
+ JSL_PLACEHOLDER_ERROR_PREFIX,
121
+ JSL_PLACEHOLDER_ERROR_MSG,
122
+ JSL_PLACEHOLDER_ERROR_MSGENC,
123
+ JSLPlaceholder_Limit
124
+ } JSLPlaceholder;
125
+
126
+ const char *placeholders[] = {
127
+ "__FILE__",
128
+ "__FILENAME__",
129
+ "__LINE__",
130
+ "__COL__",
131
+ "__ERROR__",
132
+ "__ERROR_NAME__",
133
+ "__ERROR_PREFIX__",
134
+ "__ERROR_MSG__",
135
+ "__ERROR_MSGENC__"
136
+ };
137
+
138
+
139
+ /* Warning information */
140
+ #define IS_JSL_WARNING_MSG(errnum) ((errnum) > JSMSG_START_LINT_MESSAGES)
141
+
142
+ #define CAN_DISABLE_WARNING(errnum) ((IS_JSL_WARNING_MSG(errnum) || \
143
+ ((errnum) == JSMSG_NO_RETURN_VALUE) || \
144
+ ((errnum) == JSMSG_DUPLICATE_FORMAL) || \
145
+ ((errnum) == JSMSG_EQUAL_AS_ASSIGN) || \
146
+ ((errnum) == JSMSG_VAR_HIDES_ARG) || \
147
+ ((errnum) == JSMSG_REDECLARED_VAR) || \
148
+ ((errnum) == JSMSG_ANON_NO_RETURN_VALUE)) && \
149
+ ((errnum) != JSMSG_UNDECLARED_IDENTIFIER))
150
+
151
+ #define WARNING_PREFIX "warning";
152
+ #define STRICT_WARNING_PREFIX "warning";
153
+ #define LINT_WARNING_PREFIX "lint warning";
154
+
155
+ #define JSL_OUTPUTFORMAT_ENCODE "encode:"
156
+
157
+ char *errorNames[JSErr_Limit] = {
158
+ #define MSG_DEF(name, number, count, exception, format) #name,
159
+ #include "js.msg"
160
+ #undef MSG_DEF
161
+ };
162
+
163
+ /* globals */
164
+ int gExitCode = 0;
165
+ int gNumWarnings = 0, gNumErrors = 0;
166
+
167
+ typedef enum {
168
+ JSL_FILETYPE_UNKNOWN,
169
+ JSL_FILETYPE_JS,
170
+ JSL_FILETYPE_HTML
171
+ } JSLFileType;
172
+
173
+ typedef struct JSLScriptDependencyList {
174
+ JSCList links;
175
+ struct JSLScriptList *script;
176
+ } JSLScriptDependencyList;
177
+
178
+ typedef struct JSLPathList {
179
+ JSCList links;
180
+ char path[MAXPATHLEN+1];
181
+ } JSLPathList;
182
+
183
+ typedef struct JSLScriptList {
184
+ JSCList links;
185
+
186
+ char path[MAXPATHLEN+1];
187
+ JSObject *obj;
188
+ JSLScriptDependencyList directDependencies;
189
+ } JSLScriptList;
190
+
191
+ JSLScriptList gScriptList;
192
+ JSLPathList gIncludePathList;
193
+
194
+
195
+ /* settings */
196
+ JSBool gAlwaysUseOptionExplicit = JS_FALSE;
197
+ JSBool gEnableLegacyControlComments = JS_TRUE;
198
+ JSBool gLambdaAssignRequiresSemicolon = JS_TRUE;
199
+ JSBool gEnableJScriptFunctionExtensions = JS_FALSE;
200
+ JSBool gRecurse = JS_FALSE;
201
+ JSBool gShowFileListing = JS_TRUE;
202
+ JSBool gShowContext = JS_TRUE;
203
+ /* Error format; this is the default for backward compatibility reasons */
204
+ char gOutputFormat[MAX_CONF_LINE+1] = "__FILE__(__LINE__): __ERROR__";
205
+ #ifdef WIN32
206
+ JSBool gPauseAtEnd = JS_FALSE;
207
+ #endif
208
+
209
+ JSBool showErrMsgs[JSErr_Limit] = {
210
+ #define MSG_DEF(name, number, count, exception, format) \
211
+ (number != JSMSG_BLOCK_WITHOUT_BRACES && \
212
+ number != JSMSG_MISSING_OPTION_EXPLICIT),
213
+ #include "js.msg"
214
+ #undef MSG_DEF
215
+ };
216
+
217
+
218
+ /* compatibility */
219
+
220
+ #ifdef WIN32
221
+ #define strcasecmp(src, dest) stricmp((src), (dest))
222
+ #define strncasecmp(src, dest, count) strnicmp((src), (dest), (count))
223
+ #endif
224
+
225
+ #ifdef WIN32
226
+ #define path_cmp(src, dest) strcasecmp((src), (dest))
227
+ #else
228
+ #define path_cmp(src, dest) strcmp((src), (dest))
229
+ #endif
230
+
231
+
232
+ static const char *
233
+ GetFileName(const char *path);
234
+
235
+ /*
236
+ * From http://xoomer.virgilio.it/acantato/dev/wildcard/wildmatch.html:
237
+ *
238
+ * I found this on a Walnut Creek CD (C/C++ user group library).
239
+ *
240
+ * The original code is from the C/C++ Users Journal. The author is Mike Cornelison.
241
+ * No use restriction is mentioned in the source file or the other files I found in the CD.
242
+ *
243
+ * NOTE: Renamed function and modified not to use mapCaseTable.
244
+ */
245
+ static JSBool
246
+ PathMatchesWildcards(const char *pat, const char *str) {
247
+ int i, star;
248
+
249
+ new_segment:
250
+
251
+ star = 0;
252
+ if (*pat == '*') {
253
+ star = 1;
254
+ do { pat++; } while (*pat == '*'); /* enddo */
255
+ } /* endif */
256
+
257
+ test_match:
258
+
259
+ for (i = 0; pat[i] && (pat[i] != '*'); i++) {
260
+ if (toupper(str[i]) != toupper(pat[i])) {
261
+ if (!str[i]) return 0;
262
+ if ((pat[i] == '?') && (str[i] != '.')) continue;
263
+ if (!star) return 0;
264
+ str++;
265
+ goto test_match;
266
+ }
267
+ }
268
+ if (pat[i] == '*') {
269
+ str += i;
270
+ pat += i;
271
+ goto new_segment;
272
+ }
273
+ if (!str[i]) return 1;
274
+ if (i && pat[i - 1] == '*') return 1;
275
+ if (!star) return 0;
276
+ str++;
277
+ goto test_match;
278
+ }
279
+
280
+ #ifdef WIN32
281
+
282
+ static JSBool
283
+ IsDir(char *path)
284
+ {
285
+ DWORD attr = GetFileAttributes(path);
286
+ return attr != INVALID_FILE_ATTRIBUTES &&
287
+ (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
288
+ }
289
+
290
+ #else
291
+
292
+ static JSBool
293
+ IsDir(char *filename)
294
+ {
295
+ struct stat tmp;
296
+ if (stat(filename, &tmp) >= 0) {
297
+ return (tmp.st_mode & S_IFMT) == S_IFDIR;
298
+ }
299
+ else
300
+ return JS_FALSE;
301
+ }
302
+
303
+ #endif
304
+
305
+
306
+
307
+
308
+ #ifdef WIN32
309
+
310
+ struct dirent {
311
+ char d_name[MAXPATHLEN];
312
+ };
313
+
314
+ typedef struct DIR {
315
+ long handle;
316
+ JSBool more;
317
+ struct _finddata_t finddata;
318
+ struct dirent cur;
319
+ } DIR;
320
+
321
+ static DIR*
322
+ opendir(const char *name)
323
+ {
324
+ char *qualifiedPath;
325
+ DIR *dir;
326
+
327
+ dir = malloc(sizeof(DIR));
328
+ if (!dir)
329
+ return NULL;
330
+ memset(dir, 0, sizeof(DIR));
331
+
332
+ /* do the find */
333
+ qualifiedPath = JS_smprintf("%s\\*", name);
334
+ dir->handle = _findfirst(qualifiedPath, &dir->finddata);
335
+ JS_smprintf_free(qualifiedPath);
336
+
337
+ if (dir->handle > 0) {
338
+ dir->more = JS_TRUE;
339
+ return dir;
340
+ }
341
+ else if (errno == ENOENT) {
342
+ dir->more = JS_FALSE;
343
+ return dir;
344
+ }
345
+ else {
346
+ free(dir);
347
+ return NULL;
348
+ }
349
+ }
350
+
351
+ static
352
+ struct dirent *readdir(DIR *dir)
353
+ {
354
+ if (!dir || !dir->more)
355
+ return NULL;
356
+
357
+ /* copy name */
358
+ strcpy(dir->cur.d_name, dir->finddata.name);
359
+ /* more? */
360
+ dir->more = (_findnext(dir->handle, &dir->finddata) >= 0);
361
+ return &dir->cur;
362
+ };
363
+
364
+ static int
365
+ closedir(DIR *dir)
366
+ {
367
+ if (dir) {
368
+ _findclose(dir->handle);
369
+ memset(dir, 0, sizeof(DIR));
370
+ free (dir);
371
+ }
372
+ return 0;
373
+ }
374
+
375
+ /* caller should allocate MAXPATHLEN; does not set errno; returns null on failure */
376
+ static char *
377
+ JSL_RealPath(const char *path, char *resolved_path)
378
+ {
379
+ int ret = GetFullPathName(path, _MAX_PATH, resolved_path, NULL);
380
+ if (!ret || ret > _MAX_PATH) {
381
+ return NULL;
382
+ }
383
+ return resolved_path;
384
+ }
385
+
386
+ #else
387
+
388
+ static const char *
389
+ JSL_RealPath(const char *path, char *resolved_path)
390
+ {
391
+ char *folder, *resolved;
392
+ const char *file;
393
+
394
+ resolved = realpath(path, resolved_path);
395
+ if (resolved)
396
+ return resolved;
397
+
398
+ /* get the folder name */
399
+ file = GetFileName(path);
400
+ folder = JS_smprintf("%s%c", path, DEFAULT_DIRECTORY_SEPARATOR);
401
+ folder[file - path] = 0;
402
+
403
+ resolved = realpath(folder, resolved_path);
404
+ JS_smprintf_free(folder);
405
+
406
+ if (resolved) {
407
+ char dirSeparator[] = { DEFAULT_DIRECTORY_SEPARATOR, 0 };
408
+ strcat(resolved, dirSeparator);
409
+ strcat(resolved, file);
410
+ }
411
+ return resolved;
412
+ }
413
+
414
+ #endif
415
+
416
+
417
+
418
+ static void
419
+ SetExitCode(int level)
420
+ {
421
+ if (level > gExitCode)
422
+ gExitCode = level;
423
+ }
424
+
425
+ static const char *
426
+ GetFileName(const char *path)
427
+ {
428
+ const char *file, *tmp;
429
+ file = strrchr(path, '/');
430
+ tmp = strrchr(path, '\\');
431
+ if (tmp && (!file || file < tmp)) {
432
+ file = tmp;
433
+ }
434
+ if (file)
435
+ file++;
436
+ else
437
+ file = path;
438
+ return file;
439
+ }
440
+
441
+ #define COUNT_AND_SKIP_NEWLINES(bufptr, lineno) \
442
+ do { \
443
+ if (*(bufptr) == '\r') { \
444
+ (lineno)++; \
445
+ (bufptr)++; \
446
+ if (*(bufptr) == '\n') \
447
+ (bufptr)++; \
448
+ } \
449
+ else if (*(bufptr) == '\n') { \
450
+ (lineno)++; \
451
+ (bufptr)++; \
452
+ } \
453
+ else \
454
+ break; \
455
+ } while (1)
456
+
457
+ static void
458
+ OutputErrorVariableValue(const char *value, JSBool encode)
459
+ {
460
+ const char *pos;
461
+
462
+ if (!value)
463
+ return;
464
+
465
+ if (!encode) {
466
+ fputs(value, stdout);
467
+ return;
468
+ }
469
+
470
+ pos = value;
471
+ while (*pos) {
472
+ switch (*pos) {
473
+ case '\\':
474
+ case '\"':
475
+ case '\'':
476
+ fputc('\\', stdout);
477
+ fputc(*pos, stdout);
478
+ break;
479
+ case '\t':
480
+ fputs("\\t", stdout);
481
+ break;
482
+ case '\r':
483
+ fputs("\\r", stdout);
484
+ break;
485
+ case '\n':
486
+ fputs("\\n", stdout);
487
+ break;
488
+ default:
489
+ fputc(*pos, stdout);
490
+ break;
491
+ }
492
+ pos++;
493
+ }
494
+ }
495
+
496
+ /* lineno may be zero if line number is not given */
497
+ static void
498
+ OutputErrorMessage(const char *path, int lineno, int colno, const char *errName,
499
+ const char *messagePrefix, const char *message)
500
+ {
501
+ const char *formatPos;
502
+ JSBool shouldEncode;
503
+ formatPos = gOutputFormat;
504
+
505
+ /* check for the encode instruction */
506
+ shouldEncode = (strncasecmp(formatPos, JSL_OUTPUTFORMAT_ENCODE, strlen(JSL_OUTPUTFORMAT_ENCODE)) == 0);
507
+ if (shouldEncode)
508
+ formatPos += strlen(JSL_OUTPUTFORMAT_ENCODE);
509
+
510
+ while (JS_TRUE) {
511
+ int i;
512
+ JSLPlaceholder placeholderType;
513
+ const char *placeholderPos;
514
+ char *tmp;
515
+
516
+ placeholderType = JSLPlaceholder_Limit;
517
+ placeholderPos = NULL;
518
+
519
+ for (i = 0; i < JSLPlaceholder_Limit; i++) {
520
+ const char *tmp;
521
+ tmp = strstr(formatPos, placeholders[i]);
522
+ if (tmp && (!placeholderPos || tmp < placeholderPos)) {
523
+ placeholderType = i;
524
+ placeholderPos = tmp;
525
+ }
526
+ }
527
+
528
+ /* print any skip any skipped text */
529
+ if (placeholderPos) {
530
+ while (formatPos < placeholderPos) {
531
+ fputc(*formatPos, stdout);
532
+ formatPos++;
533
+ }
534
+ }
535
+
536
+ switch (placeholderType) {
537
+ case JSL_PLACEHOLDER_FILE:
538
+ if (path)
539
+ OutputErrorVariableValue(path, shouldEncode);
540
+ break;
541
+
542
+ case JSL_PLACEHOLDER_FILENAME:
543
+ if (path)
544
+ OutputErrorVariableValue(GetFileName(path), shouldEncode);
545
+ break;
546
+
547
+ case JSL_PLACEHOLDER_LINE:
548
+ tmp = JS_smprintf("%i", lineno);
549
+ OutputErrorVariableValue(tmp, shouldEncode);
550
+ JS_smprintf_free(tmp);
551
+ break;
552
+
553
+ case JSL_PLACEHOLDER_COL:
554
+ tmp = JS_smprintf("%i", colno);
555
+ OutputErrorVariableValue(tmp, shouldEncode);
556
+ JS_smprintf_free(tmp);
557
+ break;
558
+
559
+ case JSL_PLACEHOLDER_ERROR:
560
+ if (messagePrefix && message) {
561
+ tmp = JS_smprintf("%s: %s", messagePrefix, message);
562
+ OutputErrorVariableValue(tmp, shouldEncode);
563
+ JS_smprintf_free(tmp);
564
+ }
565
+ else if (messagePrefix)
566
+ OutputErrorVariableValue(messagePrefix, shouldEncode);
567
+ else if (message)
568
+ OutputErrorVariableValue(message, shouldEncode);
569
+ break;
570
+
571
+ case JSL_PLACEHOLDER_ERROR_NAME:
572
+ if (errName)
573
+ OutputErrorVariableValue(errName, shouldEncode);
574
+ break;
575
+
576
+ case JSL_PLACEHOLDER_ERROR_PREFIX:
577
+ if (messagePrefix)
578
+ OutputErrorVariableValue(messagePrefix, shouldEncode);
579
+ break;
580
+
581
+ case JSL_PLACEHOLDER_ERROR_MSG:
582
+ if (message)
583
+ OutputErrorVariableValue(message, shouldEncode);
584
+ break;
585
+
586
+ case JSL_PLACEHOLDER_ERROR_MSGENC:
587
+ /* backward compatibility - always encode */
588
+ if (message)
589
+ OutputErrorVariableValue(message, JS_TRUE);
590
+ break;
591
+
592
+ case JSLPlaceholder_Limit:
593
+ default:
594
+ JS_ASSERT(!placeholderPos);
595
+ fputs(formatPos, stdout);
596
+ fputc('\n', stdout);
597
+ return;
598
+ }
599
+
600
+ /* only called if there was a placeholder; skip the placeholder */
601
+ JS_ASSERT(placeholderPos);
602
+ formatPos += strlen(placeholders[placeholderType]);
603
+ }
604
+ }
605
+
606
+ static JSLPathList*
607
+ AllocPathListItem(const char *path)
608
+ {
609
+ JSLPathList *pathItem;
610
+
611
+ /* alloc */
612
+ pathItem = malloc(sizeof(JSLPathList));
613
+ memset(pathItem, 0, sizeof(JSLPathList));
614
+
615
+ /* init path */
616
+ JS_INIT_CLIST(&pathItem->links);
617
+ strncpy(pathItem->path, path, MAXPATHLEN);
618
+
619
+ return pathItem;
620
+ }
621
+
622
+ /* returns false if already in list */
623
+ static void
624
+ AddPathToList(JSLPathList *pathList, const char *path)
625
+ {
626
+ JSLPathList *pathItem;
627
+ pathItem = AllocPathListItem(path);
628
+ JS_APPEND_LINK(&pathItem->links, &pathList->links);
629
+ }
630
+
631
+ static void
632
+ FreePathList(JSContext *cx, JSLPathList *pathList)
633
+ {
634
+ while (!JS_CLIST_IS_EMPTY(&pathList->links)) {
635
+ JSLPathList *curFileItem = (JSLPathList*)JS_LIST_HEAD(&pathList->links);
636
+ JS_REMOVE_LINK(&curFileItem->links);
637
+ JS_free(cx, curFileItem);
638
+ }
639
+ }
640
+
641
+ static JSLScriptList*
642
+ AllocScriptListItem(JSContext *cx, const char *path)
643
+ {
644
+ JSLScriptList *script;
645
+
646
+ /* alloc */
647
+ script = malloc(sizeof(JSLScriptList));
648
+ memset(script, 0, sizeof(JSLScriptList));
649
+
650
+ /* init path */
651
+ JS_INIT_CLIST(&script->links);
652
+ strncpy(script->path, path, MAXPATHLEN);
653
+
654
+ /* init object */
655
+ script->obj = JS_NewObject(cx, NULL, NULL, NULL);
656
+
657
+ /* init depends */
658
+ JS_INIT_CLIST(&script->directDependencies.links);
659
+ script->directDependencies.script = NULL;
660
+
661
+ return script;
662
+ }
663
+
664
+ /* returns false if already in list */
665
+ static JSBool
666
+ AddNewScriptToList(JSContext *cx, const char *path, JSLScriptList **script)
667
+ {
668
+ JSLScriptList *cur;
669
+ cur = (JSLScriptList*)JS_LIST_HEAD(&gScriptList.links);
670
+
671
+ while (cur != &gScriptList) {
672
+ if (path_cmp(path, cur->path) == 0) {
673
+ if (script)
674
+ *script = cur;
675
+ return JS_FALSE;
676
+ }
677
+ cur = (JSLScriptList*)JS_NEXT_LINK(&cur->links);
678
+ }
679
+
680
+ cur = AllocScriptListItem(cx, path);
681
+ JS_APPEND_LINK(&cur->links, &gScriptList.links);
682
+
683
+ if (script)
684
+ *script = cur;
685
+ return JS_TRUE;
686
+ }
687
+
688
+ static void
689
+ AddDirectDependency(JSLScriptDependencyList *dependencies, JSLScriptList *dependencyScript)
690
+ {
691
+ /* create dependency item */
692
+ JSLScriptDependencyList *dependency;
693
+ dependency = malloc(sizeof(JSLScriptDependencyList));
694
+ memset(dependency, 0, sizeof(JSLScriptDependencyList));
695
+ dependency->script = dependencyScript;
696
+
697
+ /* add to list */
698
+ JS_APPEND_LINK(&dependency->links, &dependencies->links);
699
+ }
700
+
701
+ static JSBool
702
+ IsObjectInList(JSLObjectList *dependencies, JSObject *dependency)
703
+ {
704
+ JSLObjectList *cur = (JSLObjectList*)JS_LIST_HEAD(&dependencies->links);
705
+ while (cur != dependencies) {
706
+ if (cur->obj == dependency)
707
+ return JS_TRUE;
708
+
709
+ cur = (JSLObjectList*)JS_NEXT_LINK(&cur->links);
710
+ }
711
+
712
+ return JS_FALSE;
713
+ }
714
+
715
+ static void
716
+ AddObjectToList(JSLObjectList *dependencies, JSObject *dependency)
717
+ {
718
+ /* create list object item */
719
+ JSLObjectList *listItem;
720
+ listItem = malloc(sizeof(JSLObjectList));
721
+ memset(listItem, 0, sizeof(JSLObjectList));
722
+ listItem->obj = dependency;
723
+
724
+ /* add to list */
725
+ JS_APPEND_LINK(&listItem->links, &dependencies->links);
726
+ }
727
+
728
+ static void
729
+ LoadScriptDependencies(JSLObjectList *dependencies, JSLScriptList *script)
730
+ {
731
+ /* load script dependencies for direct dependencies */
732
+ JSLScriptDependencyList *cur = (JSLScriptDependencyList*)JS_LIST_HEAD(&script->directDependencies.links);
733
+ while (cur != &script->directDependencies) {
734
+ /* check recursion */
735
+ if (!IsObjectInList(dependencies, cur->script->obj)) {
736
+ AddObjectToList(dependencies, cur->script->obj);
737
+ LoadScriptDependencies(dependencies, cur->script);
738
+ }
739
+ cur = (JSLScriptDependencyList*)JS_NEXT_LINK(&cur->links);
740
+ }
741
+ }
742
+
743
+
744
+ static JSBool
745
+ ProcessScriptContents(JSContext *cx, JSObject *obj, JSLFileType type,
746
+ const char *path, const char *contents,
747
+ JSLImportCallback callback, void *callbackParms);
748
+
749
+ static JSBool
750
+ ProcessSingleScript(JSContext *cx, JSObject *obj, const char *relpath, JSLScriptList *parentScript);
751
+
752
+
753
+ typedef struct JSLImportScriptParms {
754
+ JSObject *obj;
755
+ JSLScriptList *script;
756
+ JSLObjectList *dependencies;
757
+ } JSLImportScriptParms;
758
+
759
+ static void
760
+ ImportScript(JSContext *cx, const char *path, void *parms)
761
+ {
762
+ JSLImportScriptParms *importParms = (JSLImportScriptParms*)parms;
763
+ ProcessSingleScript(cx, importParms->obj, path, importParms->script);
764
+ LoadScriptDependencies(importParms->dependencies, importParms->script);
765
+ }
766
+
767
+ /* no-case comparison */
768
+ static JSBool
769
+ EndsWithSuffixNoCase(const char *s1, const char *s2)
770
+ {
771
+ int len1, len2;
772
+ len1 = strlen(s1);
773
+ len2 = strlen(s2);
774
+
775
+ if (len1 < len2)
776
+ return JS_FALSE;
777
+
778
+ return strcasecmp(s1 + len1 - len2, s2) == 0;
779
+ }
780
+
781
+ static JSLFileType
782
+ GetFileTypeFromPath(const char *path)
783
+ {
784
+ const char *basename;
785
+ int len;
786
+
787
+ basename = GetFileName(path);
788
+ len = strlen(basename);
789
+
790
+ if (EndsWithSuffixNoCase(basename, ".js"))
791
+ return JSL_FILETYPE_JS;
792
+
793
+ if (EndsWithSuffixNoCase(basename, ".htm") ||
794
+ EndsWithSuffixNoCase(basename, ".html")) {
795
+ return JSL_FILETYPE_HTML;
796
+ }
797
+
798
+ return JSL_FILETYPE_UNKNOWN;
799
+ }
800
+
801
+ static JSBool
802
+ ResolveScriptPath(const char *relpath, char *path, JSLScriptList *parentScript)
803
+ {
804
+ JSBool result;
805
+ struct stat _stat;
806
+ JSLPathList *inc;
807
+
808
+ char workingDir[MAXPATHLEN+1];
809
+ workingDir[0] = 0;
810
+ getcwd(workingDir, sizeof(workingDir));
811
+
812
+ if (parentScript)
813
+ {
814
+ const char *basename;
815
+ char *folder;
816
+
817
+ /* get the folder name */
818
+ basename = GetFileName(parentScript->path);
819
+ folder = JS_smprintf("%s%c", parentScript->path, DEFAULT_DIRECTORY_SEPARATOR);
820
+ folder[basename - parentScript->path] = DEFAULT_DIRECTORY_SEPARATOR;
821
+ folder[basename - parentScript->path + 1] = 0;
822
+
823
+ /* change folder to handle relative paths */
824
+ chdir(folder);
825
+ JS_smprintf_free(folder);
826
+ }
827
+
828
+ result= (JSL_RealPath(relpath, path) != NULL);
829
+ chdir(workingDir);
830
+
831
+ /* if the file exists, return true */
832
+ if (result && -1!=stat(path, &_stat))
833
+ return JS_TRUE;
834
+
835
+ for (inc= (JSLPathList*)JS_LIST_HEAD(&gIncludePathList.links);
836
+ inc!=&gIncludePathList;
837
+ inc= (JSLPathList*)JS_NEXT_LINK(&inc->links))
838
+ {
839
+ chdir(inc->path);
840
+ result= (JSL_RealPath(relpath, path) != NULL);
841
+ chdir(workingDir);
842
+
843
+ if (!result)
844
+ continue;
845
+
846
+ /* check to see whether the file exists */
847
+ if (-1==stat(path, &_stat))
848
+ continue;
849
+
850
+ return JS_TRUE;
851
+ }
852
+
853
+ return JS_FALSE;
854
+ }
855
+
856
+ static JSBool
857
+ ProcessSingleScript(JSContext *cx, JSObject *obj, const char *relpath, JSLScriptList *parentScript)
858
+ {
859
+ JSLImportScriptParms importParms;
860
+ char path[MAXPATHLEN+1];
861
+ long fileSize;
862
+ char *contents;
863
+ JSLScriptList *scriptInfo;
864
+ JSLObjectList dependencies;
865
+ JSBool tmp_result;
866
+ FILE *file;
867
+
868
+ tmp_result = ResolveScriptPath(relpath, path, parentScript);
869
+
870
+ if (!tmp_result) {
871
+ OutputErrorMessage(relpath, 0, 0, NULL, NULL, "unable to resolve file");
872
+ SetExitCode(EXITCODE_FILE_ERROR);
873
+ return JS_FALSE;
874
+ }
875
+
876
+ /* returns false if already in list */
877
+ tmp_result = AddNewScriptToList(cx, path, &scriptInfo);
878
+ if (parentScript)
879
+ AddDirectDependency(&parentScript->directDependencies, scriptInfo);
880
+ if (!tmp_result)
881
+ return JS_TRUE;
882
+
883
+ if (gShowFileListing) {
884
+ fputs(GetFileName(path), stdout);
885
+ fputc('\n', stdout);
886
+ }
887
+
888
+ file = fopen(path, "r");
889
+ if (!file) {
890
+ OutputErrorMessage(path, 0, 0, NULL, "can't open file", strerror(errno));
891
+ SetExitCode(EXITCODE_FILE_ERROR);
892
+ return JS_FALSE;
893
+ }
894
+
895
+ /* seek to the send to determine file size*/
896
+ if (fseek(file, 0, SEEK_END) != 0 ||
897
+ (fileSize = ftell(file)) < 0 ||
898
+ fseek(file, 0, SEEK_SET) != 0) {
899
+
900
+ fclose(file);
901
+ OutputErrorMessage(path, 0, 0, NULL, "can't read file", strerror(errno));
902
+ SetExitCode(EXITCODE_FILE_ERROR);
903
+ return JS_FALSE;
904
+ }
905
+
906
+ /* alloc memory */
907
+ contents = (char*)JS_malloc(cx, fileSize+1);
908
+ if (contents == NULL) {
909
+ fclose(file);
910
+ OutputErrorMessage(path, 0, 0, NULL, "can't read file", "out of memory");
911
+ SetExitCode(EXITCODE_FILE_ERROR);
912
+ return JS_FALSE;
913
+ }
914
+
915
+ /* read file */
916
+ fileSize = fread(contents, 1, fileSize, file);
917
+ if (ferror(file)) {
918
+ fclose(file);
919
+ JS_free(cx, contents);
920
+ OutputErrorMessage(path, 0, 0, NULL, "can't read file", strerror(errno));
921
+ SetExitCode(EXITCODE_FILE_ERROR);
922
+ return JS_FALSE;
923
+ }
924
+ contents[fileSize] = 0;
925
+ fclose(file);
926
+
927
+ JS_INIT_CLIST(&dependencies.links);
928
+ LoadScriptDependencies(&dependencies, scriptInfo);
929
+
930
+ importParms.obj = obj;
931
+ importParms.script = scriptInfo;
932
+ importParms.dependencies = &dependencies;
933
+
934
+ if (JS_PushLintIdentifers(cx, scriptInfo->obj, &dependencies,
935
+ gAlwaysUseOptionExplicit, gLambdaAssignRequiresSemicolon,
936
+ gEnableLegacyControlComments, gEnableJScriptFunctionExtensions,
937
+ ImportScript, &importParms)) {
938
+ tmp_result = ProcessScriptContents(cx, obj, GetFileTypeFromPath(path), path,
939
+ contents, ImportScript, &importParms);
940
+ JS_PopLintIdentifers(cx);
941
+ }
942
+ else {
943
+ SetExitCode(EXITCODE_JS_ERROR);
944
+ tmp_result = JS_FALSE;
945
+ }
946
+
947
+ /* free object list */
948
+ while (!JS_CLIST_IS_EMPTY(&dependencies.links)) {
949
+ JSLObjectList *dependency;
950
+ dependency = (JSLObjectList*)JS_LIST_HEAD(&dependencies.links);
951
+ JS_REMOVE_LINK(&dependency->links);
952
+ }
953
+
954
+ JS_free(cx, contents);
955
+ return tmp_result;
956
+ }
957
+
958
+ static JSBool
959
+ ProcessScriptContents(JSContext *cx, JSObject *obj, JSLFileType type,
960
+ const char *path, const char *contents,
961
+ JSLImportCallback callback, void *callbackParms)
962
+ {
963
+ JSScript *script;
964
+ JSBool isHTMLFile;
965
+ isHTMLFile = JS_FALSE;
966
+
967
+ /* skip the UTF-8 BOM */
968
+ if (contents[0] == gUTF8BOM[0] &&
969
+ contents[1] == gUTF8BOM[1] &&
970
+ contents[2] == gUTF8BOM[2]) {
971
+ contents += 3;
972
+ }
973
+
974
+ /* yech... */
975
+ if (type == JSL_FILETYPE_UNKNOWN || type == JSL_FILETYPE_HTML) {
976
+ int lineno;
977
+ JSBool containsHTMLScript, containsHTMLStartTag, containsHTMLEndTag;
978
+ const char *contentsPos;
979
+ contentsPos = contents;
980
+
981
+ lineno = 1;
982
+ containsHTMLScript = containsHTMLStartTag = containsHTMLEndTag = JS_FALSE;
983
+
984
+ while (*contentsPos) {
985
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
986
+ if (!*contentsPos)
987
+ break;
988
+
989
+ /* see if this is disproved by garbage after the end HTML tag */
990
+ if (isHTMLFile && !containsHTMLScript && containsHTMLStartTag && containsHTMLEndTag) {
991
+ if (!isspace(*contentsPos))
992
+ isHTMLFile = JS_FALSE;
993
+ }
994
+
995
+ if (*contentsPos != '<') {
996
+ contentsPos++;
997
+ continue;
998
+ }
999
+ contentsPos++;
1000
+
1001
+ /* skip whitespace */
1002
+ while (*contentsPos) {
1003
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1004
+ if (!*contentsPos)
1005
+ break;
1006
+ if (!isspace(*contentsPos))
1007
+ break;
1008
+ contentsPos++;
1009
+ }
1010
+ if (!*contentsPos)
1011
+ break;
1012
+
1013
+ if (containsHTMLStartTag && *contentsPos == '/') {
1014
+ contentsPos++;
1015
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1016
+ if (!*contentsPos)
1017
+ break;
1018
+
1019
+ if (strncasecmp(contentsPos, "html", 4) == 0 && !isalnum(*(contentsPos+4))) {
1020
+ contentsPos += 4;
1021
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1022
+ if (!*contentsPos)
1023
+ break;
1024
+
1025
+ /* skip whitespace */
1026
+ while (*contentsPos) {
1027
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1028
+ if (!*contentsPos)
1029
+ break;
1030
+ if (!isspace(*contentsPos))
1031
+ break;
1032
+ contentsPos++;
1033
+ }
1034
+ if (!*contentsPos)
1035
+ break;
1036
+
1037
+ if (*contentsPos == '>') {
1038
+ containsHTMLEndTag = JS_TRUE;
1039
+ /* may be disproven later */
1040
+ isHTMLFile = JS_TRUE;
1041
+ }
1042
+
1043
+ contentsPos++;
1044
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1045
+ }
1046
+ }
1047
+ else if (strncasecmp(contentsPos, "html", 4) == 0 && !isalnum(*(contentsPos+4))) {
1048
+ /* html tag */
1049
+ contentsPos += 4;
1050
+ containsHTMLStartTag = JS_TRUE;
1051
+ }
1052
+ else if (strncasecmp(contentsPos, "script", 6) != 0 || isalnum(*(contentsPos+6))) {
1053
+ /* not the script tag that we're looking for */
1054
+ contentsPos++;
1055
+ }
1056
+ else {
1057
+ /* script tag */
1058
+ const char *startOfScript, *endOfScript;
1059
+ int lineStartOfScript;
1060
+ const char *scriptSrcStart, *scriptSrcEnd;
1061
+ contentsPos += 6;
1062
+
1063
+ /* find start of script */
1064
+ lineStartOfScript = 0;
1065
+ startOfScript = NULL;
1066
+ endOfScript = NULL;
1067
+ scriptSrcStart = NULL;
1068
+ scriptSrcEnd = NULL;
1069
+ while (*contentsPos) {
1070
+ JSBool inSrcAttr;
1071
+ inSrcAttr = JS_FALSE;
1072
+
1073
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1074
+ if (!*contentsPos)
1075
+ break;
1076
+
1077
+ /* check if previous char was space */
1078
+ if (isspace(*(contentsPos-1)) && strncasecmp(contentsPos, "src", 3) == 0 && !isalnum(*(contentsPos+3))) {
1079
+ contentsPos += 3;
1080
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1081
+
1082
+ /* skip spaces */
1083
+ while (*contentsPos && isspace(*contentsPos)) {
1084
+ *contentsPos++;
1085
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1086
+ }
1087
+
1088
+ /* check for equals */
1089
+ if (!*contentsPos || *contentsPos != '=') {
1090
+ OutputErrorMessage(path, lineno, 0, NULL, "html error", "expected src attribute");
1091
+ SetExitCode(EXITCODE_JS_ERROR);
1092
+ return JS_FALSE;
1093
+ }
1094
+
1095
+ if (scriptSrcStart) {
1096
+ OutputErrorMessage(path, lineno, 0, NULL, "html error", "only one src attribute is allowed");
1097
+ SetExitCode(EXITCODE_JS_ERROR);
1098
+ return JS_FALSE;
1099
+ }
1100
+
1101
+ /* skip spaces */
1102
+ *contentsPos++;
1103
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1104
+
1105
+ /* force quotes on src attribute */
1106
+ if (!*contentsPos || (*contentsPos != '\"' && *contentsPos != '\'')) {
1107
+ OutputErrorMessage(path, lineno, 0, NULL, "html error", "missing quotes on src attribute");
1108
+ SetExitCode(EXITCODE_JS_ERROR);
1109
+ return JS_FALSE;
1110
+ }
1111
+
1112
+ /* src starts after quote */
1113
+ scriptSrcStart = contentsPos;
1114
+ scriptSrcStart++;
1115
+ }
1116
+ if (*contentsPos == '\"' || *contentsPos == '\'') {
1117
+ const char *startPos;
1118
+ startPos = contentsPos;
1119
+ contentsPos++;
1120
+
1121
+ while (*contentsPos) {
1122
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1123
+ if (!*contentsPos)
1124
+ break;
1125
+ if (*contentsPos == *startPos) {
1126
+ contentsPos++;
1127
+ break;
1128
+ }
1129
+ contentsPos++;
1130
+ }
1131
+
1132
+ if (scriptSrcStart && !scriptSrcEnd) {
1133
+ if (!*contentsPos) {
1134
+ OutputErrorMessage(path, lineno, 0, NULL, "html error",
1135
+ "unexpected end of file when looking for end of src attribute");
1136
+ SetExitCode(EXITCODE_JS_ERROR);
1137
+ return JS_FALSE;
1138
+ }
1139
+ scriptSrcEnd = contentsPos-2/*point to before quote*/;
1140
+ }
1141
+ else if (!*contentsPos)
1142
+ break;
1143
+ }
1144
+ else if (*contentsPos == '>') {
1145
+ contentsPos++;
1146
+ startOfScript = contentsPos;
1147
+ lineStartOfScript = lineno;
1148
+ break;
1149
+ }
1150
+ else
1151
+ contentsPos++;
1152
+ }
1153
+
1154
+ /* look for the end of the script */
1155
+ while (startOfScript && *contentsPos) {
1156
+ const char *possibleEndOfScript;
1157
+ possibleEndOfScript = NULL;
1158
+
1159
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1160
+ if (!*contentsPos)
1161
+ break;
1162
+
1163
+ /* tag */
1164
+ if (*contentsPos != '<') {
1165
+ contentsPos++;
1166
+ continue;
1167
+ }
1168
+ possibleEndOfScript = contentsPos;
1169
+ contentsPos++;
1170
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1171
+ if (!*contentsPos)
1172
+ break;
1173
+
1174
+ /* end tag */
1175
+ if (*contentsPos != '/') {
1176
+ contentsPos++;
1177
+ continue;
1178
+ }
1179
+ contentsPos++;
1180
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1181
+ if (!*contentsPos)
1182
+ break;
1183
+
1184
+ if (strncasecmp(contentsPos, "script", 6) == 0 && !isalnum(*(contentsPos+6))) {
1185
+ /* script end tag! */
1186
+ contentsPos += 6;
1187
+
1188
+ while (*contentsPos && *contentsPos != '>') {
1189
+ COUNT_AND_SKIP_NEWLINES(contentsPos, lineno);
1190
+ contentsPos++;
1191
+ }
1192
+ if (!*contentsPos)
1193
+ break;
1194
+
1195
+ if (*contentsPos == '>') {
1196
+ contentsPos++;
1197
+
1198
+ /*
1199
+ * If no compilable unit can be found, the last end tag found will be
1200
+ * treated as the end of the script
1201
+ .*/
1202
+ endOfScript = possibleEndOfScript;
1203
+
1204
+ if (JS_BufferIsCompilableUnit(cx, obj, startOfScript, possibleEndOfScript-startOfScript)) {
1205
+ /* this is a compilable unit; go for it */
1206
+ break;
1207
+ }
1208
+ }
1209
+ }
1210
+ }
1211
+
1212
+ if (scriptSrcStart && scriptSrcEnd) {
1213
+ const char *scriptPos;
1214
+ scriptPos = startOfScript;
1215
+
1216
+ while (scriptPos < endOfScript) {
1217
+ if (!isspace(*scriptPos)) {
1218
+ OutputErrorMessage(path, lineno, 0, NULL, "html error", "script tag should be empty if a src attribute is specified");
1219
+ SetExitCode(EXITCODE_JS_ERROR);
1220
+ return JS_FALSE;
1221
+ }
1222
+ scriptPos++;
1223
+ }
1224
+ }
1225
+
1226
+ if (!startOfScript || !endOfScript) {
1227
+ OutputErrorMessage(path, lineno, 0, NULL, "html error", "unable to find end of script tag");
1228
+ SetExitCode(EXITCODE_JS_ERROR);
1229
+ return JS_FALSE;
1230
+ }
1231
+
1232
+ isHTMLFile = JS_TRUE;
1233
+ containsHTMLScript = JS_TRUE;
1234
+
1235
+ if (scriptSrcStart && scriptSrcEnd) {
1236
+ char srcAttr[MAXPATHLEN+1];
1237
+ int attrLen;
1238
+ attrLen = scriptSrcEnd-scriptSrcStart+1;
1239
+
1240
+ if (attrLen > MAXPATHLEN) {
1241
+ OutputErrorMessage(path, lineno, 0, NULL, "html error", "src attribute exceeded maximum length");
1242
+ SetExitCode(EXITCODE_JS_ERROR);
1243
+ return JS_FALSE;
1244
+ }
1245
+
1246
+ strncpy(srcAttr, scriptSrcStart, attrLen);
1247
+ srcAttr[attrLen] = 0;
1248
+
1249
+ if (callback)
1250
+ callback(cx, srcAttr, callbackParms);
1251
+ }
1252
+ else {
1253
+ script = JS_CompileScript(cx, obj, startOfScript, endOfScript - startOfScript, path, lineStartOfScript);
1254
+ if (script)
1255
+ JS_DestroyScript(cx, script);
1256
+ else {
1257
+ /* no execution; must be compilation error */
1258
+ JS_ReportPendingException(cx);
1259
+ SetExitCode(EXITCODE_JS_ERROR);
1260
+ return JS_FALSE;
1261
+ }
1262
+ }
1263
+ }
1264
+ }
1265
+ }
1266
+
1267
+ /* if the type wasn't known, treat as JS if no hardcoded HTML tags were found */
1268
+ if ((type == JSL_FILETYPE_UNKNOWN && !isHTMLFile) ||
1269
+ type == JSL_FILETYPE_JS) {
1270
+ const char *contentsPos;
1271
+ contentsPos = contents;
1272
+
1273
+ /*
1274
+ * It's not interactive - just execute it.
1275
+ *
1276
+ * Support the UNIX #! shell hack; gobble the first line if it starts
1277
+ * with '#'. TODO - this isn't quite compatible with sharp variables,
1278
+ * as a legal js program (using sharp variables) might start with '#'.
1279
+ * But that would require multi-character lookahead.
1280
+ */
1281
+ if (*contentsPos == '#') {
1282
+ while(contentsPos[1]) {
1283
+ if (contentsPos[1] == '\n' || contentsPos[1] == '\r')
1284
+ break;
1285
+ contentsPos++;
1286
+ }
1287
+ }
1288
+
1289
+ script = JS_CompileScript(cx, obj, contentsPos, strlen(contentsPos), path, 1);
1290
+ if (script) {
1291
+ JS_DestroyScript(cx, script);
1292
+ return JS_TRUE;
1293
+ }
1294
+ /* no execution; must be compilation error */
1295
+ JS_ReportPendingException(cx);
1296
+ SetExitCode(EXITCODE_JS_ERROR);
1297
+ return JS_FALSE;
1298
+ }
1299
+ else {
1300
+ return JS_TRUE;
1301
+ }
1302
+ }
1303
+
1304
+ static JSBool
1305
+ ProcessScripts(JSContext *cx, JSObject *obj, char *relpath)
1306
+ {
1307
+ DIR *search_dir;
1308
+ char path[MAXPATHLEN+1];
1309
+ char *folder;
1310
+ const char *file;
1311
+
1312
+ struct dirent *cur;
1313
+
1314
+ /* get the folder name */
1315
+ file = GetFileName(relpath);
1316
+ folder = JS_smprintf("%s%c", relpath, DEFAULT_DIRECTORY_SEPARATOR);
1317
+ folder[file - relpath] = 0;
1318
+
1319
+ /* resolve relative paths */
1320
+ if (!JSL_RealPath(relpath, path)) {
1321
+ OutputErrorMessage(relpath, 0, 0, NULL, NULL, "unable to resolve path");
1322
+ SetExitCode(EXITCODE_FILE_ERROR);
1323
+ return JS_FALSE;
1324
+ }
1325
+
1326
+ /* get the full folder name */
1327
+ file = GetFileName(path);
1328
+ JS_smprintf_free(folder);
1329
+ folder = JS_smprintf("%s%c", path, DEFAULT_DIRECTORY_SEPARATOR);
1330
+ folder[file - path] = 0;
1331
+
1332
+ if (strchr(file, '?') != NULL || strchr(file, '*') != NULL) {
1333
+ /* this has wildcards, so do a search on this path */
1334
+ search_dir = opendir(folder);
1335
+ if (!search_dir) {
1336
+ OutputErrorMessage(relpath, 0, 0, NULL, NULL, "unable to search directory");
1337
+ SetExitCode(EXITCODE_FILE_ERROR);
1338
+ return JS_FALSE;
1339
+ }
1340
+ }
1341
+ else {
1342
+ /* see if it's a folder */
1343
+ search_dir = opendir(path);
1344
+ if (!search_dir) {
1345
+ /* if not, was this intended as a folder? */
1346
+ if (*path && (path[strlen(path)-1] == '/' || path[strlen(path)-1] == '\\')) {
1347
+ OutputErrorMessage(path, 0, 0, NULL, "can't open file", "path does not exist");
1348
+ JS_free(cx, folder);
1349
+ SetExitCode(EXITCODE_FILE_ERROR);
1350
+ return JS_FALSE;
1351
+ }
1352
+ else {
1353
+ /* treat as a file */
1354
+ JS_free(cx, folder);
1355
+ return ProcessSingleScript(cx, obj, path, NULL);
1356
+ }
1357
+ }
1358
+ }
1359
+
1360
+ while ((cur = readdir(search_dir)) != NULL) {
1361
+ char curPath[MAXPATHLEN+1];
1362
+ char *tmp;
1363
+
1364
+ curPath[0] = 0;
1365
+
1366
+ if (cur->d_name[0] == '.' && (cur->d_name[1] == 0 ||
1367
+ (cur->d_name[1] == '.' && cur->d_name[2] == 0))) {
1368
+ /*single/double dot*/
1369
+ continue;
1370
+ }
1371
+
1372
+ tmp = JS_smprintf("%s%s", folder, cur->d_name);
1373
+ if (!JSL_RealPath(tmp, curPath)) {
1374
+ JS_free(cx, tmp);
1375
+ closedir(search_dir);
1376
+ OutputErrorMessage(relpath, 0, 0, NULL, NULL, "unable to resolve path");
1377
+ SetExitCode(EXITCODE_FILE_ERROR);
1378
+ return JS_FALSE;
1379
+ }
1380
+ JS_free(cx, tmp);
1381
+
1382
+ /* test for directory */
1383
+ if (IsDir(curPath)) {
1384
+ if (gRecurse) {
1385
+ tmp = JS_smprintf("%s%c%s", curPath, DEFAULT_DIRECTORY_SEPARATOR, file);
1386
+ ProcessScripts(cx, obj, tmp);
1387
+ JS_free(cx, tmp);
1388
+ }
1389
+ }
1390
+ else if (PathMatchesWildcards(file, cur->d_name)) {
1391
+ /* process script */
1392
+ ProcessSingleScript(cx, obj, curPath, NULL);
1393
+ }
1394
+ }
1395
+
1396
+ closedir(search_dir);
1397
+ JS_free(cx, folder);
1398
+ return JS_TRUE;
1399
+ }
1400
+
1401
+ static JSBool
1402
+ ProcessStdin(JSContext *cx, JSObject *obj)
1403
+ {
1404
+ #define GROW_SIZE 10*1024
1405
+
1406
+ char *contentsPos, *contents;
1407
+ int buffer_size;
1408
+ JSBool success;
1409
+
1410
+ /* allocate buffer */
1411
+ buffer_size = GROW_SIZE;
1412
+ contents = (char*)JS_malloc(cx, buffer_size);
1413
+ contentsPos = contents;
1414
+
1415
+ /* read data */
1416
+ while ((*contentsPos = fgetc(stdin)) != EOF) {
1417
+ contentsPos++;
1418
+
1419
+ if (contentsPos-contents+1/*NULL*/ >= buffer_size) {
1420
+ /* NOTE: win32 was crashing over the JS_realloc call */
1421
+ size_t prevOffset, prevSize;
1422
+ char *prevContents;
1423
+
1424
+ /* save info about prev buffer */
1425
+ prevOffset = contentsPos - contents;
1426
+ prevSize = buffer_size;
1427
+ prevContents = contents;
1428
+
1429
+ /* allocate to new buffer */
1430
+ buffer_size += GROW_SIZE;
1431
+ contents = JS_malloc(cx, buffer_size);
1432
+ if (!contents) {
1433
+ JS_free(cx, prevContents);
1434
+ SetExitCode(EXITCODE_JS_ERROR);
1435
+ return JS_FALSE;
1436
+ }
1437
+
1438
+ /* restore old information */
1439
+ memcpy(contents, prevContents, prevSize);
1440
+ contentsPos = contents + prevOffset;
1441
+ JS_free(cx, prevContents);
1442
+ }
1443
+ }
1444
+ *contentsPos = 0;
1445
+
1446
+ /* lint */
1447
+ if (!JS_PushLintIdentifers(cx, NULL, NULL, gAlwaysUseOptionExplicit, gLambdaAssignRequiresSemicolon,
1448
+ gEnableLegacyControlComments, gEnableJScriptFunctionExtensions, NULL, NULL)) {
1449
+ JS_free(cx, contents);
1450
+ SetExitCode(EXITCODE_JS_ERROR);
1451
+ return JS_FALSE;
1452
+ }
1453
+
1454
+ success = ProcessScriptContents(cx, obj, JSL_FILETYPE_UNKNOWN, NULL, contents, NULL, NULL);
1455
+ JS_PopLintIdentifers(cx);
1456
+ JS_free(cx, contents);
1457
+
1458
+ if (!success)
1459
+ SetExitCode(EXITCODE_JS_ERROR);
1460
+ return success;
1461
+ }
1462
+
1463
+ static void
1464
+ PrintConfErrName(const uintN number, const char *format)
1465
+ {
1466
+ int chars;
1467
+
1468
+ fputc(showErrMsgs[number] ? '+' : '-', stdout);
1469
+ fputs(errorNames[number], stdout);
1470
+ chars = 1 + strlen(errorNames[number]);
1471
+
1472
+ while (chars < 30) {
1473
+ fputc(' ', stdout);
1474
+ chars++;
1475
+ }
1476
+ fputs("# ", stdout);
1477
+ fputs(format, stdout);
1478
+ fputs("\n", stdout);
1479
+ }
1480
+
1481
+ static void
1482
+ PrintDefaultConf(void)
1483
+ {
1484
+ fputs(
1485
+ "#\n"
1486
+ "# Configuration File for JavaScript Lint " JSL_VERSION "\n"
1487
+ "# " JSL_DEVELOPED_BY "\n"
1488
+ "#\n"
1489
+ "# This configuration file can be used to lint a collection of scripts, or to enable\n"
1490
+ "# or disable warnings for scripts that are linted via the command line.\n"
1491
+ "#\n"
1492
+ "\n"
1493
+ "### Warnings\n"
1494
+ "# Enable or disable warnings based on requirements.\n"
1495
+ "# Use \"+WarningName\" to display or \"-WarningName\" to suppress.\n"
1496
+ "#\n"
1497
+ , stdout);
1498
+
1499
+ /* keep in sync with ProcessConf */
1500
+ #define MSG_DEF(name, number, count, exception, format) \
1501
+ { if (CAN_DISABLE_WARNING(number)) PrintConfErrName(number, format); }
1502
+ #include "js.msg"
1503
+ #undef MSG_DEF
1504
+
1505
+ fputs(
1506
+ "\n\n### Output format\n"
1507
+ "# Customize the format of the error message.\n"
1508
+ "# __FILE__ indicates current file path\n"
1509
+ "# __FILENAME__ indicates current file name\n"
1510
+ "# __LINE__ indicates current line\n"
1511
+ "# __ERROR__ indicates error message\n"
1512
+ "#\n"
1513
+ "# Visual Studio syntax (default):\n"
1514
+ "+output-format __FILE__(__LINE__): __ERROR__\n"
1515
+ "# Alternative syntax:\n"
1516
+ "#+output-format __FILE__:__LINE__: __ERROR__\n"
1517
+ , stdout);
1518
+
1519
+ fputs(
1520
+ "\n\n### Context\n"
1521
+ "# Show the in-line position of the error.\n"
1522
+ "# Use \"+context\" to display or \"-context\" to suppress.\n"
1523
+ "#\n"
1524
+ "+context\n"
1525
+ , stdout);
1526
+
1527
+ fputs(
1528
+ "\n\n### Semicolons\n"
1529
+ "# By default, assignments of an anonymous function to a variable or\n"
1530
+ "# property (such as a function prototype) must be followed by a semicolon.\n"
1531
+ "#\n"
1532
+ "+lambda_assign_requires_semicolon\n"
1533
+ , stdout);
1534
+
1535
+ fputs(
1536
+ "\n\n### Control Comments\n"
1537
+ "# Both JavaScript Lint and the JScript interpreter confuse each other with the syntax for\n"
1538
+ "# the /*@keyword@*/ control comments and JScript conditional comments. (The latter is\n"
1539
+ "# enabled in JScript with @cc_on@). The /*jsl:keyword*/ syntax is preferred for this reason,\n"
1540
+ "# although legacy control comments are enabled by default for backward compatibility.\n"
1541
+ "#\n"
1542
+ "+legacy_control_comments\n"
1543
+ , stdout);
1544
+
1545
+ fputs(
1546
+ "\n\n### JScript Function Extensions\n"
1547
+ "# JScript allows member functions to be defined like this:\n"
1548
+ "# function MyObj() { /*constructor*/ }\n"
1549
+ "# function MyObj.prototype.go() { /*member function*/ }\n"
1550
+ "#\n"
1551
+ "# It also allows events to be attached like this:\n"
1552
+ "# function window::onload() { /*init page*/ }\n"
1553
+ "#\n"
1554
+ "# This is a Microsoft-only JavaScript extension. Enable this setting to allow them.\n"
1555
+ "#\n"
1556
+ "-jscript_function_extensions\n"
1557
+ , stdout);
1558
+
1559
+ fputs(
1560
+ "\n\n### Defining identifiers\n"
1561
+ "# By default, \"option explicit\" is enabled on a per-file basis.\n"
1562
+ "# To enable this for all files, use \"+always_use_option_explicit\"\n"
1563
+ "-always_use_option_explicit\n"
1564
+ "\n"
1565
+ "# Define certain identifiers of which the lint is not aware.\n"
1566
+ "# (Use this in conjunction with the \"undeclared identifier\" warning.)\n"
1567
+ "#\n"
1568
+ "# Common uses for webpages might be:\n"
1569
+ "#+define window\n"
1570
+ "#+define document\n"
1571
+ , stdout);
1572
+
1573
+ #ifdef WIN32
1574
+ fputs(
1575
+ "\n\n### Interactive\n"
1576
+ "# Prompt for a keystroke before exiting.\n"
1577
+ "#+pauseatend\n"
1578
+ , stdout);
1579
+ #endif
1580
+
1581
+ fputs(
1582
+ "\n\n### Files\n"
1583
+ "# Specify which files to lint\n"
1584
+ "# Use \"+recurse\" to enable recursion (disabled by default).\n"
1585
+ "# To add a set of files, use \"+process FileName\", \"+process Folder\\Path\\*.js\",\n"
1586
+ "# or \"+process Folder\\Path\\*.htm\".\n"
1587
+ "#\n"
1588
+ "+process jsl-test.js\n"
1589
+ , stdout);
1590
+ }
1591
+
1592
+ static void
1593
+ PrintHeader(void)
1594
+ {
1595
+ fprintf(stdout, "JavaScript Lint %s (%s)\n", JSL_VERSION, JS_GetImplementationVersion());
1596
+ fputs(JSL_DEVELOPED_BY "\n\n", stdout);
1597
+ }
1598
+
1599
+ static int
1600
+ usage(void)
1601
+ {
1602
+ fputc('\n', stdout);
1603
+ PrintHeader();
1604
+ fputs("Usage: jsl [-help:conf]\n"
1605
+ "\t[-conf filename] [-process filename] [+recurse|-recurse] [-stdin]\n"
1606
+ "\t[-nologo] [-nofilelisting] [-nocontext] [-nosummary] [-output-format ______]\n",
1607
+ stdout);
1608
+ #ifdef WIN32
1609
+ fputs("\t[-pauseatend]\n", stdout);
1610
+ #endif
1611
+
1612
+ fputs(
1613
+ "\nError levels:\n"
1614
+ " 0 - Success\n"
1615
+ " 1 - JavaScript warnings\n"
1616
+ " 2 - Usage or configuration error\n"
1617
+ " 3 - JavaScript error\n"
1618
+ " 4 - File error\n",
1619
+ stdout);
1620
+ SetExitCode(EXITCODE_USAGE_OR_CONFIGERR);
1621
+ return EXITCODE_USAGE_OR_CONFIGERR;
1622
+ }
1623
+
1624
+ static int
1625
+ LintConfError(JSContext *cx, const char *path, int lineno, const char *err)
1626
+ {
1627
+ OutputErrorMessage(path, lineno, 0, NULL, "configuration error", err);
1628
+ SetExitCode(EXITCODE_USAGE_OR_CONFIGERR);
1629
+ return EXITCODE_USAGE_OR_CONFIGERR;
1630
+ }
1631
+
1632
+ static int
1633
+ ProcessConf(JSContext *cx, JSObject *obj, const char *relpath, JSLPathList *scriptPaths)
1634
+ {
1635
+ char path[MAXPATHLEN+1];
1636
+ char line[MAX_CONF_LINE+1];
1637
+ int linelen, lineno;
1638
+ int ch;
1639
+
1640
+ FILE *file;
1641
+
1642
+ /* resolve relative paths */
1643
+ if (!JSL_RealPath(relpath, path)) {
1644
+ OutputErrorMessage(relpath, 0, 0, NULL, NULL, "unable to resolve path");
1645
+ SetExitCode(EXITCODE_FILE_ERROR);
1646
+ return EXITCODE_FILE_ERROR;
1647
+ }
1648
+
1649
+ /* open file */
1650
+ file = fopen(path, "r");
1651
+ if (!file) {
1652
+ OutputErrorMessage(path, 0, 0, NULL, "can't open file", strerror(errno));
1653
+ return EXITCODE_FILE_ERROR;
1654
+ }
1655
+
1656
+ ch = 0;
1657
+ lineno = 1;
1658
+ while(ch != EOF) {
1659
+ JSBool incomment;
1660
+ char *linepos;
1661
+ int i;
1662
+ incomment = JS_FALSE;
1663
+ linelen = 0;
1664
+
1665
+ /* read line */
1666
+ while((ch = fgetc(file)) != EOF && ch != '\n' && ch != '\r') {
1667
+ if (incomment) {
1668
+ /*ignore*/
1669
+ }
1670
+ else if (ch == '#') {
1671
+ incomment = JS_TRUE;
1672
+ }
1673
+ else if (linelen == MAX_CONF_LINE) {
1674
+ fclose(file);
1675
+ return LintConfError(cx, path, lineno, "exceeded maximum line length");
1676
+ }
1677
+ else
1678
+ line[linelen++] = ch;
1679
+ }
1680
+
1681
+ /* remove trailing whitespace */
1682
+ while (linelen > 0 && isspace(line[linelen-1]))
1683
+ linelen--;
1684
+ /* null-terminate */
1685
+ line[linelen] = 0;
1686
+ linepos = line;
1687
+
1688
+ /* skip the UTF-8 BOM on the first line */
1689
+ if (lineno == 1 && linelen >= sizeof(gUTF8BOM) && memcmp(linepos, gUTF8BOM, sizeof(gUTF8BOM)) == 0) {
1690
+ linepos += sizeof(gUTF8BOM);
1691
+ linelen -= sizeof(gUTF8BOM);
1692
+ }
1693
+
1694
+ if (!*linepos) {
1695
+ /* ignore blank line */
1696
+ }
1697
+ else if (*linepos == '-' || *linepos == '+') {
1698
+ JSBool enable;
1699
+ enable = (*linepos == '+');
1700
+ linepos++;
1701
+
1702
+ if (strcasecmp(linepos, "recurse") == 0) {
1703
+ gRecurse = enable;
1704
+ }
1705
+ else if (strcasecmp(linepos, "context") == 0) {
1706
+ gShowContext = enable;
1707
+ }
1708
+ else if (strncasecmp(linepos, "process", strlen("process")) == 0) {
1709
+ char delimiter;
1710
+ char *path;
1711
+
1712
+ if (!enable) {
1713
+ fclose(file);
1714
+ return LintConfError(cx, path, lineno, "-process is an invalid setting");
1715
+ }
1716
+
1717
+ linepos += strlen("process");
1718
+
1719
+ /* require (but skip) whitespace */
1720
+ if (!*linepos || !isspace(*linepos)) goto ProcessSettingErr_MissingPath;
1721
+ while (*linepos && isspace(*linepos))
1722
+ linepos++;
1723
+ if (!*linepos) goto ProcessSettingErr_MissingPath;
1724
+
1725
+ /* allow quote */
1726
+ if (*linepos == '\'') {
1727
+ delimiter = *linepos;
1728
+ linepos++;
1729
+ }
1730
+ else if (*linepos == '"') {
1731
+ delimiter = *linepos;
1732
+ linepos++;
1733
+ }
1734
+ else
1735
+ delimiter = 0;
1736
+
1737
+ /* read path */
1738
+ if (!*linepos) goto ProcessSettingErr_MissingQuote;
1739
+ path = linepos;
1740
+ while (*linepos && *linepos != delimiter)
1741
+ linepos++;
1742
+ if (delimiter && !*linepos) goto ProcessSettingErr_MissingQuote;
1743
+
1744
+ /* yank ending quote */
1745
+ if (linepos[0] && linepos[1]) goto ProcessSettingErr_Garbage;
1746
+ *linepos = 0;
1747
+
1748
+ AddPathToList(scriptPaths, path);
1749
+
1750
+ if (JS_FALSE) {
1751
+ ProcessSettingErr_MissingPath:
1752
+ fclose(file);
1753
+ return LintConfError(cx, path, lineno, "invalid process setting: missing path");
1754
+ ProcessSettingErr_MissingQuote:
1755
+ fclose(file);
1756
+ return LintConfError(cx, path, lineno, "invalid process setting: missing or mismatched quote");
1757
+ ProcessSettingErr_Garbage:
1758
+ fclose(file);
1759
+ return LintConfError(cx, path, lineno, "invalid process setting: garbage after path");
1760
+ }
1761
+ }
1762
+ else if (strncasecmp(linepos, "include", strlen("include")) == 0) {
1763
+ char delimiter;
1764
+ char *path;
1765
+
1766
+ if (!enable) {
1767
+ fclose(file);
1768
+ return LintConfError(cx, path, lineno, "-include is an invalid setting");
1769
+ }
1770
+
1771
+ linepos += strlen("include");
1772
+
1773
+ /* require (but skip) whitespace */
1774
+ if (!*linepos || !isspace(*linepos)) goto ProcessSettingErr_MissingPath;
1775
+ while (*linepos && isspace(*linepos))
1776
+ linepos++;
1777
+ if (!*linepos) goto ProcessSettingErr_MissingPath;
1778
+
1779
+ /* allow quote */
1780
+ if (*linepos == '\'') {
1781
+ delimiter = *linepos;
1782
+ linepos++;
1783
+ }
1784
+ else if (*linepos == '"') {
1785
+ delimiter = *linepos;
1786
+ linepos++;
1787
+ }
1788
+ else
1789
+ delimiter = 0;
1790
+
1791
+ /* read path */
1792
+ if (!*linepos) goto ProcessSettingErr_MissingQuote;
1793
+ path = linepos;
1794
+ while (*linepos && *linepos != delimiter)
1795
+ linepos++;
1796
+ if (delimiter && !*linepos) goto ProcessSettingErr_MissingQuote;
1797
+
1798
+ /* yank ending quote */
1799
+ if (linepos[0] && linepos[1]) goto ProcessSettingErr_Garbage;
1800
+ *linepos = 0;
1801
+
1802
+ AddPathToList(&gIncludePathList, path);
1803
+ /*
1804
+ if (JS_FALSE) {
1805
+ ProcessSettingErr_MissingPath:
1806
+ fclose(file);
1807
+ return LintConfError(cx, path, lineno, "invalid include setting: missing path");
1808
+ ProcessSettingErr_MissingQuote:
1809
+ fclose(file);
1810
+ return LintConfError(cx, path, lineno, "invalid include setting: missing or mismatched quote");
1811
+ ProcessSettingErr_Garbage:
1812
+ fclose(file);
1813
+ return LintConfError(cx, path, lineno, "invalid include setting: garbage after path");
1814
+ }
1815
+ */
1816
+ }
1817
+ else if (strncasecmp(linepos, "output-format", strlen("output-format")) == 0) {
1818
+ linepos += strlen("output-format");
1819
+
1820
+ /* skip whitespace */
1821
+ if (!*linepos || !isspace(*linepos)) {
1822
+ fclose(file);
1823
+ return LintConfError(cx, path, lineno, "expected whitespace after \"output-format\"");
1824
+ }
1825
+ while (*linepos && isspace(*linepos))
1826
+ linepos++;
1827
+
1828
+ if (!*linepos) {
1829
+ fclose(file);
1830
+ return LintConfError(cx, path, lineno, "expected format string after \"output-format\"");
1831
+ }
1832
+
1833
+ if (!enable) {
1834
+ fclose(file);
1835
+ return LintConfError(cx, path, lineno, "-output-format is an invalid setting");
1836
+ }
1837
+ strncpy(gOutputFormat, linepos, sizeof(gOutputFormat)-1);
1838
+ }
1839
+ else if (strcasecmp(linepos, "always_use_option_explicit") == 0) {
1840
+ gAlwaysUseOptionExplicit = enable;
1841
+ }
1842
+ else if (strcasecmp(linepos, "lambda_assign_requires_semicolon") == 0) {
1843
+ gLambdaAssignRequiresSemicolon = enable;
1844
+ }
1845
+ else if (strcasecmp(linepos, "legacy_control_comments") == 0) {
1846
+ gEnableLegacyControlComments = enable;
1847
+ }
1848
+ else if (strcasecmp(linepos, "jscript_function_extensions") == 0) {
1849
+ gEnableJScriptFunctionExtensions = enable;
1850
+ }
1851
+ else if (strncasecmp(linepos, "define", strlen("define")) == 0) {
1852
+ jsval val;
1853
+ val = JSVAL_VOID;
1854
+
1855
+ linepos += strlen("define");
1856
+
1857
+ /* skip whitespace */
1858
+ if (!*linepos || !isspace(*linepos)) {
1859
+ fclose(file);
1860
+ return LintConfError(cx, path, lineno, "expected whitespace after \"define\"");
1861
+ }
1862
+ while (*linepos && isspace(*linepos))
1863
+ linepos++;
1864
+
1865
+ if (!*linepos) {
1866
+ fclose(file);
1867
+ return LintConfError(cx, path, lineno, "expected identifier after \"define\"");
1868
+ }
1869
+
1870
+ if (!enable) {
1871
+ fclose(file);
1872
+ return LintConfError(cx, path, lineno, "Identifiers cannot be undefined");
1873
+ }
1874
+
1875
+ /* validate identifier */
1876
+ if (!JS_IsValidIdentifier(linepos)) {
1877
+ char *tmp;
1878
+ int result;
1879
+
1880
+ tmp = JS_smprintf("invalid identifier: \"%s\"", linepos);
1881
+
1882
+ fclose(file);
1883
+ result = LintConfError(cx, path, lineno, tmp);
1884
+ JS_free(cx, tmp);
1885
+ return result;
1886
+ }
1887
+ else if (JS_GetProperty(cx, obj, linepos, &val) && val != JSVAL_VOID) {
1888
+ char *tmp;
1889
+ tmp = JS_smprintf("identifier already defined: \"%s\"", linepos);
1890
+ OutputErrorMessage(path, lineno, 0, NULL, "configuration warning", tmp);
1891
+ JS_free(cx, tmp);
1892
+ }
1893
+ else if (!JS_SetProperty(cx, obj, linepos, &val)) {
1894
+ fclose(file);
1895
+ return LintConfError(cx, path, lineno, "unable to define identifier");
1896
+ }
1897
+ }
1898
+ #ifdef WIN32
1899
+ else if (strcasecmp(linepos, "pauseatend") == 0) {
1900
+ if (!enable) {
1901
+ fclose(file);
1902
+ return LintConfError(cx, path, lineno, "pauseatend cannot be disabled");
1903
+ }
1904
+
1905
+ gPauseAtEnd = JS_TRUE;
1906
+ }
1907
+ #endif
1908
+ else if (strcasecmp(linepos, "useless_expr") == 0) {
1909
+ /* deprecated */
1910
+ }
1911
+ else {
1912
+ /* keep in sync with PrintDefaultConf */
1913
+ for (i = 1; i < JSErr_Limit; i++) {
1914
+ if (CAN_DISABLE_WARNING(i)) {
1915
+ if (strcasecmp(linepos, errorNames[i]) == 0) {
1916
+ showErrMsgs[i] = enable;
1917
+ break;
1918
+ }
1919
+ }
1920
+ }
1921
+ if (i == JSErr_Limit) {
1922
+ fclose(file);
1923
+ return LintConfError(cx, path, lineno, "unrecognized config setting");
1924
+ }
1925
+ }
1926
+ }
1927
+ else {
1928
+ fclose(file);
1929
+ return LintConfError(cx, path, lineno, "unrecognized line format");
1930
+ }
1931
+
1932
+ lineno++;
1933
+ }
1934
+
1935
+ return 0;
1936
+ }
1937
+
1938
+ static int
1939
+ ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc)
1940
+ {
1941
+ int i, result;
1942
+ /* command line should take precedence over config */
1943
+ JSBool overrideRecurse, overrideShowContext, overrideOutputFormat;
1944
+ JSBool argRecurse, argShowContext;
1945
+ JSBool argPrintLogo, argPrintSummary, argUseStdin;
1946
+ JSBool argEncodeFormat;
1947
+ char argOutputFormat[MAX_CONF_LINE+1];
1948
+ /* paths */
1949
+ const char *configPath;
1950
+ JSLPathList scriptPaths;
1951
+
1952
+ if (!argc)
1953
+ return usage();
1954
+
1955
+ result = 0;
1956
+
1957
+ overrideRecurse = JS_FALSE;
1958
+ overrideShowContext = JS_FALSE;
1959
+ overrideOutputFormat = JS_FALSE;
1960
+ argRecurse = JS_FALSE;
1961
+ argShowContext = JS_FALSE;
1962
+ argPrintLogo = JS_TRUE;
1963
+ argPrintSummary = JS_TRUE;
1964
+ argUseStdin = JS_FALSE;
1965
+ argEncodeFormat = JS_FALSE;
1966
+ argOutputFormat[0] = '\0';
1967
+
1968
+ configPath = NULL;
1969
+ JS_INIT_CLIST(&scriptPaths.links);
1970
+
1971
+
1972
+ for (i = 0; i < argc; i++) {
1973
+ char *parm;
1974
+ parm = argv[i];
1975
+
1976
+ if (strcasecmp(parm, "+recurse") == 0) {
1977
+ overrideRecurse = JS_TRUE;
1978
+ argRecurse = JS_TRUE;
1979
+ }
1980
+ else if (strcasecmp(parm, "-recurse") == 0) {
1981
+ overrideRecurse = JS_TRUE;
1982
+ argRecurse = JS_FALSE;
1983
+ }
1984
+ else if (strcasecmp(parm, "+context") == 0) {
1985
+ /* backward compatibility */
1986
+ overrideShowContext = JS_TRUE;
1987
+ argShowContext = JS_TRUE;
1988
+ }
1989
+ else if (strcasecmp(parm, "-context") == 0) {
1990
+ /* backward compatibility */
1991
+ overrideShowContext = JS_TRUE;
1992
+ argShowContext = JS_FALSE;
1993
+ }
1994
+ else {
1995
+ /* skip - and -- (backward compatibility) */
1996
+ int dashes;
1997
+ dashes = 0;
1998
+ if (*parm == '-') {
1999
+ parm++;
2000
+ dashes++;
2001
+ if (*parm == '-') {
2002
+ parm++;
2003
+ dashes++;
2004
+ }
2005
+ }
2006
+
2007
+ if (strcasecmp(parm, "help:conf") == 0) {
2008
+ PrintDefaultConf();
2009
+ result = 0;
2010
+ goto cleanup;
2011
+ }
2012
+ else if (strcasecmp(parm, "nologo") == 0) {
2013
+ argPrintLogo = JS_FALSE;
2014
+ }
2015
+ else if (strcasecmp(parm, "nofilelisting") == 0) {
2016
+ gShowFileListing = JS_FALSE;
2017
+ }
2018
+ else if (strcasecmp(parm, "nocontext") == 0) {
2019
+ overrideShowContext = JS_TRUE;
2020
+ argShowContext = JS_FALSE;
2021
+ }
2022
+ else if (strcasecmp(parm, "nosummary") == 0) {
2023
+ argPrintSummary = JS_FALSE;
2024
+ }
2025
+ else if (strcasecmp(parm, "output-format") == 0 && dashes == 1) {
2026
+ int requiredBufferSize;
2027
+ if (++i >= argc) {
2028
+ fprintf(stdout, "Error: missing output format.");
2029
+ result = usage();
2030
+ goto cleanup;
2031
+ }
2032
+
2033
+ /* check length */
2034
+ requiredBufferSize = strlen(argv[i])+1;
2035
+ if (requiredBufferSize > sizeof(gOutputFormat) ||
2036
+ requiredBufferSize > sizeof(argOutputFormat)) {
2037
+ fprintf(stdout, "Error: the output format exceeds the maximum length");
2038
+ result = usage();
2039
+ goto cleanup;
2040
+ }
2041
+
2042
+ overrideOutputFormat = JS_TRUE;
2043
+ strcpy(argOutputFormat, argv[i]);
2044
+ }
2045
+ else if (strcasecmp(parm, "stdin") == 0) {
2046
+ argUseStdin = JS_TRUE;
2047
+ }
2048
+ else if (strcasecmp(parm, "conf") == 0) {
2049
+ /* only allow one config */
2050
+ if (configPath) {
2051
+ fputs("Error: multiple configuration files.\n", stdout);
2052
+ result = usage();
2053
+ goto cleanup;
2054
+ }
2055
+
2056
+ if (++i >= argc) {
2057
+ fprintf(stdout, "Error: missing configuration path\n");
2058
+ result = usage();
2059
+ goto cleanup;
2060
+ }
2061
+
2062
+ configPath = argv[i];
2063
+ }
2064
+ else if (strcasecmp(parm, "process") == 0) {
2065
+ if (++i < argc)
2066
+ AddPathToList(&scriptPaths, argv[i]);
2067
+ else {
2068
+ fprintf(stdout, "Error: missing file path to process\n");
2069
+ result = usage();
2070
+ goto cleanup;
2071
+ }
2072
+ }
2073
+ else if (strcasecmp(parm, "include") == 0) {
2074
+ if (++i < argc)
2075
+ AddPathToList(&gIncludePathList, argv[i]);
2076
+ else {
2077
+ fprintf(stdout, "Error: missing path for include\n");
2078
+ result = usage();
2079
+ goto cleanup;
2080
+ }
2081
+ }
2082
+ #ifdef WIN32
2083
+ else if (strcasecmp(parm, "pauseatend") == 0) {
2084
+ gPauseAtEnd = JS_TRUE;
2085
+ }
2086
+ #endif
2087
+ else {
2088
+ fprintf(stdout, "Error: unrecognized parameter: %s\n", argv[i]);
2089
+ result = usage();
2090
+ goto cleanup;
2091
+ }
2092
+ }
2093
+ }
2094
+
2095
+ /* stdin is exclusive! */
2096
+ if (argUseStdin && !JS_CLIST_IS_EMPTY(&scriptPaths.links)) {
2097
+ fputs("Error: cannot process other scripts when reading from stdin\n", stdout);
2098
+ result = usage();
2099
+ goto cleanup;
2100
+ }
2101
+
2102
+ if (argPrintLogo)
2103
+ PrintHeader();
2104
+
2105
+ if (configPath) {
2106
+ result = ProcessConf(cx, obj, configPath, &scriptPaths);
2107
+ if (result)
2108
+ goto cleanup;
2109
+ }
2110
+
2111
+ /* handle command-line overrides */
2112
+ if (overrideRecurse)
2113
+ gRecurse = argRecurse;
2114
+ if (overrideShowContext)
2115
+ gShowContext = argShowContext;
2116
+ if (overrideOutputFormat)
2117
+ strcpy(gOutputFormat, argOutputFormat);
2118
+
2119
+ if (argUseStdin) {
2120
+ ProcessStdin(cx, obj);
2121
+ }
2122
+ else {
2123
+ /* delete items from the array as they're processed */
2124
+ while (!JS_CLIST_IS_EMPTY(&scriptPaths.links)) {
2125
+ JSLPathList *curFileItem = (JSLPathList*)JS_LIST_HEAD(&scriptPaths.links);
2126
+ ProcessScripts(cx, obj, curFileItem->path);
2127
+ JS_REMOVE_LINK(&curFileItem->links);
2128
+ JS_free(cx, curFileItem);
2129
+ }
2130
+ }
2131
+
2132
+ if (argPrintSummary)
2133
+ fprintf(stdout, "\n%i error(s), %i warning(s)\n", gNumErrors, gNumWarnings);
2134
+ return gExitCode;
2135
+
2136
+ cleanup:
2137
+ /* delete items */
2138
+ FreePathList(cx, &scriptPaths);
2139
+ return result;
2140
+ }
2141
+
2142
+ #define LAZY_STANDARD_CLASSES
2143
+
2144
+ static JSBool
2145
+ global_enumerate(JSContext *cx, JSObject *obj)
2146
+ {
2147
+ #ifdef LAZY_STANDARD_CLASSES
2148
+ return JS_EnumerateStandardClasses(cx, obj);
2149
+ #else
2150
+ return JS_TRUE;
2151
+ #endif
2152
+ }
2153
+
2154
+ static JSBool
2155
+ global_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
2156
+ JSObject **objp)
2157
+ {
2158
+ #ifdef LAZY_STANDARD_CLASSES
2159
+ if ((flags & JSRESOLVE_ASSIGNING) == 0) {
2160
+ JSBool resolved;
2161
+
2162
+ if (!JS_ResolveStandardClass(cx, obj, id, &resolved))
2163
+ return JS_FALSE;
2164
+ if (resolved) {
2165
+ *objp = obj;
2166
+ return JS_TRUE;
2167
+ }
2168
+ }
2169
+ #endif
2170
+
2171
+ return JS_TRUE;
2172
+
2173
+ }
2174
+
2175
+ JSClass global_class = {
2176
+ "global", JSCLASS_NEW_RESOLVE,
2177
+ JS_PropertyStub, JS_PropertyStub,
2178
+ JS_PropertyStub, JS_PropertyStub,
2179
+ global_enumerate, (JSResolveOp) global_resolve,
2180
+ JS_ConvertStub, JS_FinalizeStub
2181
+ };
2182
+
2183
+ static void
2184
+ my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
2185
+ {
2186
+ int i, j, k, n, colno;
2187
+ const char *prefix;
2188
+
2189
+ if (!report) {
2190
+ OutputErrorMessage(NULL, 0, 0, NULL, NULL, message);
2191
+ return;
2192
+ }
2193
+
2194
+ /* Conditionally ignore reported warnings. */
2195
+ if (!showErrMsgs[report->errorNumber]) {
2196
+ return;
2197
+ }
2198
+
2199
+ if (CAN_DISABLE_WARNING(report->errorNumber) && SHOULD_IGNORE_LINT_WARNINGS(cx)) {
2200
+ return;
2201
+ }
2202
+
2203
+ prefix = NULL;
2204
+ if (JSREPORT_IS_WARNING(report->flags)) {
2205
+ if (IS_JSL_WARNING_MSG(report->errorNumber)) {
2206
+ prefix = LINT_WARNING_PREFIX;
2207
+ }
2208
+ else if (JSREPORT_IS_STRICT(report->flags)) {
2209
+ prefix = STRICT_WARNING_PREFIX;
2210
+ }
2211
+ else
2212
+ prefix = WARNING_PREFIX;
2213
+ }
2214
+ else {
2215
+ prefix = NULL;
2216
+ }
2217
+
2218
+ /* colno is 1-based */
2219
+ colno = 0;
2220
+ if (report->linebuf)
2221
+ colno = PTRDIFF(report->tokenptr, report->linebuf, char)+1;
2222
+
2223
+ OutputErrorMessage(report->filename, report->lineno, colno,
2224
+ errorNames[report->errorNumber], prefix, message);
2225
+
2226
+ if (report->linebuf && gShowContext) {
2227
+ /* report->linebuf usually ends with a newline. */
2228
+ n = strlen(report->linebuf);
2229
+ fprintf(stdout, "%s%s%s%s",
2230
+ ""/*prefix*/,
2231
+ report->linebuf,
2232
+ (n > 0 && report->linebuf[n-1] == '\n') ? "" : "\n",
2233
+ ""/*prefix*/);
2234
+ n = PTRDIFF(report->tokenptr, report->linebuf, char);
2235
+ for (i = j = 0; i < n; i++) {
2236
+ if (report->linebuf[i] == '\t') {
2237
+ for (k = (j + 8) & ~7; j < k; j++) {
2238
+ fputc('.', stdout);
2239
+ }
2240
+ continue;
2241
+ }
2242
+ fputc('.', stdout);
2243
+ j++;
2244
+ }
2245
+ fputs("^\n\n", stdout);
2246
+ }
2247
+
2248
+ if (!JSREPORT_IS_WARNING(report->flags)) {
2249
+ SetExitCode(EXITCODE_JS_ERROR);
2250
+ gNumErrors++;
2251
+ }
2252
+ else {
2253
+ SetExitCode(EXITCODE_JS_WARNING);
2254
+ gNumWarnings++;
2255
+ }
2256
+ }
2257
+
2258
+ static JSBool
2259
+ LoadErrNames(JSContext *cx)
2260
+ {
2261
+ int i;
2262
+ for (i = 0; i < JSErr_Limit; i++) {
2263
+ char *tmp;
2264
+
2265
+ /* remove prefix */
2266
+ JS_ASSERT(strncasecmp(errorNames[i], "JSMSG_", 6) == 0);
2267
+ tmp = JS_strdup(cx, errorNames[i] + 6);
2268
+ if (!tmp)
2269
+ return JS_FALSE;
2270
+ errorNames[i] = tmp;
2271
+
2272
+ /* to lowercase */
2273
+ while (*tmp) {
2274
+ *tmp = tolower(*tmp);
2275
+ tmp++;
2276
+ }
2277
+ }
2278
+
2279
+ return JS_TRUE;
2280
+ }
2281
+
2282
+ static void
2283
+ FreeErrNames(JSContext *cx)
2284
+ {
2285
+ int i;
2286
+ for (i = 0; i < JSErr_Limit; i++) {
2287
+ JS_free(cx, errorNames[i]);
2288
+ errorNames[i] = NULL;
2289
+ }
2290
+ }
2291
+
2292
+ int
2293
+ main(int argc, char **argv, char **envp)
2294
+ {
2295
+ JSVersion version;
2296
+ JSRuntime *rt;
2297
+ JSContext *cx;
2298
+ JSObject *glob;
2299
+ int result;
2300
+
2301
+ version = JSVERSION_DEFAULT;
2302
+
2303
+ argc--;
2304
+ argv++;
2305
+
2306
+ JS_INIT_CLIST(&gScriptList.links);
2307
+ JS_INIT_CLIST(&gIncludePathList.links);
2308
+ JS_ASSERT(sizeof(placeholders) / sizeof(placeholders[0]) == JSLPlaceholder_Limit);
2309
+
2310
+ rt = JS_NewRuntime(64L * 1024L * 1024L);
2311
+ if (!rt)
2312
+ return 1;
2313
+
2314
+ cx = JS_NewContext(rt, 8192);
2315
+ if (!cx)
2316
+ return 1;
2317
+ JS_SetErrorReporter(cx, my_ErrorReporter);
2318
+
2319
+ glob = JS_NewObject(cx, &global_class, NULL, NULL);
2320
+ if (!glob)
2321
+ return 1;
2322
+ #ifdef LAZY_STANDARD_CLASSES
2323
+ JS_SetGlobalObject(cx, glob);
2324
+ #else
2325
+ if (!JS_InitStandardClasses(cx, glob))
2326
+ return 1;
2327
+ #endif
2328
+
2329
+ /* switch over error names to lower-case values */
2330
+ if (!LoadErrNames(cx))
2331
+ return 1;
2332
+
2333
+ /* Set version only after there is a global object. */
2334
+ if (version != JSVERSION_DEFAULT)
2335
+ JS_SetVersion(cx, version);
2336
+
2337
+ JS_ToggleOptions(cx, JSOPTION_STRICT);
2338
+
2339
+ result = ProcessArgs(cx, glob, argv, argc);
2340
+
2341
+ FreeErrNames(cx);
2342
+ JS_DestroyContext(cx);
2343
+ JS_DestroyRuntime(rt);
2344
+ JS_ShutDown();
2345
+
2346
+ /* clean up list of files */
2347
+ while (!JS_CLIST_IS_EMPTY(&gScriptList.links)) {
2348
+ JSLScriptList *scriptItem;
2349
+ scriptItem = (JSLScriptList*)JS_LIST_HEAD(&gScriptList.links);
2350
+ JS_REMOVE_LINK(&scriptItem->links);
2351
+
2352
+ /* clean up dependencies */
2353
+ while (!JS_CLIST_IS_EMPTY(&scriptItem->directDependencies.links)) {
2354
+ JSLScriptDependencyList *dependency;
2355
+ dependency = (JSLScriptDependencyList*)JS_LIST_HEAD(&scriptItem->directDependencies.links);
2356
+ JS_REMOVE_LINK(&dependency->links);
2357
+ }
2358
+
2359
+ JS_free(cx, scriptItem);
2360
+ }
2361
+
2362
+ #ifdef WIN32
2363
+ if (gPauseAtEnd) {
2364
+ fputs("Press any key to continue...", stdout);
2365
+ getch();
2366
+ fputc('\n', stdout);
2367
+ }
2368
+ #endif
2369
+
2370
+ return result;
2371
+ }