Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 10159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10170 array->SetLength(length + 2); | 10170 array->SetLength(length + 2); |
| 10171 return array; | 10171 return array; |
| 10172 } | 10172 } |
| 10173 | 10173 |
| 10174 | 10174 |
| 10175 bool ArrayList::IsFull() { | 10175 bool ArrayList::IsFull() { |
| 10176 int capacity = length(); | 10176 int capacity = length(); |
| 10177 return kFirstIndex + Length() == capacity; | 10177 return kFirstIndex + Length() == capacity; |
| 10178 } | 10178 } |
| 10179 | 10179 |
| 10180 namespace { | |
| 10180 | 10181 |
| 10181 Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) { | 10182 Handle<FixedArray> EnsureSpaceInFixedArray(Handle<FixedArray> array, |
| 10183 int length) { | |
| 10182 int capacity = array->length(); | 10184 int capacity = array->length(); |
| 10183 bool empty = (capacity == 0); | 10185 if (capacity < length) { |
| 10184 if (capacity < kFirstIndex + length) { | |
| 10185 Isolate* isolate = array->GetIsolate(); | 10186 Isolate* isolate = array->GetIsolate(); |
| 10186 int new_capacity = kFirstIndex + length; | 10187 int new_capacity = length; |
| 10187 new_capacity = new_capacity + Max(new_capacity / 2, 2); | 10188 new_capacity = new_capacity + Max(new_capacity / 2, 2); |
| 10188 int grow_by = new_capacity - capacity; | 10189 int grow_by = new_capacity - capacity; |
| 10189 array = Handle<ArrayList>::cast( | 10190 array = Handle<ArrayList>::cast( |
| 10190 isolate->factory()->CopyFixedArrayAndGrow(array, grow_by)); | 10191 isolate->factory()->CopyFixedArrayAndGrow(array, grow_by)); |
| 10191 if (empty) array->SetLength(0); | |
| 10192 } | 10192 } |
| 10193 return array; | 10193 return array; |
| 10194 } | 10194 } |
| 10195 | 10195 |
| 10196 } // namespace | |
| 10197 | |
| 10198 Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) { | |
| 10199 const bool empty = (array->length() == 0); | |
| 10200 auto ret = Handle<ArrayList>::cast( | |
| 10201 EnsureSpaceInFixedArray(array, kFirstIndex + length)); | |
| 10202 if (empty) ret->SetLength(0); | |
| 10203 return ret; | |
| 10204 } | |
| 10205 | |
| 10206 Handle<FrameArray> FrameArray::Allocate(Isolate* isolate, | |
|
Toon Verwaest
2016/08/23 13:14:08
So I guess I'm suggesting that a FrameArray should
jgruber
2016/08/23 15:32:13
Yes they're very similar. There doesn't seem to be
| |
| 10207 int number_of_frames) { | |
| 10208 DCHECK(0 <= number_of_frames); | |
|
Toon Verwaest
2016/08/23 13:14:08
DCHECK_LE(0, number_of_frames);
jgruber
2016/08/23 15:32:13
Done.
| |
| 10209 Factory* factory = isolate->factory(); | |
| 10210 Handle<FixedArray> result = | |
| 10211 factory->NewFixedArrayWithHoles(LengthFor(number_of_frames)); | |
| 10212 return Handle<FrameArray>::cast(result); | |
| 10213 } | |
| 10214 | |
| 10215 Handle<FrameArray> FrameArray::AppendJSFrame( | |
| 10216 Handle<FrameArray> in, int frame_ix, Handle<Object> receiver, | |
| 10217 Handle<JSFunction> function, Handle<AbstractCode> code, int offset) { | |
| 10218 Handle<FrameArray> array = EnsureSpace(in, LengthFor(frame_ix + 1)); | |
| 10219 array->SetReceiver(frame_ix, *receiver); | |
| 10220 array->SetFunction(frame_ix, *function); | |
| 10221 array->SetCode(frame_ix, *code); | |
| 10222 array->SetOffset(frame_ix, Smi::FromInt(offset)); | |
| 10223 return array; | |
| 10224 } | |
| 10225 | |
| 10226 Handle<FrameArray> FrameArray::AppendWasmFrame( | |
| 10227 Handle<FrameArray> in, int frame_ix, Handle<Object> wasm_object, | |
| 10228 int wasm_function_index, Handle<AbstractCode> code, int offset) { | |
| 10229 Handle<FrameArray> array = EnsureSpace(in, LengthFor(frame_ix + 1)); | |
| 10230 array->SetWasmObject(frame_ix, *wasm_object); | |
| 10231 array->SetWasmFunctionIndex(frame_ix, Smi::FromInt(wasm_function_index)); | |
| 10232 array->SetCode(frame_ix, *code); | |
| 10233 array->SetOffset(frame_ix, Smi::FromInt(offset)); | |
| 10234 return array; | |
| 10235 } | |
| 10236 | |
| 10237 Handle<FrameArray> FrameArray::EnsureSpace(Handle<FrameArray> array, | |
| 10238 int length) { | |
| 10239 return Handle<FrameArray>::cast(EnsureSpaceInFixedArray(array, length)); | |
| 10240 } | |
| 10241 | |
| 10196 Handle<DescriptorArray> DescriptorArray::Allocate(Isolate* isolate, | 10242 Handle<DescriptorArray> DescriptorArray::Allocate(Isolate* isolate, |
| 10197 int number_of_descriptors, | 10243 int number_of_descriptors, |
| 10198 int slack, | 10244 int slack, |
| 10199 PretenureFlag pretenure) { | 10245 PretenureFlag pretenure) { |
| 10200 DCHECK(0 <= number_of_descriptors); | 10246 DCHECK(0 <= number_of_descriptors); |
| 10201 Factory* factory = isolate->factory(); | 10247 Factory* factory = isolate->factory(); |
| 10202 // Do not use DescriptorArray::cast on incomplete object. | 10248 // Do not use DescriptorArray::cast on incomplete object. |
| 10203 int size = number_of_descriptors + slack; | 10249 int size = number_of_descriptors + slack; |
| 10204 if (size == 0) return factory->empty_descriptor_array(); | 10250 if (size == 0) return factory->empty_descriptor_array(); |
| 10205 // Allocate the array of keys. | 10251 // Allocate the array of keys. |
| (...skipping 9070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 19276 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, | 19322 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, |
| 19277 PrototypeIterator::END_AT_NULL); | 19323 PrototypeIterator::END_AT_NULL); |
| 19278 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { | 19324 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { |
| 19279 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; | 19325 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; |
| 19280 } | 19326 } |
| 19281 return false; | 19327 return false; |
| 19282 } | 19328 } |
| 19283 | 19329 |
| 19284 } // namespace internal | 19330 } // namespace internal |
| 19285 } // namespace v8 | 19331 } // namespace v8 |
| OLD | NEW |