Changeset 222563 in webkit for trunk/Source/JavaScriptCore/runtime/JSArrayInlines.h
- Timestamp:
- Sep 27, 2017, 11:37:41 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/JSArrayInlines.h
r218449 r222563 81 81 } 82 82 83 ALWAYS_INLINE void JSArray::pushInline(ExecState* exec, JSValue value) 84 { 85 VM& vm = exec->vm(); 86 auto scope = DECLARE_THROW_SCOPE(vm); 87 88 Butterfly* butterfly = m_butterfly.getMayBeNull(); 89 90 switch (indexingType()) { 91 case ArrayClass: { 92 createInitialUndecided(vm, 0); 93 FALLTHROUGH; 94 } 95 96 case ArrayWithUndecided: { 97 convertUndecidedForValue(vm, value); 98 scope.release(); 99 push(exec, value); 100 return; 101 } 102 103 case ArrayWithInt32: { 104 if (!value.isInt32()) { 105 convertInt32ForValue(vm, value); 106 scope.release(); 107 push(exec, value); 108 return; 109 } 110 111 unsigned length = butterfly->publicLength(); 112 ASSERT(length <= butterfly->vectorLength()); 113 if (length < butterfly->vectorLength()) { 114 butterfly->contiguousInt32()[length].setWithoutWriteBarrier(value); 115 butterfly->setPublicLength(length + 1); 116 return; 117 } 118 119 if (UNLIKELY(length > MAX_ARRAY_INDEX)) { 120 methodTable(vm)->putByIndex(this, exec, length, value, true); 121 if (!scope.exception()) 122 throwException(exec, scope, createRangeError(exec, ASCIILiteral(LengthExceededTheMaximumArrayLengthError))); 123 return; 124 } 125 126 scope.release(); 127 putByIndexBeyondVectorLengthWithoutAttributes<Int32Shape>(exec, length, value); 128 return; 129 } 130 131 case ArrayWithContiguous: { 132 unsigned length = butterfly->publicLength(); 133 ASSERT(length <= butterfly->vectorLength()); 134 if (length < butterfly->vectorLength()) { 135 butterfly->contiguous()[length].set(vm, this, value); 136 butterfly->setPublicLength(length + 1); 137 return; 138 } 139 140 if (UNLIKELY(length > MAX_ARRAY_INDEX)) { 141 methodTable(vm)->putByIndex(this, exec, length, value, true); 142 if (!scope.exception()) 143 throwException(exec, scope, createRangeError(exec, ASCIILiteral(LengthExceededTheMaximumArrayLengthError))); 144 return; 145 } 146 147 scope.release(); 148 putByIndexBeyondVectorLengthWithoutAttributes<ContiguousShape>(exec, length, value); 149 return; 150 } 151 152 case ArrayWithDouble: { 153 if (!value.isNumber()) { 154 convertDoubleToContiguous(vm); 155 scope.release(); 156 push(exec, value); 157 return; 158 } 159 double valueAsDouble = value.asNumber(); 160 if (valueAsDouble != valueAsDouble) { 161 convertDoubleToContiguous(vm); 162 scope.release(); 163 push(exec, value); 164 return; 165 } 166 167 unsigned length = butterfly->publicLength(); 168 ASSERT(length <= butterfly->vectorLength()); 169 if (length < butterfly->vectorLength()) { 170 butterfly->contiguousDouble()[length] = valueAsDouble; 171 butterfly->setPublicLength(length + 1); 172 return; 173 } 174 175 if (UNLIKELY(length > MAX_ARRAY_INDEX)) { 176 methodTable(vm)->putByIndex(this, exec, length, value, true); 177 if (!scope.exception()) 178 throwException(exec, scope, createRangeError(exec, ASCIILiteral(LengthExceededTheMaximumArrayLengthError))); 179 return; 180 } 181 182 scope.release(); 183 putByIndexBeyondVectorLengthWithoutAttributes<DoubleShape>(exec, length, value); 184 return; 185 } 186 187 case ArrayWithSlowPutArrayStorage: { 188 unsigned oldLength = length(); 189 bool putResult = false; 190 if (attemptToInterceptPutByIndexOnHole(exec, oldLength, value, true, putResult)) { 191 if (!scope.exception() && oldLength < 0xFFFFFFFFu) { 192 scope.release(); 193 setLength(exec, oldLength + 1, true); 194 } 195 return; 196 } 197 FALLTHROUGH; 198 } 199 200 case ArrayWithArrayStorage: { 201 ArrayStorage* storage = butterfly->arrayStorage(); 202 203 // Fast case - push within vector, always update m_length & m_numValuesInVector. 204 unsigned length = storage->length(); 205 if (length < storage->vectorLength()) { 206 storage->m_vector[length].set(vm, this, value); 207 storage->setLength(length + 1); 208 ++storage->m_numValuesInVector; 209 return; 210 } 211 212 // Pushing to an array of invalid length (2^31-1) stores the property, but throws a range error. 213 if (UNLIKELY(storage->length() > MAX_ARRAY_INDEX)) { 214 methodTable(vm)->putByIndex(this, exec, storage->length(), value, true); 215 // Per ES5.1 15.4.4.7 step 6 & 15.4.5.1 step 3.d. 216 if (!scope.exception()) 217 throwException(exec, scope, createRangeError(exec, ASCIILiteral(LengthExceededTheMaximumArrayLengthError))); 218 return; 219 } 220 221 // Handled the same as putIndex. 222 scope.release(); 223 putByIndexBeyondVectorLengthWithArrayStorage(exec, storage->length(), value, true, storage); 224 return; 225 } 226 227 default: 228 RELEASE_ASSERT_NOT_REACHED(); 229 } 230 } 231 83 232 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.