Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Merge nodejs/master
Browse files Browse the repository at this point in the history
Merge 3f98b0f as of 2017-08-07.
This is an automatically created merge. For any problems please
contact @kunalspathak.
  • Loading branch information
chakrabot committed Aug 8, 2017
2 parents 4abaa11 + 3f98b0f commit 8038ab4
Show file tree
Hide file tree
Showing 16 changed files with 658 additions and 379 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,16 @@ CPPLINT_EXCLUDE += src/queue.h
CPPLINT_EXCLUDE += src/tree.h
CPPLINT_EXCLUDE += $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h)
CPPLINT_EXCLUDE += $(wildcard test/addons-napi/??_*/*.cc test/addons-napi/??_*/*.h)
# These files were copied more or less verbatim from V8.
CPPLINT_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h

CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
src/*.c \
src/*.cc \
src/*.h \
src/*/*.c \
src/*/*.cc \
src/*/*.h \
test/addons/*/*.cc \
test/addons/*/*.h \
test/cctest/*.cc \
Expand Down
17 changes: 17 additions & 0 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
return console;
}
});
setupInspectorCommandLineAPI();
}

function installInspectorConsole(globalConsole) {
Expand Down Expand Up @@ -312,6 +313,22 @@
return wrappedConsole;
}

function setupInspectorCommandLineAPI() {
const { addCommandLineAPI } = process.binding('inspector');
if (!addCommandLineAPI) return;

const Module = NativeModule.require('module');
const { makeRequireFunction } = NativeModule.require('internal/module');
const path = NativeModule.require('path');
const cwd = tryGetCwd(path);

const consoleAPIModule = new Module('<inspector console>');
consoleAPIModule.paths =
Module._nodeModulePaths(cwd).concat(Module.globalPaths);

addCommandLineAPI('require', makeRequireFunction(consoleAPIModule));
}

function setupProcessFatal() {
const async_wrap = process.binding('async_wrap');
// Arrays containing hook flags and ids for async_hook calls.
Expand Down
38 changes: 23 additions & 15 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ class ChannelWrap : public AsyncWrap {

void Setup();
void EnsureServers();
void CleanupTimer();

inline uv_timer_t* timer_handle() { return &timer_handle_; }
inline uv_timer_t* timer_handle() { return timer_handle_; }
inline ares_channel cares_channel() { return channel_; }
inline bool query_last_ok() const { return query_last_ok_; }
inline void set_query_last_ok(bool ok) { query_last_ok_ = ok; }
Expand All @@ -152,7 +153,7 @@ class ChannelWrap : public AsyncWrap {
static void AresTimeout(uv_timer_t* handle);

private:
uv_timer_t timer_handle_;
uv_timer_t* timer_handle_;
ares_channel channel_;
bool query_last_ok_;
bool is_servers_default_;
Expand All @@ -163,6 +164,7 @@ class ChannelWrap : public AsyncWrap {
ChannelWrap::ChannelWrap(Environment* env,
Local<Object> object)
: AsyncWrap(env, object, PROVIDER_DNSCHANNEL),
timer_handle_(nullptr),
channel_(nullptr),
query_last_ok_(true),
is_servers_default_(true),
Expand Down Expand Up @@ -236,7 +238,8 @@ RB_GENERATE_STATIC(node_ares_task_list, node_ares_task, node, cmp_ares_tasks)
/* This is called once per second by loop->timer. It is used to constantly */
/* call back into c-ares for possibly processing timeouts. */
void ChannelWrap::AresTimeout(uv_timer_t* handle) {
ChannelWrap* channel = ContainerOf(&ChannelWrap::timer_handle_, handle);
ChannelWrap* channel = static_cast<ChannelWrap*>(handle->data);
CHECK_EQ(channel->timer_handle(), handle);
CHECK_EQ(false, RB_EMPTY(channel->task_list()));
ares_process_fd(channel->cares_channel(), ARES_SOCKET_BAD, ARES_SOCKET_BAD);
}
Expand Down Expand Up @@ -505,25 +508,30 @@ void ChannelWrap::Setup() {

/* Initialize the timeout timer. The timer won't be started until the */
/* first socket is opened. */
uv_timer_init(env()->event_loop(), &timer_handle_);
env()->RegisterHandleCleanup(
reinterpret_cast<uv_handle_t*>(&timer_handle_),
[](Environment* env, uv_handle_t* handle, void* arg) {
uv_close(handle, [](uv_handle_t* handle) {
ChannelWrap* channel = ContainerOf(
&ChannelWrap::timer_handle_,
reinterpret_cast<uv_timer_t*>(handle));
channel->env()->FinishHandleCleanup(handle);
});
},
nullptr);
CleanupTimer();
timer_handle_ = new uv_timer_t();
timer_handle_->data = static_cast<void*>(this);
uv_timer_init(env()->event_loop(), timer_handle_);
}


ChannelWrap::~ChannelWrap() {
if (library_inited_)
ares_library_cleanup();

ares_destroy(channel_);
CleanupTimer();
}


void ChannelWrap::CleanupTimer() {
if (timer_handle_ == nullptr) return;

uv_close(reinterpret_cast<uv_handle_t*>(timer_handle_),
[](uv_handle_t* handle) {
delete reinterpret_cast<uv_timer_t*>(handle);
});
timer_handle_ = nullptr;
}


Expand Down
1 change: 1 addition & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ namespace node {
V(context, v8::Context) \
V(domain_array, v8::Array) \
V(domains_stack_array, v8::Array) \
V(inspector_console_api_object, v8::Object) \
V(jsstream_constructor_template, v8::FunctionTemplate) \
V(module_load_list_array, v8::Array) \
V(pbkdf2_constructor_template, v8::ObjectTemplate) \
Expand Down
37 changes: 37 additions & 0 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace node {
namespace inspector {
namespace {
using v8::Array;
using v8::Context;
using v8::External;
using v8::Function;
Expand Down Expand Up @@ -554,6 +555,20 @@ class NodeInspectorClient : public V8InspectorClient {
return env_->context();
}

void installAdditionalCommandLineAPI(Local<Context> context,
Local<Object> target) override {
Local<Object> console_api = env_->inspector_console_api_object();

Local<Array> properties =
console_api->GetOwnPropertyNames(context).ToLocalChecked();
for (uint32_t i = 0; i < properties->Length(); ++i) {
Local<Value> key = properties->Get(context, i).ToLocalChecked();
target->Set(context,
key,
console_api->Get(context, key).ToLocalChecked()).FromJust();
}
}

void FatalException(Local<Value> error, Local<v8::Message> message) {
Local<Context> context = env_->context();

Expand Down Expand Up @@ -682,6 +697,20 @@ bool Agent::StartIoThread(bool wait_for_connect) {
return true;
}

static void AddCommandLineAPI(
const FunctionCallbackInfo<Value>& info) {
auto env = Environment::GetCurrent(info);
Local<Context> context = env->context();

if (info.Length() != 2 || !info[0]->IsString()) {
return env->ThrowTypeError("inspector.addCommandLineAPI takes "
"exactly 2 arguments: a string and a value.");
}

Local<Object> console_api = env->inspector_console_api_object();
console_api->Set(context, info[0], info[1]).FromJust();
}

void Agent::Stop() {
if (io_ != nullptr) {
io_->Stop();
Expand Down Expand Up @@ -784,8 +813,16 @@ void Url(const FunctionCallbackInfo<Value>& args) {
void Agent::InitInspector(Local<Object> target, Local<Value> unused,
Local<Context> context, void* priv) {
Environment* env = Environment::GetCurrent(context);
{
auto obj = Object::New(env->isolate());
auto null = Null(env->isolate());
CHECK(obj->SetPrototype(context, null).FromJust());
env->set_inspector_console_api_object(obj);
}

Agent* agent = env->inspector_agent();
env->SetMethod(target, "consoleCall", InspectorConsoleCall);
env->SetMethod(target, "addCommandLineAPI", AddCommandLineAPI);
if (agent->debug_options_.wait_for_connect())
env->SetMethod(target, "callAndPauseOnStart", CallAndPauseOnStart);
env->SetMethod(target, "connect", ConnectJSBindingsSession);
Expand Down
3 changes: 1 addition & 2 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <node_object_wrap.h>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <vector>
#include "uv.h"
Expand Down Expand Up @@ -850,7 +849,7 @@ napi_status napi_get_last_error_info(napi_env env,
static_assert(
node::arraysize(error_messages) == napi_escape_called_twice + 1,
"Count of error messages must match count of error values");
assert(env->last_error.error_code <= napi_escape_called_twice);
CHECK_LE(env->last_error.error_code, napi_escape_called_twice);

// Wait until someone requests the last error information to fetch the error
// message string
Expand Down
16 changes: 1 addition & 15 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2699,18 +2699,6 @@ int Connection::HandleSSLError(const char* func,
}


void Connection::ClearError() {
#ifndef NDEBUG
HandleScope scope(ssl_env()->isolate());

// We should clear the error in JS-land
Local<String> error_key = ssl_env()->error_string();
Local<Value> error = object()->Get(error_key);
CHECK_EQ(error->BooleanValue(), false);
#endif // NDEBUG
}


void Connection::SetShutdownFlags() {
HandleScope scope(ssl_env()->isolate());

Expand Down Expand Up @@ -5676,9 +5664,7 @@ void RandomBytesBuffer(const FunctionCallbackInfo<Value>& args) {
data,
RandomBytesRequest::DONT_FREE_DATA);
if (args[3]->IsFunction()) {
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(args.GetIsolate(), "ondone"),
args[3]).FromJust();
obj->Set(env->context(), env->ondone_string(), args[3]).FromJust();

if (env->in_domain()) {
obj->Set(env->context(),
Expand Down
1 change: 0 additions & 1 deletion src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ class Connection : public AsyncWrap, public SSLWrap<Connection> {

int HandleSSLError(const char* func, int rv, ZeroStatus zs, SyscallStatus ss);

void ClearError();
void SetShutdownFlags();

Connection(Environment* env,
Expand Down
10 changes: 3 additions & 7 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ void TCPWrap::Initialize(Local<Object> target,
// Init properties
t->InstanceTemplate()->Set(String::NewFromUtf8(env->isolate(), "reading"),
Boolean::New(env->isolate(), false));
t->InstanceTemplate()->Set(String::NewFromUtf8(env->isolate(), "owner"),
Null(env->isolate()));
t->InstanceTemplate()->Set(String::NewFromUtf8(env->isolate(), "onread"),
Null(env->isolate()));
t->InstanceTemplate()->Set(String::NewFromUtf8(env->isolate(),
"onconnection"),
Null(env->isolate()));
t->InstanceTemplate()->Set(env->owner_string(), Null(env->isolate()));
t->InstanceTemplate()->Set(env->onread_string(), Null(env->isolate()));
t->InstanceTemplate()->Set(env->onconnection_string(), Null(env->isolate()));

env->SetProtoMethod(t, "getAsyncId", AsyncWrap::GetAsyncId);
env->SetProtoMethod(t, "asyncReset", AsyncWrap::AsyncReset);
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace tracing {

class Agent {
public:
explicit Agent();
Agent();
void Start(v8::Platform* platform, const std::string& enabled_categories);
void Stop();

Expand Down
13 changes: 8 additions & 5 deletions src/tracing/node_trace_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ NodeTraceBuffer::NodeTraceBuffer(size_t max_chunks,
current_buf_.store(&buffer1_);

flush_signal_.data = this;
int err = uv_async_init(tracing_loop_, &flush_signal_, NonBlockingFlushSignalCb);
int err = uv_async_init(tracing_loop_, &flush_signal_,
NonBlockingFlushSignalCb);
CHECK_EQ(err, 0);

exit_signal_.data = this;
Expand All @@ -105,7 +106,7 @@ NodeTraceBuffer::NodeTraceBuffer(size_t max_chunks,
NodeTraceBuffer::~NodeTraceBuffer() {
uv_async_send(&exit_signal_);
Mutex::ScopedLock scoped_lock(exit_mutex_);
while(!exited_) {
while (!exited_) {
exit_cond_.Wait(scoped_lock);
}
}
Expand Down Expand Up @@ -138,7 +139,7 @@ bool NodeTraceBuffer::Flush() {
bool NodeTraceBuffer::TryLoadAvailableBuffer() {
InternalTraceBuffer* prev_buf = current_buf_.load();
if (prev_buf->IsFull()) {
uv_async_send(&flush_signal_); // trigger flush on a separate thread
uv_async_send(&flush_signal_); // trigger flush on a separate thread
InternalTraceBuffer* other_buf = prev_buf == &buffer1_ ?
&buffer2_ : &buffer1_;
if (!other_buf->IsFull()) {
Expand All @@ -165,8 +166,10 @@ void NodeTraceBuffer::NonBlockingFlushSignalCb(uv_async_t* signal) {
void NodeTraceBuffer::ExitSignalCb(uv_async_t* signal) {
NodeTraceBuffer* buffer = reinterpret_cast<NodeTraceBuffer*>(signal->data);
uv_close(reinterpret_cast<uv_handle_t*>(&buffer->flush_signal_), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&buffer->exit_signal_), [](uv_handle_t* signal) {
NodeTraceBuffer* buffer = reinterpret_cast<NodeTraceBuffer*>(signal->data);
uv_close(reinterpret_cast<uv_handle_t*>(&buffer->exit_signal_),
[](uv_handle_t* signal) {
NodeTraceBuffer* buffer =
reinterpret_cast<NodeTraceBuffer*>(signal->data);
Mutex::ScopedLock scoped_lock(buffer->exit_mutex_);
buffer->exited_ = true;
buffer->exit_cond_.Signal(scoped_lock);
Expand Down
7 changes: 3 additions & 4 deletions src/tracing/node_trace_buffer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SRC_NODE_TRACE_BUFFER_H_
#define SRC_NODE_TRACE_BUFFER_H_
#ifndef SRC_TRACING_NODE_TRACE_BUFFER_H_
#define SRC_TRACING_NODE_TRACE_BUFFER_H_

#include "node_mutex.h"
#include "tracing/node_trace_writer.h"
Expand Down Expand Up @@ -75,7 +75,6 @@ class NodeTraceBuffer : public TraceBuffer {
// Used to wait until async handles have been closed.
ConditionVariable exit_cond_;
std::unique_ptr<NodeTraceWriter> trace_writer_;
// TODO: Change std::atomic to something less contentious.
std::atomic<InternalTraceBuffer*> current_buf_;
InternalTraceBuffer buffer1_;
InternalTraceBuffer buffer2_;
Expand All @@ -84,4 +83,4 @@ class NodeTraceBuffer : public TraceBuffer {
} // namespace tracing
} // namespace node

#endif // SRC_NODE_TRACING_CONTROLLER_H_
#endif // SRC_TRACING_NODE_TRACE_BUFFER_H_
17 changes: 10 additions & 7 deletions src/tracing/node_trace_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void NodeTraceWriter::WriteSuffix() {
{
Mutex::ScopedLock scoped_lock(stream_mutex_);
if (total_traces_ > 0) {
total_traces_ = 0; // so we don't write it again in FlushPrivate
total_traces_ = 0; // so we don't write it again in FlushPrivate
// Appends "]}" to stream_.
delete json_trace_writer_;
should_flush = true;
Expand All @@ -49,7 +49,7 @@ NodeTraceWriter::~NodeTraceWriter() {
}
uv_async_send(&exit_signal_);
Mutex::ScopedLock scoped_lock(request_mutex_);
while(!exited_) {
while (!exited_) {
exit_cond_.Wait(scoped_lock);
}
}
Expand Down Expand Up @@ -110,8 +110,8 @@ void NodeTraceWriter::FlushSignalCb(uv_async_t* signal) {
trace_writer->FlushPrivate();
}

// TODO: Remove (is it necessary to change the API? Since because of WriteSuffix
// it no longer matters whether it's true or false)
// TODO(matthewloring): Remove (is it necessary to change the API?
// Since because of WriteSuffix it no longer matters whether it's true or false)
void NodeTraceWriter::Flush() {
Flush(true);
}
Expand Down Expand Up @@ -172,9 +172,12 @@ void NodeTraceWriter::WriteCb(uv_fs_t* req) {
// static
void NodeTraceWriter::ExitSignalCb(uv_async_t* signal) {
NodeTraceWriter* trace_writer = static_cast<NodeTraceWriter*>(signal->data);
uv_close(reinterpret_cast<uv_handle_t*>(&trace_writer->flush_signal_), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&trace_writer->exit_signal_), [](uv_handle_t* signal) {
NodeTraceWriter* trace_writer = static_cast<NodeTraceWriter*>(signal->data);
uv_close(reinterpret_cast<uv_handle_t*>(&trace_writer->flush_signal_),
nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&trace_writer->exit_signal_),
[](uv_handle_t* signal) {
NodeTraceWriter* trace_writer =
static_cast<NodeTraceWriter*>(signal->data);
Mutex::ScopedLock scoped_lock(trace_writer->request_mutex_);
trace_writer->exited_ = true;
trace_writer->exit_cond_.Signal(scoped_lock);
Expand Down
Loading

0 comments on commit 8038ab4

Please sign in to comment.