Merge pull request #1019 from atom/locale-in-node

Initialize ICU in Node mode
This commit is contained in:
Cheng Zhao 2015-01-16 17:08:30 -08:00
commit c59bd82f6f
6 changed files with 42 additions and 3 deletions

View file

@ -340,8 +340,8 @@
'chromium_src/chrome/browser/ui/views/color_chooser_win.cc', 'chromium_src/chrome/browser/ui/views/color_chooser_win.cc',
], ],
'framework_sources': [ 'framework_sources': [
'atom/app/atom_library_main.cc',
'atom/app/atom_library_main.h', 'atom/app/atom_library_main.h',
'atom/app/atom_library_main.mm',
], ],
'locales': [ 'locales': [
'am', 'ar', 'bg', 'bn', 'ca', 'cs', 'da', 'de', 'el', 'en-GB', 'am', 'ar', 'bg', 'bn', 'ca', 'cs', 'da', 'de', 'el', 'en-GB',
@ -801,6 +801,9 @@
'vendor', 'vendor',
'<(libchromiumcontent_include_dir)', '<(libchromiumcontent_include_dir)',
], ],
'defines': [
'PRODUCT_NAME="<(product_name)"',
],
'export_dependent_settings': [ 'export_dependent_settings': [
'<(project_name)_lib', '<(project_name)_lib',
], ],

View file

@ -11,6 +11,9 @@
extern "C" { extern "C" {
__attribute__((visibility("default"))) __attribute__((visibility("default")))
int AtomMain(int argc, const char* argv[]); int AtomMain(int argc, const char* argv[]);
__attribute__((visibility("default")))
void AtomInitializeICU();
} }
#endif // OS_MACOSX #endif // OS_MACOSX

View file

@ -5,6 +5,9 @@
#include "atom/app/atom_library_main.h" #include "atom/app/atom_library_main.h"
#include "atom/app/atom_main_delegate.h" #include "atom/app/atom_main_delegate.h"
#include "base/i18n/icu_util.h"
#include "base/mac/bundle_locations.h"
#include "brightray/common/mac/main_application_bundle.h"
#include "content/public/app/content_main.h" #include "content/public/app/content_main.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
@ -15,4 +18,13 @@ int AtomMain(int argc, const char* argv[]) {
params.argv = argv; params.argv = argv;
return content::ContentMain(params); return content::ContentMain(params);
} }
void AtomInitializeICU() {
base::mac::SetOverrideFrameworkBundlePath(
brightray::MainApplicationBundlePath()
.Append("Contents")
.Append("Frameworks")
.Append(PRODUCT_NAME " Framework.framework"));
base::i18n::InitializeICU();
}
#endif // OS_MACOSX #endif // OS_MACOSX

View file

@ -28,6 +28,8 @@
#include "atom/app/atom_library_main.h" #include "atom/app/atom_library_main.h"
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
#include "base/i18n/icu_util.h"
// Declaration of node::Start. // Declaration of node::Start.
namespace node { namespace node {
int Start(int argc, char *argv[]); int Start(int argc, char *argv[]);
@ -89,6 +91,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
} }
} }
// Now that conversion is done, we can finally start. // Now that conversion is done, we can finally start.
base::i18n::InitializeICU();
return node::Start(argc, argv); return node::Start(argc, argv);
} else if (env->GetVar("ATOM_SHELL_INTERNAL_CRASH_SERVICE", } else if (env->GetVar("ATOM_SHELL_INTERNAL_CRASH_SERVICE",
&crash_service_indicator) && &crash_service_indicator) &&
@ -113,8 +116,10 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
char* node_indicator = getenv("ATOM_SHELL_INTERNAL_RUN_AS_NODE"); char* node_indicator = getenv("ATOM_SHELL_INTERNAL_RUN_AS_NODE");
if (node_indicator != NULL && strcmp(node_indicator, "1") == 0) if (node_indicator != NULL && strcmp(node_indicator, "1") == 0) {
base::i18n::InitializeICU();
return node::Start(argc, const_cast<char**>(argv)); return node::Start(argc, const_cast<char**>(argv));
}
atom::AtomMainDelegate delegate; atom::AtomMainDelegate delegate;
content::ContentMainParams params(&delegate); content::ContentMainParams params(&delegate);
@ -127,8 +132,10 @@ int main(int argc, const char* argv[]) {
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
char* node_indicator = getenv("ATOM_SHELL_INTERNAL_RUN_AS_NODE"); char* node_indicator = getenv("ATOM_SHELL_INTERNAL_RUN_AS_NODE");
if (node_indicator != NULL && strcmp(node_indicator, "1") == 0) if (node_indicator != NULL && strcmp(node_indicator, "1") == 0) {
AtomInitializeICU();
return node::Start(argc, const_cast<char**>(argv)); return node::Start(argc, const_cast<char**>(argv));
}
return AtomMain(argc, argv); return AtomMain(argc, argv);
} }

View file

@ -0,0 +1,7 @@
process.on('message', function (msg) {
process.send([
'a'.localeCompare('a'),
'ä'.localeCompare('z', 'de'),
'ä'.localeCompare('a', 'sv', { sensitivity: 'base' }),
]);
});

View file

@ -41,6 +41,13 @@ describe 'node feature', ->
done() done()
child.send 'message' child.send 'message'
it 'has String::localeCompare working in script', (done) ->
child = child_process.fork path.join(fixtures, 'module', 'locale-compare.js')
child.on 'message', (msg) ->
assert.deepEqual msg, [0, -1, 1]
done()
child.send 'message'
describe 'contexts', -> describe 'contexts', ->
describe 'setTimeout in fs callback', -> describe 'setTimeout in fs callback', ->
it 'does not crash', (done) -> it 'does not crash', (done) ->