GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/sharedarraybuffer_metadata.h Lines: 2 2 100.0 %
Date: 2019-09-25 22:36:03 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_SHAREDARRAYBUFFER_METADATA_H_
2
#define SRC_SHAREDARRAYBUFFER_METADATA_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "node.h"
7
#include <memory>
8
9
namespace node {
10
namespace worker {
11
12
class SharedArrayBufferMetadata;
13
14
// This is an object associated with a SharedArrayBuffer, which keeps track
15
// of a cross-thread reference count. Once a SharedArrayBuffer is transferred
16
// for the first time (or is attempted to be transferred), one of these objects
17
// is created, and the SharedArrayBuffer is moved from internalized mode into
18
// externalized mode (i.e. the JS engine no longer frees the memory on its own).
19
//
20
// This will always be referred to using a std::shared_ptr, since it keeps
21
// a reference count and is guaranteed to be thread-safe.
22
typedef std::shared_ptr<SharedArrayBufferMetadata>
23
    SharedArrayBufferMetadataReference;
24
25
class SharedArrayBufferMetadata
26
    : public std::enable_shared_from_this<SharedArrayBufferMetadata> {
27
 public:
28
  static SharedArrayBufferMetadataReference ForSharedArrayBuffer(
29
      Environment* env,
30
      v8::Local<v8::Context> context,
31
      v8::Local<v8::SharedArrayBuffer> source);
32
  ~SharedArrayBufferMetadata();
33
34
  // Create a SharedArrayBuffer object for a specific Environment and Context.
35
  // The created SharedArrayBuffer will be in externalized mode and has
36
  // a hidden object attached to it, during whose lifetime the reference
37
  // count is increased by 1.
38
  v8::MaybeLocal<v8::SharedArrayBuffer> GetSharedArrayBuffer(
39
      Environment* env, v8::Local<v8::Context> context);
40
314
  std::shared_ptr<v8::ArrayBuffer::Allocator> allocator() const {
41
314
    return allocator_;
42
  }
43
44
  SharedArrayBufferMetadata(SharedArrayBufferMetadata&& other) = delete;
45
  SharedArrayBufferMetadata& operator=(
46
      SharedArrayBufferMetadata&& other) = delete;
47
  SharedArrayBufferMetadata& operator=(
48
      const SharedArrayBufferMetadata&) = delete;
49
  SharedArrayBufferMetadata(const SharedArrayBufferMetadata&) = delete;
50
51
 private:
52
  SharedArrayBufferMetadata(
53
      const v8::SharedArrayBuffer::Contents&,
54
      std::shared_ptr<v8::ArrayBuffer::Allocator>);
55
56
  // Attach a lifetime tracker object with a reference count to `target`.
57
  v8::Maybe<bool> AssignToSharedArrayBuffer(
58
      Environment* env,
59
      v8::Local<v8::Context> context,
60
      v8::Local<v8::SharedArrayBuffer> target);
61
62
  v8::SharedArrayBuffer::Contents contents_;
63
  std::shared_ptr<v8::ArrayBuffer::Allocator> allocator_;
64
};
65
66
}  // namespace worker
67
}  // namespace node
68
69
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
70
71
72
#endif  // SRC_SHAREDARRAYBUFFER_METADATA_H_