@@ -169,10 +169,8 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
169169 return exit_code;
170170}
171171
172- int main ( int argc, char ** argv ) {
172+ static int BoxednodeMain (std::vector<std::string> args ) {
173173 boxednode::InitializeOncePerProcess ();
174- argv = uv_setup_args (argc, argv);
175- std::vector<std::string> args (argv, argv + argc);
176174 std::vector<std::string> exec_args;
177175 std::vector<std::string> errors;
178176
@@ -205,6 +203,44 @@ int main(int argc, char** argv) {
205203 return ret;
206204}
207205
206+ #ifdef _WIN32
207+ int wmain (int argc, wchar_t * wargv[]) {
208+ // Convert argv to UTF8
209+ std::vector<std::string> args;
210+ for (int i = 0 ; i < argc; i++) {
211+ DWORD size = WideCharToMultiByte (CP_UTF8,
212+ 0 ,
213+ wargv[i],
214+ -1 ,
215+ nullptr ,
216+ 0 ,
217+ nullptr ,
218+ nullptr );
219+ assert (size > 0 );
220+ std::string arg (size, ' \0 ' );
221+ DWORD result = WideCharToMultiByte (CP_UTF8,
222+ 0 ,
223+ wargv[i],
224+ -1 ,
225+ &arg[0 ],
226+ size,
227+ nullptr ,
228+ nullptr );
229+ assert (result > 0 );
230+ arg.resize (result - 1 );
231+ args.emplace_back (std::move (arg));
232+ }
233+ return BoxednodeMain (std::move (args));
234+ }
235+
236+ #else
237+ int main (int argc, char ** argv) {
238+ argv = uv_setup_args (argc, argv);
239+ std::vector<std::string> args (argv, argv + argc);
240+ return BoxednodeMain (std::move (args));
241+ }
242+ #endif
243+
208244// The code below is mostly lifted directly from node.cc
209245// TODO(addaleax): Expose these APIs on the Node.js side.
210246
0 commit comments