Merge pull request #7578 from electron/windows-logging
Show console output from Windows when ELECTRON_RUN_AS_NODE is set
This commit is contained in:
Коммит
ce847fc3ca
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,6 +27,8 @@ class AtomBindings {
|
|||
// load native code from Electron instead.
|
||||
void BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process);
|
||||
|
||||
static void Log(const base::string16& message);
|
||||
|
||||
private:
|
||||
void ActivateUVLoop(v8::Isolate* isolate);
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
console.log(JSON.stringify({
|
||||
processLog: typeof process.log,
|
||||
processType: typeof process.type,
|
||||
window: typeof window
|
||||
}))
|
|
@ -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 () {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 219cca155dfd97312693c73e5b429bb2f8bc0063
|
||||
Subproject commit 811cfe3fcd360179d3dd436e3d80e1b045adf633
|
Загрузка…
Ссылка в новой задаче