v8Util = process.atomBinding 'v8_util'
# Convert a real value into meta data.
-valueToMeta = (sender, value) ->
+valueToMeta = (sender, value, optimizeSimpleObject=false) ->
meta = type: typeof value
meta.type = 'buffer' if Buffer.isBuffer value
meta.type = 'array' if Array.isArray value
meta.type = 'promise' if value? and value.constructor.name is 'Promise'
+ # Treat simple objects as value.
+ if optimizeSimpleObject and meta.type is 'object' and v8Util.getHiddenValue value, 'simple'
+ meta.type = 'value'
+
# Treat the arguments object as array.
meta.type = 'array' if meta.type is 'object' and value.callee? and value.length?
callFunction = (event, func, caller, args) ->
if v8Util.getHiddenValue(func, 'asynchronous') and typeof args[args.length - 1] isnt 'function'
args.push (ret) ->
- event.returnValue = valueToMeta event.sender, ret
+ event.returnValue = valueToMeta event.sender, ret, true
func.apply caller, args
else
ret = func.apply caller, args
- event.returnValue = valueToMeta event.sender, ret
+ event.returnValue = valueToMeta event.sender, ret, true
# Send by BrowserWindow when its render view is deleted.
process.on 'ATOM_BROWSER_RELEASE_RENDER_VIEW', (id) ->
v8::Local<v8::Value> Converter<gfx::Point>::ToV8(v8::Isolate* isolate,
const gfx::Point& val) {
- mate::Dictionary dict(isolate, v8::Object::New(isolate));
+ mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
+ dict.SetHidden("simple", true);
dict.Set("x", val.x());
dict.Set("y", val.y());
return dict.GetHandle();
v8::Local<v8::Value> Converter<gfx::Size>::ToV8(v8::Isolate* isolate,
const gfx::Size& val) {
- mate::Dictionary dict(isolate, v8::Object::New(isolate));
+ mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
+ dict.SetHidden("simple", true);
dict.Set("width", val.width());
dict.Set("height", val.height());
return dict.GetHandle();
v8::Local<v8::Value> Converter<gfx::Rect>::ToV8(v8::Isolate* isolate,
const gfx::Rect& val) {
- mate::Dictionary dict(isolate, v8::Object::New(isolate));
+ mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
+ dict.SetHidden("simple", true);
dict.Set("x", val.x());
dict.Set("y", val.y());
dict.Set("width", val.width());
v8::Local<v8::Value> Converter<gfx::Display>::ToV8(v8::Isolate* isolate,
const gfx::Display& val) {
- mate::Dictionary dict(isolate, v8::Object::New(isolate));
+ mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
+ dict.SetHidden("simple", true);
dict.Set("id", val.id());
dict.Set("bounds", val.bounds());
dict.Set("workArea", val.work_area());
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
+#include "native_mate/dictionary.h"
#include "vendor/node/src/node_buffer.h"
namespace atom {
v8::Local<v8::Value> V8ValueConverter::ToV8Object(
v8::Isolate* isolate, const base::DictionaryValue* val) const {
- v8::Local<v8::Object> result(v8::Object::New(isolate));
+ mate::Dictionary result = mate::Dictionary::CreateEmpty(isolate);
+ result.SetHidden("simple", true);
for (base::DictionaryValue::Iterator iter(*val);
!iter.IsAtEnd(); iter.Advance()) {
CHECK(!child_v8.IsEmpty());
v8::TryCatch try_catch;
- result->Set(
- v8::String::NewFromUtf8(isolate, key.c_str(), v8::String::kNormalString,
- key.length()),
- child_v8);
+ result.Set(key, child_v8);
if (try_catch.HasCaught()) {
LOG(ERROR) << "Setter for property " << key.c_str() << " threw an "
<< "exception.";
}
}
- return result;
+ return result.GetHandle();
}
base::Value* V8ValueConverter::FromV8ValueImpl(
-Subproject commit b41635e80921bddbf1a36f030490e063cd593477
+Subproject commit f5e34deb1a5226b4e7e620cb65fce0225471d4d9