diff options
author | Nathan Rajlich <nathan@tootallnate.net> | 2012-10-13 16:16:56 -0700 |
---|---|---|
committer | Nathan Rajlich <nathan@tootallnate.net> | 2012-10-13 16:16:56 -0700 |
commit | 4b238b4c2ae8f5cf409cea5ca214b480b00e1a86 (patch) | |
tree | 0c403c3a2f0f117bfe7230fc7bfbd197ebf78845 /src/node_buffer.cc | |
parent | 47643d2ec517ceb8f7ce180142262e393c4d8e89 (diff) | |
parent | 4a23add90f155e6761d443d1277a31c2a2a4abb2 (diff) | |
download | android-node-v8-4b238b4c2ae8f5cf409cea5ca214b480b00e1a86.tar.gz android-node-v8-4b238b4c2ae8f5cf409cea5ca214b480b00e1a86.tar.bz2 android-node-v8-4b238b4c2ae8f5cf409cea5ca214b480b00e1a86.zip |
Merge remote-tracking branch 'origin/v0.8'
Conflicts:
AUTHORS
ChangeLog
deps/uv/test/runner-win.c
doc/api/process.markdown
lib/repl.js
src/node_crypto.cc
src/node_version.h
Diffstat (limited to 'src/node_buffer.cc')
-rw-r--r-- | src/node_buffer.cc | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 11829dfa06..427647622d 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -24,6 +24,7 @@ #include "node_buffer.h" #include "v8.h" +#include "v8-profiler.h" #include <assert.h> #include <stdlib.h> // malloc, free @@ -33,9 +34,10 @@ # include <arpa/inet.h> // htons, htonl #endif - #define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define BUFFER_CLASS_ID (0xBABE) + namespace node { using namespace v8; @@ -188,6 +190,7 @@ Buffer::Buffer(Handle<Object> wrapper, size_t length) : ObjectWrap() { length_ = 0; callback_ = NULL; + handle_.SetWrapperClassId(BUFFER_CLASS_ID); Replace(NULL, length, NULL, NULL); } @@ -730,6 +733,61 @@ bool Buffer::HasInstance(v8::Handle<v8::Value> val) { } +class RetainedBufferInfo: public v8::RetainedObjectInfo { +public: + RetainedBufferInfo(Buffer* buffer); + virtual void Dispose(); + virtual bool IsEquivalent(RetainedObjectInfo* other); + virtual intptr_t GetHash(); + virtual const char* GetLabel(); + virtual intptr_t GetSizeInBytes(); +private: + Buffer* buffer_; + static const char label[]; +}; + +const char RetainedBufferInfo::label[] = "Buffer"; + + +RetainedBufferInfo::RetainedBufferInfo(Buffer* buffer): buffer_(buffer) { +} + + +void RetainedBufferInfo::Dispose() { + buffer_ = NULL; + delete this; +} + + +bool RetainedBufferInfo::IsEquivalent(RetainedObjectInfo* other) { + return label == other->GetLabel() && + buffer_ == static_cast<RetainedBufferInfo*>(other)->buffer_; +} + + +intptr_t RetainedBufferInfo::GetHash() { + return reinterpret_cast<intptr_t>(buffer_); +} + + +const char* RetainedBufferInfo::GetLabel() { + return label; +} + + +intptr_t RetainedBufferInfo::GetSizeInBytes() { + return Buffer::Length(buffer_); +} + + +RetainedObjectInfo* WrapperInfo(uint16_t class_id, Handle<Value> wrapper) { + assert(class_id == BUFFER_CLASS_ID); + assert(Buffer::HasInstance(wrapper)); + Buffer* buffer = Buffer::Unwrap<Buffer>(wrapper.As<Object>()); + return new RetainedBufferInfo(buffer); +} + + void Buffer::Initialize(Handle<Object> target) { HandleScope scope; @@ -777,6 +835,8 @@ void Buffer::Initialize(Handle<Object> target) { Buffer::MakeFastBuffer); target->Set(String::NewSymbol("SlowBuffer"), constructor_template->GetFunction()); + + HeapProfiler::DefineWrapperClass(BUFFER_CLASS_ID, WrapperInfo); } |