Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/PostTraversalTask.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_PostTraversalTask_h
8
#define mozilla_PostTraversalTask_h
9
10
#include "nscore.h"
11
12
/* a task to be performed immediately after a Servo traversal */
13
14
namespace mozilla {
15
namespace dom {
16
class FontFace;
17
class FontFaceSet;
18
} // namespace dom
19
} // namespace mozilla
20
class gfxUserFontEntry;
21
22
namespace mozilla {
23
24
/**
25
 * A PostTraversalTask is a task to be performed immediately after a Servo
26
 * traversal.  There are just a few tasks we need to perform, so we use this
27
 * class rather than Runnables, to avoid virtual calls and some allocations.
28
 *
29
 * A PostTraversalTask is only safe to run immediately after the Servo
30
 * traversal, since it can hold raw pointers to DOM objects.
31
 */
32
class PostTraversalTask
33
{
34
public:
35
  static PostTraversalTask ResolveFontFaceLoadedPromise(dom::FontFace* aFontFace)
36
0
  {
37
0
    auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
38
0
    task.mTarget = aFontFace;
39
0
    return task;
40
0
  }
41
42
  static PostTraversalTask RejectFontFaceLoadedPromise(dom::FontFace* aFontFace,
43
                                                       nsresult aResult)
44
0
  {
45
0
    auto task = PostTraversalTask(Type::ResolveFontFaceLoadedPromise);
46
0
    task.mTarget = aFontFace;
47
0
    task.mResult = aResult;
48
0
    return task;
49
0
  }
50
51
  static PostTraversalTask DispatchLoadingEventAndReplaceReadyPromise(
52
    dom::FontFaceSet* aFontFaceSet)
53
0
  {
54
0
    auto task =
55
0
      PostTraversalTask(Type::DispatchLoadingEventAndReplaceReadyPromise);
56
0
    task.mTarget = aFontFaceSet;
57
0
    return task;
58
0
  }
59
60
  static PostTraversalTask DispatchFontFaceSetCheckLoadingFinishedAfterDelay(
61
    dom::FontFaceSet* aFontFaceSet)
62
0
  {
63
0
    auto task =
64
0
      PostTraversalTask(Type::DispatchFontFaceSetCheckLoadingFinishedAfterDelay);
65
0
    task.mTarget = aFontFaceSet;
66
0
    return task;
67
0
  }
68
69
  static PostTraversalTask LoadFontEntry(gfxUserFontEntry* aFontEntry)
70
0
  {
71
0
    auto task = PostTraversalTask(Type::LoadFontEntry);
72
0
    task.mTarget = aFontEntry;
73
0
    return task;
74
0
  }
75
76
  void Run();
77
78
private:
79
  // For any new raw pointer type that we need to store in a PostTraversalTask,
80
  // please add an assertion that class' destructor that we are not in a Servo
81
  // traversal, to protect against the possibility of having dangling pointers.
82
  enum class Type
83
  {
84
    // mTarget (FontFace*)
85
    ResolveFontFaceLoadedPromise,
86
87
    // mTarget (FontFace*)
88
    // mResult
89
    RejectFontFaceLoadedPromise,
90
91
    // mTarget (FontFaceSet*)
92
    DispatchLoadingEventAndReplaceReadyPromise,
93
94
    // mTarget (FontFaceSet*)
95
    DispatchFontFaceSetCheckLoadingFinishedAfterDelay,
96
97
    // mTarget (gfxUserFontEntry*)
98
    LoadFontEntry,
99
  };
100
101
  explicit PostTraversalTask(Type aType)
102
    : mType(aType)
103
    , mTarget(nullptr)
104
    , mResult(NS_OK)
105
0
  {
106
0
  }
107
108
  Type mType;
109
  void* mTarget;
110
  nsresult mResult;
111
};
112
113
} // namespace mozilla
114
115
#endif // mozilla_PostTraversalTask_h