blob: af061507c1c25707ae11621438eb4c3abf6e6d70 [file] [log] [blame]
darinc758b282002-11-20 21:12:14 +00001/*
darinc758b282002-11-20 21:12:14 +00002 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
fpizlo@apple.com74485fb2015-02-10 03:27:43 +00003 * Copyright (C) 2003, 2007, 2008, 2009, 2012, 2015 Apple Inc. All rights reserved.
darinc758b282002-11-20 21:12:14 +00004 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
mjscdff33b2006-01-23 21:41:36 +000017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
darinc758b282002-11-20 21:12:14 +000018 *
19 */
20
darin@apple.com5c0863d2008-06-16 04:17:44 +000021#ifndef JSArray_h
22#define JSArray_h
darinc758b282002-11-20 21:12:14 +000023
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +000024#include "ArrayConventions.h"
mark.lam@apple.coma4fe7ab2012-11-09 03:03:44 +000025#include "ButterflyInlines.h"
ggaren@apple.come5531972012-08-30 23:33:05 +000026#include "JSObject.h"
darinc758b282002-11-20 21:12:14 +000027
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000028namespace JSC {
darinc758b282002-11-20 21:12:14 +000029
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000030class JSArray;
31class LLIntOffsetsExtractor;
barraclough@apple.com617f4642011-12-23 01:41:04 +000032
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000033class JSArray : public JSNonFinalObject {
34 friend class LLIntOffsetsExtractor;
35 friend class Walker;
36 friend class JIT;
mrowe@apple.comf88a4632008-09-07 05:44:58 +000037
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000038public:
39 typedef JSNonFinalObject Base;
akling@apple.com4b9e0002015-04-13 19:12:48 +000040 static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames;
commit-queue@webkit.org6c25c522011-08-09 20:46:17 +000041
fpizlo@apple.com372fa822013-08-21 19:43:47 +000042 static size_t allocationSize(size_t inlineCapacity)
43 {
44 ASSERT_UNUSED(inlineCapacity, !inlineCapacity);
45 return sizeof(JSArray);
46 }
47
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000048protected:
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000049 explicit JSArray(VM& vm, Structure* structure, Butterfly* butterfly)
50 : JSNonFinalObject(vm, structure, butterfly)
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +000051 {
fpizlo@apple.com0e9910a2012-10-09 23:39:53 +000052 }
53
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000054public:
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000055 static JSArray* create(VM&, Structure*, unsigned initialLength = 0);
akling@apple.com406c2f82015-06-16 18:38:04 +000056 static JSArray* createWithButterfly(VM&, Structure*, Butterfly*);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000057
58 // tryCreateUninitialized is used for fast construction of arrays whose size and
59 // contents are known at time of creation. Clients of this interface must:
60 // - null-check the result (indicating out of memory, or otherwise unable to allocate vector).
61 // - call 'initializeIndex' for all properties in sequence, for 0 <= i < initialLength.
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000062 static JSArray* tryCreateUninitialized(VM&, Structure*, unsigned initialLength);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000063
barraclough@apple.com61ff98c2013-08-21 22:32:10 +000064 JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool throwException);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000065
fpizlo@apple.comff27eed2014-07-23 04:33:37 +000066 JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000067
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +000068 DECLARE_EXPORT_INFO;
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000069
70 unsigned length() const { return getArrayLength(); }
71 // OK to use on new arrays, but not if it might be a RegExpMatchArray.
fpizlo@apple.comff27eed2014-07-23 04:33:37 +000072 JS_EXPORT_PRIVATE bool setLength(ExecState*, unsigned, bool throwException = false);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000073
fpizlo@apple.comff27eed2014-07-23 04:33:37 +000074 JS_EXPORT_PRIVATE void push(ExecState*, JSValue);
75 JS_EXPORT_PRIVATE JSValue pop(ExecState*);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000076
akling@apple.com59585302015-05-22 10:18:47 +000077 JSArray* fastSlice(ExecState&, unsigned startIndex, unsigned count);
rniwa@webkit.org2fa49732015-05-12 21:04:10 +000078
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000079 enum ShiftCountMode {
80 // This form of shift hints that we're doing queueing. With this assumption in hand,
81 // we convert to ArrayStorage, which has queue optimizations.
82 ShiftCountForShift,
83
84 // This form of shift hints that we're just doing care and feeding on an array that
85 // is probably typically used for ordinary accesses. With this assumption in hand,
86 // we try to preserve whatever indexing type it has already.
87 ShiftCountForSplice
88 };
89
90 bool shiftCountForShift(ExecState* exec, unsigned startIndex, unsigned count)
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +000091 {
mhahnenberg@apple.coma3572b42014-05-20 18:07:48 +000092 return shiftCountWithArrayStorage(exec->vm(), startIndex, count, ensureArrayStorage(exec->vm()));
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000093 }
mhahnenberg@apple.coma3572b42014-05-20 18:07:48 +000094 bool shiftCountForSplice(ExecState* exec, unsigned& startIndex, unsigned count)
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +000095 {
96 return shiftCountWithAnyIndexingType(exec, startIndex, count);
97 }
98 template<ShiftCountMode shiftCountMode>
mhahnenberg@apple.coma3572b42014-05-20 18:07:48 +000099 bool shiftCount(ExecState* exec, unsigned& startIndex, unsigned count)
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000100 {
101 switch (shiftCountMode) {
102 case ShiftCountForShift:
103 return shiftCountForShift(exec, startIndex, count);
104 case ShiftCountForSplice:
105 return shiftCountForSplice(exec, startIndex, count);
106 default:
107 CRASH();
108 return false;
109 }
110 }
111
112 bool unshiftCountForShift(ExecState* exec, unsigned startIndex, unsigned count)
113 {
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000114 return unshiftCountWithArrayStorage(exec, startIndex, count, ensureArrayStorage(exec->vm()));
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000115 }
116 bool unshiftCountForSplice(ExecState* exec, unsigned startIndex, unsigned count)
117 {
118 return unshiftCountWithAnyIndexingType(exec, startIndex, count);
119 }
120 template<ShiftCountMode shiftCountMode>
121 bool unshiftCount(ExecState* exec, unsigned startIndex, unsigned count)
122 {
123 switch (shiftCountMode) {
124 case ShiftCountForShift:
125 return unshiftCountForShift(exec, startIndex, count);
126 case ShiftCountForSplice:
127 return unshiftCountForSplice(exec, startIndex, count);
128 default:
129 CRASH();
130 return false;
131 }
132 }
133
fpizlo@apple.comff27eed2014-07-23 04:33:37 +0000134 JS_EXPORT_PRIVATE void fillArgList(ExecState*, MarkedArgumentBuffer&);
fpizlo@apple.combcfd39e2015-02-10 23:16:36 +0000135 JS_EXPORT_PRIVATE void copyToArguments(ExecState*, VirtualRegister firstElementDest, unsigned offset, unsigned length);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000136
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000137 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype, IndexingType indexingType)
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000138 {
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +0000139 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info(), indexingType);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000140 }
141
142protected:
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000143 static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
144
145 static bool deleteProperty(JSCell*, ExecState*, PropertyName);
146 JS_EXPORT_PRIVATE static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
147
148private:
149 bool isLengthWritable()
150 {
151 ArrayStorage* storage = arrayStorageOrNull();
152 if (!storage)
153 return true;
154 SparseArrayValueMap* map = storage->m_sparseMap.get();
155 return !map || !map->lengthIsReadOnly();
156 }
157
mhahnenberg@apple.coma3572b42014-05-20 18:07:48 +0000158 bool shiftCountWithAnyIndexingType(ExecState*, unsigned& startIndex, unsigned count);
fpizlo@apple.comff27eed2014-07-23 04:33:37 +0000159 JS_EXPORT_PRIVATE bool shiftCountWithArrayStorage(VM&, unsigned startIndex, unsigned count, ArrayStorage*);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000160
161 bool unshiftCountWithAnyIndexingType(ExecState*, unsigned startIndex, unsigned count);
162 bool unshiftCountWithArrayStorage(ExecState*, unsigned startIndex, unsigned count, ArrayStorage*);
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000163 bool unshiftCountSlowCase(VM&, bool, unsigned);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000164
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000165 bool setLengthWithArrayStorage(ExecState*, unsigned newLength, bool throwException, ArrayStorage*);
166 void setLengthWritable(ExecState*, bool writable);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000167};
168
oliver@apple.coma03796a2013-07-25 04:01:20 +0000169inline Butterfly* createContiguousArrayButterfly(VM& vm, JSCell* intendedOwner, unsigned length, unsigned& vectorLength)
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000170{
171 IndexingHeader header;
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000172 vectorLength = std::max(length, BASE_VECTOR_LEN);
173 header.setVectorLength(vectorLength);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000174 header.setPublicLength(length);
175 Butterfly* result = Butterfly::create(
oliver@apple.coma03796a2013-07-25 04:01:20 +0000176 vm, intendedOwner, 0, 0, true, header, vectorLength * sizeof(EncodedJSValue));
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000177 return result;
178}
179
oliver@apple.coma03796a2013-07-25 04:01:20 +0000180inline Butterfly* createArrayButterfly(VM& vm, JSCell* intendedOwner, unsigned initialLength)
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000181{
182 Butterfly* butterfly = Butterfly::create(
oliver@apple.coma03796a2013-07-25 04:01:20 +0000183 vm, intendedOwner, 0, 0, true, baseIndexingHeaderForArray(initialLength),
184 ArrayStorage::sizeFor(BASE_VECTOR_LEN));
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000185 ArrayStorage* storage = butterfly->arrayStorage();
186 storage->m_indexBias = 0;
187 storage->m_sparseMap.clear();
188 storage->m_numValuesInVector = 0;
189 return butterfly;
190}
191
oliver@apple.coma03796a2013-07-25 04:01:20 +0000192Butterfly* createArrayButterflyInDictionaryIndexingMode(
193 VM&, JSCell* intendedOwner, unsigned initialLength);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000194
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000195inline JSArray* JSArray::create(VM& vm, Structure* structure, unsigned initialLength)
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000196{
197 Butterfly* butterfly;
dbatyai.u-szeged@partner.samsung.comb382e6d2014-03-26 15:08:12 +0000198 if (LIKELY(!hasAnyArrayStorage(structure->indexingType()))) {
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000199 ASSERT(
200 hasUndecided(structure->indexingType())
201 || hasInt32(structure->indexingType())
202 || hasDouble(structure->indexingType())
203 || hasContiguous(structure->indexingType()));
204 unsigned vectorLength;
oliver@apple.coma03796a2013-07-25 04:01:20 +0000205 butterfly = createContiguousArrayButterfly(vm, 0, initialLength, vectorLength);
fpizlo@apple.comc8f36872015-05-05 02:40:28 +0000206 ASSERT(initialLength < MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000207 if (hasDouble(structure->indexingType())) {
208 for (unsigned i = 0; i < vectorLength; ++i)
fpizlo@apple.combeef4522014-04-16 22:44:00 +0000209 butterfly->contiguousDouble()[i] = PNaN;
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000210 }
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000211 } else {
212 ASSERT(
213 structure->indexingType() == ArrayWithSlowPutArrayStorage
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000214 || structure->indexingType() == ArrayWithArrayStorage);
oliver@apple.coma03796a2013-07-25 04:01:20 +0000215 butterfly = createArrayButterfly(vm, 0, initialLength);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000216 }
akling@apple.com406c2f82015-06-16 18:38:04 +0000217
218 return createWithButterfly(vm, structure, butterfly);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000219}
220
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000221inline JSArray* JSArray::tryCreateUninitialized(VM& vm, Structure* structure, unsigned initialLength)
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000222{
223 unsigned vectorLength = std::max(BASE_VECTOR_LEN, initialLength);
224 if (vectorLength > MAX_STORAGE_VECTOR_LENGTH)
225 return 0;
226
227 Butterfly* butterfly;
dbatyai.u-szeged@partner.samsung.comb382e6d2014-03-26 15:08:12 +0000228 if (LIKELY(!hasAnyArrayStorage(structure->indexingType()))) {
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000229 ASSERT(
230 hasUndecided(structure->indexingType())
231 || hasInt32(structure->indexingType())
232 || hasDouble(structure->indexingType())
233 || hasContiguous(structure->indexingType()));
234
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000235 void* temp;
oliver@apple.coma03796a2013-07-25 04:01:20 +0000236 if (!vm.heap.tryAllocateStorage(0, Butterfly::totalSize(0, 0, true, vectorLength * sizeof(EncodedJSValue)), &temp))
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000237 return 0;
238 butterfly = Butterfly::fromBase(temp, 0, 0);
239 butterfly->setVectorLength(vectorLength);
240 butterfly->setPublicLength(initialLength);
fpizlo@apple.com0d5d62c2013-01-08 20:21:36 +0000241 if (hasDouble(structure->indexingType())) {
242 for (unsigned i = initialLength; i < vectorLength; ++i)
fpizlo@apple.combeef4522014-04-16 22:44:00 +0000243 butterfly->contiguousDouble()[i] = PNaN;
fpizlo@apple.com0d5d62c2013-01-08 20:21:36 +0000244 }
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000245 } else {
246 void* temp;
oliver@apple.coma03796a2013-07-25 04:01:20 +0000247 if (!vm.heap.tryAllocateStorage(0, Butterfly::totalSize(0, 0, true, ArrayStorage::sizeFor(vectorLength)), &temp))
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000248 return 0;
249 butterfly = Butterfly::fromBase(temp, 0, 0);
250 *butterfly->indexingHeader() = indexingHeaderForArray(initialLength, vectorLength);
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +0000251 ArrayStorage* storage = butterfly->arrayStorage();
252 storage->m_indexBias = 0;
253 storage->m_sparseMap.clear();
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000254 storage->m_numValuesInVector = initialLength;
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +0000255 }
akling@apple.com406c2f82015-06-16 18:38:04 +0000256
257 return createWithButterfly(vm, structure, butterfly);
258}
259
260inline JSArray* JSArray::createWithButterfly(VM& vm, Structure* structure, Butterfly* butterfly)
261{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000262 JSArray* array = new (NotNull, allocateCell<JSArray>(vm.heap)) JSArray(vm, structure, butterfly);
263 array->finishCreation(vm);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000264 return array;
265}
mhahnenberg@apple.comc2748322012-02-10 22:44:09 +0000266
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000267JSArray* asArray(JSValue);
darin@apple.com5a494422008-10-18 23:08:12 +0000268
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000269inline JSArray* asArray(JSCell* cell)
270{
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +0000271 ASSERT(cell->inherits(JSArray::info()));
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000272 return jsCast<JSArray*>(cell);
273}
darin@apple.com5a494422008-10-18 23:08:12 +0000274
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000275inline JSArray* asArray(JSValue value)
276{
277 return asArray(value.asCell());
278}
darin@apple.com8a1a5b52009-09-04 19:03:33 +0000279
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +0000280inline bool isJSArray(JSCell* cell) { return cell->classInfo() == JSArray::info(); }
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000281inline bool isJSArray(JSValue v) { return v.isCell() && isJSArray(v.asCell()); }
ggaren@apple.comc3343bd2009-02-24 03:58:09 +0000282
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000283inline JSArray* constructArray(ExecState* exec, Structure* arrayStructure, const ArgList& values)
284{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000285 VM& vm = exec->vm();
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000286 unsigned length = values.size();
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000287 JSArray* array = JSArray::tryCreateUninitialized(vm, arrayStructure, length);
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000288
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000289 // FIXME: we should probably throw an out of memory error here, but
290 // when making this change we should check that all clients of this
291 // function will correctly handle an exception being thrown from here.
oliver@apple.com51b41da2013-01-23 21:44:29 +0000292 RELEASE_ASSERT(array);
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000293
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000294 for (unsigned i = 0; i < length; ++i)
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000295 array->initializeIndex(vm, i, values.at(i));
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000296 return array;
297}
mhahnenberg@apple.com87ff87d2012-02-26 22:41:41 +0000298
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000299inline JSArray* constructArray(ExecState* exec, Structure* arrayStructure, const JSValue* values, unsigned length)
300{
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000301 VM& vm = exec->vm();
302 JSArray* array = JSArray::tryCreateUninitialized(vm, arrayStructure, length);
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000303
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000304 // FIXME: we should probably throw an out of memory error here, but
305 // when making this change we should check that all clients of this
306 // function will correctly handle an exception being thrown from here.
oliver@apple.com51b41da2013-01-23 21:44:29 +0000307 RELEASE_ASSERT(array);
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000308
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000309 for (unsigned i = 0; i < length; ++i)
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000310 array->initializeIndex(vm, i, values[i]);
fpizlo@apple.coma34ff7d2012-11-06 19:10:37 +0000311 return array;
312}
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000313
msaboff@apple.comb70e41b2013-09-13 18:03:55 +0000314inline JSArray* constructArrayNegativeIndexed(ExecState* exec, Structure* arrayStructure, const JSValue* values, unsigned length)
315{
316 VM& vm = exec->vm();
317 JSArray* array = JSArray::tryCreateUninitialized(vm, arrayStructure, length);
318
319 // FIXME: we should probably throw an out of memory error here, but
320 // when making this change we should check that all clients of this
321 // function will correctly handle an exception being thrown from here.
322 RELEASE_ASSERT(array);
323
324 for (int i = 0; i < static_cast<int>(length); ++i)
325 array->initializeIndex(vm, i, values[-i]);
326 return array;
327}
328
fpizlo@apple.com6c89cd32012-06-26 19:42:05 +0000329} // namespace JSC
darinc758b282002-11-20 21:12:14 +0000330
weinig@apple.com0e2d66e2008-07-06 05:26:58 +0000331#endif // JSArray_h