File: heap_test_platform.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (105 lines) | stat: -rw-r--r-- 3,986 bytes parent folder | download | duplicates (5)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_TEST_PLATFORM_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_TEST_PLATFORM_H_

#include <memory>

#include "v8/include/v8-platform.h"

namespace blink {

// Tests do not require that tasks can actually run, just that they can posted.
class HeapTestingMockTaskRunner final : public v8::TaskRunner {
 public:
  bool IdleTasksEnabled() override { return false; }
  bool NonNestableTasksEnabled() const override { return false; }
  bool NonNestableDelayedTasksEnabled() const override { return false; }

 private:
  void PostTaskImpl(std::unique_ptr<v8::Task> task,
                    const v8::SourceLocation& location) override {}
  void PostNonNestableTaskImpl(std::unique_ptr<v8::Task> task,
                               const v8::SourceLocation& location) override {}
  void PostDelayedTaskImpl(std::unique_ptr<v8::Task> task,
                           double delay_in_seconds,
                           const v8::SourceLocation& location) override {}
  void PostNonNestableDelayedTaskImpl(
      std::unique_ptr<v8::Task> task,
      double delay_in_seconds,
      const v8::SourceLocation& location) override {}
  void PostIdleTaskImpl(std::unique_ptr<v8::IdleTask> task,
                        const v8::SourceLocation& location) override {}
};

class HeapTestingPlatformAdapter final : public v8::Platform {
 public:
  explicit HeapTestingPlatformAdapter(v8::Platform* platform)
      : platform_(platform),
        task_runner_(std::make_shared<HeapTestingMockTaskRunner>()) {}

  HeapTestingPlatformAdapter(const HeapTestingPlatformAdapter&) = delete;
  HeapTestingPlatformAdapter& operator=(const HeapTestingPlatformAdapter&) =
      delete;

  v8::PageAllocator* GetPageAllocator() final {
    return platform_->GetPageAllocator();
  }
  void OnCriticalMemoryPressure() final {
    platform_->OnCriticalMemoryPressure();
  }
  int NumberOfWorkerThreads() final {
    return platform_->NumberOfWorkerThreads();
  }
  std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
      v8::Isolate* isolate,
      v8::TaskPriority priority) final {
    // Provides task runner that allows for incremental tasks even in detached
    // mode.
    return task_runner_;
  }
  void PostTaskOnWorkerThreadImpl(v8::TaskPriority priority,
                                  std::unique_ptr<v8::Task> task,
                                  const v8::SourceLocation& location) final {
    platform_->PostTaskOnWorkerThread(priority, std::move(task), location);
  }
  void PostDelayedTaskOnWorkerThreadImpl(
      v8::TaskPriority priority,
      std::unique_ptr<v8::Task> task,
      double delay_in_seconds,
      const v8::SourceLocation& location) final {
    platform_->PostDelayedTaskOnWorkerThread(priority, std::move(task), delay_in_seconds, location);
  }
  bool IdleTasksEnabled(v8::Isolate* isolate) final {
    return platform_->IdleTasksEnabled(isolate);
  }
  std::unique_ptr<v8::JobHandle> CreateJobImpl(
      v8::TaskPriority priority,
      std::unique_ptr<v8::JobTask> job_task,
      const v8::SourceLocation& location) final {
    return platform_->CreateJob(priority, std::move(job_task));
  }
  double MonotonicallyIncreasingTime() final {
    return platform_->MonotonicallyIncreasingTime();
  }
  double CurrentClockTimeMillis() final {
    return platform_->CurrentClockTimeMillis();
  }
  StackTracePrinter GetStackTracePrinter() final {
    return platform_->GetStackTracePrinter();
  }
  v8::TracingController* GetTracingController() final {
    return platform_->GetTracingController();
  }
  void DumpWithoutCrashing() final { platform_->DumpWithoutCrashing(); }

 private:
  v8::Platform* platform_;
  std::shared_ptr<v8::TaskRunner> task_runner_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_TEST_PLATFORM_H_