diff --git a/atom/browser/lib/rpc-server.coffee b/atom/browser/lib/rpc-server.coffee index 3eba472570a..d19b5cf0659 100644 --- a/atom/browser/lib/rpc-server.coffee +++ b/atom/browser/lib/rpc-server.coffee @@ -4,7 +4,7 @@ objectsRegistry = require './objects-registry.js' 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 @@ -12,6 +12,10 @@ valueToMeta = (sender, 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? @@ -80,11 +84,11 @@ unwrapArgs = (sender, args) -> 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) -> diff --git a/atom/common/native_mate_converters/gfx_converter.cc b/atom/common/native_mate_converters/gfx_converter.cc index 6620276b584..37e7aeb3a48 100644 --- a/atom/common/native_mate_converters/gfx_converter.cc +++ b/atom/common/native_mate_converters/gfx_converter.cc @@ -14,7 +14,8 @@ namespace mate { v8::Local Converter::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(); @@ -35,7 +36,8 @@ bool Converter::FromV8(v8::Isolate* isolate, v8::Local Converter::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(); @@ -56,7 +58,8 @@ bool Converter::FromV8(v8::Isolate* isolate, v8::Local Converter::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()); @@ -95,7 +98,8 @@ struct Converter { v8::Local Converter::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()); diff --git a/atom/common/native_mate_converters/v8_value_converter.cc b/atom/common/native_mate_converters/v8_value_converter.cc index a6358b363ee..a91e614fc6d 100644 --- a/atom/common/native_mate_converters/v8_value_converter.cc +++ b/atom/common/native_mate_converters/v8_value_converter.cc @@ -11,6 +11,7 @@ #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 { @@ -179,7 +180,8 @@ v8::Local V8ValueConverter::ToV8Array( v8::Local V8ValueConverter::ToV8Object( v8::Isolate* isolate, const base::DictionaryValue* val) const { - v8::Local 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()) { @@ -188,17 +190,14 @@ v8::Local V8ValueConverter::ToV8Object( 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( diff --git a/vendor/native_mate b/vendor/native_mate index b41635e8092..f5e34deb1a5 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit b41635e80921bddbf1a36f030490e063cd593477 +Subproject commit f5e34deb1a5226b4e7e620cb65fce0225471d4d9