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

Annotation of /trunk/js/jsarray.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 399 - (hide annotations)
Tue Dec 9 03:37:47 2008 UTC (11 years, 8 months ago) by siliconforks
File MIME type: text/plain
File size: 7224 byte(s)
Use SpiderMonkey from Firefox 3.1b2.

1 siliconforks 332 /* -*- 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     /*
135     * Fast dense-array-to-buffer conversions.
136     *
137     * If the array is a dense array, fill [offset..offset+count] values
138     * into destination, assuming that types are consistent. Return
139     * JS_TRUE if successful, otherwise JS_FALSE -- note that the
140     * destination buffer may be modified even if JS_FALSE is returned
141     * (e.g. due to finding an inappropriate type later on in the array).
142     * If JS_FALSE is returned, no error conditions or exceptions are set
143     * on the context.
144     *
145     * For ArrayToJSUint8, ArrayToJSUint16, and ArrayToJSUint32, each element
146     * in the array a) must be an integer; b) must be >= 0. Integers
147     * are clamped to fit in the destination size. Only JSVAL_IS_INT values
148     * are considered to be valid, so for JSUint32, the maximum value that
149     * can be fast-converted is less than the full unsigned 32-bit range.
150     *
151     * For ArrayToJSInt8, ArrayToJSInt16, ArrayToJSInt32, each element in
152     * the array must be an integer. Integers are clamped to fit in the
153     * destination size. Only JSVAL_IS_INT values are considered to be
154     * valid, so for JSInt32, the maximum value that can be
155     * fast-converted is less than the full signed 32-bit range.
156     *
157     * For ArrayToJSDouble, each element in the array must be an
158     * integer -or- a double (JSVAL_IS_NUMBER).
159     */
160    
161     JS_FRIEND_API(JSBool)
162     js_ArrayToJSUint8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
163     JSUint8 *dest);
164    
165     JS_FRIEND_API(JSBool)
166     js_ArrayToJSUint16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
167     JSUint16 *dest);
168    
169     JS_FRIEND_API(JSBool)
170     js_ArrayToJSUint32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
171     JSUint32 *dest);
172    
173     JS_FRIEND_API(JSBool)
174     js_ArrayToJSInt8Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
175     JSInt8 *dest);
176    
177     JS_FRIEND_API(JSBool)
178     js_ArrayToJSInt16Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
179     JSInt16 *dest);
180    
181     JS_FRIEND_API(JSBool)
182     js_ArrayToJSInt32Buffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
183     JSInt32 *dest);
184    
185     JS_FRIEND_API(JSBool)
186     js_ArrayToJSDoubleBuffer(JSContext *cx, JSObject *obj, jsuint offset, jsuint count,
187     jsdouble *dest);
188    
189     JS_END_EXTERN_C
190    
191     #endif /* jsarray_h___ */

  ViewVC Help
Powered by ViewVC 1.1.24