Bug 752461 - Hide click-to-play overlays when choosing "never activate plugins.....
[gecko.git] / js / src / jsarray.h
blob092ee3ab5d08ef8a9233be67438e899bdf5a417a
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
14 * License.
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
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.
24 * Contributor(s):
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 ***** */
40 #ifndef jsarray_h___
41 #define jsarray_h___
43 * JS Array interface.
45 #include "jscntxt.h"
46 #include "jsprvtd.h"
47 #include "jspubtd.h"
48 #include "jsatom.h"
49 #include "jsobj.h"
51 /* Small arrays are dense, no matter what. */
52 const unsigned MIN_SPARSE_INDEX = 256;
54 namespace js {
55 /* 2^32-2, inclusive */
56 const uint32_t MAX_ARRAY_INDEX = 4294967294u;
59 inline JSBool
60 js_IdIsIndex(jsid id, uint32_t *indexp)
62 if (JSID_IS_INT(id)) {
63 int32_t i = JSID_TO_INT(id);
64 if (i < 0)
65 return JS_FALSE;
66 *indexp = (uint32_t)i;
67 return JS_TRUE;
70 if (JS_UNLIKELY(!JSID_IS_STRING(id)))
71 return JS_FALSE;
73 return js::StringIsArrayIndex(JSID_TO_ATOM(id), indexp);
76 extern JSObject *
77 js_InitArrayClass(JSContext *cx, JSObject *obj);
79 extern bool
80 js_InitContextBusyArrayTable(JSContext *cx);
82 namespace js {
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
95 * array elements.
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. */
108 extern JSObject *
109 NewDenseCopiedArray(JSContext *cx, uint32_t length, const Value *vp, JSObject *proto = NULL);
111 /* Create a sparse array. */
112 extern JSObject *
113 NewSlowEmptyArray(JSContext *cx);
115 } /* namespace js */
117 extern JSBool
118 js_GetLengthProperty(JSContext *cx, JSObject *obj, uint32_t *lengthp);
120 extern JSBool
121 js_SetLengthProperty(JSContext *cx, JSObject *obj, double length);
123 namespace js {
125 extern JSBool
126 array_defineElement(JSContext *cx, JSObject *obj, uint32_t index, const Value *value,
127 PropertyOp getter, StrictPropertyOp setter, unsigned attrs);
129 extern JSBool
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.
138 extern bool
139 GetElements(JSContext *cx, HandleObject aobj, uint32_t length, js::Value *vp);
141 /* Natives exposed for optimization by the interpreter and JITs. */
143 extern JSBool
144 array_sort(JSContext *cx, unsigned argc, js::Value *vp);
146 extern JSBool
147 array_push(JSContext *cx, unsigned argc, js::Value *vp);
149 extern JSBool
150 array_pop(JSContext *cx, unsigned argc, js::Value *vp);
152 extern JSBool
153 array_concat(JSContext *cx, unsigned argc, js::Value *vp);
155 extern JSBool
156 array_shift(JSContext *cx, unsigned argc, js::Value *vp);
158 } /* namespace js */
160 #ifdef DEBUG
161 extern JSBool
162 js_ArrayInfo(JSContext *cx, unsigned argc, jsval *vp);
163 #endif
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.)
172 extern JSBool
173 js_NewbornArrayPush(JSContext *cx, JSObject *obj, const js::Value &v);
175 JSBool
176 js_PrototypeHasIndexedProperties(JSContext *cx, JSObject *obj);
179 * Utility to access the value from the id returned by array_lookupProperty.
181 JSBool
182 js_GetDenseArrayElementValue(JSContext *cx, JSObject *obj, jsid id,
183 js::Value *vp);
185 /* Array constructor native. Exposed only so the JIT can know its address. */
186 JSBool
187 js_Array(JSContext *cx, unsigned argc, js::Value *vp);
189 #endif /* jsarray_h___ */