From dfc0910023d51354b004a6eb01698d9374a4ee78 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 9 Aug 2016 14:43:38 -0600 Subject: [PATCH] Stringify/parse temporary window state to avoid nulling out references If the object passed via IPC contains any keys of the same reference, all but one of these keys will be nulled out. Converting to/from a string avoids this problem. --- spec/application-delegate-spec.js | 19 +++++++++++++++++++ src/application-delegate.coffee | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 spec/application-delegate-spec.js diff --git a/spec/application-delegate-spec.js b/spec/application-delegate-spec.js new file mode 100644 index 000000000..5512c88ea --- /dev/null +++ b/spec/application-delegate-spec.js @@ -0,0 +1,19 @@ +/** @babel */ + +import {it, fit, ffit, fffit, beforeEach, afterEach} from './async-spec-helpers' +import ApplicationDelegate from '../src/application-delegate' + +describe('ApplicationDelegate', function () { + describe('set/getTemporaryWindowState', function () { + it('can serialize object trees containing redundant child object references', async function () { + const applicationDelegate = new ApplicationDelegate() + const childObject = {c: 1} + const sentObject = {a: childObject, b: childObject} + + await applicationDelegate.setTemporaryWindowState(sentObject) + const receivedObject = await applicationDelegate.getTemporaryWindowState() + + expect(receivedObject).toEqual(sentObject) + }) + }) +}) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index 3372962be..853ac54f5 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -23,10 +23,10 @@ class ApplicationDelegate ipcRenderer.send("call-window-method", "close") getTemporaryWindowState: -> - ipcHelpers.call('get-temporary-window-state') + ipcHelpers.call('get-temporary-window-state').then (stateJSON) -> JSON.parse(stateJSON) setTemporaryWindowState: (state) -> - ipcHelpers.call('set-temporary-window-state', state) + ipcHelpers.call('set-temporary-window-state', JSON.stringify(state)) getWindowSize: -> [width, height] = remote.getCurrentWindow().getSize()