Support remote Promise in renderer

This commit is contained in:
Ryohei Ikegami 2015-07-31 14:26:57 +09:00
parent 2eaaad610d
commit ddf2cfd48d
2 changed files with 4 additions and 0 deletions

View file

@ -10,6 +10,7 @@ valueToMeta = (sender, value) ->
meta.type = 'buffer' if Buffer.isBuffer value meta.type = 'buffer' if Buffer.isBuffer value
meta.type = 'value' if value is null meta.type = 'value' if value is null
meta.type = 'array' if Array.isArray value meta.type = 'array' if Array.isArray value
meta.type = 'promise' if Promise.resolve(value) == value
# Treat the arguments object as array. # Treat the arguments object as array.
meta.type = 'array' if meta.type is 'object' and value.callee? and value.length? meta.type = 'array' if meta.type is 'object' and value.callee? and value.length?
@ -29,6 +30,8 @@ valueToMeta = (sender, value) ->
meta.members.push {name: prop, type: typeof field} for prop, field of value meta.members.push {name: prop, type: typeof field} for prop, field of value
else if meta.type is 'buffer' else if meta.type is 'buffer'
meta.value = Array::slice.call value, 0 meta.value = Array::slice.call value, 0
else if meta.type is 'promise'
meta.then = valueToMeta(sender, value.then.bind(value))
else else
meta.type = 'value' meta.type = 'value'
meta.value = value meta.value = value

View file

@ -44,6 +44,7 @@ metaToValue = (meta) ->
when 'value' then meta.value when 'value' then meta.value
when 'array' then (metaToValue(el) for el in meta.members) when 'array' then (metaToValue(el) for el in meta.members)
when 'buffer' then new Buffer(meta.value) when 'buffer' then new Buffer(meta.value)
when 'promise' then Promise.resolve(then: metaToValue(meta.then))
when 'error' when 'error'
throw new Error("#{meta.message}\n#{meta.stack}") throw new Error("#{meta.message}\n#{meta.stack}")
else else