libv8 3.3.10.2

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 (700) hide show
  1. data/.gitignore +8 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +4 -0
  4. data/README.md +44 -0
  5. data/Rakefile +73 -0
  6. data/ext/libv8/extconf.rb +9 -0
  7. data/lib/libv8.rb +15 -0
  8. data/lib/libv8/Makefile +38 -0
  9. data/lib/libv8/detect_cpu.rb +27 -0
  10. data/lib/libv8/fpic-on-linux-amd64.patch +13 -0
  11. data/lib/libv8/scons/CHANGES.txt +5334 -0
  12. data/lib/libv8/scons/LICENSE.txt +20 -0
  13. data/lib/libv8/scons/MANIFEST +199 -0
  14. data/lib/libv8/scons/PKG-INFO +13 -0
  15. data/lib/libv8/scons/README.txt +243 -0
  16. data/lib/libv8/scons/RELEASE.txt +98 -0
  17. data/lib/libv8/scons/engine/SCons/Action.py +1241 -0
  18. data/lib/libv8/scons/engine/SCons/Builder.py +877 -0
  19. data/lib/libv8/scons/engine/SCons/CacheDir.py +216 -0
  20. data/lib/libv8/scons/engine/SCons/Conftest.py +793 -0
  21. data/lib/libv8/scons/engine/SCons/Debug.py +220 -0
  22. data/lib/libv8/scons/engine/SCons/Defaults.py +480 -0
  23. data/lib/libv8/scons/engine/SCons/Environment.py +2318 -0
  24. data/lib/libv8/scons/engine/SCons/Errors.py +205 -0
  25. data/lib/libv8/scons/engine/SCons/Executor.py +633 -0
  26. data/lib/libv8/scons/engine/SCons/Job.py +435 -0
  27. data/lib/libv8/scons/engine/SCons/Memoize.py +244 -0
  28. data/lib/libv8/scons/engine/SCons/Node/Alias.py +152 -0
  29. data/lib/libv8/scons/engine/SCons/Node/FS.py +3142 -0
  30. data/lib/libv8/scons/engine/SCons/Node/Python.py +128 -0
  31. data/lib/libv8/scons/engine/SCons/Node/__init__.py +1328 -0
  32. data/lib/libv8/scons/engine/SCons/Options/BoolOption.py +50 -0
  33. data/lib/libv8/scons/engine/SCons/Options/EnumOption.py +50 -0
  34. data/lib/libv8/scons/engine/SCons/Options/ListOption.py +50 -0
  35. data/lib/libv8/scons/engine/SCons/Options/PackageOption.py +50 -0
  36. data/lib/libv8/scons/engine/SCons/Options/PathOption.py +76 -0
  37. data/lib/libv8/scons/engine/SCons/Options/__init__.py +67 -0
  38. data/lib/libv8/scons/engine/SCons/PathList.py +231 -0
  39. data/lib/libv8/scons/engine/SCons/Platform/__init__.py +241 -0
  40. data/lib/libv8/scons/engine/SCons/Platform/aix.py +69 -0
  41. data/lib/libv8/scons/engine/SCons/Platform/cygwin.py +55 -0
  42. data/lib/libv8/scons/engine/SCons/Platform/darwin.py +46 -0
  43. data/lib/libv8/scons/engine/SCons/Platform/hpux.py +46 -0
  44. data/lib/libv8/scons/engine/SCons/Platform/irix.py +44 -0
  45. data/lib/libv8/scons/engine/SCons/Platform/os2.py +58 -0
  46. data/lib/libv8/scons/engine/SCons/Platform/posix.py +263 -0
  47. data/lib/libv8/scons/engine/SCons/Platform/sunos.py +50 -0
  48. data/lib/libv8/scons/engine/SCons/Platform/win32.py +385 -0
  49. data/lib/libv8/scons/engine/SCons/SConf.py +1030 -0
  50. data/lib/libv8/scons/engine/SCons/SConsign.py +383 -0
  51. data/lib/libv8/scons/engine/SCons/Scanner/C.py +132 -0
  52. data/lib/libv8/scons/engine/SCons/Scanner/D.py +73 -0
  53. data/lib/libv8/scons/engine/SCons/Scanner/Dir.py +109 -0
  54. data/lib/libv8/scons/engine/SCons/Scanner/Fortran.py +316 -0
  55. data/lib/libv8/scons/engine/SCons/Scanner/IDL.py +48 -0
  56. data/lib/libv8/scons/engine/SCons/Scanner/LaTeX.py +384 -0
  57. data/lib/libv8/scons/engine/SCons/Scanner/Prog.py +101 -0
  58. data/lib/libv8/scons/engine/SCons/Scanner/RC.py +55 -0
  59. data/lib/libv8/scons/engine/SCons/Scanner/__init__.py +413 -0
  60. data/lib/libv8/scons/engine/SCons/Script/Interactive.py +384 -0
  61. data/lib/libv8/scons/engine/SCons/Script/Main.py +1334 -0
  62. data/lib/libv8/scons/engine/SCons/Script/SConsOptions.py +939 -0
  63. data/lib/libv8/scons/engine/SCons/Script/SConscript.py +640 -0
  64. data/lib/libv8/scons/engine/SCons/Script/__init__.py +412 -0
  65. data/lib/libv8/scons/engine/SCons/Sig.py +63 -0
  66. data/lib/libv8/scons/engine/SCons/Subst.py +904 -0
  67. data/lib/libv8/scons/engine/SCons/Taskmaster.py +1017 -0
  68. data/lib/libv8/scons/engine/SCons/Tool/386asm.py +61 -0
  69. data/lib/libv8/scons/engine/SCons/Tool/BitKeeper.py +67 -0
  70. data/lib/libv8/scons/engine/SCons/Tool/CVS.py +73 -0
  71. data/lib/libv8/scons/engine/SCons/Tool/FortranCommon.py +246 -0
  72. data/lib/libv8/scons/engine/SCons/Tool/JavaCommon.py +323 -0
  73. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/__init__.py +56 -0
  74. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/arch.py +61 -0
  75. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/common.py +240 -0
  76. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/netframework.py +82 -0
  77. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/sdk.py +391 -0
  78. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/vc.py +456 -0
  79. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/vs.py +499 -0
  80. data/lib/libv8/scons/engine/SCons/Tool/Perforce.py +103 -0
  81. data/lib/libv8/scons/engine/SCons/Tool/PharLapCommon.py +137 -0
  82. data/lib/libv8/scons/engine/SCons/Tool/RCS.py +64 -0
  83. data/lib/libv8/scons/engine/SCons/Tool/SCCS.py +64 -0
  84. data/lib/libv8/scons/engine/SCons/Tool/Subversion.py +71 -0
  85. data/lib/libv8/scons/engine/SCons/Tool/__init__.py +681 -0
  86. data/lib/libv8/scons/engine/SCons/Tool/aixc++.py +82 -0
  87. data/lib/libv8/scons/engine/SCons/Tool/aixcc.py +74 -0
  88. data/lib/libv8/scons/engine/SCons/Tool/aixf77.py +80 -0
  89. data/lib/libv8/scons/engine/SCons/Tool/aixlink.py +76 -0
  90. data/lib/libv8/scons/engine/SCons/Tool/applelink.py +71 -0
  91. data/lib/libv8/scons/engine/SCons/Tool/ar.py +63 -0
  92. data/lib/libv8/scons/engine/SCons/Tool/as.py +78 -0
  93. data/lib/libv8/scons/engine/SCons/Tool/bcc32.py +81 -0
  94. data/lib/libv8/scons/engine/SCons/Tool/c++.py +99 -0
  95. data/lib/libv8/scons/engine/SCons/Tool/cc.py +102 -0
  96. data/lib/libv8/scons/engine/SCons/Tool/cvf.py +58 -0
  97. data/lib/libv8/scons/engine/SCons/Tool/default.py +50 -0
  98. data/lib/libv8/scons/engine/SCons/Tool/dmd.py +223 -0
  99. data/lib/libv8/scons/engine/SCons/Tool/dvi.py +64 -0
  100. data/lib/libv8/scons/engine/SCons/Tool/dvipdf.py +124 -0
  101. data/lib/libv8/scons/engine/SCons/Tool/dvips.py +94 -0
  102. data/lib/libv8/scons/engine/SCons/Tool/f77.py +62 -0
  103. data/lib/libv8/scons/engine/SCons/Tool/f90.py +62 -0
  104. data/lib/libv8/scons/engine/SCons/Tool/f95.py +63 -0
  105. data/lib/libv8/scons/engine/SCons/Tool/filesystem.py +98 -0
  106. data/lib/libv8/scons/engine/SCons/Tool/fortran.py +62 -0
  107. data/lib/libv8/scons/engine/SCons/Tool/g++.py +90 -0
  108. data/lib/libv8/scons/engine/SCons/Tool/g77.py +73 -0
  109. data/lib/libv8/scons/engine/SCons/Tool/gas.py +53 -0
  110. data/lib/libv8/scons/engine/SCons/Tool/gcc.py +80 -0
  111. data/lib/libv8/scons/engine/SCons/Tool/gfortran.py +64 -0
  112. data/lib/libv8/scons/engine/SCons/Tool/gnulink.py +63 -0
  113. data/lib/libv8/scons/engine/SCons/Tool/gs.py +81 -0
  114. data/lib/libv8/scons/engine/SCons/Tool/hpc++.py +84 -0
  115. data/lib/libv8/scons/engine/SCons/Tool/hpcc.py +53 -0
  116. data/lib/libv8/scons/engine/SCons/Tool/hplink.py +77 -0
  117. data/lib/libv8/scons/engine/SCons/Tool/icc.py +59 -0
  118. data/lib/libv8/scons/engine/SCons/Tool/icl.py +52 -0
  119. data/lib/libv8/scons/engine/SCons/Tool/ifl.py +72 -0
  120. data/lib/libv8/scons/engine/SCons/Tool/ifort.py +88 -0
  121. data/lib/libv8/scons/engine/SCons/Tool/ilink.py +59 -0
  122. data/lib/libv8/scons/engine/SCons/Tool/ilink32.py +60 -0
  123. data/lib/libv8/scons/engine/SCons/Tool/install.py +229 -0
  124. data/lib/libv8/scons/engine/SCons/Tool/intelc.py +482 -0
  125. data/lib/libv8/scons/engine/SCons/Tool/ipkg.py +67 -0
  126. data/lib/libv8/scons/engine/SCons/Tool/jar.py +110 -0
  127. data/lib/libv8/scons/engine/SCons/Tool/javac.py +230 -0
  128. data/lib/libv8/scons/engine/SCons/Tool/javah.py +137 -0
  129. data/lib/libv8/scons/engine/SCons/Tool/latex.py +79 -0
  130. data/lib/libv8/scons/engine/SCons/Tool/lex.py +97 -0
  131. data/lib/libv8/scons/engine/SCons/Tool/link.py +121 -0
  132. data/lib/libv8/scons/engine/SCons/Tool/linkloc.py +112 -0
  133. data/lib/libv8/scons/engine/SCons/Tool/m4.py +63 -0
  134. data/lib/libv8/scons/engine/SCons/Tool/masm.py +77 -0
  135. data/lib/libv8/scons/engine/SCons/Tool/midl.py +88 -0
  136. data/lib/libv8/scons/engine/SCons/Tool/mingw.py +158 -0
  137. data/lib/libv8/scons/engine/SCons/Tool/mslib.py +64 -0
  138. data/lib/libv8/scons/engine/SCons/Tool/mslink.py +266 -0
  139. data/lib/libv8/scons/engine/SCons/Tool/mssdk.py +50 -0
  140. data/lib/libv8/scons/engine/SCons/Tool/msvc.py +268 -0
  141. data/lib/libv8/scons/engine/SCons/Tool/msvs.py +1388 -0
  142. data/lib/libv8/scons/engine/SCons/Tool/mwcc.py +207 -0
  143. data/lib/libv8/scons/engine/SCons/Tool/mwld.py +107 -0
  144. data/lib/libv8/scons/engine/SCons/Tool/nasm.py +72 -0
  145. data/lib/libv8/scons/engine/SCons/Tool/packaging/__init__.py +312 -0
  146. data/lib/libv8/scons/engine/SCons/Tool/packaging/ipk.py +185 -0
  147. data/lib/libv8/scons/engine/SCons/Tool/packaging/msi.py +527 -0
  148. data/lib/libv8/scons/engine/SCons/Tool/packaging/rpm.py +365 -0
  149. data/lib/libv8/scons/engine/SCons/Tool/packaging/src_tarbz2.py +43 -0
  150. data/lib/libv8/scons/engine/SCons/Tool/packaging/src_targz.py +43 -0
  151. data/lib/libv8/scons/engine/SCons/Tool/packaging/src_zip.py +43 -0
  152. data/lib/libv8/scons/engine/SCons/Tool/packaging/tarbz2.py +44 -0
  153. data/lib/libv8/scons/engine/SCons/Tool/packaging/targz.py +44 -0
  154. data/lib/libv8/scons/engine/SCons/Tool/packaging/zip.py +44 -0
  155. data/lib/libv8/scons/engine/SCons/Tool/pdf.py +78 -0
  156. data/lib/libv8/scons/engine/SCons/Tool/pdflatex.py +83 -0
  157. data/lib/libv8/scons/engine/SCons/Tool/pdftex.py +108 -0
  158. data/lib/libv8/scons/engine/SCons/Tool/qt.py +336 -0
  159. data/lib/libv8/scons/engine/SCons/Tool/rmic.py +120 -0
  160. data/lib/libv8/scons/engine/SCons/Tool/rpcgen.py +70 -0
  161. data/lib/libv8/scons/engine/SCons/Tool/rpm.py +132 -0
  162. data/lib/libv8/scons/engine/SCons/Tool/sgiar.py +68 -0
  163. data/lib/libv8/scons/engine/SCons/Tool/sgic++.py +58 -0
  164. data/lib/libv8/scons/engine/SCons/Tool/sgicc.py +53 -0
  165. data/lib/libv8/scons/engine/SCons/Tool/sgilink.py +63 -0
  166. data/lib/libv8/scons/engine/SCons/Tool/sunar.py +67 -0
  167. data/lib/libv8/scons/engine/SCons/Tool/sunc++.py +142 -0
  168. data/lib/libv8/scons/engine/SCons/Tool/suncc.py +58 -0
  169. data/lib/libv8/scons/engine/SCons/Tool/sunf77.py +63 -0
  170. data/lib/libv8/scons/engine/SCons/Tool/sunf90.py +64 -0
  171. data/lib/libv8/scons/engine/SCons/Tool/sunf95.py +64 -0
  172. data/lib/libv8/scons/engine/SCons/Tool/sunlink.py +77 -0
  173. data/lib/libv8/scons/engine/SCons/Tool/swig.py +182 -0
  174. data/lib/libv8/scons/engine/SCons/Tool/tar.py +73 -0
  175. data/lib/libv8/scons/engine/SCons/Tool/tex.py +813 -0
  176. data/lib/libv8/scons/engine/SCons/Tool/textfile.py +175 -0
  177. data/lib/libv8/scons/engine/SCons/Tool/tlib.py +53 -0
  178. data/lib/libv8/scons/engine/SCons/Tool/wix.py +99 -0
  179. data/lib/libv8/scons/engine/SCons/Tool/yacc.py +130 -0
  180. data/lib/libv8/scons/engine/SCons/Tool/zip.py +99 -0
  181. data/lib/libv8/scons/engine/SCons/Util.py +1492 -0
  182. data/lib/libv8/scons/engine/SCons/Variables/BoolVariable.py +89 -0
  183. data/lib/libv8/scons/engine/SCons/Variables/EnumVariable.py +103 -0
  184. data/lib/libv8/scons/engine/SCons/Variables/ListVariable.py +135 -0
  185. data/lib/libv8/scons/engine/SCons/Variables/PackageVariable.py +106 -0
  186. data/lib/libv8/scons/engine/SCons/Variables/PathVariable.py +147 -0
  187. data/lib/libv8/scons/engine/SCons/Variables/__init__.py +312 -0
  188. data/lib/libv8/scons/engine/SCons/Warnings.py +246 -0
  189. data/lib/libv8/scons/engine/SCons/__init__.py +49 -0
  190. data/lib/libv8/scons/engine/SCons/compat/__init__.py +237 -0
  191. data/lib/libv8/scons/engine/SCons/compat/_scons_builtins.py +150 -0
  192. data/lib/libv8/scons/engine/SCons/compat/_scons_collections.py +45 -0
  193. data/lib/libv8/scons/engine/SCons/compat/_scons_dbm.py +45 -0
  194. data/lib/libv8/scons/engine/SCons/compat/_scons_hashlib.py +76 -0
  195. data/lib/libv8/scons/engine/SCons/compat/_scons_io.py +45 -0
  196. data/lib/libv8/scons/engine/SCons/compat/_scons_sets.py +563 -0
  197. data/lib/libv8/scons/engine/SCons/compat/_scons_subprocess.py +1281 -0
  198. data/lib/libv8/scons/engine/SCons/cpp.py +589 -0
  199. data/lib/libv8/scons/engine/SCons/dblite.py +251 -0
  200. data/lib/libv8/scons/engine/SCons/exitfuncs.py +77 -0
  201. data/lib/libv8/scons/os_spawnv_fix.diff +83 -0
  202. data/lib/libv8/scons/scons-time.1 +1017 -0
  203. data/lib/libv8/scons/scons.1 +15219 -0
  204. data/lib/libv8/scons/sconsign.1 +208 -0
  205. data/lib/libv8/scons/script/scons +196 -0
  206. data/lib/libv8/scons/script/scons-time +1544 -0
  207. data/lib/libv8/scons/script/scons.bat +31 -0
  208. data/lib/libv8/scons/script/sconsign +513 -0
  209. data/lib/libv8/scons/setup.cfg +6 -0
  210. data/lib/libv8/scons/setup.py +425 -0
  211. data/lib/libv8/v8/.gitignore +35 -0
  212. data/lib/libv8/v8/AUTHORS +44 -0
  213. data/lib/libv8/v8/ChangeLog +2839 -0
  214. data/lib/libv8/v8/LICENSE +52 -0
  215. data/lib/libv8/v8/LICENSE.strongtalk +29 -0
  216. data/lib/libv8/v8/LICENSE.v8 +26 -0
  217. data/lib/libv8/v8/LICENSE.valgrind +45 -0
  218. data/lib/libv8/v8/SConstruct +1478 -0
  219. data/lib/libv8/v8/build/README.txt +49 -0
  220. data/lib/libv8/v8/build/all.gyp +18 -0
  221. data/lib/libv8/v8/build/armu.gypi +32 -0
  222. data/lib/libv8/v8/build/common.gypi +144 -0
  223. data/lib/libv8/v8/build/gyp_v8 +145 -0
  224. data/lib/libv8/v8/include/v8-debug.h +395 -0
  225. data/lib/libv8/v8/include/v8-preparser.h +117 -0
  226. data/lib/libv8/v8/include/v8-profiler.h +505 -0
  227. data/lib/libv8/v8/include/v8-testing.h +104 -0
  228. data/lib/libv8/v8/include/v8.h +4124 -0
  229. data/lib/libv8/v8/include/v8stdint.h +53 -0
  230. data/lib/libv8/v8/preparser/SConscript +38 -0
  231. data/lib/libv8/v8/preparser/preparser-process.cc +379 -0
  232. data/lib/libv8/v8/src/SConscript +368 -0
  233. data/lib/libv8/v8/src/accessors.cc +767 -0
  234. data/lib/libv8/v8/src/accessors.h +123 -0
  235. data/lib/libv8/v8/src/allocation-inl.h +49 -0
  236. data/lib/libv8/v8/src/allocation.cc +122 -0
  237. data/lib/libv8/v8/src/allocation.h +143 -0
  238. data/lib/libv8/v8/src/api.cc +5845 -0
  239. data/lib/libv8/v8/src/api.h +574 -0
  240. data/lib/libv8/v8/src/apinatives.js +110 -0
  241. data/lib/libv8/v8/src/apiutils.h +73 -0
  242. data/lib/libv8/v8/src/arguments.h +118 -0
  243. data/lib/libv8/v8/src/arm/assembler-arm-inl.h +353 -0
  244. data/lib/libv8/v8/src/arm/assembler-arm.cc +2661 -0
  245. data/lib/libv8/v8/src/arm/assembler-arm.h +1375 -0
  246. data/lib/libv8/v8/src/arm/builtins-arm.cc +1658 -0
  247. data/lib/libv8/v8/src/arm/code-stubs-arm.cc +6398 -0
  248. data/lib/libv8/v8/src/arm/code-stubs-arm.h +673 -0
  249. data/lib/libv8/v8/src/arm/codegen-arm.cc +52 -0
  250. data/lib/libv8/v8/src/arm/codegen-arm.h +91 -0
  251. data/lib/libv8/v8/src/arm/constants-arm.cc +152 -0
  252. data/lib/libv8/v8/src/arm/constants-arm.h +775 -0
  253. data/lib/libv8/v8/src/arm/cpu-arm.cc +120 -0
  254. data/lib/libv8/v8/src/arm/debug-arm.cc +317 -0
  255. data/lib/libv8/v8/src/arm/deoptimizer-arm.cc +754 -0
  256. data/lib/libv8/v8/src/arm/disasm-arm.cc +1506 -0
  257. data/lib/libv8/v8/src/arm/frames-arm.cc +45 -0
  258. data/lib/libv8/v8/src/arm/frames-arm.h +168 -0
  259. data/lib/libv8/v8/src/arm/full-codegen-arm.cc +4375 -0
  260. data/lib/libv8/v8/src/arm/ic-arm.cc +1562 -0
  261. data/lib/libv8/v8/src/arm/lithium-arm.cc +2206 -0
  262. data/lib/libv8/v8/src/arm/lithium-arm.h +2348 -0
  263. data/lib/libv8/v8/src/arm/lithium-codegen-arm.cc +4526 -0
  264. data/lib/libv8/v8/src/arm/lithium-codegen-arm.h +403 -0
  265. data/lib/libv8/v8/src/arm/lithium-gap-resolver-arm.cc +305 -0
  266. data/lib/libv8/v8/src/arm/lithium-gap-resolver-arm.h +84 -0
  267. data/lib/libv8/v8/src/arm/macro-assembler-arm.cc +3163 -0
  268. data/lib/libv8/v8/src/arm/macro-assembler-arm.h +1126 -0
  269. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.cc +1287 -0
  270. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.h +253 -0
  271. data/lib/libv8/v8/src/arm/simulator-arm.cc +3424 -0
  272. data/lib/libv8/v8/src/arm/simulator-arm.h +431 -0
  273. data/lib/libv8/v8/src/arm/stub-cache-arm.cc +4243 -0
  274. data/lib/libv8/v8/src/array.js +1366 -0
  275. data/lib/libv8/v8/src/assembler.cc +1207 -0
  276. data/lib/libv8/v8/src/assembler.h +858 -0
  277. data/lib/libv8/v8/src/ast-inl.h +112 -0
  278. data/lib/libv8/v8/src/ast.cc +1146 -0
  279. data/lib/libv8/v8/src/ast.h +2188 -0
  280. data/lib/libv8/v8/src/atomicops.h +167 -0
  281. data/lib/libv8/v8/src/atomicops_internals_arm_gcc.h +145 -0
  282. data/lib/libv8/v8/src/atomicops_internals_mips_gcc.h +169 -0
  283. data/lib/libv8/v8/src/atomicops_internals_x86_gcc.cc +133 -0
  284. data/lib/libv8/v8/src/atomicops_internals_x86_gcc.h +287 -0
  285. data/lib/libv8/v8/src/atomicops_internals_x86_macosx.h +301 -0
  286. data/lib/libv8/v8/src/atomicops_internals_x86_msvc.h +203 -0
  287. data/lib/libv8/v8/src/bignum-dtoa.cc +655 -0
  288. data/lib/libv8/v8/src/bignum-dtoa.h +81 -0
  289. data/lib/libv8/v8/src/bignum.cc +768 -0
  290. data/lib/libv8/v8/src/bignum.h +140 -0
  291. data/lib/libv8/v8/src/bootstrapper.cc +2184 -0
  292. data/lib/libv8/v8/src/bootstrapper.h +188 -0
  293. data/lib/libv8/v8/src/builtins.cc +1707 -0
  294. data/lib/libv8/v8/src/builtins.h +371 -0
  295. data/lib/libv8/v8/src/bytecodes-irregexp.h +105 -0
  296. data/lib/libv8/v8/src/cached-powers.cc +177 -0
  297. data/lib/libv8/v8/src/cached-powers.h +65 -0
  298. data/lib/libv8/v8/src/char-predicates-inl.h +94 -0
  299. data/lib/libv8/v8/src/char-predicates.h +67 -0
  300. data/lib/libv8/v8/src/checks.cc +110 -0
  301. data/lib/libv8/v8/src/checks.h +296 -0
  302. data/lib/libv8/v8/src/circular-queue-inl.h +53 -0
  303. data/lib/libv8/v8/src/circular-queue.cc +122 -0
  304. data/lib/libv8/v8/src/circular-queue.h +103 -0
  305. data/lib/libv8/v8/src/code-stubs.cc +267 -0
  306. data/lib/libv8/v8/src/code-stubs.h +1011 -0
  307. data/lib/libv8/v8/src/code.h +70 -0
  308. data/lib/libv8/v8/src/codegen.cc +231 -0
  309. data/lib/libv8/v8/src/codegen.h +84 -0
  310. data/lib/libv8/v8/src/compilation-cache.cc +540 -0
  311. data/lib/libv8/v8/src/compilation-cache.h +287 -0
  312. data/lib/libv8/v8/src/compiler.cc +786 -0
  313. data/lib/libv8/v8/src/compiler.h +312 -0
  314. data/lib/libv8/v8/src/contexts.cc +347 -0
  315. data/lib/libv8/v8/src/contexts.h +391 -0
  316. data/lib/libv8/v8/src/conversions-inl.h +106 -0
  317. data/lib/libv8/v8/src/conversions.cc +1131 -0
  318. data/lib/libv8/v8/src/conversions.h +135 -0
  319. data/lib/libv8/v8/src/counters.cc +93 -0
  320. data/lib/libv8/v8/src/counters.h +254 -0
  321. data/lib/libv8/v8/src/cpu-profiler-inl.h +101 -0
  322. data/lib/libv8/v8/src/cpu-profiler.cc +609 -0
  323. data/lib/libv8/v8/src/cpu-profiler.h +302 -0
  324. data/lib/libv8/v8/src/cpu.h +69 -0
  325. data/lib/libv8/v8/src/d8-debug.cc +367 -0
  326. data/lib/libv8/v8/src/d8-debug.h +158 -0
  327. data/lib/libv8/v8/src/d8-posix.cc +695 -0
  328. data/lib/libv8/v8/src/d8-readline.cc +130 -0
  329. data/lib/libv8/v8/src/d8-windows.cc +42 -0
  330. data/lib/libv8/v8/src/d8.cc +803 -0
  331. data/lib/libv8/v8/src/d8.gyp +91 -0
  332. data/lib/libv8/v8/src/d8.h +235 -0
  333. data/lib/libv8/v8/src/d8.js +2798 -0
  334. data/lib/libv8/v8/src/data-flow.cc +66 -0
  335. data/lib/libv8/v8/src/data-flow.h +205 -0
  336. data/lib/libv8/v8/src/date.js +1103 -0
  337. data/lib/libv8/v8/src/dateparser-inl.h +127 -0
  338. data/lib/libv8/v8/src/dateparser.cc +178 -0
  339. data/lib/libv8/v8/src/dateparser.h +266 -0
  340. data/lib/libv8/v8/src/debug-agent.cc +447 -0
  341. data/lib/libv8/v8/src/debug-agent.h +129 -0
  342. data/lib/libv8/v8/src/debug-debugger.js +2569 -0
  343. data/lib/libv8/v8/src/debug.cc +3165 -0
  344. data/lib/libv8/v8/src/debug.h +1057 -0
  345. data/lib/libv8/v8/src/deoptimizer.cc +1256 -0
  346. data/lib/libv8/v8/src/deoptimizer.h +602 -0
  347. data/lib/libv8/v8/src/disasm.h +80 -0
  348. data/lib/libv8/v8/src/disassembler.cc +343 -0
  349. data/lib/libv8/v8/src/disassembler.h +58 -0
  350. data/lib/libv8/v8/src/diy-fp.cc +58 -0
  351. data/lib/libv8/v8/src/diy-fp.h +117 -0
  352. data/lib/libv8/v8/src/double.h +238 -0
  353. data/lib/libv8/v8/src/dtoa.cc +103 -0
  354. data/lib/libv8/v8/src/dtoa.h +85 -0
  355. data/lib/libv8/v8/src/execution.cc +849 -0
  356. data/lib/libv8/v8/src/execution.h +297 -0
  357. data/lib/libv8/v8/src/extensions/experimental/break-iterator.cc +250 -0
  358. data/lib/libv8/v8/src/extensions/experimental/break-iterator.h +89 -0
  359. data/lib/libv8/v8/src/extensions/experimental/collator.cc +218 -0
  360. data/lib/libv8/v8/src/extensions/experimental/collator.h +69 -0
  361. data/lib/libv8/v8/src/extensions/experimental/experimental.gyp +94 -0
  362. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.cc +78 -0
  363. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.h +54 -0
  364. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.cc +112 -0
  365. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.h +60 -0
  366. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.cc +43 -0
  367. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.h +49 -0
  368. data/lib/libv8/v8/src/extensions/experimental/i18n.js +180 -0
  369. data/lib/libv8/v8/src/extensions/experimental/language-matcher.cc +251 -0
  370. data/lib/libv8/v8/src/extensions/experimental/language-matcher.h +95 -0
  371. data/lib/libv8/v8/src/extensions/externalize-string-extension.cc +141 -0
  372. data/lib/libv8/v8/src/extensions/externalize-string-extension.h +50 -0
  373. data/lib/libv8/v8/src/extensions/gc-extension.cc +58 -0
  374. data/lib/libv8/v8/src/extensions/gc-extension.h +49 -0
  375. data/lib/libv8/v8/src/factory.cc +1222 -0
  376. data/lib/libv8/v8/src/factory.h +442 -0
  377. data/lib/libv8/v8/src/fast-dtoa.cc +736 -0
  378. data/lib/libv8/v8/src/fast-dtoa.h +83 -0
  379. data/lib/libv8/v8/src/fixed-dtoa.cc +405 -0
  380. data/lib/libv8/v8/src/fixed-dtoa.h +55 -0
  381. data/lib/libv8/v8/src/flag-definitions.h +560 -0
  382. data/lib/libv8/v8/src/flags.cc +551 -0
  383. data/lib/libv8/v8/src/flags.h +79 -0
  384. data/lib/libv8/v8/src/frames-inl.h +247 -0
  385. data/lib/libv8/v8/src/frames.cc +1243 -0
  386. data/lib/libv8/v8/src/frames.h +870 -0
  387. data/lib/libv8/v8/src/full-codegen.cc +1374 -0
  388. data/lib/libv8/v8/src/full-codegen.h +771 -0
  389. data/lib/libv8/v8/src/func-name-inferrer.cc +92 -0
  390. data/lib/libv8/v8/src/func-name-inferrer.h +111 -0
  391. data/lib/libv8/v8/src/gdb-jit.cc +1555 -0
  392. data/lib/libv8/v8/src/gdb-jit.h +143 -0
  393. data/lib/libv8/v8/src/global-handles.cc +665 -0
  394. data/lib/libv8/v8/src/global-handles.h +284 -0
  395. data/lib/libv8/v8/src/globals.h +325 -0
  396. data/lib/libv8/v8/src/handles-inl.h +177 -0
  397. data/lib/libv8/v8/src/handles.cc +987 -0
  398. data/lib/libv8/v8/src/handles.h +382 -0
  399. data/lib/libv8/v8/src/hashmap.cc +230 -0
  400. data/lib/libv8/v8/src/hashmap.h +123 -0
  401. data/lib/libv8/v8/src/heap-inl.h +704 -0
  402. data/lib/libv8/v8/src/heap-profiler.cc +1173 -0
  403. data/lib/libv8/v8/src/heap-profiler.h +397 -0
  404. data/lib/libv8/v8/src/heap.cc +5930 -0
  405. data/lib/libv8/v8/src/heap.h +2268 -0
  406. data/lib/libv8/v8/src/hydrogen-instructions.cc +1769 -0
  407. data/lib/libv8/v8/src/hydrogen-instructions.h +3971 -0
  408. data/lib/libv8/v8/src/hydrogen.cc +6239 -0
  409. data/lib/libv8/v8/src/hydrogen.h +1202 -0
  410. data/lib/libv8/v8/src/ia32/assembler-ia32-inl.h +446 -0
  411. data/lib/libv8/v8/src/ia32/assembler-ia32.cc +2487 -0
  412. data/lib/libv8/v8/src/ia32/assembler-ia32.h +1144 -0
  413. data/lib/libv8/v8/src/ia32/builtins-ia32.cc +1621 -0
  414. data/lib/libv8/v8/src/ia32/code-stubs-ia32.cc +6198 -0
  415. data/lib/libv8/v8/src/ia32/code-stubs-ia32.h +517 -0
  416. data/lib/libv8/v8/src/ia32/codegen-ia32.cc +265 -0
  417. data/lib/libv8/v8/src/ia32/codegen-ia32.h +79 -0
  418. data/lib/libv8/v8/src/ia32/cpu-ia32.cc +88 -0
  419. data/lib/libv8/v8/src/ia32/debug-ia32.cc +312 -0
  420. data/lib/libv8/v8/src/ia32/deoptimizer-ia32.cc +774 -0
  421. data/lib/libv8/v8/src/ia32/disasm-ia32.cc +1628 -0
  422. data/lib/libv8/v8/src/ia32/frames-ia32.cc +45 -0
  423. data/lib/libv8/v8/src/ia32/frames-ia32.h +142 -0
  424. data/lib/libv8/v8/src/ia32/full-codegen-ia32.cc +4338 -0
  425. data/lib/libv8/v8/src/ia32/ic-ia32.cc +1597 -0
  426. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.cc +4461 -0
  427. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.h +375 -0
  428. data/lib/libv8/v8/src/ia32/lithium-gap-resolver-ia32.cc +475 -0
  429. data/lib/libv8/v8/src/ia32/lithium-gap-resolver-ia32.h +110 -0
  430. data/lib/libv8/v8/src/ia32/lithium-ia32.cc +2261 -0
  431. data/lib/libv8/v8/src/ia32/lithium-ia32.h +2396 -0
  432. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.cc +2136 -0
  433. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.h +775 -0
  434. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.cc +1263 -0
  435. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.h +216 -0
  436. data/lib/libv8/v8/src/ia32/simulator-ia32.cc +30 -0
  437. data/lib/libv8/v8/src/ia32/simulator-ia32.h +74 -0
  438. data/lib/libv8/v8/src/ia32/stub-cache-ia32.cc +3847 -0
  439. data/lib/libv8/v8/src/ic-inl.h +130 -0
  440. data/lib/libv8/v8/src/ic.cc +2577 -0
  441. data/lib/libv8/v8/src/ic.h +736 -0
  442. data/lib/libv8/v8/src/inspector.cc +63 -0
  443. data/lib/libv8/v8/src/inspector.h +62 -0
  444. data/lib/libv8/v8/src/interpreter-irregexp.cc +659 -0
  445. data/lib/libv8/v8/src/interpreter-irregexp.h +49 -0
  446. data/lib/libv8/v8/src/isolate-inl.h +50 -0
  447. data/lib/libv8/v8/src/isolate.cc +1869 -0
  448. data/lib/libv8/v8/src/isolate.h +1382 -0
  449. data/lib/libv8/v8/src/json-parser.cc +504 -0
  450. data/lib/libv8/v8/src/json-parser.h +161 -0
  451. data/lib/libv8/v8/src/json.js +342 -0
  452. data/lib/libv8/v8/src/jsregexp.cc +5385 -0
  453. data/lib/libv8/v8/src/jsregexp.h +1492 -0
  454. data/lib/libv8/v8/src/list-inl.h +212 -0
  455. data/lib/libv8/v8/src/list.h +174 -0
  456. data/lib/libv8/v8/src/lithium-allocator-inl.h +142 -0
  457. data/lib/libv8/v8/src/lithium-allocator.cc +2123 -0
  458. data/lib/libv8/v8/src/lithium-allocator.h +630 -0
  459. data/lib/libv8/v8/src/lithium.cc +190 -0
  460. data/lib/libv8/v8/src/lithium.h +597 -0
  461. data/lib/libv8/v8/src/liveedit-debugger.js +1082 -0
  462. data/lib/libv8/v8/src/liveedit.cc +1691 -0
  463. data/lib/libv8/v8/src/liveedit.h +180 -0
  464. data/lib/libv8/v8/src/liveobjectlist-inl.h +126 -0
  465. data/lib/libv8/v8/src/liveobjectlist.cc +2589 -0
  466. data/lib/libv8/v8/src/liveobjectlist.h +322 -0
  467. data/lib/libv8/v8/src/log-inl.h +59 -0
  468. data/lib/libv8/v8/src/log-utils.cc +428 -0
  469. data/lib/libv8/v8/src/log-utils.h +231 -0
  470. data/lib/libv8/v8/src/log.cc +1993 -0
  471. data/lib/libv8/v8/src/log.h +476 -0
  472. data/lib/libv8/v8/src/macro-assembler.h +120 -0
  473. data/lib/libv8/v8/src/macros.py +178 -0
  474. data/lib/libv8/v8/src/mark-compact.cc +3143 -0
  475. data/lib/libv8/v8/src/mark-compact.h +506 -0
  476. data/lib/libv8/v8/src/math.js +264 -0
  477. data/lib/libv8/v8/src/messages.cc +179 -0
  478. data/lib/libv8/v8/src/messages.h +113 -0
  479. data/lib/libv8/v8/src/messages.js +1096 -0
  480. data/lib/libv8/v8/src/mips/assembler-mips-inl.h +312 -0
  481. data/lib/libv8/v8/src/mips/assembler-mips.cc +1960 -0
  482. data/lib/libv8/v8/src/mips/assembler-mips.h +1138 -0
  483. data/lib/libv8/v8/src/mips/builtins-mips.cc +1628 -0
  484. data/lib/libv8/v8/src/mips/code-stubs-mips.cc +6656 -0
  485. data/lib/libv8/v8/src/mips/code-stubs-mips.h +682 -0
  486. data/lib/libv8/v8/src/mips/codegen-mips.cc +52 -0
  487. data/lib/libv8/v8/src/mips/codegen-mips.h +98 -0
  488. data/lib/libv8/v8/src/mips/constants-mips.cc +352 -0
  489. data/lib/libv8/v8/src/mips/constants-mips.h +739 -0
  490. data/lib/libv8/v8/src/mips/cpu-mips.cc +96 -0
  491. data/lib/libv8/v8/src/mips/debug-mips.cc +308 -0
  492. data/lib/libv8/v8/src/mips/deoptimizer-mips.cc +91 -0
  493. data/lib/libv8/v8/src/mips/disasm-mips.cc +1050 -0
  494. data/lib/libv8/v8/src/mips/frames-mips.cc +47 -0
  495. data/lib/libv8/v8/src/mips/frames-mips.h +219 -0
  496. data/lib/libv8/v8/src/mips/full-codegen-mips.cc +4388 -0
  497. data/lib/libv8/v8/src/mips/ic-mips.cc +1580 -0
  498. data/lib/libv8/v8/src/mips/lithium-codegen-mips.h +65 -0
  499. data/lib/libv8/v8/src/mips/lithium-mips.h +307 -0
  500. data/lib/libv8/v8/src/mips/macro-assembler-mips.cc +4056 -0
  501. data/lib/libv8/v8/src/mips/macro-assembler-mips.h +1214 -0
  502. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.cc +1251 -0
  503. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.h +252 -0
  504. data/lib/libv8/v8/src/mips/simulator-mips.cc +2621 -0
  505. data/lib/libv8/v8/src/mips/simulator-mips.h +401 -0
  506. data/lib/libv8/v8/src/mips/stub-cache-mips.cc +4285 -0
  507. data/lib/libv8/v8/src/mirror-debugger.js +2382 -0
  508. data/lib/libv8/v8/src/mksnapshot.cc +328 -0
  509. data/lib/libv8/v8/src/natives.h +64 -0
  510. data/lib/libv8/v8/src/objects-debug.cc +738 -0
  511. data/lib/libv8/v8/src/objects-inl.h +4323 -0
  512. data/lib/libv8/v8/src/objects-printer.cc +829 -0
  513. data/lib/libv8/v8/src/objects-visiting.cc +148 -0
  514. data/lib/libv8/v8/src/objects-visiting.h +424 -0
  515. data/lib/libv8/v8/src/objects.cc +10585 -0
  516. data/lib/libv8/v8/src/objects.h +6838 -0
  517. data/lib/libv8/v8/src/parser.cc +4997 -0
  518. data/lib/libv8/v8/src/parser.h +765 -0
  519. data/lib/libv8/v8/src/platform-cygwin.cc +779 -0
  520. data/lib/libv8/v8/src/platform-freebsd.cc +826 -0
  521. data/lib/libv8/v8/src/platform-linux.cc +1149 -0
  522. data/lib/libv8/v8/src/platform-macos.cc +830 -0
  523. data/lib/libv8/v8/src/platform-nullos.cc +479 -0
  524. data/lib/libv8/v8/src/platform-openbsd.cc +640 -0
  525. data/lib/libv8/v8/src/platform-posix.cc +424 -0
  526. data/lib/libv8/v8/src/platform-solaris.cc +762 -0
  527. data/lib/libv8/v8/src/platform-tls-mac.h +62 -0
  528. data/lib/libv8/v8/src/platform-tls-win32.h +62 -0
  529. data/lib/libv8/v8/src/platform-tls.h +50 -0
  530. data/lib/libv8/v8/src/platform-win32.cc +2021 -0
  531. data/lib/libv8/v8/src/platform.h +667 -0
  532. data/lib/libv8/v8/src/preparse-data-format.h +62 -0
  533. data/lib/libv8/v8/src/preparse-data.cc +183 -0
  534. data/lib/libv8/v8/src/preparse-data.h +225 -0
  535. data/lib/libv8/v8/src/preparser-api.cc +220 -0
  536. data/lib/libv8/v8/src/preparser.cc +1450 -0
  537. data/lib/libv8/v8/src/preparser.h +493 -0
  538. data/lib/libv8/v8/src/prettyprinter.cc +1493 -0
  539. data/lib/libv8/v8/src/prettyprinter.h +223 -0
  540. data/lib/libv8/v8/src/profile-generator-inl.h +128 -0
  541. data/lib/libv8/v8/src/profile-generator.cc +3098 -0
  542. data/lib/libv8/v8/src/profile-generator.h +1126 -0
  543. data/lib/libv8/v8/src/property.cc +105 -0
  544. data/lib/libv8/v8/src/property.h +365 -0
  545. data/lib/libv8/v8/src/proxy.js +83 -0
  546. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp-inl.h +78 -0
  547. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp.cc +471 -0
  548. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp.h +142 -0
  549. data/lib/libv8/v8/src/regexp-macro-assembler-tracer.cc +373 -0
  550. data/lib/libv8/v8/src/regexp-macro-assembler-tracer.h +104 -0
  551. data/lib/libv8/v8/src/regexp-macro-assembler.cc +267 -0
  552. data/lib/libv8/v8/src/regexp-macro-assembler.h +243 -0
  553. data/lib/libv8/v8/src/regexp-stack.cc +111 -0
  554. data/lib/libv8/v8/src/regexp-stack.h +147 -0
  555. data/lib/libv8/v8/src/regexp.js +483 -0
  556. data/lib/libv8/v8/src/rewriter.cc +360 -0
  557. data/lib/libv8/v8/src/rewriter.h +50 -0
  558. data/lib/libv8/v8/src/runtime-profiler.cc +489 -0
  559. data/lib/libv8/v8/src/runtime-profiler.h +201 -0
  560. data/lib/libv8/v8/src/runtime.cc +12227 -0
  561. data/lib/libv8/v8/src/runtime.h +652 -0
  562. data/lib/libv8/v8/src/runtime.js +649 -0
  563. data/lib/libv8/v8/src/safepoint-table.cc +256 -0
  564. data/lib/libv8/v8/src/safepoint-table.h +270 -0
  565. data/lib/libv8/v8/src/scanner-base.cc +952 -0
  566. data/lib/libv8/v8/src/scanner-base.h +670 -0
  567. data/lib/libv8/v8/src/scanner.cc +345 -0
  568. data/lib/libv8/v8/src/scanner.h +146 -0
  569. data/lib/libv8/v8/src/scopeinfo.cc +646 -0
  570. data/lib/libv8/v8/src/scopeinfo.h +254 -0
  571. data/lib/libv8/v8/src/scopes.cc +1150 -0
  572. data/lib/libv8/v8/src/scopes.h +507 -0
  573. data/lib/libv8/v8/src/serialize.cc +1574 -0
  574. data/lib/libv8/v8/src/serialize.h +589 -0
  575. data/lib/libv8/v8/src/shell.h +55 -0
  576. data/lib/libv8/v8/src/simulator.h +43 -0
  577. data/lib/libv8/v8/src/small-pointer-list.h +163 -0
  578. data/lib/libv8/v8/src/smart-pointer.h +109 -0
  579. data/lib/libv8/v8/src/snapshot-common.cc +83 -0
  580. data/lib/libv8/v8/src/snapshot-empty.cc +54 -0
  581. data/lib/libv8/v8/src/snapshot.h +91 -0
  582. data/lib/libv8/v8/src/spaces-inl.h +529 -0
  583. data/lib/libv8/v8/src/spaces.cc +3145 -0
  584. data/lib/libv8/v8/src/spaces.h +2369 -0
  585. data/lib/libv8/v8/src/splay-tree-inl.h +310 -0
  586. data/lib/libv8/v8/src/splay-tree.h +205 -0
  587. data/lib/libv8/v8/src/string-search.cc +41 -0
  588. data/lib/libv8/v8/src/string-search.h +568 -0
  589. data/lib/libv8/v8/src/string-stream.cc +592 -0
  590. data/lib/libv8/v8/src/string-stream.h +191 -0
  591. data/lib/libv8/v8/src/string.js +994 -0
  592. data/lib/libv8/v8/src/strtod.cc +440 -0
  593. data/lib/libv8/v8/src/strtod.h +40 -0
  594. data/lib/libv8/v8/src/stub-cache.cc +1965 -0
  595. data/lib/libv8/v8/src/stub-cache.h +924 -0
  596. data/lib/libv8/v8/src/third_party/valgrind/valgrind.h +3925 -0
  597. data/lib/libv8/v8/src/token.cc +63 -0
  598. data/lib/libv8/v8/src/token.h +288 -0
  599. data/lib/libv8/v8/src/type-info.cc +507 -0
  600. data/lib/libv8/v8/src/type-info.h +272 -0
  601. data/lib/libv8/v8/src/unbound-queue-inl.h +95 -0
  602. data/lib/libv8/v8/src/unbound-queue.h +69 -0
  603. data/lib/libv8/v8/src/unicode-inl.h +238 -0
  604. data/lib/libv8/v8/src/unicode.cc +1624 -0
  605. data/lib/libv8/v8/src/unicode.h +280 -0
  606. data/lib/libv8/v8/src/uri.js +408 -0
  607. data/lib/libv8/v8/src/utils-inl.h +48 -0
  608. data/lib/libv8/v8/src/utils.cc +371 -0
  609. data/lib/libv8/v8/src/utils.h +800 -0
  610. data/lib/libv8/v8/src/v8-counters.cc +62 -0
  611. data/lib/libv8/v8/src/v8-counters.h +314 -0
  612. data/lib/libv8/v8/src/v8.cc +213 -0
  613. data/lib/libv8/v8/src/v8.h +131 -0
  614. data/lib/libv8/v8/src/v8checks.h +64 -0
  615. data/lib/libv8/v8/src/v8dll-main.cc +44 -0
  616. data/lib/libv8/v8/src/v8globals.h +512 -0
  617. data/lib/libv8/v8/src/v8memory.h +82 -0
  618. data/lib/libv8/v8/src/v8natives.js +1310 -0
  619. data/lib/libv8/v8/src/v8preparserdll-main.cc +39 -0
  620. data/lib/libv8/v8/src/v8threads.cc +464 -0
  621. data/lib/libv8/v8/src/v8threads.h +165 -0
  622. data/lib/libv8/v8/src/v8utils.h +319 -0
  623. data/lib/libv8/v8/src/variables.cc +114 -0
  624. data/lib/libv8/v8/src/variables.h +167 -0
  625. data/lib/libv8/v8/src/version.cc +116 -0
  626. data/lib/libv8/v8/src/version.h +68 -0
  627. data/lib/libv8/v8/src/vm-state-inl.h +138 -0
  628. data/lib/libv8/v8/src/vm-state.h +71 -0
  629. data/lib/libv8/v8/src/win32-headers.h +96 -0
  630. data/lib/libv8/v8/src/x64/assembler-x64-inl.h +462 -0
  631. data/lib/libv8/v8/src/x64/assembler-x64.cc +3027 -0
  632. data/lib/libv8/v8/src/x64/assembler-x64.h +1633 -0
  633. data/lib/libv8/v8/src/x64/builtins-x64.cc +1520 -0
  634. data/lib/libv8/v8/src/x64/code-stubs-x64.cc +5132 -0
  635. data/lib/libv8/v8/src/x64/code-stubs-x64.h +514 -0
  636. data/lib/libv8/v8/src/x64/codegen-x64.cc +146 -0
  637. data/lib/libv8/v8/src/x64/codegen-x64.h +76 -0
  638. data/lib/libv8/v8/src/x64/cpu-x64.cc +88 -0
  639. data/lib/libv8/v8/src/x64/debug-x64.cc +319 -0
  640. data/lib/libv8/v8/src/x64/deoptimizer-x64.cc +815 -0
  641. data/lib/libv8/v8/src/x64/disasm-x64.cc +1832 -0
  642. data/lib/libv8/v8/src/x64/frames-x64.cc +45 -0
  643. data/lib/libv8/v8/src/x64/frames-x64.h +130 -0
  644. data/lib/libv8/v8/src/x64/full-codegen-x64.cc +4318 -0
  645. data/lib/libv8/v8/src/x64/ic-x64.cc +1608 -0
  646. data/lib/libv8/v8/src/x64/lithium-codegen-x64.cc +4267 -0
  647. data/lib/libv8/v8/src/x64/lithium-codegen-x64.h +367 -0
  648. data/lib/libv8/v8/src/x64/lithium-gap-resolver-x64.cc +320 -0
  649. data/lib/libv8/v8/src/x64/lithium-gap-resolver-x64.h +74 -0
  650. data/lib/libv8/v8/src/x64/lithium-x64.cc +2202 -0
  651. data/lib/libv8/v8/src/x64/lithium-x64.h +2333 -0
  652. data/lib/libv8/v8/src/x64/macro-assembler-x64.cc +3745 -0
  653. data/lib/libv8/v8/src/x64/macro-assembler-x64.h +1290 -0
  654. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.cc +1398 -0
  655. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.h +282 -0
  656. data/lib/libv8/v8/src/x64/simulator-x64.cc +27 -0
  657. data/lib/libv8/v8/src/x64/simulator-x64.h +72 -0
  658. data/lib/libv8/v8/src/x64/stub-cache-x64.cc +3610 -0
  659. data/lib/libv8/v8/src/zone-inl.h +140 -0
  660. data/lib/libv8/v8/src/zone.cc +196 -0
  661. data/lib/libv8/v8/src/zone.h +240 -0
  662. data/lib/libv8/v8/tools/codemap.js +265 -0
  663. data/lib/libv8/v8/tools/consarray.js +93 -0
  664. data/lib/libv8/v8/tools/csvparser.js +78 -0
  665. data/lib/libv8/v8/tools/disasm.py +92 -0
  666. data/lib/libv8/v8/tools/freebsd-tick-processor +10 -0
  667. data/lib/libv8/v8/tools/gc-nvp-trace-processor.py +342 -0
  668. data/lib/libv8/v8/tools/gcmole/README +62 -0
  669. data/lib/libv8/v8/tools/gcmole/gccause.lua +60 -0
  670. data/lib/libv8/v8/tools/gcmole/gcmole.cc +1261 -0
  671. data/lib/libv8/v8/tools/gcmole/gcmole.lua +378 -0
  672. data/lib/libv8/v8/tools/generate-ten-powers.scm +286 -0
  673. data/lib/libv8/v8/tools/grokdump.py +841 -0
  674. data/lib/libv8/v8/tools/gyp/v8.gyp +995 -0
  675. data/lib/libv8/v8/tools/js2c.py +364 -0
  676. data/lib/libv8/v8/tools/jsmin.py +280 -0
  677. data/lib/libv8/v8/tools/linux-tick-processor +35 -0
  678. data/lib/libv8/v8/tools/ll_prof.py +942 -0
  679. data/lib/libv8/v8/tools/logreader.js +185 -0
  680. data/lib/libv8/v8/tools/mac-nm +18 -0
  681. data/lib/libv8/v8/tools/mac-tick-processor +6 -0
  682. data/lib/libv8/v8/tools/oom_dump/README +31 -0
  683. data/lib/libv8/v8/tools/oom_dump/SConstruct +42 -0
  684. data/lib/libv8/v8/tools/oom_dump/oom_dump.cc +288 -0
  685. data/lib/libv8/v8/tools/presubmit.py +305 -0
  686. data/lib/libv8/v8/tools/process-heap-prof.py +120 -0
  687. data/lib/libv8/v8/tools/profile.js +751 -0
  688. data/lib/libv8/v8/tools/profile_view.js +219 -0
  689. data/lib/libv8/v8/tools/run-valgrind.py +77 -0
  690. data/lib/libv8/v8/tools/splaytree.js +316 -0
  691. data/lib/libv8/v8/tools/stats-viewer.py +468 -0
  692. data/lib/libv8/v8/tools/test.py +1510 -0
  693. data/lib/libv8/v8/tools/tickprocessor-driver.js +59 -0
  694. data/lib/libv8/v8/tools/tickprocessor.js +877 -0
  695. data/lib/libv8/v8/tools/utils.py +96 -0
  696. data/lib/libv8/v8/tools/visual_studio/README.txt +12 -0
  697. data/lib/libv8/v8/tools/windows-tick-processor.bat +30 -0
  698. data/lib/libv8/version.rb +4 -0
  699. data/libv8.gemspec +31 -0
  700. metadata +800 -0
@@ -0,0 +1,45 @@
1
+ // Copyright 2006-2008 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #include "v8.h"
29
+
30
+ #if defined(V8_TARGET_ARCH_IA32)
31
+
32
+ #include "frames-inl.h"
33
+
34
+ namespace v8 {
35
+ namespace internal {
36
+
37
+
38
+ Address ExitFrame::ComputeStackPointer(Address fp) {
39
+ return Memory::Address_at(fp + ExitFrameConstants::kSPOffset);
40
+ }
41
+
42
+
43
+ } } // namespace v8::internal
44
+
45
+ #endif // V8_TARGET_ARCH_IA32
@@ -0,0 +1,142 @@
1
+ // Copyright 2006-2008 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef V8_IA32_FRAMES_IA32_H_
29
+ #define V8_IA32_FRAMES_IA32_H_
30
+
31
+ namespace v8 {
32
+ namespace internal {
33
+
34
+
35
+ // Register lists
36
+ // Note that the bit values must match those used in actual instruction encoding
37
+ static const int kNumRegs = 8;
38
+
39
+
40
+ // Caller-saved registers
41
+ static const RegList kJSCallerSaved =
42
+ 1 << 0 | // eax
43
+ 1 << 1 | // ecx
44
+ 1 << 2 | // edx
45
+ 1 << 3 | // ebx - used as a caller-saved register in JavaScript code
46
+ 1 << 7; // edi - callee function
47
+
48
+ static const int kNumJSCallerSaved = 5;
49
+
50
+ typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
51
+
52
+
53
+ // Number of registers for which space is reserved in safepoints.
54
+ static const int kNumSafepointRegisters = 8;
55
+
56
+ // ----------------------------------------------------
57
+
58
+
59
+ class StackHandlerConstants : public AllStatic {
60
+ public:
61
+ static const int kNextOffset = 0 * kPointerSize;
62
+ static const int kFPOffset = 1 * kPointerSize;
63
+ static const int kStateOffset = 2 * kPointerSize;
64
+ static const int kPCOffset = 3 * kPointerSize;
65
+
66
+ static const int kSize = kPCOffset + kPointerSize;
67
+ };
68
+
69
+
70
+ class EntryFrameConstants : public AllStatic {
71
+ public:
72
+ static const int kCallerFPOffset = -6 * kPointerSize;
73
+
74
+ static const int kFunctionArgOffset = +3 * kPointerSize;
75
+ static const int kReceiverArgOffset = +4 * kPointerSize;
76
+ static const int kArgcOffset = +5 * kPointerSize;
77
+ static const int kArgvOffset = +6 * kPointerSize;
78
+ };
79
+
80
+
81
+ class ExitFrameConstants : public AllStatic {
82
+ public:
83
+ static const int kCodeOffset = -2 * kPointerSize;
84
+ static const int kSPOffset = -1 * kPointerSize;
85
+
86
+ static const int kCallerFPOffset = 0 * kPointerSize;
87
+ static const int kCallerPCOffset = +1 * kPointerSize;
88
+
89
+ // FP-relative displacement of the caller's SP. It points just
90
+ // below the saved PC.
91
+ static const int kCallerSPDisplacement = +2 * kPointerSize;
92
+ };
93
+
94
+
95
+ class StandardFrameConstants : public AllStatic {
96
+ public:
97
+ // StandardFrame::IterateExpressions assumes that kContextOffset is the last
98
+ // object pointer.
99
+ static const int kFixedFrameSize = 4; // Currently unused.
100
+ static const int kExpressionsOffset = -3 * kPointerSize;
101
+ static const int kMarkerOffset = -2 * kPointerSize;
102
+ static const int kContextOffset = -1 * kPointerSize;
103
+ static const int kCallerFPOffset = 0 * kPointerSize;
104
+ static const int kCallerPCOffset = +1 * kPointerSize;
105
+ static const int kCallerSPOffset = +2 * kPointerSize;
106
+ };
107
+
108
+
109
+ class JavaScriptFrameConstants : public AllStatic {
110
+ public:
111
+ // FP-relative.
112
+ static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
113
+ static const int kLastParameterOffset = +2 * kPointerSize;
114
+ static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
115
+
116
+ // Caller SP-relative.
117
+ static const int kParam0Offset = -2 * kPointerSize;
118
+ static const int kReceiverOffset = -1 * kPointerSize;
119
+ };
120
+
121
+
122
+ class ArgumentsAdaptorFrameConstants : public AllStatic {
123
+ public:
124
+ static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
125
+ };
126
+
127
+
128
+ class InternalFrameConstants : public AllStatic {
129
+ public:
130
+ static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
131
+ };
132
+
133
+
134
+ inline Object* JavaScriptFrame::function_slot_object() const {
135
+ const int offset = JavaScriptFrameConstants::kFunctionOffset;
136
+ return Memory::Object_at(fp() + offset);
137
+ }
138
+
139
+
140
+ } } // namespace v8::internal
141
+
142
+ #endif // V8_IA32_FRAMES_IA32_H_
@@ -0,0 +1,4338 @@
1
+ // Copyright 2011 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #include "v8.h"
29
+
30
+ #if defined(V8_TARGET_ARCH_IA32)
31
+
32
+ #include "code-stubs.h"
33
+ #include "codegen.h"
34
+ #include "compiler.h"
35
+ #include "debug.h"
36
+ #include "full-codegen.h"
37
+ #include "parser.h"
38
+ #include "scopes.h"
39
+ #include "stub-cache.h"
40
+
41
+ namespace v8 {
42
+ namespace internal {
43
+
44
+
45
+ #define __ ACCESS_MASM(masm_)
46
+
47
+
48
+ static unsigned GetPropertyId(Property* property) {
49
+ if (property->is_synthetic()) return AstNode::kNoNumber;
50
+ return property->id();
51
+ }
52
+
53
+
54
+ class JumpPatchSite BASE_EMBEDDED {
55
+ public:
56
+ explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) {
57
+ #ifdef DEBUG
58
+ info_emitted_ = false;
59
+ #endif
60
+ }
61
+
62
+ ~JumpPatchSite() {
63
+ ASSERT(patch_site_.is_bound() == info_emitted_);
64
+ }
65
+
66
+ void EmitJumpIfNotSmi(Register reg,
67
+ Label* target,
68
+ Label::Distance distance = Label::kFar) {
69
+ __ test(reg, Immediate(kSmiTagMask));
70
+ EmitJump(not_carry, target, distance); // Always taken before patched.
71
+ }
72
+
73
+ void EmitJumpIfSmi(Register reg,
74
+ Label* target,
75
+ Label::Distance distance = Label::kFar) {
76
+ __ test(reg, Immediate(kSmiTagMask));
77
+ EmitJump(carry, target, distance); // Never taken before patched.
78
+ }
79
+
80
+ void EmitPatchInfo() {
81
+ int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_);
82
+ ASSERT(is_int8(delta_to_patch_site));
83
+ __ test(eax, Immediate(delta_to_patch_site));
84
+ #ifdef DEBUG
85
+ info_emitted_ = true;
86
+ #endif
87
+ }
88
+
89
+ bool is_bound() const { return patch_site_.is_bound(); }
90
+
91
+ private:
92
+ // jc will be patched with jz, jnc will become jnz.
93
+ void EmitJump(Condition cc, Label* target, Label::Distance distance) {
94
+ ASSERT(!patch_site_.is_bound() && !info_emitted_);
95
+ ASSERT(cc == carry || cc == not_carry);
96
+ __ bind(&patch_site_);
97
+ __ j(cc, target, distance);
98
+ }
99
+
100
+ MacroAssembler* masm_;
101
+ Label patch_site_;
102
+ #ifdef DEBUG
103
+ bool info_emitted_;
104
+ #endif
105
+ };
106
+
107
+
108
+ // Generate code for a JS function. On entry to the function the receiver
109
+ // and arguments have been pushed on the stack left to right, with the
110
+ // return address on top of them. The actual argument count matches the
111
+ // formal parameter count expected by the function.
112
+ //
113
+ // The live registers are:
114
+ // o edi: the JS function object being called (ie, ourselves)
115
+ // o esi: our context
116
+ // o ebp: our caller's frame pointer
117
+ // o esp: stack pointer (pointing to return address)
118
+ //
119
+ // The function builds a JS frame. Please see JavaScriptFrameConstants in
120
+ // frames-ia32.h for its layout.
121
+ void FullCodeGenerator::Generate(CompilationInfo* info) {
122
+ ASSERT(info_ == NULL);
123
+ info_ = info;
124
+ SetFunctionPosition(function());
125
+ Comment cmnt(masm_, "[ function compiled by full code generator");
126
+
127
+ #ifdef DEBUG
128
+ if (strlen(FLAG_stop_at) > 0 &&
129
+ info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) {
130
+ __ int3();
131
+ }
132
+ #endif
133
+
134
+ // Strict mode functions need to replace the receiver with undefined
135
+ // when called as functions (without an explicit receiver
136
+ // object). ecx is zero for method calls and non-zero for function
137
+ // calls.
138
+ if (info->is_strict_mode()) {
139
+ Label ok;
140
+ __ test(ecx, Operand(ecx));
141
+ __ j(zero, &ok, Label::kNear);
142
+ // +1 for return address.
143
+ int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize;
144
+ __ mov(Operand(esp, receiver_offset),
145
+ Immediate(isolate()->factory()->undefined_value()));
146
+ __ bind(&ok);
147
+ }
148
+
149
+ __ push(ebp); // Caller's frame pointer.
150
+ __ mov(ebp, esp);
151
+ __ push(esi); // Callee's context.
152
+ __ push(edi); // Callee's JS Function.
153
+
154
+ { Comment cmnt(masm_, "[ Allocate locals");
155
+ int locals_count = scope()->num_stack_slots();
156
+ if (locals_count == 1) {
157
+ __ push(Immediate(isolate()->factory()->undefined_value()));
158
+ } else if (locals_count > 1) {
159
+ __ mov(eax, Immediate(isolate()->factory()->undefined_value()));
160
+ for (int i = 0; i < locals_count; i++) {
161
+ __ push(eax);
162
+ }
163
+ }
164
+ }
165
+
166
+ bool function_in_register = true;
167
+
168
+ // Possibly allocate a local context.
169
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
170
+ if (heap_slots > 0) {
171
+ Comment cmnt(masm_, "[ Allocate local context");
172
+ // Argument to NewContext is the function, which is still in edi.
173
+ __ push(edi);
174
+ if (heap_slots <= FastNewContextStub::kMaximumSlots) {
175
+ FastNewContextStub stub(heap_slots);
176
+ __ CallStub(&stub);
177
+ } else {
178
+ __ CallRuntime(Runtime::kNewContext, 1);
179
+ }
180
+ function_in_register = false;
181
+ // Context is returned in both eax and esi. It replaces the context
182
+ // passed to us. It's saved in the stack and kept live in esi.
183
+ __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi);
184
+
185
+ // Copy parameters into context if necessary.
186
+ int num_parameters = scope()->num_parameters();
187
+ for (int i = 0; i < num_parameters; i++) {
188
+ Slot* slot = scope()->parameter(i)->AsSlot();
189
+ if (slot != NULL && slot->type() == Slot::CONTEXT) {
190
+ int parameter_offset = StandardFrameConstants::kCallerSPOffset +
191
+ (num_parameters - 1 - i) * kPointerSize;
192
+ // Load parameter from stack.
193
+ __ mov(eax, Operand(ebp, parameter_offset));
194
+ // Store it in the context.
195
+ int context_offset = Context::SlotOffset(slot->index());
196
+ __ mov(Operand(esi, context_offset), eax);
197
+ // Update the write barrier. This clobbers all involved
198
+ // registers, so we have use a third register to avoid
199
+ // clobbering esi.
200
+ __ mov(ecx, esi);
201
+ __ RecordWrite(ecx, context_offset, eax, ebx);
202
+ }
203
+ }
204
+ }
205
+
206
+ Variable* arguments = scope()->arguments();
207
+ if (arguments != NULL) {
208
+ // Function uses arguments object.
209
+ Comment cmnt(masm_, "[ Allocate arguments object");
210
+ if (function_in_register) {
211
+ __ push(edi);
212
+ } else {
213
+ __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
214
+ }
215
+ // Receiver is just before the parameters on the caller's stack.
216
+ int offset = scope()->num_parameters() * kPointerSize;
217
+ __ lea(edx,
218
+ Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset));
219
+ __ push(edx);
220
+ __ SafePush(Immediate(Smi::FromInt(scope()->num_parameters())));
221
+ // Arguments to ArgumentsAccessStub:
222
+ // function, receiver address, parameter count.
223
+ // The stub will rewrite receiver and parameter count if the previous
224
+ // stack frame was an arguments adapter frame.
225
+ ArgumentsAccessStub stub(
226
+ is_strict_mode() ? ArgumentsAccessStub::NEW_STRICT
227
+ : ArgumentsAccessStub::NEW_NON_STRICT);
228
+ __ CallStub(&stub);
229
+
230
+ Variable* arguments_shadow = scope()->arguments_shadow();
231
+ if (arguments_shadow != NULL) {
232
+ __ mov(ecx, eax); // Duplicate result.
233
+ Move(arguments_shadow->AsSlot(), ecx, ebx, edx);
234
+ }
235
+ Move(arguments->AsSlot(), eax, ebx, edx);
236
+ }
237
+
238
+ if (FLAG_trace) {
239
+ __ CallRuntime(Runtime::kTraceEnter, 0);
240
+ }
241
+
242
+ // Visit the declarations and body unless there is an illegal
243
+ // redeclaration.
244
+ if (scope()->HasIllegalRedeclaration()) {
245
+ Comment cmnt(masm_, "[ Declarations");
246
+ scope()->VisitIllegalRedeclaration(this);
247
+
248
+ } else {
249
+ { Comment cmnt(masm_, "[ Declarations");
250
+ // For named function expressions, declare the function name as a
251
+ // constant.
252
+ if (scope()->is_function_scope() && scope()->function() != NULL) {
253
+ EmitDeclaration(scope()->function(), Variable::CONST, NULL);
254
+ }
255
+ VisitDeclarations(scope()->declarations());
256
+ }
257
+
258
+ { Comment cmnt(masm_, "[ Stack check");
259
+ PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS);
260
+ Label ok;
261
+ ExternalReference stack_limit =
262
+ ExternalReference::address_of_stack_limit(isolate());
263
+ __ cmp(esp, Operand::StaticVariable(stack_limit));
264
+ __ j(above_equal, &ok, Label::kNear);
265
+ StackCheckStub stub;
266
+ __ CallStub(&stub);
267
+ __ bind(&ok);
268
+ }
269
+
270
+ { Comment cmnt(masm_, "[ Body");
271
+ ASSERT(loop_depth() == 0);
272
+ VisitStatements(function()->body());
273
+ ASSERT(loop_depth() == 0);
274
+ }
275
+ }
276
+
277
+ // Always emit a 'return undefined' in case control fell off the end of
278
+ // the body.
279
+ { Comment cmnt(masm_, "[ return <undefined>;");
280
+ __ mov(eax, isolate()->factory()->undefined_value());
281
+ EmitReturnSequence();
282
+ }
283
+ }
284
+
285
+
286
+ void FullCodeGenerator::ClearAccumulator() {
287
+ __ Set(eax, Immediate(Smi::FromInt(0)));
288
+ }
289
+
290
+
291
+ void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt) {
292
+ Comment cmnt(masm_, "[ Stack check");
293
+ Label ok;
294
+ ExternalReference stack_limit =
295
+ ExternalReference::address_of_stack_limit(isolate());
296
+ __ cmp(esp, Operand::StaticVariable(stack_limit));
297
+ __ j(above_equal, &ok, Label::kNear);
298
+ StackCheckStub stub;
299
+ __ CallStub(&stub);
300
+ // Record a mapping of this PC offset to the OSR id. This is used to find
301
+ // the AST id from the unoptimized code in order to use it as a key into
302
+ // the deoptimization input data found in the optimized code.
303
+ RecordStackCheck(stmt->OsrEntryId());
304
+
305
+ // Loop stack checks can be patched to perform on-stack replacement. In
306
+ // order to decide whether or not to perform OSR we embed the loop depth
307
+ // in a test instruction after the call so we can extract it from the OSR
308
+ // builtin.
309
+ ASSERT(loop_depth() > 0);
310
+ __ test(eax, Immediate(Min(loop_depth(), Code::kMaxLoopNestingMarker)));
311
+
312
+ __ bind(&ok);
313
+ PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
314
+ // Record a mapping of the OSR id to this PC. This is used if the OSR
315
+ // entry becomes the target of a bailout. We don't expect it to be, but
316
+ // we want it to work if it is.
317
+ PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS);
318
+ }
319
+
320
+
321
+ void FullCodeGenerator::EmitReturnSequence() {
322
+ Comment cmnt(masm_, "[ Return sequence");
323
+ if (return_label_.is_bound()) {
324
+ __ jmp(&return_label_);
325
+ } else {
326
+ // Common return label
327
+ __ bind(&return_label_);
328
+ if (FLAG_trace) {
329
+ __ push(eax);
330
+ __ CallRuntime(Runtime::kTraceExit, 1);
331
+ }
332
+ #ifdef DEBUG
333
+ // Add a label for checking the size of the code used for returning.
334
+ Label check_exit_codesize;
335
+ masm_->bind(&check_exit_codesize);
336
+ #endif
337
+ SetSourcePosition(function()->end_position() - 1);
338
+ __ RecordJSReturn();
339
+ // Do not use the leave instruction here because it is too short to
340
+ // patch with the code required by the debugger.
341
+ __ mov(esp, ebp);
342
+ __ pop(ebp);
343
+
344
+ int arguments_bytes = (scope()->num_parameters() + 1) * kPointerSize;
345
+ __ Ret(arguments_bytes, ecx);
346
+ #ifdef ENABLE_DEBUGGER_SUPPORT
347
+ // Check that the size of the code used for returning is large enough
348
+ // for the debugger's requirements.
349
+ ASSERT(Assembler::kJSReturnSequenceLength <=
350
+ masm_->SizeOfCodeGeneratedSince(&check_exit_codesize));
351
+ #endif
352
+ }
353
+ }
354
+
355
+
356
+ void FullCodeGenerator::EffectContext::Plug(Slot* slot) const {
357
+ }
358
+
359
+
360
+ void FullCodeGenerator::AccumulatorValueContext::Plug(Slot* slot) const {
361
+ MemOperand slot_operand = codegen()->EmitSlotSearch(slot, result_register());
362
+ __ mov(result_register(), slot_operand);
363
+ }
364
+
365
+
366
+ void FullCodeGenerator::StackValueContext::Plug(Slot* slot) const {
367
+ MemOperand slot_operand = codegen()->EmitSlotSearch(slot, result_register());
368
+ // Memory operands can be pushed directly.
369
+ __ push(slot_operand);
370
+ }
371
+
372
+
373
+ void FullCodeGenerator::TestContext::Plug(Slot* slot) const {
374
+ // For simplicity we always test the accumulator register.
375
+ codegen()->Move(result_register(), slot);
376
+ codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
377
+ codegen()->DoTest(true_label_, false_label_, fall_through_);
378
+ }
379
+
380
+
381
+ void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const {
382
+ UNREACHABLE(); // Not used on IA32.
383
+ }
384
+
385
+
386
+ void FullCodeGenerator::AccumulatorValueContext::Plug(
387
+ Heap::RootListIndex index) const {
388
+ UNREACHABLE(); // Not used on IA32.
389
+ }
390
+
391
+
392
+ void FullCodeGenerator::StackValueContext::Plug(
393
+ Heap::RootListIndex index) const {
394
+ UNREACHABLE(); // Not used on IA32.
395
+ }
396
+
397
+
398
+ void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const {
399
+ UNREACHABLE(); // Not used on IA32.
400
+ }
401
+
402
+
403
+ void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const {
404
+ }
405
+
406
+
407
+ void FullCodeGenerator::AccumulatorValueContext::Plug(
408
+ Handle<Object> lit) const {
409
+ if (lit->IsSmi()) {
410
+ __ SafeSet(result_register(), Immediate(lit));
411
+ } else {
412
+ __ Set(result_register(), Immediate(lit));
413
+ }
414
+ }
415
+
416
+
417
+ void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
418
+ if (lit->IsSmi()) {
419
+ __ SafePush(Immediate(lit));
420
+ } else {
421
+ __ push(Immediate(lit));
422
+ }
423
+ }
424
+
425
+
426
+ void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
427
+ codegen()->PrepareForBailoutBeforeSplit(TOS_REG,
428
+ true,
429
+ true_label_,
430
+ false_label_);
431
+ ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals.
432
+ if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) {
433
+ if (false_label_ != fall_through_) __ jmp(false_label_);
434
+ } else if (lit->IsTrue() || lit->IsJSObject()) {
435
+ if (true_label_ != fall_through_) __ jmp(true_label_);
436
+ } else if (lit->IsString()) {
437
+ if (String::cast(*lit)->length() == 0) {
438
+ if (false_label_ != fall_through_) __ jmp(false_label_);
439
+ } else {
440
+ if (true_label_ != fall_through_) __ jmp(true_label_);
441
+ }
442
+ } else if (lit->IsSmi()) {
443
+ if (Smi::cast(*lit)->value() == 0) {
444
+ if (false_label_ != fall_through_) __ jmp(false_label_);
445
+ } else {
446
+ if (true_label_ != fall_through_) __ jmp(true_label_);
447
+ }
448
+ } else {
449
+ // For simplicity we always test the accumulator register.
450
+ __ mov(result_register(), lit);
451
+ codegen()->DoTest(true_label_, false_label_, fall_through_);
452
+ }
453
+ }
454
+
455
+
456
+ void FullCodeGenerator::EffectContext::DropAndPlug(int count,
457
+ Register reg) const {
458
+ ASSERT(count > 0);
459
+ __ Drop(count);
460
+ }
461
+
462
+
463
+ void FullCodeGenerator::AccumulatorValueContext::DropAndPlug(
464
+ int count,
465
+ Register reg) const {
466
+ ASSERT(count > 0);
467
+ __ Drop(count);
468
+ __ Move(result_register(), reg);
469
+ }
470
+
471
+
472
+ void FullCodeGenerator::StackValueContext::DropAndPlug(int count,
473
+ Register reg) const {
474
+ ASSERT(count > 0);
475
+ if (count > 1) __ Drop(count - 1);
476
+ __ mov(Operand(esp, 0), reg);
477
+ }
478
+
479
+
480
+ void FullCodeGenerator::TestContext::DropAndPlug(int count,
481
+ Register reg) const {
482
+ ASSERT(count > 0);
483
+ // For simplicity we always test the accumulator register.
484
+ __ Drop(count);
485
+ __ Move(result_register(), reg);
486
+ codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
487
+ codegen()->DoTest(true_label_, false_label_, fall_through_);
488
+ }
489
+
490
+
491
+ void FullCodeGenerator::EffectContext::Plug(Label* materialize_true,
492
+ Label* materialize_false) const {
493
+ ASSERT(materialize_true == materialize_false);
494
+ __ bind(materialize_true);
495
+ }
496
+
497
+
498
+ void FullCodeGenerator::AccumulatorValueContext::Plug(
499
+ Label* materialize_true,
500
+ Label* materialize_false) const {
501
+ Label done;
502
+ __ bind(materialize_true);
503
+ __ mov(result_register(), isolate()->factory()->true_value());
504
+ __ jmp(&done, Label::kNear);
505
+ __ bind(materialize_false);
506
+ __ mov(result_register(), isolate()->factory()->false_value());
507
+ __ bind(&done);
508
+ }
509
+
510
+
511
+ void FullCodeGenerator::StackValueContext::Plug(
512
+ Label* materialize_true,
513
+ Label* materialize_false) const {
514
+ Label done;
515
+ __ bind(materialize_true);
516
+ __ push(Immediate(isolate()->factory()->true_value()));
517
+ __ jmp(&done, Label::kNear);
518
+ __ bind(materialize_false);
519
+ __ push(Immediate(isolate()->factory()->false_value()));
520
+ __ bind(&done);
521
+ }
522
+
523
+
524
+ void FullCodeGenerator::TestContext::Plug(Label* materialize_true,
525
+ Label* materialize_false) const {
526
+ ASSERT(materialize_true == true_label_);
527
+ ASSERT(materialize_false == false_label_);
528
+ }
529
+
530
+
531
+ void FullCodeGenerator::EffectContext::Plug(bool flag) const {
532
+ }
533
+
534
+
535
+ void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const {
536
+ Handle<Object> value = flag
537
+ ? isolate()->factory()->true_value()
538
+ : isolate()->factory()->false_value();
539
+ __ mov(result_register(), value);
540
+ }
541
+
542
+
543
+ void FullCodeGenerator::StackValueContext::Plug(bool flag) const {
544
+ Handle<Object> value = flag
545
+ ? isolate()->factory()->true_value()
546
+ : isolate()->factory()->false_value();
547
+ __ push(Immediate(value));
548
+ }
549
+
550
+
551
+ void FullCodeGenerator::TestContext::Plug(bool flag) const {
552
+ codegen()->PrepareForBailoutBeforeSplit(TOS_REG,
553
+ true,
554
+ true_label_,
555
+ false_label_);
556
+ if (flag) {
557
+ if (true_label_ != fall_through_) __ jmp(true_label_);
558
+ } else {
559
+ if (false_label_ != fall_through_) __ jmp(false_label_);
560
+ }
561
+ }
562
+
563
+
564
+ void FullCodeGenerator::DoTest(Label* if_true,
565
+ Label* if_false,
566
+ Label* fall_through) {
567
+ ToBooleanStub stub;
568
+ __ push(result_register());
569
+ __ CallStub(&stub);
570
+ __ test(eax, Operand(eax));
571
+ // The stub returns nonzero for true.
572
+ Split(not_zero, if_true, if_false, fall_through);
573
+ }
574
+
575
+
576
+ void FullCodeGenerator::Split(Condition cc,
577
+ Label* if_true,
578
+ Label* if_false,
579
+ Label* fall_through) {
580
+ if (if_false == fall_through) {
581
+ __ j(cc, if_true);
582
+ } else if (if_true == fall_through) {
583
+ __ j(NegateCondition(cc), if_false);
584
+ } else {
585
+ __ j(cc, if_true);
586
+ __ jmp(if_false);
587
+ }
588
+ }
589
+
590
+
591
+ MemOperand FullCodeGenerator::EmitSlotSearch(Slot* slot, Register scratch) {
592
+ switch (slot->type()) {
593
+ case Slot::PARAMETER:
594
+ case Slot::LOCAL:
595
+ return Operand(ebp, SlotOffset(slot));
596
+ case Slot::CONTEXT: {
597
+ int context_chain_length =
598
+ scope()->ContextChainLength(slot->var()->scope());
599
+ __ LoadContext(scratch, context_chain_length);
600
+ return ContextOperand(scratch, slot->index());
601
+ }
602
+ case Slot::LOOKUP:
603
+ UNREACHABLE();
604
+ }
605
+ UNREACHABLE();
606
+ return Operand(eax, 0);
607
+ }
608
+
609
+
610
+ void FullCodeGenerator::Move(Register destination, Slot* source) {
611
+ MemOperand location = EmitSlotSearch(source, destination);
612
+ __ mov(destination, location);
613
+ }
614
+
615
+
616
+ void FullCodeGenerator::Move(Slot* dst,
617
+ Register src,
618
+ Register scratch1,
619
+ Register scratch2) {
620
+ ASSERT(dst->type() != Slot::LOOKUP); // Not yet implemented.
621
+ ASSERT(!scratch1.is(src) && !scratch2.is(src));
622
+ MemOperand location = EmitSlotSearch(dst, scratch1);
623
+ __ mov(location, src);
624
+ // Emit the write barrier code if the location is in the heap.
625
+ if (dst->type() == Slot::CONTEXT) {
626
+ int offset = Context::SlotOffset(dst->index());
627
+ ASSERT(!scratch1.is(esi) && !src.is(esi) && !scratch2.is(esi));
628
+ __ RecordWrite(scratch1, offset, src, scratch2);
629
+ }
630
+ }
631
+
632
+
633
+ void FullCodeGenerator::PrepareForBailoutBeforeSplit(State state,
634
+ bool should_normalize,
635
+ Label* if_true,
636
+ Label* if_false) {
637
+ // Only prepare for bailouts before splits if we're in a test
638
+ // context. Otherwise, we let the Visit function deal with the
639
+ // preparation to avoid preparing with the same AST id twice.
640
+ if (!context()->IsTest() || !info_->IsOptimizable()) return;
641
+
642
+ Label skip;
643
+ if (should_normalize) __ jmp(&skip, Label::kNear);
644
+
645
+ ForwardBailoutStack* current = forward_bailout_stack_;
646
+ while (current != NULL) {
647
+ PrepareForBailout(current->expr(), state);
648
+ current = current->parent();
649
+ }
650
+
651
+ if (should_normalize) {
652
+ __ cmp(eax, isolate()->factory()->true_value());
653
+ Split(equal, if_true, if_false, NULL);
654
+ __ bind(&skip);
655
+ }
656
+ }
657
+
658
+
659
+ void FullCodeGenerator::EmitDeclaration(Variable* variable,
660
+ Variable::Mode mode,
661
+ FunctionLiteral* function) {
662
+ Comment cmnt(masm_, "[ Declaration");
663
+ ASSERT(variable != NULL); // Must have been resolved.
664
+ Slot* slot = variable->AsSlot();
665
+ Property* prop = variable->AsProperty();
666
+
667
+ if (slot != NULL) {
668
+ switch (slot->type()) {
669
+ case Slot::PARAMETER:
670
+ case Slot::LOCAL:
671
+ if (mode == Variable::CONST) {
672
+ __ mov(Operand(ebp, SlotOffset(slot)),
673
+ Immediate(isolate()->factory()->the_hole_value()));
674
+ } else if (function != NULL) {
675
+ VisitForAccumulatorValue(function);
676
+ __ mov(Operand(ebp, SlotOffset(slot)), result_register());
677
+ }
678
+ break;
679
+
680
+ case Slot::CONTEXT:
681
+ // We bypass the general EmitSlotSearch because we know more about
682
+ // this specific context.
683
+
684
+ // The variable in the decl always resides in the current function
685
+ // context.
686
+ ASSERT_EQ(0, scope()->ContextChainLength(variable->scope()));
687
+ if (FLAG_debug_code) {
688
+ // Check that we're not inside a 'with'.
689
+ __ mov(ebx, ContextOperand(esi, Context::FCONTEXT_INDEX));
690
+ __ cmp(ebx, Operand(esi));
691
+ __ Check(equal, "Unexpected declaration in current context.");
692
+ }
693
+ if (mode == Variable::CONST) {
694
+ __ mov(ContextOperand(esi, slot->index()),
695
+ Immediate(isolate()->factory()->the_hole_value()));
696
+ // No write barrier since the hole value is in old space.
697
+ } else if (function != NULL) {
698
+ VisitForAccumulatorValue(function);
699
+ __ mov(ContextOperand(esi, slot->index()), result_register());
700
+ int offset = Context::SlotOffset(slot->index());
701
+ __ mov(ebx, esi);
702
+ __ RecordWrite(ebx, offset, result_register(), ecx);
703
+ }
704
+ break;
705
+
706
+ case Slot::LOOKUP: {
707
+ __ push(esi);
708
+ __ push(Immediate(variable->name()));
709
+ // Declaration nodes are always introduced in one of two modes.
710
+ ASSERT(mode == Variable::VAR || mode == Variable::CONST);
711
+ PropertyAttributes attr = (mode == Variable::VAR) ? NONE : READ_ONLY;
712
+ __ push(Immediate(Smi::FromInt(attr)));
713
+ // Push initial value, if any.
714
+ // Note: For variables we must not push an initial value (such as
715
+ // 'undefined') because we may have a (legal) redeclaration and we
716
+ // must not destroy the current value.
717
+ if (mode == Variable::CONST) {
718
+ __ push(Immediate(isolate()->factory()->the_hole_value()));
719
+ } else if (function != NULL) {
720
+ VisitForStackValue(function);
721
+ } else {
722
+ __ push(Immediate(Smi::FromInt(0))); // No initial value!
723
+ }
724
+ __ CallRuntime(Runtime::kDeclareContextSlot, 4);
725
+ break;
726
+ }
727
+ }
728
+
729
+ } else if (prop != NULL) {
730
+ // A const declaration aliasing a parameter is an illegal redeclaration.
731
+ ASSERT(mode != Variable::CONST);
732
+ if (function != NULL) {
733
+ // We are declaring a function that rewrites to a property.
734
+ // Use (keyed) IC to set the initial value. We cannot visit the
735
+ // rewrite because it's shared and we risk recording duplicate AST
736
+ // IDs for bailouts from optimized code.
737
+ ASSERT(prop->obj()->AsVariableProxy() != NULL);
738
+ { AccumulatorValueContext for_object(this);
739
+ EmitVariableLoad(prop->obj()->AsVariableProxy()->var());
740
+ }
741
+
742
+ __ push(eax);
743
+ VisitForAccumulatorValue(function);
744
+ __ pop(edx);
745
+
746
+ ASSERT(prop->key()->AsLiteral() != NULL &&
747
+ prop->key()->AsLiteral()->handle()->IsSmi());
748
+ __ SafeSet(ecx, Immediate(prop->key()->AsLiteral()->handle()));
749
+
750
+ Handle<Code> ic = is_strict_mode()
751
+ ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict()
752
+ : isolate()->builtins()->KeyedStoreIC_Initialize();
753
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber);
754
+ }
755
+ }
756
+ }
757
+
758
+
759
+ void FullCodeGenerator::VisitDeclaration(Declaration* decl) {
760
+ EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun());
761
+ }
762
+
763
+
764
+ void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
765
+ // Call the runtime to declare the globals.
766
+ __ push(esi); // The context is the first argument.
767
+ __ push(Immediate(pairs));
768
+ __ push(Immediate(Smi::FromInt(is_eval() ? 1 : 0)));
769
+ __ push(Immediate(Smi::FromInt(strict_mode_flag())));
770
+ __ CallRuntime(Runtime::kDeclareGlobals, 4);
771
+ // Return value is ignored.
772
+ }
773
+
774
+
775
+ void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
776
+ Comment cmnt(masm_, "[ SwitchStatement");
777
+ Breakable nested_statement(this, stmt);
778
+ SetStatementPosition(stmt);
779
+
780
+ // Keep the switch value on the stack until a case matches.
781
+ VisitForStackValue(stmt->tag());
782
+ PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
783
+
784
+ ZoneList<CaseClause*>* clauses = stmt->cases();
785
+ CaseClause* default_clause = NULL; // Can occur anywhere in the list.
786
+
787
+ Label next_test; // Recycled for each test.
788
+ // Compile all the tests with branches to their bodies.
789
+ for (int i = 0; i < clauses->length(); i++) {
790
+ CaseClause* clause = clauses->at(i);
791
+ clause->body_target()->Unuse();
792
+
793
+ // The default is not a test, but remember it as final fall through.
794
+ if (clause->is_default()) {
795
+ default_clause = clause;
796
+ continue;
797
+ }
798
+
799
+ Comment cmnt(masm_, "[ Case comparison");
800
+ __ bind(&next_test);
801
+ next_test.Unuse();
802
+
803
+ // Compile the label expression.
804
+ VisitForAccumulatorValue(clause->label());
805
+
806
+ // Perform the comparison as if via '==='.
807
+ __ mov(edx, Operand(esp, 0)); // Switch value.
808
+ bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT);
809
+ JumpPatchSite patch_site(masm_);
810
+ if (inline_smi_code) {
811
+ Label slow_case;
812
+ __ mov(ecx, edx);
813
+ __ or_(ecx, Operand(eax));
814
+ patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear);
815
+
816
+ __ cmp(edx, Operand(eax));
817
+ __ j(not_equal, &next_test);
818
+ __ Drop(1); // Switch value is no longer needed.
819
+ __ jmp(clause->body_target());
820
+ __ bind(&slow_case);
821
+ }
822
+
823
+ // Record position before stub call for type feedback.
824
+ SetSourcePosition(clause->position());
825
+ Handle<Code> ic = CompareIC::GetUninitialized(Token::EQ_STRICT);
826
+ EmitCallIC(ic, &patch_site, clause->CompareId());
827
+ __ test(eax, Operand(eax));
828
+ __ j(not_equal, &next_test);
829
+ __ Drop(1); // Switch value is no longer needed.
830
+ __ jmp(clause->body_target());
831
+ }
832
+
833
+ // Discard the test value and jump to the default if present, otherwise to
834
+ // the end of the statement.
835
+ __ bind(&next_test);
836
+ __ Drop(1); // Switch value is no longer needed.
837
+ if (default_clause == NULL) {
838
+ __ jmp(nested_statement.break_target());
839
+ } else {
840
+ __ jmp(default_clause->body_target());
841
+ }
842
+
843
+ // Compile all the case bodies.
844
+ for (int i = 0; i < clauses->length(); i++) {
845
+ Comment cmnt(masm_, "[ Case body");
846
+ CaseClause* clause = clauses->at(i);
847
+ __ bind(clause->body_target());
848
+ PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS);
849
+ VisitStatements(clause->statements());
850
+ }
851
+
852
+ __ bind(nested_statement.break_target());
853
+ PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
854
+ }
855
+
856
+
857
+ void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
858
+ Comment cmnt(masm_, "[ ForInStatement");
859
+ SetStatementPosition(stmt);
860
+
861
+ Label loop, exit;
862
+ ForIn loop_statement(this, stmt);
863
+ increment_loop_depth();
864
+
865
+ // Get the object to enumerate over. Both SpiderMonkey and JSC
866
+ // ignore null and undefined in contrast to the specification; see
867
+ // ECMA-262 section 12.6.4.
868
+ VisitForAccumulatorValue(stmt->enumerable());
869
+ __ cmp(eax, isolate()->factory()->undefined_value());
870
+ __ j(equal, &exit);
871
+ __ cmp(eax, isolate()->factory()->null_value());
872
+ __ j(equal, &exit);
873
+
874
+ // Convert the object to a JS object.
875
+ Label convert, done_convert;
876
+ __ test(eax, Immediate(kSmiTagMask));
877
+ __ j(zero, &convert, Label::kNear);
878
+ __ CmpObjectType(eax, FIRST_JS_OBJECT_TYPE, ecx);
879
+ __ j(above_equal, &done_convert, Label::kNear);
880
+ __ bind(&convert);
881
+ __ push(eax);
882
+ __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
883
+ __ bind(&done_convert);
884
+ __ push(eax);
885
+
886
+ // Check cache validity in generated code. This is a fast case for
887
+ // the JSObject::IsSimpleEnum cache validity checks. If we cannot
888
+ // guarantee cache validity, call the runtime system to check cache
889
+ // validity or get the property names in a fixed array.
890
+ Label next, call_runtime;
891
+ __ mov(ecx, eax);
892
+ __ bind(&next);
893
+
894
+ // Check that there are no elements. Register ecx contains the
895
+ // current JS object we've reached through the prototype chain.
896
+ __ cmp(FieldOperand(ecx, JSObject::kElementsOffset),
897
+ isolate()->factory()->empty_fixed_array());
898
+ __ j(not_equal, &call_runtime);
899
+
900
+ // Check that instance descriptors are not empty so that we can
901
+ // check for an enum cache. Leave the map in ebx for the subsequent
902
+ // prototype load.
903
+ __ mov(ebx, FieldOperand(ecx, HeapObject::kMapOffset));
904
+ __ mov(edx, FieldOperand(ebx, Map::kInstanceDescriptorsOrBitField3Offset));
905
+ __ JumpIfSmi(edx, &call_runtime);
906
+
907
+ // Check that there is an enum cache in the non-empty instance
908
+ // descriptors (edx). This is the case if the next enumeration
909
+ // index field does not contain a smi.
910
+ __ mov(edx, FieldOperand(edx, DescriptorArray::kEnumerationIndexOffset));
911
+ __ test(edx, Immediate(kSmiTagMask));
912
+ __ j(zero, &call_runtime);
913
+
914
+ // For all objects but the receiver, check that the cache is empty.
915
+ Label check_prototype;
916
+ __ cmp(ecx, Operand(eax));
917
+ __ j(equal, &check_prototype, Label::kNear);
918
+ __ mov(edx, FieldOperand(edx, DescriptorArray::kEnumCacheBridgeCacheOffset));
919
+ __ cmp(edx, isolate()->factory()->empty_fixed_array());
920
+ __ j(not_equal, &call_runtime);
921
+
922
+ // Load the prototype from the map and loop if non-null.
923
+ __ bind(&check_prototype);
924
+ __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset));
925
+ __ cmp(ecx, isolate()->factory()->null_value());
926
+ __ j(not_equal, &next);
927
+
928
+ // The enum cache is valid. Load the map of the object being
929
+ // iterated over and use the cache for the iteration.
930
+ Label use_cache;
931
+ __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset));
932
+ __ jmp(&use_cache, Label::kNear);
933
+
934
+ // Get the set of properties to enumerate.
935
+ __ bind(&call_runtime);
936
+ __ push(eax); // Duplicate the enumerable object on the stack.
937
+ __ CallRuntime(Runtime::kGetPropertyNamesFast, 1);
938
+
939
+ // If we got a map from the runtime call, we can do a fast
940
+ // modification check. Otherwise, we got a fixed array, and we have
941
+ // to do a slow check.
942
+ Label fixed_array;
943
+ __ cmp(FieldOperand(eax, HeapObject::kMapOffset),
944
+ isolate()->factory()->meta_map());
945
+ __ j(not_equal, &fixed_array, Label::kNear);
946
+
947
+ // We got a map in register eax. Get the enumeration cache from it.
948
+ __ bind(&use_cache);
949
+ __ LoadInstanceDescriptors(eax, ecx);
950
+ __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumerationIndexOffset));
951
+ __ mov(edx, FieldOperand(ecx, DescriptorArray::kEnumCacheBridgeCacheOffset));
952
+
953
+ // Setup the four remaining stack slots.
954
+ __ push(eax); // Map.
955
+ __ push(edx); // Enumeration cache.
956
+ __ mov(eax, FieldOperand(edx, FixedArray::kLengthOffset));
957
+ __ push(eax); // Enumeration cache length (as smi).
958
+ __ push(Immediate(Smi::FromInt(0))); // Initial index.
959
+ __ jmp(&loop);
960
+
961
+ // We got a fixed array in register eax. Iterate through that.
962
+ __ bind(&fixed_array);
963
+ __ push(Immediate(Smi::FromInt(0))); // Map (0) - force slow check.
964
+ __ push(eax);
965
+ __ mov(eax, FieldOperand(eax, FixedArray::kLengthOffset));
966
+ __ push(eax); // Fixed array length (as smi).
967
+ __ push(Immediate(Smi::FromInt(0))); // Initial index.
968
+
969
+ // Generate code for doing the condition check.
970
+ __ bind(&loop);
971
+ __ mov(eax, Operand(esp, 0 * kPointerSize)); // Get the current index.
972
+ __ cmp(eax, Operand(esp, 1 * kPointerSize)); // Compare to the array length.
973
+ __ j(above_equal, loop_statement.break_target());
974
+
975
+ // Get the current entry of the array into register ebx.
976
+ __ mov(ebx, Operand(esp, 2 * kPointerSize));
977
+ __ mov(ebx, FieldOperand(ebx, eax, times_2, FixedArray::kHeaderSize));
978
+
979
+ // Get the expected map from the stack or a zero map in the
980
+ // permanent slow case into register edx.
981
+ __ mov(edx, Operand(esp, 3 * kPointerSize));
982
+
983
+ // Check if the expected map still matches that of the enumerable.
984
+ // If not, we have to filter the key.
985
+ Label update_each;
986
+ __ mov(ecx, Operand(esp, 4 * kPointerSize));
987
+ __ cmp(edx, FieldOperand(ecx, HeapObject::kMapOffset));
988
+ __ j(equal, &update_each, Label::kNear);
989
+
990
+ // Convert the entry to a string or null if it isn't a property
991
+ // anymore. If the property has been removed while iterating, we
992
+ // just skip it.
993
+ __ push(ecx); // Enumerable.
994
+ __ push(ebx); // Current entry.
995
+ __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION);
996
+ __ test(eax, Operand(eax));
997
+ __ j(equal, loop_statement.continue_target());
998
+ __ mov(ebx, Operand(eax));
999
+
1000
+ // Update the 'each' property or variable from the possibly filtered
1001
+ // entry in register ebx.
1002
+ __ bind(&update_each);
1003
+ __ mov(result_register(), ebx);
1004
+ // Perform the assignment as if via '='.
1005
+ { EffectContext context(this);
1006
+ EmitAssignment(stmt->each(), stmt->AssignmentId());
1007
+ }
1008
+
1009
+ // Generate code for the body of the loop.
1010
+ Visit(stmt->body());
1011
+
1012
+ // Generate code for going to the next element by incrementing the
1013
+ // index (smi) stored on top of the stack.
1014
+ __ bind(loop_statement.continue_target());
1015
+ __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1)));
1016
+
1017
+ EmitStackCheck(stmt);
1018
+ __ jmp(&loop);
1019
+
1020
+ // Remove the pointers stored on the stack.
1021
+ __ bind(loop_statement.break_target());
1022
+ __ add(Operand(esp), Immediate(5 * kPointerSize));
1023
+
1024
+ // Exit and decrement the loop depth.
1025
+ __ bind(&exit);
1026
+ decrement_loop_depth();
1027
+ }
1028
+
1029
+
1030
+ void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info,
1031
+ bool pretenure) {
1032
+ // Use the fast case closure allocation code that allocates in new
1033
+ // space for nested functions that don't need literals cloning. If
1034
+ // we're running with the --always-opt or the --prepare-always-opt
1035
+ // flag, we need to use the runtime function so that the new function
1036
+ // we are creating here gets a chance to have its code optimized and
1037
+ // doesn't just get a copy of the existing unoptimized code.
1038
+ if (!FLAG_always_opt &&
1039
+ !FLAG_prepare_always_opt &&
1040
+ !pretenure &&
1041
+ scope()->is_function_scope() &&
1042
+ info->num_literals() == 0) {
1043
+ FastNewClosureStub stub(info->strict_mode() ? kStrictMode : kNonStrictMode);
1044
+ __ push(Immediate(info));
1045
+ __ CallStub(&stub);
1046
+ } else {
1047
+ __ push(esi);
1048
+ __ push(Immediate(info));
1049
+ __ push(Immediate(pretenure
1050
+ ? isolate()->factory()->true_value()
1051
+ : isolate()->factory()->false_value()));
1052
+ __ CallRuntime(Runtime::kNewClosure, 3);
1053
+ }
1054
+ context()->Plug(eax);
1055
+ }
1056
+
1057
+
1058
+ void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) {
1059
+ Comment cmnt(masm_, "[ VariableProxy");
1060
+ EmitVariableLoad(expr->var());
1061
+ }
1062
+
1063
+
1064
+ void FullCodeGenerator::EmitLoadGlobalSlotCheckExtensions(
1065
+ Slot* slot,
1066
+ TypeofState typeof_state,
1067
+ Label* slow) {
1068
+ Register context = esi;
1069
+ Register temp = edx;
1070
+
1071
+ Scope* s = scope();
1072
+ while (s != NULL) {
1073
+ if (s->num_heap_slots() > 0) {
1074
+ if (s->calls_eval()) {
1075
+ // Check that extension is NULL.
1076
+ __ cmp(ContextOperand(context, Context::EXTENSION_INDEX),
1077
+ Immediate(0));
1078
+ __ j(not_equal, slow);
1079
+ }
1080
+ // Load next context in chain.
1081
+ __ mov(temp, ContextOperand(context, Context::CLOSURE_INDEX));
1082
+ __ mov(temp, FieldOperand(temp, JSFunction::kContextOffset));
1083
+ // Walk the rest of the chain without clobbering esi.
1084
+ context = temp;
1085
+ }
1086
+ // If no outer scope calls eval, we do not need to check more
1087
+ // context extensions. If we have reached an eval scope, we check
1088
+ // all extensions from this point.
1089
+ if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break;
1090
+ s = s->outer_scope();
1091
+ }
1092
+
1093
+ if (s != NULL && s->is_eval_scope()) {
1094
+ // Loop up the context chain. There is no frame effect so it is
1095
+ // safe to use raw labels here.
1096
+ Label next, fast;
1097
+ if (!context.is(temp)) {
1098
+ __ mov(temp, context);
1099
+ }
1100
+ __ bind(&next);
1101
+ // Terminate at global context.
1102
+ __ cmp(FieldOperand(temp, HeapObject::kMapOffset),
1103
+ Immediate(isolate()->factory()->global_context_map()));
1104
+ __ j(equal, &fast, Label::kNear);
1105
+ // Check that extension is NULL.
1106
+ __ cmp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0));
1107
+ __ j(not_equal, slow);
1108
+ // Load next context in chain.
1109
+ __ mov(temp, ContextOperand(temp, Context::CLOSURE_INDEX));
1110
+ __ mov(temp, FieldOperand(temp, JSFunction::kContextOffset));
1111
+ __ jmp(&next);
1112
+ __ bind(&fast);
1113
+ }
1114
+
1115
+ // All extension objects were empty and it is safe to use a global
1116
+ // load IC call.
1117
+ __ mov(eax, GlobalObjectOperand());
1118
+ __ mov(ecx, slot->var()->name());
1119
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
1120
+ RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF)
1121
+ ? RelocInfo::CODE_TARGET
1122
+ : RelocInfo::CODE_TARGET_CONTEXT;
1123
+ EmitCallIC(ic, mode, AstNode::kNoNumber);
1124
+ }
1125
+
1126
+
1127
+ MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(
1128
+ Slot* slot,
1129
+ Label* slow) {
1130
+ ASSERT(slot->type() == Slot::CONTEXT);
1131
+ Register context = esi;
1132
+ Register temp = ebx;
1133
+
1134
+ for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) {
1135
+ if (s->num_heap_slots() > 0) {
1136
+ if (s->calls_eval()) {
1137
+ // Check that extension is NULL.
1138
+ __ cmp(ContextOperand(context, Context::EXTENSION_INDEX),
1139
+ Immediate(0));
1140
+ __ j(not_equal, slow);
1141
+ }
1142
+ __ mov(temp, ContextOperand(context, Context::CLOSURE_INDEX));
1143
+ __ mov(temp, FieldOperand(temp, JSFunction::kContextOffset));
1144
+ // Walk the rest of the chain without clobbering esi.
1145
+ context = temp;
1146
+ }
1147
+ }
1148
+ // Check that last extension is NULL.
1149
+ __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0));
1150
+ __ j(not_equal, slow);
1151
+
1152
+ // This function is used only for loads, not stores, so it's safe to
1153
+ // return an esi-based operand (the write barrier cannot be allowed to
1154
+ // destroy the esi register).
1155
+ return ContextOperand(context, slot->index());
1156
+ }
1157
+
1158
+
1159
+ void FullCodeGenerator::EmitDynamicLoadFromSlotFastCase(
1160
+ Slot* slot,
1161
+ TypeofState typeof_state,
1162
+ Label* slow,
1163
+ Label* done) {
1164
+ // Generate fast-case code for variables that might be shadowed by
1165
+ // eval-introduced variables. Eval is used a lot without
1166
+ // introducing variables. In those cases, we do not want to
1167
+ // perform a runtime call for all variables in the scope
1168
+ // containing the eval.
1169
+ if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) {
1170
+ EmitLoadGlobalSlotCheckExtensions(slot, typeof_state, slow);
1171
+ __ jmp(done);
1172
+ } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) {
1173
+ Slot* potential_slot = slot->var()->local_if_not_shadowed()->AsSlot();
1174
+ Expression* rewrite = slot->var()->local_if_not_shadowed()->rewrite();
1175
+ if (potential_slot != NULL) {
1176
+ // Generate fast case for locals that rewrite to slots.
1177
+ __ mov(eax,
1178
+ ContextSlotOperandCheckExtensions(potential_slot, slow));
1179
+ if (potential_slot->var()->mode() == Variable::CONST) {
1180
+ __ cmp(eax, isolate()->factory()->the_hole_value());
1181
+ __ j(not_equal, done);
1182
+ __ mov(eax, isolate()->factory()->undefined_value());
1183
+ }
1184
+ __ jmp(done);
1185
+ } else if (rewrite != NULL) {
1186
+ // Generate fast case for calls of an argument function.
1187
+ Property* property = rewrite->AsProperty();
1188
+ if (property != NULL) {
1189
+ VariableProxy* obj_proxy = property->obj()->AsVariableProxy();
1190
+ Literal* key_literal = property->key()->AsLiteral();
1191
+ if (obj_proxy != NULL &&
1192
+ key_literal != NULL &&
1193
+ obj_proxy->IsArguments() &&
1194
+ key_literal->handle()->IsSmi()) {
1195
+ // Load arguments object if there are no eval-introduced
1196
+ // variables. Then load the argument from the arguments
1197
+ // object using keyed load.
1198
+ __ mov(edx,
1199
+ ContextSlotOperandCheckExtensions(obj_proxy->var()->AsSlot(),
1200
+ slow));
1201
+ __ SafeSet(eax, Immediate(key_literal->handle()));
1202
+ Handle<Code> ic =
1203
+ isolate()->builtins()->KeyedLoadIC_Initialize();
1204
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(property));
1205
+ __ jmp(done);
1206
+ }
1207
+ }
1208
+ }
1209
+ }
1210
+ }
1211
+
1212
+
1213
+ void FullCodeGenerator::EmitVariableLoad(Variable* var) {
1214
+ // Four cases: non-this global variables, lookup slots, all other
1215
+ // types of slots, and parameters that rewrite to explicit property
1216
+ // accesses on the arguments object.
1217
+ Slot* slot = var->AsSlot();
1218
+ Property* property = var->AsProperty();
1219
+
1220
+ if (var->is_global() && !var->is_this()) {
1221
+ Comment cmnt(masm_, "Global variable");
1222
+ // Use inline caching. Variable name is passed in ecx and the global
1223
+ // object on the stack.
1224
+ __ mov(eax, GlobalObjectOperand());
1225
+ __ mov(ecx, var->name());
1226
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
1227
+ EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT, AstNode::kNoNumber);
1228
+ context()->Plug(eax);
1229
+
1230
+ } else if (slot != NULL && slot->type() == Slot::LOOKUP) {
1231
+ Label done, slow;
1232
+
1233
+ // Generate code for loading from variables potentially shadowed
1234
+ // by eval-introduced variables.
1235
+ EmitDynamicLoadFromSlotFastCase(slot, NOT_INSIDE_TYPEOF, &slow, &done);
1236
+
1237
+ __ bind(&slow);
1238
+ Comment cmnt(masm_, "Lookup slot");
1239
+ __ push(esi); // Context.
1240
+ __ push(Immediate(var->name()));
1241
+ __ CallRuntime(Runtime::kLoadContextSlot, 2);
1242
+ __ bind(&done);
1243
+
1244
+ context()->Plug(eax);
1245
+
1246
+ } else if (slot != NULL) {
1247
+ Comment cmnt(masm_, (slot->type() == Slot::CONTEXT)
1248
+ ? "Context slot"
1249
+ : "Stack slot");
1250
+ if (var->mode() == Variable::CONST) {
1251
+ // Constants may be the hole value if they have not been initialized.
1252
+ // Unhole them.
1253
+ Label done;
1254
+ MemOperand slot_operand = EmitSlotSearch(slot, eax);
1255
+ __ mov(eax, slot_operand);
1256
+ __ cmp(eax, isolate()->factory()->the_hole_value());
1257
+ __ j(not_equal, &done, Label::kNear);
1258
+ __ mov(eax, isolate()->factory()->undefined_value());
1259
+ __ bind(&done);
1260
+ context()->Plug(eax);
1261
+ } else {
1262
+ context()->Plug(slot);
1263
+ }
1264
+
1265
+ } else {
1266
+ Comment cmnt(masm_, "Rewritten parameter");
1267
+ ASSERT_NOT_NULL(property);
1268
+ // Rewritten parameter accesses are of the form "slot[literal]".
1269
+
1270
+ // Assert that the object is in a slot.
1271
+ Variable* object_var = property->obj()->AsVariableProxy()->AsVariable();
1272
+ ASSERT_NOT_NULL(object_var);
1273
+ Slot* object_slot = object_var->AsSlot();
1274
+ ASSERT_NOT_NULL(object_slot);
1275
+
1276
+ // Load the object.
1277
+ MemOperand object_loc = EmitSlotSearch(object_slot, eax);
1278
+ __ mov(edx, object_loc);
1279
+
1280
+ // Assert that the key is a smi.
1281
+ Literal* key_literal = property->key()->AsLiteral();
1282
+ ASSERT_NOT_NULL(key_literal);
1283
+ ASSERT(key_literal->handle()->IsSmi());
1284
+
1285
+ // Load the key.
1286
+ __ SafeSet(eax, Immediate(key_literal->handle()));
1287
+
1288
+ // Do a keyed property load.
1289
+ Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize();
1290
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(property));
1291
+
1292
+ // Drop key and object left on the stack by IC.
1293
+ context()->Plug(eax);
1294
+ }
1295
+ }
1296
+
1297
+
1298
+ void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
1299
+ Comment cmnt(masm_, "[ RegExpLiteral");
1300
+ Label materialized;
1301
+ // Registers will be used as follows:
1302
+ // edi = JS function.
1303
+ // ecx = literals array.
1304
+ // ebx = regexp literal.
1305
+ // eax = regexp literal clone.
1306
+ __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
1307
+ __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset));
1308
+ int literal_offset =
1309
+ FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
1310
+ __ mov(ebx, FieldOperand(ecx, literal_offset));
1311
+ __ cmp(ebx, isolate()->factory()->undefined_value());
1312
+ __ j(not_equal, &materialized, Label::kNear);
1313
+
1314
+ // Create regexp literal using runtime function
1315
+ // Result will be in eax.
1316
+ __ push(ecx);
1317
+ __ push(Immediate(Smi::FromInt(expr->literal_index())));
1318
+ __ push(Immediate(expr->pattern()));
1319
+ __ push(Immediate(expr->flags()));
1320
+ __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4);
1321
+ __ mov(ebx, eax);
1322
+
1323
+ __ bind(&materialized);
1324
+ int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
1325
+ Label allocated, runtime_allocate;
1326
+ __ AllocateInNewSpace(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT);
1327
+ __ jmp(&allocated);
1328
+
1329
+ __ bind(&runtime_allocate);
1330
+ __ push(ebx);
1331
+ __ push(Immediate(Smi::FromInt(size)));
1332
+ __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
1333
+ __ pop(ebx);
1334
+
1335
+ __ bind(&allocated);
1336
+ // Copy the content into the newly allocated memory.
1337
+ // (Unroll copy loop once for better throughput).
1338
+ for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) {
1339
+ __ mov(edx, FieldOperand(ebx, i));
1340
+ __ mov(ecx, FieldOperand(ebx, i + kPointerSize));
1341
+ __ mov(FieldOperand(eax, i), edx);
1342
+ __ mov(FieldOperand(eax, i + kPointerSize), ecx);
1343
+ }
1344
+ if ((size % (2 * kPointerSize)) != 0) {
1345
+ __ mov(edx, FieldOperand(ebx, size - kPointerSize));
1346
+ __ mov(FieldOperand(eax, size - kPointerSize), edx);
1347
+ }
1348
+ context()->Plug(eax);
1349
+ }
1350
+
1351
+
1352
+ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
1353
+ Comment cmnt(masm_, "[ ObjectLiteral");
1354
+ __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
1355
+ __ push(FieldOperand(edi, JSFunction::kLiteralsOffset));
1356
+ __ push(Immediate(Smi::FromInt(expr->literal_index())));
1357
+ __ push(Immediate(expr->constant_properties()));
1358
+ int flags = expr->fast_elements()
1359
+ ? ObjectLiteral::kFastElements
1360
+ : ObjectLiteral::kNoFlags;
1361
+ flags |= expr->has_function()
1362
+ ? ObjectLiteral::kHasFunction
1363
+ : ObjectLiteral::kNoFlags;
1364
+ __ push(Immediate(Smi::FromInt(flags)));
1365
+ if (expr->depth() > 1) {
1366
+ __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
1367
+ } else {
1368
+ __ CallRuntime(Runtime::kCreateObjectLiteralShallow, 4);
1369
+ }
1370
+
1371
+ // If result_saved is true the result is on top of the stack. If
1372
+ // result_saved is false the result is in eax.
1373
+ bool result_saved = false;
1374
+
1375
+ // Mark all computed expressions that are bound to a key that
1376
+ // is shadowed by a later occurrence of the same key. For the
1377
+ // marked expressions, no store code is emitted.
1378
+ expr->CalculateEmitStore();
1379
+
1380
+ for (int i = 0; i < expr->properties()->length(); i++) {
1381
+ ObjectLiteral::Property* property = expr->properties()->at(i);
1382
+ if (property->IsCompileTimeValue()) continue;
1383
+
1384
+ Literal* key = property->key();
1385
+ Expression* value = property->value();
1386
+ if (!result_saved) {
1387
+ __ push(eax); // Save result on the stack
1388
+ result_saved = true;
1389
+ }
1390
+ switch (property->kind()) {
1391
+ case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1392
+ ASSERT(!CompileTimeValue::IsCompileTimeValue(value));
1393
+ // Fall through.
1394
+ case ObjectLiteral::Property::COMPUTED:
1395
+ if (key->handle()->IsSymbol()) {
1396
+ if (property->emit_store()) {
1397
+ VisitForAccumulatorValue(value);
1398
+ __ mov(ecx, Immediate(key->handle()));
1399
+ __ mov(edx, Operand(esp, 0));
1400
+ Handle<Code> ic = is_strict_mode()
1401
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
1402
+ : isolate()->builtins()->StoreIC_Initialize();
1403
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, key->id());
1404
+ PrepareForBailoutForId(key->id(), NO_REGISTERS);
1405
+ } else {
1406
+ VisitForEffect(value);
1407
+ }
1408
+ break;
1409
+ }
1410
+ // Fall through.
1411
+ case ObjectLiteral::Property::PROTOTYPE:
1412
+ __ push(Operand(esp, 0)); // Duplicate receiver.
1413
+ VisitForStackValue(key);
1414
+ VisitForStackValue(value);
1415
+ if (property->emit_store()) {
1416
+ __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes
1417
+ __ CallRuntime(Runtime::kSetProperty, 4);
1418
+ } else {
1419
+ __ Drop(3);
1420
+ }
1421
+ break;
1422
+ case ObjectLiteral::Property::SETTER:
1423
+ case ObjectLiteral::Property::GETTER:
1424
+ __ push(Operand(esp, 0)); // Duplicate receiver.
1425
+ VisitForStackValue(key);
1426
+ __ push(Immediate(property->kind() == ObjectLiteral::Property::SETTER ?
1427
+ Smi::FromInt(1) :
1428
+ Smi::FromInt(0)));
1429
+ VisitForStackValue(value);
1430
+ __ CallRuntime(Runtime::kDefineAccessor, 4);
1431
+ break;
1432
+ default: UNREACHABLE();
1433
+ }
1434
+ }
1435
+
1436
+ if (expr->has_function()) {
1437
+ ASSERT(result_saved);
1438
+ __ push(Operand(esp, 0));
1439
+ __ CallRuntime(Runtime::kToFastProperties, 1);
1440
+ }
1441
+
1442
+ if (result_saved) {
1443
+ context()->PlugTOS();
1444
+ } else {
1445
+ context()->Plug(eax);
1446
+ }
1447
+ }
1448
+
1449
+
1450
+ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1451
+ Comment cmnt(masm_, "[ ArrayLiteral");
1452
+
1453
+ ZoneList<Expression*>* subexprs = expr->values();
1454
+ int length = subexprs->length();
1455
+
1456
+ __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
1457
+ __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset));
1458
+ __ push(Immediate(Smi::FromInt(expr->literal_index())));
1459
+ __ push(Immediate(expr->constant_elements()));
1460
+ if (expr->constant_elements()->map() ==
1461
+ isolate()->heap()->fixed_cow_array_map()) {
1462
+ ASSERT(expr->depth() == 1);
1463
+ FastCloneShallowArrayStub stub(
1464
+ FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length);
1465
+ __ CallStub(&stub);
1466
+ __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1);
1467
+ } else if (expr->depth() > 1) {
1468
+ __ CallRuntime(Runtime::kCreateArrayLiteral, 3);
1469
+ } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) {
1470
+ __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3);
1471
+ } else {
1472
+ FastCloneShallowArrayStub stub(
1473
+ FastCloneShallowArrayStub::CLONE_ELEMENTS, length);
1474
+ __ CallStub(&stub);
1475
+ }
1476
+
1477
+ bool result_saved = false; // Is the result saved to the stack?
1478
+
1479
+ // Emit code to evaluate all the non-constant subexpressions and to store
1480
+ // them into the newly cloned array.
1481
+ for (int i = 0; i < length; i++) {
1482
+ Expression* subexpr = subexprs->at(i);
1483
+ // If the subexpression is a literal or a simple materialized literal it
1484
+ // is already set in the cloned array.
1485
+ if (subexpr->AsLiteral() != NULL ||
1486
+ CompileTimeValue::IsCompileTimeValue(subexpr)) {
1487
+ continue;
1488
+ }
1489
+
1490
+ if (!result_saved) {
1491
+ __ push(eax);
1492
+ result_saved = true;
1493
+ }
1494
+ VisitForAccumulatorValue(subexpr);
1495
+
1496
+ // Store the subexpression value in the array's elements.
1497
+ __ mov(ebx, Operand(esp, 0)); // Copy of array literal.
1498
+ __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset));
1499
+ int offset = FixedArray::kHeaderSize + (i * kPointerSize);
1500
+ __ mov(FieldOperand(ebx, offset), result_register());
1501
+
1502
+ // Update the write barrier for the array store.
1503
+ __ RecordWrite(ebx, offset, result_register(), ecx);
1504
+
1505
+ PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);
1506
+ }
1507
+
1508
+ if (result_saved) {
1509
+ context()->PlugTOS();
1510
+ } else {
1511
+ context()->Plug(eax);
1512
+ }
1513
+ }
1514
+
1515
+
1516
+ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
1517
+ Comment cmnt(masm_, "[ Assignment");
1518
+ // Invalid left-hand sides are rewritten to have a 'throw ReferenceError'
1519
+ // on the left-hand side.
1520
+ if (!expr->target()->IsValidLeftHandSide()) {
1521
+ VisitForEffect(expr->target());
1522
+ return;
1523
+ }
1524
+
1525
+ // Left-hand side can only be a property, a global or a (parameter or local)
1526
+ // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY.
1527
+ enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
1528
+ LhsKind assign_type = VARIABLE;
1529
+ Property* property = expr->target()->AsProperty();
1530
+ if (property != NULL) {
1531
+ assign_type = (property->key()->IsPropertyName())
1532
+ ? NAMED_PROPERTY
1533
+ : KEYED_PROPERTY;
1534
+ }
1535
+
1536
+ // Evaluate LHS expression.
1537
+ switch (assign_type) {
1538
+ case VARIABLE:
1539
+ // Nothing to do here.
1540
+ break;
1541
+ case NAMED_PROPERTY:
1542
+ if (expr->is_compound()) {
1543
+ // We need the receiver both on the stack and in the accumulator.
1544
+ VisitForAccumulatorValue(property->obj());
1545
+ __ push(result_register());
1546
+ } else {
1547
+ VisitForStackValue(property->obj());
1548
+ }
1549
+ break;
1550
+ case KEYED_PROPERTY: {
1551
+ if (expr->is_compound()) {
1552
+ if (property->is_arguments_access()) {
1553
+ VariableProxy* obj_proxy = property->obj()->AsVariableProxy();
1554
+ MemOperand slot_operand =
1555
+ EmitSlotSearch(obj_proxy->var()->AsSlot(), ecx);
1556
+ __ push(slot_operand);
1557
+ __ SafeSet(eax, Immediate(property->key()->AsLiteral()->handle()));
1558
+ } else {
1559
+ VisitForStackValue(property->obj());
1560
+ VisitForAccumulatorValue(property->key());
1561
+ }
1562
+ __ mov(edx, Operand(esp, 0));
1563
+ __ push(eax);
1564
+ } else {
1565
+ if (property->is_arguments_access()) {
1566
+ VariableProxy* obj_proxy = property->obj()->AsVariableProxy();
1567
+ MemOperand slot_operand =
1568
+ EmitSlotSearch(obj_proxy->var()->AsSlot(), ecx);
1569
+ __ push(slot_operand);
1570
+ __ SafePush(Immediate(property->key()->AsLiteral()->handle()));
1571
+ } else {
1572
+ VisitForStackValue(property->obj());
1573
+ VisitForStackValue(property->key());
1574
+ }
1575
+ }
1576
+ break;
1577
+ }
1578
+ }
1579
+
1580
+ // For compound assignments we need another deoptimization point after the
1581
+ // variable/property load.
1582
+ if (expr->is_compound()) {
1583
+ { AccumulatorValueContext context(this);
1584
+ switch (assign_type) {
1585
+ case VARIABLE:
1586
+ EmitVariableLoad(expr->target()->AsVariableProxy()->var());
1587
+ PrepareForBailout(expr->target(), TOS_REG);
1588
+ break;
1589
+ case NAMED_PROPERTY:
1590
+ EmitNamedPropertyLoad(property);
1591
+ PrepareForBailoutForId(expr->CompoundLoadId(), TOS_REG);
1592
+ break;
1593
+ case KEYED_PROPERTY:
1594
+ EmitKeyedPropertyLoad(property);
1595
+ PrepareForBailoutForId(expr->CompoundLoadId(), TOS_REG);
1596
+ break;
1597
+ }
1598
+ }
1599
+
1600
+ Token::Value op = expr->binary_op();
1601
+ __ push(eax); // Left operand goes on the stack.
1602
+ VisitForAccumulatorValue(expr->value());
1603
+
1604
+ OverwriteMode mode = expr->value()->ResultOverwriteAllowed()
1605
+ ? OVERWRITE_RIGHT
1606
+ : NO_OVERWRITE;
1607
+ SetSourcePosition(expr->position() + 1);
1608
+ AccumulatorValueContext context(this);
1609
+ if (ShouldInlineSmiCase(op)) {
1610
+ EmitInlineSmiBinaryOp(expr->binary_operation(),
1611
+ op,
1612
+ mode,
1613
+ expr->target(),
1614
+ expr->value());
1615
+ } else {
1616
+ EmitBinaryOp(expr->binary_operation(), op, mode);
1617
+ }
1618
+
1619
+ // Deoptimization point in case the binary operation may have side effects.
1620
+ PrepareForBailout(expr->binary_operation(), TOS_REG);
1621
+ } else {
1622
+ VisitForAccumulatorValue(expr->value());
1623
+ }
1624
+
1625
+ // Record source position before possible IC call.
1626
+ SetSourcePosition(expr->position());
1627
+
1628
+ // Store the value.
1629
+ switch (assign_type) {
1630
+ case VARIABLE:
1631
+ EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
1632
+ expr->op());
1633
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
1634
+ context()->Plug(eax);
1635
+ break;
1636
+ case NAMED_PROPERTY:
1637
+ EmitNamedPropertyAssignment(expr);
1638
+ break;
1639
+ case KEYED_PROPERTY:
1640
+ EmitKeyedPropertyAssignment(expr);
1641
+ break;
1642
+ }
1643
+ }
1644
+
1645
+
1646
+ void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
1647
+ SetSourcePosition(prop->position());
1648
+ Literal* key = prop->key()->AsLiteral();
1649
+ ASSERT(!key->handle()->IsSmi());
1650
+ __ mov(ecx, Immediate(key->handle()));
1651
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
1652
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(prop));
1653
+ }
1654
+
1655
+
1656
+ void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
1657
+ SetSourcePosition(prop->position());
1658
+ Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize();
1659
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(prop));
1660
+ }
1661
+
1662
+
1663
+ void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr,
1664
+ Token::Value op,
1665
+ OverwriteMode mode,
1666
+ Expression* left,
1667
+ Expression* right) {
1668
+ // Do combined smi check of the operands. Left operand is on the
1669
+ // stack. Right operand is in eax.
1670
+ Label smi_case, done, stub_call;
1671
+ __ pop(edx);
1672
+ __ mov(ecx, eax);
1673
+ __ or_(eax, Operand(edx));
1674
+ JumpPatchSite patch_site(masm_);
1675
+ patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear);
1676
+
1677
+ __ bind(&stub_call);
1678
+ __ mov(eax, ecx);
1679
+ BinaryOpStub stub(op, mode);
1680
+ EmitCallIC(stub.GetCode(), &patch_site, expr->id());
1681
+ __ jmp(&done, Label::kNear);
1682
+
1683
+ // Smi case.
1684
+ __ bind(&smi_case);
1685
+ __ mov(eax, edx); // Copy left operand in case of a stub call.
1686
+
1687
+ switch (op) {
1688
+ case Token::SAR:
1689
+ __ SmiUntag(eax);
1690
+ __ SmiUntag(ecx);
1691
+ __ sar_cl(eax); // No checks of result necessary
1692
+ __ SmiTag(eax);
1693
+ break;
1694
+ case Token::SHL: {
1695
+ Label result_ok;
1696
+ __ SmiUntag(eax);
1697
+ __ SmiUntag(ecx);
1698
+ __ shl_cl(eax);
1699
+ // Check that the *signed* result fits in a smi.
1700
+ __ cmp(eax, 0xc0000000);
1701
+ __ j(positive, &result_ok);
1702
+ __ SmiTag(ecx);
1703
+ __ jmp(&stub_call);
1704
+ __ bind(&result_ok);
1705
+ __ SmiTag(eax);
1706
+ break;
1707
+ }
1708
+ case Token::SHR: {
1709
+ Label result_ok;
1710
+ __ SmiUntag(eax);
1711
+ __ SmiUntag(ecx);
1712
+ __ shr_cl(eax);
1713
+ __ test(eax, Immediate(0xc0000000));
1714
+ __ j(zero, &result_ok);
1715
+ __ SmiTag(ecx);
1716
+ __ jmp(&stub_call);
1717
+ __ bind(&result_ok);
1718
+ __ SmiTag(eax);
1719
+ break;
1720
+ }
1721
+ case Token::ADD:
1722
+ __ add(eax, Operand(ecx));
1723
+ __ j(overflow, &stub_call);
1724
+ break;
1725
+ case Token::SUB:
1726
+ __ sub(eax, Operand(ecx));
1727
+ __ j(overflow, &stub_call);
1728
+ break;
1729
+ case Token::MUL: {
1730
+ __ SmiUntag(eax);
1731
+ __ imul(eax, Operand(ecx));
1732
+ __ j(overflow, &stub_call);
1733
+ __ test(eax, Operand(eax));
1734
+ __ j(not_zero, &done, Label::kNear);
1735
+ __ mov(ebx, edx);
1736
+ __ or_(ebx, Operand(ecx));
1737
+ __ j(negative, &stub_call);
1738
+ break;
1739
+ }
1740
+ case Token::BIT_OR:
1741
+ __ or_(eax, Operand(ecx));
1742
+ break;
1743
+ case Token::BIT_AND:
1744
+ __ and_(eax, Operand(ecx));
1745
+ break;
1746
+ case Token::BIT_XOR:
1747
+ __ xor_(eax, Operand(ecx));
1748
+ break;
1749
+ default:
1750
+ UNREACHABLE();
1751
+ }
1752
+
1753
+ __ bind(&done);
1754
+ context()->Plug(eax);
1755
+ }
1756
+
1757
+
1758
+ void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr,
1759
+ Token::Value op,
1760
+ OverwriteMode mode) {
1761
+ __ pop(edx);
1762
+ BinaryOpStub stub(op, mode);
1763
+ // NULL signals no inlined smi code.
1764
+ EmitCallIC(stub.GetCode(), NULL, expr->id());
1765
+ context()->Plug(eax);
1766
+ }
1767
+
1768
+
1769
+ void FullCodeGenerator::EmitAssignment(Expression* expr, int bailout_ast_id) {
1770
+ // Invalid left-hand sides are rewritten to have a 'throw
1771
+ // ReferenceError' on the left-hand side.
1772
+ if (!expr->IsValidLeftHandSide()) {
1773
+ VisitForEffect(expr);
1774
+ return;
1775
+ }
1776
+
1777
+ // Left-hand side can only be a property, a global or a (parameter or local)
1778
+ // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY.
1779
+ enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
1780
+ LhsKind assign_type = VARIABLE;
1781
+ Property* prop = expr->AsProperty();
1782
+ if (prop != NULL) {
1783
+ assign_type = (prop->key()->IsPropertyName())
1784
+ ? NAMED_PROPERTY
1785
+ : KEYED_PROPERTY;
1786
+ }
1787
+
1788
+ switch (assign_type) {
1789
+ case VARIABLE: {
1790
+ Variable* var = expr->AsVariableProxy()->var();
1791
+ EffectContext context(this);
1792
+ EmitVariableAssignment(var, Token::ASSIGN);
1793
+ break;
1794
+ }
1795
+ case NAMED_PROPERTY: {
1796
+ __ push(eax); // Preserve value.
1797
+ VisitForAccumulatorValue(prop->obj());
1798
+ __ mov(edx, eax);
1799
+ __ pop(eax); // Restore value.
1800
+ __ mov(ecx, prop->key()->AsLiteral()->handle());
1801
+ Handle<Code> ic = is_strict_mode()
1802
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
1803
+ : isolate()->builtins()->StoreIC_Initialize();
1804
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber);
1805
+ break;
1806
+ }
1807
+ case KEYED_PROPERTY: {
1808
+ __ push(eax); // Preserve value.
1809
+ if (prop->is_synthetic()) {
1810
+ ASSERT(prop->obj()->AsVariableProxy() != NULL);
1811
+ ASSERT(prop->key()->AsLiteral() != NULL);
1812
+ { AccumulatorValueContext for_object(this);
1813
+ EmitVariableLoad(prop->obj()->AsVariableProxy()->var());
1814
+ }
1815
+ __ mov(edx, eax);
1816
+ __ SafeSet(ecx, Immediate(prop->key()->AsLiteral()->handle()));
1817
+ } else {
1818
+ VisitForStackValue(prop->obj());
1819
+ VisitForAccumulatorValue(prop->key());
1820
+ __ mov(ecx, eax);
1821
+ __ pop(edx);
1822
+ }
1823
+ __ pop(eax); // Restore value.
1824
+ Handle<Code> ic = is_strict_mode()
1825
+ ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict()
1826
+ : isolate()->builtins()->KeyedStoreIC_Initialize();
1827
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber);
1828
+ break;
1829
+ }
1830
+ }
1831
+ PrepareForBailoutForId(bailout_ast_id, TOS_REG);
1832
+ context()->Plug(eax);
1833
+ }
1834
+
1835
+
1836
+ void FullCodeGenerator::EmitVariableAssignment(Variable* var,
1837
+ Token::Value op) {
1838
+ // Left-hand sides that rewrite to explicit property accesses do not reach
1839
+ // here.
1840
+ ASSERT(var != NULL);
1841
+ ASSERT(var->is_global() || var->AsSlot() != NULL);
1842
+
1843
+ if (var->is_global()) {
1844
+ ASSERT(!var->is_this());
1845
+ // Assignment to a global variable. Use inline caching for the
1846
+ // assignment. Right-hand-side value is passed in eax, variable name in
1847
+ // ecx, and the global object on the stack.
1848
+ __ mov(ecx, var->name());
1849
+ __ mov(edx, GlobalObjectOperand());
1850
+ Handle<Code> ic = is_strict_mode()
1851
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
1852
+ : isolate()->builtins()->StoreIC_Initialize();
1853
+ EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT, AstNode::kNoNumber);
1854
+
1855
+ } else if (op == Token::INIT_CONST) {
1856
+ // Like var declarations, const declarations are hoisted to function
1857
+ // scope. However, unlike var initializers, const initializers are able
1858
+ // to drill a hole to that function context, even from inside a 'with'
1859
+ // context. We thus bypass the normal static scope lookup.
1860
+ Slot* slot = var->AsSlot();
1861
+ Label skip;
1862
+ switch (slot->type()) {
1863
+ case Slot::PARAMETER:
1864
+ // No const parameters.
1865
+ UNREACHABLE();
1866
+ break;
1867
+ case Slot::LOCAL:
1868
+ __ mov(edx, Operand(ebp, SlotOffset(slot)));
1869
+ __ cmp(edx, isolate()->factory()->the_hole_value());
1870
+ __ j(not_equal, &skip);
1871
+ __ mov(Operand(ebp, SlotOffset(slot)), eax);
1872
+ break;
1873
+ case Slot::CONTEXT: {
1874
+ __ mov(ecx, ContextOperand(esi, Context::FCONTEXT_INDEX));
1875
+ __ mov(edx, ContextOperand(ecx, slot->index()));
1876
+ __ cmp(edx, isolate()->factory()->the_hole_value());
1877
+ __ j(not_equal, &skip);
1878
+ __ mov(ContextOperand(ecx, slot->index()), eax);
1879
+ int offset = Context::SlotOffset(slot->index());
1880
+ __ mov(edx, eax); // Preserve the stored value in eax.
1881
+ __ RecordWrite(ecx, offset, edx, ebx);
1882
+ break;
1883
+ }
1884
+ case Slot::LOOKUP:
1885
+ __ push(eax);
1886
+ __ push(esi);
1887
+ __ push(Immediate(var->name()));
1888
+ __ CallRuntime(Runtime::kInitializeConstContextSlot, 3);
1889
+ break;
1890
+ }
1891
+ __ bind(&skip);
1892
+
1893
+ } else if (var->mode() != Variable::CONST) {
1894
+ // Perform the assignment for non-const variables. Const assignments
1895
+ // are simply skipped.
1896
+ Slot* slot = var->AsSlot();
1897
+ switch (slot->type()) {
1898
+ case Slot::PARAMETER:
1899
+ case Slot::LOCAL:
1900
+ // Perform the assignment.
1901
+ __ mov(Operand(ebp, SlotOffset(slot)), eax);
1902
+ break;
1903
+
1904
+ case Slot::CONTEXT: {
1905
+ MemOperand target = EmitSlotSearch(slot, ecx);
1906
+ // Perform the assignment and issue the write barrier.
1907
+ __ mov(target, eax);
1908
+ // The value of the assignment is in eax. RecordWrite clobbers its
1909
+ // register arguments.
1910
+ __ mov(edx, eax);
1911
+ int offset = Context::SlotOffset(slot->index());
1912
+ __ RecordWrite(ecx, offset, edx, ebx);
1913
+ break;
1914
+ }
1915
+
1916
+ case Slot::LOOKUP:
1917
+ // Call the runtime for the assignment.
1918
+ __ push(eax); // Value.
1919
+ __ push(esi); // Context.
1920
+ __ push(Immediate(var->name()));
1921
+ __ push(Immediate(Smi::FromInt(strict_mode_flag())));
1922
+ __ CallRuntime(Runtime::kStoreContextSlot, 4);
1923
+ break;
1924
+ }
1925
+ }
1926
+ }
1927
+
1928
+
1929
+ void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
1930
+ // Assignment to a property, using a named store IC.
1931
+ Property* prop = expr->target()->AsProperty();
1932
+ ASSERT(prop != NULL);
1933
+ ASSERT(prop->key()->AsLiteral() != NULL);
1934
+
1935
+ // If the assignment starts a block of assignments to the same object,
1936
+ // change to slow case to avoid the quadratic behavior of repeatedly
1937
+ // adding fast properties.
1938
+ if (expr->starts_initialization_block()) {
1939
+ __ push(result_register());
1940
+ __ push(Operand(esp, kPointerSize)); // Receiver is now under value.
1941
+ __ CallRuntime(Runtime::kToSlowProperties, 1);
1942
+ __ pop(result_register());
1943
+ }
1944
+
1945
+ // Record source code position before IC call.
1946
+ SetSourcePosition(expr->position());
1947
+ __ mov(ecx, prop->key()->AsLiteral()->handle());
1948
+ if (expr->ends_initialization_block()) {
1949
+ __ mov(edx, Operand(esp, 0));
1950
+ } else {
1951
+ __ pop(edx);
1952
+ }
1953
+ Handle<Code> ic = is_strict_mode()
1954
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
1955
+ : isolate()->builtins()->StoreIC_Initialize();
1956
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
1957
+
1958
+ // If the assignment ends an initialization block, revert to fast case.
1959
+ if (expr->ends_initialization_block()) {
1960
+ __ push(eax); // Result of assignment, saved even if not needed.
1961
+ __ push(Operand(esp, kPointerSize)); // Receiver is under value.
1962
+ __ CallRuntime(Runtime::kToFastProperties, 1);
1963
+ __ pop(eax);
1964
+ __ Drop(1);
1965
+ }
1966
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
1967
+ context()->Plug(eax);
1968
+ }
1969
+
1970
+
1971
+ void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) {
1972
+ // Assignment to a property, using a keyed store IC.
1973
+
1974
+ // If the assignment starts a block of assignments to the same object,
1975
+ // change to slow case to avoid the quadratic behavior of repeatedly
1976
+ // adding fast properties.
1977
+ if (expr->starts_initialization_block()) {
1978
+ __ push(result_register());
1979
+ // Receiver is now under the key and value.
1980
+ __ push(Operand(esp, 2 * kPointerSize));
1981
+ __ CallRuntime(Runtime::kToSlowProperties, 1);
1982
+ __ pop(result_register());
1983
+ }
1984
+
1985
+ __ pop(ecx);
1986
+ if (expr->ends_initialization_block()) {
1987
+ __ mov(edx, Operand(esp, 0)); // Leave receiver on the stack for later.
1988
+ } else {
1989
+ __ pop(edx);
1990
+ }
1991
+ // Record source code position before IC call.
1992
+ SetSourcePosition(expr->position());
1993
+ Handle<Code> ic = is_strict_mode()
1994
+ ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict()
1995
+ : isolate()->builtins()->KeyedStoreIC_Initialize();
1996
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
1997
+
1998
+ // If the assignment ends an initialization block, revert to fast case.
1999
+ if (expr->ends_initialization_block()) {
2000
+ __ pop(edx);
2001
+ __ push(eax); // Result of assignment, saved even if not needed.
2002
+ __ push(edx);
2003
+ __ CallRuntime(Runtime::kToFastProperties, 1);
2004
+ __ pop(eax);
2005
+ }
2006
+
2007
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2008
+ context()->Plug(eax);
2009
+ }
2010
+
2011
+
2012
+ void FullCodeGenerator::VisitProperty(Property* expr) {
2013
+ Comment cmnt(masm_, "[ Property");
2014
+ Expression* key = expr->key();
2015
+
2016
+ if (key->IsPropertyName()) {
2017
+ VisitForAccumulatorValue(expr->obj());
2018
+ EmitNamedPropertyLoad(expr);
2019
+ context()->Plug(eax);
2020
+ } else {
2021
+ VisitForStackValue(expr->obj());
2022
+ VisitForAccumulatorValue(expr->key());
2023
+ __ pop(edx);
2024
+ EmitKeyedPropertyLoad(expr);
2025
+ context()->Plug(eax);
2026
+ }
2027
+ }
2028
+
2029
+
2030
+ void FullCodeGenerator::EmitCallWithIC(Call* expr,
2031
+ Handle<Object> name,
2032
+ RelocInfo::Mode mode) {
2033
+ // Code common for calls using the IC.
2034
+ ZoneList<Expression*>* args = expr->arguments();
2035
+ int arg_count = args->length();
2036
+ { PreservePositionScope scope(masm()->positions_recorder());
2037
+ for (int i = 0; i < arg_count; i++) {
2038
+ VisitForStackValue(args->at(i));
2039
+ }
2040
+ __ Set(ecx, Immediate(name));
2041
+ }
2042
+ // Record source position of the IC call.
2043
+ SetSourcePosition(expr->position());
2044
+ InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2045
+ Handle<Code> ic =
2046
+ isolate()->stub_cache()->ComputeCallInitialize(arg_count, in_loop, mode);
2047
+ EmitCallIC(ic, mode, expr->id());
2048
+ RecordJSReturnSite(expr);
2049
+ // Restore context register.
2050
+ __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
2051
+ context()->Plug(eax);
2052
+ }
2053
+
2054
+
2055
+ void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr,
2056
+ Expression* key) {
2057
+ // Load the key.
2058
+ VisitForAccumulatorValue(key);
2059
+
2060
+ // Swap the name of the function and the receiver on the stack to follow
2061
+ // the calling convention for call ICs.
2062
+ __ pop(ecx);
2063
+ __ push(eax);
2064
+ __ push(ecx);
2065
+
2066
+ // Load the arguments.
2067
+ ZoneList<Expression*>* args = expr->arguments();
2068
+ int arg_count = args->length();
2069
+ { PreservePositionScope scope(masm()->positions_recorder());
2070
+ for (int i = 0; i < arg_count; i++) {
2071
+ VisitForStackValue(args->at(i));
2072
+ }
2073
+ }
2074
+ // Record source position of the IC call.
2075
+ SetSourcePosition(expr->position());
2076
+ InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2077
+ Handle<Code> ic = isolate()->stub_cache()->ComputeKeyedCallInitialize(
2078
+ arg_count, in_loop);
2079
+ __ mov(ecx, Operand(esp, (arg_count + 1) * kPointerSize)); // Key.
2080
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
2081
+ RecordJSReturnSite(expr);
2082
+ // Restore context register.
2083
+ __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
2084
+ context()->DropAndPlug(1, eax); // Drop the key still on the stack.
2085
+ }
2086
+
2087
+
2088
+ void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) {
2089
+ // Code common for calls using the call stub.
2090
+ ZoneList<Expression*>* args = expr->arguments();
2091
+ int arg_count = args->length();
2092
+ { PreservePositionScope scope(masm()->positions_recorder());
2093
+ for (int i = 0; i < arg_count; i++) {
2094
+ VisitForStackValue(args->at(i));
2095
+ }
2096
+ }
2097
+ // Record source position for debugger.
2098
+ SetSourcePosition(expr->position());
2099
+ InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2100
+ CallFunctionStub stub(arg_count, in_loop, flags);
2101
+ __ CallStub(&stub);
2102
+ RecordJSReturnSite(expr);
2103
+ // Restore context register.
2104
+ __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
2105
+ context()->DropAndPlug(1, eax);
2106
+ }
2107
+
2108
+
2109
+ void FullCodeGenerator::EmitResolvePossiblyDirectEval(ResolveEvalFlag flag,
2110
+ int arg_count) {
2111
+ // Push copy of the first argument or undefined if it doesn't exist.
2112
+ if (arg_count > 0) {
2113
+ __ push(Operand(esp, arg_count * kPointerSize));
2114
+ } else {
2115
+ __ push(Immediate(isolate()->factory()->undefined_value()));
2116
+ }
2117
+
2118
+ // Push the receiver of the enclosing function.
2119
+ __ push(Operand(ebp, (2 + scope()->num_parameters()) * kPointerSize));
2120
+
2121
+ // Push the strict mode flag.
2122
+ __ push(Immediate(Smi::FromInt(strict_mode_flag())));
2123
+
2124
+ __ CallRuntime(flag == SKIP_CONTEXT_LOOKUP
2125
+ ? Runtime::kResolvePossiblyDirectEvalNoLookup
2126
+ : Runtime::kResolvePossiblyDirectEval, 4);
2127
+ }
2128
+
2129
+
2130
+ void FullCodeGenerator::VisitCall(Call* expr) {
2131
+ #ifdef DEBUG
2132
+ // We want to verify that RecordJSReturnSite gets called on all paths
2133
+ // through this function. Avoid early returns.
2134
+ expr->return_is_recorded_ = false;
2135
+ #endif
2136
+
2137
+ Comment cmnt(masm_, "[ Call");
2138
+ Expression* fun = expr->expression();
2139
+ Variable* var = fun->AsVariableProxy()->AsVariable();
2140
+
2141
+ if (var != NULL && var->is_possibly_eval()) {
2142
+ // In a call to eval, we first call %ResolvePossiblyDirectEval to
2143
+ // resolve the function we need to call and the receiver of the
2144
+ // call. Then we call the resolved function using the given
2145
+ // arguments.
2146
+ ZoneList<Expression*>* args = expr->arguments();
2147
+ int arg_count = args->length();
2148
+ { PreservePositionScope pos_scope(masm()->positions_recorder());
2149
+ VisitForStackValue(fun);
2150
+ // Reserved receiver slot.
2151
+ __ push(Immediate(isolate()->factory()->undefined_value()));
2152
+
2153
+ // Push the arguments.
2154
+ for (int i = 0; i < arg_count; i++) {
2155
+ VisitForStackValue(args->at(i));
2156
+ }
2157
+
2158
+ // If we know that eval can only be shadowed by eval-introduced
2159
+ // variables we attempt to load the global eval function directly
2160
+ // in generated code. If we succeed, there is no need to perform a
2161
+ // context lookup in the runtime system.
2162
+ Label done;
2163
+ if (var->AsSlot() != NULL && var->mode() == Variable::DYNAMIC_GLOBAL) {
2164
+ Label slow;
2165
+ EmitLoadGlobalSlotCheckExtensions(var->AsSlot(),
2166
+ NOT_INSIDE_TYPEOF,
2167
+ &slow);
2168
+ // Push the function and resolve eval.
2169
+ __ push(eax);
2170
+ EmitResolvePossiblyDirectEval(SKIP_CONTEXT_LOOKUP, arg_count);
2171
+ __ jmp(&done);
2172
+ __ bind(&slow);
2173
+ }
2174
+
2175
+ // Push copy of the function (found below the arguments) and
2176
+ // resolve eval.
2177
+ __ push(Operand(esp, (arg_count + 1) * kPointerSize));
2178
+ EmitResolvePossiblyDirectEval(PERFORM_CONTEXT_LOOKUP, arg_count);
2179
+ if (done.is_linked()) {
2180
+ __ bind(&done);
2181
+ }
2182
+
2183
+ // The runtime call returns a pair of values in eax (function) and
2184
+ // edx (receiver). Touch up the stack with the right values.
2185
+ __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx);
2186
+ __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax);
2187
+ }
2188
+ // Record source position for debugger.
2189
+ SetSourcePosition(expr->position());
2190
+ InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2191
+ CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_IMPLICIT);
2192
+ __ CallStub(&stub);
2193
+ RecordJSReturnSite(expr);
2194
+ // Restore context register.
2195
+ __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
2196
+ context()->DropAndPlug(1, eax);
2197
+ } else if (var != NULL && !var->is_this() && var->is_global()) {
2198
+ // Push global object as receiver for the call IC.
2199
+ __ push(GlobalObjectOperand());
2200
+ EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT);
2201
+ } else if (var != NULL && var->AsSlot() != NULL &&
2202
+ var->AsSlot()->type() == Slot::LOOKUP) {
2203
+ // Call to a lookup slot (dynamically introduced variable).
2204
+ Label slow, done;
2205
+
2206
+ { PreservePositionScope scope(masm()->positions_recorder());
2207
+ // Generate code for loading from variables potentially shadowed
2208
+ // by eval-introduced variables.
2209
+ EmitDynamicLoadFromSlotFastCase(var->AsSlot(),
2210
+ NOT_INSIDE_TYPEOF,
2211
+ &slow,
2212
+ &done);
2213
+ }
2214
+
2215
+ __ bind(&slow);
2216
+ // Call the runtime to find the function to call (returned in eax)
2217
+ // and the object holding it (returned in edx).
2218
+ __ push(context_register());
2219
+ __ push(Immediate(var->name()));
2220
+ __ CallRuntime(Runtime::kLoadContextSlot, 2);
2221
+ __ push(eax); // Function.
2222
+ __ push(edx); // Receiver.
2223
+
2224
+ // If fast case code has been generated, emit code to push the
2225
+ // function and receiver and have the slow path jump around this
2226
+ // code.
2227
+ if (done.is_linked()) {
2228
+ Label call;
2229
+ __ jmp(&call);
2230
+ __ bind(&done);
2231
+ // Push function.
2232
+ __ push(eax);
2233
+ // Push global receiver.
2234
+ __ mov(ebx, GlobalObjectOperand());
2235
+ __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset));
2236
+ __ bind(&call);
2237
+ }
2238
+
2239
+ // The receiver is either the global receiver or an object found
2240
+ // by LoadContextSlot. That object could be the hole if the
2241
+ // receiver is implicitly the global object.
2242
+ EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT);
2243
+ } else if (fun->AsProperty() != NULL) {
2244
+ // Call to an object property.
2245
+ Property* prop = fun->AsProperty();
2246
+ Literal* key = prop->key()->AsLiteral();
2247
+ if (key != NULL && key->handle()->IsSymbol()) {
2248
+ // Call to a named property, use call IC.
2249
+ { PreservePositionScope scope(masm()->positions_recorder());
2250
+ VisitForStackValue(prop->obj());
2251
+ }
2252
+ EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET);
2253
+ } else {
2254
+ // Call to a keyed property.
2255
+ // For a synthetic property use keyed load IC followed by function call,
2256
+ // for a regular property use keyed EmitCallIC.
2257
+ if (prop->is_synthetic()) {
2258
+ // Do not visit the object and key subexpressions (they are shared
2259
+ // by all occurrences of the same rewritten parameter).
2260
+ ASSERT(prop->obj()->AsVariableProxy() != NULL);
2261
+ ASSERT(prop->obj()->AsVariableProxy()->var()->AsSlot() != NULL);
2262
+ Slot* slot = prop->obj()->AsVariableProxy()->var()->AsSlot();
2263
+ MemOperand operand = EmitSlotSearch(slot, edx);
2264
+ __ mov(edx, operand);
2265
+
2266
+ ASSERT(prop->key()->AsLiteral() != NULL);
2267
+ ASSERT(prop->key()->AsLiteral()->handle()->IsSmi());
2268
+ __ mov(eax, prop->key()->AsLiteral()->handle());
2269
+
2270
+ // Record source code position for IC call.
2271
+ SetSourcePosition(prop->position());
2272
+
2273
+ Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize();
2274
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(prop));
2275
+ // Push result (function).
2276
+ __ push(eax);
2277
+ // Push Global receiver.
2278
+ __ mov(ecx, GlobalObjectOperand());
2279
+ __ push(FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset));
2280
+ EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS);
2281
+ } else {
2282
+ { PreservePositionScope scope(masm()->positions_recorder());
2283
+ VisitForStackValue(prop->obj());
2284
+ }
2285
+ EmitKeyedCallWithIC(expr, prop->key());
2286
+ }
2287
+ }
2288
+ } else {
2289
+ { PreservePositionScope scope(masm()->positions_recorder());
2290
+ VisitForStackValue(fun);
2291
+ }
2292
+ // Load global receiver object.
2293
+ __ mov(ebx, GlobalObjectOperand());
2294
+ __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset));
2295
+ // Emit function call.
2296
+ EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS);
2297
+ }
2298
+
2299
+ #ifdef DEBUG
2300
+ // RecordJSReturnSite should have been called.
2301
+ ASSERT(expr->return_is_recorded_);
2302
+ #endif
2303
+ }
2304
+
2305
+
2306
+ void FullCodeGenerator::VisitCallNew(CallNew* expr) {
2307
+ Comment cmnt(masm_, "[ CallNew");
2308
+ // According to ECMA-262, section 11.2.2, page 44, the function
2309
+ // expression in new calls must be evaluated before the
2310
+ // arguments.
2311
+
2312
+ // Push constructor on the stack. If it's not a function it's used as
2313
+ // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is
2314
+ // ignored.
2315
+ VisitForStackValue(expr->expression());
2316
+
2317
+ // Push the arguments ("left-to-right") on the stack.
2318
+ ZoneList<Expression*>* args = expr->arguments();
2319
+ int arg_count = args->length();
2320
+ for (int i = 0; i < arg_count; i++) {
2321
+ VisitForStackValue(args->at(i));
2322
+ }
2323
+
2324
+ // Call the construct call builtin that handles allocation and
2325
+ // constructor invocation.
2326
+ SetSourcePosition(expr->position());
2327
+
2328
+ // Load function and argument count into edi and eax.
2329
+ __ SafeSet(eax, Immediate(arg_count));
2330
+ __ mov(edi, Operand(esp, arg_count * kPointerSize));
2331
+
2332
+ Handle<Code> construct_builtin =
2333
+ isolate()->builtins()->JSConstructCall();
2334
+ __ call(construct_builtin, RelocInfo::CONSTRUCT_CALL);
2335
+ context()->Plug(eax);
2336
+ }
2337
+
2338
+
2339
+ void FullCodeGenerator::EmitIsSmi(ZoneList<Expression*>* args) {
2340
+ ASSERT(args->length() == 1);
2341
+
2342
+ VisitForAccumulatorValue(args->at(0));
2343
+
2344
+ Label materialize_true, materialize_false;
2345
+ Label* if_true = NULL;
2346
+ Label* if_false = NULL;
2347
+ Label* fall_through = NULL;
2348
+ context()->PrepareTest(&materialize_true, &materialize_false,
2349
+ &if_true, &if_false, &fall_through);
2350
+
2351
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2352
+ __ test(eax, Immediate(kSmiTagMask));
2353
+ Split(zero, if_true, if_false, fall_through);
2354
+
2355
+ context()->Plug(if_true, if_false);
2356
+ }
2357
+
2358
+
2359
+ void FullCodeGenerator::EmitIsNonNegativeSmi(ZoneList<Expression*>* args) {
2360
+ ASSERT(args->length() == 1);
2361
+
2362
+ VisitForAccumulatorValue(args->at(0));
2363
+
2364
+ Label materialize_true, materialize_false;
2365
+ Label* if_true = NULL;
2366
+ Label* if_false = NULL;
2367
+ Label* fall_through = NULL;
2368
+ context()->PrepareTest(&materialize_true, &materialize_false,
2369
+ &if_true, &if_false, &fall_through);
2370
+
2371
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2372
+ __ test(eax, Immediate(kSmiTagMask | 0x80000000));
2373
+ Split(zero, if_true, if_false, fall_through);
2374
+
2375
+ context()->Plug(if_true, if_false);
2376
+ }
2377
+
2378
+
2379
+ void FullCodeGenerator::EmitIsObject(ZoneList<Expression*>* args) {
2380
+ ASSERT(args->length() == 1);
2381
+
2382
+ VisitForAccumulatorValue(args->at(0));
2383
+
2384
+ Label materialize_true, materialize_false;
2385
+ Label* if_true = NULL;
2386
+ Label* if_false = NULL;
2387
+ Label* fall_through = NULL;
2388
+ context()->PrepareTest(&materialize_true, &materialize_false,
2389
+ &if_true, &if_false, &fall_through);
2390
+
2391
+ __ test(eax, Immediate(kSmiTagMask));
2392
+ __ j(zero, if_false);
2393
+ __ cmp(eax, isolate()->factory()->null_value());
2394
+ __ j(equal, if_true);
2395
+ __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
2396
+ // Undetectable objects behave like undefined when tested with typeof.
2397
+ __ movzx_b(ecx, FieldOperand(ebx, Map::kBitFieldOffset));
2398
+ __ test(ecx, Immediate(1 << Map::kIsUndetectable));
2399
+ __ j(not_zero, if_false);
2400
+ __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceTypeOffset));
2401
+ __ cmp(ecx, FIRST_JS_OBJECT_TYPE);
2402
+ __ j(below, if_false);
2403
+ __ cmp(ecx, LAST_JS_OBJECT_TYPE);
2404
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2405
+ Split(below_equal, if_true, if_false, fall_through);
2406
+
2407
+ context()->Plug(if_true, if_false);
2408
+ }
2409
+
2410
+
2411
+ void FullCodeGenerator::EmitIsSpecObject(ZoneList<Expression*>* args) {
2412
+ ASSERT(args->length() == 1);
2413
+
2414
+ VisitForAccumulatorValue(args->at(0));
2415
+
2416
+ Label materialize_true, materialize_false;
2417
+ Label* if_true = NULL;
2418
+ Label* if_false = NULL;
2419
+ Label* fall_through = NULL;
2420
+ context()->PrepareTest(&materialize_true, &materialize_false,
2421
+ &if_true, &if_false, &fall_through);
2422
+
2423
+ __ test(eax, Immediate(kSmiTagMask));
2424
+ __ j(equal, if_false);
2425
+ __ CmpObjectType(eax, FIRST_JS_OBJECT_TYPE, ebx);
2426
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2427
+ Split(above_equal, if_true, if_false, fall_through);
2428
+
2429
+ context()->Plug(if_true, if_false);
2430
+ }
2431
+
2432
+
2433
+ void FullCodeGenerator::EmitIsUndetectableObject(ZoneList<Expression*>* args) {
2434
+ ASSERT(args->length() == 1);
2435
+
2436
+ VisitForAccumulatorValue(args->at(0));
2437
+
2438
+ Label materialize_true, materialize_false;
2439
+ Label* if_true = NULL;
2440
+ Label* if_false = NULL;
2441
+ Label* fall_through = NULL;
2442
+ context()->PrepareTest(&materialize_true, &materialize_false,
2443
+ &if_true, &if_false, &fall_through);
2444
+
2445
+ __ test(eax, Immediate(kSmiTagMask));
2446
+ __ j(zero, if_false);
2447
+ __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
2448
+ __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset));
2449
+ __ test(ebx, Immediate(1 << Map::kIsUndetectable));
2450
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2451
+ Split(not_zero, if_true, if_false, fall_through);
2452
+
2453
+ context()->Plug(if_true, if_false);
2454
+ }
2455
+
2456
+
2457
+ void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf(
2458
+ ZoneList<Expression*>* args) {
2459
+ ASSERT(args->length() == 1);
2460
+
2461
+ VisitForAccumulatorValue(args->at(0));
2462
+
2463
+ Label materialize_true, materialize_false;
2464
+ Label* if_true = NULL;
2465
+ Label* if_false = NULL;
2466
+ Label* fall_through = NULL;
2467
+ context()->PrepareTest(&materialize_true, &materialize_false,
2468
+ &if_true, &if_false, &fall_through);
2469
+
2470
+ if (FLAG_debug_code) __ AbortIfSmi(eax);
2471
+
2472
+ // Check whether this map has already been checked to be safe for default
2473
+ // valueOf.
2474
+ __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
2475
+ __ test_b(FieldOperand(ebx, Map::kBitField2Offset),
2476
+ 1 << Map::kStringWrapperSafeForDefaultValueOf);
2477
+ __ j(not_zero, if_true);
2478
+
2479
+ // Check for fast case object. Return false for slow case objects.
2480
+ __ mov(ecx, FieldOperand(eax, JSObject::kPropertiesOffset));
2481
+ __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset));
2482
+ __ cmp(ecx, FACTORY->hash_table_map());
2483
+ __ j(equal, if_false);
2484
+
2485
+ // Look for valueOf symbol in the descriptor array, and indicate false if
2486
+ // found. The type is not checked, so if it is a transition it is a false
2487
+ // negative.
2488
+ __ LoadInstanceDescriptors(ebx, ebx);
2489
+ __ mov(ecx, FieldOperand(ebx, FixedArray::kLengthOffset));
2490
+ // ebx: descriptor array
2491
+ // ecx: length of descriptor array
2492
+ // Calculate the end of the descriptor array.
2493
+ STATIC_ASSERT(kSmiTag == 0);
2494
+ STATIC_ASSERT(kSmiTagSize == 1);
2495
+ STATIC_ASSERT(kPointerSize == 4);
2496
+ __ lea(ecx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize));
2497
+ // Calculate location of the first key name.
2498
+ __ add(Operand(ebx),
2499
+ Immediate(FixedArray::kHeaderSize +
2500
+ DescriptorArray::kFirstIndex * kPointerSize));
2501
+ // Loop through all the keys in the descriptor array. If one of these is the
2502
+ // symbol valueOf the result is false.
2503
+ Label entry, loop;
2504
+ __ jmp(&entry);
2505
+ __ bind(&loop);
2506
+ __ mov(edx, FieldOperand(ebx, 0));
2507
+ __ cmp(edx, FACTORY->value_of_symbol());
2508
+ __ j(equal, if_false);
2509
+ __ add(Operand(ebx), Immediate(kPointerSize));
2510
+ __ bind(&entry);
2511
+ __ cmp(ebx, Operand(ecx));
2512
+ __ j(not_equal, &loop);
2513
+
2514
+ // Reload map as register ebx was used as temporary above.
2515
+ __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
2516
+
2517
+ // If a valueOf property is not found on the object check that it's
2518
+ // prototype is the un-modified String prototype. If not result is false.
2519
+ __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset));
2520
+ __ test(ecx, Immediate(kSmiTagMask));
2521
+ __ j(zero, if_false);
2522
+ __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset));
2523
+ __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX)));
2524
+ __ mov(edx,
2525
+ FieldOperand(edx, GlobalObject::kGlobalContextOffset));
2526
+ __ cmp(ecx,
2527
+ ContextOperand(edx,
2528
+ Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX));
2529
+ __ j(not_equal, if_false);
2530
+ // Set the bit in the map to indicate that it has been checked safe for
2531
+ // default valueOf and set true result.
2532
+ __ or_(FieldOperand(ebx, Map::kBitField2Offset),
2533
+ Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf));
2534
+ __ jmp(if_true);
2535
+
2536
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2537
+ context()->Plug(if_true, if_false);
2538
+ }
2539
+
2540
+
2541
+ void FullCodeGenerator::EmitIsFunction(ZoneList<Expression*>* args) {
2542
+ ASSERT(args->length() == 1);
2543
+
2544
+ VisitForAccumulatorValue(args->at(0));
2545
+
2546
+ Label materialize_true, materialize_false;
2547
+ Label* if_true = NULL;
2548
+ Label* if_false = NULL;
2549
+ Label* fall_through = NULL;
2550
+ context()->PrepareTest(&materialize_true, &materialize_false,
2551
+ &if_true, &if_false, &fall_through);
2552
+
2553
+ __ test(eax, Immediate(kSmiTagMask));
2554
+ __ j(zero, if_false);
2555
+ __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx);
2556
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2557
+ Split(equal, if_true, if_false, fall_through);
2558
+
2559
+ context()->Plug(if_true, if_false);
2560
+ }
2561
+
2562
+
2563
+ void FullCodeGenerator::EmitIsArray(ZoneList<Expression*>* args) {
2564
+ ASSERT(args->length() == 1);
2565
+
2566
+ VisitForAccumulatorValue(args->at(0));
2567
+
2568
+ Label materialize_true, materialize_false;
2569
+ Label* if_true = NULL;
2570
+ Label* if_false = NULL;
2571
+ Label* fall_through = NULL;
2572
+ context()->PrepareTest(&materialize_true, &materialize_false,
2573
+ &if_true, &if_false, &fall_through);
2574
+
2575
+ __ test(eax, Immediate(kSmiTagMask));
2576
+ __ j(equal, if_false);
2577
+ __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx);
2578
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2579
+ Split(equal, if_true, if_false, fall_through);
2580
+
2581
+ context()->Plug(if_true, if_false);
2582
+ }
2583
+
2584
+
2585
+ void FullCodeGenerator::EmitIsRegExp(ZoneList<Expression*>* args) {
2586
+ ASSERT(args->length() == 1);
2587
+
2588
+ VisitForAccumulatorValue(args->at(0));
2589
+
2590
+ Label materialize_true, materialize_false;
2591
+ Label* if_true = NULL;
2592
+ Label* if_false = NULL;
2593
+ Label* fall_through = NULL;
2594
+ context()->PrepareTest(&materialize_true, &materialize_false,
2595
+ &if_true, &if_false, &fall_through);
2596
+
2597
+ __ test(eax, Immediate(kSmiTagMask));
2598
+ __ j(equal, if_false);
2599
+ __ CmpObjectType(eax, JS_REGEXP_TYPE, ebx);
2600
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2601
+ Split(equal, if_true, if_false, fall_through);
2602
+
2603
+ context()->Plug(if_true, if_false);
2604
+ }
2605
+
2606
+
2607
+
2608
+ void FullCodeGenerator::EmitIsConstructCall(ZoneList<Expression*>* args) {
2609
+ ASSERT(args->length() == 0);
2610
+
2611
+ Label materialize_true, materialize_false;
2612
+ Label* if_true = NULL;
2613
+ Label* if_false = NULL;
2614
+ Label* fall_through = NULL;
2615
+ context()->PrepareTest(&materialize_true, &materialize_false,
2616
+ &if_true, &if_false, &fall_through);
2617
+
2618
+ // Get the frame pointer for the calling frame.
2619
+ __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
2620
+
2621
+ // Skip the arguments adaptor frame if it exists.
2622
+ Label check_frame_marker;
2623
+ __ cmp(Operand(eax, StandardFrameConstants::kContextOffset),
2624
+ Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
2625
+ __ j(not_equal, &check_frame_marker);
2626
+ __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset));
2627
+
2628
+ // Check the marker in the calling frame.
2629
+ __ bind(&check_frame_marker);
2630
+ __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset),
2631
+ Immediate(Smi::FromInt(StackFrame::CONSTRUCT)));
2632
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2633
+ Split(equal, if_true, if_false, fall_through);
2634
+
2635
+ context()->Plug(if_true, if_false);
2636
+ }
2637
+
2638
+
2639
+ void FullCodeGenerator::EmitObjectEquals(ZoneList<Expression*>* args) {
2640
+ ASSERT(args->length() == 2);
2641
+
2642
+ // Load the two objects into registers and perform the comparison.
2643
+ VisitForStackValue(args->at(0));
2644
+ VisitForAccumulatorValue(args->at(1));
2645
+
2646
+ Label materialize_true, materialize_false;
2647
+ Label* if_true = NULL;
2648
+ Label* if_false = NULL;
2649
+ Label* fall_through = NULL;
2650
+ context()->PrepareTest(&materialize_true, &materialize_false,
2651
+ &if_true, &if_false, &fall_through);
2652
+
2653
+ __ pop(ebx);
2654
+ __ cmp(eax, Operand(ebx));
2655
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2656
+ Split(equal, if_true, if_false, fall_through);
2657
+
2658
+ context()->Plug(if_true, if_false);
2659
+ }
2660
+
2661
+
2662
+ void FullCodeGenerator::EmitArguments(ZoneList<Expression*>* args) {
2663
+ ASSERT(args->length() == 1);
2664
+
2665
+ // ArgumentsAccessStub expects the key in edx and the formal
2666
+ // parameter count in eax.
2667
+ VisitForAccumulatorValue(args->at(0));
2668
+ __ mov(edx, eax);
2669
+ __ SafeSet(eax, Immediate(Smi::FromInt(scope()->num_parameters())));
2670
+ ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT);
2671
+ __ CallStub(&stub);
2672
+ context()->Plug(eax);
2673
+ }
2674
+
2675
+
2676
+ void FullCodeGenerator::EmitArgumentsLength(ZoneList<Expression*>* args) {
2677
+ ASSERT(args->length() == 0);
2678
+
2679
+ Label exit;
2680
+ // Get the number of formal parameters.
2681
+ __ SafeSet(eax, Immediate(Smi::FromInt(scope()->num_parameters())));
2682
+
2683
+ // Check if the calling frame is an arguments adaptor frame.
2684
+ __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
2685
+ __ cmp(Operand(ebx, StandardFrameConstants::kContextOffset),
2686
+ Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
2687
+ __ j(not_equal, &exit);
2688
+
2689
+ // Arguments adaptor case: Read the arguments length from the
2690
+ // adaptor frame.
2691
+ __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset));
2692
+
2693
+ __ bind(&exit);
2694
+ if (FLAG_debug_code) __ AbortIfNotSmi(eax);
2695
+ context()->Plug(eax);
2696
+ }
2697
+
2698
+
2699
+ void FullCodeGenerator::EmitClassOf(ZoneList<Expression*>* args) {
2700
+ ASSERT(args->length() == 1);
2701
+ Label done, null, function, non_function_constructor;
2702
+
2703
+ VisitForAccumulatorValue(args->at(0));
2704
+
2705
+ // If the object is a smi, we return null.
2706
+ __ test(eax, Immediate(kSmiTagMask));
2707
+ __ j(zero, &null);
2708
+
2709
+ // Check that the object is a JS object but take special care of JS
2710
+ // functions to make sure they have 'Function' as their class.
2711
+ __ CmpObjectType(eax, FIRST_JS_OBJECT_TYPE, eax); // Map is now in eax.
2712
+ __ j(below, &null);
2713
+
2714
+ // As long as JS_FUNCTION_TYPE is the last instance type and it is
2715
+ // right after LAST_JS_OBJECT_TYPE, we can avoid checking for
2716
+ // LAST_JS_OBJECT_TYPE.
2717
+ ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
2718
+ ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1);
2719
+ __ CmpInstanceType(eax, JS_FUNCTION_TYPE);
2720
+ __ j(equal, &function);
2721
+
2722
+ // Check if the constructor in the map is a function.
2723
+ __ mov(eax, FieldOperand(eax, Map::kConstructorOffset));
2724
+ __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx);
2725
+ __ j(not_equal, &non_function_constructor);
2726
+
2727
+ // eax now contains the constructor function. Grab the
2728
+ // instance class name from there.
2729
+ __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset));
2730
+ __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset));
2731
+ __ jmp(&done);
2732
+
2733
+ // Functions have class 'Function'.
2734
+ __ bind(&function);
2735
+ __ mov(eax, isolate()->factory()->function_class_symbol());
2736
+ __ jmp(&done);
2737
+
2738
+ // Objects with a non-function constructor have class 'Object'.
2739
+ __ bind(&non_function_constructor);
2740
+ __ mov(eax, isolate()->factory()->Object_symbol());
2741
+ __ jmp(&done);
2742
+
2743
+ // Non-JS objects have class null.
2744
+ __ bind(&null);
2745
+ __ mov(eax, isolate()->factory()->null_value());
2746
+
2747
+ // All done.
2748
+ __ bind(&done);
2749
+
2750
+ context()->Plug(eax);
2751
+ }
2752
+
2753
+
2754
+ void FullCodeGenerator::EmitLog(ZoneList<Expression*>* args) {
2755
+ // Conditionally generate a log call.
2756
+ // Args:
2757
+ // 0 (literal string): The type of logging (corresponds to the flags).
2758
+ // This is used to determine whether or not to generate the log call.
2759
+ // 1 (string): Format string. Access the string at argument index 2
2760
+ // with '%2s' (see Logger::LogRuntime for all the formats).
2761
+ // 2 (array): Arguments to the format string.
2762
+ ASSERT_EQ(args->length(), 3);
2763
+ #ifdef ENABLE_LOGGING_AND_PROFILING
2764
+ if (CodeGenerator::ShouldGenerateLog(args->at(0))) {
2765
+ VisitForStackValue(args->at(1));
2766
+ VisitForStackValue(args->at(2));
2767
+ __ CallRuntime(Runtime::kLog, 2);
2768
+ }
2769
+ #endif
2770
+ // Finally, we're expected to leave a value on the top of the stack.
2771
+ __ mov(eax, isolate()->factory()->undefined_value());
2772
+ context()->Plug(eax);
2773
+ }
2774
+
2775
+
2776
+ void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) {
2777
+ ASSERT(args->length() == 0);
2778
+
2779
+ Label slow_allocate_heapnumber;
2780
+ Label heapnumber_allocated;
2781
+
2782
+ __ AllocateHeapNumber(edi, ebx, ecx, &slow_allocate_heapnumber);
2783
+ __ jmp(&heapnumber_allocated);
2784
+
2785
+ __ bind(&slow_allocate_heapnumber);
2786
+ // Allocate a heap number.
2787
+ __ CallRuntime(Runtime::kNumberAlloc, 0);
2788
+ __ mov(edi, eax);
2789
+
2790
+ __ bind(&heapnumber_allocated);
2791
+
2792
+ __ PrepareCallCFunction(1, ebx);
2793
+ __ mov(Operand(esp, 0), Immediate(ExternalReference::isolate_address()));
2794
+ __ CallCFunction(ExternalReference::random_uint32_function(isolate()),
2795
+ 1);
2796
+
2797
+ // Convert 32 random bits in eax to 0.(32 random bits) in a double
2798
+ // by computing:
2799
+ // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
2800
+ // This is implemented on both SSE2 and FPU.
2801
+ if (CpuFeatures::IsSupported(SSE2)) {
2802
+ CpuFeatures::Scope fscope(SSE2);
2803
+ __ mov(ebx, Immediate(0x49800000)); // 1.0 x 2^20 as single.
2804
+ __ movd(xmm1, Operand(ebx));
2805
+ __ movd(xmm0, Operand(eax));
2806
+ __ cvtss2sd(xmm1, xmm1);
2807
+ __ xorps(xmm0, xmm1);
2808
+ __ subsd(xmm0, xmm1);
2809
+ __ movdbl(FieldOperand(edi, HeapNumber::kValueOffset), xmm0);
2810
+ } else {
2811
+ // 0x4130000000000000 is 1.0 x 2^20 as a double.
2812
+ __ mov(FieldOperand(edi, HeapNumber::kExponentOffset),
2813
+ Immediate(0x41300000));
2814
+ __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), eax);
2815
+ __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset));
2816
+ __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), Immediate(0));
2817
+ __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset));
2818
+ __ fsubp(1);
2819
+ __ fstp_d(FieldOperand(edi, HeapNumber::kValueOffset));
2820
+ }
2821
+ __ mov(eax, edi);
2822
+ context()->Plug(eax);
2823
+ }
2824
+
2825
+
2826
+ void FullCodeGenerator::EmitSubString(ZoneList<Expression*>* args) {
2827
+ // Load the arguments on the stack and call the stub.
2828
+ SubStringStub stub;
2829
+ ASSERT(args->length() == 3);
2830
+ VisitForStackValue(args->at(0));
2831
+ VisitForStackValue(args->at(1));
2832
+ VisitForStackValue(args->at(2));
2833
+ __ CallStub(&stub);
2834
+ context()->Plug(eax);
2835
+ }
2836
+
2837
+
2838
+ void FullCodeGenerator::EmitRegExpExec(ZoneList<Expression*>* args) {
2839
+ // Load the arguments on the stack and call the stub.
2840
+ RegExpExecStub stub;
2841
+ ASSERT(args->length() == 4);
2842
+ VisitForStackValue(args->at(0));
2843
+ VisitForStackValue(args->at(1));
2844
+ VisitForStackValue(args->at(2));
2845
+ VisitForStackValue(args->at(3));
2846
+ __ CallStub(&stub);
2847
+ context()->Plug(eax);
2848
+ }
2849
+
2850
+
2851
+ void FullCodeGenerator::EmitValueOf(ZoneList<Expression*>* args) {
2852
+ ASSERT(args->length() == 1);
2853
+
2854
+ VisitForAccumulatorValue(args->at(0)); // Load the object.
2855
+
2856
+ Label done;
2857
+ // If the object is a smi return the object.
2858
+ __ test(eax, Immediate(kSmiTagMask));
2859
+ __ j(zero, &done, Label::kNear);
2860
+ // If the object is not a value type, return the object.
2861
+ __ CmpObjectType(eax, JS_VALUE_TYPE, ebx);
2862
+ __ j(not_equal, &done, Label::kNear);
2863
+ __ mov(eax, FieldOperand(eax, JSValue::kValueOffset));
2864
+
2865
+ __ bind(&done);
2866
+ context()->Plug(eax);
2867
+ }
2868
+
2869
+
2870
+ void FullCodeGenerator::EmitMathPow(ZoneList<Expression*>* args) {
2871
+ // Load the arguments on the stack and call the runtime function.
2872
+ ASSERT(args->length() == 2);
2873
+ VisitForStackValue(args->at(0));
2874
+ VisitForStackValue(args->at(1));
2875
+
2876
+ if (CpuFeatures::IsSupported(SSE2)) {
2877
+ MathPowStub stub;
2878
+ __ CallStub(&stub);
2879
+ } else {
2880
+ __ CallRuntime(Runtime::kMath_pow, 2);
2881
+ }
2882
+ context()->Plug(eax);
2883
+ }
2884
+
2885
+
2886
+ void FullCodeGenerator::EmitSetValueOf(ZoneList<Expression*>* args) {
2887
+ ASSERT(args->length() == 2);
2888
+
2889
+ VisitForStackValue(args->at(0)); // Load the object.
2890
+ VisitForAccumulatorValue(args->at(1)); // Load the value.
2891
+ __ pop(ebx); // eax = value. ebx = object.
2892
+
2893
+ Label done;
2894
+ // If the object is a smi, return the value.
2895
+ __ test(ebx, Immediate(kSmiTagMask));
2896
+ __ j(zero, &done, Label::kNear);
2897
+
2898
+ // If the object is not a value type, return the value.
2899
+ __ CmpObjectType(ebx, JS_VALUE_TYPE, ecx);
2900
+ __ j(not_equal, &done, Label::kNear);
2901
+
2902
+ // Store the value.
2903
+ __ mov(FieldOperand(ebx, JSValue::kValueOffset), eax);
2904
+ // Update the write barrier. Save the value as it will be
2905
+ // overwritten by the write barrier code and is needed afterward.
2906
+ __ mov(edx, eax);
2907
+ __ RecordWrite(ebx, JSValue::kValueOffset, edx, ecx);
2908
+
2909
+ __ bind(&done);
2910
+ context()->Plug(eax);
2911
+ }
2912
+
2913
+
2914
+ void FullCodeGenerator::EmitNumberToString(ZoneList<Expression*>* args) {
2915
+ ASSERT_EQ(args->length(), 1);
2916
+
2917
+ // Load the argument on the stack and call the stub.
2918
+ VisitForStackValue(args->at(0));
2919
+
2920
+ NumberToStringStub stub;
2921
+ __ CallStub(&stub);
2922
+ context()->Plug(eax);
2923
+ }
2924
+
2925
+
2926
+ void FullCodeGenerator::EmitStringCharFromCode(ZoneList<Expression*>* args) {
2927
+ ASSERT(args->length() == 1);
2928
+
2929
+ VisitForAccumulatorValue(args->at(0));
2930
+
2931
+ Label done;
2932
+ StringCharFromCodeGenerator generator(eax, ebx);
2933
+ generator.GenerateFast(masm_);
2934
+ __ jmp(&done);
2935
+
2936
+ NopRuntimeCallHelper call_helper;
2937
+ generator.GenerateSlow(masm_, call_helper);
2938
+
2939
+ __ bind(&done);
2940
+ context()->Plug(ebx);
2941
+ }
2942
+
2943
+
2944
+ void FullCodeGenerator::EmitStringCharCodeAt(ZoneList<Expression*>* args) {
2945
+ ASSERT(args->length() == 2);
2946
+
2947
+ VisitForStackValue(args->at(0));
2948
+ VisitForAccumulatorValue(args->at(1));
2949
+
2950
+ Register object = ebx;
2951
+ Register index = eax;
2952
+ Register scratch = ecx;
2953
+ Register result = edx;
2954
+
2955
+ __ pop(object);
2956
+
2957
+ Label need_conversion;
2958
+ Label index_out_of_range;
2959
+ Label done;
2960
+ StringCharCodeAtGenerator generator(object,
2961
+ index,
2962
+ scratch,
2963
+ result,
2964
+ &need_conversion,
2965
+ &need_conversion,
2966
+ &index_out_of_range,
2967
+ STRING_INDEX_IS_NUMBER);
2968
+ generator.GenerateFast(masm_);
2969
+ __ jmp(&done);
2970
+
2971
+ __ bind(&index_out_of_range);
2972
+ // When the index is out of range, the spec requires us to return
2973
+ // NaN.
2974
+ __ Set(result, Immediate(isolate()->factory()->nan_value()));
2975
+ __ jmp(&done);
2976
+
2977
+ __ bind(&need_conversion);
2978
+ // Move the undefined value into the result register, which will
2979
+ // trigger conversion.
2980
+ __ Set(result, Immediate(isolate()->factory()->undefined_value()));
2981
+ __ jmp(&done);
2982
+
2983
+ NopRuntimeCallHelper call_helper;
2984
+ generator.GenerateSlow(masm_, call_helper);
2985
+
2986
+ __ bind(&done);
2987
+ context()->Plug(result);
2988
+ }
2989
+
2990
+
2991
+ void FullCodeGenerator::EmitStringCharAt(ZoneList<Expression*>* args) {
2992
+ ASSERT(args->length() == 2);
2993
+
2994
+ VisitForStackValue(args->at(0));
2995
+ VisitForAccumulatorValue(args->at(1));
2996
+
2997
+ Register object = ebx;
2998
+ Register index = eax;
2999
+ Register scratch1 = ecx;
3000
+ Register scratch2 = edx;
3001
+ Register result = eax;
3002
+
3003
+ __ pop(object);
3004
+
3005
+ Label need_conversion;
3006
+ Label index_out_of_range;
3007
+ Label done;
3008
+ StringCharAtGenerator generator(object,
3009
+ index,
3010
+ scratch1,
3011
+ scratch2,
3012
+ result,
3013
+ &need_conversion,
3014
+ &need_conversion,
3015
+ &index_out_of_range,
3016
+ STRING_INDEX_IS_NUMBER);
3017
+ generator.GenerateFast(masm_);
3018
+ __ jmp(&done);
3019
+
3020
+ __ bind(&index_out_of_range);
3021
+ // When the index is out of range, the spec requires us to return
3022
+ // the empty string.
3023
+ __ Set(result, Immediate(isolate()->factory()->empty_string()));
3024
+ __ jmp(&done);
3025
+
3026
+ __ bind(&need_conversion);
3027
+ // Move smi zero into the result register, which will trigger
3028
+ // conversion.
3029
+ __ Set(result, Immediate(Smi::FromInt(0)));
3030
+ __ jmp(&done);
3031
+
3032
+ NopRuntimeCallHelper call_helper;
3033
+ generator.GenerateSlow(masm_, call_helper);
3034
+
3035
+ __ bind(&done);
3036
+ context()->Plug(result);
3037
+ }
3038
+
3039
+
3040
+ void FullCodeGenerator::EmitStringAdd(ZoneList<Expression*>* args) {
3041
+ ASSERT_EQ(2, args->length());
3042
+
3043
+ VisitForStackValue(args->at(0));
3044
+ VisitForStackValue(args->at(1));
3045
+
3046
+ StringAddStub stub(NO_STRING_ADD_FLAGS);
3047
+ __ CallStub(&stub);
3048
+ context()->Plug(eax);
3049
+ }
3050
+
3051
+
3052
+ void FullCodeGenerator::EmitStringCompare(ZoneList<Expression*>* args) {
3053
+ ASSERT_EQ(2, args->length());
3054
+
3055
+ VisitForStackValue(args->at(0));
3056
+ VisitForStackValue(args->at(1));
3057
+
3058
+ StringCompareStub stub;
3059
+ __ CallStub(&stub);
3060
+ context()->Plug(eax);
3061
+ }
3062
+
3063
+
3064
+ void FullCodeGenerator::EmitMathSin(ZoneList<Expression*>* args) {
3065
+ // Load the argument on the stack and call the stub.
3066
+ TranscendentalCacheStub stub(TranscendentalCache::SIN,
3067
+ TranscendentalCacheStub::TAGGED);
3068
+ ASSERT(args->length() == 1);
3069
+ VisitForStackValue(args->at(0));
3070
+ __ CallStub(&stub);
3071
+ context()->Plug(eax);
3072
+ }
3073
+
3074
+
3075
+ void FullCodeGenerator::EmitMathCos(ZoneList<Expression*>* args) {
3076
+ // Load the argument on the stack and call the stub.
3077
+ TranscendentalCacheStub stub(TranscendentalCache::COS,
3078
+ TranscendentalCacheStub::TAGGED);
3079
+ ASSERT(args->length() == 1);
3080
+ VisitForStackValue(args->at(0));
3081
+ __ CallStub(&stub);
3082
+ context()->Plug(eax);
3083
+ }
3084
+
3085
+
3086
+ void FullCodeGenerator::EmitMathLog(ZoneList<Expression*>* args) {
3087
+ // Load the argument on the stack and call the stub.
3088
+ TranscendentalCacheStub stub(TranscendentalCache::LOG,
3089
+ TranscendentalCacheStub::TAGGED);
3090
+ ASSERT(args->length() == 1);
3091
+ VisitForStackValue(args->at(0));
3092
+ __ CallStub(&stub);
3093
+ context()->Plug(eax);
3094
+ }
3095
+
3096
+
3097
+ void FullCodeGenerator::EmitMathSqrt(ZoneList<Expression*>* args) {
3098
+ // Load the argument on the stack and call the runtime function.
3099
+ ASSERT(args->length() == 1);
3100
+ VisitForStackValue(args->at(0));
3101
+ __ CallRuntime(Runtime::kMath_sqrt, 1);
3102
+ context()->Plug(eax);
3103
+ }
3104
+
3105
+
3106
+ void FullCodeGenerator::EmitCallFunction(ZoneList<Expression*>* args) {
3107
+ ASSERT(args->length() >= 2);
3108
+
3109
+ int arg_count = args->length() - 2; // 2 ~ receiver and function.
3110
+ for (int i = 0; i < arg_count + 1; ++i) {
3111
+ VisitForStackValue(args->at(i));
3112
+ }
3113
+ VisitForAccumulatorValue(args->last()); // Function.
3114
+
3115
+ // InvokeFunction requires the function in edi. Move it in there.
3116
+ __ mov(edi, result_register());
3117
+ ParameterCount count(arg_count);
3118
+ __ InvokeFunction(edi, count, CALL_FUNCTION);
3119
+ __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
3120
+ context()->Plug(eax);
3121
+ }
3122
+
3123
+
3124
+ void FullCodeGenerator::EmitRegExpConstructResult(ZoneList<Expression*>* args) {
3125
+ // Load the arguments on the stack and call the stub.
3126
+ RegExpConstructResultStub stub;
3127
+ ASSERT(args->length() == 3);
3128
+ VisitForStackValue(args->at(0));
3129
+ VisitForStackValue(args->at(1));
3130
+ VisitForStackValue(args->at(2));
3131
+ __ CallStub(&stub);
3132
+ context()->Plug(eax);
3133
+ }
3134
+
3135
+
3136
+ void FullCodeGenerator::EmitSwapElements(ZoneList<Expression*>* args) {
3137
+ ASSERT(args->length() == 3);
3138
+ VisitForStackValue(args->at(0));
3139
+ VisitForStackValue(args->at(1));
3140
+ VisitForStackValue(args->at(2));
3141
+ Label done;
3142
+ Label slow_case;
3143
+ Register object = eax;
3144
+ Register index_1 = ebx;
3145
+ Register index_2 = ecx;
3146
+ Register elements = edi;
3147
+ Register temp = edx;
3148
+ __ mov(object, Operand(esp, 2 * kPointerSize));
3149
+ // Fetch the map and check if array is in fast case.
3150
+ // Check that object doesn't require security checks and
3151
+ // has no indexed interceptor.
3152
+ __ CmpObjectType(object, JS_ARRAY_TYPE, temp);
3153
+ __ j(not_equal, &slow_case);
3154
+ __ test_b(FieldOperand(temp, Map::kBitFieldOffset),
3155
+ KeyedLoadIC::kSlowCaseBitFieldMask);
3156
+ __ j(not_zero, &slow_case);
3157
+
3158
+ // Check the object's elements are in fast case and writable.
3159
+ __ mov(elements, FieldOperand(object, JSObject::kElementsOffset));
3160
+ __ cmp(FieldOperand(elements, HeapObject::kMapOffset),
3161
+ Immediate(isolate()->factory()->fixed_array_map()));
3162
+ __ j(not_equal, &slow_case);
3163
+
3164
+ // Check that both indices are smis.
3165
+ __ mov(index_1, Operand(esp, 1 * kPointerSize));
3166
+ __ mov(index_2, Operand(esp, 0));
3167
+ __ mov(temp, index_1);
3168
+ __ or_(temp, Operand(index_2));
3169
+ __ test(temp, Immediate(kSmiTagMask));
3170
+ __ j(not_zero, &slow_case);
3171
+
3172
+ // Check that both indices are valid.
3173
+ __ mov(temp, FieldOperand(object, JSArray::kLengthOffset));
3174
+ __ cmp(temp, Operand(index_1));
3175
+ __ j(below_equal, &slow_case);
3176
+ __ cmp(temp, Operand(index_2));
3177
+ __ j(below_equal, &slow_case);
3178
+
3179
+ // Bring addresses into index1 and index2.
3180
+ __ lea(index_1, CodeGenerator::FixedArrayElementOperand(elements, index_1));
3181
+ __ lea(index_2, CodeGenerator::FixedArrayElementOperand(elements, index_2));
3182
+
3183
+ // Swap elements. Use object and temp as scratch registers.
3184
+ __ mov(object, Operand(index_1, 0));
3185
+ __ mov(temp, Operand(index_2, 0));
3186
+ __ mov(Operand(index_2, 0), object);
3187
+ __ mov(Operand(index_1, 0), temp);
3188
+
3189
+ Label new_space;
3190
+ __ InNewSpace(elements, temp, equal, &new_space);
3191
+
3192
+ __ mov(object, elements);
3193
+ __ RecordWriteHelper(object, index_1, temp);
3194
+ __ RecordWriteHelper(elements, index_2, temp);
3195
+
3196
+ __ bind(&new_space);
3197
+ // We are done. Drop elements from the stack, and return undefined.
3198
+ __ add(Operand(esp), Immediate(3 * kPointerSize));
3199
+ __ mov(eax, isolate()->factory()->undefined_value());
3200
+ __ jmp(&done);
3201
+
3202
+ __ bind(&slow_case);
3203
+ __ CallRuntime(Runtime::kSwapElements, 3);
3204
+
3205
+ __ bind(&done);
3206
+ context()->Plug(eax);
3207
+ }
3208
+
3209
+
3210
+ void FullCodeGenerator::EmitGetFromCache(ZoneList<Expression*>* args) {
3211
+ ASSERT_EQ(2, args->length());
3212
+
3213
+ ASSERT_NE(NULL, args->at(0)->AsLiteral());
3214
+ int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value();
3215
+
3216
+ Handle<FixedArray> jsfunction_result_caches(
3217
+ isolate()->global_context()->jsfunction_result_caches());
3218
+ if (jsfunction_result_caches->length() <= cache_id) {
3219
+ __ Abort("Attempt to use undefined cache.");
3220
+ __ mov(eax, isolate()->factory()->undefined_value());
3221
+ context()->Plug(eax);
3222
+ return;
3223
+ }
3224
+
3225
+ VisitForAccumulatorValue(args->at(1));
3226
+
3227
+ Register key = eax;
3228
+ Register cache = ebx;
3229
+ Register tmp = ecx;
3230
+ __ mov(cache, ContextOperand(esi, Context::GLOBAL_INDEX));
3231
+ __ mov(cache,
3232
+ FieldOperand(cache, GlobalObject::kGlobalContextOffset));
3233
+ __ mov(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX));
3234
+ __ mov(cache,
3235
+ FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id)));
3236
+
3237
+ Label done, not_found;
3238
+ // tmp now holds finger offset as a smi.
3239
+ ASSERT(kSmiTag == 0 && kSmiTagSize == 1);
3240
+ __ mov(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset));
3241
+ __ cmp(key, CodeGenerator::FixedArrayElementOperand(cache, tmp));
3242
+ __ j(not_equal, &not_found);
3243
+
3244
+ __ mov(eax, CodeGenerator::FixedArrayElementOperand(cache, tmp, 1));
3245
+ __ jmp(&done);
3246
+
3247
+ __ bind(&not_found);
3248
+ // Call runtime to perform the lookup.
3249
+ __ push(cache);
3250
+ __ push(key);
3251
+ __ CallRuntime(Runtime::kGetFromCache, 2);
3252
+
3253
+ __ bind(&done);
3254
+ context()->Plug(eax);
3255
+ }
3256
+
3257
+
3258
+ void FullCodeGenerator::EmitIsRegExpEquivalent(ZoneList<Expression*>* args) {
3259
+ ASSERT_EQ(2, args->length());
3260
+
3261
+ Register right = eax;
3262
+ Register left = ebx;
3263
+ Register tmp = ecx;
3264
+
3265
+ VisitForStackValue(args->at(0));
3266
+ VisitForAccumulatorValue(args->at(1));
3267
+ __ pop(left);
3268
+
3269
+ Label done, fail, ok;
3270
+ __ cmp(left, Operand(right));
3271
+ __ j(equal, &ok);
3272
+ // Fail if either is a non-HeapObject.
3273
+ __ mov(tmp, left);
3274
+ __ and_(Operand(tmp), right);
3275
+ __ test(Operand(tmp), Immediate(kSmiTagMask));
3276
+ __ j(zero, &fail);
3277
+ __ mov(tmp, FieldOperand(left, HeapObject::kMapOffset));
3278
+ __ CmpInstanceType(tmp, JS_REGEXP_TYPE);
3279
+ __ j(not_equal, &fail);
3280
+ __ cmp(tmp, FieldOperand(right, HeapObject::kMapOffset));
3281
+ __ j(not_equal, &fail);
3282
+ __ mov(tmp, FieldOperand(left, JSRegExp::kDataOffset));
3283
+ __ cmp(tmp, FieldOperand(right, JSRegExp::kDataOffset));
3284
+ __ j(equal, &ok);
3285
+ __ bind(&fail);
3286
+ __ mov(eax, Immediate(isolate()->factory()->false_value()));
3287
+ __ jmp(&done);
3288
+ __ bind(&ok);
3289
+ __ mov(eax, Immediate(isolate()->factory()->true_value()));
3290
+ __ bind(&done);
3291
+
3292
+ context()->Plug(eax);
3293
+ }
3294
+
3295
+
3296
+ void FullCodeGenerator::EmitHasCachedArrayIndex(ZoneList<Expression*>* args) {
3297
+ ASSERT(args->length() == 1);
3298
+
3299
+ VisitForAccumulatorValue(args->at(0));
3300
+
3301
+ if (FLAG_debug_code) {
3302
+ __ AbortIfNotString(eax);
3303
+ }
3304
+
3305
+ Label materialize_true, materialize_false;
3306
+ Label* if_true = NULL;
3307
+ Label* if_false = NULL;
3308
+ Label* fall_through = NULL;
3309
+ context()->PrepareTest(&materialize_true, &materialize_false,
3310
+ &if_true, &if_false, &fall_through);
3311
+
3312
+ __ test(FieldOperand(eax, String::kHashFieldOffset),
3313
+ Immediate(String::kContainsCachedArrayIndexMask));
3314
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
3315
+ Split(zero, if_true, if_false, fall_through);
3316
+
3317
+ context()->Plug(if_true, if_false);
3318
+ }
3319
+
3320
+
3321
+ void FullCodeGenerator::EmitGetCachedArrayIndex(ZoneList<Expression*>* args) {
3322
+ ASSERT(args->length() == 1);
3323
+ VisitForAccumulatorValue(args->at(0));
3324
+
3325
+ if (FLAG_debug_code) {
3326
+ __ AbortIfNotString(eax);
3327
+ }
3328
+
3329
+ __ mov(eax, FieldOperand(eax, String::kHashFieldOffset));
3330
+ __ IndexFromHash(eax, eax);
3331
+
3332
+ context()->Plug(eax);
3333
+ }
3334
+
3335
+
3336
+ void FullCodeGenerator::EmitFastAsciiArrayJoin(ZoneList<Expression*>* args) {
3337
+ Label bailout, done, one_char_separator, long_separator,
3338
+ non_trivial_array, not_size_one_array, loop,
3339
+ loop_1, loop_1_condition, loop_2, loop_2_entry, loop_3, loop_3_entry;
3340
+
3341
+ ASSERT(args->length() == 2);
3342
+ // We will leave the separator on the stack until the end of the function.
3343
+ VisitForStackValue(args->at(1));
3344
+ // Load this to eax (= array)
3345
+ VisitForAccumulatorValue(args->at(0));
3346
+ // All aliases of the same register have disjoint lifetimes.
3347
+ Register array = eax;
3348
+ Register elements = no_reg; // Will be eax.
3349
+
3350
+ Register index = edx;
3351
+
3352
+ Register string_length = ecx;
3353
+
3354
+ Register string = esi;
3355
+
3356
+ Register scratch = ebx;
3357
+
3358
+ Register array_length = edi;
3359
+ Register result_pos = no_reg; // Will be edi.
3360
+
3361
+ // Separator operand is already pushed.
3362
+ Operand separator_operand = Operand(esp, 2 * kPointerSize);
3363
+ Operand result_operand = Operand(esp, 1 * kPointerSize);
3364
+ Operand array_length_operand = Operand(esp, 0);
3365
+ __ sub(Operand(esp), Immediate(2 * kPointerSize));
3366
+ __ cld();
3367
+ // Check that the array is a JSArray
3368
+ __ test(array, Immediate(kSmiTagMask));
3369
+ __ j(zero, &bailout);
3370
+ __ CmpObjectType(array, JS_ARRAY_TYPE, scratch);
3371
+ __ j(not_equal, &bailout);
3372
+
3373
+ // Check that the array has fast elements.
3374
+ __ test_b(FieldOperand(scratch, Map::kBitField2Offset),
3375
+ 1 << Map::kHasFastElements);
3376
+ __ j(zero, &bailout);
3377
+
3378
+ // If the array has length zero, return the empty string.
3379
+ __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset));
3380
+ __ SmiUntag(array_length);
3381
+ __ j(not_zero, &non_trivial_array);
3382
+ __ mov(result_operand, isolate()->factory()->empty_string());
3383
+ __ jmp(&done);
3384
+
3385
+ // Save the array length.
3386
+ __ bind(&non_trivial_array);
3387
+ __ mov(array_length_operand, array_length);
3388
+
3389
+ // Save the FixedArray containing array's elements.
3390
+ // End of array's live range.
3391
+ elements = array;
3392
+ __ mov(elements, FieldOperand(array, JSArray::kElementsOffset));
3393
+ array = no_reg;
3394
+
3395
+
3396
+ // Check that all array elements are sequential ASCII strings, and
3397
+ // accumulate the sum of their lengths, as a smi-encoded value.
3398
+ __ Set(index, Immediate(0));
3399
+ __ Set(string_length, Immediate(0));
3400
+ // Loop condition: while (index < length).
3401
+ // Live loop registers: index, array_length, string,
3402
+ // scratch, string_length, elements.
3403
+ if (FLAG_debug_code) {
3404
+ __ cmp(index, Operand(array_length));
3405
+ __ Assert(less, "No empty arrays here in EmitFastAsciiArrayJoin");
3406
+ }
3407
+ __ bind(&loop);
3408
+ __ mov(string, FieldOperand(elements,
3409
+ index,
3410
+ times_pointer_size,
3411
+ FixedArray::kHeaderSize));
3412
+ __ test(string, Immediate(kSmiTagMask));
3413
+ __ j(zero, &bailout);
3414
+ __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset));
3415
+ __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
3416
+ __ and_(scratch, Immediate(
3417
+ kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
3418
+ __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag);
3419
+ __ j(not_equal, &bailout);
3420
+ __ add(string_length,
3421
+ FieldOperand(string, SeqAsciiString::kLengthOffset));
3422
+ __ j(overflow, &bailout);
3423
+ __ add(Operand(index), Immediate(1));
3424
+ __ cmp(index, Operand(array_length));
3425
+ __ j(less, &loop);
3426
+
3427
+ // If array_length is 1, return elements[0], a string.
3428
+ __ cmp(array_length, 1);
3429
+ __ j(not_equal, &not_size_one_array);
3430
+ __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize));
3431
+ __ mov(result_operand, scratch);
3432
+ __ jmp(&done);
3433
+
3434
+ __ bind(&not_size_one_array);
3435
+
3436
+ // End of array_length live range.
3437
+ result_pos = array_length;
3438
+ array_length = no_reg;
3439
+
3440
+ // Live registers:
3441
+ // string_length: Sum of string lengths, as a smi.
3442
+ // elements: FixedArray of strings.
3443
+
3444
+ // Check that the separator is a flat ASCII string.
3445
+ __ mov(string, separator_operand);
3446
+ __ test(string, Immediate(kSmiTagMask));
3447
+ __ j(zero, &bailout);
3448
+ __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset));
3449
+ __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
3450
+ __ and_(scratch, Immediate(
3451
+ kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
3452
+ __ cmp(scratch, ASCII_STRING_TYPE);
3453
+ __ j(not_equal, &bailout);
3454
+
3455
+ // Add (separator length times array_length) - separator length
3456
+ // to string_length.
3457
+ __ mov(scratch, separator_operand);
3458
+ __ mov(scratch, FieldOperand(scratch, SeqAsciiString::kLengthOffset));
3459
+ __ sub(string_length, Operand(scratch)); // May be negative, temporarily.
3460
+ __ imul(scratch, array_length_operand);
3461
+ __ j(overflow, &bailout);
3462
+ __ add(string_length, Operand(scratch));
3463
+ __ j(overflow, &bailout);
3464
+
3465
+ __ shr(string_length, 1);
3466
+ // Live registers and stack values:
3467
+ // string_length
3468
+ // elements
3469
+ __ AllocateAsciiString(result_pos, string_length, scratch,
3470
+ index, string, &bailout);
3471
+ __ mov(result_operand, result_pos);
3472
+ __ lea(result_pos, FieldOperand(result_pos, SeqAsciiString::kHeaderSize));
3473
+
3474
+
3475
+ __ mov(string, separator_operand);
3476
+ __ cmp(FieldOperand(string, SeqAsciiString::kLengthOffset),
3477
+ Immediate(Smi::FromInt(1)));
3478
+ __ j(equal, &one_char_separator);
3479
+ __ j(greater, &long_separator);
3480
+
3481
+
3482
+ // Empty separator case
3483
+ __ mov(index, Immediate(0));
3484
+ __ jmp(&loop_1_condition);
3485
+ // Loop condition: while (index < length).
3486
+ __ bind(&loop_1);
3487
+ // Each iteration of the loop concatenates one string to the result.
3488
+ // Live values in registers:
3489
+ // index: which element of the elements array we are adding to the result.
3490
+ // result_pos: the position to which we are currently copying characters.
3491
+ // elements: the FixedArray of strings we are joining.
3492
+
3493
+ // Get string = array[index].
3494
+ __ mov(string, FieldOperand(elements, index,
3495
+ times_pointer_size,
3496
+ FixedArray::kHeaderSize));
3497
+ __ mov(string_length,
3498
+ FieldOperand(string, String::kLengthOffset));
3499
+ __ shr(string_length, 1);
3500
+ __ lea(string,
3501
+ FieldOperand(string, SeqAsciiString::kHeaderSize));
3502
+ __ CopyBytes(string, result_pos, string_length, scratch);
3503
+ __ add(Operand(index), Immediate(1));
3504
+ __ bind(&loop_1_condition);
3505
+ __ cmp(index, array_length_operand);
3506
+ __ j(less, &loop_1); // End while (index < length).
3507
+ __ jmp(&done);
3508
+
3509
+
3510
+
3511
+ // One-character separator case
3512
+ __ bind(&one_char_separator);
3513
+ // Replace separator with its ascii character value.
3514
+ __ mov_b(scratch, FieldOperand(string, SeqAsciiString::kHeaderSize));
3515
+ __ mov_b(separator_operand, scratch);
3516
+
3517
+ __ Set(index, Immediate(0));
3518
+ // Jump into the loop after the code that copies the separator, so the first
3519
+ // element is not preceded by a separator
3520
+ __ jmp(&loop_2_entry);
3521
+ // Loop condition: while (index < length).
3522
+ __ bind(&loop_2);
3523
+ // Each iteration of the loop concatenates one string to the result.
3524
+ // Live values in registers:
3525
+ // index: which element of the elements array we are adding to the result.
3526
+ // result_pos: the position to which we are currently copying characters.
3527
+
3528
+ // Copy the separator character to the result.
3529
+ __ mov_b(scratch, separator_operand);
3530
+ __ mov_b(Operand(result_pos, 0), scratch);
3531
+ __ inc(result_pos);
3532
+
3533
+ __ bind(&loop_2_entry);
3534
+ // Get string = array[index].
3535
+ __ mov(string, FieldOperand(elements, index,
3536
+ times_pointer_size,
3537
+ FixedArray::kHeaderSize));
3538
+ __ mov(string_length,
3539
+ FieldOperand(string, String::kLengthOffset));
3540
+ __ shr(string_length, 1);
3541
+ __ lea(string,
3542
+ FieldOperand(string, SeqAsciiString::kHeaderSize));
3543
+ __ CopyBytes(string, result_pos, string_length, scratch);
3544
+ __ add(Operand(index), Immediate(1));
3545
+
3546
+ __ cmp(index, array_length_operand);
3547
+ __ j(less, &loop_2); // End while (index < length).
3548
+ __ jmp(&done);
3549
+
3550
+
3551
+ // Long separator case (separator is more than one character).
3552
+ __ bind(&long_separator);
3553
+
3554
+ __ Set(index, Immediate(0));
3555
+ // Jump into the loop after the code that copies the separator, so the first
3556
+ // element is not preceded by a separator
3557
+ __ jmp(&loop_3_entry);
3558
+ // Loop condition: while (index < length).
3559
+ __ bind(&loop_3);
3560
+ // Each iteration of the loop concatenates one string to the result.
3561
+ // Live values in registers:
3562
+ // index: which element of the elements array we are adding to the result.
3563
+ // result_pos: the position to which we are currently copying characters.
3564
+
3565
+ // Copy the separator to the result.
3566
+ __ mov(string, separator_operand);
3567
+ __ mov(string_length,
3568
+ FieldOperand(string, String::kLengthOffset));
3569
+ __ shr(string_length, 1);
3570
+ __ lea(string,
3571
+ FieldOperand(string, SeqAsciiString::kHeaderSize));
3572
+ __ CopyBytes(string, result_pos, string_length, scratch);
3573
+
3574
+ __ bind(&loop_3_entry);
3575
+ // Get string = array[index].
3576
+ __ mov(string, FieldOperand(elements, index,
3577
+ times_pointer_size,
3578
+ FixedArray::kHeaderSize));
3579
+ __ mov(string_length,
3580
+ FieldOperand(string, String::kLengthOffset));
3581
+ __ shr(string_length, 1);
3582
+ __ lea(string,
3583
+ FieldOperand(string, SeqAsciiString::kHeaderSize));
3584
+ __ CopyBytes(string, result_pos, string_length, scratch);
3585
+ __ add(Operand(index), Immediate(1));
3586
+
3587
+ __ cmp(index, array_length_operand);
3588
+ __ j(less, &loop_3); // End while (index < length).
3589
+ __ jmp(&done);
3590
+
3591
+
3592
+ __ bind(&bailout);
3593
+ __ mov(result_operand, isolate()->factory()->undefined_value());
3594
+ __ bind(&done);
3595
+ __ mov(eax, result_operand);
3596
+ // Drop temp values from the stack, and restore context register.
3597
+ __ add(Operand(esp), Immediate(3 * kPointerSize));
3598
+
3599
+ __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
3600
+ context()->Plug(eax);
3601
+ }
3602
+
3603
+
3604
+ void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
3605
+ Handle<String> name = expr->name();
3606
+ if (name->length() > 0 && name->Get(0) == '_') {
3607
+ Comment cmnt(masm_, "[ InlineRuntimeCall");
3608
+ EmitInlineRuntimeCall(expr);
3609
+ return;
3610
+ }
3611
+
3612
+ Comment cmnt(masm_, "[ CallRuntime");
3613
+ ZoneList<Expression*>* args = expr->arguments();
3614
+
3615
+ if (expr->is_jsruntime()) {
3616
+ // Prepare for calling JS runtime function.
3617
+ __ mov(eax, GlobalObjectOperand());
3618
+ __ push(FieldOperand(eax, GlobalObject::kBuiltinsOffset));
3619
+ }
3620
+
3621
+ // Push the arguments ("left-to-right").
3622
+ int arg_count = args->length();
3623
+ for (int i = 0; i < arg_count; i++) {
3624
+ VisitForStackValue(args->at(i));
3625
+ }
3626
+
3627
+ if (expr->is_jsruntime()) {
3628
+ // Call the JS runtime function via a call IC.
3629
+ __ Set(ecx, Immediate(expr->name()));
3630
+ InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
3631
+ RelocInfo::Mode mode = RelocInfo::CODE_TARGET;
3632
+ Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize(
3633
+ arg_count, in_loop, mode);
3634
+ EmitCallIC(ic, mode, expr->id());
3635
+ // Restore context register.
3636
+ __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
3637
+ } else {
3638
+ // Call the C runtime function.
3639
+ __ CallRuntime(expr->function(), arg_count);
3640
+ }
3641
+ context()->Plug(eax);
3642
+ }
3643
+
3644
+
3645
+ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
3646
+ switch (expr->op()) {
3647
+ case Token::DELETE: {
3648
+ Comment cmnt(masm_, "[ UnaryOperation (DELETE)");
3649
+ Property* prop = expr->expression()->AsProperty();
3650
+ Variable* var = expr->expression()->AsVariableProxy()->AsVariable();
3651
+
3652
+ if (prop != NULL) {
3653
+ if (prop->is_synthetic()) {
3654
+ // Result of deleting parameters is false, even when they rewrite
3655
+ // to accesses on the arguments object.
3656
+ context()->Plug(false);
3657
+ } else {
3658
+ VisitForStackValue(prop->obj());
3659
+ VisitForStackValue(prop->key());
3660
+ __ push(Immediate(Smi::FromInt(strict_mode_flag())));
3661
+ __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
3662
+ context()->Plug(eax);
3663
+ }
3664
+ } else if (var != NULL) {
3665
+ // Delete of an unqualified identifier is disallowed in strict mode
3666
+ // but "delete this" is.
3667
+ ASSERT(strict_mode_flag() == kNonStrictMode || var->is_this());
3668
+ if (var->is_global()) {
3669
+ __ push(GlobalObjectOperand());
3670
+ __ push(Immediate(var->name()));
3671
+ __ push(Immediate(Smi::FromInt(kNonStrictMode)));
3672
+ __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
3673
+ context()->Plug(eax);
3674
+ } else if (var->AsSlot() != NULL &&
3675
+ var->AsSlot()->type() != Slot::LOOKUP) {
3676
+ // Result of deleting non-global, non-dynamic variables is false.
3677
+ // The subexpression does not have side effects.
3678
+ context()->Plug(false);
3679
+ } else {
3680
+ // Non-global variable. Call the runtime to try to delete from the
3681
+ // context where the variable was introduced.
3682
+ __ push(context_register());
3683
+ __ push(Immediate(var->name()));
3684
+ __ CallRuntime(Runtime::kDeleteContextSlot, 2);
3685
+ context()->Plug(eax);
3686
+ }
3687
+ } else {
3688
+ // Result of deleting non-property, non-variable reference is true.
3689
+ // The subexpression may have side effects.
3690
+ VisitForEffect(expr->expression());
3691
+ context()->Plug(true);
3692
+ }
3693
+ break;
3694
+ }
3695
+
3696
+ case Token::VOID: {
3697
+ Comment cmnt(masm_, "[ UnaryOperation (VOID)");
3698
+ VisitForEffect(expr->expression());
3699
+ context()->Plug(isolate()->factory()->undefined_value());
3700
+ break;
3701
+ }
3702
+
3703
+ case Token::NOT: {
3704
+ Comment cmnt(masm_, "[ UnaryOperation (NOT)");
3705
+ if (context()->IsEffect()) {
3706
+ // Unary NOT has no side effects so it's only necessary to visit the
3707
+ // subexpression. Match the optimizing compiler by not branching.
3708
+ VisitForEffect(expr->expression());
3709
+ } else {
3710
+ Label materialize_true, materialize_false;
3711
+ Label* if_true = NULL;
3712
+ Label* if_false = NULL;
3713
+ Label* fall_through = NULL;
3714
+
3715
+ // Notice that the labels are swapped.
3716
+ context()->PrepareTest(&materialize_true, &materialize_false,
3717
+ &if_false, &if_true, &fall_through);
3718
+ if (context()->IsTest()) ForwardBailoutToChild(expr);
3719
+ VisitForControl(expr->expression(), if_true, if_false, fall_through);
3720
+ context()->Plug(if_false, if_true); // Labels swapped.
3721
+ }
3722
+ break;
3723
+ }
3724
+
3725
+ case Token::TYPEOF: {
3726
+ Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)");
3727
+ { StackValueContext context(this);
3728
+ VisitForTypeofValue(expr->expression());
3729
+ }
3730
+ __ CallRuntime(Runtime::kTypeof, 1);
3731
+ context()->Plug(eax);
3732
+ break;
3733
+ }
3734
+
3735
+ case Token::ADD: {
3736
+ Comment cmt(masm_, "[ UnaryOperation (ADD)");
3737
+ VisitForAccumulatorValue(expr->expression());
3738
+ Label no_conversion;
3739
+ __ test(result_register(), Immediate(kSmiTagMask));
3740
+ __ j(zero, &no_conversion);
3741
+ ToNumberStub convert_stub;
3742
+ __ CallStub(&convert_stub);
3743
+ __ bind(&no_conversion);
3744
+ context()->Plug(result_register());
3745
+ break;
3746
+ }
3747
+
3748
+ case Token::SUB:
3749
+ EmitUnaryOperation(expr, "[ UnaryOperation (SUB)");
3750
+ break;
3751
+
3752
+ case Token::BIT_NOT:
3753
+ EmitUnaryOperation(expr, "[ UnaryOperation (BIT_NOT)");
3754
+ break;
3755
+
3756
+ default:
3757
+ UNREACHABLE();
3758
+ }
3759
+ }
3760
+
3761
+
3762
+ void FullCodeGenerator::EmitUnaryOperation(UnaryOperation* expr,
3763
+ const char* comment) {
3764
+ // TODO(svenpanne): Allowing format strings in Comment would be nice here...
3765
+ Comment cmt(masm_, comment);
3766
+ bool can_overwrite = expr->expression()->ResultOverwriteAllowed();
3767
+ UnaryOverwriteMode overwrite =
3768
+ can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE;
3769
+ UnaryOpStub stub(expr->op(), overwrite);
3770
+ // UnaryOpStub expects the argument to be in the
3771
+ // accumulator register eax.
3772
+ VisitForAccumulatorValue(expr->expression());
3773
+ SetSourcePosition(expr->position());
3774
+ EmitCallIC(stub.GetCode(), NULL, expr->id());
3775
+ context()->Plug(eax);
3776
+ }
3777
+
3778
+
3779
+ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
3780
+ Comment cmnt(masm_, "[ CountOperation");
3781
+ SetSourcePosition(expr->position());
3782
+
3783
+ // Invalid left-hand sides are rewritten to have a 'throw ReferenceError'
3784
+ // as the left-hand side.
3785
+ if (!expr->expression()->IsValidLeftHandSide()) {
3786
+ VisitForEffect(expr->expression());
3787
+ return;
3788
+ }
3789
+
3790
+ // Expression can only be a property, a global or a (parameter or local)
3791
+ // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY.
3792
+ enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
3793
+ LhsKind assign_type = VARIABLE;
3794
+ Property* prop = expr->expression()->AsProperty();
3795
+ // In case of a property we use the uninitialized expression context
3796
+ // of the key to detect a named property.
3797
+ if (prop != NULL) {
3798
+ assign_type =
3799
+ (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY;
3800
+ }
3801
+
3802
+ // Evaluate expression and get value.
3803
+ if (assign_type == VARIABLE) {
3804
+ ASSERT(expr->expression()->AsVariableProxy()->var() != NULL);
3805
+ AccumulatorValueContext context(this);
3806
+ EmitVariableLoad(expr->expression()->AsVariableProxy()->var());
3807
+ } else {
3808
+ // Reserve space for result of postfix operation.
3809
+ if (expr->is_postfix() && !context()->IsEffect()) {
3810
+ __ push(Immediate(Smi::FromInt(0)));
3811
+ }
3812
+ if (assign_type == NAMED_PROPERTY) {
3813
+ // Put the object both on the stack and in the accumulator.
3814
+ VisitForAccumulatorValue(prop->obj());
3815
+ __ push(eax);
3816
+ EmitNamedPropertyLoad(prop);
3817
+ } else {
3818
+ if (prop->is_arguments_access()) {
3819
+ VariableProxy* obj_proxy = prop->obj()->AsVariableProxy();
3820
+ MemOperand slot_operand =
3821
+ EmitSlotSearch(obj_proxy->var()->AsSlot(), ecx);
3822
+ __ push(slot_operand);
3823
+ __ SafeSet(eax, Immediate(prop->key()->AsLiteral()->handle()));
3824
+ } else {
3825
+ VisitForStackValue(prop->obj());
3826
+ VisitForAccumulatorValue(prop->key());
3827
+ }
3828
+ __ mov(edx, Operand(esp, 0));
3829
+ __ push(eax);
3830
+ EmitKeyedPropertyLoad(prop);
3831
+ }
3832
+ }
3833
+
3834
+ // We need a second deoptimization point after loading the value
3835
+ // in case evaluating the property load my have a side effect.
3836
+ if (assign_type == VARIABLE) {
3837
+ PrepareForBailout(expr->expression(), TOS_REG);
3838
+ } else {
3839
+ PrepareForBailoutForId(expr->CountId(), TOS_REG);
3840
+ }
3841
+
3842
+ // Call ToNumber only if operand is not a smi.
3843
+ Label no_conversion;
3844
+ if (ShouldInlineSmiCase(expr->op())) {
3845
+ __ test(eax, Immediate(kSmiTagMask));
3846
+ __ j(zero, &no_conversion, Label::kNear);
3847
+ }
3848
+ ToNumberStub convert_stub;
3849
+ __ CallStub(&convert_stub);
3850
+ __ bind(&no_conversion);
3851
+
3852
+ // Save result for postfix expressions.
3853
+ if (expr->is_postfix()) {
3854
+ if (!context()->IsEffect()) {
3855
+ // Save the result on the stack. If we have a named or keyed property
3856
+ // we store the result under the receiver that is currently on top
3857
+ // of the stack.
3858
+ switch (assign_type) {
3859
+ case VARIABLE:
3860
+ __ push(eax);
3861
+ break;
3862
+ case NAMED_PROPERTY:
3863
+ __ mov(Operand(esp, kPointerSize), eax);
3864
+ break;
3865
+ case KEYED_PROPERTY:
3866
+ __ mov(Operand(esp, 2 * kPointerSize), eax);
3867
+ break;
3868
+ }
3869
+ }
3870
+ }
3871
+
3872
+ // Inline smi case if we are in a loop.
3873
+ Label done, stub_call;
3874
+ JumpPatchSite patch_site(masm_);
3875
+
3876
+ if (ShouldInlineSmiCase(expr->op())) {
3877
+ if (expr->op() == Token::INC) {
3878
+ __ add(Operand(eax), Immediate(Smi::FromInt(1)));
3879
+ } else {
3880
+ __ sub(Operand(eax), Immediate(Smi::FromInt(1)));
3881
+ }
3882
+ __ j(overflow, &stub_call, Label::kNear);
3883
+ // We could eliminate this smi check if we split the code at
3884
+ // the first smi check before calling ToNumber.
3885
+ patch_site.EmitJumpIfSmi(eax, &done, Label::kNear);
3886
+
3887
+ __ bind(&stub_call);
3888
+ // Call stub. Undo operation first.
3889
+ if (expr->op() == Token::INC) {
3890
+ __ sub(Operand(eax), Immediate(Smi::FromInt(1)));
3891
+ } else {
3892
+ __ add(Operand(eax), Immediate(Smi::FromInt(1)));
3893
+ }
3894
+ }
3895
+
3896
+ // Record position before stub call.
3897
+ SetSourcePosition(expr->position());
3898
+
3899
+ // Call stub for +1/-1.
3900
+ __ mov(edx, eax);
3901
+ __ mov(eax, Immediate(Smi::FromInt(1)));
3902
+ BinaryOpStub stub(expr->binary_op(), NO_OVERWRITE);
3903
+ EmitCallIC(stub.GetCode(), &patch_site, expr->CountId());
3904
+ __ bind(&done);
3905
+
3906
+ // Store the value returned in eax.
3907
+ switch (assign_type) {
3908
+ case VARIABLE:
3909
+ if (expr->is_postfix()) {
3910
+ // Perform the assignment as if via '='.
3911
+ { EffectContext context(this);
3912
+ EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
3913
+ Token::ASSIGN);
3914
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
3915
+ context.Plug(eax);
3916
+ }
3917
+ // For all contexts except EffectContext We have the result on
3918
+ // top of the stack.
3919
+ if (!context()->IsEffect()) {
3920
+ context()->PlugTOS();
3921
+ }
3922
+ } else {
3923
+ // Perform the assignment as if via '='.
3924
+ EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
3925
+ Token::ASSIGN);
3926
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
3927
+ context()->Plug(eax);
3928
+ }
3929
+ break;
3930
+ case NAMED_PROPERTY: {
3931
+ __ mov(ecx, prop->key()->AsLiteral()->handle());
3932
+ __ pop(edx);
3933
+ Handle<Code> ic = is_strict_mode()
3934
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
3935
+ : isolate()->builtins()->StoreIC_Initialize();
3936
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
3937
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
3938
+ if (expr->is_postfix()) {
3939
+ if (!context()->IsEffect()) {
3940
+ context()->PlugTOS();
3941
+ }
3942
+ } else {
3943
+ context()->Plug(eax);
3944
+ }
3945
+ break;
3946
+ }
3947
+ case KEYED_PROPERTY: {
3948
+ __ pop(ecx);
3949
+ __ pop(edx);
3950
+ Handle<Code> ic = is_strict_mode()
3951
+ ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict()
3952
+ : isolate()->builtins()->KeyedStoreIC_Initialize();
3953
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
3954
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
3955
+ if (expr->is_postfix()) {
3956
+ // Result is on the stack
3957
+ if (!context()->IsEffect()) {
3958
+ context()->PlugTOS();
3959
+ }
3960
+ } else {
3961
+ context()->Plug(eax);
3962
+ }
3963
+ break;
3964
+ }
3965
+ }
3966
+ }
3967
+
3968
+
3969
+ void FullCodeGenerator::VisitForTypeofValue(Expression* expr) {
3970
+ VariableProxy* proxy = expr->AsVariableProxy();
3971
+ ASSERT(!context()->IsEffect());
3972
+ ASSERT(!context()->IsTest());
3973
+
3974
+ if (proxy != NULL && !proxy->var()->is_this() && proxy->var()->is_global()) {
3975
+ Comment cmnt(masm_, "Global variable");
3976
+ __ mov(eax, GlobalObjectOperand());
3977
+ __ mov(ecx, Immediate(proxy->name()));
3978
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
3979
+ // Use a regular load, not a contextual load, to avoid a reference
3980
+ // error.
3981
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber);
3982
+ PrepareForBailout(expr, TOS_REG);
3983
+ context()->Plug(eax);
3984
+ } else if (proxy != NULL &&
3985
+ proxy->var()->AsSlot() != NULL &&
3986
+ proxy->var()->AsSlot()->type() == Slot::LOOKUP) {
3987
+ Label done, slow;
3988
+
3989
+ // Generate code for loading from variables potentially shadowed
3990
+ // by eval-introduced variables.
3991
+ Slot* slot = proxy->var()->AsSlot();
3992
+ EmitDynamicLoadFromSlotFastCase(slot, INSIDE_TYPEOF, &slow, &done);
3993
+
3994
+ __ bind(&slow);
3995
+ __ push(esi);
3996
+ __ push(Immediate(proxy->name()));
3997
+ __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2);
3998
+ PrepareForBailout(expr, TOS_REG);
3999
+ __ bind(&done);
4000
+
4001
+ context()->Plug(eax);
4002
+ } else {
4003
+ // This expression cannot throw a reference error at the top level.
4004
+ context()->HandleExpression(expr);
4005
+ }
4006
+ }
4007
+
4008
+
4009
+ bool FullCodeGenerator::TryLiteralCompare(Token::Value op,
4010
+ Expression* left,
4011
+ Expression* right,
4012
+ Label* if_true,
4013
+ Label* if_false,
4014
+ Label* fall_through) {
4015
+ if (op != Token::EQ && op != Token::EQ_STRICT) return false;
4016
+
4017
+ // Check for the pattern: typeof <expression> == <string literal>.
4018
+ Literal* right_literal = right->AsLiteral();
4019
+ if (right_literal == NULL) return false;
4020
+ Handle<Object> right_literal_value = right_literal->handle();
4021
+ if (!right_literal_value->IsString()) return false;
4022
+ UnaryOperation* left_unary = left->AsUnaryOperation();
4023
+ if (left_unary == NULL || left_unary->op() != Token::TYPEOF) return false;
4024
+ Handle<String> check = Handle<String>::cast(right_literal_value);
4025
+
4026
+ { AccumulatorValueContext context(this);
4027
+ VisitForTypeofValue(left_unary->expression());
4028
+ }
4029
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
4030
+
4031
+ if (check->Equals(isolate()->heap()->number_symbol())) {
4032
+ __ JumpIfSmi(eax, if_true);
4033
+ __ cmp(FieldOperand(eax, HeapObject::kMapOffset),
4034
+ isolate()->factory()->heap_number_map());
4035
+ Split(equal, if_true, if_false, fall_through);
4036
+ } else if (check->Equals(isolate()->heap()->string_symbol())) {
4037
+ __ JumpIfSmi(eax, if_false);
4038
+ __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edx);
4039
+ __ j(above_equal, if_false);
4040
+ // Check for undetectable objects => false.
4041
+ __ test_b(FieldOperand(edx, Map::kBitFieldOffset),
4042
+ 1 << Map::kIsUndetectable);
4043
+ Split(zero, if_true, if_false, fall_through);
4044
+ } else if (check->Equals(isolate()->heap()->boolean_symbol())) {
4045
+ __ cmp(eax, isolate()->factory()->true_value());
4046
+ __ j(equal, if_true);
4047
+ __ cmp(eax, isolate()->factory()->false_value());
4048
+ Split(equal, if_true, if_false, fall_through);
4049
+ } else if (check->Equals(isolate()->heap()->undefined_symbol())) {
4050
+ __ cmp(eax, isolate()->factory()->undefined_value());
4051
+ __ j(equal, if_true);
4052
+ __ JumpIfSmi(eax, if_false);
4053
+ // Check for undetectable objects => true.
4054
+ __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset));
4055
+ __ movzx_b(ecx, FieldOperand(edx, Map::kBitFieldOffset));
4056
+ __ test(ecx, Immediate(1 << Map::kIsUndetectable));
4057
+ Split(not_zero, if_true, if_false, fall_through);
4058
+ } else if (check->Equals(isolate()->heap()->function_symbol())) {
4059
+ __ JumpIfSmi(eax, if_false);
4060
+ __ CmpObjectType(eax, FIRST_FUNCTION_CLASS_TYPE, edx);
4061
+ Split(above_equal, if_true, if_false, fall_through);
4062
+ } else if (check->Equals(isolate()->heap()->object_symbol())) {
4063
+ __ JumpIfSmi(eax, if_false);
4064
+ __ cmp(eax, isolate()->factory()->null_value());
4065
+ __ j(equal, if_true);
4066
+ __ CmpObjectType(eax, FIRST_JS_OBJECT_TYPE, edx);
4067
+ __ j(below, if_false);
4068
+ __ CmpInstanceType(edx, FIRST_FUNCTION_CLASS_TYPE);
4069
+ __ j(above_equal, if_false);
4070
+ // Check for undetectable objects => false.
4071
+ __ test_b(FieldOperand(edx, Map::kBitFieldOffset),
4072
+ 1 << Map::kIsUndetectable);
4073
+ Split(zero, if_true, if_false, fall_through);
4074
+ } else {
4075
+ if (if_false != fall_through) __ jmp(if_false);
4076
+ }
4077
+
4078
+ return true;
4079
+ }
4080
+
4081
+
4082
+ void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
4083
+ Comment cmnt(masm_, "[ CompareOperation");
4084
+ SetSourcePosition(expr->position());
4085
+
4086
+ // Always perform the comparison for its control flow. Pack the result
4087
+ // into the expression's context after the comparison is performed.
4088
+
4089
+ Label materialize_true, materialize_false;
4090
+ Label* if_true = NULL;
4091
+ Label* if_false = NULL;
4092
+ Label* fall_through = NULL;
4093
+ context()->PrepareTest(&materialize_true, &materialize_false,
4094
+ &if_true, &if_false, &fall_through);
4095
+
4096
+ // First we try a fast inlined version of the compare when one of
4097
+ // the operands is a literal.
4098
+ Token::Value op = expr->op();
4099
+ Expression* left = expr->left();
4100
+ Expression* right = expr->right();
4101
+ if (TryLiteralCompare(op, left, right, if_true, if_false, fall_through)) {
4102
+ context()->Plug(if_true, if_false);
4103
+ return;
4104
+ }
4105
+
4106
+ VisitForStackValue(expr->left());
4107
+ switch (expr->op()) {
4108
+ case Token::IN:
4109
+ VisitForStackValue(expr->right());
4110
+ __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION);
4111
+ PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
4112
+ __ cmp(eax, isolate()->factory()->true_value());
4113
+ Split(equal, if_true, if_false, fall_through);
4114
+ break;
4115
+
4116
+ case Token::INSTANCEOF: {
4117
+ VisitForStackValue(expr->right());
4118
+ InstanceofStub stub(InstanceofStub::kNoFlags);
4119
+ __ CallStub(&stub);
4120
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
4121
+ __ test(eax, Operand(eax));
4122
+ // The stub returns 0 for true.
4123
+ Split(zero, if_true, if_false, fall_through);
4124
+ break;
4125
+ }
4126
+
4127
+ default: {
4128
+ VisitForAccumulatorValue(expr->right());
4129
+ Condition cc = no_condition;
4130
+ bool strict = false;
4131
+ switch (op) {
4132
+ case Token::EQ_STRICT:
4133
+ strict = true;
4134
+ // Fall through
4135
+ case Token::EQ:
4136
+ cc = equal;
4137
+ __ pop(edx);
4138
+ break;
4139
+ case Token::LT:
4140
+ cc = less;
4141
+ __ pop(edx);
4142
+ break;
4143
+ case Token::GT:
4144
+ // Reverse left and right sizes to obtain ECMA-262 conversion order.
4145
+ cc = less;
4146
+ __ mov(edx, result_register());
4147
+ __ pop(eax);
4148
+ break;
4149
+ case Token::LTE:
4150
+ // Reverse left and right sizes to obtain ECMA-262 conversion order.
4151
+ cc = greater_equal;
4152
+ __ mov(edx, result_register());
4153
+ __ pop(eax);
4154
+ break;
4155
+ case Token::GTE:
4156
+ cc = greater_equal;
4157
+ __ pop(edx);
4158
+ break;
4159
+ case Token::IN:
4160
+ case Token::INSTANCEOF:
4161
+ default:
4162
+ UNREACHABLE();
4163
+ }
4164
+
4165
+ bool inline_smi_code = ShouldInlineSmiCase(op);
4166
+ JumpPatchSite patch_site(masm_);
4167
+ if (inline_smi_code) {
4168
+ Label slow_case;
4169
+ __ mov(ecx, Operand(edx));
4170
+ __ or_(ecx, Operand(eax));
4171
+ patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear);
4172
+ __ cmp(edx, Operand(eax));
4173
+ Split(cc, if_true, if_false, NULL);
4174
+ __ bind(&slow_case);
4175
+ }
4176
+
4177
+ // Record position and call the compare IC.
4178
+ SetSourcePosition(expr->position());
4179
+ Handle<Code> ic = CompareIC::GetUninitialized(op);
4180
+ EmitCallIC(ic, &patch_site, expr->id());
4181
+
4182
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
4183
+ __ test(eax, Operand(eax));
4184
+ Split(cc, if_true, if_false, fall_through);
4185
+ }
4186
+ }
4187
+
4188
+ // Convert the result of the comparison into one expected for this
4189
+ // expression's context.
4190
+ context()->Plug(if_true, if_false);
4191
+ }
4192
+
4193
+
4194
+ void FullCodeGenerator::VisitCompareToNull(CompareToNull* expr) {
4195
+ Label materialize_true, materialize_false;
4196
+ Label* if_true = NULL;
4197
+ Label* if_false = NULL;
4198
+ Label* fall_through = NULL;
4199
+ context()->PrepareTest(&materialize_true, &materialize_false,
4200
+ &if_true, &if_false, &fall_through);
4201
+
4202
+ VisitForAccumulatorValue(expr->expression());
4203
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
4204
+
4205
+ __ cmp(eax, isolate()->factory()->null_value());
4206
+ if (expr->is_strict()) {
4207
+ Split(equal, if_true, if_false, fall_through);
4208
+ } else {
4209
+ __ j(equal, if_true);
4210
+ __ cmp(eax, isolate()->factory()->undefined_value());
4211
+ __ j(equal, if_true);
4212
+ __ test(eax, Immediate(kSmiTagMask));
4213
+ __ j(zero, if_false);
4214
+ // It can be an undetectable object.
4215
+ __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset));
4216
+ __ movzx_b(edx, FieldOperand(edx, Map::kBitFieldOffset));
4217
+ __ test(edx, Immediate(1 << Map::kIsUndetectable));
4218
+ Split(not_zero, if_true, if_false, fall_through);
4219
+ }
4220
+ context()->Plug(if_true, if_false);
4221
+ }
4222
+
4223
+
4224
+ void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) {
4225
+ __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
4226
+ context()->Plug(eax);
4227
+ }
4228
+
4229
+
4230
+ Register FullCodeGenerator::result_register() {
4231
+ return eax;
4232
+ }
4233
+
4234
+
4235
+ Register FullCodeGenerator::context_register() {
4236
+ return esi;
4237
+ }
4238
+
4239
+
4240
+ void FullCodeGenerator::EmitCallIC(Handle<Code> ic,
4241
+ RelocInfo::Mode mode,
4242
+ unsigned ast_id) {
4243
+ ASSERT(mode == RelocInfo::CODE_TARGET ||
4244
+ mode == RelocInfo::CODE_TARGET_CONTEXT);
4245
+ switch (ic->kind()) {
4246
+ case Code::LOAD_IC:
4247
+ __ IncrementCounter(isolate()->counters()->named_load_full(), 1);
4248
+ break;
4249
+ case Code::KEYED_LOAD_IC:
4250
+ __ IncrementCounter(isolate()->counters()->keyed_load_full(), 1);
4251
+ break;
4252
+ case Code::STORE_IC:
4253
+ __ IncrementCounter(isolate()->counters()->named_store_full(), 1);
4254
+ break;
4255
+ case Code::KEYED_STORE_IC:
4256
+ __ IncrementCounter(isolate()->counters()->keyed_store_full(), 1);
4257
+ default:
4258
+ break;
4259
+ }
4260
+ __ call(ic, mode, ast_id);
4261
+ }
4262
+
4263
+
4264
+ void FullCodeGenerator::EmitCallIC(Handle<Code> ic,
4265
+ JumpPatchSite* patch_site,
4266
+ unsigned ast_id) {
4267
+ Counters* counters = isolate()->counters();
4268
+ switch (ic->kind()) {
4269
+ case Code::LOAD_IC:
4270
+ __ IncrementCounter(counters->named_load_full(), 1);
4271
+ break;
4272
+ case Code::KEYED_LOAD_IC:
4273
+ __ IncrementCounter(counters->keyed_load_full(), 1);
4274
+ break;
4275
+ case Code::STORE_IC:
4276
+ __ IncrementCounter(counters->named_store_full(), 1);
4277
+ break;
4278
+ case Code::KEYED_STORE_IC:
4279
+ __ IncrementCounter(counters->keyed_store_full(), 1);
4280
+ default:
4281
+ break;
4282
+ }
4283
+ __ call(ic, RelocInfo::CODE_TARGET, ast_id);
4284
+ if (patch_site != NULL && patch_site->is_bound()) {
4285
+ patch_site->EmitPatchInfo();
4286
+ } else {
4287
+ __ nop(); // Signals no inlined code.
4288
+ }
4289
+ }
4290
+
4291
+
4292
+ void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) {
4293
+ ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset);
4294
+ __ mov(Operand(ebp, frame_offset), value);
4295
+ }
4296
+
4297
+
4298
+ void FullCodeGenerator::LoadContextField(Register dst, int context_index) {
4299
+ __ mov(dst, ContextOperand(esi, context_index));
4300
+ }
4301
+
4302
+
4303
+ // ----------------------------------------------------------------------------
4304
+ // Non-local control flow support.
4305
+
4306
+ void FullCodeGenerator::EnterFinallyBlock() {
4307
+ // Cook return address on top of stack (smi encoded Code* delta)
4308
+ ASSERT(!result_register().is(edx));
4309
+ __ mov(edx, Operand(esp, 0));
4310
+ __ sub(Operand(edx), Immediate(masm_->CodeObject()));
4311
+ ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize);
4312
+ ASSERT_EQ(0, kSmiTag);
4313
+ __ add(edx, Operand(edx)); // Convert to smi.
4314
+ __ mov(Operand(esp, 0), edx);
4315
+ // Store result register while executing finally block.
4316
+ __ push(result_register());
4317
+ }
4318
+
4319
+
4320
+ void FullCodeGenerator::ExitFinallyBlock() {
4321
+ ASSERT(!result_register().is(edx));
4322
+ // Restore result register from stack.
4323
+ __ pop(result_register());
4324
+ // Uncook return address.
4325
+ __ mov(edx, Operand(esp, 0));
4326
+ __ sar(edx, 1); // Convert smi to int.
4327
+ __ add(Operand(edx), Immediate(masm_->CodeObject()));
4328
+ __ mov(Operand(esp, 0), edx);
4329
+ // And return.
4330
+ __ ret(0);
4331
+ }
4332
+
4333
+
4334
+ #undef __
4335
+
4336
+ } } // namespace v8::internal
4337
+
4338
+ #endif // V8_TARGET_ARCH_IA32