Module names starting with atom_common_ can be loaded by both sides.

This commit is contained in:
Cheng Zhao 2013-04-25 15:36:01 +08:00
parent 70fe77ca34
commit ab4015ef51
2 changed files with 13 additions and 6 deletions

View file

@ -32,17 +32,18 @@ namespace atom {
#include "common/api/atom_extensions.h" // NOLINT #include "common/api/atom_extensions.h" // NOLINT
node::node_module_struct* GetBuiltinModule(const char *name, bool is_browser) { node::node_module_struct* GetBuiltinModule(const char *name, bool is_browser) {
char buf[128]; char common[128];
char spec[128];
node::node_module_struct *cur = NULL; node::node_module_struct *cur = NULL;
if (is_browser) snprintf(common, sizeof(common), "atom_common_%s", name);
snprintf(buf, sizeof(buf), "atom_browser_%s", name); snprintf(spec, sizeof(spec),
else (is_browser ? "atom_browser_%s": "atom_renderer_%s"),
snprintf(buf, sizeof(buf), "atom_renderer_%s", name); name);
/* TODO: you could look these up in a hash, but there are only /* TODO: you could look these up in a hash, but there are only
* a few, and once loaded they are cached. */ * a few, and once loaded they are cached. */
for (int i = 0; node_module_list[i] != NULL; i++) { for (int i = 0; node_module_list[i] != NULL; i++) {
cur = node_module_list[i]; cur = node_module_list[i];
if (strcmp(cur->modname, buf) == 0) { if (strcmp(cur->modname, common) == 0 || strcmp(cur->modname, spec) == 0) {
return cur; return cur;
} }
} }

View file

@ -8,9 +8,15 @@
NODE_EXT_LIST_START NODE_EXT_LIST_START
// Module names start with `atom_browser_` can only be used by browser process.
NODE_EXT_LIST_ITEM(atom_browser_ipc) NODE_EXT_LIST_ITEM(atom_browser_ipc)
NODE_EXT_LIST_ITEM(atom_browser_window) NODE_EXT_LIST_ITEM(atom_browser_window)
// Module names start with `atom_renderer_` can only be used by renderer
// process.
NODE_EXT_LIST_ITEM(atom_renderer_ipc) NODE_EXT_LIST_ITEM(atom_renderer_ipc)
// Module names start with `atom_common_` can be used by both browser and
// renderer processes.
NODE_EXT_LIST_END NODE_EXT_LIST_END