Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions resources/main-template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
return exit_code;
}

int main(int argc, char** argv) {
static int BoxednodeMain(std::vector<std::string> args) {
boxednode::InitializeOncePerProcess();
argv = uv_setup_args(argc, argv);
std::vector<std::string> args(argv, argv + argc);
std::vector<std::string> exec_args;
std::vector<std::string> errors;

Expand Down Expand Up @@ -205,6 +203,44 @@ int main(int argc, char** argv) {
return ret;
}

#ifdef _WIN32
int wmain(int argc, wchar_t* wargv[]) {
// Convert argv to UTF8
std::vector<std::string> args;
for (int i = 0; i < argc; i++) {
DWORD size = WideCharToMultiByte(CP_UTF8,
0,
wargv[i],
-1,
nullptr,
0,
nullptr,
nullptr);
assert(size > 0);
std::string arg(size, '\0');
DWORD result = WideCharToMultiByte(CP_UTF8,
0,
wargv[i],
-1,
&arg[0],
size,
nullptr,
nullptr);
assert(result > 0);
arg.resize(result - 1);
args.emplace_back(std::move(arg));
}
return BoxednodeMain(std::move(args));
}

#else
int main(int argc, char** argv) {
argv = uv_setup_args(argc, argv);
std::vector<std::string> args(argv, argv + argc);
return BoxednodeMain(std::move(args));
}
#endif

// The code below is mostly lifted directly from node.cc
// TODO(addaleax): Expose these APIs on the Node.js side.

Expand Down
7 changes: 7 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ describe('basic functionality', () => {
assert.strictEqual(stdout, '42\n');
}

{
const { stdout } = await execFile(
path.resolve(__dirname, `resources/example${exeSuffix}`), ['"🐈"'],
{ encoding: 'utf8' });
assert.strictEqual(stdout, '🐈\n');
}

{
const { stdout } = await execFile(
path.resolve(__dirname, `resources/example${exeSuffix}`), ['process.argv.length'],
Expand Down