jbarnette-johnson 1.0.0.200806240111 → 1.0.0.200807291507

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. data/MANIFEST +1 -0
  2. data/Rakefile +3 -10
  3. data/bin/johnson +2 -1
  4. data/ext/spidermonkey/context.c +3 -4
  5. data/ext/spidermonkey/context.h +1 -1
  6. data/ext/spidermonkey/conversions.c +39 -33
  7. data/ext/spidermonkey/debugger.c +5 -5
  8. data/ext/spidermonkey/immutable_node.c.erb +11 -11
  9. data/ext/spidermonkey/jroot.h +4 -4
  10. data/ext/spidermonkey/js_land_proxy.c +9 -8
  11. data/ext/spidermonkey/ruby_land_proxy.c +5 -4
  12. data/ext/spidermonkey/runtime.c +1 -1
  13. data/johnson.gemspec +36 -0
  14. data/lib/hoe.rb +0 -7
  15. data/lib/johnson/cli/options.rb +10 -4
  16. data/lib/johnson/spidermonkey/runtime.rb +2 -2
  17. data/lib/johnson/version.rb +4 -2
  18. data/lib/johnson.rb +1 -0
  19. data/test/johnson/runtime_test.rb +11 -0
  20. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +6 -0
  21. data/vendor/spidermonkey/.cvsignore +9 -0
  22. data/vendor/spidermonkey/Makefile.in +462 -0
  23. data/vendor/spidermonkey/Makefile.ref +364 -0
  24. data/vendor/spidermonkey/README.html +820 -0
  25. data/vendor/spidermonkey/SpiderMonkey.rsp +12 -0
  26. data/vendor/spidermonkey/Y.js +19 -0
  27. data/vendor/spidermonkey/build.mk +43 -0
  28. data/vendor/spidermonkey/config/AIX4.1.mk +65 -0
  29. data/vendor/spidermonkey/config/AIX4.2.mk +64 -0
  30. data/vendor/spidermonkey/config/AIX4.3.mk +65 -0
  31. data/vendor/spidermonkey/config/Darwin.mk +83 -0
  32. data/vendor/spidermonkey/config/Darwin1.3.mk +81 -0
  33. data/vendor/spidermonkey/config/Darwin1.4.mk +41 -0
  34. data/vendor/spidermonkey/config/Darwin5.2.mk +81 -0
  35. data/vendor/spidermonkey/config/Darwin5.3.mk +81 -0
  36. data/vendor/spidermonkey/config/HP-UXB.10.10.mk +77 -0
  37. data/vendor/spidermonkey/config/HP-UXB.10.20.mk +77 -0
  38. data/vendor/spidermonkey/config/HP-UXB.11.00.mk +80 -0
  39. data/vendor/spidermonkey/config/IRIX.mk +87 -0
  40. data/vendor/spidermonkey/config/IRIX5.3.mk +44 -0
  41. data/vendor/spidermonkey/config/IRIX6.1.mk +44 -0
  42. data/vendor/spidermonkey/config/IRIX6.2.mk +44 -0
  43. data/vendor/spidermonkey/config/IRIX6.3.mk +44 -0
  44. data/vendor/spidermonkey/config/IRIX6.5.mk +44 -0
  45. data/vendor/spidermonkey/config/Linux_All.mk +103 -0
  46. data/vendor/spidermonkey/config/Mac_OS10.0.mk +82 -0
  47. data/vendor/spidermonkey/config/OSF1V4.0.mk +72 -0
  48. data/vendor/spidermonkey/config/OSF1V5.0.mk +69 -0
  49. data/vendor/spidermonkey/config/SunOS4.1.4.mk +101 -0
  50. data/vendor/spidermonkey/config/SunOS5.10.mk +50 -0
  51. data/vendor/spidermonkey/config/SunOS5.3.mk +91 -0
  52. data/vendor/spidermonkey/config/SunOS5.4.mk +92 -0
  53. data/vendor/spidermonkey/config/SunOS5.5.1.mk +44 -0
  54. data/vendor/spidermonkey/config/SunOS5.5.mk +87 -0
  55. data/vendor/spidermonkey/config/SunOS5.6.mk +89 -0
  56. data/vendor/spidermonkey/config/SunOS5.7.mk +44 -0
  57. data/vendor/spidermonkey/config/SunOS5.8.mk +44 -0
  58. data/vendor/spidermonkey/config/SunOS5.9.mk +44 -0
  59. data/vendor/spidermonkey/config/WINNT4.0.mk +117 -0
  60. data/vendor/spidermonkey/config/WINNT5.0.mk +117 -0
  61. data/vendor/spidermonkey/config/WINNT5.1.mk +117 -0
  62. data/vendor/spidermonkey/config/WINNT5.2.mk +117 -0
  63. data/vendor/spidermonkey/config/WINNT6.0.mk +117 -0
  64. data/vendor/spidermonkey/config/dgux.mk +64 -0
  65. data/vendor/spidermonkey/config.mk +192 -0
  66. data/vendor/spidermonkey/editline/Makefile.ref +144 -0
  67. data/vendor/spidermonkey/editline/README +83 -0
  68. data/vendor/spidermonkey/editline/editline.3 +175 -0
  69. data/vendor/spidermonkey/editline/editline.c +1369 -0
  70. data/vendor/spidermonkey/editline/editline.h +135 -0
  71. data/vendor/spidermonkey/editline/sysunix.c +182 -0
  72. data/vendor/spidermonkey/editline/unix.h +82 -0
  73. data/vendor/spidermonkey/fdlibm/.cvsignore +7 -0
  74. data/vendor/spidermonkey/fdlibm/Makefile.in +127 -0
  75. data/vendor/spidermonkey/fdlibm/Makefile.ref +192 -0
  76. data/vendor/spidermonkey/fdlibm/e_acos.c +147 -0
  77. data/vendor/spidermonkey/fdlibm/e_acosh.c +105 -0
  78. data/vendor/spidermonkey/fdlibm/e_asin.c +156 -0
  79. data/vendor/spidermonkey/fdlibm/e_atan2.c +165 -0
  80. data/vendor/spidermonkey/fdlibm/e_atanh.c +110 -0
  81. data/vendor/spidermonkey/fdlibm/e_cosh.c +133 -0
  82. data/vendor/spidermonkey/fdlibm/e_exp.c +202 -0
  83. data/vendor/spidermonkey/fdlibm/e_fmod.c +184 -0
  84. data/vendor/spidermonkey/fdlibm/e_gamma.c +71 -0
  85. data/vendor/spidermonkey/fdlibm/e_gamma_r.c +70 -0
  86. data/vendor/spidermonkey/fdlibm/e_hypot.c +173 -0
  87. data/vendor/spidermonkey/fdlibm/e_j0.c +524 -0
  88. data/vendor/spidermonkey/fdlibm/e_j1.c +523 -0
  89. data/vendor/spidermonkey/fdlibm/e_jn.c +315 -0
  90. data/vendor/spidermonkey/fdlibm/e_lgamma.c +71 -0
  91. data/vendor/spidermonkey/fdlibm/e_lgamma_r.c +347 -0
  92. data/vendor/spidermonkey/fdlibm/e_log.c +184 -0
  93. data/vendor/spidermonkey/fdlibm/e_log10.c +134 -0
  94. data/vendor/spidermonkey/fdlibm/e_pow.c +386 -0
  95. data/vendor/spidermonkey/fdlibm/e_rem_pio2.c +222 -0
  96. data/vendor/spidermonkey/fdlibm/e_remainder.c +120 -0
  97. data/vendor/spidermonkey/fdlibm/e_scalb.c +89 -0
  98. data/vendor/spidermonkey/fdlibm/e_sinh.c +122 -0
  99. data/vendor/spidermonkey/fdlibm/e_sqrt.c +497 -0
  100. data/vendor/spidermonkey/fdlibm/fdlibm.h +273 -0
  101. data/vendor/spidermonkey/fdlibm/fdlibm.mak +1453 -0
  102. data/vendor/spidermonkey/fdlibm/fdlibm.mdp +0 -0
  103. data/vendor/spidermonkey/fdlibm/k_cos.c +135 -0
  104. data/vendor/spidermonkey/fdlibm/k_rem_pio2.c +354 -0
  105. data/vendor/spidermonkey/fdlibm/k_sin.c +114 -0
  106. data/vendor/spidermonkey/fdlibm/k_standard.c +785 -0
  107. data/vendor/spidermonkey/fdlibm/k_tan.c +170 -0
  108. data/vendor/spidermonkey/fdlibm/s_asinh.c +101 -0
  109. data/vendor/spidermonkey/fdlibm/s_atan.c +175 -0
  110. data/vendor/spidermonkey/fdlibm/s_cbrt.c +133 -0
  111. data/vendor/spidermonkey/fdlibm/s_ceil.c +120 -0
  112. data/vendor/spidermonkey/fdlibm/s_copysign.c +72 -0
  113. data/vendor/spidermonkey/fdlibm/s_cos.c +118 -0
  114. data/vendor/spidermonkey/fdlibm/s_erf.c +356 -0
  115. data/vendor/spidermonkey/fdlibm/s_expm1.c +267 -0
  116. data/vendor/spidermonkey/fdlibm/s_fabs.c +70 -0
  117. data/vendor/spidermonkey/fdlibm/s_finite.c +71 -0
  118. data/vendor/spidermonkey/fdlibm/s_floor.c +121 -0
  119. data/vendor/spidermonkey/fdlibm/s_frexp.c +99 -0
  120. data/vendor/spidermonkey/fdlibm/s_ilogb.c +85 -0
  121. data/vendor/spidermonkey/fdlibm/s_isnan.c +74 -0
  122. data/vendor/spidermonkey/fdlibm/s_ldexp.c +66 -0
  123. data/vendor/spidermonkey/fdlibm/s_lib_version.c +73 -0
  124. data/vendor/spidermonkey/fdlibm/s_log1p.c +211 -0
  125. data/vendor/spidermonkey/fdlibm/s_logb.c +79 -0
  126. data/vendor/spidermonkey/fdlibm/s_matherr.c +64 -0
  127. data/vendor/spidermonkey/fdlibm/s_modf.c +132 -0
  128. data/vendor/spidermonkey/fdlibm/s_nextafter.c +124 -0
  129. data/vendor/spidermonkey/fdlibm/s_rint.c +131 -0
  130. data/vendor/spidermonkey/fdlibm/s_scalbn.c +107 -0
  131. data/vendor/spidermonkey/fdlibm/s_signgam.c +40 -0
  132. data/vendor/spidermonkey/fdlibm/s_significand.c +68 -0
  133. data/vendor/spidermonkey/fdlibm/s_sin.c +118 -0
  134. data/vendor/spidermonkey/fdlibm/s_tan.c +112 -0
  135. data/vendor/spidermonkey/fdlibm/s_tanh.c +122 -0
  136. data/vendor/spidermonkey/fdlibm/w_acos.c +78 -0
  137. data/vendor/spidermonkey/fdlibm/w_acosh.c +78 -0
  138. data/vendor/spidermonkey/fdlibm/w_asin.c +80 -0
  139. data/vendor/spidermonkey/fdlibm/w_atan2.c +79 -0
  140. data/vendor/spidermonkey/fdlibm/w_atanh.c +81 -0
  141. data/vendor/spidermonkey/fdlibm/w_cosh.c +77 -0
  142. data/vendor/spidermonkey/fdlibm/w_exp.c +88 -0
  143. data/vendor/spidermonkey/fdlibm/w_fmod.c +78 -0
  144. data/vendor/spidermonkey/fdlibm/w_gamma.c +85 -0
  145. data/vendor/spidermonkey/fdlibm/w_gamma_r.c +81 -0
  146. data/vendor/spidermonkey/fdlibm/w_hypot.c +78 -0
  147. data/vendor/spidermonkey/fdlibm/w_j0.c +105 -0
  148. data/vendor/spidermonkey/fdlibm/w_j1.c +106 -0
  149. data/vendor/spidermonkey/fdlibm/w_jn.c +128 -0
  150. data/vendor/spidermonkey/fdlibm/w_lgamma.c +85 -0
  151. data/vendor/spidermonkey/fdlibm/w_lgamma_r.c +81 -0
  152. data/vendor/spidermonkey/fdlibm/w_log.c +78 -0
  153. data/vendor/spidermonkey/fdlibm/w_log10.c +81 -0
  154. data/vendor/spidermonkey/fdlibm/w_pow.c +99 -0
  155. data/vendor/spidermonkey/fdlibm/w_remainder.c +77 -0
  156. data/vendor/spidermonkey/fdlibm/w_scalb.c +95 -0
  157. data/vendor/spidermonkey/fdlibm/w_sinh.c +77 -0
  158. data/vendor/spidermonkey/fdlibm/w_sqrt.c +77 -0
  159. data/vendor/spidermonkey/javascript-trace.d +73 -0
  160. data/vendor/spidermonkey/js.c +3951 -0
  161. data/vendor/spidermonkey/js.mak +4438 -0
  162. data/vendor/spidermonkey/js.mdp +0 -0
  163. data/vendor/spidermonkey/js.msg +307 -0
  164. data/vendor/spidermonkey/js.pkg +2 -0
  165. data/vendor/spidermonkey/js3240.rc +79 -0
  166. data/vendor/spidermonkey/jsOS240.def +654 -0
  167. data/vendor/spidermonkey/jsapi.c +5836 -0
  168. data/vendor/spidermonkey/jsapi.h +2624 -0
  169. data/vendor/spidermonkey/jsarena.c +450 -0
  170. data/vendor/spidermonkey/jsarena.h +318 -0
  171. data/vendor/spidermonkey/jsarray.c +2988 -0
  172. data/vendor/spidermonkey/jsarray.h +124 -0
  173. data/vendor/spidermonkey/jsatom.c +1045 -0
  174. data/vendor/spidermonkey/jsatom.h +442 -0
  175. data/vendor/spidermonkey/jsbit.h +253 -0
  176. data/vendor/spidermonkey/jsbool.c +176 -0
  177. data/vendor/spidermonkey/jsbool.h +73 -0
  178. data/vendor/spidermonkey/jsclist.h +139 -0
  179. data/vendor/spidermonkey/jscntxt.c +1348 -0
  180. data/vendor/spidermonkey/jscntxt.h +1120 -0
  181. data/vendor/spidermonkey/jscompat.h +57 -0
  182. data/vendor/spidermonkey/jsconfig.h +248 -0
  183. data/vendor/spidermonkey/jsconfig.mk +181 -0
  184. data/vendor/spidermonkey/jscpucfg.c +383 -0
  185. data/vendor/spidermonkey/jscpucfg.h +212 -0
  186. data/vendor/spidermonkey/jsdate.c +2398 -0
  187. data/vendor/spidermonkey/jsdate.h +124 -0
  188. data/vendor/spidermonkey/jsdbgapi.c +1799 -0
  189. data/vendor/spidermonkey/jsdbgapi.h +464 -0
  190. data/vendor/spidermonkey/jsdhash.c +868 -0
  191. data/vendor/spidermonkey/jsdhash.h +592 -0
  192. data/vendor/spidermonkey/jsdtoa.c +3167 -0
  193. data/vendor/spidermonkey/jsdtoa.h +130 -0
  194. data/vendor/spidermonkey/jsdtracef.c +317 -0
  195. data/vendor/spidermonkey/jsdtracef.h +77 -0
  196. data/vendor/spidermonkey/jsemit.c +6909 -0
  197. data/vendor/spidermonkey/jsemit.h +741 -0
  198. data/vendor/spidermonkey/jsexn.c +1371 -0
  199. data/vendor/spidermonkey/jsexn.h +96 -0
  200. data/vendor/spidermonkey/jsfile.c +2736 -0
  201. data/vendor/spidermonkey/jsfile.h +56 -0
  202. data/vendor/spidermonkey/jsfile.msg +90 -0
  203. data/vendor/spidermonkey/jsfun.c +2634 -0
  204. data/vendor/spidermonkey/jsfun.h +254 -0
  205. data/vendor/spidermonkey/jsgc.c +3554 -0
  206. data/vendor/spidermonkey/jsgc.h +403 -0
  207. data/vendor/spidermonkey/jshash.c +476 -0
  208. data/vendor/spidermonkey/jshash.h +151 -0
  209. data/vendor/spidermonkey/jsify.pl +485 -0
  210. data/vendor/spidermonkey/jsinterp.c +6981 -0
  211. data/vendor/spidermonkey/jsinterp.h +521 -0
  212. data/vendor/spidermonkey/jsinvoke.c +43 -0
  213. data/vendor/spidermonkey/jsiter.c +1067 -0
  214. data/vendor/spidermonkey/jsiter.h +122 -0
  215. data/vendor/spidermonkey/jskeyword.tbl +124 -0
  216. data/vendor/spidermonkey/jskwgen.c +460 -0
  217. data/vendor/spidermonkey/jslibmath.h +266 -0
  218. data/vendor/spidermonkey/jslock.c +1309 -0
  219. data/vendor/spidermonkey/jslock.h +313 -0
  220. data/vendor/spidermonkey/jslocko.asm +60 -0
  221. data/vendor/spidermonkey/jslog2.c +94 -0
  222. data/vendor/spidermonkey/jslong.c +264 -0
  223. data/vendor/spidermonkey/jslong.h +412 -0
  224. data/vendor/spidermonkey/jsmath.c +568 -0
  225. data/vendor/spidermonkey/jsmath.h +57 -0
  226. data/vendor/spidermonkey/jsnum.c +1228 -0
  227. data/vendor/spidermonkey/jsnum.h +283 -0
  228. data/vendor/spidermonkey/jsobj.c +5266 -0
  229. data/vendor/spidermonkey/jsobj.h +709 -0
  230. data/vendor/spidermonkey/jsopcode.c +5245 -0
  231. data/vendor/spidermonkey/jsopcode.h +394 -0
  232. data/vendor/spidermonkey/jsopcode.tbl +523 -0
  233. data/vendor/spidermonkey/jsotypes.h +202 -0
  234. data/vendor/spidermonkey/jsparse.c +6680 -0
  235. data/vendor/spidermonkey/jsparse.h +511 -0
  236. data/vendor/spidermonkey/jsprf.c +1262 -0
  237. data/vendor/spidermonkey/jsprf.h +150 -0
  238. data/vendor/spidermonkey/jsproto.tbl +128 -0
  239. data/vendor/spidermonkey/jsprvtd.h +267 -0
  240. data/vendor/spidermonkey/jspubtd.h +744 -0
  241. data/vendor/spidermonkey/jsregexp.c +4352 -0
  242. data/vendor/spidermonkey/jsregexp.h +183 -0
  243. data/vendor/spidermonkey/jsreops.tbl +145 -0
  244. data/vendor/spidermonkey/jsscan.c +2003 -0
  245. data/vendor/spidermonkey/jsscan.h +387 -0
  246. data/vendor/spidermonkey/jsscope.c +1948 -0
  247. data/vendor/spidermonkey/jsscope.h +418 -0
  248. data/vendor/spidermonkey/jsscript.c +1832 -0
  249. data/vendor/spidermonkey/jsscript.h +287 -0
  250. data/vendor/spidermonkey/jsshell.msg +50 -0
  251. data/vendor/spidermonkey/jsstddef.h +83 -0
  252. data/vendor/spidermonkey/jsstr.c +5004 -0
  253. data/vendor/spidermonkey/jsstr.h +641 -0
  254. data/vendor/spidermonkey/jstypes.h +475 -0
  255. data/vendor/spidermonkey/jsutil.c +345 -0
  256. data/vendor/spidermonkey/jsutil.h +157 -0
  257. data/vendor/spidermonkey/jsxdrapi.c +800 -0
  258. data/vendor/spidermonkey/jsxdrapi.h +218 -0
  259. data/vendor/spidermonkey/jsxml.c +8471 -0
  260. data/vendor/spidermonkey/jsxml.h +349 -0
  261. data/vendor/spidermonkey/lock_SunOS.s +119 -0
  262. data/vendor/spidermonkey/perfect.js +39 -0
  263. data/vendor/spidermonkey/plify_jsdhash.sed +36 -0
  264. data/vendor/spidermonkey/prmjtime.c +846 -0
  265. data/vendor/spidermonkey/prmjtime.h +103 -0
  266. data/vendor/spidermonkey/resource.h +15 -0
  267. data/vendor/spidermonkey/rules.mk +197 -0
  268. data/vendor/spidermonkey/win32.order +384 -0
  269. metadata +4 -3
@@ -0,0 +1,124 @@
1
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ *
3
+ * ***** BEGIN LICENSE BLOCK *****
4
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
+ *
6
+ * The contents of this file are subject to the Mozilla Public License Version
7
+ * 1.1 (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ * http://www.mozilla.org/MPL/
10
+ *
11
+ * Software distributed under the License is distributed on an "AS IS" basis,
12
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
+ * for the specific language governing rights and limitations under the
14
+ * License.
15
+ *
16
+ * The Original Code is Mozilla Communicator client code, released
17
+ * March 31, 1998.
18
+ *
19
+ * The Initial Developer of the Original Code is
20
+ * Netscape Communications Corporation.
21
+ * Portions created by the Initial Developer are Copyright (C) 1998
22
+ * the Initial Developer. All Rights Reserved.
23
+ *
24
+ * Contributor(s):
25
+ *
26
+ * Alternatively, the contents of this file may be used under the terms of
27
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
28
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
+ * in which case the provisions of the GPL or the LGPL are applicable instead
30
+ * of those above. If you wish to allow use of your version of this file only
31
+ * under the terms of either the GPL or the LGPL, and not to allow others to
32
+ * use your version of this file under the terms of the MPL, indicate your
33
+ * decision by deleting the provisions above and replace them with the notice
34
+ * and other provisions required by the GPL or the LGPL. If you do not delete
35
+ * the provisions above, a recipient may use your version of this file under
36
+ * the terms of any one of the MPL, the GPL or the LGPL.
37
+ *
38
+ * ***** END LICENSE BLOCK ***** */
39
+
40
+ /*
41
+ * JS Date class interface.
42
+ */
43
+
44
+ #ifndef jsdate_h___
45
+ #define jsdate_h___
46
+
47
+ JS_BEGIN_EXTERN_C
48
+
49
+ extern JSClass js_DateClass;
50
+
51
+ extern JSObject *
52
+ js_InitDateClass(JSContext *cx, JSObject *obj);
53
+
54
+ /*
55
+ * These functions provide a C interface to the date/time object
56
+ */
57
+
58
+ /*
59
+ * Construct a new Date Object from a time value given in milliseconds UTC
60
+ * since the epoch.
61
+ */
62
+ extern JS_FRIEND_API(JSObject*)
63
+ js_NewDateObjectMsec(JSContext* cx, jsdouble msec_time);
64
+
65
+ /*
66
+ * Construct a new Date Object from an exploded local time value.
67
+ *
68
+ * Assert that mon < 12 to help catch off-by-one user errors, which are common
69
+ * due to the 0-based month numbering copied into JS from Java (java.util.Date
70
+ * in 1995). js_DateSetMonth (below) likewise asserts month < 12.
71
+ */
72
+ extern JS_FRIEND_API(JSObject*)
73
+ js_NewDateObject(JSContext* cx, int year, int mon, int mday,
74
+ int hour, int min, int sec);
75
+
76
+ /*
77
+ * Detect whether the internal date value is NaN. (Because failure is
78
+ * out-of-band for js_DateGet*)
79
+ */
80
+ extern JS_FRIEND_API(JSBool)
81
+ js_DateIsValid(JSContext *cx, JSObject* obj);
82
+
83
+ extern JS_FRIEND_API(int)
84
+ js_DateGetYear(JSContext *cx, JSObject* obj);
85
+
86
+ extern JS_FRIEND_API(int)
87
+ js_DateGetMonth(JSContext *cx, JSObject* obj);
88
+
89
+ extern JS_FRIEND_API(int)
90
+ js_DateGetDate(JSContext *cx, JSObject* obj);
91
+
92
+ extern JS_FRIEND_API(int)
93
+ js_DateGetHours(JSContext *cx, JSObject* obj);
94
+
95
+ extern JS_FRIEND_API(int)
96
+ js_DateGetMinutes(JSContext *cx, JSObject* obj);
97
+
98
+ extern JS_FRIEND_API(int)
99
+ js_DateGetSeconds(JSContext *cx, JSObject* obj);
100
+
101
+ extern JS_FRIEND_API(void)
102
+ js_DateSetYear(JSContext *cx, JSObject *obj, int year);
103
+
104
+ extern JS_FRIEND_API(void)
105
+ js_DateSetMonth(JSContext *cx, JSObject *obj, int month);
106
+
107
+ extern JS_FRIEND_API(void)
108
+ js_DateSetDate(JSContext *cx, JSObject *obj, int date);
109
+
110
+ extern JS_FRIEND_API(void)
111
+ js_DateSetHours(JSContext *cx, JSObject *obj, int hours);
112
+
113
+ extern JS_FRIEND_API(void)
114
+ js_DateSetMinutes(JSContext *cx, JSObject *obj, int minutes);
115
+
116
+ extern JS_FRIEND_API(void)
117
+ js_DateSetSeconds(JSContext *cx, JSObject *obj, int seconds);
118
+
119
+ extern JS_FRIEND_API(jsdouble)
120
+ js_DateGetMsecSinceEpoch(JSContext *cx, JSObject *obj);
121
+
122
+ JS_END_EXTERN_C
123
+
124
+ #endif /* jsdate_h___ */
@@ -0,0 +1,1799 @@
1
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ * vim: set ts=8 sw=4 et tw=78:
3
+ *
4
+ * ***** BEGIN LICENSE BLOCK *****
5
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6
+ *
7
+ * The contents of this file are subject to the Mozilla Public License Version
8
+ * 1.1 (the "License"); you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ * http://www.mozilla.org/MPL/
11
+ *
12
+ * Software distributed under the License is distributed on an "AS IS" basis,
13
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14
+ * for the specific language governing rights and limitations under the
15
+ * License.
16
+ *
17
+ * The Original Code is Mozilla Communicator client code, released
18
+ * March 31, 1998.
19
+ *
20
+ * The Initial Developer of the Original Code is
21
+ * Netscape Communications Corporation.
22
+ * Portions created by the Initial Developer are Copyright (C) 1998
23
+ * the Initial Developer. All Rights Reserved.
24
+ *
25
+ * Contributor(s):
26
+ *
27
+ * Alternatively, the contents of this file may be used under the terms of
28
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
29
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30
+ * in which case the provisions of the GPL or the LGPL are applicable instead
31
+ * of those above. If you wish to allow use of your version of this file only
32
+ * under the terms of either the GPL or the LGPL, and not to allow others to
33
+ * use your version of this file under the terms of the MPL, indicate your
34
+ * decision by deleting the provisions above and replace them with the notice
35
+ * and other provisions required by the GPL or the LGPL. If you do not delete
36
+ * the provisions above, a recipient may use your version of this file under
37
+ * the terms of any one of the MPL, the GPL or the LGPL.
38
+ *
39
+ * ***** END LICENSE BLOCK ***** */
40
+
41
+ /*
42
+ * JS debugging API.
43
+ */
44
+ #include "jsstddef.h"
45
+ #include <string.h>
46
+ #include "jstypes.h"
47
+ #include "jsutil.h" /* Added by JSIFY */
48
+ #include "jsclist.h"
49
+ #include "jsapi.h"
50
+ #include "jscntxt.h"
51
+ #include "jsconfig.h"
52
+ #include "jsdbgapi.h"
53
+ #include "jsemit.h"
54
+ #include "jsfun.h"
55
+ #include "jsgc.h"
56
+ #include "jsinterp.h"
57
+ #include "jslock.h"
58
+ #include "jsobj.h"
59
+ #include "jsopcode.h"
60
+ #include "jsparse.h"
61
+ #include "jsscope.h"
62
+ #include "jsscript.h"
63
+ #include "jsstr.h"
64
+
65
+ typedef struct JSTrap {
66
+ JSCList links;
67
+ JSScript *script;
68
+ jsbytecode *pc;
69
+ JSOp op;
70
+ JSTrapHandler handler;
71
+ void *closure;
72
+ } JSTrap;
73
+
74
+ #define DBG_LOCK(rt) JS_ACQUIRE_LOCK((rt)->debuggerLock)
75
+ #define DBG_UNLOCK(rt) JS_RELEASE_LOCK((rt)->debuggerLock)
76
+ #define DBG_LOCK_EVAL(rt,expr) (DBG_LOCK(rt), (expr), DBG_UNLOCK(rt))
77
+
78
+ /*
79
+ * NB: FindTrap must be called with rt->debuggerLock acquired.
80
+ */
81
+ static JSTrap *
82
+ FindTrap(JSRuntime *rt, JSScript *script, jsbytecode *pc)
83
+ {
84
+ JSTrap *trap;
85
+
86
+ for (trap = (JSTrap *)rt->trapList.next;
87
+ trap != (JSTrap *)&rt->trapList;
88
+ trap = (JSTrap *)trap->links.next) {
89
+ if (trap->script == script && trap->pc == pc)
90
+ return trap;
91
+ }
92
+ return NULL;
93
+ }
94
+
95
+ jsbytecode *
96
+ js_UntrapScriptCode(JSContext *cx, JSScript *script)
97
+ {
98
+ jsbytecode *code;
99
+ JSRuntime *rt;
100
+ JSTrap *trap;
101
+
102
+ code = script->code;
103
+ rt = cx->runtime;
104
+ DBG_LOCK(rt);
105
+ for (trap = (JSTrap *)rt->trapList.next;
106
+ trap != (JSTrap *)&rt->trapList;
107
+ trap = (JSTrap *)trap->links.next) {
108
+ if (trap->script == script &&
109
+ (size_t)(trap->pc - script->code) < script->length) {
110
+ if (code == script->code) {
111
+ jssrcnote *sn, *notes;
112
+ size_t nbytes;
113
+
114
+ nbytes = script->length * sizeof(jsbytecode);
115
+ notes = SCRIPT_NOTES(script);
116
+ for (sn = notes; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn))
117
+ continue;
118
+ nbytes += (sn - notes + 1) * sizeof *sn;
119
+
120
+ code = (jsbytecode *) JS_malloc(cx, nbytes);
121
+ if (!code)
122
+ break;
123
+ memcpy(code, script->code, nbytes);
124
+ JS_CLEAR_GSN_CACHE(cx);
125
+ }
126
+ code[trap->pc - script->code] = trap->op;
127
+ }
128
+ }
129
+ DBG_UNLOCK(rt);
130
+ return code;
131
+ }
132
+
133
+ JS_PUBLIC_API(JSBool)
134
+ JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
135
+ JSTrapHandler handler, void *closure)
136
+ {
137
+ JSTrap *junk, *trap, *twin;
138
+ JSRuntime *rt;
139
+ uint32 sample;
140
+
141
+ JS_ASSERT((JSOp) *pc != JSOP_TRAP);
142
+ junk = NULL;
143
+ rt = cx->runtime;
144
+ DBG_LOCK(rt);
145
+ trap = FindTrap(rt, script, pc);
146
+ if (trap) {
147
+ JS_ASSERT(trap->script == script && trap->pc == pc);
148
+ JS_ASSERT(*pc == JSOP_TRAP);
149
+ } else {
150
+ sample = rt->debuggerMutations;
151
+ DBG_UNLOCK(rt);
152
+ trap = (JSTrap *) JS_malloc(cx, sizeof *trap);
153
+ if (!trap)
154
+ return JS_FALSE;
155
+ trap->closure = NULL;
156
+ if(!js_AddRoot(cx, &trap->closure, "trap->closure")) {
157
+ JS_free(cx, trap);
158
+ return JS_FALSE;
159
+ }
160
+ DBG_LOCK(rt);
161
+ twin = (rt->debuggerMutations != sample)
162
+ ? FindTrap(rt, script, pc)
163
+ : NULL;
164
+ if (twin) {
165
+ junk = trap;
166
+ trap = twin;
167
+ } else {
168
+ JS_APPEND_LINK(&trap->links, &rt->trapList);
169
+ ++rt->debuggerMutations;
170
+ trap->script = script;
171
+ trap->pc = pc;
172
+ trap->op = (JSOp)*pc;
173
+ *pc = JSOP_TRAP;
174
+ }
175
+ }
176
+ trap->handler = handler;
177
+ trap->closure = closure;
178
+ DBG_UNLOCK(rt);
179
+ if (junk) {
180
+ js_RemoveRoot(rt, &junk->closure);
181
+ JS_free(cx, junk);
182
+ }
183
+ return JS_TRUE;
184
+ }
185
+
186
+ JS_PUBLIC_API(JSOp)
187
+ JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc)
188
+ {
189
+ JSRuntime *rt;
190
+ JSTrap *trap;
191
+ JSOp op;
192
+
193
+ rt = cx->runtime;
194
+ DBG_LOCK(rt);
195
+ trap = FindTrap(rt, script, pc);
196
+ op = trap ? trap->op : (JSOp) *pc;
197
+ DBG_UNLOCK(rt);
198
+ return op;
199
+ }
200
+
201
+ static void
202
+ DestroyTrapAndUnlock(JSContext *cx, JSTrap *trap)
203
+ {
204
+ ++cx->runtime->debuggerMutations;
205
+ JS_REMOVE_LINK(&trap->links);
206
+ *trap->pc = (jsbytecode)trap->op;
207
+ DBG_UNLOCK(cx->runtime);
208
+
209
+ js_RemoveRoot(cx->runtime, &trap->closure);
210
+ JS_free(cx, trap);
211
+ }
212
+
213
+ JS_PUBLIC_API(void)
214
+ JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
215
+ JSTrapHandler *handlerp, void **closurep)
216
+ {
217
+ JSTrap *trap;
218
+
219
+ DBG_LOCK(cx->runtime);
220
+ trap = FindTrap(cx->runtime, script, pc);
221
+ if (handlerp)
222
+ *handlerp = trap ? trap->handler : NULL;
223
+ if (closurep)
224
+ *closurep = trap ? trap->closure : NULL;
225
+ if (trap)
226
+ DestroyTrapAndUnlock(cx, trap);
227
+ else
228
+ DBG_UNLOCK(cx->runtime);
229
+ }
230
+
231
+ JS_PUBLIC_API(void)
232
+ JS_ClearScriptTraps(JSContext *cx, JSScript *script)
233
+ {
234
+ JSRuntime *rt;
235
+ JSTrap *trap, *next;
236
+ uint32 sample;
237
+
238
+ rt = cx->runtime;
239
+ DBG_LOCK(rt);
240
+ for (trap = (JSTrap *)rt->trapList.next;
241
+ trap != (JSTrap *)&rt->trapList;
242
+ trap = next) {
243
+ next = (JSTrap *)trap->links.next;
244
+ if (trap->script == script) {
245
+ sample = rt->debuggerMutations;
246
+ DestroyTrapAndUnlock(cx, trap);
247
+ DBG_LOCK(rt);
248
+ if (rt->debuggerMutations != sample + 1)
249
+ next = (JSTrap *)rt->trapList.next;
250
+ }
251
+ }
252
+ DBG_UNLOCK(rt);
253
+ }
254
+
255
+ JS_PUBLIC_API(void)
256
+ JS_ClearAllTraps(JSContext *cx)
257
+ {
258
+ JSRuntime *rt;
259
+ JSTrap *trap, *next;
260
+ uint32 sample;
261
+
262
+ rt = cx->runtime;
263
+ DBG_LOCK(rt);
264
+ for (trap = (JSTrap *)rt->trapList.next;
265
+ trap != (JSTrap *)&rt->trapList;
266
+ trap = next) {
267
+ next = (JSTrap *)trap->links.next;
268
+ sample = rt->debuggerMutations;
269
+ DestroyTrapAndUnlock(cx, trap);
270
+ DBG_LOCK(rt);
271
+ if (rt->debuggerMutations != sample + 1)
272
+ next = (JSTrap *)rt->trapList.next;
273
+ }
274
+ DBG_UNLOCK(rt);
275
+ }
276
+
277
+ JS_PUBLIC_API(JSTrapStatus)
278
+ JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval)
279
+ {
280
+ JSTrap *trap;
281
+ jsint op;
282
+ JSTrapStatus status;
283
+
284
+ DBG_LOCK(cx->runtime);
285
+ trap = FindTrap(cx->runtime, script, pc);
286
+ JS_ASSERT(!trap || trap->handler);
287
+ if (!trap) {
288
+ op = (JSOp) *pc;
289
+ DBG_UNLOCK(cx->runtime);
290
+
291
+ /* Defend against "pc for wrong script" API usage error. */
292
+ JS_ASSERT(op != JSOP_TRAP);
293
+
294
+ #ifdef JS_THREADSAFE
295
+ /* If the API was abused, we must fail for want of the real op. */
296
+ if (op == JSOP_TRAP)
297
+ return JSTRAP_ERROR;
298
+
299
+ /* Assume a race with a debugger thread and try to carry on. */
300
+ *rval = INT_TO_JSVAL(op);
301
+ return JSTRAP_CONTINUE;
302
+ #else
303
+ /* Always fail if single-threaded (must be an API usage error). */
304
+ return JSTRAP_ERROR;
305
+ #endif
306
+ }
307
+ DBG_UNLOCK(cx->runtime);
308
+
309
+ /*
310
+ * It's important that we not use 'trap->' after calling the callback --
311
+ * the callback might remove the trap!
312
+ */
313
+ op = (jsint)trap->op;
314
+ status = trap->handler(cx, script, pc, rval, trap->closure);
315
+ if (status == JSTRAP_CONTINUE) {
316
+ /* By convention, return the true op to the interpreter in rval. */
317
+ *rval = INT_TO_JSVAL(op);
318
+ }
319
+ return status;
320
+ }
321
+
322
+ JS_PUBLIC_API(JSBool)
323
+ JS_SetInterrupt(JSRuntime *rt, JSTrapHandler handler, void *closure)
324
+ {
325
+ rt->globalDebugHooks.interruptHandler = handler;
326
+ rt->globalDebugHooks.interruptHandlerData = closure;
327
+ return JS_TRUE;
328
+ }
329
+
330
+ JS_PUBLIC_API(JSBool)
331
+ JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep)
332
+ {
333
+ if (handlerp)
334
+ *handlerp = (JSTrapHandler)rt->globalDebugHooks.interruptHandler;
335
+ if (closurep)
336
+ *closurep = rt->globalDebugHooks.interruptHandlerData;
337
+ rt->globalDebugHooks.interruptHandler = 0;
338
+ rt->globalDebugHooks.interruptHandlerData = 0;
339
+ return JS_TRUE;
340
+ }
341
+
342
+ /************************************************************************/
343
+
344
+ typedef struct JSWatchPoint {
345
+ JSCList links;
346
+ JSObject *object; /* weak link, see js_FinalizeObject */
347
+ JSScopeProperty *sprop;
348
+ JSPropertyOp setter;
349
+ JSWatchPointHandler handler;
350
+ void *closure;
351
+ uintN flags;
352
+ } JSWatchPoint;
353
+
354
+ #define JSWP_LIVE 0x1 /* live because set and not cleared */
355
+ #define JSWP_HELD 0x2 /* held while running handler/setter */
356
+
357
+ /*
358
+ * NB: DropWatchPointAndUnlock releases cx->runtime->debuggerLock in all cases.
359
+ */
360
+ static JSBool
361
+ DropWatchPointAndUnlock(JSContext *cx, JSWatchPoint *wp, uintN flag)
362
+ {
363
+ JSBool ok, found;
364
+ JSScopeProperty *sprop;
365
+ JSScope *scope;
366
+ JSPropertyOp setter;
367
+
368
+ ok = JS_TRUE;
369
+ wp->flags &= ~flag;
370
+ if (wp->flags != 0) {
371
+ DBG_UNLOCK(cx->runtime);
372
+ return ok;
373
+ }
374
+
375
+ /*
376
+ * Remove wp from the list, then if there are no other watchpoints for
377
+ * wp->sprop in any scope, restore wp->sprop->setter from wp.
378
+ */
379
+ ++cx->runtime->debuggerMutations;
380
+ JS_REMOVE_LINK(&wp->links);
381
+ sprop = wp->sprop;
382
+
383
+ /*
384
+ * Passing null for the scope parameter tells js_GetWatchedSetter to find
385
+ * any watch point for sprop, and not to lock or unlock rt->debuggerLock.
386
+ * If js_ChangeNativePropertyAttrs fails, propagate failure after removing
387
+ * wp->closure's root and freeing wp.
388
+ */
389
+ setter = js_GetWatchedSetter(cx->runtime, NULL, sprop);
390
+ DBG_UNLOCK(cx->runtime);
391
+ if (!setter) {
392
+ JS_LOCK_OBJ(cx, wp->object);
393
+ scope = OBJ_SCOPE(wp->object);
394
+ found = (scope->object == wp->object &&
395
+ SCOPE_GET_PROPERTY(scope, sprop->id));
396
+ JS_UNLOCK_SCOPE(cx, scope);
397
+
398
+ /*
399
+ * If the property wasn't found on wp->object or didn't exist, then
400
+ * someone else has dealt with this sprop, and we don't need to change
401
+ * the property attributes.
402
+ */
403
+ if (found) {
404
+ sprop = js_ChangeScopePropertyAttrs(cx, scope, sprop,
405
+ 0, sprop->attrs,
406
+ sprop->getter,
407
+ wp->setter);
408
+ if (!sprop)
409
+ ok = JS_FALSE;
410
+ }
411
+ }
412
+
413
+ JS_free(cx, wp);
414
+ return ok;
415
+ }
416
+
417
+ /*
418
+ * NB: js_TraceWatchPoints does not acquire cx->runtime->debuggerLock, since
419
+ * the debugger should never be racing with the GC (i.e., the debugger must
420
+ * respect the request model).
421
+ */
422
+ void
423
+ js_TraceWatchPoints(JSTracer *trc, JSObject *obj)
424
+ {
425
+ JSRuntime *rt;
426
+ JSWatchPoint *wp;
427
+
428
+ rt = trc->context->runtime;
429
+
430
+ for (wp = (JSWatchPoint *)rt->watchPointList.next;
431
+ wp != (JSWatchPoint *)&rt->watchPointList;
432
+ wp = (JSWatchPoint *)wp->links.next) {
433
+ if (wp->object == obj) {
434
+ TRACE_SCOPE_PROPERTY(trc, wp->sprop);
435
+ if ((wp->sprop->attrs & JSPROP_SETTER) && wp->setter) {
436
+ JS_CALL_OBJECT_TRACER(trc, (JSObject *)wp->setter,
437
+ "wp->setter");
438
+ }
439
+ JS_SET_TRACING_NAME(trc, "wp->closure");
440
+ js_CallValueTracerIfGCThing(trc, (jsval) wp->closure);
441
+ }
442
+ }
443
+ }
444
+
445
+ void
446
+ js_SweepWatchPoints(JSContext *cx)
447
+ {
448
+ JSRuntime *rt;
449
+ JSWatchPoint *wp, *next;
450
+ uint32 sample;
451
+
452
+ rt = cx->runtime;
453
+ DBG_LOCK(rt);
454
+ for (wp = (JSWatchPoint *)rt->watchPointList.next;
455
+ wp != (JSWatchPoint *)&rt->watchPointList;
456
+ wp = next) {
457
+ next = (JSWatchPoint *)wp->links.next;
458
+ if (js_IsAboutToBeFinalized(cx, wp->object)) {
459
+ sample = rt->debuggerMutations;
460
+
461
+ /* Ignore failures. */
462
+ DropWatchPointAndUnlock(cx, wp, JSWP_LIVE);
463
+ DBG_LOCK(rt);
464
+ if (rt->debuggerMutations != sample + 1)
465
+ next = (JSWatchPoint *)rt->watchPointList.next;
466
+ }
467
+ }
468
+ DBG_UNLOCK(rt);
469
+ }
470
+
471
+
472
+
473
+ /*
474
+ * NB: FindWatchPoint must be called with rt->debuggerLock acquired.
475
+ */
476
+ static JSWatchPoint *
477
+ FindWatchPoint(JSRuntime *rt, JSScope *scope, jsid id)
478
+ {
479
+ JSWatchPoint *wp;
480
+
481
+ for (wp = (JSWatchPoint *)rt->watchPointList.next;
482
+ wp != (JSWatchPoint *)&rt->watchPointList;
483
+ wp = (JSWatchPoint *)wp->links.next) {
484
+ if (wp->object == scope->object && wp->sprop->id == id)
485
+ return wp;
486
+ }
487
+ return NULL;
488
+ }
489
+
490
+ JSScopeProperty *
491
+ js_FindWatchPoint(JSRuntime *rt, JSScope *scope, jsid id)
492
+ {
493
+ JSWatchPoint *wp;
494
+ JSScopeProperty *sprop;
495
+
496
+ DBG_LOCK(rt);
497
+ wp = FindWatchPoint(rt, scope, id);
498
+ sprop = wp ? wp->sprop : NULL;
499
+ DBG_UNLOCK(rt);
500
+ return sprop;
501
+ }
502
+
503
+ /*
504
+ * Secret handshake with DropWatchPointAndUnlock: if (!scope), we know our
505
+ * caller has acquired rt->debuggerLock, so we don't have to.
506
+ */
507
+ JSPropertyOp
508
+ js_GetWatchedSetter(JSRuntime *rt, JSScope *scope,
509
+ const JSScopeProperty *sprop)
510
+ {
511
+ JSPropertyOp setter;
512
+ JSWatchPoint *wp;
513
+
514
+ setter = NULL;
515
+ if (scope)
516
+ DBG_LOCK(rt);
517
+ for (wp = (JSWatchPoint *)rt->watchPointList.next;
518
+ wp != (JSWatchPoint *)&rt->watchPointList;
519
+ wp = (JSWatchPoint *)wp->links.next) {
520
+ if ((!scope || wp->object == scope->object) && wp->sprop == sprop) {
521
+ setter = wp->setter;
522
+ break;
523
+ }
524
+ }
525
+ if (scope)
526
+ DBG_UNLOCK(rt);
527
+ return setter;
528
+ }
529
+
530
+ JSBool JS_DLL_CALLBACK
531
+ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
532
+ {
533
+ JSRuntime *rt;
534
+ JSWatchPoint *wp;
535
+ JSScopeProperty *sprop;
536
+ jsval propid, userid;
537
+ JSScope *scope;
538
+ JSBool ok;
539
+
540
+ rt = cx->runtime;
541
+ DBG_LOCK(rt);
542
+ for (wp = (JSWatchPoint *)rt->watchPointList.next;
543
+ wp != (JSWatchPoint *)&rt->watchPointList;
544
+ wp = (JSWatchPoint *)wp->links.next) {
545
+ sprop = wp->sprop;
546
+ if (wp->object == obj && SPROP_USERID(sprop) == id &&
547
+ !(wp->flags & JSWP_HELD)) {
548
+ wp->flags |= JSWP_HELD;
549
+ DBG_UNLOCK(rt);
550
+
551
+ JS_LOCK_OBJ(cx, obj);
552
+ propid = ID_TO_VALUE(sprop->id);
553
+ userid = (sprop->flags & SPROP_HAS_SHORTID)
554
+ ? INT_TO_JSVAL(sprop->shortid)
555
+ : propid;
556
+ scope = OBJ_SCOPE(obj);
557
+ JS_UNLOCK_OBJ(cx, obj);
558
+
559
+ /* NB: wp is held, so we can safely dereference it still. */
560
+ ok = wp->handler(cx, obj, propid,
561
+ SPROP_HAS_VALID_SLOT(sprop, scope)
562
+ ? OBJ_GET_SLOT(cx, obj, sprop->slot)
563
+ : JSVAL_VOID,
564
+ vp, wp->closure);
565
+ if (ok) {
566
+ /*
567
+ * Create a pseudo-frame for the setter invocation so that any
568
+ * stack-walking security code under the setter will correctly
569
+ * identify the guilty party. So that the watcher appears to
570
+ * be active to obj_eval and other such code, point frame.pc
571
+ * at the JSOP_STOP at the end of the script.
572
+ *
573
+ * The pseudo-frame is not created for fast natives as they
574
+ * are treated as interpreter frame extensions and always
575
+ * trusted.
576
+ */
577
+ JSObject *closure;
578
+ JSClass *clasp;
579
+ JSFunction *fun;
580
+ JSScript *script;
581
+ JSBool injectFrame;
582
+ uintN nslots;
583
+ jsval smallv[5];
584
+ jsval *argv;
585
+ JSStackFrame frame;
586
+ JSFrameRegs regs;
587
+
588
+ closure = (JSObject *) wp->closure;
589
+ clasp = OBJ_GET_CLASS(cx, closure);
590
+ if (clasp == &js_FunctionClass) {
591
+ fun = GET_FUNCTION_PRIVATE(cx, closure);
592
+ script = FUN_SCRIPT(fun);
593
+ } else if (clasp == &js_ScriptClass) {
594
+ fun = NULL;
595
+ script = (JSScript *) JS_GetPrivate(cx, closure);
596
+ } else {
597
+ fun = NULL;
598
+ script = NULL;
599
+ }
600
+
601
+ nslots = 2;
602
+ injectFrame = JS_TRUE;
603
+ if (fun) {
604
+ nslots += FUN_MINARGS(fun);
605
+ if (!FUN_INTERPRETED(fun)) {
606
+ nslots += fun->u.n.extra;
607
+ injectFrame = !(fun->flags & JSFUN_FAST_NATIVE);
608
+ }
609
+ }
610
+
611
+ if (injectFrame) {
612
+ if (nslots <= JS_ARRAY_LENGTH(smallv)) {
613
+ argv = smallv;
614
+ } else {
615
+ argv = (jsval *) JS_malloc(cx, nslots * sizeof(jsval));
616
+ if (!argv) {
617
+ DBG_LOCK(rt);
618
+ DropWatchPointAndUnlock(cx, wp, JSWP_HELD);
619
+ return JS_FALSE;
620
+ }
621
+ }
622
+
623
+ argv[0] = OBJECT_TO_JSVAL(closure);
624
+ argv[1] = JSVAL_NULL;
625
+ memset(argv + 2, 0, (nslots - 2) * sizeof(jsval));
626
+
627
+ memset(&frame, 0, sizeof(frame));
628
+ frame.script = script;
629
+ frame.regs = NULL;
630
+ if (script) {
631
+ JS_ASSERT(script->length >= JSOP_STOP_LENGTH);
632
+ regs.pc = script->code + script->length
633
+ - JSOP_STOP_LENGTH;
634
+ regs.sp = NULL;
635
+ frame.regs = &regs;
636
+ }
637
+ frame.callee = closure;
638
+ frame.fun = fun;
639
+ frame.argv = argv + 2;
640
+ frame.down = cx->fp;
641
+ frame.scopeChain = OBJ_GET_PARENT(cx, closure);
642
+
643
+ cx->fp = &frame;
644
+ }
645
+ #ifdef __GNUC__
646
+ else
647
+ argv = NULL; /* suppress bogus gcc warnings */
648
+ #endif
649
+ ok = !wp->setter ||
650
+ ((sprop->attrs & JSPROP_SETTER)
651
+ ? js_InternalCall(cx, obj, OBJECT_TO_JSVAL(wp->setter),
652
+ 1, vp, vp)
653
+ : wp->setter(cx, OBJ_THIS_OBJECT(cx, obj), userid, vp));
654
+ if (injectFrame) {
655
+ /* Evil code can cause us to have an arguments object. */
656
+ if (frame.callobj)
657
+ ok &= js_PutCallObject(cx, &frame);
658
+ if (frame.argsobj)
659
+ ok &= js_PutArgsObject(cx, &frame);
660
+
661
+ cx->fp = frame.down;
662
+ if (argv != smallv)
663
+ JS_free(cx, argv);
664
+ }
665
+ }
666
+ DBG_LOCK(rt);
667
+ return DropWatchPointAndUnlock(cx, wp, JSWP_HELD) && ok;
668
+ }
669
+ }
670
+ DBG_UNLOCK(rt);
671
+ return JS_TRUE;
672
+ }
673
+
674
+ JSBool JS_DLL_CALLBACK
675
+ js_watch_set_wrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
676
+ jsval *rval)
677
+ {
678
+ JSObject *funobj;
679
+ JSFunction *wrapper;
680
+ jsval userid;
681
+
682
+ funobj = JSVAL_TO_OBJECT(argv[-2]);
683
+ JS_ASSERT(OBJ_GET_CLASS(cx, funobj) == &js_FunctionClass);
684
+ wrapper = GET_FUNCTION_PRIVATE(cx, funobj);
685
+ userid = ATOM_KEY(wrapper->atom);
686
+ *rval = argv[0];
687
+ return js_watch_set(cx, obj, userid, rval);
688
+ }
689
+
690
+ JSPropertyOp
691
+ js_WrapWatchedSetter(JSContext *cx, jsid id, uintN attrs, JSPropertyOp setter)
692
+ {
693
+ JSAtom *atom;
694
+ JSFunction *wrapper;
695
+
696
+ if (!(attrs & JSPROP_SETTER))
697
+ return &js_watch_set; /* & to silence schoolmarmish MSVC */
698
+
699
+ if (JSID_IS_ATOM(id)) {
700
+ atom = JSID_TO_ATOM(id);
701
+ } else if (JSID_IS_INT(id)) {
702
+ if (!js_ValueToStringId(cx, INT_JSID_TO_JSVAL(id), &id))
703
+ return NULL;
704
+ atom = JSID_TO_ATOM(id);
705
+ } else {
706
+ atom = NULL;
707
+ }
708
+ wrapper = js_NewFunction(cx, NULL, js_watch_set_wrapper, 1, 0,
709
+ OBJ_GET_PARENT(cx, (JSObject *)setter),
710
+ atom);
711
+ if (!wrapper)
712
+ return NULL;
713
+ return (JSPropertyOp) FUN_OBJECT(wrapper);
714
+ }
715
+
716
+ JS_PUBLIC_API(JSBool)
717
+ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval idval,
718
+ JSWatchPointHandler handler, void *closure)
719
+ {
720
+ jsid propid;
721
+ JSObject *pobj;
722
+ JSProperty *prop;
723
+ JSScopeProperty *sprop;
724
+ JSRuntime *rt;
725
+ JSBool ok;
726
+ JSWatchPoint *wp;
727
+ JSPropertyOp watcher;
728
+
729
+ if (!OBJ_IS_NATIVE(obj)) {
730
+ JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WATCH,
731
+ OBJ_GET_CLASS(cx, obj)->name);
732
+ return JS_FALSE;
733
+ }
734
+
735
+ if (JSVAL_IS_INT(idval))
736
+ propid = INT_JSVAL_TO_JSID(idval);
737
+ else if (!js_ValueToStringId(cx, idval, &propid))
738
+ return JS_FALSE;
739
+
740
+ if (!js_LookupProperty(cx, obj, propid, &pobj, &prop))
741
+ return JS_FALSE;
742
+ sprop = (JSScopeProperty *) prop;
743
+ rt = cx->runtime;
744
+ if (!sprop) {
745
+ /* Check for a deleted symbol watchpoint, which holds its property. */
746
+ sprop = js_FindWatchPoint(rt, OBJ_SCOPE(obj), propid);
747
+ if (!sprop) {
748
+ /* Make a new property in obj so we can watch for the first set. */
749
+ if (!js_DefineProperty(cx, obj, propid, JSVAL_VOID,
750
+ NULL, NULL, JSPROP_ENUMERATE,
751
+ &prop)) {
752
+ return JS_FALSE;
753
+ }
754
+ sprop = (JSScopeProperty *) prop;
755
+ }
756
+ } else if (pobj != obj) {
757
+ /* Clone the prototype property so we can watch the right object. */
758
+ jsval value;
759
+ JSPropertyOp getter, setter;
760
+ uintN attrs, flags;
761
+ intN shortid;
762
+
763
+ if (OBJ_IS_NATIVE(pobj)) {
764
+ value = SPROP_HAS_VALID_SLOT(sprop, OBJ_SCOPE(pobj))
765
+ ? LOCKED_OBJ_GET_SLOT(pobj, sprop->slot)
766
+ : JSVAL_VOID;
767
+ getter = sprop->getter;
768
+ setter = sprop->setter;
769
+ attrs = sprop->attrs;
770
+ flags = sprop->flags;
771
+ shortid = sprop->shortid;
772
+ } else {
773
+ if (!OBJ_GET_PROPERTY(cx, pobj, propid, &value) ||
774
+ !OBJ_GET_ATTRIBUTES(cx, pobj, propid, prop, &attrs)) {
775
+ OBJ_DROP_PROPERTY(cx, pobj, prop);
776
+ return JS_FALSE;
777
+ }
778
+ getter = setter = NULL;
779
+ flags = 0;
780
+ shortid = 0;
781
+ }
782
+ OBJ_DROP_PROPERTY(cx, pobj, prop);
783
+
784
+ /* Recall that obj is native, whether or not pobj is native. */
785
+ if (!js_DefineNativeProperty(cx, obj, propid, value, getter, setter,
786
+ attrs, flags, shortid, &prop)) {
787
+ return JS_FALSE;
788
+ }
789
+ sprop = (JSScopeProperty *) prop;
790
+ }
791
+
792
+ /*
793
+ * At this point, prop/sprop exists in obj, obj is locked, and we must
794
+ * OBJ_DROP_PROPERTY(cx, obj, prop) before returning.
795
+ */
796
+ ok = JS_TRUE;
797
+ DBG_LOCK(rt);
798
+ wp = FindWatchPoint(rt, OBJ_SCOPE(obj), propid);
799
+ if (!wp) {
800
+ DBG_UNLOCK(rt);
801
+ watcher = js_WrapWatchedSetter(cx, propid, sprop->attrs, sprop->setter);
802
+ if (!watcher) {
803
+ ok = JS_FALSE;
804
+ goto out;
805
+ }
806
+
807
+ wp = (JSWatchPoint *) JS_malloc(cx, sizeof *wp);
808
+ if (!wp) {
809
+ ok = JS_FALSE;
810
+ goto out;
811
+ }
812
+ wp->handler = NULL;
813
+ wp->closure = NULL;
814
+ wp->object = obj;
815
+ JS_ASSERT(sprop->setter != js_watch_set || pobj != obj);
816
+ wp->setter = sprop->setter;
817
+ wp->flags = JSWP_LIVE;
818
+
819
+ /* XXXbe nest in obj lock here */
820
+ sprop = js_ChangeNativePropertyAttrs(cx, obj, sprop, 0, sprop->attrs,
821
+ sprop->getter, watcher);
822
+ if (!sprop) {
823
+ /* Self-link so DropWatchPointAndUnlock can JS_REMOVE_LINK it. */
824
+ JS_INIT_CLIST(&wp->links);
825
+ DBG_LOCK(rt);
826
+ DropWatchPointAndUnlock(cx, wp, JSWP_LIVE);
827
+ ok = JS_FALSE;
828
+ goto out;
829
+ }
830
+ wp->sprop = sprop;
831
+
832
+ /*
833
+ * Now that wp is fully initialized, append it to rt's wp list.
834
+ * Because obj is locked we know that no other thread could have added
835
+ * a watchpoint for (obj, propid).
836
+ */
837
+ DBG_LOCK(rt);
838
+ JS_ASSERT(!FindWatchPoint(rt, OBJ_SCOPE(obj), propid));
839
+ JS_APPEND_LINK(&wp->links, &rt->watchPointList);
840
+ ++rt->debuggerMutations;
841
+ }
842
+ wp->handler = handler;
843
+ wp->closure = closure;
844
+ DBG_UNLOCK(rt);
845
+
846
+ out:
847
+ OBJ_DROP_PROPERTY(cx, obj, prop);
848
+ return ok;
849
+ }
850
+
851
+ JS_PUBLIC_API(JSBool)
852
+ JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsval id,
853
+ JSWatchPointHandler *handlerp, void **closurep)
854
+ {
855
+ JSRuntime *rt;
856
+ JSWatchPoint *wp;
857
+
858
+ rt = cx->runtime;
859
+ DBG_LOCK(rt);
860
+ for (wp = (JSWatchPoint *)rt->watchPointList.next;
861
+ wp != (JSWatchPoint *)&rt->watchPointList;
862
+ wp = (JSWatchPoint *)wp->links.next) {
863
+ if (wp->object == obj && SPROP_USERID(wp->sprop) == id) {
864
+ if (handlerp)
865
+ *handlerp = wp->handler;
866
+ if (closurep)
867
+ *closurep = wp->closure;
868
+ return DropWatchPointAndUnlock(cx, wp, JSWP_LIVE);
869
+ }
870
+ }
871
+ DBG_UNLOCK(rt);
872
+ if (handlerp)
873
+ *handlerp = NULL;
874
+ if (closurep)
875
+ *closurep = NULL;
876
+ return JS_TRUE;
877
+ }
878
+
879
+ JS_PUBLIC_API(JSBool)
880
+ JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj)
881
+ {
882
+ JSRuntime *rt;
883
+ JSWatchPoint *wp, *next;
884
+ uint32 sample;
885
+
886
+ rt = cx->runtime;
887
+ DBG_LOCK(rt);
888
+ for (wp = (JSWatchPoint *)rt->watchPointList.next;
889
+ wp != (JSWatchPoint *)&rt->watchPointList;
890
+ wp = next) {
891
+ next = (JSWatchPoint *)wp->links.next;
892
+ if (wp->object == obj) {
893
+ sample = rt->debuggerMutations;
894
+ if (!DropWatchPointAndUnlock(cx, wp, JSWP_LIVE))
895
+ return JS_FALSE;
896
+ DBG_LOCK(rt);
897
+ if (rt->debuggerMutations != sample + 1)
898
+ next = (JSWatchPoint *)rt->watchPointList.next;
899
+ }
900
+ }
901
+ DBG_UNLOCK(rt);
902
+ return JS_TRUE;
903
+ }
904
+
905
+ JS_PUBLIC_API(JSBool)
906
+ JS_ClearAllWatchPoints(JSContext *cx)
907
+ {
908
+ JSRuntime *rt;
909
+ JSWatchPoint *wp, *next;
910
+ uint32 sample;
911
+
912
+ rt = cx->runtime;
913
+ DBG_LOCK(rt);
914
+ for (wp = (JSWatchPoint *)rt->watchPointList.next;
915
+ wp != (JSWatchPoint *)&rt->watchPointList;
916
+ wp = next) {
917
+ next = (JSWatchPoint *)wp->links.next;
918
+ sample = rt->debuggerMutations;
919
+ if (!DropWatchPointAndUnlock(cx, wp, JSWP_LIVE))
920
+ return JS_FALSE;
921
+ DBG_LOCK(rt);
922
+ if (rt->debuggerMutations != sample + 1)
923
+ next = (JSWatchPoint *)rt->watchPointList.next;
924
+ }
925
+ DBG_UNLOCK(rt);
926
+ return JS_TRUE;
927
+ }
928
+
929
+ /************************************************************************/
930
+
931
+ JS_PUBLIC_API(uintN)
932
+ JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc)
933
+ {
934
+ return js_PCToLineNumber(cx, script, pc);
935
+ }
936
+
937
+ JS_PUBLIC_API(jsbytecode *)
938
+ JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno)
939
+ {
940
+ return js_LineNumberToPC(script, lineno);
941
+ }
942
+
943
+ JS_PUBLIC_API(JSScript *)
944
+ JS_GetFunctionScript(JSContext *cx, JSFunction *fun)
945
+ {
946
+ return FUN_SCRIPT(fun);
947
+ }
948
+
949
+ JS_PUBLIC_API(JSNative)
950
+ JS_GetFunctionNative(JSContext *cx, JSFunction *fun)
951
+ {
952
+ return FUN_NATIVE(fun);
953
+ }
954
+
955
+ JS_PUBLIC_API(JSFastNative)
956
+ JS_GetFunctionFastNative(JSContext *cx, JSFunction *fun)
957
+ {
958
+ return FUN_FAST_NATIVE(fun);
959
+ }
960
+
961
+ JS_PUBLIC_API(JSPrincipals *)
962
+ JS_GetScriptPrincipals(JSContext *cx, JSScript *script)
963
+ {
964
+ return script->principals;
965
+ }
966
+
967
+ /************************************************************************/
968
+
969
+ /*
970
+ * Stack Frame Iterator
971
+ */
972
+ JS_PUBLIC_API(JSStackFrame *)
973
+ JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp)
974
+ {
975
+ *iteratorp = (*iteratorp == NULL) ? cx->fp : (*iteratorp)->down;
976
+ return *iteratorp;
977
+ }
978
+
979
+ JS_PUBLIC_API(JSScript *)
980
+ JS_GetFrameScript(JSContext *cx, JSStackFrame *fp)
981
+ {
982
+ return fp->script;
983
+ }
984
+
985
+ JS_PUBLIC_API(jsbytecode *)
986
+ JS_GetFramePC(JSContext *cx, JSStackFrame *fp)
987
+ {
988
+ return fp->regs ? fp->regs->pc : NULL;
989
+ }
990
+
991
+ JS_PUBLIC_API(JSStackFrame *)
992
+ JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp)
993
+ {
994
+ if (!fp)
995
+ fp = cx->fp;
996
+ while (fp) {
997
+ if (fp->script)
998
+ return fp;
999
+ fp = fp->down;
1000
+ }
1001
+ return NULL;
1002
+ }
1003
+
1004
+ JS_PUBLIC_API(JSPrincipals *)
1005
+ JS_StackFramePrincipals(JSContext *cx, JSStackFrame *fp)
1006
+ {
1007
+ if (fp->fun) {
1008
+ JSRuntime *rt = cx->runtime;
1009
+
1010
+ if (rt->findObjectPrincipals) {
1011
+ if (FUN_OBJECT(fp->fun) != fp->callee)
1012
+ return rt->findObjectPrincipals(cx, fp->callee);
1013
+ /* FALL THROUGH */
1014
+ }
1015
+ }
1016
+ if (fp->script)
1017
+ return fp->script->principals;
1018
+ return NULL;
1019
+ }
1020
+
1021
+ JS_PUBLIC_API(JSPrincipals *)
1022
+ JS_EvalFramePrincipals(JSContext *cx, JSStackFrame *fp, JSStackFrame *caller)
1023
+ {
1024
+ JSRuntime *rt;
1025
+ JSPrincipals *principals, *callerPrincipals;
1026
+
1027
+ rt = cx->runtime;
1028
+ if (rt->findObjectPrincipals) {
1029
+ principals = rt->findObjectPrincipals(cx, fp->callee);
1030
+ } else {
1031
+ principals = NULL;
1032
+ }
1033
+ if (!caller)
1034
+ return principals;
1035
+ callerPrincipals = JS_StackFramePrincipals(cx, caller);
1036
+ return (callerPrincipals && principals &&
1037
+ callerPrincipals->subsume(callerPrincipals, principals))
1038
+ ? principals
1039
+ : callerPrincipals;
1040
+ }
1041
+
1042
+ JS_PUBLIC_API(void *)
1043
+ JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp)
1044
+ {
1045
+ if (fp->annotation && fp->script) {
1046
+ JSPrincipals *principals = JS_StackFramePrincipals(cx, fp);
1047
+
1048
+ if (principals && principals->globalPrivilegesEnabled(cx, principals)) {
1049
+ /*
1050
+ * Give out an annotation only if privileges have not been revoked
1051
+ * or disabled globally.
1052
+ */
1053
+ return fp->annotation;
1054
+ }
1055
+ }
1056
+
1057
+ return NULL;
1058
+ }
1059
+
1060
+ JS_PUBLIC_API(void)
1061
+ JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation)
1062
+ {
1063
+ fp->annotation = annotation;
1064
+ }
1065
+
1066
+ JS_PUBLIC_API(void *)
1067
+ JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp)
1068
+ {
1069
+ JSPrincipals *principals;
1070
+
1071
+ principals = JS_StackFramePrincipals(cx, fp);
1072
+ if (!principals)
1073
+ return NULL;
1074
+ return principals->getPrincipalArray(cx, principals);
1075
+ }
1076
+
1077
+ JS_PUBLIC_API(JSBool)
1078
+ JS_IsNativeFrame(JSContext *cx, JSStackFrame *fp)
1079
+ {
1080
+ return !fp->script;
1081
+ }
1082
+
1083
+ /* this is deprecated, use JS_GetFrameScopeChain instead */
1084
+ JS_PUBLIC_API(JSObject *)
1085
+ JS_GetFrameObject(JSContext *cx, JSStackFrame *fp)
1086
+ {
1087
+ return fp->scopeChain;
1088
+ }
1089
+
1090
+ JS_PUBLIC_API(JSObject *)
1091
+ JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp)
1092
+ {
1093
+ /* Force creation of argument and call objects if not yet created */
1094
+ (void) JS_GetFrameCallObject(cx, fp);
1095
+ return js_GetScopeChain(cx, fp);
1096
+ }
1097
+
1098
+ JS_PUBLIC_API(JSObject *)
1099
+ JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp)
1100
+ {
1101
+ if (! fp->fun)
1102
+ return NULL;
1103
+
1104
+ /* Force creation of argument object if not yet created */
1105
+ (void) js_GetArgsObject(cx, fp);
1106
+
1107
+ /*
1108
+ * XXX ill-defined: null return here means error was reported, unlike a
1109
+ * null returned above or in the #else
1110
+ */
1111
+ return js_GetCallObject(cx, fp, NULL);
1112
+ }
1113
+
1114
+ JS_PUBLIC_API(JSObject *)
1115
+ JS_GetFrameThis(JSContext *cx, JSStackFrame *fp)
1116
+ {
1117
+ JSStackFrame *afp;
1118
+
1119
+ if (fp->flags & JSFRAME_COMPUTED_THIS)
1120
+ return fp->thisp;
1121
+
1122
+ /* js_ComputeThis gets confused if fp != cx->fp, so set it aside. */
1123
+ if (cx->fp != fp) {
1124
+ afp = cx->fp;
1125
+ if (afp) {
1126
+ afp->dormantNext = cx->dormantFrameChain;
1127
+ cx->dormantFrameChain = afp;
1128
+ cx->fp = fp;
1129
+ }
1130
+ } else {
1131
+ afp = NULL;
1132
+ }
1133
+
1134
+ if (!fp->thisp && fp->argv)
1135
+ fp->thisp = js_ComputeThis(cx, JS_TRUE, fp->argv);
1136
+
1137
+ if (afp) {
1138
+ cx->fp = afp;
1139
+ cx->dormantFrameChain = afp->dormantNext;
1140
+ afp->dormantNext = NULL;
1141
+ }
1142
+
1143
+ return fp->thisp;
1144
+ }
1145
+
1146
+ JS_PUBLIC_API(JSFunction *)
1147
+ JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp)
1148
+ {
1149
+ return fp->fun;
1150
+ }
1151
+
1152
+ JS_PUBLIC_API(JSObject *)
1153
+ JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp)
1154
+ {
1155
+ /*
1156
+ * Test both fp->fun and fp->argv to defend against any control flow from
1157
+ * the compiler reaching this API entry point, where fp is a frame pushed
1158
+ * by the compiler that has non-null fun but null argv.
1159
+ */
1160
+ if (fp->fun && fp->argv) {
1161
+ JSObject *obj = fp->callee;
1162
+
1163
+ JS_ASSERT(OBJ_GET_CLASS(cx, obj) == &js_FunctionClass);
1164
+ JS_ASSERT(OBJ_GET_PRIVATE(cx, obj) == fp->fun);
1165
+ return obj;
1166
+ }
1167
+ return NULL;
1168
+ }
1169
+
1170
+ JS_PUBLIC_API(JSBool)
1171
+ JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp)
1172
+ {
1173
+ return (fp->flags & JSFRAME_CONSTRUCTING) != 0;
1174
+ }
1175
+
1176
+ JS_PUBLIC_API(JSObject *)
1177
+ JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp)
1178
+ {
1179
+ return fp->callee;
1180
+ }
1181
+
1182
+ JS_PUBLIC_API(JSBool)
1183
+ JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp)
1184
+ {
1185
+ return (fp->flags & JSFRAME_DEBUGGER) != 0;
1186
+ }
1187
+
1188
+ JS_PUBLIC_API(jsval)
1189
+ JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp)
1190
+ {
1191
+ return fp->rval;
1192
+ }
1193
+
1194
+ JS_PUBLIC_API(void)
1195
+ JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval)
1196
+ {
1197
+ fp->rval = rval;
1198
+ }
1199
+
1200
+ /************************************************************************/
1201
+
1202
+ JS_PUBLIC_API(const char *)
1203
+ JS_GetScriptFilename(JSContext *cx, JSScript *script)
1204
+ {
1205
+ return script->filename;
1206
+ }
1207
+
1208
+ JS_PUBLIC_API(uintN)
1209
+ JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script)
1210
+ {
1211
+ return script->lineno;
1212
+ }
1213
+
1214
+ JS_PUBLIC_API(uintN)
1215
+ JS_GetScriptLineExtent(JSContext *cx, JSScript *script)
1216
+ {
1217
+ return js_GetScriptLineExtent(script);
1218
+ }
1219
+
1220
+ JS_PUBLIC_API(JSVersion)
1221
+ JS_GetScriptVersion(JSContext *cx, JSScript *script)
1222
+ {
1223
+ return (JSVersion) (script->version & JSVERSION_MASK);
1224
+ }
1225
+
1226
+ /***************************************************************************/
1227
+
1228
+ JS_PUBLIC_API(void)
1229
+ JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata)
1230
+ {
1231
+ rt->globalDebugHooks.newScriptHook = hook;
1232
+ rt->globalDebugHooks.newScriptHookData = callerdata;
1233
+ }
1234
+
1235
+ JS_PUBLIC_API(void)
1236
+ JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
1237
+ void *callerdata)
1238
+ {
1239
+ rt->globalDebugHooks.destroyScriptHook = hook;
1240
+ rt->globalDebugHooks.destroyScriptHookData = callerdata;
1241
+ }
1242
+
1243
+ /***************************************************************************/
1244
+
1245
+ JS_PUBLIC_API(JSBool)
1246
+ JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
1247
+ const jschar *chars, uintN length,
1248
+ const char *filename, uintN lineno,
1249
+ jsval *rval)
1250
+ {
1251
+ JSObject *scobj;
1252
+ uint32 flags;
1253
+ JSScript *script;
1254
+ JSBool ok;
1255
+
1256
+ scobj = JS_GetFrameScopeChain(cx, fp);
1257
+ if (!scobj)
1258
+ return JS_FALSE;
1259
+
1260
+ /*
1261
+ * XXX Hack around ancient compiler API to propagate the JSFRAME_SPECIAL
1262
+ * flags to the code generator.
1263
+ */
1264
+ flags = fp->flags;
1265
+ fp->flags |= JSFRAME_DEBUGGER | JSFRAME_EVAL;
1266
+ script = js_CompileScript(cx, scobj, JS_StackFramePrincipals(cx, fp),
1267
+ TCF_COMPILE_N_GO, chars, length, NULL,
1268
+ filename, lineno);
1269
+ fp->flags = flags;
1270
+ if (!script)
1271
+ return JS_FALSE;
1272
+
1273
+ ok = js_Execute(cx, scobj, script, fp, JSFRAME_DEBUGGER | JSFRAME_EVAL,
1274
+ rval);
1275
+ js_DestroyScript(cx, script);
1276
+ return ok;
1277
+ }
1278
+
1279
+ JS_PUBLIC_API(JSBool)
1280
+ JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
1281
+ const char *bytes, uintN length,
1282
+ const char *filename, uintN lineno,
1283
+ jsval *rval)
1284
+ {
1285
+ jschar *chars;
1286
+ JSBool ok;
1287
+ size_t len = length;
1288
+
1289
+ chars = js_InflateString(cx, bytes, &len);
1290
+ if (!chars)
1291
+ return JS_FALSE;
1292
+ length = (uintN) len;
1293
+ ok = JS_EvaluateUCInStackFrame(cx, fp, chars, length, filename, lineno,
1294
+ rval);
1295
+ JS_free(cx, chars);
1296
+
1297
+ return ok;
1298
+ }
1299
+
1300
+ /************************************************************************/
1301
+
1302
+ /* XXXbe this all needs to be reworked to avoid requiring JSScope types. */
1303
+
1304
+ JS_PUBLIC_API(JSScopeProperty *)
1305
+ JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp)
1306
+ {
1307
+ JSScopeProperty *sprop;
1308
+ JSScope *scope;
1309
+
1310
+ sprop = *iteratorp;
1311
+ scope = OBJ_SCOPE(obj);
1312
+
1313
+ /* XXXbe minor(?) incompatibility: iterate in reverse definition order */
1314
+ if (!sprop) {
1315
+ sprop = SCOPE_LAST_PROP(scope);
1316
+ } else {
1317
+ while ((sprop = sprop->parent) != NULL) {
1318
+ if (!SCOPE_HAD_MIDDLE_DELETE(scope))
1319
+ break;
1320
+ if (SCOPE_HAS_PROPERTY(scope, sprop))
1321
+ break;
1322
+ }
1323
+ }
1324
+ *iteratorp = sprop;
1325
+ return sprop;
1326
+ }
1327
+
1328
+ JS_PUBLIC_API(JSBool)
1329
+ JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *sprop,
1330
+ JSPropertyDesc *pd)
1331
+ {
1332
+ JSScope *scope;
1333
+ JSScopeProperty *aprop;
1334
+ jsval lastException;
1335
+ JSBool wasThrowing;
1336
+
1337
+ pd->id = ID_TO_VALUE(sprop->id);
1338
+
1339
+ wasThrowing = cx->throwing;
1340
+ if (wasThrowing) {
1341
+ lastException = cx->exception;
1342
+ if (JSVAL_IS_GCTHING(lastException) &&
1343
+ !js_AddRoot(cx, &lastException, "lastException")) {
1344
+ return JS_FALSE;
1345
+ }
1346
+ cx->throwing = JS_FALSE;
1347
+ }
1348
+
1349
+ if (!js_GetProperty(cx, obj, sprop->id, &pd->value)) {
1350
+ if (!cx->throwing) {
1351
+ pd->flags = JSPD_ERROR;
1352
+ pd->value = JSVAL_VOID;
1353
+ } else {
1354
+ pd->flags = JSPD_EXCEPTION;
1355
+ pd->value = cx->exception;
1356
+ }
1357
+ } else {
1358
+ pd->flags = 0;
1359
+ }
1360
+
1361
+ cx->throwing = wasThrowing;
1362
+ if (wasThrowing) {
1363
+ cx->exception = lastException;
1364
+ if (JSVAL_IS_GCTHING(lastException))
1365
+ js_RemoveRoot(cx->runtime, &lastException);
1366
+ }
1367
+
1368
+ pd->flags |= ((sprop->attrs & JSPROP_ENUMERATE) ? JSPD_ENUMERATE : 0)
1369
+ | ((sprop->attrs & JSPROP_READONLY) ? JSPD_READONLY : 0)
1370
+ | ((sprop->attrs & JSPROP_PERMANENT) ? JSPD_PERMANENT : 0);
1371
+ pd->spare = 0;
1372
+ if (sprop->getter == js_GetCallArg) {
1373
+ pd->slot = sprop->shortid;
1374
+ pd->flags |= JSPD_ARGUMENT;
1375
+ } else if (sprop->getter == js_GetCallVar) {
1376
+ pd->slot = sprop->shortid;
1377
+ pd->flags |= JSPD_VARIABLE;
1378
+ } else {
1379
+ pd->slot = 0;
1380
+ }
1381
+ pd->alias = JSVAL_VOID;
1382
+ scope = OBJ_SCOPE(obj);
1383
+ if (SPROP_HAS_VALID_SLOT(sprop, scope)) {
1384
+ for (aprop = SCOPE_LAST_PROP(scope); aprop; aprop = aprop->parent) {
1385
+ if (aprop != sprop && aprop->slot == sprop->slot) {
1386
+ pd->alias = ID_TO_VALUE(aprop->id);
1387
+ break;
1388
+ }
1389
+ }
1390
+ }
1391
+ return JS_TRUE;
1392
+ }
1393
+
1394
+ JS_PUBLIC_API(JSBool)
1395
+ JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda)
1396
+ {
1397
+ JSClass *clasp;
1398
+ JSScope *scope;
1399
+ uint32 i, n;
1400
+ JSPropertyDesc *pd;
1401
+ JSScopeProperty *sprop;
1402
+
1403
+ clasp = OBJ_GET_CLASS(cx, obj);
1404
+ if (!OBJ_IS_NATIVE(obj) || (clasp->flags & JSCLASS_NEW_ENUMERATE)) {
1405
+ JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
1406
+ JSMSG_CANT_DESCRIBE_PROPS, clasp->name);
1407
+ return JS_FALSE;
1408
+ }
1409
+ if (!clasp->enumerate(cx, obj))
1410
+ return JS_FALSE;
1411
+
1412
+ /* have no props, or object's scope has not mutated from that of proto */
1413
+ scope = OBJ_SCOPE(obj);
1414
+ if (scope->object != obj || scope->entryCount == 0) {
1415
+ pda->length = 0;
1416
+ pda->array = NULL;
1417
+ return JS_TRUE;
1418
+ }
1419
+
1420
+ n = STOBJ_NSLOTS(obj);
1421
+ if (n > scope->entryCount)
1422
+ n = scope->entryCount;
1423
+ pd = (JSPropertyDesc *) JS_malloc(cx, (size_t)n * sizeof(JSPropertyDesc));
1424
+ if (!pd)
1425
+ return JS_FALSE;
1426
+ i = 0;
1427
+ for (sprop = SCOPE_LAST_PROP(scope); sprop; sprop = sprop->parent) {
1428
+ if (SCOPE_HAD_MIDDLE_DELETE(scope) && !SCOPE_HAS_PROPERTY(scope, sprop))
1429
+ continue;
1430
+ if (!js_AddRoot(cx, &pd[i].id, NULL))
1431
+ goto bad;
1432
+ if (!js_AddRoot(cx, &pd[i].value, NULL))
1433
+ goto bad;
1434
+ if (!JS_GetPropertyDesc(cx, obj, sprop, &pd[i]))
1435
+ goto bad;
1436
+ if ((pd[i].flags & JSPD_ALIAS) && !js_AddRoot(cx, &pd[i].alias, NULL))
1437
+ goto bad;
1438
+ if (++i == n)
1439
+ break;
1440
+ }
1441
+ pda->length = i;
1442
+ pda->array = pd;
1443
+ return JS_TRUE;
1444
+
1445
+ bad:
1446
+ pda->length = i + 1;
1447
+ pda->array = pd;
1448
+ JS_PutPropertyDescArray(cx, pda);
1449
+ return JS_FALSE;
1450
+ }
1451
+
1452
+ JS_PUBLIC_API(void)
1453
+ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda)
1454
+ {
1455
+ JSPropertyDesc *pd;
1456
+ uint32 i;
1457
+
1458
+ pd = pda->array;
1459
+ for (i = 0; i < pda->length; i++) {
1460
+ js_RemoveRoot(cx->runtime, &pd[i].id);
1461
+ js_RemoveRoot(cx->runtime, &pd[i].value);
1462
+ if (pd[i].flags & JSPD_ALIAS)
1463
+ js_RemoveRoot(cx->runtime, &pd[i].alias);
1464
+ }
1465
+ JS_free(cx, pd);
1466
+ }
1467
+
1468
+ /************************************************************************/
1469
+
1470
+ JS_PUBLIC_API(JSBool)
1471
+ JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure)
1472
+ {
1473
+ rt->globalDebugHooks.debuggerHandler = handler;
1474
+ rt->globalDebugHooks.debuggerHandlerData = closure;
1475
+ return JS_TRUE;
1476
+ }
1477
+
1478
+ JS_PUBLIC_API(JSBool)
1479
+ JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure)
1480
+ {
1481
+ rt->globalDebugHooks.sourceHandler = handler;
1482
+ rt->globalDebugHooks.sourceHandlerData = closure;
1483
+ return JS_TRUE;
1484
+ }
1485
+
1486
+ JS_PUBLIC_API(JSBool)
1487
+ JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure)
1488
+ {
1489
+ rt->globalDebugHooks.executeHook = hook;
1490
+ rt->globalDebugHooks.executeHookData = closure;
1491
+ return JS_TRUE;
1492
+ }
1493
+
1494
+ JS_PUBLIC_API(JSBool)
1495
+ JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure)
1496
+ {
1497
+ rt->globalDebugHooks.callHook = hook;
1498
+ rt->globalDebugHooks.callHookData = closure;
1499
+ return JS_TRUE;
1500
+ }
1501
+
1502
+ JS_PUBLIC_API(JSBool)
1503
+ JS_SetObjectHook(JSRuntime *rt, JSObjectHook hook, void *closure)
1504
+ {
1505
+ rt->globalDebugHooks.objectHook = hook;
1506
+ rt->globalDebugHooks.objectHookData = closure;
1507
+ return JS_TRUE;
1508
+ }
1509
+
1510
+ JS_PUBLIC_API(JSBool)
1511
+ JS_SetThrowHook(JSRuntime *rt, JSTrapHandler hook, void *closure)
1512
+ {
1513
+ rt->globalDebugHooks.throwHook = hook;
1514
+ rt->globalDebugHooks.throwHookData = closure;
1515
+ return JS_TRUE;
1516
+ }
1517
+
1518
+ JS_PUBLIC_API(JSBool)
1519
+ JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure)
1520
+ {
1521
+ rt->globalDebugHooks.debugErrorHook = hook;
1522
+ rt->globalDebugHooks.debugErrorHookData = closure;
1523
+ return JS_TRUE;
1524
+ }
1525
+
1526
+ /************************************************************************/
1527
+
1528
+ JS_PUBLIC_API(size_t)
1529
+ JS_GetObjectTotalSize(JSContext *cx, JSObject *obj)
1530
+ {
1531
+ size_t nbytes;
1532
+ JSScope *scope;
1533
+
1534
+ nbytes = sizeof *obj;
1535
+ if (obj->dslots) {
1536
+ nbytes += ((uint32)obj->dslots[-1] - JS_INITIAL_NSLOTS + 1)
1537
+ * sizeof obj->dslots[0];
1538
+ }
1539
+ if (OBJ_IS_NATIVE(obj)) {
1540
+ scope = OBJ_SCOPE(obj);
1541
+ if (scope->object == obj) {
1542
+ nbytes += sizeof *scope;
1543
+ nbytes += SCOPE_CAPACITY(scope) * sizeof(JSScopeProperty *);
1544
+ }
1545
+ }
1546
+ return nbytes;
1547
+ }
1548
+
1549
+ static size_t
1550
+ GetAtomTotalSize(JSContext *cx, JSAtom *atom)
1551
+ {
1552
+ size_t nbytes;
1553
+
1554
+ nbytes = sizeof(JSAtom *) + sizeof(JSDHashEntryStub);
1555
+ if (ATOM_IS_STRING(atom)) {
1556
+ nbytes += sizeof(JSString);
1557
+ nbytes += (JSFLATSTR_LENGTH(ATOM_TO_STRING(atom)) + 1) * sizeof(jschar);
1558
+ } else if (ATOM_IS_DOUBLE(atom)) {
1559
+ nbytes += sizeof(jsdouble);
1560
+ }
1561
+ return nbytes;
1562
+ }
1563
+
1564
+ JS_PUBLIC_API(size_t)
1565
+ JS_GetFunctionTotalSize(JSContext *cx, JSFunction *fun)
1566
+ {
1567
+ size_t nbytes;
1568
+
1569
+ nbytes = sizeof *fun;
1570
+ nbytes += JS_GetObjectTotalSize(cx, FUN_OBJECT(fun));
1571
+ if (FUN_INTERPRETED(fun))
1572
+ nbytes += JS_GetScriptTotalSize(cx, fun->u.i.script);
1573
+ if (fun->atom)
1574
+ nbytes += GetAtomTotalSize(cx, fun->atom);
1575
+ return nbytes;
1576
+ }
1577
+
1578
+ #include "jsemit.h"
1579
+
1580
+ JS_PUBLIC_API(size_t)
1581
+ JS_GetScriptTotalSize(JSContext *cx, JSScript *script)
1582
+ {
1583
+ size_t nbytes, pbytes;
1584
+ jsatomid i;
1585
+ jssrcnote *sn, *notes;
1586
+ JSObjectArray *objarray;
1587
+ JSPrincipals *principals;
1588
+
1589
+ nbytes = sizeof *script;
1590
+ if (script->object)
1591
+ nbytes += JS_GetObjectTotalSize(cx, script->object);
1592
+
1593
+ nbytes += script->length * sizeof script->code[0];
1594
+ nbytes += script->atomMap.length * sizeof script->atomMap.vector[0];
1595
+ for (i = 0; i < script->atomMap.length; i++)
1596
+ nbytes += GetAtomTotalSize(cx, script->atomMap.vector[i]);
1597
+
1598
+ if (script->filename)
1599
+ nbytes += strlen(script->filename) + 1;
1600
+
1601
+ notes = SCRIPT_NOTES(script);
1602
+ for (sn = notes; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn))
1603
+ continue;
1604
+ nbytes += (sn - notes + 1) * sizeof *sn;
1605
+
1606
+ if (script->objectsOffset != 0) {
1607
+ objarray = JS_SCRIPT_OBJECTS(script);
1608
+ i = objarray->length;
1609
+ nbytes += sizeof *objarray + i * sizeof objarray->vector[0];
1610
+ do {
1611
+ nbytes += JS_GetObjectTotalSize(cx, objarray->vector[--i]);
1612
+ } while (i != 0);
1613
+ }
1614
+
1615
+ if (script->regexpsOffset != 0) {
1616
+ objarray = JS_SCRIPT_REGEXPS(script);
1617
+ i = objarray->length;
1618
+ nbytes += sizeof *objarray + i * sizeof objarray->vector[0];
1619
+ do {
1620
+ nbytes += JS_GetObjectTotalSize(cx, objarray->vector[--i]);
1621
+ } while (i != 0);
1622
+ }
1623
+
1624
+ if (script->trynotesOffset != 0) {
1625
+ nbytes += sizeof(JSTryNoteArray) +
1626
+ JS_SCRIPT_TRYNOTES(script)->length * sizeof(JSTryNote);
1627
+ }
1628
+
1629
+ principals = script->principals;
1630
+ if (principals) {
1631
+ JS_ASSERT(principals->refcount);
1632
+ pbytes = sizeof *principals;
1633
+ if (principals->refcount > 1)
1634
+ pbytes = JS_HOWMANY(pbytes, principals->refcount);
1635
+ nbytes += pbytes;
1636
+ }
1637
+
1638
+ return nbytes;
1639
+ }
1640
+
1641
+ JS_PUBLIC_API(uint32)
1642
+ JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp)
1643
+ {
1644
+ if (!fp)
1645
+ fp = cx->fp;
1646
+ while (fp) {
1647
+ if (fp->script)
1648
+ return JS_GetScriptFilenameFlags(fp->script);
1649
+ fp = fp->down;
1650
+ }
1651
+ return 0;
1652
+ }
1653
+
1654
+ JS_PUBLIC_API(uint32)
1655
+ JS_GetScriptFilenameFlags(JSScript *script)
1656
+ {
1657
+ JS_ASSERT(script);
1658
+ if (!script->filename)
1659
+ return JSFILENAME_NULL;
1660
+ return js_GetScriptFilenameFlags(script->filename);
1661
+ }
1662
+
1663
+ JS_PUBLIC_API(JSBool)
1664
+ JS_FlagScriptFilenamePrefix(JSRuntime *rt, const char *prefix, uint32 flags)
1665
+ {
1666
+ if (!js_SaveScriptFilenameRT(rt, prefix, flags))
1667
+ return JS_FALSE;
1668
+ return JS_TRUE;
1669
+ }
1670
+
1671
+ JS_PUBLIC_API(JSBool)
1672
+ JS_IsSystemObject(JSContext *cx, JSObject *obj)
1673
+ {
1674
+ return STOBJ_IS_SYSTEM(obj);
1675
+ }
1676
+
1677
+ JS_PUBLIC_API(JSObject *)
1678
+ JS_NewSystemObject(JSContext *cx, JSClass *clasp, JSObject *proto,
1679
+ JSObject *parent, JSBool system)
1680
+ {
1681
+ JSObject *obj;
1682
+
1683
+ obj = js_NewObject(cx, clasp, proto, parent, 0);
1684
+ if (obj && system)
1685
+ STOBJ_SET_SYSTEM(obj);
1686
+ return obj;
1687
+ }
1688
+
1689
+ /************************************************************************/
1690
+
1691
+ JS_PUBLIC_API(JSDebugHooks *)
1692
+ JS_GetGlobalDebugHooks(JSRuntime *rt)
1693
+ {
1694
+ return &rt->globalDebugHooks;
1695
+ }
1696
+
1697
+ JS_PUBLIC_API(JSDebugHooks *)
1698
+ JS_SetContextDebugHooks(JSContext *cx, JSDebugHooks *hooks)
1699
+ {
1700
+ JSDebugHooks *old;
1701
+
1702
+ JS_ASSERT(hooks);
1703
+ old = cx->debugHooks;
1704
+ cx->debugHooks = hooks;
1705
+ return old;
1706
+ }
1707
+
1708
+ #ifdef MOZ_SHARK
1709
+
1710
+ #include <CHUD/CHUD.h>
1711
+
1712
+ JS_PUBLIC_API(JSBool)
1713
+ JS_StartChudRemote()
1714
+ {
1715
+ if (chudIsRemoteAccessAcquired() &&
1716
+ (chudStartRemotePerfMonitor("Mozilla") == chudSuccess)) {
1717
+ return JS_TRUE;
1718
+ }
1719
+
1720
+ return JS_FALSE;
1721
+ }
1722
+
1723
+ JS_PUBLIC_API(JSBool)
1724
+ JS_StopChudRemote()
1725
+ {
1726
+ if (chudIsRemoteAccessAcquired() &&
1727
+ (chudStopRemotePerfMonitor() == chudSuccess)) {
1728
+ return JS_TRUE;
1729
+ }
1730
+
1731
+ return JS_FALSE;
1732
+ }
1733
+
1734
+ JS_PUBLIC_API(JSBool)
1735
+ JS_ConnectShark()
1736
+ {
1737
+ if (!chudIsInitialized() && (chudInitialize() != chudSuccess))
1738
+ return JS_FALSE;
1739
+
1740
+ if (chudAcquireRemoteAccess() != chudSuccess)
1741
+ return JS_FALSE;
1742
+
1743
+ return JS_TRUE;
1744
+ }
1745
+
1746
+ JS_PUBLIC_API(JSBool)
1747
+ JS_DisconnectShark()
1748
+ {
1749
+ if (chudIsRemoteAccessAcquired() && (chudReleaseRemoteAccess() != chudSuccess))
1750
+ return JS_FALSE;
1751
+
1752
+ return JS_TRUE;
1753
+ }
1754
+
1755
+ JS_FRIEND_API(JSBool)
1756
+ js_StartShark(JSContext *cx, JSObject *obj,
1757
+ uintN argc, jsval *argv, jsval *rval)
1758
+ {
1759
+ if (!JS_StartChudRemote()) {
1760
+ JS_ReportError(cx, "Error starting CHUD.");
1761
+ }
1762
+
1763
+ return JS_TRUE;
1764
+ }
1765
+
1766
+ JS_FRIEND_API(JSBool)
1767
+ js_StopShark(JSContext *cx, JSObject *obj,
1768
+ uintN argc, jsval *argv, jsval *rval)
1769
+ {
1770
+ if (!JS_StopChudRemote()) {
1771
+ JS_ReportError(cx, "Error stopping CHUD.");
1772
+ }
1773
+
1774
+ return JS_TRUE;
1775
+ }
1776
+
1777
+ JS_FRIEND_API(JSBool)
1778
+ js_ConnectShark(JSContext *cx, JSObject *obj,
1779
+ uintN argc, jsval *argv, jsval *rval)
1780
+ {
1781
+ if (!JS_ConnectShark()) {
1782
+ JS_ReportError(cx, "Error connecting to Shark.");
1783
+ }
1784
+
1785
+ return JS_TRUE;
1786
+ }
1787
+
1788
+ JS_FRIEND_API(JSBool)
1789
+ js_DisconnectShark(JSContext *cx, JSObject *obj,
1790
+ uintN argc, jsval *argv, jsval *rval)
1791
+ {
1792
+ if (!JS_DisconnectShark()) {
1793
+ JS_ReportError(cx, "Error disconnecting from Shark.");
1794
+ }
1795
+
1796
+ return JS_TRUE;
1797
+ }
1798
+
1799
+ #endif /* MOZ_SHARK */