diff --git a/atom/app/node_main.cc b/atom/app/node_main.cc index 040b4b615..fb44ba73e 100644 --- a/atom/app/node_main.cc +++ b/atom/app/node_main.cc @@ -14,6 +14,12 @@ #include "gin/public/isolate_holder.h" #include "gin/v8_initializer.h" +#if defined(OS_WIN) +#include "atom/common/api/atom_bindings.h" +#include "atom/common/native_mate_converters/string16_converter.h" +#include "native_mate/dictionary.h" +#endif + #include "atom/common/node_includes.h" namespace atom { @@ -51,6 +57,11 @@ int NodeMain(int argc, char *argv[]) { if (node_debugger.IsRunning()) env->AssignToContext(v8::Debug::GetDebugContext()); +#if defined(OS_WIN) + mate::Dictionary process(gin_env.isolate(), env->process_object()); + process.SetMethod("log", &AtomBindings::Log); +#endif + node::LoadEnvironment(env); bool more; diff --git a/atom/common/api/atom_bindings.cc b/atom/common/api/atom_bindings.cc index 311e7e987..27b3352f3 100644 --- a/atom/common/api/atom_bindings.cc +++ b/atom/common/api/atom_bindings.cc @@ -79,10 +79,6 @@ void FatalErrorCallback(const char* location, const char* message) { Crash(); } -void Log(const base::string16& message) { - std::cout << message << std::flush; -} - } // namespace @@ -157,4 +153,9 @@ void AtomBindings::OnCallNextTick(uv_async_t* handle) { self->pending_next_ticks_.clear(); } +// static +void AtomBindings::Log(const base::string16& message) { + std::cout << message << std::flush; +} + } // namespace atom diff --git a/atom/common/api/atom_bindings.h b/atom/common/api/atom_bindings.h index 39f3b53a2..2e4c4a937 100644 --- a/atom/common/api/atom_bindings.h +++ b/atom/common/api/atom_bindings.h @@ -27,6 +27,8 @@ class AtomBindings { // load native code from Electron instead. void BindTo(v8::Isolate* isolate, v8::Local process); + static void Log(const base::string16& message); + private: void ActivateUVLoop(v8::Isolate* isolate); diff --git a/spec/fixtures/module/run-as-node.js b/spec/fixtures/module/run-as-node.js new file mode 100644 index 000000000..20812f046 --- /dev/null +++ b/spec/fixtures/module/run-as-node.js @@ -0,0 +1,5 @@ +console.log(JSON.stringify({ + processLog: typeof process.log, + processType: typeof process.type, + window: typeof window +})) diff --git a/spec/node-spec.js b/spec/node-spec.js index 5742bea7f..d6151175d 100644 --- a/spec/node-spec.js +++ b/spec/node-spec.js @@ -92,6 +92,29 @@ describe('node feature', function () { }) }) }) + + describe('child_process.spawn', function () { + it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', function (done) { + const child = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], { + env: { + ELECTRON_RUN_AS_NODE: true + } + }) + + let output = '' + child.stdout.on('data', function (data) { + output += data + }) + child.stdout.on('close', function () { + assert.deepEqual(JSON.parse(output), { + processLog: process.platform === 'win32' ? 'function' : 'undefined', + processType: 'undefined', + window: 'undefined' + }) + done() + }) + }) + }) }) describe('contexts', function () { diff --git a/vendor/node b/vendor/node index 219cca155..811cfe3fc 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 219cca155dfd97312693c73e5b429bb2f8bc0063 +Subproject commit 811cfe3fcd360179d3dd436e3d80e1b045adf633