Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

patches for Electron #6

Closed
wants to merge 17 commits into from
Closed
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
2 changes: 2 additions & 0 deletions deps/uv/include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,8 @@ union uv_any_req {
struct uv_loop_s {
/* User data - use this for whatever. */
void* data;
/* Callback when loop's watcher queue updates. */
void (*on_watcher_queue_updated)(uv_loop_t*);
/* Loop reference counting. */
unsigned int active_handles;
void* handle_queue[2];
Expand Down
12 changes: 10 additions & 2 deletions deps/uv/src/unix/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,11 @@ void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
}
#endif

if (QUEUE_EMPTY(&w->watcher_queue))
if (QUEUE_EMPTY(&w->watcher_queue)) {
QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
if (loop->on_watcher_queue_updated)
loop->on_watcher_queue_updated(loop);
}

if (loop->watchers[w->fd] == NULL) {
loop->watchers[w->fd] = w;
Expand Down Expand Up @@ -837,8 +840,11 @@ void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
w->events = 0;
}
}
else if (QUEUE_EMPTY(&w->watcher_queue))
else if (QUEUE_EMPTY(&w->watcher_queue)) {
QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
if (loop->on_watcher_queue_updated)
loop->on_watcher_queue_updated(loop);
}
}


Expand All @@ -854,6 +860,8 @@ void uv__io_close(uv_loop_t* loop, uv__io_t* w) {
void uv__io_feed(uv_loop_t* loop, uv__io_t* w) {
if (QUEUE_EMPTY(&w->pending_queue))
QUEUE_INSERT_TAIL(&loop->pending_queue, &w->pending_queue);
if (loop->on_watcher_queue_updated)
loop->on_watcher_queue_updated(loop);
}


Expand Down
4 changes: 4 additions & 0 deletions deps/uv/src/win/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ uv_handle_type uv_guess_handle(uv_file file) {
return UV_FILE;

default:
#if defined(_WIN32)
return UV_FILE;
#else
return UV_UNKNOWN_HANDLE;
#endif
}
}

Expand Down
3 changes: 3 additions & 0 deletions deps/uv/src/win/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,9 @@ int uv_spawn(uv_loop_t* loop,
process_flags |= DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP;
}

/* Don't create console window. */
process_flags |= CREATE_NO_WINDOW;

if (!CreateProcessW(application_path,
arguments,
NULL,
Expand Down
13 changes: 13 additions & 0 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,19 @@ exports.fork = function(modulePath /*, args, options*/) {
options.stdio = options.silent ? ['pipe', 'pipe', 'pipe', 'ipc'] :
[0, 1, 2, 'ipc'];

// When forking a child script, we setup a special environment to make
// the atom-shell binary run like the upstream node.
if (!options.env) {
options.env = Object.create(process.env);
}
options.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'] = 1;

// On Mac we use the helper app as node binary.
if (!options.execPath && process.type && process.platform == 'darwin') {
options.execPath = require('path').resolve(process.resourcesPath, '..',
'Frameworks', 'Atom Helper.app', 'Contents', 'MacOS', 'Atom Helper');
}

options.execPath = options.execPath || process.execPath;

return spawn(options.execPath, args, options);
Expand Down
10 changes: 10 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,11 +838,21 @@ fs.lstatSync = function(path) {
return binding.lstat(pathModule._makeLong(path));
};

fs.lstatSyncNoException = function(path) {
nullCheck(path);
return binding.lstatNoException(pathModule._makeLong(path));
};

fs.statSync = function(path) {
nullCheck(path);
return binding.stat(pathModule._makeLong(path));
};

fs.statSyncNoException = function(path) {
nullCheck(path);
return binding.statNoException(pathModule._makeLong(path));
};

fs.readlink = function(path, callback) {
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
Expand Down
30 changes: 10 additions & 20 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ const debug = Module._debug;
// -> a/index.<ext>

function statPath(path) {
var fs = NativeModule.require('fs');
/*
try {
return fs.statSync(path);
} catch (ex) {}
return false;
*/
var result = fs.statSyncNoException(path);
return result === false ? false : result;
}

// check if the directory is a package.json dir
Expand All @@ -71,8 +76,11 @@ function readPackage(requestPath) {
return packageMainCache[requestPath];
}

var fs = NativeModule.require('fs');
var jsonPath = path.resolve(requestPath, 'package.json');
if (fs.statSyncNoException(jsonPath) === false) // check existence.
return false;
try {
var jsonPath = path.resolve(requestPath, 'package.json');
var json = fs.readFileSync(jsonPath, 'utf8');
} catch (e) {
return false;
Expand Down Expand Up @@ -454,30 +462,12 @@ Module.runMain = function() {
};

Module._initPaths = function() {
const isWindows = process.platform === 'win32';

if (isWindows) {
var homeDir = process.env.USERPROFILE;
} else {
var homeDir = process.env.HOME;
}

var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];

if (homeDir) {
paths.unshift(path.resolve(homeDir, '.node_libraries'));
paths.unshift(path.resolve(homeDir, '.node_modules'));
}

var nodePath = process.env['NODE_PATH'];
if (nodePath) {
paths = nodePath.split(path.delimiter).concat(paths);
}

modulePaths = paths;

// clone as a read-only copy, for introspection.
Module.globalPaths = modulePaths.slice(0);
Module.globalPaths = modulePaths;
};

// bootstrap repl
Expand Down
27 changes: 2 additions & 25 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@

'targets': [
{
'target_name': 'iojs',
'type': 'executable',
'target_name': 'node',
'type': 'shared_library',

'dependencies': [
'node_js2c#host',
Expand Down Expand Up @@ -105,7 +105,6 @@
'src/node_file.cc',
'src/node_http_parser.cc',
'src/node_javascript.cc',
'src/node_main.cc',
'src/node_os.cc',
'src/node_v8.cc',
'src/node_v8_platform.cc',
Expand Down Expand Up @@ -207,22 +206,6 @@
[ 'node_shared_openssl=="false"', {
'dependencies': [
'./deps/openssl/openssl.gyp:openssl',

# For tests
'./deps/openssl/openssl.gyp:openssl-cli',
],
# Do not let unused OpenSSL symbols to slip away
'xcode_settings': {
'OTHER_LDFLAGS': [
'-Wl,-force_load,<(PRODUCT_DIR)/libopenssl.a',
],
},
'conditions': [
['OS in "linux freebsd"', {
'ldflags': [
'-Wl,--whole-archive <(PRODUCT_DIR)/libopenssl.a -Wl,--no-whole-archive',
],
}],
],
}]]
}, {
Expand Down Expand Up @@ -389,12 +372,6 @@
],
}],
],
'msvs_settings': {
'VCManifestTool': {
'EmbedManifest': 'true',
'AdditionalManifestFiles': 'src/res/node.exe.extra.manifest'
}
},
},
# generate ETW header and resource files
{
Expand Down
5 changes: 3 additions & 2 deletions src/debug-agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#ifndef SRC_DEBUG_AGENT_H_
#define SRC_DEBUG_AGENT_H_

#include "node.h"
#include "util.h"
#include "util-inl.h"
#include "uv.h"
Expand Down Expand Up @@ -66,8 +67,8 @@ class AgentMessage {

class Agent {
public:
explicit Agent(node::Environment* env);
~Agent();
NODE_EXTERN explicit Agent(node::Environment* env);
NODE_EXTERN ~Agent();

typedef void (*DispatchHandler)(node::Environment* env);

Expand Down
29 changes: 24 additions & 5 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ using v8::V8;
using v8::Value;
using v8::kExternalUint32Array;

bool g_standalone_mode = true;
bool g_upstream_node_mode = true;

static bool print_eval = false;
static bool force_repl = false;
static bool trace_deprecation = false;
Expand All @@ -116,8 +119,6 @@ static bool abort_on_uncaught_exception = false;
static const char* eval_string = nullptr;
static unsigned int preload_module_count = 0;
static const char** preload_modules = nullptr;
static bool use_debug_agent = false;
static bool debug_wait_connect = false;
static int debug_port = 5858;
static bool v8_is_profiling = false;
static bool node_is_initialized = false;
Expand All @@ -126,6 +127,10 @@ static node_module* modlist_builtin;
static node_module* modlist_linked;
static node_module* modlist_addon;

// Exposed for use from atom::NodeMain.
bool use_debug_agent = false;
bool debug_wait_connect = false;

#if defined(NODE_HAVE_I18N_SUPPORT)
// Path to ICU data (for i18n / Intl)
static const char* icu_data_dir = nullptr;
Expand Down Expand Up @@ -793,7 +798,11 @@ Local<Value> UVException(Isolate* isolate,
if (!msg || !msg[0])
msg = uv_strerror(errorno);

Local<String> js_code = OneByteString(isolate, uv_err_name(errorno));
const char* err_name = uv_err_name(errorno);
if (err_name == NULL)
err_name = "UnknownSystemError";

Local<String> js_code = OneByteString(isolate, err_name);
Local<String> js_syscall = OneByteString(isolate, syscall);
Local<String> js_path;
Local<String> js_dest;
Expand Down Expand Up @@ -1089,6 +1098,7 @@ Handle<Value> MakeCallback(Environment* env,
env->tick_callback_function()->Call(process, 0, nullptr);
CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());

if (!g_standalone_mode) try_catch.Reset();
if (try_catch.HasCaught()) {
return Undefined(env->isolate());
}
Expand All @@ -1115,6 +1125,7 @@ Handle<Value> MakeCallback(Environment* env,

tick_info->set_in_tick(false);

if (!g_standalone_mode) try_catch.Reset();
if (try_catch.HasCaught()) {
tick_info->set_last_threw(true);
return Undefined(env->isolate());
Expand Down Expand Up @@ -2891,8 +2902,12 @@ static void RawDebug(const FunctionCallbackInfo<Value>& args) {
void LoadEnvironment(Environment* env) {
HandleScope handle_scope(env->isolate());

if (g_upstream_node_mode) { // No indent to minimize diff.
env->isolate()->SetFatalErrorHandler(node::OnFatalError);
} // g_upstream_node_mode
if (g_standalone_mode) { // No indent to minimize diff.
env->isolate()->AddMessageListener(OnMessage);
} // g_standalone_mode

// Compile, execute the src/node.js file. (Which was included as static C
// string in node_natives.h. 'natve_node' is the string containing that
Expand Down Expand Up @@ -3187,8 +3202,8 @@ static void DispatchMessagesDebugAgentCallback(Environment* env) {
uv_async_send(&dispatch_debug_messages_async);
}


static void StartDebug(Environment* env, bool wait) {
// Called from atom::NodeMain.
void StartDebug(Environment* env, bool wait) {
CHECK(!debugger_running);

env->debugger_agent()->set_dispatch_handler(
Expand Down Expand Up @@ -3531,6 +3546,7 @@ void Init(int* argc,
// Initialize prog_start_time to get relative uptime.
prog_start_time = static_cast<double>(uv_now(uv_default_loop()));

if (g_upstream_node_mode) { // No indent to minimize diff.
// Make inherited handles noninheritable.
uv_disable_stdio_inheritance();

Expand Down Expand Up @@ -3595,12 +3611,15 @@ void Init(int* argc,
const char expose_debug_as[] = "--expose_debug_as=v8debug";
V8::SetFlagsFromString(expose_debug_as, sizeof(expose_debug_as) - 1);
}
} // g_upstream_node_mode

#if 0
V8::SetArrayBufferAllocator(&ArrayBufferAllocator::the_singleton);

if (!use_debug_agent) {
RegisterDebugSignalHandler();
}
#endif

// We should set node_is_initialized here instead of in node::Start,
// otherwise embedders using node::Init to initialize everything will not be
Expand Down
12 changes: 8 additions & 4 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ typedef intptr_t ssize_t;
namespace node {

NODE_EXTERN extern bool no_deprecation;
NODE_EXTERN extern bool use_debug_agent;
NODE_EXTERN extern bool debug_wait_connect;

NODE_EXTERN int Start(int argc, char *argv[]);
NODE_EXTERN void Init(int* argc,
Expand Down Expand Up @@ -184,6 +186,8 @@ NODE_EXTERN void EmitBeforeExit(Environment* env);
NODE_EXTERN int EmitExit(Environment* env);
NODE_EXTERN void RunAtExit(Environment* env);

NODE_EXTERN void StartDebug(Environment* env, bool wait);

/* Converts a unixtime to V8 Date */
#define NODE_UNIXTIME_V8(t) v8::Date::New(v8::Isolate::GetCurrent(), \
1000 * static_cast<double>(t))
Expand Down Expand Up @@ -369,14 +373,14 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
#if defined(_MSC_VER)
#pragma section(".CRT$XCU", read)
#define NODE_C_CTOR(fn) \
static void __cdecl fn(void); \
void __cdecl fn(void); \
__declspec(dllexport, allocate(".CRT$XCU")) \
void (__cdecl*fn ## _)(void) = fn; \
static void __cdecl fn(void)
void __cdecl fn(void)
#else
#define NODE_C_CTOR(fn) \
static void fn(void) __attribute__((constructor)); \
static void fn(void)
void fn(void) __attribute__((constructor)); \
void fn(void)
#endif

#define NODE_MODULE_X(modname, regfunc, priv, flags) \
Expand Down
Loading