GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_buffer.h Lines: 4 6 66.7 %
Date: 2019-09-12 22:30:12 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
namespace Buffer {
31
32
static const unsigned int kMaxLength = v8::TypedArray::kMaxLength;
33
34
typedef void (*FreeCallback)(char* data, void* hint);
35
36
NODE_EXTERN bool HasInstance(v8::Local<v8::Value> val);
37
NODE_EXTERN bool HasInstance(v8::Local<v8::Object> val);
38
NODE_EXTERN char* Data(v8::Local<v8::Value> val);
39
NODE_EXTERN char* Data(v8::Local<v8::Object> val);
40
NODE_EXTERN size_t Length(v8::Local<v8::Value> val);
41
NODE_EXTERN size_t Length(v8::Local<v8::Object> val);
42
43
// public constructor - data is copied
44
NODE_EXTERN v8::MaybeLocal<v8::Object> Copy(v8::Isolate* isolate,
45
                                            const char* data,
46
                                            size_t len);
47
48
// public constructor
49
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
50
51
// public constructor from string
52
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
53
                                           v8::Local<v8::String> string,
54
                                           enum encoding enc = UTF8);
55
56
// public constructor - data is used, callback is passed data on object gc
57
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
58
                                           char* data,
59
                                           size_t length,
60
                                           FreeCallback callback,
61
                                           void* hint);
62
63
// public constructor - data is used.
64
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
65
                                           char* data,
66
                                           size_t len);
67
68
// This is verbose to be explicit with inline commenting
69
285922
static inline bool IsWithinBounds(size_t off, size_t len, size_t max) {
70
  // Asking to seek too far into the buffer
71
  // check to avoid wrapping in subsequent subtraction
72
285922
  if (off > max)
73
    return false;
74
75
  // Asking for more than is left over in the buffer
76
285922
  if (max - off < len)
77
    return false;
78
79
  // Otherwise we're in bounds
80
285922
  return true;
81
}
82
83
}  // namespace Buffer
84
}  // namespace node
85
86
#endif  // SRC_NODE_BUFFER_H_