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

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 591 lines | 315 code | 78 blank | 198 comment | 21 complexity | e5dda830be4969e2c8188a1ecd3d31e5 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. * 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. #ifndef jsinterp_h___
  41. #define jsinterp_h___
  42. /*
  43. * JS interpreter interface.
  44. */
  45. #include "jsprvtd.h"
  46. #include "jspubtd.h"
  47. #include "jsfun.h"
  48. #include "jsopcode.h"
  49. #include "jsscript.h"
  50. JS_BEGIN_EXTERN_C
  51. typedef struct JSFrameRegs {
  52. jsbytecode *pc; /* program counter */
  53. jsval *sp; /* stack pointer */
  54. } JSFrameRegs;
  55. /*
  56. * JS stack frame, may be allocated on the C stack by native callers. Always
  57. * allocated on cx->stackPool for calls from the interpreter to an interpreted
  58. * function.
  59. *
  60. * NB: This struct is manually initialized in jsinterp.c and jsiter.c. If you
  61. * add new members, update both files. But first, try to remove members. The
  62. * sharp* and xml* members should be moved onto the stack as local variables
  63. * with well-known slots, if possible.
  64. */
  65. struct JSStackFrame {
  66. JSFrameRegs *regs;
  67. jsbytecode *imacpc; /* null or interpreter macro call pc */
  68. jsval *slots; /* variables, locals and operand stack */
  69. JSObject *callobj; /* lazily created Call object */
  70. JSObject *argsobj; /* lazily created arguments object */
  71. JSObject *varobj; /* variables object, where vars go */
  72. JSObject *callee; /* function or script object */
  73. JSScript *script; /* script being interpreted */
  74. JSFunction *fun; /* function being called or null */
  75. JSObject *thisp; /* "this" pointer if in method */
  76. uintN argc; /* actual argument count */
  77. jsval *argv; /* base of argument stack slots */
  78. jsval rval; /* function return value */
  79. JSStackFrame *down; /* previous frame */
  80. void *annotation; /* used by Java security */
  81. JSObject *scopeChain; /* scope chain */
  82. uintN sharpDepth; /* array/object initializer depth */
  83. JSObject *sharpArray; /* scope for #n= initializer vars */
  84. uint32 flags; /* frame flags -- see below */
  85. JSStackFrame *dormantNext; /* next dormant frame chain */
  86. JSObject *xmlNamespace; /* null or default xml namespace in E4X */
  87. JSObject *blockChain; /* active compile-time block scopes */
  88. JSStackFrame *displaySave; /* previous value of display entry for
  89. script->staticDepth */
  90. #ifdef DEBUG
  91. jsrefcount pcDisabledSave; /* for balanced property cache control */
  92. #endif
  93. };
  94. #ifdef DEBUG
  95. #ifdef __cplusplus
  96. static JS_INLINE uintN
  97. FramePCOffset(JSStackFrame* fp)
  98. {
  99. return uintN((fp->imacpc ? fp->imacpc : fp->regs->pc) - fp->script->code);
  100. }
  101. #endif
  102. #endif
  103. static JS_INLINE jsval *
  104. StackBase(JSStackFrame *fp)
  105. {
  106. return fp->slots + fp->script->nfixed;
  107. }
  108. static JS_INLINE uintN
  109. GlobalVarCount(JSStackFrame *fp)
  110. {
  111. uintN n;
  112. JS_ASSERT(!fp->fun);
  113. n = fp->script->nfixed;
  114. if (fp->script->regexpsOffset != 0)
  115. n -= JS_SCRIPT_REGEXPS(fp->script)->length;
  116. return n;
  117. }
  118. typedef struct JSInlineFrame {
  119. JSStackFrame frame; /* base struct */
  120. JSFrameRegs callerRegs; /* parent's frame registers */
  121. void *mark; /* mark before inline frame */
  122. void *hookData; /* debugger call hook data */
  123. JSVersion callerVersion; /* dynamic version of calling script */
  124. } JSInlineFrame;
  125. /* JS stack frame flags. */
  126. #define JSFRAME_CONSTRUCTING 0x01 /* frame is for a constructor invocation */
  127. #define JSFRAME_COMPUTED_THIS 0x02 /* frame.thisp was computed already */
  128. #define JSFRAME_ASSIGNING 0x04 /* a complex (not simplex JOF_ASSIGNING) op
  129. is currently assigning to a property */
  130. #define JSFRAME_DEBUGGER 0x08 /* frame for JS_EvaluateInStackFrame */
  131. #define JSFRAME_EVAL 0x10 /* frame for obj_eval */
  132. #define JSFRAME_ROOTED_ARGV 0x20 /* frame.argv is rooted by the caller */
  133. #define JSFRAME_YIELDING 0x40 /* js_Interpret dispatched JSOP_YIELD */
  134. #define JSFRAME_ITERATOR 0x80 /* trying to get an iterator for for-in */
  135. #define JSFRAME_POP_BLOCKS 0x100 /* scope chain contains blocks to pop */
  136. #define JSFRAME_GENERATOR 0x200 /* frame belongs to generator-iterator */
  137. #define JSFRAME_IMACRO_START 0x400 /* imacro starting -- see jstracer.h */
  138. #define JSFRAME_OVERRIDE_SHIFT 24 /* override bit-set params; see jsfun.c */
  139. #define JSFRAME_OVERRIDE_BITS 8
  140. #define JSFRAME_SPECIAL (JSFRAME_DEBUGGER | JSFRAME_EVAL)
  141. /*
  142. * Property cache with structurally typed capabilities for invalidation, for
  143. * polymorphic callsite method/get/set speedups.
  144. *
  145. * See bug https://bugzilla.mozilla.org/show_bug.cgi?id=365851.
  146. */
  147. #define PROPERTY_CACHE_LOG2 12
  148. #define PROPERTY_CACHE_SIZE JS_BIT(PROPERTY_CACHE_LOG2)
  149. #define PROPERTY_CACHE_MASK JS_BITMASK(PROPERTY_CACHE_LOG2)
  150. /*
  151. * Add kshape rather than xor it to avoid collisions between nearby bytecode
  152. * that are evolving an object by setting successive properties, incrementing
  153. * the object's scope->shape on each set.
  154. */
  155. #define PROPERTY_CACHE_HASH(pc,kshape) \
  156. (((((jsuword)(pc) >> PROPERTY_CACHE_LOG2) ^ (jsuword)(pc)) + (kshape)) & \
  157. PROPERTY_CACHE_MASK)
  158. #define PROPERTY_CACHE_HASH_PC(pc,kshape) \
  159. PROPERTY_CACHE_HASH(pc, kshape)
  160. #define PROPERTY_CACHE_HASH_ATOM(atom,obj,pobj) \
  161. PROPERTY_CACHE_HASH((jsuword)(atom) >> 2, OBJ_SHAPE(obj))
  162. /*
  163. * Property cache value capability macros.
  164. */
  165. #define PCVCAP_PROTOBITS 4
  166. #define PCVCAP_PROTOSIZE JS_BIT(PCVCAP_PROTOBITS)
  167. #define PCVCAP_PROTOMASK JS_BITMASK(PCVCAP_PROTOBITS)
  168. #define PCVCAP_SCOPEBITS 4
  169. #define PCVCAP_SCOPESIZE JS_BIT(PCVCAP_SCOPEBITS)
  170. #define PCVCAP_SCOPEMASK JS_BITMASK(PCVCAP_SCOPEBITS)
  171. #define PCVCAP_TAGBITS (PCVCAP_PROTOBITS + PCVCAP_SCOPEBITS)
  172. #define PCVCAP_TAGMASK JS_BITMASK(PCVCAP_TAGBITS)
  173. #define PCVCAP_TAG(t) ((t) & PCVCAP_TAGMASK)
  174. #define PCVCAP_MAKE(t,s,p) (((t) << PCVCAP_TAGBITS) | \
  175. ((s) << PCVCAP_PROTOBITS) | \
  176. (p))
  177. #define PCVCAP_SHAPE(t) ((t) >> PCVCAP_TAGBITS)
  178. #define SHAPE_OVERFLOW_BIT JS_BIT(32 - PCVCAP_TAGBITS)
  179. /*
  180. * When sprop is not null and the shape generation triggers the GC due to a
  181. * shape overflow, the functions roots sprop.
  182. */
  183. extern uint32
  184. js_GenerateShape(JSContext *cx, JSBool gcLocked, JSScopeProperty *sprop);
  185. struct JSPropCacheEntry {
  186. jsbytecode *kpc; /* pc if vcap tag is <= 1, else atom */
  187. jsuword kshape; /* key shape if pc, else obj for atom */
  188. jsuword vcap; /* value capability, see above */
  189. jsuword vword; /* value word, see PCVAL_* below */
  190. };
  191. #if defined DEBUG_brendan || defined DEBUG_brendaneich
  192. #define JS_PROPERTY_CACHE_METERING 1
  193. #endif
  194. typedef struct JSPropertyCache {
  195. JSPropCacheEntry table[PROPERTY_CACHE_SIZE];
  196. JSBool empty;
  197. jsrefcount disabled; /* signed for anti-underflow asserts */
  198. #ifdef JS_PROPERTY_CACHE_METERING
  199. uint32 fills; /* number of cache entry fills */
  200. uint32 nofills; /* couldn't fill (e.g. default get) */
  201. uint32 rofills; /* set on read-only prop can't fill */
  202. uint32 disfills; /* fill attempts on disabled cache */
  203. uint32 oddfills; /* fill attempt after setter deleted */
  204. uint32 modfills; /* fill that rehashed to a new entry */
  205. uint32 brandfills; /* scope brandings to type structural
  206. method fills */
  207. uint32 noprotos; /* resolve-returned non-proto pobj */
  208. uint32 longchains; /* overlong scope and/or proto chain */
  209. uint32 recycles; /* cache entries recycled by fills */
  210. uint32 pcrecycles; /* pc-keyed entries recycled by atom-
  211. keyed fills */
  212. uint32 tests; /* cache probes */
  213. uint32 pchits; /* fast-path polymorphic op hits */
  214. uint32 protopchits; /* pchits hitting immediate prototype */
  215. uint32 initests; /* cache probes from JSOP_INITPROP */
  216. uint32 inipchits; /* init'ing next property pchit case */
  217. uint32 inipcmisses; /* init'ing next property pc misses */
  218. uint32 settests; /* cache probes from JOF_SET opcodes */
  219. uint32 addpchits; /* adding next property pchit case */
  220. uint32 setpchits; /* setting existing property pchit */
  221. uint32 setpcmisses; /* setting/adding property pc misses */
  222. uint32 slotchanges; /* clasp->reserveSlots result variance-
  223. induced slot changes */
  224. uint32 setmisses; /* JSOP_SET{NAME,PROP} total misses */
  225. uint32 idmisses; /* slow-path key id == atom misses */
  226. uint32 komisses; /* slow-path key object misses */
  227. uint32 vcmisses; /* value capability misses */
  228. uint32 misses; /* cache misses */
  229. uint32 flushes; /* cache flushes */
  230. uint32 pcpurges; /* shadowing purges on proto chain */
  231. # define PCMETER(x) x
  232. #else
  233. # define PCMETER(x) ((void)0)
  234. #endif
  235. } JSPropertyCache;
  236. /*
  237. * Property cache value tagging/untagging macros.
  238. */
  239. #define PCVAL_OBJECT 0
  240. #define PCVAL_SLOT 1
  241. #define PCVAL_SPROP 2
  242. #define PCVAL_TAGBITS 2
  243. #define PCVAL_TAGMASK JS_BITMASK(PCVAL_TAGBITS)
  244. #define PCVAL_TAG(v) ((v) & PCVAL_TAGMASK)
  245. #define PCVAL_CLRTAG(v) ((v) & ~(jsuword)PCVAL_TAGMASK)
  246. #define PCVAL_SETTAG(v,t) ((jsuword)(v) | (t))
  247. #define PCVAL_NULL 0
  248. #define PCVAL_IS_NULL(v) ((v) == PCVAL_NULL)
  249. #define PCVAL_IS_OBJECT(v) (PCVAL_TAG(v) == PCVAL_OBJECT)
  250. #define PCVAL_TO_OBJECT(v) ((JSObject *) (v))
  251. #define OBJECT_TO_PCVAL(obj) ((jsuword) (obj))
  252. #define PCVAL_OBJECT_TO_JSVAL(v) OBJECT_TO_JSVAL(PCVAL_TO_OBJECT(v))
  253. #define JSVAL_OBJECT_TO_PCVAL(v) OBJECT_TO_PCVAL(JSVAL_TO_OBJECT(v))
  254. #define PCVAL_IS_SLOT(v) ((v) & PCVAL_SLOT)
  255. #define PCVAL_TO_SLOT(v) ((jsuint)(v) >> 1)
  256. #define SLOT_TO_PCVAL(i) (((jsuword)(i) << 1) | PCVAL_SLOT)
  257. #define PCVAL_IS_SPROP(v) (PCVAL_TAG(v) == PCVAL_SPROP)
  258. #define PCVAL_TO_SPROP(v) ((JSScopeProperty *) PCVAL_CLRTAG(v))
  259. #define SPROP_TO_PCVAL(sprop) PCVAL_SETTAG(sprop, PCVAL_SPROP)
  260. /*
  261. * Fill property cache entry for key cx->fp->pc, optimized value word computed
  262. * from obj and sprop, and entry capability forged from 24-bit OBJ_SHAPE(obj),
  263. * 4-bit scopeIndex, and 4-bit protoIndex.
  264. */
  265. extern void
  266. js_FillPropertyCache(JSContext *cx, JSObject *obj, jsuword kshape,
  267. uintN scopeIndex, uintN protoIndex,
  268. JSObject *pobj, JSScopeProperty *sprop,
  269. JSPropCacheEntry **entryp);
  270. /*
  271. * Property cache lookup macros. PROPERTY_CACHE_TEST is designed to inline the
  272. * fast path in js_Interpret, so it makes "just-so" restrictions on parameters,
  273. * e.g. pobj and obj should not be the same variable, since for JOF_PROP-mode
  274. * opcodes, obj must not be changed because of a cache miss.
  275. *
  276. * On return from PROPERTY_CACHE_TEST, if atom is null then obj points to the
  277. * scope chain element in which the property was found, pobj is locked, and
  278. * entry is valid. If atom is non-null then no object is locked but entry is
  279. * still set correctly for use, e.g., by js_FillPropertyCache and atom should
  280. * be used as the id to find.
  281. *
  282. * We must lock pobj on a hit in order to close races with threads that might
  283. * be deleting a property from its scope, or otherwise invalidating property
  284. * caches (on all threads) by re-generating scope->shape.
  285. */
  286. #define PROPERTY_CACHE_TEST(cx, pc, obj, pobj, entry, atom) \
  287. do { \
  288. JSPropertyCache *cache_ = &JS_PROPERTY_CACHE(cx); \
  289. uint32 kshape_ = (JS_ASSERT(OBJ_IS_NATIVE(obj)), OBJ_SHAPE(obj)); \
  290. entry = &cache_->table[PROPERTY_CACHE_HASH_PC(pc, kshape_)]; \
  291. PCMETER(cache_->tests++); \
  292. JS_ASSERT(&obj != &pobj); \
  293. if (entry->kpc == pc && entry->kshape == kshape_) { \
  294. JSObject *tmp_; \
  295. pobj = obj; \
  296. JS_LOCK_OBJ(cx, pobj); \
  297. JS_ASSERT(PCVCAP_TAG(entry->vcap) <= 1); \
  298. if (PCVCAP_TAG(entry->vcap) == 1 && \
  299. (tmp_ = LOCKED_OBJ_GET_PROTO(pobj)) != NULL && \
  300. OBJ_IS_NATIVE(tmp_)) { \
  301. JS_UNLOCK_OBJ(cx, pobj); \
  302. pobj = tmp_; \
  303. JS_LOCK_OBJ(cx, pobj); \
  304. } \
  305. if (PCVCAP_SHAPE(entry->vcap) == OBJ_SHAPE(pobj)) { \
  306. PCMETER(cache_->pchits++); \
  307. PCMETER(!PCVCAP_TAG(entry->vcap) || cache_->protopchits++); \
  308. pobj = OBJ_SCOPE(pobj)->object; \
  309. atom = NULL; \
  310. break; \
  311. } \
  312. JS_UNLOCK_OBJ(cx, pobj); \
  313. } \
  314. atom = js_FullTestPropertyCache(cx, pc, &obj, &pobj, &entry); \
  315. if (atom) \
  316. PCMETER(cache_->misses++); \
  317. } while (0)
  318. extern JSAtom *
  319. js_FullTestPropertyCache(JSContext *cx, jsbytecode *pc,
  320. JSObject **objp, JSObject **pobjp,
  321. JSPropCacheEntry **entryp);
  322. extern void
  323. js_FlushPropertyCache(JSContext *cx);
  324. extern void
  325. js_FlushPropertyCacheForScript(JSContext *cx, JSScript *script);
  326. extern void
  327. js_DisablePropertyCache(JSContext *cx);
  328. extern void
  329. js_EnablePropertyCache(JSContext *cx);
  330. /*
  331. * Interpreter stack arena-pool alloc and free functions.
  332. */
  333. extern JS_FRIEND_API(jsval *)
  334. js_AllocStack(JSContext *cx, uintN nslots, void **markp);
  335. extern JS_FRIEND_API(void)
  336. js_FreeStack(JSContext *cx, void *mark);
  337. /*
  338. * Refresh and return fp->scopeChain. It may be stale if block scopes are
  339. * active but not yet reflected by objects in the scope chain. If a block
  340. * scope contains a with, eval, XML filtering predicate, or similar such
  341. * dynamically scoped construct, then compile-time block scope at fp->blocks
  342. * must reflect at runtime.
  343. */
  344. extern JSObject *
  345. js_GetScopeChain(JSContext *cx, JSStackFrame *fp);
  346. /*
  347. * Given a context and a vector of [callee, this, args...] for a function that
  348. * was specified with a JSFUN_THISP_PRIMITIVE flag, get the primitive value of
  349. * |this| into *thisvp. In doing so, if |this| is an object, insist it is an
  350. * instance of clasp and extract its private slot value to return via *thisvp.
  351. *
  352. * NB: this function loads and uses *vp before storing *thisvp, so the two may
  353. * alias the same jsval.
  354. */
  355. extern JSBool
  356. js_GetPrimitiveThis(JSContext *cx, jsval *vp, JSClass *clasp, jsval *thisvp);
  357. /*
  358. * For a call with arguments argv including argv[-1] (nominal |this|) and
  359. * argv[-2] (callee) replace null |this| with callee's parent, replace
  360. * primitive values with the equivalent wrapper objects and censor activation
  361. * objects as, per ECMA-262, they may not be referred to by |this|. argv[-1]
  362. * must not be a JSVAL_VOID.
  363. */
  364. extern JSObject *
  365. js_ComputeThis(JSContext *cx, JSBool lazy, jsval *argv);
  366. extern const uint16 js_PrimitiveTestFlags[];
  367. #define PRIMITIVE_THIS_TEST(fun,thisv) \
  368. (JS_ASSERT(!JSVAL_IS_VOID(thisv)), \
  369. JSFUN_THISP_TEST(JSFUN_THISP_FLAGS((fun)->flags), \
  370. js_PrimitiveTestFlags[JSVAL_TAG(thisv) - 1]))
  371. /*
  372. * NB: js_Invoke requires that cx is currently running JS (i.e., that cx->fp
  373. * is non-null), and that vp points to the callee, |this| parameter, and
  374. * actual arguments of the call. [vp .. vp + 2 + argc) must belong to the last
  375. * JS stack segment that js_AllocStack allocated. The function may use the
  376. * space available after vp + 2 + argc in the stack segment for temporaries,
  377. * so the caller should not use that space for values that must be preserved
  378. * across the call.
  379. */
  380. extern JS_FRIEND_API(JSBool)
  381. js_Invoke(JSContext *cx, uintN argc, jsval *vp, uintN flags);
  382. /*
  383. * Consolidated js_Invoke flags simply rename certain JSFRAME_* flags, so that
  384. * we can share bits stored in JSStackFrame.flags and passed to:
  385. *
  386. * js_Invoke
  387. * js_InternalInvoke
  388. * js_ValueToFunction
  389. * js_ValueToFunctionObject
  390. * js_ValueToCallableObject
  391. * js_ReportIsNotFunction
  392. *
  393. * See jsfun.h for the latter four and flag renaming macros.
  394. */
  395. #define JSINVOKE_CONSTRUCT JSFRAME_CONSTRUCTING
  396. #define JSINVOKE_ITERATOR JSFRAME_ITERATOR
  397. /*
  398. * Mask to isolate construct and iterator flags for use with jsfun.h functions.
  399. */
  400. #define JSINVOKE_FUNFLAGS (JSINVOKE_CONSTRUCT | JSINVOKE_ITERATOR)
  401. /*
  402. * "Internal" calls may come from C or C++ code using a JSContext on which no
  403. * JS is running (!cx->fp), so they may need to push a dummy JSStackFrame.
  404. */
  405. #define js_InternalCall(cx,obj,fval,argc,argv,rval) \
  406. js_InternalInvoke(cx, obj, fval, 0, argc, argv, rval)
  407. #define js_InternalConstruct(cx,obj,fval,argc,argv,rval) \
  408. js_InternalInvoke(cx, obj, fval, JSINVOKE_CONSTRUCT, argc, argv, rval)
  409. extern JSBool
  410. js_InternalInvoke(JSContext *cx, JSObject *obj, jsval fval, uintN flags,
  411. uintN argc, jsval *argv, jsval *rval);
  412. extern JSBool
  413. js_InternalGetOrSet(JSContext *cx, JSObject *obj, jsid id, jsval fval,
  414. JSAccessMode mode, uintN argc, jsval *argv, jsval *rval);
  415. extern JSBool
  416. js_Execute(JSContext *cx, JSObject *chain, JSScript *script,
  417. JSStackFrame *down, uintN flags, jsval *result);
  418. extern JSBool
  419. js_InvokeConstructor(JSContext *cx, uintN argc, JSBool clampReturn, jsval *vp);
  420. extern JSBool
  421. js_Interpret(JSContext *cx);
  422. #define JSPROP_INITIALIZER 0x100 /* NB: Not a valid property attribute. */
  423. extern JSBool
  424. js_CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs,
  425. JSObject **objp, JSProperty **propp);
  426. extern JSBool
  427. js_StrictlyEqual(JSContext *cx, jsval lval, jsval rval);
  428. /*
  429. * JS_LONE_INTERPRET indicates that the compiler should see just the code for
  430. * the js_Interpret function when compiling jsinterp.cpp. The rest of the code
  431. * from the file should be visible only when compiling jsinvoke.cpp. It allows
  432. * platform builds to optimize selectively js_Interpret when the granularity
  433. * of the optimizations with the given compiler is a compilation unit.
  434. *
  435. * JS_STATIC_INTERPRET is the modifier for functions defined in jsinterp.cpp
  436. * that only js_Interpret calls. When JS_LONE_INTERPRET is true all such
  437. * functions are declared below.
  438. */
  439. #ifndef JS_LONE_INTERPRET
  440. # ifdef _MSC_VER
  441. # define JS_LONE_INTERPRET 0
  442. # else
  443. # define JS_LONE_INTERPRET 1
  444. # endif
  445. #endif
  446. #if !JS_LONE_INTERPRET
  447. # define JS_STATIC_INTERPRET static
  448. #else
  449. # define JS_STATIC_INTERPRET
  450. extern jsval *
  451. js_AllocRawStack(JSContext *cx, uintN nslots, void **markp);
  452. extern void
  453. js_FreeRawStack(JSContext *cx, void *mark);
  454. /*
  455. * ECMA requires "the global object", but in embeddings such as the browser,
  456. * which have multiple top-level objects (windows, frames, etc. in the DOM),
  457. * we prefer fun's parent. An example that causes this code to run:
  458. *
  459. * // in window w1
  460. * function f() { return this }
  461. * function g() { return f }
  462. *
  463. * // in window w2
  464. * var h = w1.g()
  465. * alert(h() == w1)
  466. *
  467. * The alert should display "true".
  468. */
  469. extern JSObject *
  470. js_ComputeGlobalThis(JSContext *cx, JSBool lazy, jsval *argv);
  471. extern JSBool
  472. js_EnterWith(JSContext *cx, jsint stackIndex);
  473. extern void
  474. js_LeaveWith(JSContext *cx);
  475. extern JSClass *
  476. js_IsActiveWithOrBlock(JSContext *cx, JSObject *obj, int stackDepth);
  477. extern jsint
  478. js_CountWithBlocks(JSContext *cx, JSStackFrame *fp);
  479. /*
  480. * Unwind block and scope chains to match the given depth. The function sets
  481. * fp->sp on return to stackDepth.
  482. */
  483. extern JSBool
  484. js_UnwindScope(JSContext *cx, JSStackFrame *fp, jsint stackDepth,
  485. JSBool normalUnwind);
  486. extern JSBool
  487. js_InternNonIntElementId(JSContext *cx, JSObject *obj, jsval idval, jsid *idp);
  488. extern JSBool
  489. js_OnUnknownMethod(JSContext *cx, jsval *vp);
  490. /*
  491. * Find the results of incrementing or decrementing *vp. For pre-increments,
  492. * both *vp and *vp2 will contain the result on return. For post-increments,
  493. * vp will contain the original value converted to a number and vp2 will get
  494. * the result. Both vp and vp2 must be roots.
  495. */
  496. extern JSBool
  497. js_DoIncDec(JSContext *cx, const JSCodeSpec *cs, jsval *vp, jsval *vp2);
  498. /*
  499. * Opcode tracing helper. When len is not 0, cx->fp->regs->pc[-len] gives the
  500. * previous opcode.
  501. */
  502. extern void
  503. js_TraceOpcode(JSContext *cx, jsint len);
  504. /*
  505. * JS_OPMETER helper functions.
  506. */
  507. extern void
  508. js_MeterOpcodePair(JSOp op1, JSOp op2);
  509. extern void
  510. js_MeterSlotOpcode(JSOp op, uint32 slot);
  511. #endif /* JS_LONE_INTERPRET */
  512. JS_END_EXTERN_C
  513. #endif /* jsinterp_h___ */