/[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 507 by siliconforks, Sun Jan 10 07:23:34 2010 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  /* Generous sanity-bound on length (in elements) of array initialiser. */  #define ARRAY_CAPACITY_MIN      7
 #define ARRAY_INIT_LIMIT        JS_BIT(24)  
52    
53  extern JSBool  extern JSBool
54  js_IdIsIndex(jsval id, jsuint *indexp);  js_IdIsIndex(jsval id, jsuint *indexp);
55    
56  extern JSClass js_ArrayClass, js_SlowArrayClass;  extern JSClass js_ArrayClass, js_SlowArrayClass;
57    
58  #define OBJ_IS_DENSE_ARRAY(cx,obj)  (OBJ_GET_CLASS(cx, obj) == &js_ArrayClass)  static JS_INLINE JSBool
59    js_IsDenseArray(JSObject *obj)
60    {
61        return STOBJ_GET_CLASS(obj) == &js_ArrayClass;
62    }
63    
64    #define OBJ_IS_DENSE_ARRAY(cx, obj) js_IsDenseArray(obj)
65    
66  #define OBJ_IS_ARRAY(cx,obj)    (OBJ_IS_DENSE_ARRAY(cx, obj) ||               \  #define OBJ_IS_ARRAY(cx,obj)    (OBJ_IS_DENSE_ARRAY(cx, obj) ||               \
67                                   OBJ_GET_CLASS(cx, obj) == &js_SlowArrayClass)                                   OBJ_GET_CLASS(cx, obj) == &js_SlowArrayClass)
68    
69    /*
70     * Dense arrays are not native (OBJ_IS_NATIVE(cx, aobj) for a dense array aobj
71     * results in false, meaning aobj->map does not point to a JSScope).
72     *
73     * But Array methods are called via aobj.sort(), e.g., and the interpreter and
74     * the trace recorder must consult the property cache in order to perform well.
75     * The cache works only for native objects.
76     *
77     * Therefore the interpreter (js_Interpret in JSOP_GETPROP and JSOP_CALLPROP)
78     * and js_GetPropertyHelper use this inline function to skip up one link in the
79     * prototype chain when obj is a dense array, in order to find a native object
80     * (to wit, Array.prototype) in which to probe for cached methods.
81     *
82     * Note that setting aobj.__proto__ for a dense array aobj turns aobj into a
83     * slow array, avoiding the neede to skip.
84     *
85     * Callers of js_GetProtoIfDenseArray must take care to use the original object
86     * (obj) for the |this| value of a getter, setter, or method call (bug 476447).
87     */
88    #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
89    static JS_INLINE JSObject *
90    js_GetProtoIfDenseArray(JSContext *cx, JSObject *obj)
91    {
92        return OBJ_IS_DENSE_ARRAY(cx, obj) ? OBJ_GET_PROTO(cx, obj) : obj;
93    }
94    #endif
95    
96  extern JSObject *  extern JSObject *
97  js_InitArrayClass(JSContext *cx, JSObject *obj);  js_InitArrayClass(JSContext *cx, JSObject *obj);
98    
99    #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
100    extern bool
101    #else
102    extern JSBool
103    #endif
104    js_InitContextBusyArrayTable(JSContext *cx);
105    
106    #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
107  extern JSObject *  extern JSObject *
108  js_NewArrayObject(JSContext *cx, jsuint length, jsval *vector,  js_NewArrayObject(JSContext *cx, jsuint length, jsval *vector,
109                    JSBool holey = JS_FALSE);                    JSBool holey = JS_FALSE);
110    #else
111    extern JSObject *
112    js_NewArrayObject(JSContext *cx, jsuint length, jsval *vector,
113                      JSBool holey);
114    #endif
115    
116  /* Create an array object that starts out already made slow/sparse. */  /* Create an array object that starts out already made slow/sparse. */
117  extern JSObject *  extern JSObject *
# Line 76  Line 122 
122    
123  #define JSSLOT_ARRAY_LENGTH            JSSLOT_PRIVATE  #define JSSLOT_ARRAY_LENGTH            JSSLOT_PRIVATE
124  #define JSSLOT_ARRAY_COUNT             (JSSLOT_ARRAY_LENGTH + 1)  #define JSSLOT_ARRAY_COUNT             (JSSLOT_ARRAY_LENGTH + 1)
125  #define JSSLOT_ARRAY_LOOKUP_HOLDER     (JSSLOT_ARRAY_COUNT + 1)  #define JSSLOT_ARRAY_UNUSED            (JSSLOT_ARRAY_COUNT + 1)
126    
127  #define ARRAY_DENSE_LENGTH(obj)                                                \  static JS_INLINE uint32
128      (JS_ASSERT(OBJ_IS_DENSE_ARRAY(cx, obj)),                                   \  js_DenseArrayCapacity(JSObject *obj)
129       (obj)->dslots ? (uint32)(obj)->dslots[-1] : 0)  {
130        JS_ASSERT(js_IsDenseArray(obj));
131  #define ARRAY_SET_DENSE_LENGTH(obj, max)                                       \      return obj->dslots ? (uint32) obj->dslots[-1] : 0;
132      (JS_ASSERT((obj)->dslots), (obj)->dslots[-1] = (jsval)(max))  }
133    
134  #define ARRAY_GROWBY 8  static JS_INLINE void
135    js_SetDenseArrayCapacity(JSObject *obj, uint32 capacity)
136    {
137        JS_ASSERT(js_IsDenseArray(obj));
138        JS_ASSERT(obj->dslots);
139        obj->dslots[-1] = (jsval) capacity;
140    }
141    
142  extern JSBool  extern JSBool
143  js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);  js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
144    
145  extern JSBool  extern JSBool
146  js_SetLengthProperty(JSContext *cx, JSObject *obj, jsuint length);  js_SetLengthProperty(JSContext *cx, JSObject *obj, jsdouble length);
147    
148  extern JSBool  extern JSBool
149  js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);  js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
# Line 131  Line 183 
183  js_ArrayInfo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);  js_ArrayInfo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
184  #endif  #endif
185    
186  extern JSBool  extern JSBool JS_FASTCALL
187  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);  
188    
189  /*  /*
190   * Fast dense-array-to-buffer conversions.   * Fast dense-array-to-buffer conversion for use by canvas.
  *  
  * If the array is a dense array, fill [offset..offset+count] values  
  * into destination, assuming that types are consistent.  Return  
  * JS_TRUE if successful, otherwise JS_FALSE -- note that the  
  * destination buffer may be modified even if JS_FALSE is returned  
  * (e.g. due to finding an inappropriate type later on in the array).  
  * If JS_FALSE is returned, no error conditions or exceptions are set  
  * on the context.  
191   *   *
192   * For ArrayToJSUint8, ArrayToJSUint16, and ArrayToJSUint32, each element   * If the array is a dense array, fill [offset..offset+count] values into
193   * in the array a) must be an integer; b) must be >= 0.  Integers   * destination, assuming that types are consistent.  Return JS_TRUE if
194   * are clamped to fit in the destination size.  Only JSVAL_IS_INT values   * successful, otherwise JS_FALSE -- note that the destination buffer may be
195   * are considered to be valid, so for JSUint32, the maximum value that   * modified even if JS_FALSE is returned (e.g. due to finding an inappropriate
196   * can be fast-converted is less than the full unsigned 32-bit range.   * type later on in the array).  If JS_FALSE is returned, no error conditions
197     * or exceptions are set on the context.
198   *   *
199   * For ArrayToJSInt8, ArrayToJSInt16, ArrayToJSInt32, each element in   * This method succeeds if each element of the array is an integer or a double.
200   * the array must be an integer.  Integers are clamped to fit in the   * Values outside the 0-255 range are clamped to that range.  Double values are
201   * destination size.  Only JSVAL_IS_INT values are considered to be   * converted to integers in this range by clamping and then rounding to
202   * valid, so for JSInt32, the maximum value that can be   * nearest, ties to even.
  * fast-converted is less than the full signed 32-bit range.  
  *  
  * For ArrayToJSDouble, each element in the array must be an  
  * integer -or- a double (JSVAL_IS_NUMBER).  
203   */   */
204    
205  JS_FRIEND_API(JSBool)  JS_FRIEND_API(JSBool)
206  js_ArrayToJSUint8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  js_CoerceArrayToCanvasImageData(JSObject *obj, jsuint offset, jsuint count,
207                          JSUint8 *dest);                                  JSUint8 *dest);
   
 JS_FRIEND_API(JSBool)  
 js_ArrayToJSUint16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  
                          JSUint16 *dest);  
   
 JS_FRIEND_API(JSBool)  
 js_ArrayToJSUint32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  
                          JSUint32 *dest);  
208    
209  JS_FRIEND_API(JSBool)  JSBool
210  js_ArrayToJSInt8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  js_PrototypeHasIndexedProperties(JSContext *cx, JSObject *obj);
                        JSInt8 *dest);  
   
 JS_FRIEND_API(JSBool)  
 js_ArrayToJSInt16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  
                         JSInt16 *dest);  
211    
212  JS_FRIEND_API(JSBool)  /*
213  js_ArrayToJSInt32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,   * Utility to access the value from the id returned by array_lookupProperty.
214                          JSInt32 *dest);   */
215    JSBool
216    js_GetDenseArrayElementValue(JSContext *cx, JSObject *obj, JSProperty *prop,
217                                 jsval *vp);
218    
219    /* Array constructor native. Exposed only so the JIT can know its address. */
220    JSBool
221    js_Array(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval);
222    
223  JS_FRIEND_API(JSBool)  /*
224  js_ArrayToJSDoubleBuffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,   * Friend api function that allows direct creation of an array object with a
225                           jsdouble *dest);   * given capacity.  Non-null return value means allocation of the internal
226     * buffer for a capacity of at least |capacity| succeeded.  A pointer to the
227     * first element of this internal buffer is returned in the |vector| out
228     * parameter.  The caller promises to fill in the first |capacity| values
229     * starting from that pointer immediately after this function returns and
230     * without triggering GC (so this method is allowed to leave those
231     * uninitialized) and to set them to non-JSVAL_HOLE values, so that the
232     * resulting array has length and count both equal to |capacity|.
233     */
234    JS_FRIEND_API(JSObject *)
235    js_NewArrayObjectWithCapacity(JSContext *cx, jsuint capacity, jsval **vector);
236    
237  JS_END_EXTERN_C  JS_END_EXTERN_C
238    

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

  ViewVC Help
Powered by ViewVC 1.1.24