summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/bindings/wrapper_type_info.cc
blob: 45c8cc662ccb4b70276d12bcad4a48e2586b6bc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/bindings/wrapper_type_info.h"

#include "third_party/blink/renderer/platform/bindings/custom_wrappable.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/heap/heap_stats_collector.h"

namespace blink {

static_assert(offsetof(struct WrapperTypeInfo, gin_embedder) ==
                  offsetof(struct gin::WrapperInfo, embedder),
              "offset of WrapperTypeInfo.ginEmbedder must be the same as "
              "gin::WrapperInfo.embedder");

void WrapperTypeInfo::WrapperCreated() {
  ThreadState::Current()->Heap().stats_collector()->IncreaseWrapperCount(1);
}

void WrapperTypeInfo::WrapperDestroyed() {
  ThreadHeapStatsCollector* stats_collector =
      ThreadState::Current()->Heap().stats_collector();
  stats_collector->DecreaseWrapperCount(1);
  stats_collector->IncreaseCollectedWrapperCount(1);
}

void WrapperTypeInfo::Trace(Visitor* visitor, void* impl) const {
  switch (wrapper_class_id) {
    case WrapperTypeInfo::kNodeClassId:
    case WrapperTypeInfo::kObjectClassId:
      visitor->Trace(reinterpret_cast<ScriptWrappable*>(impl));
      break;
    case WrapperTypeInfo::kCustomWrappableId:
      visitor->Trace(reinterpret_cast<CustomWrappable*>(impl));
      break;
    default:
      NOTREACHED();
  }
}

void WrapperTypeInfo::TraceWithWrappers(Visitor* visitor, void* impl) const {
  switch (wrapper_class_id) {
    case WrapperTypeInfo::kNodeClassId:
    case WrapperTypeInfo::kObjectClassId:
      visitor->TraceWithWrappers(reinterpret_cast<ScriptWrappable*>(impl));
      break;
    case WrapperTypeInfo::kCustomWrappableId:
      visitor->TraceWithWrappers(reinterpret_cast<CustomWrappable*>(impl));
      break;
    default:
      NOTREACHED();
  }
}

}  // namespace blink