Bug 533705 - Lock proto-scope around canProvideEmptyScope/getEmptyScope; check for...
[mozilla-central.git] / js / src / jsinterp.h
blob07b707778d10b8c7a5caf7766cef8b6ba3612a13
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=4 sw=4 et tw=78:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
17 * The Original Code is Mozilla Communicator client code, released
18 * March 31, 1998.
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.
25 * Contributor(s):
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.
39 * ***** END LICENSE BLOCK ***** */
41 #ifndef jsinterp_h___
42 #define jsinterp_h___
44 * JS interpreter interface.
46 #include "jsprvtd.h"
47 #include "jspubtd.h"
48 #include "jsfun.h"
49 #include "jsopcode.h"
50 #include "jsscript.h"
52 JS_BEGIN_EXTERN_C
54 typedef struct JSFrameRegs {
55 jsbytecode *pc; /* program counter */
56 jsval *sp; /* stack pointer */
57 } JSFrameRegs;
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.
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.
69 struct 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 jsval argsobj; /* lazily created arguments object, must be
75 JSVAL_OBJECT */
76 JSObject *varobj; /* variables object, where vars go */
77 JSScript *script; /* script being interpreted */
78 JSFunction *fun; /* function being called or null */
79 jsval thisv; /* "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 */
87 * We can't determine in advance which local variables can live on
88 * the stack and be freed when their dynamic scope ends, and which
89 * will be closed over and need to live in the heap. So we place
90 * variables on the stack initially, note when they are closed
91 * over, and copy those that are out to the heap when we leave
92 * their dynamic scope.
94 * The bytecode compiler produces a tree of block objects
95 * accompanying each JSScript representing those lexical blocks in
96 * the script that have let-bound variables associated with them.
97 * These block objects are never modified, and never become part
98 * of any function's scope chain. Their parent slots point to the
99 * innermost block that encloses them, or are NULL in the
100 * outermost blocks within a function or in eval or global code.
102 * When we are in the static scope of such a block, blockChain
103 * points to its compiler-allocated block object; otherwise, it is
104 * NULL.
106 * scopeChain is the current scope chain, including 'call' and
107 * 'block' objects for those function calls and lexical blocks
108 * whose static scope we are currently executing in, and 'with'
109 * objects for with statements; the chain is typically terminated
110 * by a global object. However, as an optimization, the young end
111 * of the chain omits block objects we have not yet cloned. To
112 * create a closure, we clone the missing blocks from blockChain
113 * (which is always current), place them at the head of
114 * scopeChain, and use that for the closure's scope chain. If we
115 * never close over a lexical block, we never place a mutable
116 * clone of it on scopeChain.
118 * This lazy cloning is implemented in js_GetScopeChain, which is
119 * also used in some other cases --- entering 'with' blocks, for
120 * example.
122 JSObject *scopeChain;
123 JSObject *blockChain;
125 uint32 flags; /* frame flags -- see below */
126 JSStackFrame *dormantNext; /* next dormant frame chain */
127 JSStackFrame *displaySave; /* previous value of display entry for
128 script->staticLevel */
130 inline void assertValidStackDepth(uintN depth);
132 void putActivationObjects(JSContext *cx) {
134 * The order of calls here is important as js_PutCallObject needs to
135 * access argsobj.
137 if (callobj) {
138 js_PutCallObject(cx, this);
139 JS_ASSERT(!argsobj);
140 } else if (argsobj) {
141 js_PutArgsObject(cx, this);
145 jsval calleeValue() {
146 JS_ASSERT(argv);
147 return argv[-2];
150 JSObject *calleeObject() {
151 JS_ASSERT(argv);
152 return JSVAL_TO_OBJECT(argv[-2]);
155 JSObject *callee() {
156 return argv ? JSVAL_TO_OBJECT(argv[-2]) : NULL;
160 #ifdef __cplusplus
161 static JS_INLINE uintN
162 FramePCOffset(JSStackFrame* fp)
164 return uintN((fp->imacpc ? fp->imacpc : fp->regs->pc) - fp->script->code);
166 #endif
168 static JS_INLINE jsval *
169 StackBase(JSStackFrame *fp)
171 return fp->slots + fp->script->nfixed;
174 void
175 JSStackFrame::assertValidStackDepth(uintN depth)
177 JS_ASSERT(0 <= regs->sp - StackBase(this));
178 JS_ASSERT(depth <= uintptr_t(regs->sp - StackBase(this)));
181 static JS_INLINE uintN
182 GlobalVarCount(JSStackFrame *fp)
184 uintN n;
186 JS_ASSERT(!fp->fun);
187 n = fp->script->nfixed;
188 if (fp->script->regexpsOffset != 0)
189 n -= fp->script->regexps()->length;
190 return n;
193 typedef struct JSInlineFrame {
194 JSStackFrame frame; /* base struct */
195 JSFrameRegs callerRegs; /* parent's frame registers */
196 void *mark; /* mark before inline frame */
197 void *hookData; /* debugger call hook data */
198 JSVersion callerVersion; /* dynamic version of calling script */
199 } JSInlineFrame;
201 /* JS stack frame flags. */
202 #define JSFRAME_CONSTRUCTING 0x01 /* frame is for a constructor invocation */
203 #define JSFRAME_COMPUTED_THIS 0x02 /* frame.thisv was computed already and
204 JSVAL_IS_OBJECT(thisv) */
205 #define JSFRAME_ASSIGNING 0x04 /* a complex (not simplex JOF_ASSIGNING) op
206 is currently assigning to a property */
207 #define JSFRAME_DEBUGGER 0x08 /* frame for JS_EvaluateInStackFrame */
208 #define JSFRAME_EVAL 0x10 /* frame for obj_eval */
209 #define JSFRAME_ROOTED_ARGV 0x20 /* frame.argv is rooted by the caller */
210 #define JSFRAME_YIELDING 0x40 /* js_Interpret dispatched JSOP_YIELD */
211 #define JSFRAME_ITERATOR 0x80 /* trying to get an iterator for for-in */
212 #define JSFRAME_GENERATOR 0x200 /* frame belongs to generator-iterator */
213 #define JSFRAME_OVERRIDE_ARGS 0x400 /* overridden arguments local variable */
215 #define JSFRAME_SPECIAL (JSFRAME_DEBUGGER | JSFRAME_EVAL)
218 * Property cache with structurally typed capabilities for invalidation, for
219 * polymorphic callsite method/get/set speedups. For details, see
220 * <https://developer.mozilla.org/en/SpiderMonkey/Internals/Property_cache>.
222 #define PROPERTY_CACHE_LOG2 12
223 #define PROPERTY_CACHE_SIZE JS_BIT(PROPERTY_CACHE_LOG2)
224 #define PROPERTY_CACHE_MASK JS_BITMASK(PROPERTY_CACHE_LOG2)
227 * Add kshape rather than xor it to avoid collisions between nearby bytecode
228 * that are evolving an object by setting successive properties, incrementing
229 * the object's scope->shape on each set.
231 #define PROPERTY_CACHE_HASH(pc,kshape) \
232 (((((jsuword)(pc) >> PROPERTY_CACHE_LOG2) ^ (jsuword)(pc)) + (kshape)) & \
233 PROPERTY_CACHE_MASK)
235 #define PROPERTY_CACHE_HASH_PC(pc,kshape) \
236 PROPERTY_CACHE_HASH(pc, kshape)
238 #define PROPERTY_CACHE_HASH_ATOM(atom,obj) \
239 PROPERTY_CACHE_HASH((jsuword)(atom) >> 2, OBJ_SHAPE(obj))
242 * Property cache value capability macros.
244 #define PCVCAP_PROTOBITS 4
245 #define PCVCAP_PROTOSIZE JS_BIT(PCVCAP_PROTOBITS)
246 #define PCVCAP_PROTOMASK JS_BITMASK(PCVCAP_PROTOBITS)
248 #define PCVCAP_SCOPEBITS 4
249 #define PCVCAP_SCOPESIZE JS_BIT(PCVCAP_SCOPEBITS)
250 #define PCVCAP_SCOPEMASK JS_BITMASK(PCVCAP_SCOPEBITS)
252 #define PCVCAP_TAGBITS (PCVCAP_PROTOBITS + PCVCAP_SCOPEBITS)
253 #define PCVCAP_TAGMASK JS_BITMASK(PCVCAP_TAGBITS)
254 #define PCVCAP_TAG(t) ((t) & PCVCAP_TAGMASK)
256 #define PCVCAP_MAKE(t,s,p) ((uint32(t) << PCVCAP_TAGBITS) | \
257 ((s) << PCVCAP_PROTOBITS) | \
258 (p))
259 #define PCVCAP_SHAPE(t) ((t) >> PCVCAP_TAGBITS)
261 #define SHAPE_OVERFLOW_BIT JS_BIT(32 - PCVCAP_TAGBITS)
263 struct JSPropCacheEntry {
264 jsbytecode *kpc; /* pc if vcap tag is <= 1, else atom */
265 jsuword kshape; /* key shape if pc, else obj for atom */
266 jsuword vcap; /* value capability, see above */
267 jsuword vword; /* value word, see PCVAL_* below */
269 bool adding() const {
270 return PCVCAP_TAG(vcap) == 0 && kshape != PCVCAP_SHAPE(vcap);
273 bool directHit() const {
274 return PCVCAP_TAG(vcap) == 0 && kshape == PCVCAP_SHAPE(vcap);
279 * Special value for functions returning JSPropCacheEntry * to distinguish
280 * between failure and no no-cache-fill cases.
282 #define JS_NO_PROP_CACHE_FILL ((JSPropCacheEntry *) NULL + 1)
284 #if defined DEBUG_brendan || defined DEBUG_brendaneich
285 #define JS_PROPERTY_CACHE_METERING 1
286 #endif
288 typedef struct JSPropertyCache {
289 JSPropCacheEntry table[PROPERTY_CACHE_SIZE];
290 JSBool empty;
291 #ifdef JS_PROPERTY_CACHE_METERING
292 JSPropCacheEntry *pctestentry; /* entry of the last PC-based test */
293 uint32 fills; /* number of cache entry fills */
294 uint32 nofills; /* couldn't fill (e.g. default get) */
295 uint32 rofills; /* set on read-only prop can't fill */
296 uint32 disfills; /* fill attempts on disabled cache */
297 uint32 oddfills; /* fill attempt after setter deleted */
298 uint32 modfills; /* fill that rehashed to a new entry */
299 uint32 brandfills; /* scope brandings to type structural
300 method fills */
301 uint32 noprotos; /* resolve-returned non-proto pobj */
302 uint32 longchains; /* overlong scope and/or proto chain */
303 uint32 recycles; /* cache entries recycled by fills */
304 uint32 pcrecycles; /* pc-keyed entries recycled by atom-
305 keyed fills */
306 uint32 tests; /* cache probes */
307 uint32 pchits; /* fast-path polymorphic op hits */
308 uint32 protopchits; /* pchits hitting immediate prototype */
309 uint32 initests; /* cache probes from JSOP_INITPROP */
310 uint32 inipchits; /* init'ing next property pchit case */
311 uint32 inipcmisses; /* init'ing next property pc misses */
312 uint32 settests; /* cache probes from JOF_SET opcodes */
313 uint32 addpchits; /* adding next property pchit case */
314 uint32 setpchits; /* setting existing property pchit */
315 uint32 setpcmisses; /* setting/adding property pc misses */
316 uint32 setmisses; /* JSOP_SET{NAME,PROP} total misses */
317 uint32 idmisses; /* slow-path key id == atom misses */
318 uint32 komisses; /* slow-path key object misses */
319 uint32 vcmisses; /* value capability misses */
320 uint32 misses; /* cache misses */
321 uint32 flushes; /* cache flushes */
322 uint32 pcpurges; /* shadowing purges on proto chain */
323 # define PCMETER(x) x
324 #else
325 # define PCMETER(x) ((void)0)
326 #endif
327 } JSPropertyCache;
330 * Property cache value tagging/untagging macros.
332 #define PCVAL_OBJECT 0
333 #define PCVAL_SLOT 1
334 #define PCVAL_SPROP 2
336 #define PCVAL_TAGBITS 2
337 #define PCVAL_TAGMASK JS_BITMASK(PCVAL_TAGBITS)
338 #define PCVAL_TAG(v) ((v) & PCVAL_TAGMASK)
339 #define PCVAL_CLRTAG(v) ((v) & ~(jsuword)PCVAL_TAGMASK)
340 #define PCVAL_SETTAG(v,t) ((jsuword)(v) | (t))
342 #define PCVAL_NULL 0
343 #define PCVAL_IS_NULL(v) ((v) == PCVAL_NULL)
345 #define PCVAL_IS_OBJECT(v) (PCVAL_TAG(v) == PCVAL_OBJECT)
346 #define PCVAL_TO_OBJECT(v) ((JSObject *) (v))
347 #define OBJECT_TO_PCVAL(obj) ((jsuword) (obj))
349 #define PCVAL_OBJECT_TO_JSVAL(v) OBJECT_TO_JSVAL(PCVAL_TO_OBJECT(v))
350 #define JSVAL_OBJECT_TO_PCVAL(v) OBJECT_TO_PCVAL(JSVAL_TO_OBJECT(v))
352 #define PCVAL_IS_SLOT(v) ((v) & PCVAL_SLOT)
353 #define PCVAL_TO_SLOT(v) ((jsuint)(v) >> 1)
354 #define SLOT_TO_PCVAL(i) (((jsuword)(i) << 1) | PCVAL_SLOT)
356 #define PCVAL_IS_SPROP(v) (PCVAL_TAG(v) == PCVAL_SPROP)
357 #define PCVAL_TO_SPROP(v) ((JSScopeProperty *) PCVAL_CLRTAG(v))
358 #define SPROP_TO_PCVAL(sprop) PCVAL_SETTAG(sprop, PCVAL_SPROP)
361 * Fill property cache entry for key cx->fp->pc, optimized value word computed
362 * from obj and sprop, and entry capability forged from 24-bit OBJ_SHAPE(obj),
363 * 4-bit scopeIndex, and 4-bit protoIndex.
365 * Return the filled cache entry or JS_NO_PROP_CACHE_FILL if caching was not
366 * possible.
368 extern JS_REQUIRES_STACK JSPropCacheEntry *
369 js_FillPropertyCache(JSContext *cx, JSObject *obj,
370 uintN scopeIndex, uintN protoIndex, JSObject *pobj,
371 JSScopeProperty *sprop, JSBool adding);
374 * Property cache lookup macros. PROPERTY_CACHE_TEST is designed to inline the
375 * fast path in js_Interpret, so it makes "just-so" restrictions on parameters,
376 * e.g. pobj and obj should not be the same variable, since for JOF_PROP-mode
377 * opcodes, obj must not be changed because of a cache miss.
379 * On return from PROPERTY_CACHE_TEST, if atom is null then obj points to the
380 * scope chain element in which the property was found, pobj is locked, and
381 * entry is valid. If atom is non-null then no object is locked but entry is
382 * still set correctly for use, e.g., by js_FillPropertyCache and atom should
383 * be used as the id to find.
385 * We must lock pobj on a hit in order to close races with threads that might
386 * be deleting a property from its scope, or otherwise invalidating property
387 * caches (on all threads) by re-generating scope->shape.
389 #define PROPERTY_CACHE_TEST(cx, pc, obj, pobj, entry, atom) \
390 do { \
391 JSPropertyCache *cache_ = &JS_PROPERTY_CACHE(cx); \
392 uint32 kshape_ = (JS_ASSERT(OBJ_IS_NATIVE(obj)), OBJ_SHAPE(obj)); \
393 entry = &cache_->table[PROPERTY_CACHE_HASH_PC(pc, kshape_)]; \
394 PCMETER(cache_->pctestentry = entry); \
395 PCMETER(cache_->tests++); \
396 JS_ASSERT(&obj != &pobj); \
397 if (entry->kpc == pc && entry->kshape == kshape_) { \
398 JSObject *tmp_; \
399 pobj = obj; \
400 JS_ASSERT(PCVCAP_TAG(entry->vcap) <= 1); \
401 if (PCVCAP_TAG(entry->vcap) == 1 && \
402 (tmp_ = OBJ_GET_PROTO(cx, pobj)) != NULL) { \
403 pobj = tmp_; \
406 if (JS_LOCK_OBJ_IF_SHAPE(cx, pobj, PCVCAP_SHAPE(entry->vcap))) { \
407 PCMETER(cache_->pchits++); \
408 PCMETER(!PCVCAP_TAG(entry->vcap) || cache_->protopchits++); \
409 atom = NULL; \
410 break; \
413 atom = js_FullTestPropertyCache(cx, pc, &obj, &pobj, &entry); \
414 if (atom) \
415 PCMETER(cache_->misses++); \
416 } while (0)
418 extern JS_REQUIRES_STACK JSAtom *
419 js_FullTestPropertyCache(JSContext *cx, jsbytecode *pc,
420 JSObject **objp, JSObject **pobjp,
421 JSPropCacheEntry **entryp);
423 /* The property cache does not need a destructor. */
424 #define js_FinishPropertyCache(cache) ((void) 0)
426 extern void
427 js_PurgePropertyCache(JSContext *cx, JSPropertyCache *cache);
429 extern void
430 js_PurgePropertyCacheForScript(JSContext *cx, JSScript *script);
433 * Interpreter stack arena-pool alloc and free functions.
435 extern JS_REQUIRES_STACK JS_FRIEND_API(jsval *)
436 js_AllocStack(JSContext *cx, uintN nslots, void **markp);
438 extern JS_REQUIRES_STACK JS_FRIEND_API(void)
439 js_FreeStack(JSContext *cx, void *mark);
442 * Refresh and return fp->scopeChain. It may be stale if block scopes are
443 * active but not yet reflected by objects in the scope chain. If a block
444 * scope contains a with, eval, XML filtering predicate, or similar such
445 * dynamically scoped construct, then compile-time block scope at fp->blocks
446 * must reflect at runtime.
448 extern JSObject *
449 js_GetScopeChain(JSContext *cx, JSStackFrame *fp);
452 * Given a context and a vector of [callee, this, args...] for a function that
453 * was specified with a JSFUN_THISP_PRIMITIVE flag, get the primitive value of
454 * |this| into *thisvp. In doing so, if |this| is an object, insist it is an
455 * instance of clasp and extract its private slot value to return via *thisvp.
457 * NB: this function loads and uses *vp before storing *thisvp, so the two may
458 * alias the same jsval.
460 extern JSBool
461 js_GetPrimitiveThis(JSContext *cx, jsval *vp, JSClass *clasp, jsval *thisvp);
464 * For a call with arguments argv including argv[-1] (nominal |this|) and
465 * argv[-2] (callee) replace null |this| with callee's parent, replace
466 * primitive values with the equivalent wrapper objects and censor activation
467 * objects as, per ECMA-262, they may not be referred to by |this|. argv[-1]
468 * must not be a JSVAL_VOID.
470 extern JSObject *
471 js_ComputeThis(JSContext *cx, JSBool lazy, jsval *argv);
473 extern const uint16 js_PrimitiveTestFlags[];
475 #define PRIMITIVE_THIS_TEST(fun,thisv) \
476 (JS_ASSERT(!JSVAL_IS_VOID(thisv)), \
477 JSFUN_THISP_TEST(JSFUN_THISP_FLAGS((fun)->flags), \
478 js_PrimitiveTestFlags[JSVAL_TAG(thisv) - 1]))
480 #ifdef __cplusplus /* Aargh, libgjs, bug 492720. */
481 static JS_INLINE JSObject *
482 js_ComputeThisForFrame(JSContext *cx, JSStackFrame *fp)
484 if (fp->flags & JSFRAME_COMPUTED_THIS)
485 return JSVAL_TO_OBJECT(fp->thisv); /* JSVAL_COMPUTED_THIS invariant */
486 JSObject* obj = js_ComputeThis(cx, JS_TRUE, fp->argv);
487 if (!obj)
488 return NULL;
489 fp->thisv = OBJECT_TO_JSVAL(obj);
490 fp->flags |= JSFRAME_COMPUTED_THIS;
491 return obj;
493 #endif
496 * NB: js_Invoke requires that cx is currently running JS (i.e., that cx->fp
497 * is non-null), and that vp points to the callee, |this| parameter, and
498 * actual arguments of the call. [vp .. vp + 2 + argc) must belong to the last
499 * JS stack segment that js_AllocStack allocated. The function may use the
500 * space available after vp + 2 + argc in the stack segment for temporaries,
501 * so the caller should not use that space for values that must be preserved
502 * across the call.
504 extern JS_REQUIRES_STACK JS_FRIEND_API(JSBool)
505 js_Invoke(JSContext *cx, uintN argc, jsval *vp, uintN flags);
508 * Consolidated js_Invoke flags simply rename certain JSFRAME_* flags, so that
509 * we can share bits stored in JSStackFrame.flags and passed to:
511 * js_Invoke
512 * js_InternalInvoke
513 * js_ValueToFunction
514 * js_ValueToFunctionObject
515 * js_ValueToCallableObject
516 * js_ReportIsNotFunction
518 * See jsfun.h for the latter four and flag renaming macros.
520 #define JSINVOKE_CONSTRUCT JSFRAME_CONSTRUCTING
521 #define JSINVOKE_ITERATOR JSFRAME_ITERATOR
524 * Mask to isolate construct and iterator flags for use with jsfun.h functions.
526 #define JSINVOKE_FUNFLAGS (JSINVOKE_CONSTRUCT | JSINVOKE_ITERATOR)
529 * "Internal" calls may come from C or C++ code using a JSContext on which no
530 * JS is running (!cx->fp), so they may need to push a dummy JSStackFrame.
532 #define js_InternalCall(cx,obj,fval,argc,argv,rval) \
533 js_InternalInvoke(cx, obj, fval, 0, argc, argv, rval)
535 #define js_InternalConstruct(cx,obj,fval,argc,argv,rval) \
536 js_InternalInvoke(cx, obj, fval, JSINVOKE_CONSTRUCT, argc, argv, rval)
538 extern JSBool
539 js_InternalInvoke(JSContext *cx, JSObject *obj, jsval fval, uintN flags,
540 uintN argc, jsval *argv, jsval *rval);
542 extern JSBool
543 js_InternalGetOrSet(JSContext *cx, JSObject *obj, jsid id, jsval fval,
544 JSAccessMode mode, uintN argc, jsval *argv, jsval *rval);
546 extern JS_FORCES_STACK JSBool
547 js_Execute(JSContext *cx, JSObject *chain, JSScript *script,
548 JSStackFrame *down, uintN flags, jsval *result);
550 extern JS_REQUIRES_STACK JSBool
551 js_InvokeConstructor(JSContext *cx, uintN argc, JSBool clampReturn, jsval *vp);
553 extern JS_REQUIRES_STACK JSBool
554 js_Interpret(JSContext *cx);
556 #define JSPROP_INITIALIZER 0x100 /* NB: Not a valid property attribute. */
558 extern JSBool
559 js_CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs,
560 JSObject **objp, JSProperty **propp);
562 extern JSBool
563 js_StrictlyEqual(JSContext *cx, jsval lval, jsval rval);
565 /* === except that NaN is the same as NaN and -0 is not the same as +0. */
566 extern JSBool
567 js_SameValue(jsval v1, jsval v2, JSContext *cx);
569 extern JSBool
570 js_InternNonIntElementId(JSContext *cx, JSObject *obj, jsval idval, jsid *idp);
573 * Given an active context, a static scope level, and an upvar cookie, return
574 * the value of the upvar.
576 extern jsval&
577 js_GetUpvar(JSContext *cx, uintN level, uintN cookie);
580 * JS_LONE_INTERPRET indicates that the compiler should see just the code for
581 * the js_Interpret function when compiling jsinterp.cpp. The rest of the code
582 * from the file should be visible only when compiling jsinvoke.cpp. It allows
583 * platform builds to optimize selectively js_Interpret when the granularity
584 * of the optimizations with the given compiler is a compilation unit.
586 * JS_STATIC_INTERPRET is the modifier for functions defined in jsinterp.cpp
587 * that only js_Interpret calls. When JS_LONE_INTERPRET is true all such
588 * functions are declared below.
590 #ifndef JS_LONE_INTERPRET
591 # ifdef _MSC_VER
592 # define JS_LONE_INTERPRET 0
593 # else
594 # define JS_LONE_INTERPRET 1
595 # endif
596 #endif
598 #define JS_MAX_INLINE_CALL_COUNT 3000
600 #if !JS_LONE_INTERPRET
601 # define JS_STATIC_INTERPRET static
602 #else
603 # define JS_STATIC_INTERPRET
605 extern JS_REQUIRES_STACK jsval *
606 js_AllocRawStack(JSContext *cx, uintN nslots, void **markp);
608 extern JS_REQUIRES_STACK void
609 js_FreeRawStack(JSContext *cx, void *mark);
612 * ECMA requires "the global object", but in embeddings such as the browser,
613 * which have multiple top-level objects (windows, frames, etc. in the DOM),
614 * we prefer fun's parent. An example that causes this code to run:
616 * // in window w1
617 * function f() { return this }
618 * function g() { return f }
620 * // in window w2
621 * var h = w1.g()
622 * alert(h() == w1)
624 * The alert should display "true".
626 extern JSObject *
627 js_ComputeGlobalThis(JSContext *cx, JSBool lazy, jsval *argv);
629 extern JS_REQUIRES_STACK JSBool
630 js_EnterWith(JSContext *cx, jsint stackIndex);
632 extern JS_REQUIRES_STACK void
633 js_LeaveWith(JSContext *cx);
635 extern JS_REQUIRES_STACK JSClass *
636 js_IsActiveWithOrBlock(JSContext *cx, JSObject *obj, int stackDepth);
639 * Unwind block and scope chains to match the given depth. The function sets
640 * fp->sp on return to stackDepth.
642 extern JS_REQUIRES_STACK JSBool
643 js_UnwindScope(JSContext *cx, JSStackFrame *fp, jsint stackDepth,
644 JSBool normalUnwind);
646 extern JSBool
647 js_OnUnknownMethod(JSContext *cx, jsval *vp);
650 * Find the results of incrementing or decrementing *vp. For pre-increments,
651 * both *vp and *vp2 will contain the result on return. For post-increments,
652 * vp will contain the original value converted to a number and vp2 will get
653 * the result. Both vp and vp2 must be roots.
655 extern JSBool
656 js_DoIncDec(JSContext *cx, const JSCodeSpec *cs, jsval *vp, jsval *vp2);
659 * Opcode tracing helper. When len is not 0, cx->fp->regs->pc[-len] gives the
660 * previous opcode.
662 extern JS_REQUIRES_STACK void
663 js_TraceOpcode(JSContext *cx);
666 * JS_OPMETER helper functions.
668 extern void
669 js_MeterOpcodePair(JSOp op1, JSOp op2);
671 extern void
672 js_MeterSlotOpcode(JSOp op, uint32 slot);
674 #endif /* JS_LONE_INTERPRET */
676 JS_END_EXTERN_C
678 #endif /* jsinterp_h___ */