libv8 3.3.10.4 → 3.5.10.beta1

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 (538) hide show
  1. data/lib/libv8/scons/CHANGES.txt +24 -231
  2. data/lib/libv8/scons/LICENSE.txt +1 -1
  3. data/lib/libv8/scons/MANIFEST +0 -1
  4. data/lib/libv8/scons/PKG-INFO +1 -1
  5. data/lib/libv8/scons/README.txt +9 -9
  6. data/lib/libv8/scons/RELEASE.txt +75 -77
  7. data/lib/libv8/scons/engine/SCons/Action.py +6 -22
  8. data/lib/libv8/scons/engine/SCons/Builder.py +2 -2
  9. data/lib/libv8/scons/engine/SCons/CacheDir.py +2 -2
  10. data/lib/libv8/scons/engine/SCons/Debug.py +2 -2
  11. data/lib/libv8/scons/engine/SCons/Defaults.py +10 -24
  12. data/lib/libv8/scons/engine/SCons/Environment.py +19 -118
  13. data/lib/libv8/scons/engine/SCons/Errors.py +2 -2
  14. data/lib/libv8/scons/engine/SCons/Executor.py +2 -2
  15. data/lib/libv8/scons/engine/SCons/Job.py +2 -2
  16. data/lib/libv8/scons/engine/SCons/Memoize.py +2 -2
  17. data/lib/libv8/scons/engine/SCons/Node/Alias.py +2 -2
  18. data/lib/libv8/scons/engine/SCons/Node/FS.py +121 -281
  19. data/lib/libv8/scons/engine/SCons/Node/Python.py +2 -2
  20. data/lib/libv8/scons/engine/SCons/Node/__init__.py +5 -6
  21. data/lib/libv8/scons/engine/SCons/Options/BoolOption.py +2 -2
  22. data/lib/libv8/scons/engine/SCons/Options/EnumOption.py +2 -2
  23. data/lib/libv8/scons/engine/SCons/Options/ListOption.py +2 -2
  24. data/lib/libv8/scons/engine/SCons/Options/PackageOption.py +2 -2
  25. data/lib/libv8/scons/engine/SCons/Options/PathOption.py +2 -2
  26. data/lib/libv8/scons/engine/SCons/Options/__init__.py +2 -2
  27. data/lib/libv8/scons/engine/SCons/PathList.py +2 -2
  28. data/lib/libv8/scons/engine/SCons/Platform/__init__.py +2 -2
  29. data/lib/libv8/scons/engine/SCons/Platform/aix.py +2 -2
  30. data/lib/libv8/scons/engine/SCons/Platform/cygwin.py +2 -2
  31. data/lib/libv8/scons/engine/SCons/Platform/darwin.py +3 -27
  32. data/lib/libv8/scons/engine/SCons/Platform/hpux.py +2 -2
  33. data/lib/libv8/scons/engine/SCons/Platform/irix.py +2 -2
  34. data/lib/libv8/scons/engine/SCons/Platform/os2.py +2 -2
  35. data/lib/libv8/scons/engine/SCons/Platform/posix.py +2 -2
  36. data/lib/libv8/scons/engine/SCons/Platform/sunos.py +2 -2
  37. data/lib/libv8/scons/engine/SCons/Platform/win32.py +2 -2
  38. data/lib/libv8/scons/engine/SCons/SConf.py +2 -2
  39. data/lib/libv8/scons/engine/SCons/SConsign.py +3 -9
  40. data/lib/libv8/scons/engine/SCons/Scanner/C.py +2 -2
  41. data/lib/libv8/scons/engine/SCons/Scanner/D.py +2 -2
  42. data/lib/libv8/scons/engine/SCons/Scanner/Dir.py +2 -2
  43. data/lib/libv8/scons/engine/SCons/Scanner/Fortran.py +2 -2
  44. data/lib/libv8/scons/engine/SCons/Scanner/IDL.py +2 -2
  45. data/lib/libv8/scons/engine/SCons/Scanner/LaTeX.py +2 -5
  46. data/lib/libv8/scons/engine/SCons/Scanner/Prog.py +2 -2
  47. data/lib/libv8/scons/engine/SCons/Scanner/RC.py +3 -3
  48. data/lib/libv8/scons/engine/SCons/Scanner/__init__.py +2 -2
  49. data/lib/libv8/scons/engine/SCons/Script/Interactive.py +2 -2
  50. data/lib/libv8/scons/engine/SCons/Script/Main.py +11 -82
  51. data/lib/libv8/scons/engine/SCons/Script/SConsOptions.py +5 -5
  52. data/lib/libv8/scons/engine/SCons/Script/SConscript.py +2 -2
  53. data/lib/libv8/scons/engine/SCons/Script/__init__.py +2 -2
  54. data/lib/libv8/scons/engine/SCons/Sig.py +2 -2
  55. data/lib/libv8/scons/engine/SCons/Subst.py +2 -2
  56. data/lib/libv8/scons/engine/SCons/Taskmaster.py +2 -10
  57. data/lib/libv8/scons/engine/SCons/Tool/386asm.py +2 -2
  58. data/lib/libv8/scons/engine/SCons/Tool/BitKeeper.py +2 -2
  59. data/lib/libv8/scons/engine/SCons/Tool/CVS.py +2 -2
  60. data/lib/libv8/scons/engine/SCons/Tool/FortranCommon.py +2 -19
  61. data/lib/libv8/scons/engine/SCons/Tool/JavaCommon.py +2 -2
  62. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/__init__.py +2 -2
  63. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/arch.py +2 -2
  64. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/common.py +2 -2
  65. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/netframework.py +2 -2
  66. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/sdk.py +2 -2
  67. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/vc.py +6 -9
  68. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/vs.py +2 -29
  69. data/lib/libv8/scons/engine/SCons/Tool/Perforce.py +2 -2
  70. data/lib/libv8/scons/engine/SCons/Tool/PharLapCommon.py +2 -2
  71. data/lib/libv8/scons/engine/SCons/Tool/RCS.py +2 -2
  72. data/lib/libv8/scons/engine/SCons/Tool/SCCS.py +2 -2
  73. data/lib/libv8/scons/engine/SCons/Tool/Subversion.py +2 -2
  74. data/lib/libv8/scons/engine/SCons/Tool/__init__.py +3 -3
  75. data/lib/libv8/scons/engine/SCons/Tool/aixc++.py +2 -2
  76. data/lib/libv8/scons/engine/SCons/Tool/aixcc.py +2 -2
  77. data/lib/libv8/scons/engine/SCons/Tool/aixf77.py +2 -2
  78. data/lib/libv8/scons/engine/SCons/Tool/aixlink.py +2 -2
  79. data/lib/libv8/scons/engine/SCons/Tool/applelink.py +2 -2
  80. data/lib/libv8/scons/engine/SCons/Tool/ar.py +2 -2
  81. data/lib/libv8/scons/engine/SCons/Tool/as.py +2 -2
  82. data/lib/libv8/scons/engine/SCons/Tool/bcc32.py +2 -2
  83. data/lib/libv8/scons/engine/SCons/Tool/c++.py +2 -2
  84. data/lib/libv8/scons/engine/SCons/Tool/cc.py +2 -2
  85. data/lib/libv8/scons/engine/SCons/Tool/cvf.py +2 -2
  86. data/lib/libv8/scons/engine/SCons/Tool/default.py +2 -2
  87. data/lib/libv8/scons/engine/SCons/Tool/dmd.py +7 -24
  88. data/lib/libv8/scons/engine/SCons/Tool/dvi.py +2 -2
  89. data/lib/libv8/scons/engine/SCons/Tool/dvipdf.py +2 -3
  90. data/lib/libv8/scons/engine/SCons/Tool/dvips.py +2 -3
  91. data/lib/libv8/scons/engine/SCons/Tool/f77.py +2 -2
  92. data/lib/libv8/scons/engine/SCons/Tool/f90.py +2 -2
  93. data/lib/libv8/scons/engine/SCons/Tool/f95.py +2 -2
  94. data/lib/libv8/scons/engine/SCons/Tool/filesystem.py +2 -2
  95. data/lib/libv8/scons/engine/SCons/Tool/fortran.py +2 -2
  96. data/lib/libv8/scons/engine/SCons/Tool/g++.py +2 -2
  97. data/lib/libv8/scons/engine/SCons/Tool/g77.py +2 -2
  98. data/lib/libv8/scons/engine/SCons/Tool/gas.py +2 -2
  99. data/lib/libv8/scons/engine/SCons/Tool/gcc.py +2 -2
  100. data/lib/libv8/scons/engine/SCons/Tool/gfortran.py +3 -3
  101. data/lib/libv8/scons/engine/SCons/Tool/gnulink.py +3 -2
  102. data/lib/libv8/scons/engine/SCons/Tool/gs.py +2 -2
  103. data/lib/libv8/scons/engine/SCons/Tool/hpc++.py +2 -2
  104. data/lib/libv8/scons/engine/SCons/Tool/hpcc.py +2 -2
  105. data/lib/libv8/scons/engine/SCons/Tool/hplink.py +2 -2
  106. data/lib/libv8/scons/engine/SCons/Tool/icc.py +2 -2
  107. data/lib/libv8/scons/engine/SCons/Tool/icl.py +2 -2
  108. data/lib/libv8/scons/engine/SCons/Tool/ifl.py +2 -2
  109. data/lib/libv8/scons/engine/SCons/Tool/ifort.py +2 -2
  110. data/lib/libv8/scons/engine/SCons/Tool/ilink.py +2 -2
  111. data/lib/libv8/scons/engine/SCons/Tool/ilink32.py +2 -2
  112. data/lib/libv8/scons/engine/SCons/Tool/install.py +3 -57
  113. data/lib/libv8/scons/engine/SCons/Tool/intelc.py +25 -65
  114. data/lib/libv8/scons/engine/SCons/Tool/ipkg.py +2 -2
  115. data/lib/libv8/scons/engine/SCons/Tool/jar.py +3 -9
  116. data/lib/libv8/scons/engine/SCons/Tool/javac.py +2 -2
  117. data/lib/libv8/scons/engine/SCons/Tool/javah.py +2 -2
  118. data/lib/libv8/scons/engine/SCons/Tool/latex.py +2 -3
  119. data/lib/libv8/scons/engine/SCons/Tool/lex.py +2 -2
  120. data/lib/libv8/scons/engine/SCons/Tool/link.py +5 -6
  121. data/lib/libv8/scons/engine/SCons/Tool/linkloc.py +2 -2
  122. data/lib/libv8/scons/engine/SCons/Tool/m4.py +2 -2
  123. data/lib/libv8/scons/engine/SCons/Tool/masm.py +2 -2
  124. data/lib/libv8/scons/engine/SCons/Tool/midl.py +2 -2
  125. data/lib/libv8/scons/engine/SCons/Tool/mingw.py +10 -31
  126. data/lib/libv8/scons/engine/SCons/Tool/mslib.py +2 -2
  127. data/lib/libv8/scons/engine/SCons/Tool/mslink.py +9 -61
  128. data/lib/libv8/scons/engine/SCons/Tool/mssdk.py +2 -2
  129. data/lib/libv8/scons/engine/SCons/Tool/msvc.py +11 -21
  130. data/lib/libv8/scons/engine/SCons/Tool/msvs.py +59 -477
  131. data/lib/libv8/scons/engine/SCons/Tool/mwcc.py +2 -2
  132. data/lib/libv8/scons/engine/SCons/Tool/mwld.py +2 -2
  133. data/lib/libv8/scons/engine/SCons/Tool/nasm.py +2 -2
  134. data/lib/libv8/scons/engine/SCons/Tool/packaging/__init__.py +2 -2
  135. data/lib/libv8/scons/engine/SCons/Tool/packaging/ipk.py +2 -2
  136. data/lib/libv8/scons/engine/SCons/Tool/packaging/msi.py +2 -2
  137. data/lib/libv8/scons/engine/SCons/Tool/packaging/rpm.py +2 -2
  138. data/lib/libv8/scons/engine/SCons/Tool/packaging/src_tarbz2.py +2 -2
  139. data/lib/libv8/scons/engine/SCons/Tool/packaging/src_targz.py +2 -2
  140. data/lib/libv8/scons/engine/SCons/Tool/packaging/src_zip.py +2 -2
  141. data/lib/libv8/scons/engine/SCons/Tool/packaging/tarbz2.py +2 -2
  142. data/lib/libv8/scons/engine/SCons/Tool/packaging/targz.py +2 -2
  143. data/lib/libv8/scons/engine/SCons/Tool/packaging/zip.py +2 -2
  144. data/lib/libv8/scons/engine/SCons/Tool/pdf.py +2 -2
  145. data/lib/libv8/scons/engine/SCons/Tool/pdflatex.py +2 -3
  146. data/lib/libv8/scons/engine/SCons/Tool/pdftex.py +2 -3
  147. data/lib/libv8/scons/engine/SCons/Tool/qt.py +2 -2
  148. data/lib/libv8/scons/engine/SCons/Tool/rmic.py +3 -9
  149. data/lib/libv8/scons/engine/SCons/Tool/rpcgen.py +2 -2
  150. data/lib/libv8/scons/engine/SCons/Tool/rpm.py +2 -2
  151. data/lib/libv8/scons/engine/SCons/Tool/sgiar.py +2 -2
  152. data/lib/libv8/scons/engine/SCons/Tool/sgic++.py +2 -2
  153. data/lib/libv8/scons/engine/SCons/Tool/sgicc.py +2 -2
  154. data/lib/libv8/scons/engine/SCons/Tool/sgilink.py +3 -2
  155. data/lib/libv8/scons/engine/SCons/Tool/sunar.py +2 -2
  156. data/lib/libv8/scons/engine/SCons/Tool/sunc++.py +2 -2
  157. data/lib/libv8/scons/engine/SCons/Tool/suncc.py +2 -2
  158. data/lib/libv8/scons/engine/SCons/Tool/sunf77.py +2 -2
  159. data/lib/libv8/scons/engine/SCons/Tool/sunf90.py +2 -2
  160. data/lib/libv8/scons/engine/SCons/Tool/sunf95.py +2 -2
  161. data/lib/libv8/scons/engine/SCons/Tool/sunlink.py +3 -2
  162. data/lib/libv8/scons/engine/SCons/Tool/swig.py +5 -6
  163. data/lib/libv8/scons/engine/SCons/Tool/tar.py +2 -2
  164. data/lib/libv8/scons/engine/SCons/Tool/tex.py +43 -96
  165. data/lib/libv8/scons/engine/SCons/Tool/textfile.py +2 -2
  166. data/lib/libv8/scons/engine/SCons/Tool/tlib.py +2 -2
  167. data/lib/libv8/scons/engine/SCons/Tool/wix.py +2 -2
  168. data/lib/libv8/scons/engine/SCons/Tool/yacc.py +2 -12
  169. data/lib/libv8/scons/engine/SCons/Tool/zip.py +2 -2
  170. data/lib/libv8/scons/engine/SCons/Util.py +3 -3
  171. data/lib/libv8/scons/engine/SCons/Variables/BoolVariable.py +2 -2
  172. data/lib/libv8/scons/engine/SCons/Variables/EnumVariable.py +3 -3
  173. data/lib/libv8/scons/engine/SCons/Variables/ListVariable.py +2 -2
  174. data/lib/libv8/scons/engine/SCons/Variables/PackageVariable.py +2 -2
  175. data/lib/libv8/scons/engine/SCons/Variables/PathVariable.py +2 -2
  176. data/lib/libv8/scons/engine/SCons/Variables/__init__.py +2 -2
  177. data/lib/libv8/scons/engine/SCons/Warnings.py +2 -2
  178. data/lib/libv8/scons/engine/SCons/__init__.py +6 -6
  179. data/lib/libv8/scons/engine/SCons/compat/__init__.py +2 -2
  180. data/lib/libv8/scons/engine/SCons/compat/_scons_builtins.py +2 -2
  181. data/lib/libv8/scons/engine/SCons/compat/_scons_collections.py +2 -2
  182. data/lib/libv8/scons/engine/SCons/compat/_scons_dbm.py +2 -2
  183. data/lib/libv8/scons/engine/SCons/compat/_scons_hashlib.py +2 -2
  184. data/lib/libv8/scons/engine/SCons/compat/_scons_io.py +2 -2
  185. data/lib/libv8/scons/engine/SCons/cpp.py +2 -2
  186. data/lib/libv8/scons/engine/SCons/dblite.py +1 -4
  187. data/lib/libv8/scons/engine/SCons/exitfuncs.py +2 -2
  188. data/lib/libv8/scons/scons-time.1 +3 -3
  189. data/lib/libv8/scons/scons.1 +1164 -1170
  190. data/lib/libv8/scons/sconsign.1 +3 -3
  191. data/lib/libv8/scons/script/scons +22 -22
  192. data/lib/libv8/scons/script/scons-time +2 -2
  193. data/lib/libv8/scons/script/scons.bat +4 -7
  194. data/lib/libv8/scons/script/sconsign +20 -21
  195. data/lib/libv8/scons/setup.cfg +1 -0
  196. data/lib/libv8/scons/setup.py +40 -38
  197. data/lib/libv8/v8/.gitignore +1 -1
  198. data/lib/libv8/v8/AUTHORS +2 -0
  199. data/lib/libv8/v8/ChangeLog +387 -0
  200. data/lib/libv8/v8/Makefile +171 -0
  201. data/lib/libv8/v8/SConstruct +124 -51
  202. data/lib/libv8/v8/build/README.txt +31 -14
  203. data/lib/libv8/v8/build/all.gyp +11 -4
  204. data/lib/libv8/v8/build/armu.gypi +6 -2
  205. data/lib/libv8/v8/build/common.gypi +240 -94
  206. data/lib/libv8/v8/build/gyp_v8 +32 -4
  207. data/lib/libv8/v8/build/standalone.gypi +200 -0
  208. data/lib/libv8/v8/include/v8-debug.h +0 -0
  209. data/lib/libv8/v8/include/v8-profiler.h +8 -11
  210. data/lib/libv8/v8/include/v8.h +191 -108
  211. data/lib/libv8/v8/preparser/SConscript +2 -2
  212. data/lib/libv8/v8/preparser/preparser-process.cc +3 -3
  213. data/lib/libv8/v8/preparser/preparser.gyp +42 -0
  214. data/lib/libv8/v8/src/SConscript +33 -8
  215. data/lib/libv8/v8/src/accessors.cc +77 -43
  216. data/lib/libv8/v8/src/api.cc +393 -191
  217. data/lib/libv8/v8/src/api.h +4 -8
  218. data/lib/libv8/v8/src/apinatives.js +15 -3
  219. data/lib/libv8/v8/src/arguments.h +8 -0
  220. data/lib/libv8/v8/src/arm/assembler-arm.cc +120 -120
  221. data/lib/libv8/v8/src/arm/assembler-arm.h +92 -43
  222. data/lib/libv8/v8/src/arm/builtins-arm.cc +32 -39
  223. data/lib/libv8/v8/src/arm/code-stubs-arm.cc +572 -351
  224. data/lib/libv8/v8/src/arm/code-stubs-arm.h +8 -77
  225. data/lib/libv8/v8/src/arm/codegen-arm.h +0 -2
  226. data/lib/libv8/v8/src/arm/deoptimizer-arm.cc +50 -30
  227. data/lib/libv8/v8/src/arm/disasm-arm.cc +1 -1
  228. data/lib/libv8/v8/src/arm/frames-arm.h +9 -5
  229. data/lib/libv8/v8/src/arm/full-codegen-arm.cc +331 -432
  230. data/lib/libv8/v8/src/arm/ic-arm.cc +192 -124
  231. data/lib/libv8/v8/src/arm/lithium-arm.cc +216 -232
  232. data/lib/libv8/v8/src/arm/lithium-arm.h +106 -259
  233. data/lib/libv8/v8/src/arm/lithium-codegen-arm.cc +633 -642
  234. data/lib/libv8/v8/src/arm/lithium-codegen-arm.h +4 -4
  235. data/lib/libv8/v8/src/arm/lithium-gap-resolver-arm.cc +1 -3
  236. data/lib/libv8/v8/src/arm/macro-assembler-arm.cc +260 -185
  237. data/lib/libv8/v8/src/arm/macro-assembler-arm.h +45 -25
  238. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.cc +25 -13
  239. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.h +3 -0
  240. data/lib/libv8/v8/src/arm/stub-cache-arm.cc +413 -226
  241. data/lib/libv8/v8/src/array.js +38 -18
  242. data/lib/libv8/v8/src/assembler.cc +12 -5
  243. data/lib/libv8/v8/src/assembler.h +15 -9
  244. data/lib/libv8/v8/src/ast-inl.h +34 -25
  245. data/lib/libv8/v8/src/ast.cc +141 -72
  246. data/lib/libv8/v8/src/ast.h +255 -181
  247. data/lib/libv8/v8/src/bignum.cc +3 -4
  248. data/lib/libv8/v8/src/bootstrapper.cc +55 -11
  249. data/lib/libv8/v8/src/bootstrapper.h +3 -2
  250. data/lib/libv8/v8/src/builtins.cc +8 -2
  251. data/lib/libv8/v8/src/builtins.h +4 -0
  252. data/lib/libv8/v8/src/cached-powers.cc +8 -4
  253. data/lib/libv8/v8/src/checks.h +3 -3
  254. data/lib/libv8/v8/src/code-stubs.cc +173 -28
  255. data/lib/libv8/v8/src/code-stubs.h +104 -148
  256. data/lib/libv8/v8/src/codegen.cc +8 -8
  257. data/lib/libv8/v8/src/compilation-cache.cc +2 -47
  258. data/lib/libv8/v8/src/compilation-cache.h +0 -10
  259. data/lib/libv8/v8/src/compiler.cc +27 -16
  260. data/lib/libv8/v8/src/compiler.h +13 -18
  261. data/lib/libv8/v8/src/contexts.cc +107 -72
  262. data/lib/libv8/v8/src/contexts.h +70 -34
  263. data/lib/libv8/v8/src/conversions-inl.h +572 -14
  264. data/lib/libv8/v8/src/conversions.cc +9 -707
  265. data/lib/libv8/v8/src/conversions.h +23 -12
  266. data/lib/libv8/v8/src/cpu-profiler-inl.h +2 -19
  267. data/lib/libv8/v8/src/cpu-profiler.cc +4 -21
  268. data/lib/libv8/v8/src/cpu-profiler.h +8 -17
  269. data/lib/libv8/v8/src/d8-debug.cc +5 -3
  270. data/lib/libv8/v8/src/d8-debug.h +6 -7
  271. data/lib/libv8/v8/src/d8-posix.cc +1 -10
  272. data/lib/libv8/v8/src/d8.cc +721 -219
  273. data/lib/libv8/v8/src/d8.gyp +37 -12
  274. data/lib/libv8/v8/src/d8.h +141 -19
  275. data/lib/libv8/v8/src/d8.js +17 -8
  276. data/lib/libv8/v8/src/date.js +16 -5
  277. data/lib/libv8/v8/src/dateparser-inl.h +242 -39
  278. data/lib/libv8/v8/src/dateparser.cc +38 -4
  279. data/lib/libv8/v8/src/dateparser.h +170 -28
  280. data/lib/libv8/v8/src/debug-agent.cc +5 -3
  281. data/lib/libv8/v8/src/debug-agent.h +11 -7
  282. data/lib/libv8/v8/src/debug-debugger.js +65 -34
  283. data/lib/libv8/v8/src/debug.cc +30 -60
  284. data/lib/libv8/v8/src/debug.h +5 -3
  285. data/lib/libv8/v8/src/deoptimizer.cc +227 -10
  286. data/lib/libv8/v8/src/deoptimizer.h +133 -9
  287. data/lib/libv8/v8/src/disassembler.cc +22 -14
  288. data/lib/libv8/v8/src/diy-fp.cc +4 -3
  289. data/lib/libv8/v8/src/diy-fp.h +3 -3
  290. data/lib/libv8/v8/src/elements.cc +634 -0
  291. data/lib/libv8/v8/src/elements.h +95 -0
  292. data/lib/libv8/v8/src/execution.cc +5 -21
  293. data/lib/libv8/v8/src/extensions/experimental/break-iterator.cc +3 -1
  294. data/lib/libv8/v8/src/extensions/experimental/break-iterator.h +1 -1
  295. data/lib/libv8/v8/src/extensions/experimental/collator.cc +6 -2
  296. data/lib/libv8/v8/src/extensions/experimental/collator.h +1 -2
  297. data/lib/libv8/v8/src/extensions/experimental/datetime-format.cc +384 -0
  298. data/lib/libv8/v8/src/extensions/experimental/datetime-format.h +83 -0
  299. data/lib/libv8/v8/src/extensions/experimental/experimental.gyp +18 -7
  300. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.cc +12 -16
  301. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.h +1 -1
  302. data/lib/libv8/v8/src/extensions/experimental/i18n-js2c.py +126 -0
  303. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.cc +3 -4
  304. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.h +1 -1
  305. data/lib/libv8/v8/src/{shell.h → extensions/experimental/i18n-natives.h} +8 -20
  306. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.cc +45 -1
  307. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.h +21 -1
  308. data/lib/libv8/v8/src/extensions/experimental/i18n.js +211 -11
  309. data/lib/libv8/v8/src/extensions/experimental/language-matcher.cc +4 -3
  310. data/lib/libv8/v8/src/extensions/experimental/language-matcher.h +1 -1
  311. data/lib/libv8/v8/src/extensions/experimental/number-format.cc +374 -0
  312. data/lib/libv8/v8/src/extensions/experimental/number-format.h +71 -0
  313. data/lib/libv8/v8/src/factory.cc +89 -18
  314. data/lib/libv8/v8/src/factory.h +36 -8
  315. data/lib/libv8/v8/src/flag-definitions.h +11 -44
  316. data/lib/libv8/v8/src/frames-inl.h +8 -1
  317. data/lib/libv8/v8/src/frames.cc +39 -3
  318. data/lib/libv8/v8/src/frames.h +10 -3
  319. data/lib/libv8/v8/src/full-codegen.cc +311 -293
  320. data/lib/libv8/v8/src/full-codegen.h +183 -143
  321. data/lib/libv8/v8/src/func-name-inferrer.cc +29 -15
  322. data/lib/libv8/v8/src/func-name-inferrer.h +19 -9
  323. data/lib/libv8/v8/src/gdb-jit.cc +658 -55
  324. data/lib/libv8/v8/src/gdb-jit.h +6 -2
  325. data/lib/libv8/v8/src/global-handles.cc +368 -312
  326. data/lib/libv8/v8/src/global-handles.h +29 -36
  327. data/lib/libv8/v8/src/globals.h +3 -1
  328. data/lib/libv8/v8/src/handles.cc +43 -69
  329. data/lib/libv8/v8/src/handles.h +21 -16
  330. data/lib/libv8/v8/src/heap-inl.h +11 -13
  331. data/lib/libv8/v8/src/heap-profiler.cc +0 -999
  332. data/lib/libv8/v8/src/heap-profiler.h +0 -303
  333. data/lib/libv8/v8/src/heap.cc +366 -141
  334. data/lib/libv8/v8/src/heap.h +87 -26
  335. data/lib/libv8/v8/src/hydrogen-instructions.cc +192 -81
  336. data/lib/libv8/v8/src/hydrogen-instructions.h +711 -482
  337. data/lib/libv8/v8/src/hydrogen.cc +1146 -629
  338. data/lib/libv8/v8/src/hydrogen.h +100 -64
  339. data/lib/libv8/v8/src/ia32/assembler-ia32.cc +19 -0
  340. data/lib/libv8/v8/src/ia32/assembler-ia32.h +15 -2
  341. data/lib/libv8/v8/src/ia32/builtins-ia32.cc +34 -39
  342. data/lib/libv8/v8/src/ia32/code-stubs-ia32.cc +675 -377
  343. data/lib/libv8/v8/src/ia32/code-stubs-ia32.h +8 -69
  344. data/lib/libv8/v8/src/ia32/codegen-ia32.cc +1 -0
  345. data/lib/libv8/v8/src/ia32/codegen-ia32.h +0 -2
  346. data/lib/libv8/v8/src/ia32/cpu-ia32.cc +3 -2
  347. data/lib/libv8/v8/src/ia32/deoptimizer-ia32.cc +28 -3
  348. data/lib/libv8/v8/src/ia32/disasm-ia32.cc +21 -10
  349. data/lib/libv8/v8/src/ia32/frames-ia32.h +6 -5
  350. data/lib/libv8/v8/src/ia32/full-codegen-ia32.cc +459 -465
  351. data/lib/libv8/v8/src/ia32/ic-ia32.cc +196 -147
  352. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.cc +575 -650
  353. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.h +19 -21
  354. data/lib/libv8/v8/src/ia32/lithium-gap-resolver-ia32.cc +7 -2
  355. data/lib/libv8/v8/src/ia32/lithium-ia32.cc +261 -256
  356. data/lib/libv8/v8/src/ia32/lithium-ia32.h +234 -335
  357. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.cc +224 -67
  358. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.h +63 -19
  359. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.cc +22 -8
  360. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.h +3 -0
  361. data/lib/libv8/v8/src/ia32/stub-cache-ia32.cc +380 -239
  362. data/lib/libv8/v8/src/ic.cc +198 -234
  363. data/lib/libv8/v8/src/ic.h +32 -30
  364. data/lib/libv8/v8/src/interpreter-irregexp.cc +6 -4
  365. data/lib/libv8/v8/src/isolate.cc +112 -95
  366. data/lib/libv8/v8/src/isolate.h +55 -71
  367. data/lib/libv8/v8/src/json-parser.h +486 -48
  368. data/lib/libv8/v8/src/json.js +28 -23
  369. data/lib/libv8/v8/src/jsregexp.cc +163 -208
  370. data/lib/libv8/v8/src/jsregexp.h +0 -1
  371. data/lib/libv8/v8/src/lithium-allocator-inl.h +29 -27
  372. data/lib/libv8/v8/src/lithium-allocator.cc +22 -17
  373. data/lib/libv8/v8/src/lithium-allocator.h +8 -8
  374. data/lib/libv8/v8/src/lithium.cc +16 -11
  375. data/lib/libv8/v8/src/lithium.h +31 -34
  376. data/lib/libv8/v8/src/liveedit.cc +111 -15
  377. data/lib/libv8/v8/src/liveedit.h +3 -4
  378. data/lib/libv8/v8/src/liveobjectlist.cc +116 -80
  379. data/lib/libv8/v8/src/liveobjectlist.h +2 -2
  380. data/lib/libv8/v8/src/log-inl.h +0 -4
  381. data/lib/libv8/v8/src/log-utils.cc +25 -143
  382. data/lib/libv8/v8/src/log-utils.h +13 -92
  383. data/lib/libv8/v8/src/log.cc +26 -249
  384. data/lib/libv8/v8/src/log.h +6 -17
  385. data/lib/libv8/v8/src/macros.py +9 -6
  386. data/lib/libv8/v8/src/mark-compact.cc +276 -56
  387. data/lib/libv8/v8/src/mark-compact.h +20 -0
  388. data/lib/libv8/v8/src/messages.js +93 -39
  389. data/lib/libv8/v8/src/mips/assembler-mips-inl.h +9 -3
  390. data/lib/libv8/v8/src/mips/assembler-mips.cc +297 -189
  391. data/lib/libv8/v8/src/mips/assembler-mips.h +121 -54
  392. data/lib/libv8/v8/src/mips/builtins-mips.cc +23 -24
  393. data/lib/libv8/v8/src/mips/code-stubs-mips.cc +484 -263
  394. data/lib/libv8/v8/src/mips/code-stubs-mips.h +8 -83
  395. data/lib/libv8/v8/src/mips/codegen-mips.h +0 -2
  396. data/lib/libv8/v8/src/mips/constants-mips.h +37 -11
  397. data/lib/libv8/v8/src/mips/deoptimizer-mips.cc +6 -1
  398. data/lib/libv8/v8/src/mips/frames-mips.h +8 -7
  399. data/lib/libv8/v8/src/mips/full-codegen-mips.cc +258 -419
  400. data/lib/libv8/v8/src/mips/ic-mips.cc +181 -121
  401. data/lib/libv8/v8/src/mips/macro-assembler-mips.cc +640 -382
  402. data/lib/libv8/v8/src/mips/macro-assembler-mips.h +94 -89
  403. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.cc +23 -10
  404. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.h +6 -1
  405. data/lib/libv8/v8/src/mips/simulator-mips.cc +249 -49
  406. data/lib/libv8/v8/src/mips/simulator-mips.h +25 -1
  407. data/lib/libv8/v8/src/mips/stub-cache-mips.cc +373 -161
  408. data/lib/libv8/v8/src/mirror-debugger.js +55 -8
  409. data/lib/libv8/v8/src/misc-intrinsics.h +89 -0
  410. data/lib/libv8/v8/src/mksnapshot.cc +36 -4
  411. data/lib/libv8/v8/src/natives.h +5 -2
  412. data/lib/libv8/v8/src/objects-debug.cc +73 -6
  413. data/lib/libv8/v8/src/objects-inl.h +529 -164
  414. data/lib/libv8/v8/src/objects-printer.cc +67 -12
  415. data/lib/libv8/v8/src/objects-visiting.cc +13 -2
  416. data/lib/libv8/v8/src/objects-visiting.h +41 -1
  417. data/lib/libv8/v8/src/objects.cc +2200 -1177
  418. data/lib/libv8/v8/src/objects.h +912 -283
  419. data/lib/libv8/v8/src/parser.cc +566 -371
  420. data/lib/libv8/v8/src/parser.h +35 -33
  421. data/lib/libv8/v8/src/platform-cygwin.cc +10 -25
  422. data/lib/libv8/v8/src/platform-freebsd.cc +4 -29
  423. data/lib/libv8/v8/src/platform-linux.cc +60 -57
  424. data/lib/libv8/v8/src/platform-macos.cc +4 -27
  425. data/lib/libv8/v8/src/platform-nullos.cc +3 -16
  426. data/lib/libv8/v8/src/platform-openbsd.cc +247 -85
  427. data/lib/libv8/v8/src/platform-posix.cc +43 -1
  428. data/lib/libv8/v8/src/platform-solaris.cc +151 -112
  429. data/lib/libv8/v8/src/platform-tls.h +1 -1
  430. data/lib/libv8/v8/src/platform-win32.cc +65 -39
  431. data/lib/libv8/v8/src/platform.h +17 -14
  432. data/lib/libv8/v8/src/preparse-data-format.h +2 -2
  433. data/lib/libv8/v8/src/preparse-data.h +8 -2
  434. data/lib/libv8/v8/src/preparser-api.cc +2 -18
  435. data/lib/libv8/v8/src/preparser.cc +106 -65
  436. data/lib/libv8/v8/src/preparser.h +26 -5
  437. data/lib/libv8/v8/src/prettyprinter.cc +25 -43
  438. data/lib/libv8/v8/src/profile-generator-inl.h +0 -4
  439. data/lib/libv8/v8/src/profile-generator.cc +213 -34
  440. data/lib/libv8/v8/src/profile-generator.h +9 -9
  441. data/lib/libv8/v8/src/property.h +1 -0
  442. data/lib/libv8/v8/src/proxy.js +74 -4
  443. data/lib/libv8/v8/src/regexp-macro-assembler.cc +10 -6
  444. data/lib/libv8/v8/src/regexp.js +16 -11
  445. data/lib/libv8/v8/src/rewriter.cc +24 -133
  446. data/lib/libv8/v8/src/runtime-profiler.cc +27 -151
  447. data/lib/libv8/v8/src/runtime-profiler.h +5 -31
  448. data/lib/libv8/v8/src/runtime.cc +1450 -681
  449. data/lib/libv8/v8/src/runtime.h +47 -31
  450. data/lib/libv8/v8/src/runtime.js +2 -1
  451. data/lib/libv8/v8/src/scanner-base.cc +358 -220
  452. data/lib/libv8/v8/src/scanner-base.h +30 -138
  453. data/lib/libv8/v8/src/scanner.cc +0 -18
  454. data/lib/libv8/v8/src/scanner.h +0 -15
  455. data/lib/libv8/v8/src/scopeinfo.cc +3 -1
  456. data/lib/libv8/v8/src/scopeinfo.h +1 -6
  457. data/lib/libv8/v8/src/scopes.cc +243 -253
  458. data/lib/libv8/v8/src/scopes.h +58 -109
  459. data/lib/libv8/v8/src/serialize.cc +12 -54
  460. data/lib/libv8/v8/src/serialize.h +47 -0
  461. data/lib/libv8/v8/src/small-pointer-list.h +25 -0
  462. data/lib/libv8/v8/src/spaces-inl.h +4 -50
  463. data/lib/libv8/v8/src/spaces.cc +64 -131
  464. data/lib/libv8/v8/src/spaces.h +19 -70
  465. data/lib/libv8/v8/src/string-stream.cc +3 -1
  466. data/lib/libv8/v8/src/string.js +10 -6
  467. data/lib/libv8/v8/src/strtod.cc +7 -3
  468. data/lib/libv8/v8/src/stub-cache.cc +59 -129
  469. data/lib/libv8/v8/src/stub-cache.h +42 -54
  470. data/lib/libv8/v8/src/third_party/valgrind/valgrind.h +1447 -1339
  471. data/lib/libv8/v8/src/token.cc +4 -4
  472. data/lib/libv8/v8/src/token.h +6 -5
  473. data/lib/libv8/v8/src/type-info.cc +173 -129
  474. data/lib/libv8/v8/src/type-info.h +40 -22
  475. data/lib/libv8/v8/src/utils.cc +25 -304
  476. data/lib/libv8/v8/src/utils.h +118 -3
  477. data/lib/libv8/v8/src/v8-counters.h +3 -6
  478. data/lib/libv8/v8/src/v8.cc +34 -27
  479. data/lib/libv8/v8/src/v8.h +7 -7
  480. data/lib/libv8/v8/src/v8conversions.cc +129 -0
  481. data/lib/libv8/v8/src/v8conversions.h +60 -0
  482. data/lib/libv8/v8/src/v8globals.h +15 -6
  483. data/lib/libv8/v8/src/v8natives.js +300 -78
  484. data/lib/libv8/v8/src/v8threads.cc +14 -6
  485. data/lib/libv8/v8/src/v8threads.h +4 -1
  486. data/lib/libv8/v8/src/v8utils.cc +360 -0
  487. data/lib/libv8/v8/src/v8utils.h +17 -66
  488. data/lib/libv8/v8/src/variables.cc +7 -12
  489. data/lib/libv8/v8/src/variables.h +12 -10
  490. data/lib/libv8/v8/src/version.cc +2 -2
  491. data/lib/libv8/v8/src/vm-state-inl.h +0 -41
  492. data/lib/libv8/v8/src/vm-state.h +0 -11
  493. data/lib/libv8/v8/src/weakmap.js +103 -0
  494. data/lib/libv8/v8/src/x64/assembler-x64.h +6 -3
  495. data/lib/libv8/v8/src/x64/builtins-x64.cc +25 -22
  496. data/lib/libv8/v8/src/x64/code-stubs-x64.cc +523 -250
  497. data/lib/libv8/v8/src/x64/code-stubs-x64.h +8 -71
  498. data/lib/libv8/v8/src/x64/codegen-x64.cc +1 -0
  499. data/lib/libv8/v8/src/x64/codegen-x64.h +0 -2
  500. data/lib/libv8/v8/src/x64/cpu-x64.cc +2 -1
  501. data/lib/libv8/v8/src/x64/deoptimizer-x64.cc +40 -8
  502. data/lib/libv8/v8/src/x64/disasm-x64.cc +12 -10
  503. data/lib/libv8/v8/src/x64/frames-x64.h +7 -6
  504. data/lib/libv8/v8/src/x64/full-codegen-x64.cc +310 -415
  505. data/lib/libv8/v8/src/x64/ic-x64.cc +180 -117
  506. data/lib/libv8/v8/src/x64/lithium-codegen-x64.cc +411 -523
  507. data/lib/libv8/v8/src/x64/lithium-codegen-x64.h +11 -6
  508. data/lib/libv8/v8/src/x64/lithium-x64.cc +191 -216
  509. data/lib/libv8/v8/src/x64/lithium-x64.h +112 -263
  510. data/lib/libv8/v8/src/x64/macro-assembler-x64.cc +177 -61
  511. data/lib/libv8/v8/src/x64/macro-assembler-x64.h +23 -7
  512. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.cc +21 -9
  513. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.h +6 -0
  514. data/lib/libv8/v8/src/x64/stub-cache-x64.cc +273 -107
  515. data/lib/libv8/v8/src/zone.cc +31 -22
  516. data/lib/libv8/v8/src/zone.h +12 -6
  517. data/lib/libv8/v8/tools/codemap.js +8 -0
  518. data/lib/libv8/v8/tools/gcmole/Makefile +43 -0
  519. data/lib/libv8/v8/tools/gcmole/gcmole.lua +0 -2
  520. data/lib/libv8/v8/tools/gdb-v8-support.py +154 -0
  521. data/lib/libv8/v8/tools/grokdump.py +44 -35
  522. data/lib/libv8/v8/tools/gyp/v8.gyp +94 -248
  523. data/lib/libv8/v8/tools/js2c.py +83 -52
  524. data/lib/libv8/v8/tools/linux-tick-processor +4 -6
  525. data/lib/libv8/v8/tools/ll_prof.py +3 -3
  526. data/lib/libv8/v8/tools/oom_dump/README +3 -1
  527. data/lib/libv8/v8/tools/presubmit.py +11 -4
  528. data/lib/libv8/v8/tools/profile.js +46 -2
  529. data/lib/libv8/v8/tools/splaytree.js +11 -0
  530. data/lib/libv8/v8/tools/stats-viewer.py +15 -11
  531. data/lib/libv8/v8/tools/test-wrapper-gypbuild.py +227 -0
  532. data/lib/libv8/v8/tools/test.py +28 -8
  533. data/lib/libv8/v8/tools/tickprocessor.js +0 -16
  534. data/lib/libv8/version.rb +1 -1
  535. data/libv8.gemspec +2 -2
  536. metadata +31 -19
  537. data/lib/libv8/scons/engine/SCons/Tool/f03.py +0 -63
  538. data/lib/libv8/v8/src/json-parser.cc +0 -504
@@ -28,11 +28,34 @@
28
28
  #ifndef V8_CONVERSIONS_H_
29
29
  #define V8_CONVERSIONS_H_
30
30
 
31
+ #include <limits>
32
+
31
33
  #include "scanner-base.h"
32
34
 
33
35
  namespace v8 {
34
36
  namespace internal {
35
37
 
38
+ // Maximum number of significant digits in decimal representation.
39
+ // The longest possible double in decimal representation is
40
+ // (2^53 - 1) * 2 ^ -1074 that is (2 ^ 53 - 1) * 5 ^ 1074 / 10 ^ 1074
41
+ // (768 digits). If we parse a number whose first digits are equal to a
42
+ // mean of 2 adjacent doubles (that could have up to 769 digits) the result
43
+ // must be rounded to the bigger one unless the tail consists of zeros, so
44
+ // we don't need to preserve all the digits.
45
+ const int kMaxSignificantDigits = 772;
46
+
47
+
48
+ static bool isDigit(int x, int radix) {
49
+ return (x >= '0' && x <= '9' && x < '0' + radix)
50
+ || (radix > 10 && x >= 'a' && x < 'a' + radix - 10)
51
+ || (radix > 10 && x >= 'A' && x < 'A' + radix - 10);
52
+ }
53
+
54
+
55
+ static double SignedZero(bool negative) {
56
+ return negative ? -0.0 : 0.0;
57
+ }
58
+
36
59
 
37
60
  // The fast double-to-(unsigned-)int conversion routine does not guarantee
38
61
  // rounding towards zero.
@@ -87,16 +110,7 @@ enum ConversionFlags {
87
110
  };
88
111
 
89
112
 
90
- // Convert from Number object to C integer.
91
- static inline int32_t NumberToInt32(Object* number);
92
- static inline uint32_t NumberToUint32(Object* number);
93
-
94
-
95
113
  // Converts a string into a double value according to ECMA-262 9.3.1
96
- double StringToDouble(UnicodeCache* unicode_cache,
97
- String* str,
98
- int flags,
99
- double empty_string_val = 0);
100
114
  double StringToDouble(UnicodeCache* unicode_cache,
101
115
  Vector<const char> str,
102
116
  int flags,
@@ -111,9 +125,6 @@ double StringToDouble(UnicodeCache* unicode_cache,
111
125
  int flags,
112
126
  double empty_string_val = 0);
113
127
 
114
- // Converts a string into an integer.
115
- double StringToInt(UnicodeCache* unicode_cache, String* str, int radix);
116
-
117
128
  // Converts a double to a string value according to ECMA-262 9.8.1.
118
129
  // The buffer should be large enough for any floating point number.
119
130
  // 100 characters is enough.
@@ -30,8 +30,7 @@
30
30
 
31
31
  #include "cpu-profiler.h"
32
32
 
33
- #ifdef ENABLE_LOGGING_AND_PROFILING
34
-
33
+ #include <new>
35
34
  #include "circular-queue-inl.h"
36
35
  #include "profile-generator-inl.h"
37
36
  #include "unbound-queue-inl.h"
@@ -62,24 +61,10 @@ void SharedFunctionInfoMoveEventRecord::UpdateCodeMap(CodeMap* code_map) {
62
61
  }
63
62
 
64
63
 
65
- TickSampleEventRecord* TickSampleEventRecord::init(void* value) {
66
- TickSampleEventRecord* result =
67
- reinterpret_cast<TickSampleEventRecord*>(value);
68
- result->filler = 1;
69
- ASSERT(result->filler != SamplingCircularQueue::kClear);
70
- // Init the required fields only.
71
- result->sample.pc = NULL;
72
- result->sample.frames_count = 0;
73
- result->sample.has_external_callback = false;
74
- return result;
75
- }
76
-
77
-
78
64
  TickSample* ProfilerEventsProcessor::TickSampleEvent() {
79
65
  generator_->Tick();
80
66
  TickSampleEventRecord* evt =
81
- TickSampleEventRecord::init(ticks_buffer_.Enqueue());
82
- evt->order = enqueue_order_; // No increment!
67
+ new(ticks_buffer_.Enqueue()) TickSampleEventRecord(enqueue_order_);
83
68
  return &evt->sample;
84
69
  }
85
70
 
@@ -96,6 +81,4 @@ bool ProfilerEventsProcessor::FilterOutCodeCreateEvent(
96
81
 
97
82
  } } // namespace v8::internal
98
83
 
99
- #endif // ENABLE_LOGGING_AND_PROFILING
100
-
101
84
  #endif // V8_CPU_PROFILER_INL_H_
@@ -29,8 +29,6 @@
29
29
 
30
30
  #include "cpu-profiler-inl.h"
31
31
 
32
- #ifdef ENABLE_LOGGING_AND_PROFILING
33
-
34
32
  #include "frames-inl.h"
35
33
  #include "hashmap.h"
36
34
  #include "log-inl.h"
@@ -46,9 +44,8 @@ static const int kTickSamplesBufferChunkSize = 64*KB;
46
44
  static const int kTickSamplesBufferChunksCount = 16;
47
45
 
48
46
 
49
- ProfilerEventsProcessor::ProfilerEventsProcessor(Isolate* isolate,
50
- ProfileGenerator* generator)
51
- : Thread(isolate, "v8:ProfEvntProc"),
47
+ ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator)
48
+ : Thread("v8:ProfEvntProc"),
52
49
  generator_(generator),
53
50
  running_(true),
54
51
  ticks_buffer_(sizeof(TickSampleEventRecord),
@@ -182,20 +179,16 @@ void ProfilerEventsProcessor::RegExpCodeCreateEvent(
182
179
 
183
180
 
184
181
  void ProfilerEventsProcessor::AddCurrentStack() {
185
- TickSampleEventRecord record;
182
+ TickSampleEventRecord record(enqueue_order_);
186
183
  TickSample* sample = &record.sample;
187
184
  Isolate* isolate = Isolate::Current();
188
185
  sample->state = isolate->current_vm_state();
189
186
  sample->pc = reinterpret_cast<Address>(sample); // Not NULL.
190
- sample->tos = NULL;
191
- sample->has_external_callback = false;
192
- sample->frames_count = 0;
193
187
  for (StackTraceFrameIterator it(isolate);
194
188
  !it.done() && sample->frames_count < TickSample::kMaxFramesCount;
195
189
  it.Advance()) {
196
190
  sample->stack[sample->frames_count++] = it.frame()->pc();
197
191
  }
198
- record.order = enqueue_order_;
199
192
  ticks_from_vm_buffer_.Enqueue(record);
200
193
  }
201
194
 
@@ -507,7 +500,7 @@ void CpuProfiler::StartProcessorIfNotStarted() {
507
500
  saved_logging_nesting_ = isolate->logger()->logging_nesting_;
508
501
  isolate->logger()->logging_nesting_ = 0;
509
502
  generator_ = new ProfileGenerator(profiles_);
510
- processor_ = new ProfilerEventsProcessor(isolate, generator_);
503
+ processor_ = new ProfilerEventsProcessor(generator_);
511
504
  NoBarrier_Store(&is_profiling_, true);
512
505
  processor_->Start();
513
506
  // Enumerate stuff we already have in the heap.
@@ -579,31 +572,21 @@ void CpuProfiler::StopProcessor() {
579
572
  logger->logging_nesting_ = saved_logging_nesting_;
580
573
  }
581
574
 
582
- } } // namespace v8::internal
583
-
584
- #endif // ENABLE_LOGGING_AND_PROFILING
585
-
586
- namespace v8 {
587
- namespace internal {
588
575
 
589
576
  void CpuProfiler::Setup() {
590
- #ifdef ENABLE_LOGGING_AND_PROFILING
591
577
  Isolate* isolate = Isolate::Current();
592
578
  if (isolate->cpu_profiler() == NULL) {
593
579
  isolate->set_cpu_profiler(new CpuProfiler());
594
580
  }
595
- #endif
596
581
  }
597
582
 
598
583
 
599
584
  void CpuProfiler::TearDown() {
600
- #ifdef ENABLE_LOGGING_AND_PROFILING
601
585
  Isolate* isolate = Isolate::Current();
602
586
  if (isolate->cpu_profiler() != NULL) {
603
587
  delete isolate->cpu_profiler();
604
588
  }
605
589
  isolate->set_cpu_profiler(NULL);
606
- #endif
607
590
  }
608
591
 
609
592
  } } // namespace v8::internal
@@ -28,8 +28,6 @@
28
28
  #ifndef V8_CPU_PROFILER_H_
29
29
  #define V8_CPU_PROFILER_H_
30
30
 
31
- #ifdef ENABLE_LOGGING_AND_PROFILING
32
-
33
31
  #include "allocation.h"
34
32
  #include "atomicops.h"
35
33
  #include "circular-queue.h"
@@ -106,10 +104,14 @@ class SharedFunctionInfoMoveEventRecord : public CodeEventRecord {
106
104
  };
107
105
 
108
106
 
109
- class TickSampleEventRecord BASE_EMBEDDED {
107
+ class TickSampleEventRecord {
110
108
  public:
111
- TickSampleEventRecord()
112
- : filler(1) {
109
+ // The parameterless constructor is used when we dequeue data from
110
+ // the ticks buffer.
111
+ TickSampleEventRecord() { }
112
+ explicit TickSampleEventRecord(unsigned order)
113
+ : filler(1),
114
+ order(order) {
113
115
  ASSERT(filler != SamplingCircularQueue::kClear);
114
116
  }
115
117
 
@@ -125,8 +127,6 @@ class TickSampleEventRecord BASE_EMBEDDED {
125
127
  static TickSampleEventRecord* cast(void* value) {
126
128
  return reinterpret_cast<TickSampleEventRecord*>(value);
127
129
  }
128
-
129
- INLINE(static TickSampleEventRecord* init(void* value));
130
130
  };
131
131
 
132
132
 
@@ -134,8 +134,7 @@ class TickSampleEventRecord BASE_EMBEDDED {
134
134
  // methods called by event producers: VM and stack sampler threads.
135
135
  class ProfilerEventsProcessor : public Thread {
136
136
  public:
137
- ProfilerEventsProcessor(Isolate* isolate,
138
- ProfileGenerator* generator);
137
+ explicit ProfilerEventsProcessor(ProfileGenerator* generator);
139
138
  virtual ~ProfilerEventsProcessor() {}
140
139
 
141
140
  // Thread control.
@@ -205,9 +204,6 @@ class ProfilerEventsProcessor : public Thread {
205
204
  v8::internal::CpuProfiler::Call; \
206
205
  } \
207
206
  } while (false)
208
- #else
209
- #define PROFILE(isolate, Call) LOG(isolate, Call)
210
- #endif // ENABLE_LOGGING_AND_PROFILING
211
207
 
212
208
 
213
209
  namespace v8 {
@@ -220,7 +216,6 @@ class CpuProfiler {
220
216
  static void Setup();
221
217
  static void TearDown();
222
218
 
223
- #ifdef ENABLE_LOGGING_AND_PROFILING
224
219
  static void StartProfiling(const char* title);
225
220
  static void StartProfiling(String* title);
226
221
  static CpuProfile* StopProfiling(const char* title);
@@ -288,10 +283,6 @@ class CpuProfiler {
288
283
  bool need_to_stop_sampler_;
289
284
  Atomic32 is_profiling_;
290
285
 
291
- #else
292
- static INLINE(bool is_profiling(Isolate* isolate)) { return false; }
293
- #endif // ENABLE_LOGGING_AND_PROFILING
294
-
295
286
  private:
296
287
  DISALLOW_COPY_AND_ASSIGN(CpuProfiler);
297
288
  };
@@ -159,7 +159,7 @@ void HandleDebugEvent(DebugEvent event,
159
159
 
160
160
 
161
161
  void RunRemoteDebugger(int port) {
162
- RemoteDebugger debugger(i::Isolate::Current(), port);
162
+ RemoteDebugger debugger(port);
163
163
  debugger.Run();
164
164
  }
165
165
 
@@ -186,11 +186,11 @@ void RemoteDebugger::Run() {
186
186
  }
187
187
 
188
188
  // Start the receiver thread.
189
- ReceiverThread receiver(isolate_, this);
189
+ ReceiverThread receiver(this);
190
190
  receiver.Start();
191
191
 
192
192
  // Start the keyboard thread.
193
- KeyboardThread keyboard(isolate_, this);
193
+ KeyboardThread keyboard(this);
194
194
  keyboard.Start();
195
195
  PrintPrompt();
196
196
 
@@ -272,6 +272,7 @@ RemoteDebuggerEvent* RemoteDebugger::GetEvent() {
272
272
 
273
273
 
274
274
  void RemoteDebugger::HandleMessageReceived(char* message) {
275
+ Locker lock;
275
276
  HandleScope scope;
276
277
 
277
278
  // Print the event details.
@@ -300,6 +301,7 @@ void RemoteDebugger::HandleMessageReceived(char* message) {
300
301
 
301
302
 
302
303
  void RemoteDebugger::HandleKeyboardCommand(char* command) {
304
+ Locker lock;
303
305
  HandleScope scope;
304
306
 
305
307
  // Convert the debugger command to a JSON debugger request.
@@ -53,11 +53,11 @@ class ReceiverThread;
53
53
  // Remote debugging class.
54
54
  class RemoteDebugger {
55
55
  public:
56
- RemoteDebugger(i::Isolate* isolate, int port)
56
+ explicit RemoteDebugger(int port)
57
57
  : port_(port),
58
58
  event_access_(i::OS::CreateMutex()),
59
59
  event_available_(i::OS::CreateSemaphore(0)),
60
- head_(NULL), tail_(NULL), isolate_(isolate) {}
60
+ head_(NULL), tail_(NULL) {}
61
61
  void Run();
62
62
 
63
63
  // Handle events from the subordinate threads.
@@ -89,7 +89,6 @@ class RemoteDebugger {
89
89
  i::Semaphore* event_available_;
90
90
  RemoteDebuggerEvent* head_;
91
91
  RemoteDebuggerEvent* tail_;
92
- i::Isolate* isolate_;
93
92
 
94
93
  friend class ReceiverThread;
95
94
  };
@@ -98,8 +97,8 @@ class RemoteDebugger {
98
97
  // Thread reading from debugged V8 instance.
99
98
  class ReceiverThread: public i::Thread {
100
99
  public:
101
- ReceiverThread(i::Isolate* isolate, RemoteDebugger* remote_debugger)
102
- : Thread(isolate, "d8:ReceiverThrd"),
100
+ explicit ReceiverThread(RemoteDebugger* remote_debugger)
101
+ : Thread("d8:ReceiverThrd"),
103
102
  remote_debugger_(remote_debugger) {}
104
103
  ~ReceiverThread() {}
105
104
 
@@ -113,8 +112,8 @@ class ReceiverThread: public i::Thread {
113
112
  // Thread reading keyboard input.
114
113
  class KeyboardThread: public i::Thread {
115
114
  public:
116
- explicit KeyboardThread(i::Isolate* isolate, RemoteDebugger* remote_debugger)
117
- : Thread(isolate, "d8:KeyboardThrd"),
115
+ explicit KeyboardThread(RemoteDebugger* remote_debugger)
116
+ : Thread("d8:KeyboardThrd"),
118
117
  remote_debugger_(remote_debugger) {}
119
118
  ~KeyboardThread() {}
120
119
 
@@ -311,10 +311,6 @@ static Handle<Value> GetStdout(int child_fd,
311
311
  int read_timeout,
312
312
  int total_timeout) {
313
313
  Handle<String> accumulator = String::Empty();
314
- const char* source = "(function(a, b) { return a + b; })";
315
- Handle<Value> cons_as_obj(Script::Compile(String::New(source))->Run());
316
- Handle<Function> cons_function(Function::Cast(*cons_as_obj));
317
- Handle<Value> cons_args[2];
318
314
 
319
315
  int fullness = 0;
320
316
  static const int kStdoutReadBufferSize = 4096;
@@ -350,12 +346,7 @@ static Handle<Value> GetStdout(int child_fd,
350
346
  bytes_read + fullness :
351
347
  LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness);
352
348
  Handle<String> addition = String::New(buffer, length);
353
- cons_args[0] = accumulator;
354
- cons_args[1] = addition;
355
- accumulator = Handle<String>::Cast(cons_function->Call(
356
- Shell::utility_context()->Global(),
357
- 2,
358
- cons_args));
349
+ accumulator = String::Concat(accumulator, addition);
359
350
  fullness = bytes_read + fullness - length;
360
351
  memcpy(buffer, buffer + length, fullness);
361
352
  }
@@ -1,4 +1,4 @@
1
- // Copyright 2009 the V8 project authors. All rights reserved.
1
+ // Copyright 2011 the V8 project authors. All rights reserved.
2
2
  // Redistribution and use in source and binary forms, with or without
3
3
  // modification, are permitted provided that the following conditions are
4
4
  // met:
@@ -26,27 +26,50 @@
26
26
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
 
28
28
 
29
- #include <stdlib.h>
29
+ #ifdef USING_V8_SHARED // Defined when linking against shared lib on Windows.
30
+ #define V8_SHARED
31
+ #endif
32
+
33
+ #ifdef COMPRESS_STARTUP_DATA_BZ2
34
+ #include <bzlib.h>
35
+ #endif
36
+
30
37
  #include <errno.h>
38
+ #include <stdlib.h>
39
+ #include <string.h>
40
+ #include <sys/stat.h>
31
41
 
32
- #include "v8.h"
42
+ #ifdef V8_SHARED
43
+ #include <assert.h>
44
+ #include "../include/v8-testing.h"
45
+ #endif // V8_SHARED
33
46
 
34
47
  #include "d8.h"
48
+
49
+ #ifndef V8_SHARED
50
+ #include "api.h"
51
+ #include "checks.h"
35
52
  #include "d8-debug.h"
36
53
  #include "debug.h"
37
- #include "api.h"
38
54
  #include "natives.h"
39
55
  #include "platform.h"
56
+ #include "v8.h"
57
+ #endif // V8_SHARED
40
58
 
59
+ #if !defined(_WIN32) && !defined(_WIN64)
60
+ #include <unistd.h> // NOLINT
61
+ #endif
41
62
 
42
- namespace v8 {
43
-
63
+ #ifndef ASSERT
64
+ #define ASSERT(condition) assert(condition)
65
+ #endif
44
66
 
45
- const char* Shell::kHistoryFileName = ".d8_history";
46
- const char* Shell::kPrompt = "d8> ";
67
+ namespace v8 {
47
68
 
48
69
 
70
+ #ifndef V8_SHARED
49
71
  LineEditor *LineEditor::first_ = NULL;
72
+ const char* Shell::kHistoryFileName = ".d8_history";
50
73
 
51
74
 
52
75
  LineEditor::LineEditor(Type type, const char* name)
@@ -92,15 +115,22 @@ CounterMap* Shell::counter_map_;
92
115
  i::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
93
116
  CounterCollection Shell::local_counters_;
94
117
  CounterCollection* Shell::counters_ = &local_counters_;
118
+ i::Mutex* Shell::context_mutex_(i::OS::CreateMutex());
95
119
  Persistent<Context> Shell::utility_context_;
120
+ #endif // V8_SHARED
121
+
96
122
  Persistent<Context> Shell::evaluation_context_;
123
+ ShellOptions Shell::options;
124
+ const char* Shell::kPrompt = "d8> ";
97
125
 
98
126
 
127
+ #ifndef V8_SHARED
99
128
  bool CounterMap::Match(void* key1, void* key2) {
100
129
  const char* name1 = reinterpret_cast<const char*>(key1);
101
130
  const char* name2 = reinterpret_cast<const char*>(key2);
102
131
  return strcmp(name1, name2) == 0;
103
132
  }
133
+ #endif // V8_SHARED
104
134
 
105
135
 
106
136
  // Converts a V8 value to a C string.
@@ -114,16 +144,22 @@ bool Shell::ExecuteString(Handle<String> source,
114
144
  Handle<Value> name,
115
145
  bool print_result,
116
146
  bool report_exceptions) {
147
+ #ifndef V8_SHARED
148
+ bool FLAG_debugger = i::FLAG_debugger;
149
+ #else
150
+ bool FLAG_debugger = false;
151
+ #endif // V8_SHARED
117
152
  HandleScope handle_scope;
118
153
  TryCatch try_catch;
119
- if (i::FLAG_debugger) {
154
+ options.script_executed = true;
155
+ if (FLAG_debugger) {
120
156
  // When debugging make exceptions appear to be uncaught.
121
157
  try_catch.SetVerbose(true);
122
158
  }
123
159
  Handle<Script> script = Script::Compile(source, name);
124
160
  if (script.IsEmpty()) {
125
161
  // Print errors that happened during compilation.
126
- if (report_exceptions && !i::FLAG_debugger)
162
+ if (report_exceptions && !FLAG_debugger)
127
163
  ReportException(&try_catch);
128
164
  return false;
129
165
  } else {
@@ -131,7 +167,7 @@ bool Shell::ExecuteString(Handle<String> source,
131
167
  if (result.IsEmpty()) {
132
168
  ASSERT(try_catch.HasCaught());
133
169
  // Print errors that happened during execution.
134
- if (report_exceptions && !i::FLAG_debugger)
170
+ if (report_exceptions && !FLAG_debugger)
135
171
  ReportException(&try_catch);
136
172
  return false;
137
173
  } else {
@@ -152,6 +188,7 @@ bool Shell::ExecuteString(Handle<String> source,
152
188
  Handle<Value> Shell::Print(const Arguments& args) {
153
189
  Handle<Value> val = Write(args);
154
190
  printf("\n");
191
+ fflush(stdout);
155
192
  return val;
156
193
  }
157
194
 
@@ -163,7 +200,7 @@ Handle<Value> Shell::Write(const Arguments& args) {
163
200
  printf(" ");
164
201
  }
165
202
  v8::String::Utf8Value str(args[i]);
166
- int n = fwrite(*str, sizeof(**str), str.length(), stdout);
203
+ int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout));
167
204
  if (n != str.length()) {
168
205
  printf("Error in fwrite\n");
169
206
  exit(1);
@@ -187,15 +224,27 @@ Handle<Value> Shell::Read(const Arguments& args) {
187
224
 
188
225
 
189
226
  Handle<Value> Shell::ReadLine(const Arguments& args) {
190
- i::SmartPointer<char> line(i::ReadLine(""));
191
- if (*line == NULL) {
192
- return Null();
193
- }
194
- size_t len = strlen(*line);
195
- if (len > 0 && line[len - 1] == '\n') {
196
- --len;
227
+ static const int kBufferSize = 256;
228
+ char buffer[kBufferSize];
229
+ Handle<String> accumulator = String::New("");
230
+ int length;
231
+ while (true) {
232
+ // Continue reading if the line ends with an escape '\\' or the line has
233
+ // not been fully read into the buffer yet (does not end with '\n').
234
+ // If fgets gets an error, just give up.
235
+ if (fgets(buffer, kBufferSize, stdin) == NULL) return Null();
236
+ length = static_cast<int>(strlen(buffer));
237
+ if (length == 0) {
238
+ return accumulator;
239
+ } else if (buffer[length-1] != '\n') {
240
+ accumulator = String::Concat(accumulator, String::New(buffer, length));
241
+ } else if (length > 1 && buffer[length-2] == '\\') {
242
+ buffer[length-2] = '\n';
243
+ accumulator = String::Concat(accumulator, String::New(buffer, length-1));
244
+ } else {
245
+ return String::Concat(accumulator, String::New(buffer, length-1));
246
+ }
197
247
  }
198
- return String::New(*line, len);
199
248
  }
200
249
 
201
250
 
@@ -218,6 +267,110 @@ Handle<Value> Shell::Load(const Arguments& args) {
218
267
  }
219
268
 
220
269
 
270
+ Handle<Value> Shell::CreateExternalArray(const Arguments& args,
271
+ ExternalArrayType type,
272
+ size_t element_size) {
273
+ ASSERT(element_size == 1 || element_size == 2 || element_size == 4 ||
274
+ element_size == 8);
275
+ if (args.Length() != 1) {
276
+ return ThrowException(
277
+ String::New("Array constructor needs one parameter."));
278
+ }
279
+ static const int kMaxLength = 0x3fffffff;
280
+ #ifndef V8_SHARED
281
+ ASSERT(kMaxLength == i::ExternalArray::kMaxLength);
282
+ #endif // V8_SHARED
283
+ size_t length = 0;
284
+ if (args[0]->IsUint32()) {
285
+ length = args[0]->Uint32Value();
286
+ } else if (args[0]->IsNumber()) {
287
+ double raw_length = args[0]->NumberValue();
288
+ if (raw_length < 0) {
289
+ return ThrowException(String::New("Array length must not be negative."));
290
+ }
291
+ if (raw_length > kMaxLength) {
292
+ return ThrowException(
293
+ String::New("Array length exceeds maximum length."));
294
+ }
295
+ length = static_cast<size_t>(raw_length);
296
+ } else {
297
+ return ThrowException(String::New("Array length must be a number."));
298
+ }
299
+ if (length > static_cast<size_t>(kMaxLength)) {
300
+ return ThrowException(String::New("Array length exceeds maximum length."));
301
+ }
302
+ void* data = calloc(length, element_size);
303
+ if (data == NULL) {
304
+ return ThrowException(String::New("Memory allocation failed."));
305
+ }
306
+ Handle<Object> array = Object::New();
307
+ Persistent<Object> persistent_array = Persistent<Object>::New(array);
308
+ persistent_array.MakeWeak(data, ExternalArrayWeakCallback);
309
+ persistent_array.MarkIndependent();
310
+ array->SetIndexedPropertiesToExternalArrayData(data, type,
311
+ static_cast<int>(length));
312
+ array->Set(String::New("length"),
313
+ Int32::New(static_cast<int32_t>(length)), ReadOnly);
314
+ array->Set(String::New("BYTES_PER_ELEMENT"),
315
+ Int32::New(static_cast<int32_t>(element_size)));
316
+ return array;
317
+ }
318
+
319
+
320
+ void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) {
321
+ free(data);
322
+ object.Dispose();
323
+ }
324
+
325
+
326
+ Handle<Value> Shell::Int8Array(const Arguments& args) {
327
+ return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t));
328
+ }
329
+
330
+
331
+ Handle<Value> Shell::Uint8Array(const Arguments& args) {
332
+ return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t));
333
+ }
334
+
335
+
336
+ Handle<Value> Shell::Int16Array(const Arguments& args) {
337
+ return CreateExternalArray(args, kExternalShortArray, sizeof(int16_t));
338
+ }
339
+
340
+
341
+ Handle<Value> Shell::Uint16Array(const Arguments& args) {
342
+ return CreateExternalArray(args, kExternalUnsignedShortArray,
343
+ sizeof(uint16_t));
344
+ }
345
+
346
+
347
+ Handle<Value> Shell::Int32Array(const Arguments& args) {
348
+ return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t));
349
+ }
350
+
351
+
352
+ Handle<Value> Shell::Uint32Array(const Arguments& args) {
353
+ return CreateExternalArray(args, kExternalUnsignedIntArray, sizeof(uint32_t));
354
+ }
355
+
356
+
357
+ Handle<Value> Shell::Float32Array(const Arguments& args) {
358
+ return CreateExternalArray(args, kExternalFloatArray,
359
+ sizeof(float)); // NOLINT
360
+ }
361
+
362
+
363
+ Handle<Value> Shell::Float64Array(const Arguments& args) {
364
+ return CreateExternalArray(args, kExternalDoubleArray,
365
+ sizeof(double)); // NOLINT
366
+ }
367
+
368
+
369
+ Handle<Value> Shell::PixelArray(const Arguments& args) {
370
+ return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t));
371
+ }
372
+
373
+
221
374
  Handle<Value> Shell::Yield(const Arguments& args) {
222
375
  v8::Unlocker unlocker;
223
376
  return Undefined();
@@ -226,7 +379,9 @@ Handle<Value> Shell::Yield(const Arguments& args) {
226
379
 
227
380
  Handle<Value> Shell::Quit(const Arguments& args) {
228
381
  int exit_code = args[0]->Int32Value();
382
+ #ifndef V8_SHARED
229
383
  OnExit();
384
+ #endif // V8_SHARED
230
385
  exit(exit_code);
231
386
  return Undefined();
232
387
  }
@@ -275,6 +430,7 @@ void Shell::ReportException(v8::TryCatch* try_catch) {
275
430
  }
276
431
 
277
432
 
433
+ #ifndef V8_SHARED
278
434
  Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) {
279
435
  HandleScope handle_scope;
280
436
  Context::Scope context_scope(utility_context_);
@@ -308,9 +464,11 @@ Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) {
308
464
  Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
309
465
  return val;
310
466
  }
311
- #endif
467
+ #endif // ENABLE_DEBUGGER_SUPPORT
468
+ #endif // V8_SHARED
312
469
 
313
470
 
471
+ #ifndef V8_SHARED
314
472
  int32_t* Counter::Bind(const char* name, bool is_histogram) {
315
473
  int i;
316
474
  for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
@@ -342,8 +500,8 @@ Counter* CounterCollection::GetNextCounter() {
342
500
 
343
501
 
344
502
  void Shell::MapCounters(const char* name) {
345
- counters_file_ = i::OS::MemoryMappedFile::create(name,
346
- sizeof(CounterCollection), &local_counters_);
503
+ counters_file_ = i::OS::MemoryMappedFile::create(
504
+ name, sizeof(CounterCollection), &local_counters_);
347
505
  void* memory = (counters_file_ == NULL) ?
348
506
  NULL : counters_file_->memory();
349
507
  if (memory == NULL) {
@@ -409,56 +567,15 @@ void Shell::AddHistogramSample(void* histogram, int sample) {
409
567
  }
410
568
 
411
569
 
412
- void Shell::Initialize() {
413
- Shell::counter_map_ = new CounterMap();
414
- // Set up counters
415
- if (i::StrLength(i::FLAG_map_counters) != 0)
416
- MapCounters(i::FLAG_map_counters);
417
- if (i::FLAG_dump_counters) {
418
- V8::SetCounterFunction(LookupCounter);
419
- V8::SetCreateHistogramFunction(CreateHistogram);
420
- V8::SetAddHistogramSampleFunction(AddHistogramSample);
421
- }
422
-
423
- // Initialize the global objects
570
+ void Shell::InstallUtilityScript() {
571
+ Locker lock;
424
572
  HandleScope scope;
425
- Handle<ObjectTemplate> global_template = ObjectTemplate::New();
426
- global_template->Set(String::New("print"), FunctionTemplate::New(Print));
427
- global_template->Set(String::New("write"), FunctionTemplate::New(Write));
428
- global_template->Set(String::New("read"), FunctionTemplate::New(Read));
429
- global_template->Set(String::New("readline"),
430
- FunctionTemplate::New(ReadLine));
431
- global_template->Set(String::New("load"), FunctionTemplate::New(Load));
432
- global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
433
- global_template->Set(String::New("version"), FunctionTemplate::New(Version));
434
-
435
- #ifdef LIVE_OBJECT_LIST
436
- global_template->Set(String::New("lol_is_enabled"), Boolean::New(true));
437
- #else
438
- global_template->Set(String::New("lol_is_enabled"), Boolean::New(false));
439
- #endif
440
-
441
- Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
442
- AddOSMethods(os_templ);
443
- global_template->Set(String::New("os"), os_templ);
444
-
445
- utility_context_ = Context::New(NULL, global_template);
573
+ // If we use the utility context, we have to set the security tokens so that
574
+ // utility, evaluation and debug context can all access each other.
446
575
  utility_context_->SetSecurityToken(Undefined());
576
+ evaluation_context_->SetSecurityToken(Undefined());
447
577
  Context::Scope utility_scope(utility_context_);
448
578
 
449
- i::JSArguments js_args = i::FLAG_js_arguments;
450
- i::Handle<i::FixedArray> arguments_array =
451
- FACTORY->NewFixedArray(js_args.argc());
452
- for (int j = 0; j < js_args.argc(); j++) {
453
- i::Handle<i::String> arg =
454
- FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j]));
455
- arguments_array->set(j, *arg);
456
- }
457
- i::Handle<i::JSArray> arguments_jsarray =
458
- FACTORY->NewJSArrayWithElements(arguments_array);
459
- global_template->Set(String::New("arguments"),
460
- Utils::ToLocal(arguments_jsarray));
461
-
462
579
  #ifdef ENABLE_DEBUGGER_SUPPORT
463
580
  // Install the debugger object in the utility scope
464
581
  i::Debug* debug = i::Isolate::Current()->debug();
@@ -467,21 +584,21 @@ void Shell::Initialize() {
467
584
  = i::Handle<i::JSObject>(debug->debug_context()->global());
468
585
  utility_context_->Global()->Set(String::New("$debug"),
469
586
  Utils::ToLocal(js_debug));
470
- #endif
587
+ debug->debug_context()->set_security_token(HEAP->undefined_value());
588
+ #endif // ENABLE_DEBUGGER_SUPPORT
471
589
 
472
590
  // Run the d8 shell utility script in the utility context
473
591
  int source_index = i::NativesCollection<i::D8>::GetIndex("d8");
474
- i::Vector<const char> shell_source
475
- = i::NativesCollection<i::D8>::GetScriptSource(source_index);
476
- i::Vector<const char> shell_source_name
477
- = i::NativesCollection<i::D8>::GetScriptName(source_index);
592
+ i::Vector<const char> shell_source =
593
+ i::NativesCollection<i::D8>::GetRawScriptSource(source_index);
594
+ i::Vector<const char> shell_source_name =
595
+ i::NativesCollection<i::D8>::GetScriptName(source_index);
478
596
  Handle<String> source = String::New(shell_source.start(),
479
- shell_source.length());
597
+ shell_source.length());
480
598
  Handle<String> name = String::New(shell_source_name.start(),
481
- shell_source_name.length());
599
+ shell_source_name.length());
482
600
  Handle<Script> script = Script::Compile(source, name);
483
601
  script->Run();
484
-
485
602
  // Mark the d8 shell script as native to avoid it showing up as normal source
486
603
  // in the debugger.
487
604
  i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script);
@@ -492,53 +609,206 @@ void Shell::Initialize() {
492
609
  i::SharedFunctionInfo::cast(*compiled_script)->script()));
493
610
  script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE));
494
611
 
495
- // Create the evaluation context
496
- evaluation_context_ = Context::New(NULL, global_template);
497
- evaluation_context_->SetSecurityToken(Undefined());
498
-
499
612
  #ifdef ENABLE_DEBUGGER_SUPPORT
500
- // Set the security token of the debug context to allow access.
501
- debug->debug_context()->set_security_token(HEAP->undefined_value());
613
+ // Start the in-process debugger if requested.
614
+ if (i::FLAG_debugger && !i::FLAG_debugger_agent) {
615
+ v8::Debug::SetDebugEventListener(HandleDebugEvent);
616
+ }
617
+ #endif // ENABLE_DEBUGGER_SUPPORT
618
+ }
619
+ #endif // V8_SHARED
620
+
621
+
622
+ #ifdef COMPRESS_STARTUP_DATA_BZ2
623
+ class BZip2Decompressor : public v8::StartupDataDecompressor {
624
+ public:
625
+ virtual ~BZip2Decompressor() { }
626
+
627
+ protected:
628
+ virtual int DecompressData(char* raw_data,
629
+ int* raw_data_size,
630
+ const char* compressed_data,
631
+ int compressed_data_size) {
632
+ ASSERT_EQ(v8::StartupData::kBZip2,
633
+ v8::V8::GetCompressedStartupDataAlgorithm());
634
+ unsigned int decompressed_size = *raw_data_size;
635
+ int result =
636
+ BZ2_bzBuffToBuffDecompress(raw_data,
637
+ &decompressed_size,
638
+ const_cast<char*>(compressed_data),
639
+ compressed_data_size,
640
+ 0, 1);
641
+ if (result == BZ_OK) {
642
+ *raw_data_size = decompressed_size;
643
+ }
644
+ return result;
645
+ }
646
+ };
647
+ #endif
648
+
649
+ Handle<ObjectTemplate> Shell::CreateGlobalTemplate() {
650
+ Handle<ObjectTemplate> global_template = ObjectTemplate::New();
651
+ global_template->Set(String::New("print"), FunctionTemplate::New(Print));
652
+ global_template->Set(String::New("write"), FunctionTemplate::New(Write));
653
+ global_template->Set(String::New("read"), FunctionTemplate::New(Read));
654
+ global_template->Set(String::New("readline"),
655
+ FunctionTemplate::New(ReadLine));
656
+ global_template->Set(String::New("load"), FunctionTemplate::New(Load));
657
+ global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
658
+ global_template->Set(String::New("version"), FunctionTemplate::New(Version));
659
+
660
+ // Bind the handlers for external arrays.
661
+ global_template->Set(String::New("Int8Array"),
662
+ FunctionTemplate::New(Int8Array));
663
+ global_template->Set(String::New("Uint8Array"),
664
+ FunctionTemplate::New(Uint8Array));
665
+ global_template->Set(String::New("Int16Array"),
666
+ FunctionTemplate::New(Int16Array));
667
+ global_template->Set(String::New("Uint16Array"),
668
+ FunctionTemplate::New(Uint16Array));
669
+ global_template->Set(String::New("Int32Array"),
670
+ FunctionTemplate::New(Int32Array));
671
+ global_template->Set(String::New("Uint32Array"),
672
+ FunctionTemplate::New(Uint32Array));
673
+ global_template->Set(String::New("Float32Array"),
674
+ FunctionTemplate::New(Float32Array));
675
+ global_template->Set(String::New("Float64Array"),
676
+ FunctionTemplate::New(Float64Array));
677
+ global_template->Set(String::New("PixelArray"),
678
+ FunctionTemplate::New(PixelArray));
679
+
680
+ #ifdef LIVE_OBJECT_LIST
681
+ global_template->Set(String::New("lol_is_enabled"), True());
682
+ #else
683
+ global_template->Set(String::New("lol_is_enabled"), False());
684
+ #endif
685
+
686
+ #ifndef V8_SHARED
687
+ Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
688
+ AddOSMethods(os_templ);
689
+ global_template->Set(String::New("os"), os_templ);
690
+ #endif // V8_SHARED
691
+
692
+ return global_template;
693
+ }
694
+
502
695
 
696
+ void Shell::Initialize() {
697
+ #ifdef COMPRESS_STARTUP_DATA_BZ2
698
+ BZip2Decompressor startup_data_decompressor;
699
+ int bz2_result = startup_data_decompressor.Decompress();
700
+ if (bz2_result != BZ_OK) {
701
+ fprintf(stderr, "bzip error code: %d\n", bz2_result);
702
+ exit(1);
703
+ }
704
+ #endif
705
+
706
+ #ifndef V8_SHARED
707
+ Shell::counter_map_ = new CounterMap();
708
+ // Set up counters
709
+ if (i::StrLength(i::FLAG_map_counters) != 0)
710
+ MapCounters(i::FLAG_map_counters);
711
+ if (i::FLAG_dump_counters) {
712
+ V8::SetCounterFunction(LookupCounter);
713
+ V8::SetCreateHistogramFunction(CreateHistogram);
714
+ V8::SetAddHistogramSampleFunction(AddHistogramSample);
715
+ }
716
+ #endif // V8_SHARED
717
+ if (options.test_shell) return;
718
+
719
+ #ifndef V8_SHARED
720
+ Locker lock;
721
+ HandleScope scope;
722
+ Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
723
+ utility_context_ = Context::New(NULL, global_template);
724
+
725
+ #ifdef ENABLE_DEBUGGER_SUPPORT
503
726
  // Start the debugger agent if requested.
504
727
  if (i::FLAG_debugger_agent) {
505
728
  v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true);
506
729
  }
730
+ #endif // ENABLE_DEBUGGER_SUPPORT
731
+ #endif // V8_SHARED
732
+ }
507
733
 
508
- // Start the in-process debugger if requested.
509
- if (i::FLAG_debugger && !i::FLAG_debugger_agent) {
510
- v8::Debug::SetDebugEventListener(HandleDebugEvent);
734
+
735
+ Persistent<Context> Shell::CreateEvaluationContext() {
736
+ #ifndef V8_SHARED
737
+ // This needs to be a critical section since this is not thread-safe
738
+ i::ScopedLock lock(context_mutex_);
739
+ #endif // V8_SHARED
740
+ // Initialize the global objects
741
+ Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
742
+ Persistent<Context> context = Context::New(NULL, global_template);
743
+ ASSERT(!context.IsEmpty());
744
+ Context::Scope scope(context);
745
+
746
+ #ifndef V8_SHARED
747
+ i::JSArguments js_args = i::FLAG_js_arguments;
748
+ i::Handle<i::FixedArray> arguments_array =
749
+ FACTORY->NewFixedArray(js_args.argc());
750
+ for (int j = 0; j < js_args.argc(); j++) {
751
+ i::Handle<i::String> arg =
752
+ FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j]));
753
+ arguments_array->set(j, *arg);
511
754
  }
512
- #endif
755
+ i::Handle<i::JSArray> arguments_jsarray =
756
+ FACTORY->NewJSArrayWithElements(arguments_array);
757
+ context->Global()->Set(String::New("arguments"),
758
+ Utils::ToLocal(arguments_jsarray));
759
+ #endif // V8_SHARED
760
+ return context;
513
761
  }
514
762
 
515
763
 
764
+ #ifndef V8_SHARED
516
765
  void Shell::OnExit() {
517
766
  if (i::FLAG_dump_counters) {
518
- ::printf("+----------------------------------------+-------------+\n");
519
- ::printf("| Name | Value |\n");
520
- ::printf("+----------------------------------------+-------------+\n");
767
+ printf("+----------------------------------------+-------------+\n");
768
+ printf("| Name | Value |\n");
769
+ printf("+----------------------------------------+-------------+\n");
521
770
  for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
522
771
  Counter* counter = i.CurrentValue();
523
772
  if (counter->is_histogram()) {
524
- ::printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count());
525
- ::printf("| t:%-36s | %11i |\n",
526
- i.CurrentKey(),
527
- counter->sample_total());
773
+ printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count());
774
+ printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total());
528
775
  } else {
529
- ::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count());
776
+ printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count());
530
777
  }
531
778
  }
532
- ::printf("+----------------------------------------+-------------+\n");
779
+ printf("+----------------------------------------+-------------+\n");
533
780
  }
534
781
  if (counters_file_ != NULL)
535
782
  delete counters_file_;
536
783
  }
784
+ #endif // V8_SHARED
785
+
786
+
787
+ static FILE* FOpen(const char* path, const char* mode) {
788
+ #if (defined(_WIN32) || defined(_WIN64))
789
+ FILE* result;
790
+ if (fopen_s(&result, path, mode) == 0) {
791
+ return result;
792
+ } else {
793
+ return NULL;
794
+ }
795
+ #else
796
+ FILE* file = fopen(path, mode);
797
+ if (file == NULL) return NULL;
798
+ struct stat file_stat;
799
+ if (fstat(fileno(file), &file_stat) != 0) return NULL;
800
+ bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0);
801
+ if (is_regular_file) return file;
802
+ fclose(file);
803
+ return NULL;
804
+ #endif
805
+ }
537
806
 
538
807
 
539
808
  static char* ReadChars(const char* name, int* size_out) {
540
- v8::Unlocker unlocker; // Release the V8 lock while reading files.
541
- FILE* file = i::OS::FOpen(name, "rb");
809
+ // Release the V8 lock while reading files.
810
+ v8::Unlocker unlocker(Isolate::GetCurrent());
811
+ FILE* file = FOpen(name, "rb");
542
812
  if (file == NULL) return NULL;
543
813
 
544
814
  fseek(file, 0, SEEK_END);
@@ -548,7 +818,7 @@ static char* ReadChars(const char* name, int* size_out) {
548
818
  char* chars = new char[size + 1];
549
819
  chars[size] = '\0';
550
820
  for (int i = 0; i < size;) {
551
- int read = fread(&chars[i], 1, size - i, file);
821
+ int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
552
822
  i += read;
553
823
  }
554
824
  fclose(file);
@@ -557,6 +827,7 @@ static char* ReadChars(const char* name, int* size_out) {
557
827
  }
558
828
 
559
829
 
830
+ #ifndef V8_SHARED
560
831
  static char* ReadToken(char* data, char token) {
561
832
  char* next = i::OS::StrChr(data, token);
562
833
  if (next != NULL) {
@@ -576,6 +847,7 @@ static char* ReadLine(char* data) {
576
847
  static char* ReadWord(char* data) {
577
848
  return ReadToken(data, ' ');
578
849
  }
850
+ #endif // V8_SHARED
579
851
 
580
852
 
581
853
  // Reads a file into a v8 string.
@@ -590,6 +862,11 @@ Handle<String> Shell::ReadFile(const char* name) {
590
862
 
591
863
 
592
864
  void Shell::RunShell() {
865
+ Locker locker;
866
+ Context::Scope context_scope(evaluation_context_);
867
+ HandleScope handle_scope;
868
+ Handle<String> name = String::New("(d8)");
869
+ #ifndef V8_SHARED
593
870
  LineEditor* editor = LineEditor::Get();
594
871
  printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name());
595
872
  if (i::FLAG_debugger) {
@@ -597,26 +874,32 @@ void Shell::RunShell() {
597
874
  }
598
875
  editor->Open();
599
876
  while (true) {
600
- Locker locker;
601
- HandleScope handle_scope;
602
- Context::Scope context_scope(evaluation_context_);
603
877
  i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt);
604
- if (input.is_empty())
605
- break;
878
+ if (input.is_empty()) break;
606
879
  editor->AddHistory(*input);
607
- Handle<String> name = String::New("(d8)");
608
880
  ExecuteString(String::New(*input), name, true, true);
609
881
  }
610
882
  editor->Close();
883
+ #else
884
+ printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion());
885
+ static const int kBufferSize = 256;
886
+ while (true) {
887
+ char buffer[kBufferSize];
888
+ printf("%s", Shell::kPrompt);
889
+ if (fgets(buffer, kBufferSize, stdin) == NULL) break;
890
+ ExecuteString(String::New(buffer), name, true, true);
891
+ }
892
+ #endif // V8_SHARED
611
893
  printf("\n");
612
894
  }
613
895
 
614
896
 
897
+ #ifndef V8_SHARED
615
898
  class ShellThread : public i::Thread {
616
899
  public:
617
- ShellThread(i::Isolate* isolate, int no, i::Vector<const char> files)
618
- : Thread(isolate, "d8:ShellThread"),
619
- no_(no), files_(files) { }
900
+ ShellThread(int no, i::Vector<const char> files)
901
+ : Thread("d8:ShellThread"),
902
+ no_(no), files_(files) { }
620
903
  virtual void Run();
621
904
  private:
622
905
  int no_;
@@ -625,25 +908,6 @@ class ShellThread : public i::Thread {
625
908
 
626
909
 
627
910
  void ShellThread::Run() {
628
- // Prepare the context for this thread.
629
- Locker locker;
630
- HandleScope scope;
631
- Handle<ObjectTemplate> global_template = ObjectTemplate::New();
632
- global_template->Set(String::New("print"),
633
- FunctionTemplate::New(Shell::Print));
634
- global_template->Set(String::New("write"),
635
- FunctionTemplate::New(Shell::Write));
636
- global_template->Set(String::New("read"),
637
- FunctionTemplate::New(Shell::Read));
638
- global_template->Set(String::New("readline"),
639
- FunctionTemplate::New(Shell::ReadLine));
640
- global_template->Set(String::New("load"),
641
- FunctionTemplate::New(Shell::Load));
642
- global_template->Set(String::New("yield"),
643
- FunctionTemplate::New(Shell::Yield));
644
- global_template->Set(String::New("version"),
645
- FunctionTemplate::New(Shell::Version));
646
-
647
911
  char* ptr = const_cast<char*>(files_.start());
648
912
  while ((ptr != NULL) && (*ptr != '\0')) {
649
913
  // For each newline-separated line.
@@ -655,8 +919,10 @@ void ShellThread::Run() {
655
919
  continue;
656
920
  }
657
921
 
658
- Persistent<Context> thread_context = Context::New(NULL, global_template);
659
- thread_context->SetSecurityToken(Undefined());
922
+ // Prepare the context for this thread.
923
+ Locker locker;
924
+ HandleScope scope;
925
+ Persistent<Context> thread_context = Shell::CreateEvaluationContext();
660
926
  Context::Scope context_scope(thread_context);
661
927
 
662
928
  while ((ptr != NULL) && (*ptr != '\0')) {
@@ -681,117 +947,353 @@ void ShellThread::Run() {
681
947
  ptr = next_line;
682
948
  }
683
949
  }
950
+ #endif // V8_SHARED
684
951
 
685
952
 
686
- int Shell::Main(int argc, char* argv[]) {
687
- i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
688
- if (i::FLAG_help) {
689
- return 1;
953
+ void SourceGroup::ExitShell(int exit_code) {
954
+ // Use _exit instead of exit to avoid races between isolate
955
+ // threads and static destructors.
956
+ fflush(stdout);
957
+ fflush(stderr);
958
+ _exit(exit_code);
959
+ }
960
+
961
+
962
+ void SourceGroup::Execute() {
963
+ for (int i = begin_offset_; i < end_offset_; ++i) {
964
+ const char* arg = argv_[i];
965
+ if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) {
966
+ // Execute argument given to -e option directly.
967
+ HandleScope handle_scope;
968
+ Handle<String> file_name = String::New("unnamed");
969
+ Handle<String> source = String::New(argv_[i + 1]);
970
+ if (!Shell::ExecuteString(source, file_name, false, true)) {
971
+ ExitShell(1);
972
+ return;
973
+ }
974
+ ++i;
975
+ } else if (arg[0] == '-') {
976
+ // Ignore other options. They have been parsed already.
977
+ } else {
978
+ // Use all other arguments as names of files to load and run.
979
+ HandleScope handle_scope;
980
+ Handle<String> file_name = String::New(arg);
981
+ Handle<String> source = ReadFile(arg);
982
+ if (source.IsEmpty()) {
983
+ printf("Error reading '%s'\n", arg);
984
+ ExitShell(1);
985
+ return;
986
+ }
987
+ if (!Shell::ExecuteString(source, file_name, false, true)) {
988
+ ExitShell(1);
989
+ return;
990
+ }
991
+ }
690
992
  }
691
- Initialize();
692
- bool run_shell = (argc == 1);
993
+ }
994
+
995
+
996
+ Handle<String> SourceGroup::ReadFile(const char* name) {
997
+ int size;
998
+ const char* chars = ReadChars(name, &size);
999
+ if (chars == NULL) return Handle<String>();
1000
+ Handle<String> result = String::New(chars, size);
1001
+ delete[] chars;
1002
+ return result;
1003
+ }
693
1004
 
694
- // Default use preemption if threads are created.
695
- bool use_preemption = true;
696
1005
 
697
- // Default to use lowest possible thread preemption interval to test as many
698
- // edgecases as possible.
699
- int preemption_interval = 1;
1006
+ #ifndef V8_SHARED
1007
+ i::Thread::Options SourceGroup::GetThreadOptions() {
1008
+ i::Thread::Options options;
1009
+ options.name = "IsolateThread";
1010
+ // On some systems (OSX 10.6) the stack size default is 0.5Mb or less
1011
+ // which is not enough to parse the big literal expressions used in tests.
1012
+ // The stack size should be at least StackGuard::kLimitSize + some
1013
+ // OS-specific padding for thread startup code.
1014
+ options.stack_size = 2 << 20; // 2 Mb seems to be enough
1015
+ return options;
1016
+ }
700
1017
 
701
- i::List<i::Thread*> threads(1);
702
1018
 
703
- {
704
- // Acquire the V8 lock once initialization has finished. Since the thread
705
- // below may spawn new threads accessing V8 holding the V8 lock here is
706
- // mandatory.
707
- Locker locker;
708
- Context::Scope context_scope(evaluation_context_);
709
- for (int i = 1; i < argc; i++) {
710
- char* str = argv[i];
711
- if (strcmp(str, "--shell") == 0) {
712
- run_shell = true;
713
- } else if (strcmp(str, "--preemption") == 0) {
714
- use_preemption = true;
715
- } else if (strcmp(str, "--no-preemption") == 0) {
716
- use_preemption = false;
717
- } else if (strcmp(str, "--preemption-interval") == 0) {
718
- if (i + 1 < argc) {
719
- char* end = NULL;
720
- preemption_interval = strtol(argv[++i], &end, 10); // NOLINT
721
- if (preemption_interval <= 0 || *end != '\0' || errno == ERANGE) {
722
- printf("Invalid value for --preemption-interval '%s'\n", argv[i]);
723
- return 1;
724
- }
725
- } else {
726
- printf("Missing value for --preemption-interval\n");
727
- return 1;
728
- }
729
- } else if (strcmp(str, "-f") == 0) {
730
- // Ignore any -f flags for compatibility with other stand-alone
731
- // JavaScript engines.
732
- continue;
733
- } else if (strncmp(str, "--", 2) == 0) {
734
- printf("Warning: unknown flag %s.\nTry --help for options\n", str);
735
- } else if (strcmp(str, "-e") == 0 && i + 1 < argc) {
736
- // Execute argument given to -e option directly.
737
- v8::HandleScope handle_scope;
738
- v8::Handle<v8::String> file_name = v8::String::New("unnamed");
739
- v8::Handle<v8::String> source = v8::String::New(argv[i + 1]);
740
- if (!ExecuteString(source, file_name, false, true)) {
741
- OnExit();
742
- return 1;
1019
+ void SourceGroup::ExecuteInThread() {
1020
+ Isolate* isolate = Isolate::New();
1021
+ do {
1022
+ if (next_semaphore_ != NULL) next_semaphore_->Wait();
1023
+ {
1024
+ Isolate::Scope iscope(isolate);
1025
+ Locker lock(isolate);
1026
+ HandleScope scope;
1027
+ Persistent<Context> context = Shell::CreateEvaluationContext();
1028
+ {
1029
+ Context::Scope cscope(context);
1030
+ Execute();
1031
+ }
1032
+ context.Dispose();
1033
+ }
1034
+ if (done_semaphore_ != NULL) done_semaphore_->Signal();
1035
+ } while (!Shell::options.last_run);
1036
+ isolate->Dispose();
1037
+ }
1038
+
1039
+
1040
+ void SourceGroup::StartExecuteInThread() {
1041
+ if (thread_ == NULL) {
1042
+ thread_ = new IsolateThread(this);
1043
+ thread_->Start();
1044
+ }
1045
+ next_semaphore_->Signal();
1046
+ }
1047
+
1048
+
1049
+ void SourceGroup::WaitForThread() {
1050
+ if (thread_ == NULL) return;
1051
+ if (Shell::options.last_run) {
1052
+ thread_->Join();
1053
+ thread_ = NULL;
1054
+ } else {
1055
+ done_semaphore_->Wait();
1056
+ }
1057
+ }
1058
+ #endif // V8_SHARED
1059
+
1060
+
1061
+ bool Shell::SetOptions(int argc, char* argv[]) {
1062
+ for (int i = 0; i < argc; i++) {
1063
+ if (strcmp(argv[i], "--stress-opt") == 0) {
1064
+ options.stress_opt = true;
1065
+ argv[i] = NULL;
1066
+ } else if (strcmp(argv[i], "--stress-deopt") == 0) {
1067
+ options.stress_deopt = true;
1068
+ argv[i] = NULL;
1069
+ } else if (strcmp(argv[i], "--noalways-opt") == 0) {
1070
+ // No support for stressing if we can't use --always-opt.
1071
+ options.stress_opt = false;
1072
+ options.stress_deopt = false;
1073
+ } else if (strcmp(argv[i], "--shell") == 0) {
1074
+ options.interactive_shell = true;
1075
+ argv[i] = NULL;
1076
+ } else if (strcmp(argv[i], "--test") == 0) {
1077
+ options.test_shell = true;
1078
+ argv[i] = NULL;
1079
+ } else if (strcmp(argv[i], "--preemption") == 0) {
1080
+ #ifdef V8_SHARED
1081
+ printf("D8 with shared library does not support multi-threading\n");
1082
+ return false;
1083
+ #else
1084
+ options.use_preemption = true;
1085
+ argv[i] = NULL;
1086
+ #endif // V8_SHARED
1087
+ } else if (strcmp(argv[i], "--no-preemption") == 0) {
1088
+ #ifdef V8_SHARED
1089
+ printf("D8 with shared library does not support multi-threading\n");
1090
+ return false;
1091
+ #else
1092
+ options.use_preemption = false;
1093
+ argv[i] = NULL;
1094
+ #endif // V8_SHARED
1095
+ } else if (strcmp(argv[i], "--preemption-interval") == 0) {
1096
+ #ifdef V8_SHARED
1097
+ printf("D8 with shared library does not support multi-threading\n");
1098
+ return false;
1099
+ #else
1100
+ if (++i < argc) {
1101
+ argv[i-1] = NULL;
1102
+ char* end = NULL;
1103
+ options.preemption_interval = strtol(argv[i], &end, 10); // NOLINT
1104
+ if (options.preemption_interval <= 0
1105
+ || *end != '\0'
1106
+ || errno == ERANGE) {
1107
+ printf("Invalid value for --preemption-interval '%s'\n", argv[i]);
1108
+ return false;
743
1109
  }
744
- i++;
745
- } else if (strcmp(str, "-p") == 0 && i + 1 < argc) {
746
- int size = 0;
747
- const char* files = ReadChars(argv[++i], &size);
748
- if (files == NULL) return 1;
749
- ShellThread* thread =
750
- new ShellThread(i::Isolate::Current(),
751
- threads.length(),
752
- i::Vector<const char>(files, size));
753
- thread->Start();
754
- threads.Add(thread);
1110
+ argv[i] = NULL;
755
1111
  } else {
756
- // Use all other arguments as names of files to load and run.
757
- HandleScope handle_scope;
758
- Handle<String> file_name = v8::String::New(str);
759
- Handle<String> source = ReadFile(str);
760
- if (source.IsEmpty()) {
761
- printf("Error reading '%s'\n", str);
762
- return 1;
763
- }
764
- if (!ExecuteString(source, file_name, false, true)) {
765
- OnExit();
766
- return 1;
767
- }
1112
+ printf("Missing value for --preemption-interval\n");
1113
+ return false;
768
1114
  }
1115
+ #endif // V8_SHARED
1116
+ } else if (strcmp(argv[i], "-f") == 0) {
1117
+ // Ignore any -f flags for compatibility with other stand-alone
1118
+ // JavaScript engines.
1119
+ continue;
1120
+ } else if (strcmp(argv[i], "--isolate") == 0) {
1121
+ #ifdef V8_SHARED
1122
+ printf("D8 with shared library does not support multi-threading\n");
1123
+ return false;
1124
+ #endif // V8_SHARED
1125
+ options.num_isolates++;
1126
+ }
1127
+ #ifdef V8_SHARED
1128
+ else if (strcmp(argv[i], "--dump-counters") == 0) {
1129
+ printf("D8 with shared library does not include counters\n");
1130
+ return false;
1131
+ } else if (strcmp(argv[i], "-p") == 0) {
1132
+ printf("D8 with shared library does not support multi-threading\n");
1133
+ return false;
1134
+ } else if (strcmp(argv[i], "--debugger") == 0) {
1135
+ printf("Javascript debugger not included\n");
1136
+ return false;
1137
+ }
1138
+ #endif // V8_SHARED
1139
+ }
1140
+
1141
+ #ifndef V8_SHARED
1142
+ // Run parallel threads if we are not using --isolate
1143
+ for (int i = 1; i < argc; i++) {
1144
+ if (argv[i] == NULL) continue;
1145
+ if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
1146
+ if (options.num_isolates > 1) {
1147
+ printf("-p is not compatible with --isolate\n");
1148
+ return false;
1149
+ }
1150
+ argv[i] = NULL;
1151
+ if (options.parallel_files == NULL) {
1152
+ options.parallel_files = new i::List<i::Vector<const char> >();
1153
+ }
1154
+ int size = 0;
1155
+ const char* files = ReadChars(argv[++i], &size);
1156
+ if (files == NULL) {
1157
+ printf("-p option incomplete\n");
1158
+ return false;
1159
+ }
1160
+ argv[i] = NULL;
1161
+ options.parallel_files->Add(i::Vector<const char>(files, size));
1162
+ delete[] files;
1163
+ }
1164
+ }
1165
+ #endif // V8_SHARED
1166
+
1167
+ v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
1168
+
1169
+ // set up isolated source groups
1170
+ options.isolate_sources = new SourceGroup[options.num_isolates];
1171
+ SourceGroup* current = options.isolate_sources;
1172
+ current->Begin(argv, 1);
1173
+ for (int i = 1; i < argc; i++) {
1174
+ const char* str = argv[i];
1175
+ if (strcmp(str, "--isolate") == 0) {
1176
+ current->End(i);
1177
+ current++;
1178
+ current->Begin(argv, i + 1);
1179
+ } else if (strncmp(argv[i], "--", 2) == 0) {
1180
+ printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]);
1181
+ }
1182
+ }
1183
+ current->End(argc);
1184
+
1185
+ return true;
1186
+ }
1187
+
1188
+
1189
+ int Shell::RunMain(int argc, char* argv[]) {
1190
+ #ifndef V8_SHARED
1191
+ i::List<i::Thread*> threads(1);
1192
+ if (options.parallel_files != NULL)
1193
+ for (int i = 0; i < options.parallel_files->length(); i++) {
1194
+ i::Vector<const char> files = options.parallel_files->at(i);
1195
+ ShellThread* thread = new ShellThread(threads.length(), files);
1196
+ thread->Start();
1197
+ threads.Add(thread);
769
1198
  }
770
1199
 
1200
+ for (int i = 1; i < options.num_isolates; ++i) {
1201
+ options.isolate_sources[i].StartExecuteInThread();
1202
+ }
1203
+ #endif // V8_SHARED
1204
+ { // NOLINT
1205
+ Locker lock;
1206
+ HandleScope scope;
1207
+ Persistent<Context> context = CreateEvaluationContext();
1208
+ {
1209
+ Context::Scope cscope(context);
1210
+ options.isolate_sources[0].Execute();
1211
+ }
1212
+ if (options.last_run) {
1213
+ // Keep using the same context in the interactive shell
1214
+ evaluation_context_ = context;
1215
+ } else {
1216
+ context.Dispose();
1217
+ }
1218
+
1219
+ #ifndef V8_SHARED
771
1220
  // Start preemption if threads have been created and preemption is enabled.
772
- if (threads.length() > 0 && use_preemption) {
773
- Locker::StartPreemption(preemption_interval);
1221
+ if (options.parallel_files != NULL
1222
+ && threads.length() > 0
1223
+ && options.use_preemption) {
1224
+ Locker::StartPreemption(options.preemption_interval);
774
1225
  }
1226
+ #endif // V8_SHARED
1227
+ }
775
1228
 
776
- #ifdef ENABLE_DEBUGGER_SUPPORT
777
- // Run the remote debugger if requested.
778
- if (i::FLAG_remote_debugger) {
779
- RunRemoteDebugger(i::FLAG_debugger_port);
780
- return 0;
1229
+ #ifndef V8_SHARED
1230
+ for (int i = 1; i < options.num_isolates; ++i) {
1231
+ options.isolate_sources[i].WaitForThread();
1232
+ }
1233
+
1234
+ if (options.parallel_files != NULL)
1235
+ for (int i = 0; i < threads.length(); i++) {
1236
+ i::Thread* thread = threads[i];
1237
+ thread->Join();
1238
+ delete thread;
781
1239
  }
782
- #endif
1240
+ #endif // V8_SHARED
1241
+ return 0;
1242
+ }
1243
+
1244
+
1245
+ int Shell::Main(int argc, char* argv[]) {
1246
+ if (!SetOptions(argc, argv)) return 1;
1247
+ Initialize();
1248
+
1249
+ int result = 0;
1250
+ if (options.stress_opt || options.stress_deopt) {
1251
+ Testing::SetStressRunType(
1252
+ options.stress_opt ? Testing::kStressTypeOpt
1253
+ : Testing::kStressTypeDeopt);
1254
+ int stress_runs = Testing::GetStressRuns();
1255
+ for (int i = 0; i < stress_runs && result == 0; i++) {
1256
+ printf("============ Stress %d/%d ============\n", i + 1, stress_runs);
1257
+ Testing::PrepareStressRun(i);
1258
+ options.last_run = (i == stress_runs - 1);
1259
+ result = RunMain(argc, argv);
1260
+ }
1261
+ printf("======== Full Deoptimization =======\n");
1262
+ Testing::DeoptimizeAll();
1263
+ } else {
1264
+ result = RunMain(argc, argv);
783
1265
  }
784
- if (run_shell)
1266
+
1267
+
1268
+ #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
1269
+ // Run remote debugger if requested, but never on --test
1270
+ if (i::FLAG_remote_debugger && !options.test_shell) {
1271
+ InstallUtilityScript();
1272
+ RunRemoteDebugger(i::FLAG_debugger_port);
1273
+ return 0;
1274
+ }
1275
+ #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
1276
+
1277
+ // Run interactive shell if explicitly requested or if no script has been
1278
+ // executed, but never on --test
1279
+
1280
+ if (( options.interactive_shell
1281
+ || !options.script_executed )
1282
+ && !options.test_shell ) {
1283
+ #ifndef V8_SHARED
1284
+ InstallUtilityScript();
1285
+ #endif // V8_SHARED
785
1286
  RunShell();
786
- for (int i = 0; i < threads.length(); i++) {
787
- i::Thread* thread = threads[i];
788
- thread->Join();
789
- delete thread;
790
1287
  }
1288
+
1289
+ V8::Dispose();
1290
+
1291
+ #ifndef V8_SHARED
791
1292
  OnExit();
792
- return 0;
793
- }
1293
+ #endif // V8_SHARED
794
1294
 
1295
+ return result;
1296
+ }
795
1297
 
796
1298
  } // namespace v8
797
1299