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

Diff of /trunk/js/jsobj.h

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

revision 459 by siliconforks, Tue Dec 9 03:37:47 2008 UTC revision 460 by siliconforks, Sat Sep 26 23:15:22 2009 UTC
# Line 54  Line 54 
54    
55  JS_BEGIN_EXTERN_C  JS_BEGIN_EXTERN_C
56    
57    /* For detailed comments on these function pointer types, see jsprvtd.h. */
58    struct JSObjectOps {
59        /*
60         * Custom shared object map for non-native objects. For native objects
61         * this should be null indicating, that JSObject.map is an instance of
62         * JSScope.
63         */
64        const JSObjectMap   *objectMap;
65    
66        /* Mandatory non-null function pointer members. */
67        JSLookupPropOp      lookupProperty;
68        JSDefinePropOp      defineProperty;
69        JSPropertyIdOp      getProperty;
70        JSPropertyIdOp      setProperty;
71        JSAttributesOp      getAttributes;
72        JSAttributesOp      setAttributes;
73        JSPropertyIdOp      deleteProperty;
74        JSConvertOp         defaultValue;
75        JSNewEnumerateOp    enumerate;
76        JSCheckAccessIdOp   checkAccess;
77    
78        /* Optionally non-null members start here. */
79        JSObjectOp          thisObject;
80        JSPropertyRefOp     dropProperty;
81        JSNative            call;
82        JSNative            construct;
83        JSHasInstanceOp     hasInstance;
84        JSTraceOp           trace;
85        JSFinalizeOp        clear;
86        JSGetRequiredSlotOp getRequiredSlot;
87        JSSetRequiredSlotOp setRequiredSlot;
88    };
89    
90  struct JSObjectMap {  struct JSObjectMap {
     jsrefcount  nrefs;          /* count of all referencing objects */  
91      JSObjectOps *ops;           /* high level object operation vtable */      JSObjectOps *ops;           /* high level object operation vtable */
     uint32      freeslot;       /* index of next free slot in object */  
92  };  };
93    
94  /* Shorthand macros for frequently-made calls. */  /* Shorthand macros for frequently-made calls. */
# Line 123  Line 154 
154  #define JS_INITIAL_NSLOTS   5  #define JS_INITIAL_NSLOTS   5
155    
156  /*  /*
157   * When JSObject.dslots is not null, JSObject.dslots[-1] records the number of   * JSObject struct, with members sized to fit in 32 bytes on 32-bit targets,
158   * available slots.   * 64 bytes on 64-bit systems. The JSFunction struct is an extension of this
159     * struct allocated from a larger GC size-class.
160     *
161     * The classword member stores the JSClass pointer for this object, with the
162     * least two bits encoding whether this object is a "delegate" or a "system"
163     * object.
164     *
165     * An object is a delegate if it is on another object's prototype (linked by
166     * JSSLOT_PROTO) or scope (JSSLOT_PARENT) chain, and therefore the delegate
167     * might be asked implicitly to get or set a property on behalf of another
168     * object. Delegates may be accessed directly too, as may any object, but only
169     * those objects linked after the head of any prototype or scope chain are
170     * flagged as delegates. This definition helps to optimize shape-based property
171     * cache invalidation (see Purge{Scope,Proto}Chain in jsobj.cpp).
172     *
173     * The meaning of the system object bit is defined by the API client. It is
174     * set in JS_NewSystemObject and is queried by JS_IsSystemObject (jsdbgapi.h),
175     * but it has no intrinsic meaning to SpiderMonkey. Further, JSFILENAME_SYSTEM
176     * and JS_FlagScriptFilenamePrefix (also exported via jsdbgapi.h) are intended
177     * to be complementary to this bit, but it is up to the API client to implement
178     * any such association.
179     *
180     * Both these classword tag bits are initially zero; they may be set or queried
181     * using the STOBJ_(IS|SET)_(DELEGATE|SYSTEM) macros.
182     *
183     * The dslots member is null or a pointer into a dynamically allocated vector
184     * of jsvals for reserved and dynamic slots. If dslots is not null, dslots[-1]
185     * records the number of available slots.
186   */   */
187  struct JSObject {  struct JSObject {
188      JSObjectMap *map;      JSObjectMap *map;                       /* propery map, see jsscope.h */
189      jsuword     classword;      jsuword     classword;                  /* classword, see above */
190      jsval       fslots[JS_INITIAL_NSLOTS];      jsval       fslots[JS_INITIAL_NSLOTS];  /* small number of fixed slots */
191      jsval       *dslots;        /* dynamically allocated slots */      jsval       *dslots;                    /* dynamically allocated slots */
192  };  };
193    
194  #define JSSLOT_PROTO        0  #define JSSLOT_PROTO        0
# Line 144  Line 202 
202                               + JSCLASS_RESERVED_SLOTS(clasp))                               + JSCLASS_RESERVED_SLOTS(clasp))
203    
204  /*  /*
205     * Maximum net gross capacity of the obj->dslots vector, excluding the additional
206     * hidden slot used to store the length of the vector.
207     */
208    #define MAX_DSLOTS_LENGTH   (JS_MAX(~(uint32)0, ~(size_t)0) / sizeof(jsval))
209    
210    /*
211   * STOBJ prefix means Single Threaded Object. Use the following fast macros to   * STOBJ prefix means Single Threaded Object. Use the following fast macros to
212   * directly manipulate slots in obj when only one thread can access obj and   * directly manipulate slots in obj when only one thread can access obj, or
213   * when obj->map->freeslot can be inconsistent with slots.   * when accessing read-only slots within JS_INITIAL_NSLOTS.
214   */   */
215    
216  #define STOBJ_NSLOTS(obj)                                                     \  #define STOBJ_NSLOTS(obj)                                                     \
# Line 185  Line 249 
249   * flags in the two least significant bits. We do *not* synchronize updates of   * flags in the two least significant bits. We do *not* synchronize updates of
250   * obj->classword -- API clients must take care.   * obj->classword -- API clients must take care.
251   */   */
252  #define STOBJ_GET_CLASS(obj)    ((JSClass *)((obj)->classword & ~3))  #define JSSLOT_CLASS_MASK_BITS 3
253    
254    static JS_ALWAYS_INLINE JSClass*
255    STOBJ_GET_CLASS(const JSObject* obj)
256    {
257        return (JSClass *) (obj->classword & ~JSSLOT_CLASS_MASK_BITS);
258    }
259    
260  #define STOBJ_IS_DELEGATE(obj)  (((obj)->classword & 1) != 0)  #define STOBJ_IS_DELEGATE(obj)  (((obj)->classword & 1) != 0)
261  #define STOBJ_SET_DELEGATE(obj) ((obj)->classword |= 1)  #define STOBJ_SET_DELEGATE(obj) ((obj)->classword |= 1)
262  #define STOBJ_NULLSAFE_SET_DELEGATE(obj)                                      \  #define STOBJ_NULLSAFE_SET_DELEGATE(obj)                                      \
# Line 198  Line 269 
269       JSVAL_TO_PRIVATE(STOBJ_GET_SLOT(obj, JSSLOT_PRIVATE)))       JSVAL_TO_PRIVATE(STOBJ_GET_SLOT(obj, JSSLOT_PRIVATE)))
270    
271  #define OBJ_CHECK_SLOT(obj,slot)                                              \  #define OBJ_CHECK_SLOT(obj,slot)                                              \
272      JS_ASSERT(slot < (obj)->map->freeslot)      JS_ASSERT_IF(OBJ_IS_NATIVE(obj), slot < OBJ_SCOPE(obj)->freeslot)
273    
274  #define LOCKED_OBJ_GET_SLOT(obj,slot)                                         \  #define LOCKED_OBJ_GET_SLOT(obj,slot)                                         \
275      (OBJ_CHECK_SLOT(obj, slot), STOBJ_GET_SLOT(obj, slot))      (OBJ_CHECK_SLOT(obj, slot), STOBJ_GET_SLOT(obj, slot))
# Line 300  Line 371 
371  #define OBJ_GET_CLASS(cx,obj)           STOBJ_GET_CLASS(obj)  #define OBJ_GET_CLASS(cx,obj)           STOBJ_GET_CLASS(obj)
372  #define OBJ_GET_PRIVATE(cx,obj)         STOBJ_GET_PRIVATE(obj)  #define OBJ_GET_PRIVATE(cx,obj)         STOBJ_GET_PRIVATE(obj)
373    
374  /* Test whether a map or object is native. */  /*
375  #define MAP_IS_NATIVE(map)                                                    \   * Test whether the object is native. FIXME bug 492938: consider how it would
376      JS_LIKELY((map)->ops == &js_ObjectOps ||                                  \   * affect the performance to do just the !ops->objectMap check.
377                (map)->ops->newObjectMap == js_ObjectOps.newObjectMap)   */
378    #define OPS_IS_NATIVE(ops)                                                    \
379        JS_LIKELY((ops) == &js_ObjectOps || !(ops)->objectMap)
380    
381  #define OBJ_IS_NATIVE(obj)  MAP_IS_NATIVE((obj)->map)  #define OBJ_IS_NATIVE(obj)  OPS_IS_NATIVE((obj)->map->ops)
382    
383  extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps;  extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps;
384  extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps;  extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps;
# Line 347  Line 420 
420   * When popping the stack across this object's "with" statement, client code   * When popping the stack across this object's "with" statement, client code
421   * must call JS_SetPrivate(cx, withobj, NULL).   * must call JS_SetPrivate(cx, withobj, NULL).
422   */   */
423  extern JSObject *  extern JS_REQUIRES_STACK JSObject *
424  js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth);  js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth);
425    
426  /*  /*
# Line 363  Line 436 
436  js_CloneBlockObject(JSContext *cx, JSObject *proto, JSObject *parent,  js_CloneBlockObject(JSContext *cx, JSObject *proto, JSObject *parent,
437                      JSStackFrame *fp);                      JSStackFrame *fp);
438    
439  extern JSBool  extern JS_REQUIRES_STACK JSBool
440  js_PutBlockObject(JSContext *cx, JSBool normalUnwind);  js_PutBlockObject(JSContext *cx, JSBool normalUnwind);
441    
442    JSBool
443    js_XDRBlockObject(JSXDRState *xdr, JSObject **objp);
444    
445  struct JSSharpObjectMap {  struct JSSharpObjectMap {
446      jsrefcount  depth;      jsrefcount  depth;
447      jsatomid    sharpgen;      jsatomid    sharpgen;
# Line 407  Line 483 
483  js_PropertyIsEnumerable(JSContext *cx, JSObject *obj, jsid id, jsval *vp);  js_PropertyIsEnumerable(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
484    
485  extern JSObject *  extern JSObject *
 js_InitBlockClass(JSContext *cx, JSObject* obj);  
   
 extern JSObject *  
486  js_InitEval(JSContext *cx, JSObject *obj);  js_InitEval(JSContext *cx, JSObject *obj);
487    
488  extern JSObject *  extern JSObject *
489  js_InitObjectClass(JSContext *cx, JSObject *obj);  js_InitObjectClass(JSContext *cx, JSObject *obj);
490    
491  /* Select Object.prototype method names shared between jsapi.c and jsobj.c. */  extern JSObject *
492    js_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
493                 JSClass *clasp, JSNative constructor, uintN nargs,
494                 JSPropertySpec *ps, JSFunctionSpec *fs,
495                 JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
496    
497    /*
498     * Select Object.prototype method names shared between jsapi.cpp and jsobj.cpp.
499     */
500  extern const char js_watch_str[];  extern const char js_watch_str[];
501  extern const char js_unwatch_str[];  extern const char js_unwatch_str[];
502  extern const char js_hasOwnProperty_str[];  extern const char js_hasOwnProperty_str[];
# Line 426  Line 507 
507  extern const char js_lookupGetter_str[];  extern const char js_lookupGetter_str[];
508  extern const char js_lookupSetter_str[];  extern const char js_lookupSetter_str[];
509    
 extern void  
 js_InitObjectMap(JSObjectMap *map, jsrefcount nrefs, JSObjectOps *ops,  
                  JSClass *clasp);  
   
 extern JSObjectMap *  
 js_NewObjectMap(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops,  
                 JSClass *clasp, JSObject *obj);  
   
 extern void  
 js_DestroyObjectMap(JSContext *cx, JSObjectMap *map);  
   
 extern JSObjectMap *  
 js_HoldObjectMap(JSContext *cx, JSObjectMap *map);  
   
 extern JSObjectMap *  
 js_DropObjectMap(JSContext *cx, JSObjectMap *map, JSObject *obj);  
   
510  extern JSBool  extern JSBool
511  js_GetClassId(JSContext *cx, JSClass *clasp, jsid *idp);  js_GetClassId(JSContext *cx, JSClass *clasp, jsid *idp);
512    
# Line 461  Line 525 
525                             JSObject *parent, uintN objectSize);                             JSObject *parent, uintN objectSize);
526    
527  /*  /*
528     * Allocate a new native object and initialize all fslots with JSVAL_VOID
529     * starting with the specified slot. The parent slot is set to the value of
530     * proto's parent slot.
531     *
532     * Note that this is the correct global object for native class instances, but
533     * not for user-defined functions called as constructors.  Functions used as
534     * constructors must create instances parented by the parent of the function
535     * object, not by the parent of its .prototype object value.
536     */
537    extern JSObject*
538    js_NewNativeObject(JSContext *cx, JSClass *clasp, JSObject *proto, uint32 slot);
539    
540    /*
541   * Fast access to immutable standard objects (constructors and prototypes).   * Fast access to immutable standard objects (constructors and prototypes).
542   */   */
543  extern JSBool  extern JSBool
# Line 489  Line 566 
566  /* JSVAL_INT_MAX as a string */  /* JSVAL_INT_MAX as a string */
567  #define JSVAL_INT_MAX_STRING "1073741823"  #define JSVAL_INT_MAX_STRING "1073741823"
568    
569    /*
570     * Convert string indexes that convert to int jsvals as ints to save memory.
571     * Care must be taken to use this macro every time a property name is used, or
572     * else double-sets, incorrect property cache misses, or other mistakes could
573     * occur.
574     */
575  #define CHECK_FOR_STRING_INDEX(id)                                            \  #define CHECK_FOR_STRING_INDEX(id)                                            \
576      JS_BEGIN_MACRO                                                            \      JS_BEGIN_MACRO                                                            \
577          if (JSID_IS_ATOM(id)) {                                               \          if (JSID_IS_ATOM(id)) {                                               \
# Line 510  Line 593 
593                         JSBool negative);                         JSBool negative);
594    
595  /*  /*
596     * js_PurgeScopeChain does nothing if obj is not itself a prototype or parent
597     * scope, else it reshapes the scope and prototype chains it links. It calls
598     * js_PurgeScopeChainHelper, which asserts that obj is flagged as a delegate
599     * (i.e., obj has ever been on a prototype or parent chain).
600     */
601    extern void
602    js_PurgeScopeChainHelper(JSContext *cx, JSObject *obj, jsid id);
603    
604    #ifdef __cplusplus /* Aargh, libgjs, bug 492720. */
605    static JS_INLINE void
606    js_PurgeScopeChain(JSContext *cx, JSObject *obj, jsid id)
607    {
608        if (OBJ_IS_DELEGATE(cx, obj))
609            js_PurgeScopeChainHelper(cx, obj, id);
610    }
611    #endif
612    
613    /*
614   * Find or create a property named by id in obj's scope, with the given getter   * Find or create a property named by id in obj's scope, with the given getter
615   * and setter, slot, attributes, and other members.   * and setter, slot, attributes, and other members.
616   */   */
# Line 540  Line 641 
641                    JSPropertyOp getter, JSPropertyOp setter, uintN attrs,                    JSPropertyOp getter, JSPropertyOp setter, uintN attrs,
642                    JSProperty **propp);                    JSProperty **propp);
643    
644    #ifdef __cplusplus /* FIXME: bug 442399 removes this LiveConnect requirement. */
645    
646    /*
647     * Flags for the defineHow parameter of js_DefineNativeProperty.
648     */
649    const uintN JSDNP_CACHE_RESULT = 1; /* an interpreter call from JSOP_INITPROP */
650    const uintN JSDNP_DONT_PURGE   = 2; /* suppress js_PurgeScopeChain */
651    
652  extern JSBool  extern JSBool
653  js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,  js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
654                          JSPropertyOp getter, JSPropertyOp setter, uintN attrs,                          JSPropertyOp getter, JSPropertyOp setter, uintN attrs,
655                          uintN flags, intN shortid, JSProperty **propp);                          uintN flags, intN shortid, JSProperty **propp,
656                            uintN defineHow = 0);
657    #endif
658    
659  /*  /*
660   * Unlike js_DefineProperty, propp must be non-null. On success, and if id was   * Unlike js_DefineProperty, propp must be non-null. On success, and if id was
# Line 565  Line 676 
676  js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,  js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,
677                             JSObject **objp, JSProperty **propp);                             JSObject **objp, JSProperty **propp);
678    
679  extern int  /*
680  js_FindPropertyHelper(JSContext *cx, jsid id, JSObject **objp,   * If cacheResult is false, return JS_NO_PROP_CACHE_FILL on success.
681                        JSObject **pobjp, JSProperty **propp,   */
682                        JSPropCacheEntry **entryp);  extern JSPropCacheEntry *
683    js_FindPropertyHelper(JSContext *cx, jsid id, JSBool cacheResult,
684                          JSObject **objp, JSObject **pobjp, JSProperty **propp);
685    
686  /*  /*
687   * Return the index along the scope chain in which id was found, or the last   * Return the index along the scope chain in which id was found, or the last
# Line 578  Line 691 
691  js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,  js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
692                  JSProperty **propp);                  JSProperty **propp);
693    
694  extern JSObject *  extern JS_REQUIRES_STACK JSObject *
695  js_FindIdentifierBase(JSContext *cx, jsid id, JSPropCacheEntry *entry);  js_FindIdentifierBase(JSContext *cx, JSObject *scopeChain, jsid id);
696    
697  extern JSObject *  extern JSObject *
698  js_FindVariableScope(JSContext *cx, JSFunction **funp);  js_FindVariableScope(JSContext *cx, JSFunction **funp);
# Line 598  Line 711 
711  js_NativeSet(JSContext *cx, JSObject *obj, JSScopeProperty *sprop, jsval *vp);  js_NativeSet(JSContext *cx, JSObject *obj, JSScopeProperty *sprop, jsval *vp);
712    
713  extern JSBool  extern JSBool
714  js_GetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, jsval *vp,  js_GetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, JSBool cacheResult,
715                       JSPropCacheEntry **entryp);                       jsval *vp);
716    
717  extern JSBool  extern JSBool
718  js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);  js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
719    
720  extern JSBool  extern JSBool
721  js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, jsval *vp,  js_GetMethod(JSContext *cx, JSObject *obj, jsid id, JSBool cacheResult,
722                       JSPropCacheEntry **entryp);               jsval *vp);
723    
724    /*
725     * Check whether it is OK to assign an undeclared property of the global
726     * object at the current script PC.
727     */
728    extern JS_FRIEND_API(JSBool)
729    js_CheckUndeclaredVarAssignment(JSContext *cx);
730    
731    extern JSBool
732    js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, JSBool cacheResult,
733                         jsval *vp);
734    
735  extern JSBool  extern JSBool
736  js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);  js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
# Line 647  Line 771 
771  js_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);  js_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
772    
773  extern JSBool  extern JSBool
774  js_SetProtoOrParent(JSContext *cx, JSObject *obj, uint32 slot, JSObject *pobj);  js_SetProtoOrParent(JSContext *cx, JSObject *obj, uint32 slot, JSObject *pobj,
775                        JSBool checkForCycles);
776    
777  extern JSBool  extern JSBool
778  js_IsDelegate(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);  js_IsDelegate(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
# Line 721  Line 846 
846  js_ComputeFilename(JSContext *cx, JSStackFrame *caller,  js_ComputeFilename(JSContext *cx, JSStackFrame *caller,
847                     JSPrincipals *principals, uintN *linenop);                     JSPrincipals *principals, uintN *linenop);
848    
849    /* Infallible, therefore cx is last parameter instead of first. */
850    extern JSBool
851    js_IsCallable(JSObject *obj, JSContext *cx);
852    
853    void
854    js_ReportGetterOnlyAssignment(JSContext *cx);
855    
856    extern JS_FRIEND_API(JSBool)
857    js_GetterOnlyPropertyStub(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
858    
859  #ifdef DEBUG  #ifdef DEBUG
860  JS_FRIEND_API(void) js_DumpChars(const jschar *s, size_t n);  JS_FRIEND_API(void) js_DumpChars(const jschar *s, size_t n);
861  JS_FRIEND_API(void) js_DumpString(JSString *str);  JS_FRIEND_API(void) js_DumpString(JSString *str);

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

  ViewVC Help
Powered by ViewVC 1.1.24