/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jsscript.h

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs · C++ Header · 330 lines · 167 code · 49 blank · 114 comment · 12 complexity · 0f4eaec5bc0051cd70962274b55fa7bc MD5 · raw file

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * vim: set ts=8 sw=4 et tw=79 ft=cpp:
  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. #ifndef jsscript_h___
  41. #define jsscript_h___
  42. /*
  43. * JS script descriptor.
  44. */
  45. #include "jsatom.h"
  46. #include "jsprvtd.h"
  47. JS_BEGIN_EXTERN_C
  48. /*
  49. * Type of try note associated with each catch or finally block, and also with
  50. * for-in loops.
  51. */
  52. typedef enum JSTryNoteKind {
  53. JSTRY_CATCH,
  54. JSTRY_FINALLY,
  55. JSTRY_ITER
  56. } JSTryNoteKind;
  57. /*
  58. * Exception handling record.
  59. */
  60. struct JSTryNote {
  61. uint8 kind; /* one of JSTryNoteKind */
  62. uint8 padding; /* explicit padding on uint16 boundary */
  63. uint16 stackDepth; /* stack depth upon exception handler entry */
  64. uint32 start; /* start of the try statement or for-in loop
  65. relative to script->main */
  66. uint32 length; /* length of the try statement or for-in loop */
  67. };
  68. typedef struct JSTryNoteArray {
  69. JSTryNote *vector; /* array of indexed try notes */
  70. uint32 length; /* count of indexed try notes */
  71. } JSTryNoteArray;
  72. typedef struct JSObjectArray {
  73. JSObject **vector; /* array of indexed objects */
  74. uint32 length; /* count of indexed objects */
  75. } JSObjectArray;
  76. typedef struct JSUpvarArray {
  77. uint32 *vector; /* array of indexed upvar cookies */
  78. uint32 length; /* count of indexed upvar cookies */
  79. } JSUpvarArray;
  80. #define MAKE_UPVAR_COOKIE(skip,slot) ((skip) << 16 | (slot))
  81. #define UPVAR_FRAME_SKIP(cookie) ((uint32)(cookie) >> 16)
  82. #define UPVAR_FRAME_SLOT(cookie) ((uint16)(cookie))
  83. #define JS_OBJECT_ARRAY_SIZE(length) \
  84. (offsetof(JSObjectArray, vector) + sizeof(JSObject *) * (length))
  85. #if defined DEBUG && defined JS_THREADSAFE
  86. # define CHECK_SCRIPT_OWNER 1
  87. #endif
  88. struct JSScript {
  89. jsbytecode *code; /* bytecodes and their immediate operands */
  90. uint32 length; /* length of code vector */
  91. uint16 version; /* JS version under which script was compiled */
  92. uint16 nfixed; /* number of slots besides stack operands in
  93. slot array */
  94. uint8 objectsOffset; /* offset to the array of nested function,
  95. block, scope, xml and one-time regexps
  96. objects or 0 if none */
  97. uint8 upvarsOffset; /* offset of the array of display ("up")
  98. closure vars or 0 if none */
  99. uint8 regexpsOffset; /* offset to the array of to-be-cloned
  100. regexps or 0 if none. */
  101. uint8 trynotesOffset; /* offset to the array of try notes or
  102. 0 if none */
  103. uint8 flags; /* see below */
  104. jsbytecode *main; /* main entry point, after predef'ing prolog */
  105. JSAtomMap atomMap; /* maps immediate index to literal struct */
  106. const char *filename; /* source filename or null */
  107. uint32 lineno; /* base line number of script */
  108. uint16 nslots; /* vars plus maximum stack depth */
  109. uint16 staticDepth;/* static depth for display maintenance */
  110. JSPrincipals *principals;/* principals for this script */
  111. union {
  112. JSObject *object; /* optional Script-class object wrapper */
  113. JSScript *nextToGC; /* next to GC in rt->scriptsToGC list */
  114. } u;
  115. #ifdef CHECK_SCRIPT_OWNER
  116. JSThread *owner; /* for thread-safe life-cycle assertions */
  117. #endif
  118. };
  119. #define JSSF_NO_SCRIPT_RVAL 0x01 /* no need for result value of last
  120. expression statement */
  121. static JS_INLINE uintN
  122. StackDepth(JSScript *script)
  123. {
  124. return script->nslots - script->nfixed;
  125. }
  126. /* No need to store script->notes now that it is allocated right after code. */
  127. #define SCRIPT_NOTES(script) ((jssrcnote*)((script)->code+(script)->length))
  128. #define JS_SCRIPT_OBJECTS(script) \
  129. (JS_ASSERT((script)->objectsOffset != 0), \
  130. (JSObjectArray *)((uint8 *)(script) + (script)->objectsOffset))
  131. #define JS_SCRIPT_UPVARS(script) \
  132. (JS_ASSERT((script)->upvarsOffset != 0), \
  133. (JSUpvarArray *)((uint8 *)(script) + (script)->upvarsOffset))
  134. #define JS_SCRIPT_REGEXPS(script) \
  135. (JS_ASSERT((script)->regexpsOffset != 0), \
  136. (JSObjectArray *)((uint8 *)(script) + (script)->regexpsOffset))
  137. #define JS_SCRIPT_TRYNOTES(script) \
  138. (JS_ASSERT((script)->trynotesOffset != 0), \
  139. (JSTryNoteArray *)((uint8 *)(script) + (script)->trynotesOffset))
  140. #define JS_GET_SCRIPT_ATOM(script_, index, atom) \
  141. JS_BEGIN_MACRO \
  142. if (cx->fp && cx->fp->imacpc && cx->fp->script == script_) { \
  143. JS_ASSERT((size_t)(index) < js_common_atom_count); \
  144. (atom) = COMMON_ATOMS_START(&cx->runtime->atomState)[index]; \
  145. } else { \
  146. JSAtomMap *atoms_ = &(script_)->atomMap; \
  147. JS_ASSERT((uint32)(index) < atoms_->length); \
  148. (atom) = atoms_->vector[index]; \
  149. } \
  150. JS_END_MACRO
  151. #define JS_GET_SCRIPT_OBJECT(script, index, obj) \
  152. JS_BEGIN_MACRO \
  153. JSObjectArray *objects_ = JS_SCRIPT_OBJECTS(script); \
  154. JS_ASSERT((uint32)(index) < objects_->length); \
  155. (obj) = objects_->vector[index]; \
  156. JS_END_MACRO
  157. #define JS_GET_SCRIPT_FUNCTION(script, index, fun) \
  158. JS_BEGIN_MACRO \
  159. JSObject *funobj_; \
  160. \
  161. JS_GET_SCRIPT_OBJECT(script, index, funobj_); \
  162. JS_ASSERT(HAS_FUNCTION_CLASS(funobj_)); \
  163. JS_ASSERT(funobj_ == (JSObject *) STOBJ_GET_PRIVATE(funobj_)); \
  164. (fun) = (JSFunction *) funobj_; \
  165. JS_ASSERT(FUN_INTERPRETED(fun)); \
  166. JS_END_MACRO
  167. #define JS_GET_SCRIPT_REGEXP(script, index, obj) \
  168. JS_BEGIN_MACRO \
  169. JSObjectArray *regexps_ = JS_SCRIPT_REGEXPS(script); \
  170. JS_ASSERT((uint32)(index) < regexps_->length); \
  171. (obj) = regexps_->vector[index]; \
  172. JS_ASSERT(STOBJ_GET_CLASS(obj) == &js_RegExpClass); \
  173. JS_END_MACRO
  174. /*
  175. * Check if pc is inside a try block that has finally code. GC calls this to
  176. * check if it is necessary to schedule generator.close() invocation for an
  177. * unreachable generator.
  178. */
  179. JSBool
  180. js_IsInsideTryWithFinally(JSScript *script, jsbytecode *pc);
  181. extern JS_FRIEND_DATA(JSClass) js_ScriptClass;
  182. extern JSObject *
  183. js_InitScriptClass(JSContext *cx, JSObject *obj);
  184. /*
  185. * On first new context in rt, initialize script runtime state, specifically
  186. * the script filename table and its lock.
  187. */
  188. extern JSBool
  189. js_InitRuntimeScriptState(JSRuntime *rt);
  190. /*
  191. * On last context destroy for rt, if script filenames are all GC'd, free the
  192. * script filename table and its lock.
  193. */
  194. extern void
  195. js_FinishRuntimeScriptState(JSRuntime *rt);
  196. /*
  197. * On JS_DestroyRuntime(rt), forcibly free script filename prefixes and any
  198. * script filename table entries that have not been GC'd, the latter using
  199. * js_FinishRuntimeScriptState.
  200. *
  201. * This allows script filename prefixes to outlive any context in rt.
  202. */
  203. extern void
  204. js_FreeRuntimeScriptState(JSRuntime *rt);
  205. extern const char *
  206. js_SaveScriptFilename(JSContext *cx, const char *filename);
  207. extern const char *
  208. js_SaveScriptFilenameRT(JSRuntime *rt, const char *filename, uint32 flags);
  209. extern uint32
  210. js_GetScriptFilenameFlags(const char *filename);
  211. extern void
  212. js_MarkScriptFilename(const char *filename);
  213. extern void
  214. js_MarkScriptFilenames(JSRuntime *rt, JSBool keepAtoms);
  215. extern void
  216. js_SweepScriptFilenames(JSRuntime *rt);
  217. /*
  218. * Two successively less primitive ways to make a new JSScript. The first
  219. * does *not* call a non-null cx->runtime->newScriptHook -- only the second,
  220. * js_NewScriptFromCG, calls this optional debugger hook.
  221. *
  222. * The js_NewScript function can't know whether the script it creates belongs
  223. * to a function, or is top-level or eval code, but the debugger wants access
  224. * to the newly made script's function, if any -- so callers of js_NewScript
  225. * are responsible for notifying the debugger after successfully creating any
  226. * kind (function or other) of new JSScript.
  227. */
  228. extern JSScript *
  229. js_NewScript(JSContext *cx, uint32 length, uint32 nsrcnotes, uint32 natoms,
  230. uint32 nobjects, uint32 nupvars, uint32 nregexps,
  231. uint32 ntrynotes);
  232. extern JSScript *
  233. js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg);
  234. /*
  235. * New-script-hook calling is factored from js_NewScriptFromCG so that it
  236. * and callers of js_XDRScript can share this code. In the case of callers
  237. * of js_XDRScript, the hook should be invoked only after successful decode
  238. * of any owning function (the fun parameter) or script object (null fun).
  239. */
  240. extern JS_FRIEND_API(void)
  241. js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun);
  242. extern JS_FRIEND_API(void)
  243. js_CallDestroyScriptHook(JSContext *cx, JSScript *script);
  244. extern void
  245. js_DestroyScript(JSContext *cx, JSScript *script);
  246. extern void
  247. js_TraceScript(JSTracer *trc, JSScript *script);
  248. /*
  249. * To perturb as little code as possible, we introduce a js_GetSrcNote lookup
  250. * cache without adding an explicit cx parameter. Thus js_GetSrcNote becomes
  251. * a macro that uses cx from its calls' lexical environments.
  252. */
  253. #define js_GetSrcNote(script,pc) js_GetSrcNoteCached(cx, script, pc)
  254. extern jssrcnote *
  255. js_GetSrcNoteCached(JSContext *cx, JSScript *script, jsbytecode *pc);
  256. /*
  257. * NOTE: use js_FramePCToLineNumber(cx, fp) when you have an active fp, in
  258. * preference to js_PCToLineNumber (cx, fp->script fp->regs->pc), because
  259. * fp->imacpc may be non-null, indicating an active imacro.
  260. */
  261. extern uintN
  262. js_FramePCToLineNumber(JSContext *cx, JSStackFrame *fp);
  263. extern uintN
  264. js_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
  265. extern jsbytecode *
  266. js_LineNumberToPC(JSScript *script, uintN lineno);
  267. extern JS_FRIEND_API(uintN)
  268. js_GetScriptLineExtent(JSScript *script);
  269. /*
  270. * If magic is non-null, js_XDRScript succeeds on magic number mismatch but
  271. * returns false in *magic; it reflects a match via a true *magic out param.
  272. * If magic is null, js_XDRScript returns false on bad magic number errors,
  273. * which it reports.
  274. *
  275. * NB: callers must call js_CallNewScriptHook after successful JSXDR_DECODE
  276. * and subsequent set-up of owning function or script object, if any.
  277. */
  278. extern JSBool
  279. js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *magic);
  280. JS_END_EXTERN_C
  281. #endif /* jsscript_h___ */