1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/objects/embedder-data-array.h"
6
7#include "src/execution/isolate.h"
8#include "src/objects/embedder-data-array-inl.h"
9
10namespace v8 {
11namespace internal {
12
13// static
14Handle<EmbedderDataArray> EmbedderDataArray::EnsureCapacity(
15    Isolate* isolate, Handle<EmbedderDataArray> array, int index) {
16  if (index < array->length()) return array;
17  DCHECK_LT(index, kMaxLength);
18  Handle<EmbedderDataArray> new_array =
19      isolate->factory()->NewEmbedderDataArray(index + 1);
20  DisallowGarbageCollection no_gc;
21  // Last new space allocation does not require any write barriers.
22  size_t size = array->length() * kEmbedderDataSlotSize;
23  MemCopy(reinterpret_cast<void*>(new_array->slots_start()),
24          reinterpret_cast<void*>(array->slots_start()), size);
25  return new_array;
26}
27
28}  // namespace internal
29}  // namespace v8
30