From: Cheng Zhao Date: Tue, 23 Jul 2013 03:59:07 +0000 (+0800) Subject: remote.require should return the same object for the same module. X-Git-Tag: v0.1.4 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=620c9fa10996e4ce1a05b24a98e70800f13e93ba;p=electron.git remote.require should return the same object for the same module. This is required to use jasmine to test methods of the remote module. --- diff --git a/renderer/api/lib/remote.coffee b/renderer/api/lib/remote.coffee index 3a7436e8..d43feeba 100644 --- a/renderer/api/lib/remote.coffee +++ b/renderer/api/lib/remote.coffee @@ -87,9 +87,14 @@ window.addEventListener 'unload', (event) -> ipc.sendChannelSync 'ATOM_BROWSER_RELEASE_RENDER_VIEW' # Get remote module. +# (Just like node's require, the modules are cached permanently, note that this +# is safe leak since the object is not expected to get freed in browser) +moduleCache = {} exports.require = (module) -> + return moduleCache[module] if moduleCache[module]? + meta = ipc.sendChannelSync 'ATOM_BROWSER_REQUIRE', module - metaToValue meta + moduleCache[module] = metaToValue meta # Get object with specified id. exports.getObject = (id) -> diff --git a/spec/api/ipc.coffee b/spec/api/ipc.coffee new file mode 100644 index 00000000..b3482185 --- /dev/null +++ b/spec/api/ipc.coffee @@ -0,0 +1,9 @@ +assert = require 'assert' +remote = require 'remote' + +describe 'ipc', -> + describe 'remote.require', -> + it 'should returns same object for the same module', -> + dialog1 = remote.require 'dialog' + dialog2 = remote.require 'dialog' + assert.equal dialog1, dialog2