GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/node_buffer.h Lines: 4 6 66.7 %
Date: 2017-06-14 Branches: 2 4 50.0 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
#ifndef SRC_NODE_BUFFER_H_
23
#define SRC_NODE_BUFFER_H_
24
25
#include "node.h"
26
#include "v8.h"
27
28
namespace node {
29
30
extern bool zero_fill_all_buffers;
31
32
namespace Buffer {
33
34
static const unsigned int kMaxLength =
35
    sizeof(int32_t) == sizeof(intptr_t) ? 0x3fffffff : 0x7fffffff;
36
37
NODE_EXTERN typedef void (*FreeCallback)(char* data, void* hint);
38
39
NODE_EXTERN bool HasInstance(v8::Local<v8::Value> val);
40
NODE_EXTERN bool HasInstance(v8::Local<v8::Object> val);
41
NODE_EXTERN char* Data(v8::Local<v8::Value> val);
42
NODE_EXTERN char* Data(v8::Local<v8::Object> val);
43
NODE_EXTERN size_t Length(v8::Local<v8::Value> val);
44
NODE_EXTERN size_t Length(v8::Local<v8::Object> val);
45
46
// public constructor - data is copied
47
NODE_EXTERN v8::MaybeLocal<v8::Object> Copy(v8::Isolate* isolate,
48
                                            const char* data,
49
                                            size_t len);
50
51
// public constructor
52
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
53
54
// public constructor from string
55
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
56
                                           v8::Local<v8::String> string,
57
                                           enum encoding enc = UTF8);
58
59
// public constructor - data is used, callback is passed data on object gc
60
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
61
                                           char* data,
62
                                           size_t length,
63
                                           FreeCallback callback,
64
                                           void* hint);
65
66
// public constructor - data is used.
67
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
68
                                           char* data,
69
                                           size_t len);
70
71
// This is verbose to be explicit with inline commenting
72
51455
static inline bool IsWithinBounds(size_t off, size_t len, size_t max) {
73
  // Asking to seek too far into the buffer
74
  // check to avoid wrapping in subsequent subtraction
75
51455
  if (off > max)
76
    return false;
77
78
  // Asking for more than is left over in the buffer
79
51455
  if (max - off < len)
80
    return false;
81
82
  // Otherwise we're in bounds
83
51455
  return true;
84
}
85
86
}  // namespace Buffer
87
}  // namespace node
88
89
#endif  // SRC_NODE_BUFFER_H_