Skip to content

Commit

Permalink
clone IPC objects and remove unserializable values
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Mar 17, 2020
1 parent b4666cf commit 8bd8dd3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
12 changes: 12 additions & 0 deletions packages/desktop-gui/src/lib/ipc-bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ const ipcBus = (...args) => {
// get the last argument
const lastArg = args.pop()

// remove nodes that cannot be cloned
// https://github.com/cypress-io/cypress/issues/6750
args = args.map((arg) => {
return _.cloneDeepWith(arg, (val) => {
if (_.isFunction(val) || _.isElement(val)) {
return null
}

return val
})
})

let fn

// enable the last arg to be a function
Expand Down
17 changes: 14 additions & 3 deletions packages/server/lib/gui/events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ chromePolicyCheck = require("../util/chrome_policy_check")
browsers = require("../browsers")
konfig = require("../konfig")

removeUnserializableValues = (obj) =>
## remove values that cannot be cloned
## https://github.com/cypress-io/cypress/issues/6750
_.cloneDeepWith obj, (val) =>
if _.isFunction(val)
return null

handleEvent = (options, bus, event, id, type, arg) ->
debug("got request for event: %s, %o", type, arg)

sendResponse = (data = {}) ->
sendResponse = (originalData = {}) ->
try
debug("sending ipc data %o", {type: type, data: data})
data = removeUnserializableValues(originalData)

debug("sending ipc data %o", { type, data, originalData })
event.sender.send("response", data)

sendErr = (err) ->
Expand Down Expand Up @@ -318,7 +327,9 @@ handleEvent = (options, bus, event, id, type, arg) ->
throw new Error("No ipc event registered for: '#{type}'")

module.exports = {
handleEvent: handleEvent
removeUnserializableValues

handleEvent

stop: ->
ipc.removeAllListeners()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/unit/gui/events_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe "lib/gui/events", ->
it "calls Windows#open with args and resolves with return of Windows.open", ->
@handleEvent("window:open", {type: "INDEX"})
.then (assert) =>
assert.sendCalledWith(@win)
assert.sendCalledWith(events.removeUnserializableValues(@win))

it "catches errors", ->
err = new Error("foo")
Expand Down

0 comments on commit 8bd8dd3

Please sign in to comment.