Support converting Buffer to Value
This commit is contained in:
parent
d2681d2ba1
commit
ebb1ddc0df
3 changed files with 16 additions and 3 deletions
2
atom.gyp
2
atom.gyp
|
@ -224,8 +224,6 @@
|
|||
# Defined in Chromium but not exposed in its gyp file.
|
||||
'V8_USE_EXTERNAL_STARTUP_DATA',
|
||||
'ENABLE_PLUGINS',
|
||||
# Needed by Node.
|
||||
'NODE_WANT_INTERNALS=1',
|
||||
],
|
||||
'sources': [
|
||||
'<@(lib_sources)',
|
||||
|
|
|
@ -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…
Reference in a new issue