GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_blob.h Lines: 11 20 55.0 %
Date: 2021-04-22 04:13:51 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_NODE_BLOB_H_
2
#define SRC_NODE_BLOB_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "async_wrap.h"
7
#include "base_object.h"
8
#include "env.h"
9
#include "memory_tracker.h"
10
#include "node_internals.h"
11
#include "node_worker.h"
12
#include "v8.h"
13
14
#include <vector>
15
16
namespace node {
17
18
716
struct BlobEntry {
19
  std::shared_ptr<v8::BackingStore> store;
20
  size_t length;
21
  size_t offset;
22
};
23
24
98
class Blob : public BaseObject {
25
 public:
26
  static void RegisterExternalReferences(
27
      ExternalReferenceRegistry* registry);
28
  static void Initialize(Environment* env, v8::Local<v8::Object> target);
29
30
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
31
  static void ToArrayBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
32
  static void ToSlice(const v8::FunctionCallbackInfo<v8::Value>& args);
33
34
  static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
35
      Environment* env);
36
37
  static BaseObjectPtr<Blob> Create(
38
      Environment* env,
39
      const std::vector<BlobEntry> store,
40
      size_t length);
41
42
  static bool HasInstance(Environment* env, v8::Local<v8::Value> object);
43
44
78
  const std::vector<BlobEntry> entries() const {
45
78
    return store_;
46
  }
47
48
  void MemoryInfo(MemoryTracker* tracker) const override;
49
  SET_MEMORY_INFO_NAME(Blob);
50
  SET_SELF_SIZE(Blob);
51
52
  // Copies the contents of the Blob into an ArrayBuffer.
53
  v8::MaybeLocal<v8::Value> GetArrayBuffer(Environment* env);
54
55
  BaseObjectPtr<Blob> Slice(Environment* env, size_t start, size_t end);
56
57
95
  inline size_t length() const { return length_; }
58
59
2
  class BlobTransferData : public worker::TransferData {
60
   public:
61
1
    explicit BlobTransferData(
62
        const std::vector<BlobEntry>& store,
63
      size_t length)
64
1
        : store_(store),
65
1
          length_(length) {}
66
67
    BaseObjectPtr<BaseObject> Deserialize(
68
        Environment* env,
69
        v8::Local<v8::Context> context,
70
        std::unique_ptr<worker::TransferData> self) override;
71
72
    SET_MEMORY_INFO_NAME(BlobTransferData)
73
    SET_SELF_SIZE(BlobTransferData)
74
    SET_NO_MEMORY_INFO()
75
76
   private:
77
    std::vector<BlobEntry> store_;
78
    size_t length_ = 0;
79
  };
80
81
  BaseObject::TransferMode GetTransferMode() const override;
82
  std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
83
84
  Blob(
85
      Environment* env,
86
      v8::Local<v8::Object> obj,
87
      const std::vector<BlobEntry>& store,
88
      size_t length);
89
90
 private:
91
  std::vector<BlobEntry> store_;
92
  size_t length_ = 0;
93
};
94
95
68
class FixedSizeBlobCopyJob : public AsyncWrap, public ThreadPoolWork {
96
 public:
97
  enum class Mode {
98
    SYNC,
99
    ASYNC
100
  };
101
102
  static void RegisterExternalReferences(
103
      ExternalReferenceRegistry* registry);
104
  static void Initialize(Environment* env, v8::Local<v8::Object> target);
105
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
106
  static void Run(const v8::FunctionCallbackInfo<v8::Value>& args);
107
108
  bool IsNotIndicativeOfMemoryLeakAtExit() const override {
109
    return true;
110
  }
111
112
  void DoThreadPoolWork() override;
113
  void AfterThreadPoolWork(int status) override;
114
115
34
  Mode mode() const { return mode_; }
116
117
  void MemoryInfo(MemoryTracker* tracker) const override;
118
  SET_MEMORY_INFO_NAME(FixedSizeBlobCopyJob)
119
  SET_SELF_SIZE(FixedSizeBlobCopyJob)
120
121
 private:
122
  FixedSizeBlobCopyJob(
123
    Environment* env,
124
    v8::Local<v8::Object> object,
125
    Blob* blob,
126
    Mode mode = Mode::ASYNC);
127
128
  Mode mode_;
129
  std::vector<BlobEntry> source_;
130
  std::shared_ptr<v8::BackingStore> destination_;
131
  size_t length_ = 0;
132
};
133
134
}  // namespace node
135
136
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
137
#endif  // SRC_NODE_BLOB_H_