/[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 460 by siliconforks, Sat Sep 26 23:15:22 2009 UTC revision 507 by siliconforks, Sun Jan 10 07:23:34 2010 UTC
# Line 50  Line 50 
50    
51  #define ARRAY_CAPACITY_MIN      7  #define ARRAY_CAPACITY_MIN      7
52    
 /* Generous sanity-bound on length (in elements) of array initialiser. */  
 #define ARRAY_INIT_LIMIT        JS_BIT(24)  
   
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)
# Line 82  Line 85 
85   * Callers of js_GetProtoIfDenseArray must take care to use the original object   * 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).   * (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 *  static JS_INLINE JSObject *
90  js_GetProtoIfDenseArray(JSContext *cx, JSObject *obj)  js_GetProtoIfDenseArray(JSContext *cx, JSObject *obj)
91  {  {
92      return OBJ_IS_DENSE_ARRAY(cx, obj) ? OBJ_GET_PROTO(cx, obj) : obj;      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 109  Line 127 
127  static JS_INLINE uint32  static JS_INLINE uint32
128  js_DenseArrayCapacity(JSObject *obj)  js_DenseArrayCapacity(JSObject *obj)
129  {  {
130      JS_ASSERT(OBJ_IS_DENSE_ARRAY(BOGUS_CX, obj));      JS_ASSERT(js_IsDenseArray(obj));
131      return obj->dslots ? (uint32) obj->dslots[-1] : 0;      return obj->dslots ? (uint32) obj->dslots[-1] : 0;
132  }  }
133    
134  static JS_INLINE void  static JS_INLINE void
135  js_SetDenseArrayCapacity(JSObject *obj, uint32 capacity)  js_SetDenseArrayCapacity(JSObject *obj, uint32 capacity)
136  {  {
137      JS_ASSERT(OBJ_IS_DENSE_ARRAY(BOGUS_CX, obj));      JS_ASSERT(js_IsDenseArray(obj));
138      JS_ASSERT(obj->dslots);      JS_ASSERT(obj->dslots);
139      obj->dslots[-1] = (jsval) capacity;      obj->dslots[-1] = (jsval) capacity;
140  }  }
# Line 156  Line 174 
174   * comparator function cmp returns an error inside a comparison, so remember   * comparator function cmp returns an error inside a comparison, so remember
175   * to check the return value of this function.   * to check the return value of this function.
176   */   */
177  extern JS_REQUIRES_STACK JSBool  extern JSBool
178  js_MergeSort(void *vec, size_t nel, size_t elsize, JSComparator cmp,  js_MergeSort(void *vec, size_t nel, size_t elsize, JSComparator cmp,
179               void *arg, void *tmp);               void *arg, void *tmp);
180    
# Line 169  Line 187 
187  js_ArrayCompPush(JSContext *cx, JSObject *obj, jsval v);  js_ArrayCompPush(JSContext *cx, JSObject *obj, jsval v);
188    
189  /*  /*
190   * Fast dense-array-to-buffer conversions.   * Fast dense-array-to-buffer conversion for use by canvas.
191   *   *
192   * If the array is a dense array, fill [offset..offset+count] values   * If the array is a dense array, fill [offset..offset+count] values into
193   * into destination, assuming that types are consistent.  Return   * destination, assuming that types are consistent.  Return JS_TRUE if
194   * JS_TRUE if successful, otherwise JS_FALSE -- note that the   * successful, otherwise JS_FALSE -- note that the destination buffer may be
195   * destination buffer may be modified even if JS_FALSE is returned   * modified even if JS_FALSE is returned (e.g. due to finding an inappropriate
196   * (e.g. due to finding an inappropriate type later on in the array).   * type later on in the array).  If JS_FALSE is returned, no error conditions
197   * If JS_FALSE is returned, no error conditions or exceptions are set   * or exceptions are set on the context.
198   * on the context.   *
199   *   * This method succeeds if each element of the array is an integer or a double.
200   * For ArrayToJSUint8, ArrayToJSUint16, and ArrayToJSUint32, each element   * Values outside the 0-255 range are clamped to that range.  Double values are
201   * in the array a) must be an integer; b) must be >= 0.  Integers   * converted to integers in this range by clamping and then rounding to
202   * are clamped to fit in the destination size.  Only JSVAL_IS_INT values   * nearest, ties to even.
  * are considered to be valid, so for JSUint32, the maximum value that  
  * can be fast-converted is less than the full unsigned 32-bit range.  
  *  
  * For ArrayToJSInt8, ArrayToJSInt16, ArrayToJSInt32, each element in  
  * the array must be an integer.  Integers are clamped to fit in the  
  * destination size.  Only JSVAL_IS_INT values are considered to be  
  * valid, so for JSInt32, the maximum value that can be  
  * 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);  
   
 JS_FRIEND_API(JSBool)  
 js_ArrayToJSInt8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  
                        JSInt8 *dest);  
   
 JS_FRIEND_API(JSBool)  
 js_ArrayToJSInt16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  
                         JSInt16 *dest);  
   
 JS_FRIEND_API(JSBool)  
 js_ArrayToJSInt32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  
                         JSInt32 *dest);  
   
 JS_FRIEND_API(JSBool)  
 js_ArrayToJSDoubleBuffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,  
                          jsdouble *dest);  
208    
209  JSBool  JSBool
210  js_PrototypeHasIndexedProperties(JSContext *cx, JSObject *obj);  js_PrototypeHasIndexedProperties(JSContext *cx, JSObject *obj);
# Line 233  Line 216 
216  js_GetDenseArrayElementValue(JSContext *cx, JSObject *obj, JSProperty *prop,  js_GetDenseArrayElementValue(JSContext *cx, JSObject *obj, JSProperty *prop,
217                               jsval *vp);                               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    /*
224     * Friend api function that allows direct creation of an array object with a
225     * 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    
239  #endif /* jsarray_h___ */  #endif /* jsarray_h___ */

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

  ViewVC Help
Powered by ViewVC 1.1.24