ICs for scripted calls (bug 587698, r=dmandelin).
[mozilla-central.git] / js / src / jsinterp.h
blobadf784f89d2f885b988d91fea018323cedb3c5a0
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_BAILING = 0x100, /* walking out of a method JIT'd frame */
71 JSFRAME_RECORDING = 0x200, /* recording a trace */
72 JSFRAME_BAILED_AT_RETURN = 0x400, /* bailed at JSOP_RETURN */
73 JSFRAME_DUMMY = 0x800, /* frame is a dummy frame */
74 JSFRAME_IN_IMACRO = 0x1000, /* frame has imacpc value available */
76 JSFRAME_SPECIAL = JSFRAME_DEBUGGER | JSFRAME_EVAL
79 namespace js { namespace mjit {
80 class Compiler;
81 class InlineFrameAssembler;
82 } }
85 * JS stack frame, may be allocated on the C stack by native callers. Always
86 * allocated on cx->stackPool for calls from the interpreter to an interpreted
87 * function.
89 * NB: This struct is manually initialized in jsinterp.c and jsiter.c. If you
90 * add new members, update both files.
92 struct JSStackFrame
94 private:
95 JSObject *callobj; /* lazily created Call object */
96 JSObject *argsobj; /* lazily created arguments object */
97 jsbytecode *imacpc; /* null or interpreter macro call pc */
98 JSScript *script; /* script being interpreted */
101 * The value of |this| in this stack frame, or JSVAL_NULL if |this|
102 * is to be computed lazily on demand.
104 * thisv is eagerly initialized for non-function-call frames and
105 * qualified method calls, but lazily initialized in most unqualified
106 * function calls. See getThisObject().
108 * Usually if argv != NULL then thisv == argv[-1], but natives may
109 * assign to argv[-1]. Also, obj_eval can trigger a special case
110 * where two stack frames have the same argv. If one of the frames fills
111 * in both argv[-1] and thisv, the other frame's thisv is left null.
113 js::Value thisv; /* "this" pointer if in method */
114 JSFunction *fun; /* function being called or null */
116 public:
117 uintN argc; /* actual argument count */
118 js::Value *argv; /* base of argument stack slots */
120 private:
121 js::Value rval; /* function return value */
122 void *annotation; /* used by Java security */
124 public:
125 /* Maintained by StackSpace operations */
126 JSStackFrame *down; /* previous frame, part of
127 stack layout invariant */
128 jsbytecode *savedPC; /* only valid if cx->fp != this */
129 #ifdef DEBUG
130 static jsbytecode *const sInvalidPC;
131 #endif
133 void *ncode; /* jit return pc */
135 private:
136 JSObject *scopeChain;
137 JSObject *blockChain;
139 public:
140 uint32 flags; /* frame flags -- see below */
142 private:
143 /* Members only needed for inline calls. */
144 void *hookData; /* debugger call hook data */
145 JSVersion callerVersion; /* dynamic version of calling script */
147 public:
148 /* Get the frame's current bytecode, assuming |this| is in |cx|. */
149 jsbytecode *pc(JSContext *cx) const;
151 js::Value *argEnd() const {
152 return (js::Value *)this;
155 js::Value *slots() const {
156 return (js::Value *)(this + 1);
159 js::Value *base() const {
160 return slots() + getScript()->nfixed;
163 /* Call object accessors */
165 bool hasCallObj() const {
166 return callobj != NULL;
169 JSObject* getCallObj() const {
170 JS_ASSERT(hasCallObj());
171 return callobj;
174 JSObject* maybeCallObj() const {
175 return callobj;
178 void setCallObj(JSObject *obj) {
179 callobj = obj;
182 static size_t offsetCallObj() {
183 return offsetof(JSStackFrame, callobj);
186 /* Arguments object accessors */
188 bool hasArgsObj() const {
189 return argsobj != NULL;
192 JSObject* getArgsObj() const {
193 JS_ASSERT(hasArgsObj());
194 JS_ASSERT(!isEvalFrame());
195 return argsobj;
198 JSObject* maybeArgsObj() const {
199 return argsobj;
202 void setArgsObj(JSObject *obj) {
203 argsobj = obj;
206 JSObject** addressArgsObj() {
207 return &argsobj;
210 static size_t offsetArgsObj() {
211 return offsetof(JSStackFrame, argsobj);
215 * We can't determine in advance which local variables can live on
216 * the stack and be freed when their dynamic scope ends, and which
217 * will be closed over and need to live in the heap. So we place
218 * variables on the stack initially, note when they are closed
219 * over, and copy those that are out to the heap when we leave
220 * their dynamic scope.
222 * The bytecode compiler produces a tree of block objects
223 * accompanying each JSScript representing those lexical blocks in
224 * the script that have let-bound variables associated with them.
225 * These block objects are never modified, and never become part
226 * of any function's scope chain. Their parent slots point to the
227 * innermost block that encloses them, or are NULL in the
228 * outermost blocks within a function or in eval or global code.
230 * When we are in the static scope of such a block, blockChain
231 * points to its compiler-allocated block object; otherwise, it is
232 * NULL.
234 * scopeChain is the current scope chain, including 'call' and
235 * 'block' objects for those function calls and lexical blocks
236 * whose static scope we are currently executing in, and 'with'
237 * objects for with statements; the chain is typically terminated
238 * by a global object. However, as an optimization, the young end
239 * of the chain omits block objects we have not yet cloned. To
240 * create a closure, we clone the missing blocks from blockChain
241 * (which is always current), place them at the head of
242 * scopeChain, and use that for the closure's scope chain. If we
243 * never close over a lexical block, we never place a mutable
244 * clone of it on scopeChain.
246 * This lazy cloning is implemented in js_GetScopeChain, which is
247 * also used in some other cases --- entering 'with' blocks, for
248 * example.
251 /* Scope chain accessors */
253 bool hasScopeChain() const {
254 return scopeChain != NULL;
257 JSObject* getScopeChain() const {
258 JS_ASSERT(hasScopeChain());
259 return scopeChain;
262 JSObject* maybeScopeChain() const {
263 return scopeChain;
266 void setScopeChain(JSObject *obj) {
267 scopeChain = obj;
270 JSObject** addressScopeChain() {
271 return &scopeChain;
274 static size_t offsetScopeChain() {
275 return offsetof(JSStackFrame, scopeChain);
278 /* Block chain accessors */
280 bool hasBlockChain() const {
281 return blockChain != NULL;
284 JSObject* getBlockChain() const {
285 JS_ASSERT(hasBlockChain());
286 return blockChain;
289 JSObject* maybeBlockChain() const {
290 return blockChain;
293 void setBlockChain(JSObject *obj) {
294 blockChain = obj;
297 static size_t offsetBlockChain() {
298 return offsetof(JSStackFrame, blockChain);
301 /* IMacroPC accessors. */
303 bool hasIMacroPC() const { return flags & JSFRAME_IN_IMACRO; }
306 * @pre hasIMacroPC
307 * @return The PC at which an imacro started executing (guaranteed non-null. The PC of the
308 * executing imacro must be in regs.pc, so the displaced
309 * original value is stored here.
311 jsbytecode *getIMacroPC() const {
312 JS_ASSERT(flags & JSFRAME_IN_IMACRO);
313 return imacpc;
316 /* @return The imacro pc if hasIMacroPC; otherwise, NULL. */
317 jsbytecode *maybeIMacroPC() const { return hasIMacroPC() ? getIMacroPC() : NULL; }
319 void clearIMacroPC() { flags &= ~JSFRAME_IN_IMACRO; }
321 void setIMacroPC(jsbytecode *newIMacPC) {
322 JS_ASSERT(newIMacPC);
323 JS_ASSERT(!(flags & JSFRAME_IN_IMACRO));
324 imacpc = newIMacPC;
325 flags |= JSFRAME_IN_IMACRO;
328 /* Annotation accessors */
330 bool hasAnnotation() const {
331 return annotation != NULL;
334 void* getAnnotation() const {
335 JS_ASSERT(hasAnnotation());
336 return annotation;
339 void* maybeAnnotation() const {
340 return annotation;
343 void setAnnotation(void *annot) {
344 annotation = annot;
347 static size_t offsetAnnotation() {
348 return offsetof(JSStackFrame, annotation);
351 /* Debugger hook data accessors */
353 bool hasHookData() const {
354 return hookData != NULL;
357 void* getHookData() const {
358 JS_ASSERT(hasHookData());
359 return hookData;
362 void* maybeHookData() const {
363 return hookData;
366 void setHookData(void *data) {
367 hookData = data;
370 static size_t offsetHookData() {
371 return offsetof(JSStackFrame, hookData);
374 /* Version accessors */
376 JSVersion getCallerVersion() const {
377 return callerVersion;
380 void setCallerVersion(JSVersion version) {
381 callerVersion = version;
384 static size_t offsetCallerVersion() {
385 return offsetof(JSStackFrame, callerVersion);
388 /* Script accessors */
390 bool hasScript() const {
391 return script != NULL;
394 JSScript* getScript() const {
395 JS_ASSERT(hasScript());
396 return script;
399 JSScript* maybeScript() const {
400 return script;
403 size_t getFixedCount() const {
404 return getScript()->nfixed;
407 size_t getSlotCount() const {
408 return getScript()->nslots;
411 void setScript(JSScript *s) {
412 script = s;
415 static size_t offsetScript() {
416 return offsetof(JSStackFrame, script);
419 /* Function accessors */
421 bool hasFunction() const {
422 return fun != NULL;
425 JSFunction* getFunction() const {
426 JS_ASSERT(hasFunction());
427 return fun;
430 JSFunction* maybeFunction() const {
431 return fun;
434 static size_t offsetFunction() {
435 return offsetof(JSStackFrame, fun);
438 size_t numFormalArgs() const {
439 JS_ASSERT(!isEvalFrame());
440 return getFunction()->nargs;
443 void setFunction(JSFunction *f) {
444 fun = f;
447 /* This-value accessors */
449 const js::Value& getThisValue() {
450 return thisv;
453 void setThisValue(const js::Value &v) {
454 thisv = v;
457 static size_t offsetThisValue() {
458 return offsetof(JSStackFrame, thisv);
461 /* Return-value accessors */
463 const js::Value& getReturnValue() {
464 return rval;
467 void setReturnValue(const js::Value &v) {
468 rval = v;
471 void clearReturnValue() {
472 rval.setUndefined();
475 js::Value* addressReturnValue() {
476 return &rval;
479 static size_t offsetReturnValue() {
480 return offsetof(JSStackFrame, rval);
483 /* Argument count accessors */
485 size_t numActualArgs() const {
486 JS_ASSERT(!isEvalFrame());
487 return argc;
490 void setNumActualArgs(size_t n) {
491 argc = n;
494 static size_t offsetNumActualArgs() {
495 return offsetof(JSStackFrame, argc);
498 /* Other accessors */
500 void putActivationObjects(JSContext *cx) {
502 * The order of calls here is important as js_PutCallObject needs to
503 * access argsobj.
505 if (hasCallObj()) {
506 js_PutCallObject(cx, this);
507 JS_ASSERT(!hasArgsObj());
508 } else if (hasArgsObj()) {
509 js_PutArgsObject(cx, this);
513 const js::Value &calleeValue() {
514 JS_ASSERT(argv);
515 return argv[-2];
518 /* Infallible getter to return the callee object from this frame. */
519 JSObject &calleeObject() const {
520 JS_ASSERT(argv);
521 return argv[-2].toObject();
525 * Fallible getter to compute the correct callee function object, which may
526 * require deferred cloning due to JSObject::methodReadBarrier. For a frame
527 * with null fun member, return true with *vp set from this->calleeValue(),
528 * which may not be an object (it could be undefined).
530 bool getValidCalleeObject(JSContext *cx, js::Value *vp);
532 void setCalleeObject(JSObject &callable) {
533 JS_ASSERT(argv);
534 argv[-2].setObject(callable);
537 JSObject *callee() {
538 return argv ? &argv[-2].toObject() : NULL;
542 * Get the "variable object" (ES3 term) associated with the Execution
543 * Context's VariableEnvironment (ES5 10.3). The given StackSegment
544 * must contain this stack frame.
546 JSObject *varobj(js::StackSegment *seg) const;
548 /* Short for: varobj(cx->activeSegment()). */
549 JSObject *varobj(JSContext *cx) const;
551 inline JSObject *getThisObject(JSContext *cx);
553 bool isGenerator() const { return !!(flags & JSFRAME_GENERATOR); }
554 bool isFloatingGenerator() const {
555 JS_ASSERT_IF(flags & JSFRAME_FLOATING_GENERATOR, isGenerator());
556 return !!(flags & JSFRAME_FLOATING_GENERATOR);
559 bool isDummyFrame() const { return !!(flags & JSFRAME_DUMMY); }
560 bool isEvalFrame() const { return !!(flags & JSFRAME_EVAL); }
562 private:
563 JSObject *computeThisObject(JSContext *cx);
565 /* Contains static assertions for member alignment, don't call. */
566 inline void staticAsserts();
569 namespace js {
571 JS_STATIC_ASSERT(sizeof(JSStackFrame) % sizeof(Value) == 0);
572 static const size_t VALUES_PER_STACK_FRAME = sizeof(JSStackFrame) / sizeof(Value);
574 } /* namespace js */
576 inline void
577 JSStackFrame::staticAsserts()
579 JS_STATIC_ASSERT(offsetof(JSStackFrame, rval) % sizeof(js::Value) == 0);
580 JS_STATIC_ASSERT(offsetof(JSStackFrame, thisv) % sizeof(js::Value) == 0);
582 /* Static assert for x86 trampolines in MethodJIT.cpp */
583 #if defined(JS_METHODJIT)
584 # if defined(JS_CPU_X86)
585 JS_STATIC_ASSERT(offsetof(JSStackFrame, rval) == 0x28);
586 # elif defined(JS_CPU_X64)
587 JS_STATIC_ASSERT(offsetof(JSStackFrame, rval) == 0x40);
588 # endif
589 #endif
592 static JS_INLINE uintN
593 GlobalVarCount(JSStackFrame *fp)
595 JS_ASSERT(!fp->hasFunction());
596 return fp->getScript()->nfixed;
600 * Refresh and return fp->scopeChain. It may be stale if block scopes are
601 * active but not yet reflected by objects in the scope chain. If a block
602 * scope contains a with, eval, XML filtering predicate, or similar such
603 * dynamically scoped construct, then compile-time block scope at fp->blocks
604 * must reflect at runtime.
606 extern JSObject *
607 js_GetScopeChain(JSContext *cx, JSStackFrame *fp);
610 * Given a context and a vector of [callee, this, args...] for a function that
611 * was specified with a JSFUN_THISP_PRIMITIVE flag, get the primitive value of
612 * |this| into *thisvp. In doing so, if |this| is an object, insist it is an
613 * instance of clasp and extract its private slot value to return via *thisvp.
615 * NB: this function loads and uses *vp before storing *thisvp, so the two may
616 * alias the same Value.
618 extern JSBool
619 js_GetPrimitiveThis(JSContext *cx, js::Value *vp, js::Class *clasp,
620 const js::Value **vpp);
622 namespace js {
625 * For a call with arguments argv including argv[-1] (nominal |this|) and
626 * argv[-2] (callee) replace null |this| with callee's parent and replace
627 * primitive values with the equivalent wrapper objects. argv[-1] must
628 * not be JSVAL_VOID or an activation object.
630 extern bool
631 ComputeThisFromArgv(JSContext *cx, js::Value *argv);
633 JS_ALWAYS_INLINE JSObject *
634 ComputeThisFromVp(JSContext *cx, js::Value *vp)
636 extern bool ComputeThisFromArgv(JSContext *, js::Value *);
637 return ComputeThisFromArgv(cx, vp + 2) ? &vp[1].toObject() : NULL;
640 JS_ALWAYS_INLINE bool
641 ComputeThisFromVpInPlace(JSContext *cx, js::Value *vp)
643 extern bool ComputeThisFromArgv(JSContext *, js::Value *);
644 return ComputeThisFromArgv(cx, vp + 2);
647 JS_ALWAYS_INLINE bool
648 PrimitiveThisTest(JSFunction *fun, const Value &v)
650 uint16 flags = fun->flags;
651 return (v.isString() && !!(flags & JSFUN_THISP_STRING)) ||
652 (v.isNumber() && !!(flags & JSFUN_THISP_NUMBER)) ||
653 (v.isBoolean() && !!(flags & JSFUN_THISP_BOOLEAN));
657 * Abstracts the layout of the stack passed to natives from the engine and from
658 * natives to js::Invoke.
660 struct CallArgs
662 Value *argv_;
663 uintN argc_;
664 protected:
665 CallArgs() {}
666 CallArgs(Value *argv, uintN argc) : argv_(argv), argc_(argc) {}
667 public:
668 Value *base() const { return argv_ - 2; }
669 Value &callee() const { return argv_[-2]; }
670 Value &thisv() const { return argv_[-1]; }
671 Value &operator[](unsigned i) const { JS_ASSERT(i < argc_); return argv_[i]; }
672 Value *argv() const { return argv_; }
673 uintN argc() const { return argc_; }
674 Value &rval() const { return argv_[-2]; }
676 bool computeThis(JSContext *cx) const {
677 return ComputeThisFromArgv(cx, argv_);
682 * The js::InvokeArgumentsGuard passed to js_Invoke must come from an
683 * immediately-enclosing successful call to js::StackSpace::pushInvokeArgs,
684 * i.e., there must have been no un-popped pushes to cx->stack(). Furthermore,
685 * |args.getvp()[0]| should be the callee, |args.getvp()[1]| should be |this|,
686 * and the range [args.getvp() + 2, args.getvp() + 2 + args.getArgc()) should
687 * be initialized actual arguments.
689 extern JS_REQUIRES_STACK bool
690 Invoke(JSContext *cx, const CallArgs &args, uintN flags);
693 * Consolidated js_Invoke flags simply rename certain JSFRAME_* flags, so that
694 * we can share bits stored in JSStackFrame.flags and passed to:
696 * js_Invoke
697 * js_InternalInvoke
698 * js_ValueToFunction
699 * js_ValueToFunctionObject
700 * js_ValueToCallableObject
701 * js_ReportIsNotFunction
703 * See jsfun.h for the latter four and flag renaming macros.
705 #define JSINVOKE_CONSTRUCT JSFRAME_CONSTRUCTING
708 * Mask to isolate construct and iterator flags for use with jsfun.h functions.
710 #define JSINVOKE_FUNFLAGS JSINVOKE_CONSTRUCT
713 * "External" calls may come from C or C++ code using a JSContext on which no
714 * JS is running (!cx->fp), so they may need to push a dummy JSStackFrame.
717 extern bool
718 ExternalInvoke(JSContext *cx, const Value &thisv, const Value &fval,
719 uintN argc, Value *argv, Value *rval);
721 static JS_ALWAYS_INLINE bool
722 ExternalInvoke(JSContext *cx, JSObject *obj, const Value &fval,
723 uintN argc, Value *argv, Value *rval)
725 return ExternalInvoke(cx, ObjectOrNullValue(obj), fval, argc, argv, rval);
728 extern bool
729 ExternalGetOrSet(JSContext *cx, JSObject *obj, jsid id, const Value &fval,
730 JSAccessMode mode, uintN argc, Value *argv, Value *rval);
733 * These two functions invoke a function called from a constructor context
734 * (e.g. 'new'). InvokeConstructor handles the general case where a new object
735 * needs to be created for/by the constructor. ConstructWithGivenThis directly
736 * calls the constructor with the given 'this', hence the caller must
737 * understand the semantics of the constructor call.
740 extern JS_REQUIRES_STACK bool
741 InvokeConstructor(JSContext *cx, const CallArgs &args);
743 extern JS_REQUIRES_STACK bool
744 InvokeConstructorWithGivenThis(JSContext *cx, JSObject *thisobj, const Value &fval,
745 uintN argc, Value *argv, Value *rval);
748 * Executes a script with the given scope chain in the context of the given
749 * frame.
751 extern JS_FORCES_STACK bool
752 Execute(JSContext *cx, JSObject *chain, JSScript *script,
753 JSStackFrame *down, uintN flags, Value *result);
756 * Execute the caller-initialized frame for a user-defined script or function
757 * pointed to by cx->fp until completion or error.
759 extern JS_REQUIRES_STACK bool
760 Interpret(JSContext *cx, JSStackFrame *stopFp, uintN inlineCallCount = 0);
762 extern JS_REQUIRES_STACK bool
763 RunScript(JSContext *cx, JSScript *script, JSFunction *fun, JSObject *scopeChain);
765 #define JSPROP_INITIALIZER 0x100 /* NB: Not a valid property attribute. */
767 extern bool
768 CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs,
769 JSObject **objp, JSProperty **propp);
771 extern bool
772 StrictlyEqual(JSContext *cx, const Value &lval, const Value &rval);
774 /* === except that NaN is the same as NaN and -0 is not the same as +0. */
775 extern bool
776 SameValue(const Value &v1, const Value &v2, JSContext *cx);
778 extern JSType
779 TypeOfValue(JSContext *cx, const Value &v);
781 inline bool
782 InstanceOf(JSContext *cx, JSObject *obj, Class *clasp, Value *argv)
784 if (obj && obj->getClass() == clasp)
785 return true;
786 extern bool InstanceOfSlow(JSContext *, JSObject *, Class *, Value *);
787 return InstanceOfSlow(cx, obj, clasp, argv);
790 extern JSBool
791 HasInstance(JSContext *cx, JSObject *obj, const js::Value *v, JSBool *bp);
793 inline void *
794 GetInstancePrivate(JSContext *cx, JSObject *obj, Class *clasp, Value *argv)
796 if (!InstanceOf(cx, obj, clasp, argv))
797 return NULL;
798 return obj->getPrivate();
801 extern bool
802 ValueToId(JSContext *cx, const Value &v, jsid *idp);
805 * @param closureLevel The static level of the closure that the cookie
806 * pertains to.
807 * @param cookie Level amount is a "skip" (delta) value from the
808 * closure level.
809 * @return The value of the upvar.
811 extern const js::Value &
812 GetUpvar(JSContext *cx, uintN level, js::UpvarCookie cookie);
814 } /* namespace js */
817 * JS_LONE_INTERPRET indicates that the compiler should see just the code for
818 * the js_Interpret function when compiling jsinterp.cpp. The rest of the code
819 * from the file should be visible only when compiling jsinvoke.cpp. It allows
820 * platform builds to optimize selectively js_Interpret when the granularity
821 * of the optimizations with the given compiler is a compilation unit.
823 * JS_STATIC_INTERPRET is the modifier for functions defined in jsinterp.cpp
824 * that only js_Interpret calls. When JS_LONE_INTERPRET is true all such
825 * functions are declared below.
827 #ifndef JS_LONE_INTERPRET
828 # ifdef _MSC_VER
829 # define JS_LONE_INTERPRET 0
830 # else
831 # define JS_LONE_INTERPRET 1
832 # endif
833 #endif
835 #define JS_MAX_INLINE_CALL_COUNT 3000
837 #if !JS_LONE_INTERPRET
838 # define JS_STATIC_INTERPRET static
839 #else
840 # define JS_STATIC_INTERPRET
842 extern JS_REQUIRES_STACK JSBool
843 js_EnterWith(JSContext *cx, jsint stackIndex);
845 extern JS_REQUIRES_STACK void
846 js_LeaveWith(JSContext *cx);
849 * Find the results of incrementing or decrementing *vp. For pre-increments,
850 * both *vp and *vp2 will contain the result on return. For post-increments,
851 * vp will contain the original value converted to a number and vp2 will get
852 * the result. Both vp and vp2 must be roots.
854 extern JSBool
855 js_DoIncDec(JSContext *cx, const JSCodeSpec *cs, js::Value *vp, js::Value *vp2);
858 * Opcode tracing helper. When len is not 0, cx->fp->regs->pc[-len] gives the
859 * previous opcode.
861 extern JS_REQUIRES_STACK void
862 js_TraceOpcode(JSContext *cx);
865 * JS_OPMETER helper functions.
867 extern void
868 js_MeterOpcodePair(JSOp op1, JSOp op2);
870 extern void
871 js_MeterSlotOpcode(JSOp op, uint32 slot);
873 #endif /* JS_LONE_INTERPRET */
876 * Unwind block and scope chains to match the given depth. The function sets
877 * fp->sp on return to stackDepth.
879 extern JS_REQUIRES_STACK JSBool
880 js_UnwindScope(JSContext *cx, jsint stackDepth, JSBool normalUnwind);
882 extern JSBool
883 js_OnUnknownMethod(JSContext *cx, js::Value *vp);
885 extern JS_REQUIRES_STACK js::Class *
886 js_IsActiveWithOrBlock(JSContext *cx, JSObject *obj, int stackDepth);
888 inline JSObject *
889 JSStackFrame::getThisObject(JSContext *cx)
891 JS_ASSERT(!isDummyFrame());
892 return thisv.isPrimitive() ? computeThisObject(cx) : &thisv.toObject();
895 #endif /* jsinterp_h___ */