|
|
@ -61,6 +61,7 @@ using namespace v8; |
|
|
|
static Persistent<String> length_symbol; |
|
|
|
static Persistent<String> chars_written_sym; |
|
|
|
static Persistent<String> write_sym; |
|
|
|
static Persistent<Function> fast_buffer_constructor; |
|
|
|
Persistent<FunctionTemplate> Buffer::constructor_template; |
|
|
|
|
|
|
|
|
|
|
@ -913,14 +914,23 @@ bool Buffer::HasInstance(Handle<Value> val) { |
|
|
|
if (!val->IsObject()) return false; |
|
|
|
Local<Object> obj = val->ToObject(); |
|
|
|
|
|
|
|
if (obj->GetIndexedPropertiesExternalArrayDataType() == kExternalUnsignedByteArray) |
|
|
|
return true; |
|
|
|
ExternalArrayType type = obj->GetIndexedPropertiesExternalArrayDataType(); |
|
|
|
if (type != kExternalUnsignedByteArray) |
|
|
|
return false; |
|
|
|
|
|
|
|
// Also check for SlowBuffers that are empty.
|
|
|
|
if (constructor_template->HasInstance(obj)) |
|
|
|
return true; |
|
|
|
|
|
|
|
return false; |
|
|
|
assert(!fast_buffer_constructor.IsEmpty()); |
|
|
|
return obj->GetConstructor()->StrictEquals(fast_buffer_constructor); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> SetFastBufferConstructor(const Arguments& args) { |
|
|
|
assert(args[0]->IsFunction()); |
|
|
|
fast_buffer_constructor = Persistent<Function>::New(args[0].As<Function>()); |
|
|
|
return Undefined(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1036,6 +1046,8 @@ void Buffer::Initialize(Handle<Object> target) { |
|
|
|
Buffer::MakeFastBuffer); |
|
|
|
|
|
|
|
target->Set(String::NewSymbol("SlowBuffer"), constructor_template->GetFunction()); |
|
|
|
target->Set(String::NewSymbol("setFastBufferConstructor"), |
|
|
|
FunctionTemplate::New(SetFastBufferConstructor)->GetFunction()); |
|
|
|
|
|
|
|
HeapProfiler::DefineWrapperClass(BUFFER_CLASS_ID, WrapperInfo); |
|
|
|
} |
|
|
|