Merge pull request #3959 from deepak1556/remote_object_patch
remote: support arguments of type Date
This commit is contained in:
commit
af5e76f6ae
4 changed files with 16 additions and 1 deletions
|
@ -67,6 +67,7 @@ unwrapArgs = (sender, args) ->
|
||||||
when 'remote-object' then objectsRegistry.get meta.id
|
when 'remote-object' then objectsRegistry.get meta.id
|
||||||
when 'array' then unwrapArgs sender, meta.value
|
when 'array' then unwrapArgs sender, meta.value
|
||||||
when 'buffer' then new Buffer(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 'promise' then Promise.resolve(then: metaToValue(meta.then))
|
||||||
when 'object'
|
when 'object'
|
||||||
ret = v8Util.createObjectWithName meta.name
|
ret = v8Util.createObjectWithName meta.name
|
||||||
|
|
|
@ -18,6 +18,8 @@ wrapArgs = (args, visited=[]) ->
|
||||||
type: 'array', value: wrapArgs(value, visited)
|
type: 'array', value: wrapArgs(value, visited)
|
||||||
else if Buffer.isBuffer value
|
else if Buffer.isBuffer value
|
||||||
type: 'buffer', value: Array::slice.call(value, 0)
|
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'
|
else if value?.constructor.name is 'Promise'
|
||||||
type: 'promise', then: valueToMeta(value.then.bind(value))
|
type: 'promise', then: valueToMeta(value.then.bind(value))
|
||||||
else if value? and typeof value is 'object' and v8Util.getHiddenValue value, 'atomId'
|
else if value? and typeof value is 'object' and v8Util.getHiddenValue value, 'atomId'
|
||||||
|
|
|
@ -53,11 +53,19 @@ describe 'ipc module', ->
|
||||||
assert.equal obj.test, 'test'
|
assert.equal obj.test, 'test'
|
||||||
|
|
||||||
describe 'remote value in browser', ->
|
describe 'remote value in browser', ->
|
||||||
|
print = path.join(fixtures, 'module', 'print_name.js')
|
||||||
|
|
||||||
it 'keeps its constructor name for objects', ->
|
it 'keeps its constructor name for objects', ->
|
||||||
buf = new Buffer('test')
|
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'
|
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', ->
|
describe 'remote promise', ->
|
||||||
it 'can be used as promise in each side', (done) ->
|
it 'can be used as promise in each side', (done) ->
|
||||||
promise = remote.require path.join(fixtures, 'module', 'promise.js')
|
promise = remote.require path.join(fixtures, 'module', 'promise.js')
|
||||||
|
|
4
spec/fixtures/module/print_name.js
vendored
4
spec/fixtures/module/print_name.js
vendored
|
@ -1,3 +1,7 @@
|
||||||
exports.print = function(obj) {
|
exports.print = function(obj) {
|
||||||
return obj.constructor.name;
|
return obj.constructor.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.echo = function(obj) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue