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