/[jscoverage]/trunk/js/jsfun.h
ViewVC logotype

Diff of /trunk/js/jsfun.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 460 by siliconforks, Sat Sep 26 23:15:22 2009 UTC revision 507 by siliconforks, Sun Jan 10 07:23:34 2010 UTC
# Line 98  Line 98 
98   * pointer-chasing.   * pointer-chasing.
99   */   */
100  #define JSFUN_EXPR_CLOSURE  0x1000  /* expression closure: function(x) x*x */  #define JSFUN_EXPR_CLOSURE  0x1000  /* expression closure: function(x) x*x */
101  #define JSFUN_TRACEABLE     0x2000  /* can trace across calls to this native  #define JSFUN_TRCINFO       0x2000  /* when set, u.n.trcinfo is non-null,
102                                         function; use FUN_TRCINFO if set,                                         JSFunctionSpec::call points to a
103                                         FUN_CLASP if unset */                                         JSNativeTraceInfo. */
104  #define JSFUN_INTERPRETED   0x4000  /* use u.i if kind >= this value else u.n */  #define JSFUN_INTERPRETED   0x4000  /* use u.i if kind >= this value else u.n */
105  #define JSFUN_FLAT_CLOSURE  0x8000  /* flag (aka "display") closure */  #define JSFUN_FLAT_CLOSURE  0x8000  /* flag (aka "display") closure */
106  #define JSFUN_NULL_CLOSURE  0xc000  /* null closure entrains no scope chain */  #define JSFUN_NULL_CLOSURE  0xc000  /* null closure entrains no scope chain */
# Line 125  Line 125 
125  #define FUN_CLASP(fun)       (JS_ASSERT(!FUN_INTERPRETED(fun)),               \  #define FUN_CLASP(fun)       (JS_ASSERT(!FUN_INTERPRETED(fun)),               \
126                                fun->u.n.clasp)                                fun->u.n.clasp)
127  #define FUN_TRCINFO(fun)     (JS_ASSERT(!FUN_INTERPRETED(fun)),               \  #define FUN_TRCINFO(fun)     (JS_ASSERT(!FUN_INTERPRETED(fun)),               \
128                                JS_ASSERT((fun)->flags & JSFUN_TRACEABLE),      \                                JS_ASSERT((fun)->flags & JSFUN_TRCINFO),        \
129                                fun->u.n.trcinfo)                                fun->u.n.trcinfo)
130    
131  struct JSFunction {  struct JSFunction {
# Line 140  Line 140 
140              JSNative    native;   /* native method pointer or null */              JSNative    native;   /* native method pointer or null */
141              JSClass     *clasp;   /* class of objects constructed              JSClass     *clasp;   /* class of objects constructed
142                                       by this function */                                       by this function */
143              JSTraceableNative *trcinfo;  /* tracer metadata; can be first              JSNativeTraceInfo *trcinfo;
                                             element of array */  
144          } n;          } n;
145          struct {          struct {
146              uint16      nvars;    /* number of local variables */              uint16      nvars;    /* number of local variables */
# Line 162  Line 161 
161      } u;      } u;
162      JSAtom          *atom;        /* name for diagnostics and decompiling */      JSAtom          *atom;        /* name for diagnostics and decompiling */
163    
164  #ifdef __cplusplus  #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
165      bool optimizedClosure() { return FUN_KIND(this) > JSFUN_INTERPRETED; }      bool optimizedClosure() { return FUN_KIND(this) > JSFUN_INTERPRETED; }
166      bool needsWrapper()     { return FUN_NULL_CLOSURE(this) && u.i.skipmin != 0; }      bool needsWrapper()     { return FUN_NULL_CLOSURE(this) && u.i.skipmin != 0; }
167    
# Line 180  Line 179 
179          JS_ASSERT(FUN_INTERPRETED(this));          JS_ASSERT(FUN_INTERPRETED(this));
180          return countLocalNames() != 0;          return countLocalNames() != 0;
181      }      }
182  #endif  
183        uint32 countInterpretedReservedSlots() const;
184    #endif /* __cplusplus */
185  };  };
186    
187  /*  /*
188   * Traceable native.  This expands to a JSFunctionSpec initializer (like JS_FN   * Trace-annotated native. This expands to a JSFunctionSpec initializer (like
189   * in jsapi.h).  fastcall is a JSFastNative; trcinfo is a JSTraceableNative *.   * JS_FN in jsapi.h). fastcall is a JSFastNative; trcinfo is a
190     * JSNativeTraceInfo*.
191   */   */
192  #ifdef JS_TRACER  #ifdef JS_TRACER
193  /* MSVC demands the intermediate (void *) cast here. */  /* MSVC demands the intermediate (void *) cast here. */
194  # define JS_TN(name,fastcall,nargs,flags,trcinfo)                             \  # define JS_TN(name,fastcall,nargs,flags,trcinfo)                             \
195      JS_FN(name, JS_DATA_TO_FUNC_PTR(JSNative, trcinfo), nargs,                \      JS_FN(name, JS_DATA_TO_FUNC_PTR(JSNative, trcinfo), nargs,                \
196            (flags) | JSFUN_FAST_NATIVE | JSFUN_STUB_GSOPS | JSFUN_TRACEABLE)            (flags) | JSFUN_FAST_NATIVE | JSFUN_STUB_GSOPS | JSFUN_TRCINFO)
197  #else  #else
198  # define JS_TN(name,fastcall,nargs,flags,trcinfo)                             \  # define JS_TN(name,fastcall,nargs,flags,trcinfo)                             \
199      JS_FN(name, fastcall, nargs, flags)      JS_FN(name, fastcall, nargs, flags)
# Line 218  Line 220 
220   */   */
221  #define GET_FUNCTION_PRIVATE(cx, funobj)                                      \  #define GET_FUNCTION_PRIVATE(cx, funobj)                                      \
222      (JS_ASSERT(HAS_FUNCTION_CLASS(funobj)),                                   \      (JS_ASSERT(HAS_FUNCTION_CLASS(funobj)),                                   \
223       (JSFunction *) OBJ_GET_PRIVATE(cx, funobj))       (JSFunction *) (funobj)->getPrivate())
224    
225    struct js_ArgsPrivateNative;
226    
227    #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
228    inline js_ArgsPrivateNative *
229    js_GetArgsPrivateNative(JSObject *argsobj)
230    {
231        JS_ASSERT(STOBJ_GET_CLASS(argsobj) == &js_ArgumentsClass);
232        uintptr_t p = (uintptr_t) argsobj->getPrivate();
233        return (js_ArgsPrivateNative *) (p & 2 ? p & ~2 : NULL);
234    }
235    #endif
236    
237  extern JSObject *  extern JSObject *
238  js_InitFunctionClass(JSContext *cx, JSObject *obj);  js_InitFunctionClass(JSContext *cx, JSObject *obj);
# Line 273  Line 287 
287  extern JSObject *  extern JSObject *
288  js_GetCallObject(JSContext *cx, JSStackFrame *fp);  js_GetCallObject(JSContext *cx, JSStackFrame *fp);
289    
290  extern JS_FRIEND_API(JSBool)  #ifdef OJI
291    JS_EXTERN_API(void)
292    #else
293    extern void
294    #endif
295  js_PutCallObject(JSContext *cx, JSStackFrame *fp);  js_PutCallObject(JSContext *cx, JSStackFrame *fp);
296    
297    extern JSFunction *
298    js_GetCallObjectFunction(JSObject *obj);
299    
300  extern JSBool  extern JSBool
301  js_GetCallArg(JSContext *cx, JSObject *obj, jsid id, jsval *vp);  js_GetCallArg(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
302    
303  extern JS_REQUIRES_STACK JSBool  extern JSBool
304  js_GetCallVar(JSContext *cx, JSObject *obj, jsval id, jsval *vp);  js_GetCallVar(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
305    
306    extern JSBool
307    SetCallArg(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
308    
309    extern JSBool
310    SetCallVar(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
311    
312    /*
313     * js_SetCallArg and js_SetCallVar are extern fastcall copies of the setter
314     * functions. These versions are required in order to set call vars from traces.
315     * The normal versions must not be fastcall because they are stored in the
316     * property ops map.
317     */
318    extern JSBool JS_FASTCALL
319    js_SetCallArg(JSContext *cx, JSObject *obj, jsid id, jsval v);
320    
321    extern JSBool JS_FASTCALL
322    js_SetCallVar(JSContext *cx, JSObject *obj, jsid id, jsval v);
323    
324  /*  /*
325   * Slower version of js_GetCallVar used when call_resolve detects an attempt to   * Slower version of js_GetCallVar used when call_resolve detects an attempt to
326   * leak an optimized closure via indirect or debugger eval.   * leak an optimized closure via indirect or debugger eval.
327   */   */
328  extern JS_REQUIRES_STACK JSBool  extern JSBool
329  js_GetCallVarChecked(JSContext *cx, JSObject *obj, jsid id, jsval *vp);  js_GetCallVarChecked(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
330    
331  extern JSBool  extern JSBool
# Line 295  Line 334 
334  extern JSBool  extern JSBool
335  js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, jsval *vp);  js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, jsval *vp);
336    
337    #ifdef OJI
338    JS_EXTERN_API(JSObject *)
339    #else
340  extern JSObject *  extern JSObject *
341    #endif
342  js_GetArgsObject(JSContext *cx, JSStackFrame *fp);  js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
343    
344  extern JS_FRIEND_API(JSBool)  #ifdef OJI
345    JS_EXTERN_API(void)
346    #else
347    extern void
348    #endif
349  js_PutArgsObject(JSContext *cx, JSStackFrame *fp);  js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
350    
351    /*
352     * Reserved slot structure for Arguments objects:
353     *
354     * JSSLOT_PRIVATE       - the corresponding frame until the frame exits.
355     * JSSLOT_ARGS_LENGTH   - the number of actual arguments and a flag indicating
356     *                        whether arguments.length was overwritten.
357     * JSSLOT_ARGS_CALLEE   - the arguments.callee value or JSVAL_HOLE if that was
358     *                        overwritten.
359     * JSSLOT_ARGS_COPY_START .. - room to store the corresponding arguments after
360     *                        the frame exists. The slot's value will be JSVAL_HOLE
361     *                        if arguments[i] was deleted or overwritten.
362     */
363    const uint32 JSSLOT_ARGS_LENGTH =               JSSLOT_PRIVATE + 1;
364    const uint32 JSSLOT_ARGS_CALLEE =               JSSLOT_PRIVATE + 2;
365    const uint32 JSSLOT_ARGS_COPY_START =           JSSLOT_PRIVATE + 3;
366    
367    /* Number of extra fixed slots besides JSSLOT_PRIVATE. */
368    const uint32 ARGS_CLASS_FIXED_RESERVED_SLOTS =  JSSLOT_ARGS_COPY_START -
369                                                    JSSLOT_ARGS_LENGTH;
370    
371    /*
372     * JSSLOT_ARGS_LENGTH stores ((argc << 1) | overwritten_flag) as int jsval.
373     * Thus (JS_ARGS_LENGTH_MAX << 1) | 1 must fit JSVAL_INT_MAX. To assert that
374     * we check first that the shift does not overflow uint32.
375     */
376    JS_STATIC_ASSERT(JS_ARGS_LENGTH_MAX <= JS_BIT(30));
377    JS_STATIC_ASSERT(jsval((JS_ARGS_LENGTH_MAX << 1) | 1) <= JSVAL_INT_MAX);
378    
379    JS_INLINE bool
380    js_IsOverriddenArgsLength(JSObject *obj)
381    {
382        JS_ASSERT(STOBJ_GET_CLASS(obj) == &js_ArgumentsClass);
383    
384        jsval v = obj->fslots[JSSLOT_ARGS_LENGTH];
385        return (JSVAL_TO_INT(v) & 1) != 0;
386    }
387    
388  extern JSBool  extern JSBool
389  js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp);  js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp);
390    
# Line 342  Line 426 
426   * If nameWord does not name a formal parameter, use JS_LOCAL_NAME_IS_CONST to   * If nameWord does not name a formal parameter, use JS_LOCAL_NAME_IS_CONST to
427   * check if nameWord corresponds to the const declaration.   * check if nameWord corresponds to the const declaration.
428   */   */
429  extern jsuword *  extern JS_FRIEND_API(jsuword *)
430  js_GetLocalNameArray(JSContext *cx, JSFunction *fun, struct JSArenaPool *pool);  js_GetLocalNameArray(JSContext *cx, JSFunction *fun, struct JSArenaPool *pool);
431    
432  #define JS_LOCAL_NAME_TO_ATOM(nameWord)                                       \  #define JS_LOCAL_NAME_TO_ATOM(nameWord)                                       \
# Line 354  Line 438 
438  extern void  extern void
439  js_FreezeLocalNames(JSContext *cx, JSFunction *fun);  js_FreezeLocalNames(JSContext *cx, JSFunction *fun);
440    
441  extern JS_REQUIRES_STACK JSBool  extern JSBool
442  js_fun_apply(JSContext *cx, uintN argc, jsval *vp);  js_fun_apply(JSContext *cx, uintN argc, jsval *vp);
443    
444  extern JS_REQUIRES_STACK JSBool  extern JSBool
445  js_fun_call(JSContext *cx, uintN argc, jsval *vp);  js_fun_call(JSContext *cx, uintN argc, jsval *vp);
446    
447    

Legend:
Removed from v.460  
changed lines
  Added in v.507

  ViewVC Help
Powered by ViewVC 1.1.24