Skip to content

Commit

Permalink
fix: no more need to hijack process.stdout on Win32 (#25765)
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Oct 5, 2020
1 parent 9717dff commit 57dc170
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 63 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ if (is_mac) {
"wtsapi32.lib",
]

configs -= [ "//build/config/win:console" ]
configs += [
"//build/config/win:windowed",
"//build/config/win:delayloads",
Expand Down
25 changes: 0 additions & 25 deletions lib/browser/init.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Buffer } from 'buffer';
import { EventEmitter } from 'events';
import * as fs from 'fs';
import { Socket } from 'net';
import * as path from 'path';
import * as util from 'util';

const Module = require('module');

Expand All @@ -19,28 +16,6 @@ require('@electron/internal/common/init');

process._linkedBinding('electron_browser_event_emitter').setEventEmitterPrototype(EventEmitter.prototype);

if (process.platform === 'win32') {
// Redirect node's console to use our own implementations, since node can not
// handle console output when running as GUI program.
const consoleLog = (...args: any[]) => {
// @ts-ignore this typing is incorrect; 'format' is an optional parameter
// See https://nodejs.org/api/util.html#util_util_format_format_args
return process.log(util.format(...args) + '\n');
};
const streamWrite: Socket['write'] = function (chunk: Buffer | string, encoding?: any, callback?: Function) {
if (Buffer.isBuffer(chunk)) {
chunk = chunk.toString(encoding);
}
process.log(chunk);
if (callback) {
callback();
}
return true;
};
console.log = console.error = console.warn = consoleLog;
process.stdout.write = process.stderr.write = streamWrite;
}

// Don't quit on fatal error.
process.on('uncaughtException', function (error) {
// Do nothing if the user has a custom uncaught exception handler.
Expand Down
1 change: 0 additions & 1 deletion patches/node/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ feat_add_new_built_with_electron_variable_to_config_gypi.patch
feat_add_flags_for_low-level_hooks_and_exceptions.patch
fix_expose_tracing_agent_and_use_tracing_tracingcontroller_instead.patch
pass_all_globals_through_require.patch
call_process_log_from_fallback_stream_on_windows.patch
fixme_remove_async_id_assertion_check.patch
fixme_comment_trace_event_macro.patch
fix_key_gen_apis_are_not_available_in_boringssl.patch
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions shell/app/node_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ int NodeMain(int argc, char* argv[]) {
node::SetIsolateUpForNode(isolate, is);

gin_helper::Dictionary process(isolate, env->process_object());
#if defined(OS_WIN)
process.SetMethod("log", &ElectronBindings::Log);
#endif
process.SetMethod("crash", &ElectronBindings::Crash);

// Setup process.crashReporter in child node processes
Expand Down
7 changes: 0 additions & 7 deletions shell/common/api/electron_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "shell/common/api/electron_bindings.h"

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -48,7 +47,6 @@ void ElectronBindings::BindProcess(v8::Isolate* isolate,
// These bindings are shared between sandboxed & unsandboxed renderers
process->SetMethod("crash", &Crash);
process->SetMethod("hang", &Hang);
process->SetMethod("log", &Log);
process->SetMethod("getCreationTime", &GetCreationTime);
process->SetMethod("getHeapStatistics", &GetHeapStatistics);
process->SetMethod("getBlinkMemoryInfo", &GetBlinkMemoryInfo);
Expand Down Expand Up @@ -126,11 +124,6 @@ void ElectronBindings::OnCallNextTick(uv_async_t* handle) {
self->pending_next_ticks_.clear();
}

// static
void ElectronBindings::Log(const base::string16& message) {
std::cout << message << std::flush;
}

// static
void ElectronBindings::Crash() {
volatile int* zero = nullptr;
Expand Down
2 changes: 0 additions & 2 deletions shell/common/api/electron_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/process/process_metrics.h"
#include "base/strings/string16.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/node_bindings.h"
#include "uv.h" // NOLINT(build/include_directory)
Expand Down Expand Up @@ -48,7 +47,6 @@ class ElectronBindings {
gin_helper::Dictionary* process,
base::ProcessMetrics* metrics);

static void Log(const base::string16& message);
static void Crash();

private:
Expand Down
6 changes: 6 additions & 0 deletions spec-main/node-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ describe('node feature', () => {
});
});

describe('process.stdout', () => {
it('is a real Node stream', () => {
expect((process.stdout as any)._type).to.not.be.undefined();
});
});

ifdescribe(features.isRunAsNodeEnabled())('inspector', () => {
let child: childProcess.ChildProcessWithoutNullStreams;
let exitPromise: Promise<any[]>;
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/module/run-as-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
console.log(JSON.stringify({
processLog: typeof process.log,
stdoutType: process.stdout._type,
processType: typeof process.type,
window: typeof window
}));
2 changes: 1 addition & 1 deletion spec/node-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('node feature', () => {
});
await emittedOnce(child.stdout, 'close');
expect(JSON.parse(output)).to.deep.equal({
processLog: process.platform === 'win32' ? 'function' : 'undefined',
stdoutType: 'pipe',
processType: 'undefined',
window: 'undefined'
});
Expand Down

0 comments on commit 57dc170

Please sign in to comment.