From 72374b6e31b41ac257e11da14e441e9a0958f981 Mon Sep 17 00:00:00 2001 From: Robo Date: Wed, 30 Dec 2015 01:41:31 +0530 Subject: [PATCH] remote: support arguments of type Date --- atom/browser/lib/rpc-server.coffee | 1 + atom/renderer/api/lib/remote.coffee | 2 ++ spec/api-ipc-spec.coffee | 10 +++++++++- spec/fixtures/module/print_name.js | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/atom/browser/lib/rpc-server.coffee b/atom/browser/lib/rpc-server.coffee index e0256081e68a..873349f3e97a 100644 --- a/atom/browser/lib/rpc-server.coffee +++ b/atom/browser/lib/rpc-server.coffee @@ -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 diff --git a/atom/renderer/api/lib/remote.coffee b/atom/renderer/api/lib/remote.coffee index 3ed44278bd71..b73fbf50b7c1 100644 --- a/atom/renderer/api/lib/remote.coffee +++ b/atom/renderer/api/lib/remote.coffee @@ -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' diff --git a/spec/api-ipc-spec.coffee b/spec/api-ipc-spec.coffee index 1aa715c9f759..67ef717d5045 100644 --- a/spec/api-ipc-spec.coffee +++ b/spec/api-ipc-spec.coffee @@ -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') diff --git a/spec/fixtures/module/print_name.js b/spec/fixtures/module/print_name.js index 09ec33341f5c..01d13f4ba8bf 100644 --- a/spec/fixtures/module/print_name.js +++ b/spec/fixtures/module/print_name.js @@ -1,3 +1,7 @@ exports.print = function(obj) { return obj.constructor.name; } + +exports.echo = function(obj) { + return obj; +}