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

Diff of /trunk/js/jsarray.h

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

revision 332 by siliconforks, Thu Oct 23 19:03:33 2008 UTC revision 460 by siliconforks, Sat Sep 26 23:15:22 2009 UTC
# Line 44  Line 44 
44   */   */
45  #include "jsprvtd.h"  #include "jsprvtd.h"
46  #include "jspubtd.h"  #include "jspubtd.h"
47    #include "jsobj.h"
48    
49  JS_BEGIN_EXTERN_C  JS_BEGIN_EXTERN_C
50    
51    #define ARRAY_CAPACITY_MIN      7
52    
53  /* Generous sanity-bound on length (in elements) of array initialiser. */  /* Generous sanity-bound on length (in elements) of array initialiser. */
54  #define ARRAY_INIT_LIMIT        JS_BIT(24)  #define ARRAY_INIT_LIMIT        JS_BIT(24)
55    
# Line 60  Line 63 
63  #define OBJ_IS_ARRAY(cx,obj)    (OBJ_IS_DENSE_ARRAY(cx, obj) ||               \  #define OBJ_IS_ARRAY(cx,obj)    (OBJ_IS_DENSE_ARRAY(cx, obj) ||               \
64                                   OBJ_GET_CLASS(cx, obj) == &js_SlowArrayClass)                                   OBJ_GET_CLASS(cx, obj) == &js_SlowArrayClass)
65    
66    /*
67     * Dense arrays are not native (OBJ_IS_NATIVE(cx, aobj) for a dense array aobj
68     * results in false, meaning aobj->map does not point to a JSScope).
69     *
70     * But Array methods are called via aobj.sort(), e.g., and the interpreter and
71     * the trace recorder must consult the property cache in order to perform well.
72     * The cache works only for native objects.
73     *
74     * Therefore the interpreter (js_Interpret in JSOP_GETPROP and JSOP_CALLPROP)
75     * and js_GetPropertyHelper use this inline function to skip up one link in the
76     * prototype chain when obj is a dense array, in order to find a native object
77     * (to wit, Array.prototype) in which to probe for cached methods.
78     *
79     * Note that setting aobj.__proto__ for a dense array aobj turns aobj into a
80     * slow array, avoiding the neede to skip.
81     *
82     * Callers of js_GetProtoIfDenseArray must take care to use the original object
83     * (obj) for the |this| value of a getter, setter, or method call (bug 476447).
84     */
85    static JS_INLINE JSObject *
86    js_GetProtoIfDenseArray(JSContext *cx, JSObject *obj)
87    {
88        return OBJ_IS_DENSE_ARRAY(cx, obj) ? OBJ_GET_PROTO(cx, obj) : obj;
89    }
90    
91  extern JSObject *  extern JSObject *
92  js_InitArrayClass(JSContext *cx, JSObject *obj);  js_InitArrayClass(JSContext *cx, JSObject *obj);
93    
# Line 76  Line 104 
104    
105  #define JSSLOT_ARRAY_LENGTH            JSSLOT_PRIVATE  #define JSSLOT_ARRAY_LENGTH            JSSLOT_PRIVATE
106  #define JSSLOT_ARRAY_COUNT             (JSSLOT_ARRAY_LENGTH + 1)  #define JSSLOT_ARRAY_COUNT             (JSSLOT_ARRAY_LENGTH + 1)
107  #define JSSLOT_ARRAY_LOOKUP_HOLDER     (JSSLOT_ARRAY_COUNT + 1)  #define JSSLOT_ARRAY_UNUSED            (JSSLOT_ARRAY_COUNT + 1)
108    
109  #define ARRAY_DENSE_LENGTH(obj)                                                \  static JS_INLINE uint32
110      (JS_ASSERT(OBJ_IS_DENSE_ARRAY(cx, obj)),                                   \  js_DenseArrayCapacity(JSObject *obj)
111       (obj)->dslots ? (uint32)(obj)->dslots[-1] : 0)  {
112        JS_ASSERT(OBJ_IS_DENSE_ARRAY(BOGUS_CX, obj));
113  #define ARRAY_SET_DENSE_LENGTH(obj, max)                                       \      return obj->dslots ? (uint32) obj->dslots[-1] : 0;
114      (JS_ASSERT((obj)->dslots), (obj)->dslots[-1] = (jsval)(max))  }
115    
116  #define ARRAY_GROWBY 8  static JS_INLINE void
117    js_SetDenseArrayCapacity(JSObject *obj, uint32 capacity)
118    {
119        JS_ASSERT(OBJ_IS_DENSE_ARRAY(BOGUS_CX, obj));
120        JS_ASSERT(obj->dslots);
121        obj->dslots[-1] = (jsval) capacity;
122    }
123    
124  extern JSBool  extern JSBool
125  js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);  js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
126    
127  extern JSBool  extern JSBool
128  js_SetLengthProperty(JSContext *cx, JSObject *obj, jsuint length);  js_SetLengthProperty(JSContext *cx, JSObject *obj, jsdouble length);
129    
130  extern JSBool  extern JSBool
131  js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);  js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
# Line 122  Line 156 
156   * comparator function cmp returns an error inside a comparison, so remember   * comparator function cmp returns an error inside a comparison, so remember
157   * to check the return value of this function.   * to check the return value of this function.
158   */   */
159  extern JSBool  extern JS_REQUIRES_STACK JSBool
160  js_MergeSort(void *vec, size_t nel, size_t elsize, JSComparator cmp,  js_MergeSort(void *vec, size_t nel, size_t elsize, JSComparator cmp,
161               void *arg, void *tmp);               void *arg, void *tmp);
162    
# Line 131  Line 165 
165  js_ArrayInfo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);  js_ArrayInfo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
166  #endif  #endif
167    
168  extern JSBool  extern JSBool JS_FASTCALL
169  js_array_join(JSContext *cx, uintN argc, jsval *vp);  js_ArrayCompPush(JSContext *cx, JSObject *obj, jsval v);
   
 extern JSBool  
 js_array_push_slowly(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);  
   
 extern JSBool  
 js_array_push1_dense(JSContext *cx, JSObject *obj, jsval v, jsval *rval);  
   
 extern JSBool  
 js_array_push(JSContext *cx, uintN argc, jsval *vp);  
   
 extern JSBool  
 js_array_pop_slowly(JSContext *cx, JSObject* obj, jsval *vp);  
   
 extern JSBool  
 js_array_pop_dense(JSContext *cx, JSObject* obj, jsval *vp);  
   
 extern JSBool  
 js_array_pop(JSContext *cx, uintN argc, jsval *vp);  
   
 enum ArrayToStringOp {  
     TO_STRING,  
     TO_LOCALE_STRING,  
     TO_SOURCE  
 };  
   
 extern JSBool  
 js_array_join_sub(JSContext *cx, JSObject *obj, enum ArrayToStringOp op,  
                   JSString *sep, jsval *rval);  
170    
171  /*  /*
172   * Fast dense-array-to-buffer conversions.   * Fast dense-array-to-buffer conversions.
# Line 217  Line 223 
223  js_ArrayToJSDoubleBuffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  js_ArrayToJSDoubleBuffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
224                           jsdouble *dest);                           jsdouble *dest);
225    
226    JSBool
227    js_PrototypeHasIndexedProperties(JSContext *cx, JSObject *obj);
228    
229    /*
230     * Utility to access the value from the id returned by array_lookupProperty.
231     */
232    JSBool
233    js_GetDenseArrayElementValue(JSContext *cx, JSObject *obj, JSProperty *prop,
234                                 jsval *vp);
235    
236  JS_END_EXTERN_C  JS_END_EXTERN_C
237    
238  #endif /* jsarray_h___ */  #endif /* jsarray_h___ */

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

  ViewVC Help
Powered by ViewVC 1.1.24