From a3f62da615221a3e98c43d518b0c03a45783aa4d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 23 Oct 2015 14:51:25 +0800 Subject: [PATCH] Fix passing Date object in remote Close #2017. --- atom/browser/lib/rpc-server.coffee | 3 +++ atom/renderer/api/lib/remote.coffee | 1 + 2 files changed, 4 insertions(+) diff --git a/atom/browser/lib/rpc-server.coffee b/atom/browser/lib/rpc-server.coffee index 6a20d09d119a..6b1f95a841ab 100644 --- a/atom/browser/lib/rpc-server.coffee +++ b/atom/browser/lib/rpc-server.coffee @@ -11,6 +11,7 @@ valueToMeta = (sender, value, optimizeSimpleObject=false) -> meta.type = 'value' if value is null meta.type = 'array' if Array.isArray value meta.type = 'error' if value instanceof Error + meta.type = 'date' if value instanceof Date meta.type = 'promise' if value? and value.constructor.name is 'Promise' # Treat simple objects as value. @@ -39,6 +40,8 @@ valueToMeta = (sender, value, optimizeSimpleObject=false) -> meta.then = valueToMeta(sender, value.then.bind(value)) else if meta.type is 'error' meta.message = value.message + else if meta.type is 'date' + meta.value = value.getTime() else meta.type = 'value' meta.value = value diff --git a/atom/renderer/api/lib/remote.coffee b/atom/renderer/api/lib/remote.coffee index 4eb56bcf0279..8a5565f06562 100644 --- a/atom/renderer/api/lib/remote.coffee +++ b/atom/renderer/api/lib/remote.coffee @@ -47,6 +47,7 @@ metaToValue = (meta) -> when 'buffer' then new Buffer(meta.value) when 'promise' then Promise.resolve(then: metaToValue(meta.then)) when 'error' then new Error(meta.message) + when 'date' then new Date(meta.value) when 'exception' throw new Error("#{meta.message}\n#{meta.stack}") else