PageRenderTime 38ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 296 lines | 150 code | 50 blank | 96 comment | 3 complexity | 58edbe1f7a5df9208436b4271a438ae9 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  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. #ifndef jsfun_h___
  40. #define jsfun_h___
  41. /*
  42. * JS function definitions.
  43. */
  44. #include "jsprvtd.h"
  45. #include "jspubtd.h"
  46. #include "jsobj.h"
  47. JS_BEGIN_EXTERN_C
  48. typedef struct JSLocalNameMap JSLocalNameMap;
  49. /*
  50. * Depending on the number of arguments and variables in the function their
  51. * names and attributes are stored either as a single atom or as an array of
  52. * tagged atoms (when there are few locals) or as a hash-based map (when there
  53. * are many locals). In the first 2 cases the lowest bit of the atom is used
  54. * as a tag to distinguish const from var. See jsfun.c for details.
  55. */
  56. typedef union JSLocalNames {
  57. jsuword taggedAtom;
  58. jsuword *array;
  59. JSLocalNameMap *map;
  60. } JSLocalNames;
  61. struct JSFunction {
  62. JSObject object; /* GC'ed object header */
  63. uint16 nargs; /* maximum number of specified arguments,
  64. reflected as f.length/f.arity */
  65. uint16 flags; /* flags, see JSFUN_* below and in jsapi.h */
  66. union {
  67. struct {
  68. uint16 extra; /* number of arg slots for local GC roots */
  69. uint16 spare; /* reserved for future use */
  70. JSNative native; /* native method pointer or null */
  71. union {
  72. JSClass *clasp; /* class of objects constructed
  73. by this function */
  74. JSTraceableNative *trcinfo; /* tracer metadata; can be first
  75. element of array */
  76. } u;
  77. } n;
  78. struct {
  79. uint16 nvars; /* number of local variables */
  80. uint16 nupvars; /* number of upvars (computable from script
  81. but here for faster access) */
  82. JSScript *script; /* interpreted bytecode descriptor or null */
  83. JSLocalNames names; /* argument and variable names */
  84. } i;
  85. } u;
  86. JSAtom *atom; /* name for diagnostics and decompiling */
  87. };
  88. #define JSFUN_TRACEABLE 0x2000 /* can trace across calls to this native
  89. function; use FUN_TRCINFO if set,
  90. FUN_CLASP if unset */
  91. #define JSFUN_EXPR_CLOSURE 0x4000 /* expression closure: function(x)x*x */
  92. #define JSFUN_INTERPRETED 0x8000 /* use u.i if set, u.n if unset */
  93. #define JSFUN_SCRIPT_OR_FAST_NATIVE (JSFUN_INTERPRETED | JSFUN_FAST_NATIVE)
  94. #define FUN_OBJECT(fun) (&(fun)->object)
  95. #define FUN_INTERPRETED(fun) ((fun)->flags & JSFUN_INTERPRETED)
  96. #define FUN_SLOW_NATIVE(fun) (!((fun)->flags & JSFUN_SCRIPT_OR_FAST_NATIVE))
  97. #define FUN_SCRIPT(fun) (FUN_INTERPRETED(fun) ? (fun)->u.i.script : NULL)
  98. #define FUN_NATIVE(fun) (FUN_SLOW_NATIVE(fun) ? (fun)->u.n.native : NULL)
  99. #define FUN_FAST_NATIVE(fun) (((fun)->flags & JSFUN_FAST_NATIVE) \
  100. ? (JSFastNative) (fun)->u.n.native \
  101. : NULL)
  102. #define FUN_MINARGS(fun) (((fun)->flags & JSFUN_FAST_NATIVE) \
  103. ? 0 \
  104. : (fun)->nargs)
  105. #define FUN_CLASP(fun) (JS_ASSERT(!FUN_INTERPRETED(fun)), \
  106. JS_ASSERT(!((fun)->flags & JSFUN_TRACEABLE)), \
  107. fun->u.n.u.clasp)
  108. #define FUN_TRCINFO(fun) (JS_ASSERT(!FUN_INTERPRETED(fun)), \
  109. JS_ASSERT((fun)->flags & JSFUN_TRACEABLE), \
  110. fun->u.n.u.trcinfo)
  111. /*
  112. * Traceable native. This expands to a JSFunctionSpec initializer (like JS_FN
  113. * in jsapi.h). fastcall is a JSFastNative; trcinfo is a JSTraceableNative *.
  114. */
  115. #ifdef JS_TRACER
  116. /* MSVC demands the intermediate (void *) cast here. */
  117. # define JS_TN(name,fastcall,nargs,flags,trcinfo) \
  118. {name, (JSNative)(void *)(trcinfo), nargs, \
  119. (flags) | JSFUN_FAST_NATIVE | JSFUN_STUB_GSOPS | JSFUN_TRACEABLE, 0}
  120. #else
  121. # define JS_TN(name,fastcall,nargs,flags,trcinfo) \
  122. JS_FN(name, fastcall, nargs, flags)
  123. #endif
  124. extern JSClass js_ArgumentsClass;
  125. extern JS_FRIEND_DATA(JSClass) js_CallClass;
  126. /* JS_FRIEND_DATA so that VALUE_IS_FUNCTION is callable from the shell. */
  127. extern JS_FRIEND_DATA(JSClass) js_FunctionClass;
  128. #define HAS_FUNCTION_CLASS(obj) (STOBJ_GET_CLASS(obj) == &js_FunctionClass)
  129. /*
  130. * NB: jsapi.h and jsobj.h must be included before any call to this macro.
  131. */
  132. #define VALUE_IS_FUNCTION(cx, v) \
  133. (!JSVAL_IS_PRIMITIVE(v) && HAS_FUNCTION_CLASS(JSVAL_TO_OBJECT(v)))
  134. /*
  135. * Macro to access the private slot of the function object after the slot is
  136. * initialized.
  137. */
  138. #define GET_FUNCTION_PRIVATE(cx, funobj) \
  139. (JS_ASSERT(HAS_FUNCTION_CLASS(funobj)), \
  140. (JSFunction *) OBJ_GET_PRIVATE(cx, funobj))
  141. extern JSObject *
  142. js_InitFunctionClass(JSContext *cx, JSObject *obj);
  143. extern JSObject *
  144. js_InitArgumentsClass(JSContext *cx, JSObject *obj);
  145. extern JSObject *
  146. js_InitCallClass(JSContext *cx, JSObject *obj);
  147. extern JSFunction *
  148. js_NewFunction(JSContext *cx, JSObject *funobj, JSNative native, uintN nargs,
  149. uintN flags, JSObject *parent, JSAtom *atom);
  150. extern void
  151. js_TraceFunction(JSTracer *trc, JSFunction *fun);
  152. extern void
  153. js_FinalizeFunction(JSContext *cx, JSFunction *fun);
  154. extern JSObject *
  155. js_CloneFunctionObject(JSContext *cx, JSFunction *fun, JSObject *parent);
  156. extern JSBool
  157. js_LinkFunctionObject(JSContext *cx, JSFunction *fun, JSObject *object);
  158. extern JSFunction *
  159. js_DefineFunction(JSContext *cx, JSObject *obj, JSAtom *atom, JSNative native,
  160. uintN nargs, uintN flags);
  161. /*
  162. * Flags for js_ValueToFunction and js_ReportIsNotFunction. We depend on the
  163. * fact that JSINVOKE_CONSTRUCT (aka JSFRAME_CONSTRUCTING) is 1, and test that
  164. * with #if/#error in jsfun.c.
  165. */
  166. #define JSV2F_CONSTRUCT JSINVOKE_CONSTRUCT
  167. #define JSV2F_ITERATOR JSINVOKE_ITERATOR
  168. #define JSV2F_SEARCH_STACK 0x10000
  169. extern JSFunction *
  170. js_ValueToFunction(JSContext *cx, jsval *vp, uintN flags);
  171. extern JSObject *
  172. js_ValueToFunctionObject(JSContext *cx, jsval *vp, uintN flags);
  173. extern JSObject *
  174. js_ValueToCallableObject(JSContext *cx, jsval *vp, uintN flags);
  175. extern void
  176. js_ReportIsNotFunction(JSContext *cx, jsval *vp, uintN flags);
  177. extern JSObject *
  178. js_GetCallObject(JSContext *cx, JSStackFrame *fp, JSObject *parent);
  179. extern JS_FRIEND_API(JSBool)
  180. js_PutCallObject(JSContext *cx, JSStackFrame *fp);
  181. extern JSBool
  182. js_GetCallArg(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
  183. extern JSBool
  184. js_GetCallVar(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
  185. extern JSBool
  186. js_GetArgsValue(JSContext *cx, JSStackFrame *fp, jsval *vp);
  187. extern JSBool
  188. js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, jsval *vp);
  189. extern JSObject *
  190. js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
  191. extern JS_FRIEND_API(JSBool)
  192. js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
  193. extern JSBool
  194. js_XDRFunction(JSXDRState *xdr, JSObject **objp);
  195. typedef enum JSLocalKind {
  196. JSLOCAL_NONE,
  197. JSLOCAL_ARG,
  198. JSLOCAL_VAR,
  199. JSLOCAL_CONST,
  200. JSLOCAL_UPVAR
  201. } JSLocalKind;
  202. #define JS_UPVAR_LOCAL_NAME_START(fun) ((fun)->nargs + (fun)->u.i.nvars)
  203. #define JS_GET_LOCAL_NAME_COUNT(fun) (JS_UPVAR_LOCAL_NAME_START(fun) + \
  204. (fun)->u.i.nupvars)
  205. extern JSBool
  206. js_AddLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, JSLocalKind kind);
  207. /*
  208. * Look up an argument or variable name returning its kind when found or
  209. * JSLOCAL_NONE when no such name exists. When indexp is not null and the name
  210. * exists, *indexp will receive the index of the corresponding argument or
  211. * variable.
  212. */
  213. extern JSLocalKind
  214. js_LookupLocal(JSContext *cx, JSFunction *fun, JSAtom *atom, uintN *indexp);
  215. /*
  216. * Functions to work with local names as an array of words.
  217. *
  218. * js_GetLocalNameArray returns the array, or null if we are out of memory.
  219. * This function must not be called when JS_GET_LOCAL_NAME_COUNT(fun) is zero.
  220. *
  221. * The supplied pool is used to allocate the returned array, so the caller is
  222. * obligated to mark and release to free it.
  223. *
  224. * The elements of the array with index less than fun->nargs correspond to the
  225. * names of function formal parameters. An index >= fun->nargs addresses a var
  226. * binding. Use JS_LOCAL_NAME_TO_ATOM to convert array's element to an atom
  227. * pointer. This pointer can be null when the element is for a formal parameter
  228. * corresponding to a destructuring pattern.
  229. *
  230. * If nameWord does not name a formal parameter, use JS_LOCAL_NAME_IS_CONST to
  231. * check if nameWord corresponds to the const declaration.
  232. */
  233. extern jsuword *
  234. js_GetLocalNameArray(JSContext *cx, JSFunction *fun, struct JSArenaPool *pool);
  235. #define JS_LOCAL_NAME_TO_ATOM(nameWord) \
  236. ((JSAtom *) ((nameWord) & ~(jsuword) 1))
  237. #define JS_LOCAL_NAME_IS_CONST(nameWord) \
  238. ((((nameWord) & (jsuword) 1)) != 0)
  239. extern void
  240. js_FreezeLocalNames(JSContext *cx, JSFunction *fun);
  241. extern JSBool
  242. js_fun_apply(JSContext *cx, uintN argc, jsval *vp);
  243. extern JSBool
  244. js_fun_call(JSContext *cx, uintN argc, jsval *vp);
  245. JS_END_EXTERN_C
  246. #endif /* jsfun_h___ */