GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/stream_base-inl.h Lines: 54 55 98.2 %
Date: 2017-11-19 Branches: 44 80 55.0 %

Line Branch Exec Source
1
#ifndef SRC_STREAM_BASE_INL_H_
2
#define SRC_STREAM_BASE_INL_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "stream_base.h"
7
8
#include "node.h"
9
#include "env-inl.h"
10
#include "v8.h"
11
12
namespace node {
13
14
using v8::AccessorSignature;
15
using v8::External;
16
using v8::FunctionCallbackInfo;
17
using v8::FunctionTemplate;
18
using v8::HandleScope;
19
using v8::Local;
20
using v8::Object;
21
using v8::PropertyAttribute;
22
using v8::PropertyCallbackInfo;
23
using v8::String;
24
using v8::Value;
25
26
using AsyncHooks = Environment::AsyncHooks;
27
28
template <class Base>
29
10639
void StreamBase::AddMethods(Environment* env,
30
                            Local<FunctionTemplate> t,
31
                            int flags) {
32
10639
  HandleScope scope(env->isolate());
33
34
  enum PropertyAttribute attributes =
35
      static_cast<PropertyAttribute>(
36
10639
          v8::ReadOnly | v8::DontDelete | v8::DontEnum);
37
  Local<AccessorSignature> signature =
38
10639
      AccessorSignature::New(env->isolate(), t);
39
42556
  t->PrototypeTemplate()->SetAccessor(env->fd_string(),
40
                                      GetFD<Base>,
41
                                      nullptr,
42
                                      env->as_external(),
43
                                      v8::DEFAULT,
44
                                      attributes,
45
                                      signature);
46
47
42556
  t->PrototypeTemplate()->SetAccessor(env->external_stream_string(),
48
                                      GetExternal<Base>,
49
                                      nullptr,
50
                                      env->as_external(),
51
                                      v8::DEFAULT,
52
                                      attributes,
53
                                      signature);
54
55
42556
  t->PrototypeTemplate()->SetAccessor(env->bytes_read_string(),
56
                                      GetBytesRead<Base>,
57
                                      nullptr,
58
                                      env->as_external(),
59
                                      v8::DEFAULT,
60
                                      attributes,
61
                                      signature);
62
63
10639
  env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>);
64
10639
  env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>);
65
10639
  if ((flags & kFlagNoShutdown) == 0)
66
7202
    env->SetProtoMethod(t, "shutdown", JSMethod<Base, &StreamBase::Shutdown>);
67
10639
  if ((flags & kFlagHasWritev) != 0)
68
7352
    env->SetProtoMethod(t, "writev", JSMethod<Base, &StreamBase::Writev>);
69
10639
  env->SetProtoMethod(t,
70
                      "writeBuffer",
71
                      JSMethod<Base, &StreamBase::WriteBuffer>);
72
10639
  env->SetProtoMethod(t,
73
                      "writeAsciiString",
74
                      JSMethod<Base, &StreamBase::WriteString<ASCII> >);
75
10639
  env->SetProtoMethod(t,
76
                      "writeUtf8String",
77
                      JSMethod<Base, &StreamBase::WriteString<UTF8> >);
78
10639
  env->SetProtoMethod(t,
79
                      "writeUcs2String",
80
                      JSMethod<Base, &StreamBase::WriteString<UCS2> >);
81
10639
  env->SetProtoMethod(t,
82
                      "writeLatin1String",
83
10639
                      JSMethod<Base, &StreamBase::WriteString<LATIN1> >);
84
10639
}
85
86
87
template <class Base>
88
96
void StreamBase::GetFD(Local<String> key,
89
                       const PropertyCallbackInfo<Value>& args) {
90
  // Mimic implementation of StreamBase::GetFD() and UDPWrap::GetFD().
91
  Base* handle;
92
96
  ASSIGN_OR_RETURN_UNWRAP(&handle,
93
                          args.This(),
94
                          args.GetReturnValue().Set(UV_EINVAL));
95
96
96
  StreamBase* wrap = static_cast<StreamBase*>(handle);
97
96
  if (!wrap->IsAlive())
98
    return args.GetReturnValue().Set(UV_EINVAL);
99
100
288
  args.GetReturnValue().Set(wrap->GetFD());
101
}
102
103
104
template <class Base>
105
7170
void StreamBase::GetBytesRead(Local<String> key,
106
                              const PropertyCallbackInfo<Value>& args) {
107
  // The handle instance hasn't been set. So no bytes could have been read.
108
  Base* handle;
109
14342
  ASSIGN_OR_RETURN_UNWRAP(&handle,
110
                          args.This(),
111
                          args.GetReturnValue().Set(0));
112
113
7169
  StreamBase* wrap = static_cast<StreamBase*>(handle);
114
  // uint64_t -> double. 53bits is enough for all real cases.
115
21507
  args.GetReturnValue().Set(static_cast<double>(wrap->bytes_read_));
116
}
117
118
119
template <class Base>
120
4269
void StreamBase::GetExternal(Local<String> key,
121
                             const PropertyCallbackInfo<Value>& args) {
122
  Base* handle;
123
8538
  ASSIGN_OR_RETURN_UNWRAP(&handle, args.This());
124
125
4269
  StreamBase* wrap = static_cast<StreamBase*>(handle);
126
4269
  Local<External> ext = External::New(args.GetIsolate(), wrap);
127
8538
  args.GetReturnValue().Set(ext);
128
}
129
130
131
template <class Base,
132
          int (StreamBase::*Method)(const FunctionCallbackInfo<Value>& args)>
133
76782
void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) {
134
  Base* handle;
135




76783
  ASSIGN_OR_RETURN_UNWRAP(&handle, args.Holder());
136
137




76782
  StreamBase* wrap = static_cast<StreamBase*>(handle);
138




76782
  if (!wrap->IsAlive())
139
2
    return args.GetReturnValue().Set(UV_EINVAL);
140
141
76781
  AsyncHooks::InitScope init_scope(handle->env(), handle->get_async_id());
142
230343
  args.GetReturnValue().Set((wrap->*Method)(args));
143
}
144
145
146
18908
WriteWrap* WriteWrap::New(Environment* env,
147
                          Local<Object> obj,
148
                          StreamBase* wrap,
149
                          DoneCb cb,
150
                          size_t extra) {
151
18908
  size_t storage_size = ROUND_UP(sizeof(WriteWrap), kAlignSize) + extra;
152
18908
  char* storage = new char[storage_size];
153
154
18908
  return new(storage) WriteWrap(env, obj, wrap, cb, storage_size);
155
}
156
157
158
18893
void WriteWrap::Dispose() {
159
18893
  this->~WriteWrap();
160
18893
  delete[] reinterpret_cast<char*>(this);
161
18893
}
162
163
164
33064
char* WriteWrap::Extra(size_t offset) {
165
  return reinterpret_cast<char*>(this) +
166
66128
         ROUND_UP(sizeof(*this), kAlignSize) +
167
66128
         offset;
168
}
169
170
1704
size_t WriteWrap::ExtraSize() const {
171
1704
  return storage_size_ - ROUND_UP(sizeof(*this), kAlignSize);
172
}
173
174
}  // namespace node
175
176
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
177
178
#endif  // SRC_STREAM_BASE_INL_H_