From 4fc14959a87c4ce1da915d6f09ef497f101c9e71 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 16 Dec 2014 16:57:42 -0800 Subject: [PATCH] Allow same object to appear in one list when parsing V8 array Fixes #874. --- atom/common/native_mate_converters/v8_value_converter.cc | 5 ++++- spec/api-ipc-spec.coffee | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/atom/common/native_mate_converters/v8_value_converter.cc b/atom/common/native_mate_converters/v8_value_converter.cc index d40bc33dec72..4d808b356bc7 100644 --- a/atom/common/native_mate_converters/v8_value_converter.cc +++ b/atom/common/native_mate_converters/v8_value_converter.cc @@ -294,7 +294,10 @@ base::Value* V8ValueConverter::FromV8Array( if (!val->HasRealIndexedProperty(i)) continue; - base::Value* child = FromV8ValueImpl(state, child_v8, isolate); + // When parsing elements in an array, we use a new state so we can have the + // same object showed twice in array. + FromV8ValueState new_state; + base::Value* child = FromV8ValueImpl(&new_state, child_v8, isolate); if (child) result->Append(child); else diff --git a/spec/api-ipc-spec.coffee b/spec/api-ipc-spec.coffee index c63997af7e78..826b094e5341 100644 --- a/spec/api-ipc-spec.coffee +++ b/spec/api-ipc-spec.coffee @@ -60,6 +60,14 @@ describe 'ipc module', -> done() ipc.send 'message', obj + it 'should work when sending the same object twice in one message', (done) -> + obj = key: 'some' + ipc.once 'message', (message) -> + assert.deepEqual message[0], obj + assert.deepEqual message[1], obj + done() + ipc.send 'message', [obj, obj] + describe 'ipc.sendSync', -> it 'can be replied by setting event.returnValue', -> msg = ipc.sendSync 'echo', 'test'