Merge pull request #3959 from deepak1556/remote_object_patch

remote: support arguments of type Date
This commit is contained in:
Cheng Zhao 2015-12-31 18:46:22 +08:00
commit af5e76f6ae
4 changed files with 16 additions and 1 deletions

View file

@ -67,6 +67,7 @@ unwrapArgs = (sender, args) ->
when 'remote-object' then objectsRegistry.get meta.id
when 'array' then unwrapArgs sender, meta.value
when 'buffer' then new Buffer(meta.value)
when 'date' then new Date(meta.value)
when 'promise' then Promise.resolve(then: metaToValue(meta.then))
when 'object'
ret = v8Util.createObjectWithName meta.name

View file

@ -18,6 +18,8 @@ wrapArgs = (args, visited=[]) ->
type: 'array', value: wrapArgs(value, visited)
else if Buffer.isBuffer value
type: 'buffer', value: Array::slice.call(value, 0)
else if value instanceof Date
type: 'date', value: value.getTime()
else if value?.constructor.name is 'Promise'
type: 'promise', then: valueToMeta(value.then.bind(value))
else if value? and typeof value is 'object' and v8Util.getHiddenValue value, 'atomId'

View file

@ -53,11 +53,19 @@ describe 'ipc module', ->
assert.equal obj.test, 'test'
describe 'remote value in browser', ->
print = path.join(fixtures, 'module', 'print_name.js')
it 'keeps its constructor name for objects', ->
buf = new Buffer('test')
print_name = remote.require path.join(fixtures, 'module', 'print_name.js')
print_name = remote.require print
assert.equal print_name.print(buf), 'Buffer'
it 'supports instanceof Date', ->
now = new Date()
print_name = remote.require print
assert.equal print_name.print(now), 'Date'
assert.deepEqual print_name.echo(now), now
describe 'remote promise', ->
it 'can be used as promise in each side', (done) ->
promise = remote.require path.join(fixtures, 'module', 'promise.js')

View file

@ -1,3 +1,7 @@
exports.print = function(obj) {
return obj.constructor.name;
}
exports.echo = function(obj) {
return obj;
}