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 |
|
|
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 |
|
|
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) |
|
|
|
|
#define ARRAY_DENSE_LENGTH(obj) \ |
|
|
(JS_ASSERT(OBJ_IS_DENSE_ARRAY(cx, obj)), \ |
|
|
(obj)->dslots ? (uint32)(obj)->dslots[-1] : 0) |
|
108 |
|
|
109 |
#define ARRAY_SET_DENSE_LENGTH(obj, max) \ |
static JS_INLINE uint32 |
110 |
(JS_ASSERT((obj)->dslots), (obj)->dslots[-1] = (jsval)(max)) |
js_DenseArrayCapacity(JSObject *obj) |
111 |
|
{ |
112 |
#define ARRAY_GROWBY 8 |
JS_ASSERT(OBJ_IS_DENSE_ARRAY(BOGUS_CX, obj)); |
113 |
|
return obj->dslots ? (uint32) obj->dslots[-1] : 0; |
114 |
|
} |
115 |
|
|
116 |
|
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); |
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 |
|
|
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 JS_FASTCALL |
169 |
|
js_ArrayCompPush(JSContext *cx, JSObject *obj, jsval v); |
170 |
|
|
171 |
/* |
/* |
172 |
* Fast dense-array-to-buffer conversions. |
* Fast dense-array-to-buffer conversions. |
173 |
* |
* |
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___ */ |