1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
16 * The Original Code is Mozilla Communicator client code, released
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.
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.
38 * ***** END LICENSE BLOCK ***** */
51 /* Small arrays are dense, no matter what. */
52 const unsigned MIN_SPARSE_INDEX
= 256;
55 /* 2^32-2, inclusive */
56 const uint32_t MAX_ARRAY_INDEX
= 4294967294u;
60 js_IdIsIndex(jsid id
, uint32_t *indexp
)
62 if (JSID_IS_INT(id
)) {
63 int32_t i
= JSID_TO_INT(id
);
66 *indexp
= (uint32_t)i
;
70 if (JS_UNLIKELY(!JSID_IS_STRING(id
)))
73 return js::StringIsArrayIndex(JSID_TO_ATOM(id
), indexp
);
77 js_InitArrayClass(JSContext
*cx
, JSObject
*obj
);
80 js_InitContextBusyArrayTable(JSContext
*cx
);
84 /* Create a dense array with no capacity allocated, length set to 0. */
85 extern JSObject
* JS_FASTCALL
86 NewDenseEmptyArray(JSContext
*cx
, JSObject
*proto
=NULL
);
88 /* Create a dense array with length and capacity == 'length', initialized length set to 0. */
89 extern JSObject
* JS_FASTCALL
90 NewDenseAllocatedArray(JSContext
*cx
, uint32_t length
, JSObject
*proto
=NULL
);
93 * Create a dense array with length, capacity and initialized length == 'length', and filled with holes.
94 * This is a kludge, as the tracer doesn't yet track/update initialized length when initializing
97 extern JSObject
* JS_FASTCALL
98 NewDenseAllocatedEmptyArray(JSContext
*cx
, uint32_t length
, JSObject
*proto
=NULL
);
101 * Create a dense array with a set length, but without allocating space for the
102 * contents. This is useful, e.g., when accepting length from the user.
104 extern JSObject
* JS_FASTCALL
105 NewDenseUnallocatedArray(JSContext
*cx
, uint32_t length
, JSObject
*proto
=NULL
);
107 /* Create a dense array with a copy of vp. */
109 NewDenseCopiedArray(JSContext
*cx
, uint32_t length
, const Value
*vp
, JSObject
*proto
= NULL
);
111 /* Create a sparse array. */
113 NewSlowEmptyArray(JSContext
*cx
);
118 js_GetLengthProperty(JSContext
*cx
, JSObject
*obj
, uint32_t *lengthp
);
121 js_SetLengthProperty(JSContext
*cx
, JSObject
*obj
, double length
);
126 array_defineElement(JSContext
*cx
, JSObject
*obj
, uint32_t index
, const Value
*value
,
127 PropertyOp getter
, StrictPropertyOp setter
, unsigned attrs
);
130 array_deleteElement(JSContext
*cx
, JSObject
*obj
, uint32_t index
, Value
*rval
, JSBool strict
);
133 * Copy 'length' elements from aobj to vp.
135 * This function assumes 'length' is effectively the result of calling
136 * js_GetLengthProperty on aobj.
139 GetElements(JSContext
*cx
, HandleObject aobj
, uint32_t length
, js::Value
*vp
);
141 /* Natives exposed for optimization by the interpreter and JITs. */
144 array_sort(JSContext
*cx
, unsigned argc
, js::Value
*vp
);
147 array_push(JSContext
*cx
, unsigned argc
, js::Value
*vp
);
150 array_pop(JSContext
*cx
, unsigned argc
, js::Value
*vp
);
153 array_concat(JSContext
*cx
, unsigned argc
, js::Value
*vp
);
156 array_shift(JSContext
*cx
, unsigned argc
, js::Value
*vp
);
162 js_ArrayInfo(JSContext
*cx
, unsigned argc
, jsval
*vp
);
166 * Append the given (non-hole) value to the end of an array. The array must be
167 * a newborn array -- that is, one which has not been exposed to script for
168 * arbitrary manipulation. (This method optimizes on the assumption that
169 * extending the array to accommodate the element will never make the array
170 * sparse, which requires that the array be completely filled.)
173 js_NewbornArrayPush(JSContext
*cx
, JSObject
*obj
, const js::Value
&v
);
176 js_PrototypeHasIndexedProperties(JSContext
*cx
, JSObject
*obj
);
179 * Utility to access the value from the id returned by array_lookupProperty.
182 js_GetDenseArrayElementValue(JSContext
*cx
, JSObject
*obj
, jsid id
,
185 /* Array constructor native. Exposed only so the JIT can know its address. */
187 js_Array(JSContext
*cx
, unsigned argc
, js::Value
*vp
);
189 #endif /* jsarray_h___ */