1// Copyright 2020 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/heap/local-factory.h"
6
7#include "src/common/globals.h"
8#include "src/execution/local-isolate.h"
9#include "src/handles/handles.h"
10#include "src/heap/concurrent-allocator-inl.h"
11#include "src/heap/local-heap-inl.h"
12#include "src/numbers/hash-seed-inl.h"
13#include "src/objects/fixed-array.h"
14#include "src/objects/heap-object.h"
15#include "src/objects/string.h"
16#include "src/roots/roots-inl.h"
17#include "src/strings/string-hasher.h"
18
19namespace v8 {
20namespace internal {
21
22#ifdef V8_SANDBOXED_EXTERNAL_POINTERS
23LocalFactory::LocalFactory(Isolate* isolate)
24    : roots_(isolate), isolate_for_sandbox_(isolate) {}
25#else
26LocalFactory::LocalFactory(Isolate* isolate) : roots_(isolate) {}
27#endif
28
29void LocalFactory::AddToScriptList(Handle<Script> shared) {
30// TODO(leszeks): Actually add the script to the main Isolate's script list,
31// in a thread-safe way.
32//
33// At the moment, we have to do one final fix-up during off-thread
34// finalization, where we add the created script to the script list, but this
35// relies on there being exactly one script created during the lifetime of
36// this LocalFactory.
37//
38// For now, prevent accidentaly creating more scripts that don't get added to
39// the script list with a simple DCHECK.
40#ifdef DEBUG
41  DCHECK(!a_script_was_added_to_the_script_list_);
42  a_script_was_added_to_the_script_list_ = true;
43#endif
44}
45
46HeapObject LocalFactory::AllocateRaw(int size, AllocationType allocation,
47                                     AllocationAlignment alignment) {
48  DCHECK(allocation == AllocationType::kOld ||
49         allocation == AllocationType::kSharedOld);
50  return HeapObject::FromAddress(isolate()->heap()->AllocateRawOrFail(
51      size, allocation, AllocationOrigin::kRuntime, alignment));
52}
53
54}  // namespace internal
55}  // namespace v8
56