Fix passing Date object in remote

Close #2017.
This commit is contained in:
Cheng Zhao 2015-10-23 14:51:25 +08:00
parent 95fe4beda8
commit a3f62da615
2 changed files with 4 additions and 0 deletions

View file

@ -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

View file

@ -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