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

Contents of /trunk/js/jsarray.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 332 - (show annotations)
Thu Oct 23 19:03:33 2008 UTC (10 years, 11 months ago) by siliconforks
File MIME type: text/plain
File size: 7987 byte(s)
Add SpiderMonkey from Firefox 3.1b1.

The following directories and files were removed:
correct/, correct.js
liveconnect/
nanojit/
t/
v8/
vprof/
xpconnect/
all JavaScript files (Y.js, call.js, if.js, math-partial-sums.js, md5.js, perfect.js, trace-test.js, trace.js)


1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
18 *
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s):
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 #ifndef jsarray_h___
41 #define jsarray_h___
42 /*
43 * JS Array interface.
44 */
45 #include "jsprvtd.h"
46 #include "jspubtd.h"
47
48 JS_BEGIN_EXTERN_C
49
50 /* Generous sanity-bound on length (in elements) of array initialiser. */
51 #define ARRAY_INIT_LIMIT JS_BIT(24)
52
53 extern JSBool
54 js_IdIsIndex(jsval id, jsuint *indexp);
55
56 extern JSClass js_ArrayClass, js_SlowArrayClass;
57
58 #define OBJ_IS_DENSE_ARRAY(cx,obj) (OBJ_GET_CLASS(cx, obj) == &js_ArrayClass)
59
60 #define OBJ_IS_ARRAY(cx,obj) (OBJ_IS_DENSE_ARRAY(cx, obj) || \
61 OBJ_GET_CLASS(cx, obj) == &js_SlowArrayClass)
62
63 extern JSObject *
64 js_InitArrayClass(JSContext *cx, JSObject *obj);
65
66 extern JSObject *
67 js_NewArrayObject(JSContext *cx, jsuint length, jsval *vector,
68 JSBool holey = JS_FALSE);
69
70 /* Create an array object that starts out already made slow/sparse. */
71 extern JSObject *
72 js_NewSlowArrayObject(JSContext *cx);
73
74 extern JSBool
75 js_MakeArraySlow(JSContext *cx, JSObject *obj);
76
77 #define JSSLOT_ARRAY_LENGTH JSSLOT_PRIVATE
78 #define JSSLOT_ARRAY_COUNT (JSSLOT_ARRAY_LENGTH + 1)
79 #define JSSLOT_ARRAY_LOOKUP_HOLDER (JSSLOT_ARRAY_COUNT + 1)
80
81 #define ARRAY_DENSE_LENGTH(obj) \
82 (JS_ASSERT(OBJ_IS_DENSE_ARRAY(cx, obj)), \
83 (obj)->dslots ? (uint32)(obj)->dslots[-1] : 0)
84
85 #define ARRAY_SET_DENSE_LENGTH(obj, max) \
86 (JS_ASSERT((obj)->dslots), (obj)->dslots[-1] = (jsval)(max))
87
88 #define ARRAY_GROWBY 8
89
90 extern JSBool
91 js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
92
93 extern JSBool
94 js_SetLengthProperty(JSContext *cx, JSObject *obj, jsuint length);
95
96 extern JSBool
97 js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
98
99 extern JSBool JS_FASTCALL
100 js_IndexToId(JSContext *cx, jsuint index, jsid *idp);
101
102 /*
103 * Test whether an object is "array-like". Currently this means whether obj
104 * is an Array or an arguments object. We would like an API, and probably a
105 * way in the language, to bless other objects as array-like: having indexed
106 * properties, and a 'length' property of uint32 value equal to one more than
107 * the greatest index.
108 */
109 extern JSBool
110 js_IsArrayLike(JSContext *cx, JSObject *obj, JSBool *answerp, jsuint *lengthp);
111
112 /*
113 * JS-specific merge sort function.
114 */
115 typedef JSBool (*JSComparator)(void *arg, const void *a, const void *b,
116 int *result);
117 /*
118 * NB: vec is the array to be sorted, tmp is temporary space at least as big
119 * as vec. Both should be GC-rooted if appropriate.
120 *
121 * The sorted result is in vec. vec may be in an inconsistent state if the
122 * comparator function cmp returns an error inside a comparison, so remember
123 * to check the return value of this function.
124 */
125 extern JSBool
126 js_MergeSort(void *vec, size_t nel, size_t elsize, JSComparator cmp,
127 void *arg, void *tmp);
128
129 #ifdef DEBUG_ARRAYS
130 extern JSBool
131 js_ArrayInfo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
132 #endif
133
134 extern JSBool
135 js_array_join(JSContext *cx, uintN argc, jsval *vp);
136
137 extern JSBool
138 js_array_push_slowly(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
139
140 extern JSBool
141 js_array_push1_dense(JSContext *cx, JSObject *obj, jsval v, jsval *rval);
142
143 extern JSBool
144 js_array_push(JSContext *cx, uintN argc, jsval *vp);
145
146 extern JSBool
147 js_array_pop_slowly(JSContext *cx, JSObject* obj, jsval *vp);
148
149 extern JSBool
150 js_array_pop_dense(JSContext *cx, JSObject* obj, jsval *vp);
151
152 extern JSBool
153 js_array_pop(JSContext *cx, uintN argc, jsval *vp);
154
155 enum ArrayToStringOp {
156 TO_STRING,
157 TO_LOCALE_STRING,
158 TO_SOURCE
159 };
160
161 extern JSBool
162 js_array_join_sub(JSContext *cx, JSObject *obj, enum ArrayToStringOp op,
163 JSString *sep, jsval *rval);
164
165 /*
166 * Fast dense-array-to-buffer conversions.
167 *
168 * If the array is a dense array, fill [offset..offset+count] values
169 * into destination, assuming that types are consistent. Return
170 * JS_TRUE if successful, otherwise JS_FALSE -- note that the
171 * destination buffer may be modified even if JS_FALSE is returned
172 * (e.g. due to finding an inappropriate type later on in the array).
173 * If JS_FALSE is returned, no error conditions or exceptions are set
174 * on the context.
175 *
176 * For ArrayToJSUint8, ArrayToJSUint16, and ArrayToJSUint32, each element
177 * in the array a) must be an integer; b) must be >= 0. Integers
178 * are clamped to fit in the destination size. Only JSVAL_IS_INT values
179 * are considered to be valid, so for JSUint32, the maximum value that
180 * can be fast-converted is less than the full unsigned 32-bit range.
181 *
182 * For ArrayToJSInt8, ArrayToJSInt16, ArrayToJSInt32, each element in
183 * the array must be an integer. Integers are clamped to fit in the
184 * destination size. Only JSVAL_IS_INT values are considered to be
185 * valid, so for JSInt32, the maximum value that can be
186 * fast-converted is less than the full signed 32-bit range.
187 *
188 * For ArrayToJSDouble, each element in the array must be an
189 * integer -or- a double (JSVAL_IS_NUMBER).
190 */
191
192 JS_FRIEND_API(JSBool)
193 js_ArrayToJSUint8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
194 JSUint8 *dest);
195
196 JS_FRIEND_API(JSBool)
197 js_ArrayToJSUint16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
198 JSUint16 *dest);
199
200 JS_FRIEND_API(JSBool)
201 js_ArrayToJSUint32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
202 JSUint32 *dest);
203
204 JS_FRIEND_API(JSBool)
205 js_ArrayToJSInt8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
206 JSInt8 *dest);
207
208 JS_FRIEND_API(JSBool)
209 js_ArrayToJSInt16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
210 JSInt16 *dest);
211
212 JS_FRIEND_API(JSBool)
213 js_ArrayToJSInt32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
214 JSInt32 *dest);
215
216 JS_FRIEND_API(JSBool)
217 js_ArrayToJSDoubleBuffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
218 jsdouble *dest);
219
220 JS_END_EXTERN_C
221
222 #endif /* jsarray_h___ */

  ViewVC Help
Powered by ViewVC 1.1.24