diff options
author | Fedor Indutny <fedor@indutny.com> | 2015-03-07 16:42:02 -0500 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2015-03-07 18:51:05 -0500 |
commit | fe36076c78f60e61b67e6439eb7b759c4596faab (patch) | |
tree | 31f1a66e1f6f33c82f5170f0021c353b20044191 /src/stream_base-inl.h | |
parent | 7f4c95e16078451ee35dd61aba0f9d5fe99cc710 (diff) | |
download | node-new-fe36076c78f60e61b67e6439eb7b759c4596faab.tar.gz |
stream_base: WriteWrap::New/::Dispose
Encapsulate allocation/disposal of `WriteWrap` instances into the
`WriteWrap` class itself.
PR-URL: https://github.com/iojs/io.js/pull/1090
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r-- | src/stream_base-inl.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 46d9f78905..8f7f5fea41 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -15,6 +15,7 @@ using v8::FunctionTemplate; using v8::Handle; using v8::HandleScope; using v8::Local; +using v8::Object; using v8::PropertyAttribute; using v8::PropertyCallbackInfo; using v8::String; @@ -82,6 +83,31 @@ void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) { args.GetReturnValue().Set((wrap->*Method)(args)); } + +WriteWrap* WriteWrap::New(Environment* env, + Local<Object> obj, + StreamBase* wrap, + DoneCb cb, + size_t extra) { + size_t storage_size = ROUND_UP(sizeof(WriteWrap), kAlignSize) + extra; + char* storage = new char[storage_size]; + + return new(storage) WriteWrap(env, obj, wrap, cb); +} + + +void WriteWrap::Dispose() { + this->~WriteWrap(); + delete[] reinterpret_cast<char*>(this); +} + + +char* WriteWrap::Extra(size_t offset) { + return reinterpret_cast<char*>(this) + + ROUND_UP(sizeof(*this), kAlignSize) + + offset; +} + } // namespace node #endif // SRC_STREAM_BASE_INL_H_ |