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

Commit

Permalink
meta: merge node/master into node-chakracore/master
Browse files Browse the repository at this point in the history
Merge 7a055f1 as of 2017-12-12
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: Taylor Woll <[email protected]>
  • Loading branch information
boingoing committed Jan 18, 2018
2 parents bc073bf + 7a055f1 commit d21eee8
Show file tree
Hide file tree
Showing 69 changed files with 1,700 additions and 1,567 deletions.
2 changes: 1 addition & 1 deletion benchmark/fixtures/simple-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = http.createServer(function(req, res) {
const arg = params[2];
const n_chunks = parseInt(params[3], 10);
const resHow = params.length >= 5 ? params[4] : 'normal';
const chunkedEnc = params.length >= 6 && params[5] === 'false' ? false : true;
const chunkedEnc = params.length >= 6 && params[5] === '0' ? false : true;
var status = 200;

var n, i;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/http/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const bench = common.createBenchmark(main, {
len: [4, 1024, 102400],
chunks: [1, 4],
c: [50, 500],
chunkedEnc: ['true', 'false'],
chunkedEnc: [1, 0],
res: ['normal', 'setHeader', 'setHeaderWH']
});

function main(conf) {
process.env.PORT = PORT;
var server = require('../fixtures/simple-http-server.js')
.listen(process.env.PORT || common.PORT)
.listen(PORT)
.on('listening', function() {
const path =
`/${conf.type}/${conf.len}/${conf.chunks}/${conf.res}/${conf.chunkedEnc}`;
Expand Down
14 changes: 9 additions & 5 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ In this example, the variable `PI` is private to `circle.js`.
The `module.exports` property can be assigned a new value (such as a function
or object).

Below, `bar.js` makes use of the `square` module, which exports a constructor:
Below, `bar.js` makes use of the `square` module, which exports a Square class:

```js
const Square = require('./square.js');
Expand All @@ -50,10 +50,14 @@ The `square` module is defined in `square.js`:

```js
// assigning to exports will not modify module, must use module.exports
module.exports = (width) => {
return {
area: () => width ** 2
};
module.exports = class Square {
constructor(width) {
this.width = width;
}

area() {
return this.width ** 2;
}
};
```

Expand Down
3 changes: 2 additions & 1 deletion doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ terminal programs.

It is important to take note of the following:

* `SIGUSR1` is reserved by Node.js to start the debugger. It's possible to
* `SIGUSR1` is reserved by Node.js to start the [debugger][]. It's possible to
install a listener but doing so will _not_ stop the debugger from starting.
* `SIGTERM` and `SIGINT` have default handlers on non-Windows platforms that
resets the terminal mode before exiting with code `128 + signal number`. If
Expand Down Expand Up @@ -1971,6 +1971,7 @@ cases:
[`v8.setFlagsFromString()`]: v8.html#v8_v8_setflagsfromstring_flags
[Child Process]: child_process.html
[Cluster]: cluster.html
[debugger]: debugger.html
[Duplex]: stream.html#stream_duplex_and_transform_streams
[LTS]: https://github.com/nodejs/LTS/
[note on process I/O]: process.html#process_a_note_on_process_i_o
Expand Down
15 changes: 10 additions & 5 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ changes:
description: ALPN options are supported now.
-->

* `socket` {net.Socket} An instance of [`net.Socket`][]
* `socket` {net.Socket|stream.Duplex}
On the server side, any `Duplex` stream. On the client side, any
instance of [`net.Socket`][] (for generic `Duplex` stream support
on the client side, [`tls.connect()`][] must be used).
* `options` {Object}
* `isServer`: The SSL/TLS protocol is asymmetrical, TLSSockets must know if
they are to behave as a server or a client. If `true` the TLS socket will be
Expand Down Expand Up @@ -815,10 +818,12 @@ changes:
* `port` {number} Port the client should connect to.
* `path` {string} Creates unix socket connection to path. If this option is
specified, `host` and `port` are ignored.
* `socket` {net.Socket} Establish secure connection on a given socket rather
than creating a new socket. If this option is specified, `path`, `host` and
`port` are ignored. Usually, a socket is already connected when passed to
`tls.connect()`, but it can be connected later. Note that
* `socket` {stream.Duplex} Establish secure connection on a given socket
rather than creating a new socket. Typically, this is an instance of
[`net.Socket`][], but any `Duplex` stream is allowed.
If this option is specified, `path`, `host` and `port` are ignored,
except for certificate validation. Usually, a socket is already connected
when passed to `tls.connect()`, but it can be connected later. Note that
connection/disconnection/destruction of `socket` is the user's
responsibility, calling `tls.connect()` will not cause `net.connect()` to be
called.
Expand Down
36 changes: 2 additions & 34 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,7 @@ const { outHeadersKey } = require('internal/http');
const { nextTick } = require('internal/process/next_tick');
const errors = require('internal/errors');

// The actual list of disallowed characters in regexp form is more like:
// /[^A-Za-z0-9\-._~!$&'()*+,;=/:@]/
// with an additional rule for ignoring percentage-escaped characters, but
// that's a) hard to capture in a regular expression that performs well, and
// b) possibly too restrictive for real-world usage. So instead we restrict the
// filter to just control characters and spaces.
//
// This function is used in the case of small paths, where manual character code
// checks can greatly outperform the equivalent regexp (tested in V8 5.4).
function isInvalidPath(s) {
var i = 0;
if (s.charCodeAt(0) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(1) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(2) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(3) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(4) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(5) <= 32) return true;
++i;
for (; i < s.length; ++i)
if (s.charCodeAt(i) <= 32) return true;
return false;
}
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/;

function validateHost(host, name) {
if (host != null && typeof host !== 'string') {
Expand Down Expand Up @@ -117,13 +91,7 @@ function ClientRequest(options, cb) {
var path;
if (options.path) {
path = String(options.path);
var invalidPath;
if (path.length <= 39) { // Determined experimentally in V8 5.4
invalidPath = isInvalidPath(path);
} else {
invalidPath = /[\u0000-\u0020]/.test(path);
}
if (invalidPath)
if (INVALID_PATH_REGEX.test(path))
throw new errors.TypeError('ERR_UNESCAPED_CHARACTERS', 'Request path');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/_tls_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,6 @@ module.exports = {
createSecurePair:
internalUtil.deprecate(createSecurePair,
'tls.createSecurePair() is deprecated. Please use ' +
'tls.Socket instead.', 'DEP0064'),
'tls.TLSSocket instead.', 'DEP0064'),
pipe
};
9 changes: 0 additions & 9 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,6 @@ Socket.prototype.read = function(n) {
return this.read(n);
};


// FIXME(joyeecheung): this method is neither documented nor tested
Socket.prototype.listen = function() {
debug('socket.listen');
this.on('connection', arguments[0]);
listenInCluster(this, null, null, null);
};


Socket.prototype.setTimeout = function(msecs, callback) {
if (msecs === 0) {
timers.unenroll(this);
Expand Down
4 changes: 2 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function hasOwnProperty(obj, prop) {
// This is the default "writer" value if none is passed in the REPL options.
const writer = exports.writer = (obj) => util.inspect(obj, writer.options);
writer.options =
Object.assign(util.inspect.defaultOptions, { showProxy: true });
Object.assign({}, util.inspect.defaultOptions, { showProxy: true });

exports._builtinLibs = internalModule.builtinLibs;

Expand Down Expand Up @@ -470,7 +470,7 @@ function REPLServer(prompt,
if (self.useColors && self.writer === writer) {
// Turn on ANSI coloring.
self.writer = (obj) => util.inspect(obj, self.writer.options);
self.writer.options = Object.assign(writer.options, { colors: true });
self.writer.options = Object.assign({}, writer.options, { colors: true });
}

function filterInternalStackFrames(error, structuredStack) {
Expand Down
14 changes: 6 additions & 8 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,12 @@ class NodeInspectorClient : public V8InspectorClient {
}

void maxAsyncCallStackDepthChanged(int depth) override {
if (depth == 0) {
env_->inspector_agent()->DisableAsyncHook();
} else {
env_->inspector_agent()->EnableAsyncHook();
if (auto agent = env_->inspector_agent()) {
if (depth == 0) {
agent->DisableAsyncHook();
} else {
agent->EnableAsyncHook();
}
}
}

Expand Down Expand Up @@ -548,10 +550,6 @@ void Agent::Connect(InspectorSessionDelegate* delegate) {
client_->connectFrontend(delegate);
}

bool Agent::IsConnected() {
return io_ && io_->IsConnected();
}

void Agent::WaitForDisconnect() {
CHECK_NE(client_, nullptr);
client_->contextDestroyed(parent_env_->context());
Expand Down
1 change: 0 additions & 1 deletion src/inspector_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Agent {
bool IsStarted() { return !!client_; }

// IO thread started, and client connected
bool IsConnected();
bool IsWaitingForConnect();

void WaitForDisconnect();
Expand Down
73 changes: 47 additions & 26 deletions src/inspector_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class InspectorIoDelegate: public node::inspector::SocketServerDelegate {
const std::string& script_name, bool wait);
// Calls PostIncomingMessage() with appropriate InspectorAction:
// kStartSession
bool StartSession(int session_id, const std::string& target_id) override;
void StartSession(int session_id, const std::string& target_id) override;
// kSendMessage
void MessageReceived(int session_id, const std::string& message) override;
// kEndSession
Expand All @@ -145,19 +145,22 @@ class InspectorIoDelegate: public node::inspector::SocketServerDelegate {
std::vector<std::string> GetTargetIds() override;
std::string GetTargetTitle(const std::string& id) override;
std::string GetTargetUrl(const std::string& id) override;
bool IsConnected() { return connected_; }
void ServerDone() override {
io_->ServerDone();
}

void AssignTransport(InspectorSocketServer* server) {
server_ = server;
}

private:
InspectorIo* io_;
bool connected_;
int session_id_;
const std::string script_name_;
const std::string script_path_;
const std::string target_id_;
bool waiting_;
InspectorSocketServer* server_;
};

void InterruptCallback(v8::Isolate*, void* agent) {
Expand Down Expand Up @@ -226,10 +229,6 @@ void InspectorIo::Stop() {
DispatchMessages();
}

bool InspectorIo::IsConnected() {
return delegate_ != nullptr && delegate_->IsConnected();
}

bool InspectorIo::IsStarted() {
return platform_ != nullptr;
}
Expand Down Expand Up @@ -264,6 +263,7 @@ void InspectorIo::IoThreadAsyncCb(uv_async_t* async) {
MessageQueue<TransportAction> outgoing_message_queue;
io->SwapBehindLock(&io->outgoing_message_queue_, &outgoing_message_queue);
for (const auto& outgoing : outgoing_message_queue) {
int session_id = std::get<1>(outgoing);
switch (std::get<0>(outgoing)) {
case TransportAction::kKill:
transport->TerminateConnections();
Expand All @@ -272,8 +272,14 @@ void InspectorIo::IoThreadAsyncCb(uv_async_t* async) {
transport->Stop(nullptr);
break;
case TransportAction::kSendMessage:
std::string message = StringViewToUtf8(std::get<2>(outgoing)->string());
transport->Send(std::get<1>(outgoing), message);
transport->Send(session_id,
StringViewToUtf8(std::get<2>(outgoing)->string()));
break;
case TransportAction::kAcceptSession:
transport->AcceptSession(session_id);
break;
case TransportAction::kDeclineSession:
transport->DeclineSession(session_id);
break;
}
}
Expand All @@ -293,6 +299,7 @@ void InspectorIo::ThreadMain() {
wait_for_connect_);
delegate_ = &delegate;
Transport server(&delegate, &loop, options_.host_name(), options_.port());
delegate.AssignTransport(&server);
TransportAndIo<Transport> queue_transport(&server, this);
thread_req_.data = &queue_transport;
if (!server.Start()) {
Expand All @@ -308,6 +315,7 @@ void InspectorIo::ThreadMain() {
uv_run(&loop, UV_RUN_DEFAULT);
thread_req_.data = nullptr;
CHECK_EQ(uv_loop_close(&loop), 0);
delegate.AssignTransport(nullptr);
delegate_ = nullptr;
}

Expand Down Expand Up @@ -358,6 +366,21 @@ void InspectorIo::NotifyMessageReceived() {
incoming_message_cond_.Broadcast(scoped_lock);
}

TransportAction InspectorIo::Attach(int session_id) {
Agent* agent = parent_env_->inspector_agent();
if (agent->delegate() != nullptr)
return TransportAction::kDeclineSession;

CHECK_EQ(session_delegate_, nullptr);
session_id_ = session_id;
state_ = State::kConnected;
fprintf(stderr, "Debugger attached.\n");
session_delegate_ = std::unique_ptr<InspectorSessionDelegate>(
new IoSessionDelegate(this));
agent->Connect(session_delegate_.get());
return TransportAction::kAcceptSession;
}

void InspectorIo::DispatchMessages() {
// This function can be reentered if there was an incoming message while
// V8 was processing another inspector request (e.g. if the user is
Expand All @@ -375,16 +398,14 @@ void InspectorIo::DispatchMessages() {
MessageQueue<InspectorAction>::value_type task;
std::swap(dispatching_message_queue_.front(), task);
dispatching_message_queue_.pop_front();
int id = std::get<1>(task);
StringView message = std::get<2>(task)->string();
switch (std::get<0>(task)) {
case InspectorAction::kStartSession:
CHECK_EQ(session_delegate_, nullptr);
session_id_ = std::get<1>(task);
state_ = State::kConnected;
fprintf(stderr, "Debugger attached.\n");
session_delegate_ = std::unique_ptr<InspectorSessionDelegate>(
new IoSessionDelegate(this));
parent_env_->inspector_agent()->Connect(session_delegate_.get());
Write(Attach(id), id, StringView());
break;
case InspectorAction::kStartSessionUnconditionally:
Attach(id);
break;
case InspectorAction::kEndSession:
CHECK_NE(session_delegate_, nullptr);
Expand Down Expand Up @@ -428,22 +449,23 @@ InspectorIoDelegate::InspectorIoDelegate(InspectorIo* io,
const std::string& script_name,
bool wait)
: io_(io),
connected_(false),
session_id_(0),
script_name_(script_name),
script_path_(script_path),
target_id_(GenerateID()),
waiting_(wait) { }
waiting_(wait),
server_(nullptr) { }


bool InspectorIoDelegate::StartSession(int session_id,
void InspectorIoDelegate::StartSession(int session_id,
const std::string& target_id) {
if (connected_)
return false;
connected_ = true;
session_id_++;
io_->PostIncomingMessage(InspectorAction::kStartSession, session_id, "");
return true;
session_id_ = session_id;
InspectorAction action = InspectorAction::kStartSession;
if (waiting_) {
action = InspectorAction::kStartSessionUnconditionally;
server_->AcceptSession(session_id);
}
io_->PostIncomingMessage(action, session_id, "");
}

void InspectorIoDelegate::MessageReceived(int session_id,
Expand All @@ -464,7 +486,6 @@ void InspectorIoDelegate::MessageReceived(int session_id,
}

void InspectorIoDelegate::EndSession(int session_id) {
connected_ = false;
io_->PostIncomingMessage(InspectorAction::kEndSession, session_id, "");
}

Expand Down
Loading

0 comments on commit d21eee8

Please sign in to comment.