Support converting Buffer to Value
This commit is contained in:
parent
d2681d2ba1
commit
ebb1ddc0df
3 changed files with 16 additions and 3 deletions
|
@ -11,6 +11,7 @@
|
|||
#include "base/logging.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/values.h"
|
||||
#include "vendor/node/src/node_buffer.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -258,6 +259,10 @@ base::Value* V8ValueConverter::FromV8ValueImpl(
|
|||
return FromV8Object(val->ToObject(), state, isolate);
|
||||
}
|
||||
|
||||
if (node::Buffer::HasInstance(val)) {
|
||||
return FromNodeBuffer(val, state, isolate);
|
||||
}
|
||||
|
||||
if (val->IsObject()) {
|
||||
return FromV8Object(val->ToObject(), state, isolate);
|
||||
}
|
||||
|
@ -305,6 +310,14 @@ base::Value* V8ValueConverter::FromV8Array(
|
|||
return result;
|
||||
}
|
||||
|
||||
base::Value* V8ValueConverter::FromNodeBuffer(
|
||||
v8::Local<v8::Value> value,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const {
|
||||
return base::BinaryValue::CreateWithCopiedBuffer(
|
||||
node::Buffer::Data(value), node::Buffer::Length(value));
|
||||
}
|
||||
|
||||
base::Value* V8ValueConverter::FromV8Object(
|
||||
v8::Local<v8::Object> val,
|
||||
FromV8ValueState* state,
|
||||
|
|
|
@ -48,7 +48,9 @@ class V8ValueConverter {
|
|||
base::Value* FromV8Array(v8::Local<v8::Array> array,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const;
|
||||
|
||||
base::Value* FromNodeBuffer(v8::Local<v8::Value> value,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const;
|
||||
base::Value* FromV8Object(v8::Local<v8::Object> object,
|
||||
FromV8ValueState* state,
|
||||
v8::Isolate* isolate) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue