Avoid staying in Interpret() after recording (bug 593532, r=dmandelin).
[mozilla-central.git] / js / src / jsinterp.h
blob8a5bdc599f379d885e79ca74621b57ff671257f6
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"
51 #include "jsvalue.h"
53 typedef struct JSFrameRegs {
54 js::Value *sp; /* stack pointer */
55 jsbytecode *pc; /* program counter */
56 JSStackFrame *fp; /* active frame */
57 } JSFrameRegs;
59 /* JS stack frame flags. */
60 enum JSFrameFlags {
61 JSFRAME_CONSTRUCTING = 0x01, /* frame is for a constructor invocation */
62 JSFRAME_OVERRIDE_ARGS = 0x02, /* overridden arguments local variable */
63 JSFRAME_ASSIGNING = 0x04, /* a complex (not simplex JOF_ASSIGNING) op
64 is currently assigning to a property */
65 JSFRAME_DEBUGGER = 0x08, /* frame for JS_EvaluateInStackFrame */
66 JSFRAME_EVAL = 0x10, /* frame for obj_eval */
67 JSFRAME_FLOATING_GENERATOR = 0x20, /* frame copy stored in a generator obj */
68 JSFRAME_YIELDING = 0x40, /* js_Interpret dispatched JSOP_YIELD */
69 JSFRAME_GENERATOR = 0x80, /* frame belongs to generator-iterator */
70 JSFRAME_BAILED_AT_RETURN = 0x100, /* bailed at JSOP_RETURN */
71 JSFRAME_DUMMY = 0x200, /* frame is a dummy frame */
72 JSFRAME_IN_IMACRO = 0x400, /* frame has imacpc value available */
74 JSFRAME_SPECIAL = JSFRAME_DEBUGGER | JSFRAME_EVAL
77 /* Flags to toggle Interpret() execution. */
78 enum JSInterpFlags {
79 JSINTERP_RECORD = 0x01, /* interpreter has been started to record/run traces */
80 JSINTERP_SAFEPOINT = 0x02 /* interpreter should leave on a method JIT safe point */
83 namespace js { namespace mjit {
84 class Compiler;
85 class InlineFrameAssembler;
86 } }
89 * JS stack frame, may be allocated on the C stack by native callers. Always
90 * allocated on cx->stackPool for calls from the interpreter to an interpreted
91 * function.
93 * NB: This struct is manually initialized in jsinterp.c and jsiter.c. If you
94 * add new members, update both files.
96 struct JSStackFrame
98 private:
99 JSObject *callobj; /* lazily created Call object */
100 JSObject *argsobj; /* lazily created arguments object */
101 jsbytecode *imacpc; /* null or interpreter macro call pc */
102 JSScript *script; /* script being interpreted */
105 * The value of |this| in this stack frame, or JSVAL_NULL if |this|
106 * is to be computed lazily on demand.
108 * thisv is eagerly initialized for non-function-call frames and
109 * qualified method calls, but lazily initialized in most unqualified
110 * function calls. See getThisObject().
112 * Usually if argv != NULL then thisv == argv[-1], but natives may
113 * assign to argv[-1]. Also, obj_eval can trigger a special case
114 * where two stack frames have the same argv. If one of the frames fills
115 * in both argv[-1] and thisv, the other frame's thisv is left null.
117 js::Value thisv; /* "this" pointer if in method */
118 JSFunction *fun; /* function being called or null */
120 public:
121 uintN argc; /* actual argument count */
122 js::Value *argv; /* base of argument stack slots */
124 private:
125 js::Value rval; /* function return value */
126 void *annotation; /* used by Java security */
128 public:
129 /* Maintained by StackSpace operations */
130 JSStackFrame *down; /* previous frame, part of
131 stack layout invariant */
132 jsbytecode *savedPC; /* only valid if cx->fp != this */
133 #ifdef DEBUG
134 static jsbytecode *const sInvalidPC;
135 #endif
137 void *ncode; /* jit return pc */
139 private:
140 JSObject *scopeChain;
141 JSObject *blockChain;
143 public:
144 uint32 flags; /* frame flags -- see below */
146 private:
147 /* Members only needed for inline calls. */
148 void *hookData; /* debugger call hook data */
149 JSVersion callerVersion; /* dynamic version of calling script */
151 public:
152 /* Get the frame's current bytecode, assuming |this| is in |cx|. */
153 jsbytecode *pc(JSContext *cx) const;
155 js::Value *argEnd() const {
156 return (js::Value *)this;
159 js::Value *slots() const {
160 return (js::Value *)(this + 1);
163 js::Value *base() const {
164 return slots() + getScript()->nfixed;
167 /* Call object accessors */
169 bool hasCallObj() const {
170 return callobj != NULL;
173 JSObject* getCallObj() const {
174 JS_ASSERT(hasCallObj());
175 return callobj;
178 JSObject* maybeCallObj() const {
179 return callobj;
182 void setCallObj(JSObject *obj) {
183 callobj = obj;
186 static size_t offsetCallObj() {
187 return offsetof(JSStackFrame, callobj);
190 /* Arguments object accessors */
192 bool hasArgsObj() const {
193 return argsobj != NULL;
196 JSObject* getArgsObj() const {
197 JS_ASSERT(hasArgsObj());
198 JS_ASSERT(!isEvalFrame());
199 return argsobj;
202 JSObject* maybeArgsObj() const {
203 return argsobj;
206 void setArgsObj(JSObject *obj) {
207 argsobj = obj;
210 JSObject** addressArgsObj() {
211 return &argsobj;
214 static size_t offsetArgsObj() {
215 return offsetof(JSStackFrame, argsobj);
219 * We can't determine in advance which local variables can live on
220 * the stack and be freed when their dynamic scope ends, and which
221 * will be closed over and need to live in the heap. So we place
222 * variables on the stack initially, note when they are closed
223 * over, and copy those that are out to the heap when we leave
224 * their dynamic scope.
226 * The bytecode compiler produces a tree of block objects
227 * accompanying each JSScript representing those lexical blocks in
228 * the script that have let-bound variables associated with them.
229 * These block objects are never modified, and never become part
230 * of any function's scope chain. Their parent slots point to the
231 * innermost block that encloses them, or are NULL in the
232 * outermost blocks within a function or in eval or global code.
234 * When we are in the static scope of such a block, blockChain
235 * points to its compiler-allocated block object; otherwise, it is
236 * NULL.
238 * scopeChain is the current scope chain, including 'call' and
239 * 'block' objects for those function calls and lexical blocks
240 * whose static scope we are currently executing in, and 'with'
241 * objects for with statements; the chain is typically terminated
242 * by a global object. However, as an optimization, the young end
243 * of the chain omits block objects we have not yet cloned. To
244 * create a closure, we clone the missing blocks from blockChain
245 * (which is always current), place them at the head of
246 * scopeChain, and use that for the closure's scope chain. If we
247 * never close over a lexical block, we never place a mutable
248 * clone of it on scopeChain.
250 * This lazy cloning is implemented in js_GetScopeChain, which is
251 * also used in some other cases --- entering 'with' blocks, for
252 * example.
255 /* Scope chain accessors */
257 bool hasScopeChain() const {
258 return scopeChain != NULL;
261 JSObject* getScopeChain() const {
262 JS_ASSERT(hasScopeChain());
263 return scopeChain;
266 JSObject* maybeScopeChain() const {
267 return scopeChain;
270 void setScopeChain(JSObject *obj) {
271 scopeChain = obj;
274 JSObject** addressScopeChain() {
275 return &scopeChain;
278 static size_t offsetScopeChain() {
279 return offsetof(JSStackFrame, scopeChain);
282 /* Block chain accessors */
284 bool hasBlockChain() const {
285 return blockChain != NULL;
288 JSObject* getBlockChain() const {
289 JS_ASSERT(hasBlockChain());
290 return blockChain;
293 JSObject* maybeBlockChain() const {
294 return blockChain;
297 void setBlockChain(JSObject *obj) {
298 blockChain = obj;
301 static size_t offsetBlockChain() {
302 return offsetof(JSStackFrame, blockChain);
305 /* IMacroPC accessors. */
307 bool hasIMacroPC() const { return flags & JSFRAME_IN_IMACRO; }
310 * @pre hasIMacroPC
311 * @return The PC at which an imacro started executing (guaranteed non-null. The PC of the
312 * executing imacro must be in regs.pc, so the displaced
313 * original value is stored here.
315 jsbytecode *getIMacroPC() const {
316 JS_ASSERT(flags & JSFRAME_IN_IMACRO);
317 return imacpc;
320 /* @return The imacro pc if hasIMacroPC; otherwise, NULL. */
321 jsbytecode *maybeIMacroPC() const { return hasIMacroPC() ? getIMacroPC() : NULL; }
323 void clearIMacroPC() { flags &= ~JSFRAME_IN_IMACRO; }
325 void setIMacroPC(jsbytecode *newIMacPC) {
326 JS_ASSERT(newIMacPC);
327 JS_ASSERT(!(flags & JSFRAME_IN_IMACRO));
328 imacpc = newIMacPC;
329 flags |= JSFRAME_IN_IMACRO;
332 /* Annotation accessors */
334 bool hasAnnotation() const {
335 return annotation != NULL;
338 void* getAnnotation() const {
339 JS_ASSERT(hasAnnotation());
340 return annotation;
343 void* maybeAnnotation() const {
344 return annotation;
347 void setAnnotation(void *annot) {
348 annotation = annot;
351 static size_t offsetAnnotation() {
352 return offsetof(JSStackFrame, annotation);
355 /* Debugger hook data accessors */
357 bool hasHookData() const {
358 return hookData != NULL;
361 void* getHookData() const {
362 JS_ASSERT(hasHookData());
363 return hookData;
366 void* maybeHookData() const {
367 return hookData;
370 void setHookData(void *data) {
371 hookData = data;
374 static size_t offsetHookData() {
375 return offsetof(JSStackFrame, hookData);
378 /* Version accessors */
380 JSVersion getCallerVersion() const {
381 return callerVersion;
384 void setCallerVersion(JSVersion version) {
385 callerVersion = version;
388 static size_t offsetCallerVersion() {
389 return offsetof(JSStackFrame, callerVersion);
392 /* Script accessors */
394 bool hasScript() const {
395 return script != NULL;
398 JSScript* getScript() const {
399 JS_ASSERT(hasScript());
400 return script;
403 JSScript* maybeScript() const {
404 return script;
407 size_t getFixedCount() const {
408 return getScript()->nfixed;
411 size_t getSlotCount() const {
412 return getScript()->nslots;
415 void setScript(JSScript *s) {
416 script = s;
419 static size_t offsetScript() {
420 return offsetof(JSStackFrame, script);
423 /* Function accessors */
425 bool hasFunction() const {
426 return fun != NULL;
429 JSFunction* getFunction() const {
430 JS_ASSERT(hasFunction());
431 return fun;
434 JSFunction* maybeFunction() const {
435 return fun;
438 static size_t offsetFunction() {
439 return offsetof(JSStackFrame, fun);
442 size_t numFormalArgs() const {
443 JS_ASSERT(!isEvalFrame());
444 return getFunction()->nargs;
447 void setFunction(JSFunction *f) {
448 fun = f;
451 /* This-value accessors */
453 const js::Value& getThisValue() {
454 return thisv;
457 void setThisValue(const js::Value &v) {
458 thisv = v;
461 static size_t offsetThisValue() {
462 return offsetof(JSStackFrame, thisv);
465 /* Return-value accessors */
467 const js::Value& getReturnValue() {
468 return rval;
471 void setReturnValue(const js::Value &v) {
472 rval = v;
475 void clearReturnValue() {
476 rval.setUndefined();
479 js::Value* addressReturnValue() {
480 return &rval;
483 static size_t offsetReturnValue() {
484 return offsetof(JSStackFrame, rval);
487 /* Argument count accessors */
489 size_t numActualArgs() const {
490 JS_ASSERT(!isEvalFrame());
491 return argc;
494 void setNumActualArgs(size_t n) {
495 argc = n;
498 static size_t offsetNumActualArgs() {
499 return offsetof(JSStackFrame, argc);
502 /* Other accessors */
504 void putActivationObjects(JSContext *cx) {
506 * The order of calls here is important as js_PutCallObject needs to
507 * access argsobj.
509 if (hasCallObj()) {
510 js_PutCallObject(cx, this);
511 JS_ASSERT(!hasArgsObj());
512 } else if (hasArgsObj()) {
513 js_PutArgsObject(cx, this);
517 const js::Value &calleeValue() {
518 JS_ASSERT(argv);
519 return argv[-2];
522 /* Infallible getter to return the callee object from this frame. */
523 JSObject &calleeObject() const {
524 JS_ASSERT(argv);
525 return argv[-2].toObject();
529 * Fallible getter to compute the correct callee function object, which may
530 * require deferred cloning due to JSObject::methodReadBarrier. For a frame
531 * with null fun member, return true with *vp set from this->calleeValue(),
532 * which may not be an object (it could be undefined).
534 bool getValidCalleeObject(JSContext *cx, js::Value *vp);
536 void setCalleeObject(JSObject &callable) {
537 JS_ASSERT(argv);
538 argv[-2].setObject(callable);
541 JSObject *callee() {
542 return argv ? &argv[-2].toObject() : NULL;
546 * Get the "variable object" (ES3 term) associated with the Execution
547 * Context's VariableEnvironment (ES5 10.3). The given StackSegment
548 * must contain this stack frame.
550 JSObject *varobj(js::StackSegment *seg) const;
552 /* Short for: varobj(cx->activeSegment()). */
553 JSObject *varobj(JSContext *cx) const;
555 inline JSObject *getThisObject(JSContext *cx);
557 bool isGenerator() const { return !!(flags & JSFRAME_GENERATOR); }
558 bool isFloatingGenerator() const {
559 JS_ASSERT_IF(flags & JSFRAME_FLOATING_GENERATOR, isGenerator());
560 return !!(flags & JSFRAME_FLOATING_GENERATOR);
563 bool isDummyFrame() const { return !!(flags & JSFRAME_DUMMY); }
564 bool isEvalFrame() const { return !!(flags & JSFRAME_EVAL); }
566 private:
567 JSObject *computeThisObject(JSContext *cx);
569 /* Contains static assertions for member alignment, don't call. */
570 inline void staticAsserts();
573 namespace js {
575 JS_STATIC_ASSERT(sizeof(JSStackFrame) % sizeof(Value) == 0);
576 static const size_t VALUES_PER_STACK_FRAME = sizeof(JSStackFrame) / sizeof(Value);
578 } /* namespace js */
580 inline void
581 JSStackFrame::staticAsserts()
583 JS_STATIC_ASSERT(offsetof(JSStackFrame, rval) % sizeof(js::Value) == 0);
584 JS_STATIC_ASSERT(offsetof(JSStackFrame, thisv) % sizeof(js::Value) == 0);
586 /* Static assert for x86 trampolines in MethodJIT.cpp */
587 #if defined(JS_METHODJIT)
588 # if defined(JS_CPU_X86)
589 JS_STATIC_ASSERT(offsetof(JSStackFrame, rval) == 0x28);
590 # elif defined(JS_CPU_X64)
591 JS_STATIC_ASSERT(offsetof(JSStackFrame, rval) == 0x40);
592 # endif
593 #endif
596 static JS_INLINE uintN
597 GlobalVarCount(JSStackFrame *fp)
599 JS_ASSERT(!fp->hasFunction());
600 return fp->getScript()->nfixed;
604 * Refresh and return fp->scopeChain. It may be stale if block scopes are
605 * active but not yet reflected by objects in the scope chain. If a block
606 * scope contains a with, eval, XML filtering predicate, or similar such
607 * dynamically scoped construct, then compile-time block scope at fp->blocks
608 * must reflect at runtime.
610 extern JSObject *
611 js_GetScopeChain(JSContext *cx, JSStackFrame *fp);
614 * Given a context and a vector of [callee, this, args...] for a function that
615 * was specified with a JSFUN_THISP_PRIMITIVE flag, get the primitive value of
616 * |this| into *thisvp. In doing so, if |this| is an object, insist it is an
617 * instance of clasp and extract its private slot value to return via *thisvp.
619 * NB: this function loads and uses *vp before storing *thisvp, so the two may
620 * alias the same Value.
622 extern JSBool
623 js_GetPrimitiveThis(JSContext *cx, js::Value *vp, js::Class *clasp,
624 const js::Value **vpp);
626 namespace js {
629 * For a call with arguments argv including argv[-1] (nominal |this|) and
630 * argv[-2] (callee) replace null |this| with callee's parent and replace
631 * primitive values with the equivalent wrapper objects. argv[-1] must
632 * not be JSVAL_VOID or an activation object.
634 extern bool
635 ComputeThisFromArgv(JSContext *cx, js::Value *argv);
637 JS_ALWAYS_INLINE JSObject *
638 ComputeThisFromVp(JSContext *cx, js::Value *vp)
640 extern bool ComputeThisFromArgv(JSContext *, js::Value *);
641 return ComputeThisFromArgv(cx, vp + 2) ? &vp[1].toObject() : NULL;
644 JS_ALWAYS_INLINE bool
645 ComputeThisFromVpInPlace(JSContext *cx, js::Value *vp)
647 extern bool ComputeThisFromArgv(JSContext *, js::Value *);
648 return ComputeThisFromArgv(cx, vp + 2);
651 JS_ALWAYS_INLINE bool
652 PrimitiveThisTest(JSFunction *fun, const Value &v)
654 uint16 flags = fun->flags;
655 return (v.isString() && !!(flags & JSFUN_THISP_STRING)) ||
656 (v.isNumber() && !!(flags & JSFUN_THISP_NUMBER)) ||
657 (v.isBoolean() && !!(flags & JSFUN_THISP_BOOLEAN));
661 * Abstracts the layout of the stack passed to natives from the engine and from
662 * natives to js::Invoke.
664 struct CallArgs
666 Value *argv_;
667 uintN argc_;
668 protected:
669 CallArgs() {}
670 CallArgs(Value *argv, uintN argc) : argv_(argv), argc_(argc) {}
671 public:
672 Value *base() const { return argv_ - 2; }
673 Value &callee() const { return argv_[-2]; }
674 Value &thisv() const { return argv_[-1]; }
675 Value &operator[](unsigned i) const { JS_ASSERT(i < argc_); return argv_[i]; }
676 Value *argv() const { return argv_; }
677 uintN argc() const { return argc_; }
678 Value &rval() const { return argv_[-2]; }
680 bool computeThis(JSContext *cx) const {
681 return ComputeThisFromArgv(cx, argv_);
686 * The js::InvokeArgumentsGuard passed to js_Invoke must come from an
687 * immediately-enclosing successful call to js::StackSpace::pushInvokeArgs,
688 * i.e., there must have been no un-popped pushes to cx->stack(). Furthermore,
689 * |args.getvp()[0]| should be the callee, |args.getvp()[1]| should be |this|,
690 * and the range [args.getvp() + 2, args.getvp() + 2 + args.getArgc()) should
691 * be initialized actual arguments.
693 extern JS_REQUIRES_STACK bool
694 Invoke(JSContext *cx, const CallArgs &args, uintN flags);
697 * Consolidated js_Invoke flags simply rename certain JSFRAME_* flags, so that
698 * we can share bits stored in JSStackFrame.flags and passed to:
700 * js_Invoke
701 * js_InternalInvoke
702 * js_ValueToFunction
703 * js_ValueToFunctionObject
704 * js_ValueToCallableObject
705 * js_ReportIsNotFunction
707 * See jsfun.h for the latter four and flag renaming macros.
709 #define JSINVOKE_CONSTRUCT JSFRAME_CONSTRUCTING
712 * Mask to isolate construct and iterator flags for use with jsfun.h functions.
714 #define JSINVOKE_FUNFLAGS JSINVOKE_CONSTRUCT
717 * "External" calls may come from C or C++ code using a JSContext on which no
718 * JS is running (!cx->fp), so they may need to push a dummy JSStackFrame.
721 extern bool
722 ExternalInvoke(JSContext *cx, const Value &thisv, const Value &fval,
723 uintN argc, Value *argv, Value *rval);
725 static JS_ALWAYS_INLINE bool
726 ExternalInvoke(JSContext *cx, JSObject *obj, const Value &fval,
727 uintN argc, Value *argv, Value *rval)
729 return ExternalInvoke(cx, ObjectOrNullValue(obj), fval, argc, argv, rval);
732 extern bool
733 ExternalGetOrSet(JSContext *cx, JSObject *obj, jsid id, const Value &fval,
734 JSAccessMode mode, uintN argc, Value *argv, Value *rval);
737 * These two functions invoke a function called from a constructor context
738 * (e.g. 'new'). InvokeConstructor handles the general case where a new object
739 * needs to be created for/by the constructor. ConstructWithGivenThis directly
740 * calls the constructor with the given 'this', hence the caller must
741 * understand the semantics of the constructor call.
744 extern JS_REQUIRES_STACK bool
745 InvokeConstructor(JSContext *cx, const CallArgs &args);
747 extern JS_REQUIRES_STACK bool
748 InvokeConstructorWithGivenThis(JSContext *cx, JSObject *thisobj, const Value &fval,
749 uintN argc, Value *argv, Value *rval);
752 * Executes a script with the given scope chain in the context of the given
753 * frame.
755 extern JS_FORCES_STACK bool
756 Execute(JSContext *cx, JSObject *chain, JSScript *script,
757 JSStackFrame *down, uintN flags, Value *result);
760 * Execute the caller-initialized frame for a user-defined script or function
761 * pointed to by cx->fp until completion or error.
763 extern JS_REQUIRES_STACK bool
764 Interpret(JSContext *cx, JSStackFrame *stopFp, uintN inlineCallCount = 0, uintN interpFlags = 0);
766 extern JS_REQUIRES_STACK bool
767 RunScript(JSContext *cx, JSScript *script, JSFunction *fun, JSObject *scopeChain);
769 #define JSPROP_INITIALIZER 0x100 /* NB: Not a valid property attribute. */
771 extern bool
772 CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs,
773 JSObject **objp, JSProperty **propp);
775 extern bool
776 StrictlyEqual(JSContext *cx, const Value &lval, const Value &rval);
778 /* === except that NaN is the same as NaN and -0 is not the same as +0. */
779 extern bool
780 SameValue(const Value &v1, const Value &v2, JSContext *cx);
782 extern JSType
783 TypeOfValue(JSContext *cx, const Value &v);
785 inline bool
786 InstanceOf(JSContext *cx, JSObject *obj, Class *clasp, Value *argv)
788 if (obj && obj->getClass() == clasp)
789 return true;
790 extern bool InstanceOfSlow(JSContext *, JSObject *, Class *, Value *);
791 return InstanceOfSlow(cx, obj, clasp, argv);
794 extern JSBool
795 HasInstance(JSContext *cx, JSObject *obj, const js::Value *v, JSBool *bp);
797 inline void *
798 GetInstancePrivate(JSContext *cx, JSObject *obj, Class *clasp, Value *argv)
800 if (!InstanceOf(cx, obj, clasp, argv))
801 return NULL;
802 return obj->getPrivate();
805 extern bool
806 ValueToId(JSContext *cx, const Value &v, jsid *idp);
809 * @param closureLevel The static level of the closure that the cookie
810 * pertains to.
811 * @param cookie Level amount is a "skip" (delta) value from the
812 * closure level.
813 * @return The value of the upvar.
815 extern const js::Value &
816 GetUpvar(JSContext *cx, uintN level, js::UpvarCookie cookie);
818 } /* namespace js */
821 * JS_LONE_INTERPRET indicates that the compiler should see just the code for
822 * the js_Interpret function when compiling jsinterp.cpp. The rest of the code
823 * from the file should be visible only when compiling jsinvoke.cpp. It allows
824 * platform builds to optimize selectively js_Interpret when the granularity
825 * of the optimizations with the given compiler is a compilation unit.
827 * JS_STATIC_INTERPRET is the modifier for functions defined in jsinterp.cpp
828 * that only js_Interpret calls. When JS_LONE_INTERPRET is true all such
829 * functions are declared below.
831 #ifndef JS_LONE_INTERPRET
832 # ifdef _MSC_VER
833 # define JS_LONE_INTERPRET 0
834 # else
835 # define JS_LONE_INTERPRET 1
836 # endif
837 #endif
839 #define JS_MAX_INLINE_CALL_COUNT 3000
841 #if !JS_LONE_INTERPRET
842 # define JS_STATIC_INTERPRET static
843 #else
844 # define JS_STATIC_INTERPRET
846 extern JS_REQUIRES_STACK JSBool
847 js_EnterWith(JSContext *cx, jsint stackIndex);
849 extern JS_REQUIRES_STACK void
850 js_LeaveWith(JSContext *cx);
853 * Find the results of incrementing or decrementing *vp. For pre-increments,
854 * both *vp and *vp2 will contain the result on return. For post-increments,
855 * vp will contain the original value converted to a number and vp2 will get
856 * the result. Both vp and vp2 must be roots.
858 extern JSBool
859 js_DoIncDec(JSContext *cx, const JSCodeSpec *cs, js::Value *vp, js::Value *vp2);
862 * Opcode tracing helper. When len is not 0, cx->fp->regs->pc[-len] gives the
863 * previous opcode.
865 extern JS_REQUIRES_STACK void
866 js_TraceOpcode(JSContext *cx);
869 * JS_OPMETER helper functions.
871 extern void
872 js_MeterOpcodePair(JSOp op1, JSOp op2);
874 extern void
875 js_MeterSlotOpcode(JSOp op, uint32 slot);
877 #endif /* JS_LONE_INTERPRET */
880 * Unwind block and scope chains to match the given depth. The function sets
881 * fp->sp on return to stackDepth.
883 extern JS_REQUIRES_STACK JSBool
884 js_UnwindScope(JSContext *cx, jsint stackDepth, JSBool normalUnwind);
886 extern JSBool
887 js_OnUnknownMethod(JSContext *cx, js::Value *vp);
889 extern JS_REQUIRES_STACK js::Class *
890 js_IsActiveWithOrBlock(JSContext *cx, JSObject *obj, int stackDepth);
892 inline JSObject *
893 JSStackFrame::getThisObject(JSContext *cx)
895 JS_ASSERT(!isDummyFrame());
896 return thisv.isPrimitive() ? computeThisObject(cx) : &thisv.toObject();
899 #endif /* jsinterp_h___ */