GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/out/../src/node_buffer.h Lines: 2 2 100.0 %
Date: 2016-12-18 Branches: 8 16 50.0 %

Line Branch Exec Source
1
#ifndef SRC_NODE_BUFFER_H_
2
#define SRC_NODE_BUFFER_H_
3
4
#include "node.h"
5
#include "v8.h"
6
7
namespace node {
8
9
extern bool zero_fill_all_buffers;
10
11
namespace Buffer {
12
13
static const unsigned int kMaxLength =
14
    sizeof(int32_t) == sizeof(intptr_t) ? 0x3fffffff : 0x7fffffff;
15
16
NODE_EXTERN typedef void (*FreeCallback)(char* data, void* hint);
17
18
NODE_EXTERN bool HasInstance(v8::Local<v8::Value> val);
19
NODE_EXTERN bool HasInstance(v8::Local<v8::Object> val);
20
NODE_EXTERN char* Data(v8::Local<v8::Value> val);
21
NODE_EXTERN char* Data(v8::Local<v8::Object> val);
22
NODE_EXTERN size_t Length(v8::Local<v8::Value> val);
23
NODE_EXTERN size_t Length(v8::Local<v8::Object> val);
24
25
// public constructor - data is copied
26
NODE_EXTERN v8::MaybeLocal<v8::Object> Copy(v8::Isolate* isolate,
27
                                            const char* data,
28
                                            size_t len);
29
30
// public constructor
31
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
32
33
// public constructor from string
34
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
35
                                           v8::Local<v8::String> string,
36
                                           enum encoding enc = UTF8);
37
38
// public constructor - data is used, callback is passed data on object gc
39
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
40
                                           char* data,
41
                                           size_t length,
42
                                           FreeCallback callback,
43
                                           void* hint);
44
45
// public constructor - data is used.
46
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
47
                                           char* data,
48
                                           size_t len);
49
50
// This is verbose to be explicit with inline commenting
51
static inline bool IsWithinBounds(size_t off, size_t len, size_t max) {
52
  // Asking to seek too far into the buffer
53
  // check to avoid wrapping in subsequent subtraction
54


35391
  if (off > max)
55
    return false;
56
57
  // Asking for more than is left over in the buffer
58


35391
  if (max - off < len)
59
    return false;
60
61
  // Otherwise we're in bounds
62
  return true;
63
}
64
65
}  // namespace Buffer
66
}  // namespace node
67
68
#endif  // SRC_NODE_BUFFER_H_