Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 00721c2d1bbe1b08e95c134083f9e9d998c3ad9d..9916e6e1a845b4e40689e0e2f272258b890f7faf 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -10177,22 +10177,74 @@ bool ArrayList::IsFull() { |
return kFirstIndex + Length() == capacity; |
} |
+namespace { |
-Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) { |
+Handle<FixedArray> EnsureSpaceInFixedArray(Handle<FixedArray> array, |
+ int length) { |
int capacity = array->length(); |
- bool empty = (capacity == 0); |
- if (capacity < kFirstIndex + length) { |
+ if (capacity < length) { |
Isolate* isolate = array->GetIsolate(); |
- int new_capacity = kFirstIndex + length; |
+ int new_capacity = length; |
new_capacity = new_capacity + Max(new_capacity / 2, 2); |
int grow_by = new_capacity - capacity; |
array = Handle<ArrayList>::cast( |
isolate->factory()->CopyFixedArrayAndGrow(array, grow_by)); |
- if (empty) array->SetLength(0); |
} |
return array; |
} |
+} // namespace |
+ |
+Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) { |
+ const bool empty = (array->length() == 0); |
+ auto ret = Handle<ArrayList>::cast( |
+ EnsureSpaceInFixedArray(array, kFirstIndex + length)); |
+ if (empty) ret->SetLength(0); |
+ return ret; |
+} |
+ |
+// static |
+Handle<FrameArray> FrameArray::AppendJSFrame(Handle<FrameArray> in, |
+ Handle<Object> receiver, |
+ Handle<JSFunction> function, |
+ Handle<AbstractCode> code, |
+ int offset) { |
+ const int frame_count = in->FrameCount(); |
+ const int new_length = LengthFor(frame_count + 1); |
+ Handle<FrameArray> array = EnsureSpace(in, new_length); |
+ array->SetReceiver(frame_count, *receiver); |
+ array->SetFunction(frame_count, *function); |
+ array->SetCode(frame_count, *code); |
+ array->SetOffset(frame_count, Smi::FromInt(offset)); |
+ array->set(kFrameCountIndex, Smi::FromInt(frame_count + 1)); |
+ return array; |
+} |
+ |
+// static |
+Handle<FrameArray> FrameArray::AppendWasmFrame(Handle<FrameArray> in, |
+ Handle<Object> wasm_object, |
+ int wasm_function_index, |
+ Handle<AbstractCode> code, |
+ int offset) { |
+ const int frame_count = in->FrameCount(); |
+ const int new_length = LengthFor(frame_count + 1); |
+ Handle<FrameArray> array = EnsureSpace(in, new_length); |
+ array->SetWasmObject(frame_count, *wasm_object); |
+ array->SetWasmFunctionIndex(frame_count, Smi::FromInt(wasm_function_index)); |
+ array->SetCode(frame_count, *code); |
+ array->SetOffset(frame_count, Smi::FromInt(offset)); |
+ array->set(kFrameCountIndex, Smi::FromInt(frame_count + 1)); |
+ return array; |
+} |
+ |
+void FrameArray::ShrinkToFit() { Shrink(LengthFor(FrameCount())); } |
+ |
+// static |
+Handle<FrameArray> FrameArray::EnsureSpace(Handle<FrameArray> array, |
+ int length) { |
+ return Handle<FrameArray>::cast(EnsureSpaceInFixedArray(array, length)); |
+} |
+ |
Handle<DescriptorArray> DescriptorArray::Allocate(Isolate* isolate, |
int number_of_descriptors, |
int slack, |