Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: clarify usage of the cli options: -e,-p on windows #15543

Closed
wants to merge 13 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
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ cpplint:
@$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
@$(PYTHON) tools/check-imports.py

ifneq ("","$(wildcard tools/eslint/bin/eslint.js)")
ifneq ("","$(wildcard tools/eslint/)")
lint:
@EXIT_STATUS=0 ; \
$(MAKE) jslint || EXIT_STATUS=$$? ; \
Expand All @@ -943,7 +943,6 @@ lint:
@echo "Linting is not available through the source tarball."
@echo "Use the git repo instead:" \
"$ git clone https://github.com/nodejs/node.git"
exit 1

lint-ci: lint
endif
Expand Down
1 change: 1 addition & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ changes:

Identical to `-e` but prints the result.

*Note*: For options `-e` and `-p` please use double quote for the script, although it does not matter on the Linux that you use double quote or a single quote, on the Windows it makes a difference. On the Windows a single quote will not work correctly because Windows shell traditionally uses double quote as the quote char.

### `-c`, `--check`
<!-- YAML
Expand Down
3 changes: 1 addition & 2 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ instead.

Type: End-of-Life

[`Domain.dispose()`][] is removed. Recover from failed I/O actions
`Domain.dispose()` is removed. Recover from failed I/O actions
explicitly via error event handlers set on the domain instead.

<a id="DEP0013"></a>
Expand Down Expand Up @@ -688,7 +688,6 @@ difference is that `querystring.parse()` does url encoding:
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer
[`Buffer.isBuffer()`]: buffer.html#buffer_class_method_buffer_isbuffer_obj
[`Domain.dispose()`]: domain.html#domain_domain_dispose
[`EventEmitter.listenerCount(emitter, eventName)`]: events.html#events_eventemitter_listenercount_emitter_eventname
[`Server.connections`]: net.html#net_server_connections
[`Server.getConnections()`]: net.html#net_server_getconnections_callback
Expand Down
60 changes: 34 additions & 26 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2090,44 +2090,38 @@ ReadStream.prototype._read = function(n) {
}
};


ReadStream.prototype._destroy = function(err, cb) {
this.close(function(err2) {
cb(err || err2);
});
};


ReadStream.prototype.close = function(cb) {
if (cb)
this.once('close', cb);

if (this.closed || typeof this.fd !== 'number') {
if (typeof this.fd !== 'number') {
this.once('open', closeOnOpen);
this.once('open', closeFsStream.bind(null, this, cb, err));
return;
}
return process.nextTick(() => this.emit('close'));

return process.nextTick(() => {
cb(err);
this.emit('close');
});
}

this.closed = true;

fs.close(this.fd, (er) => {
if (er)
this.emit('error', er);
else
this.emit('close');
});

closeFsStream(this, cb);
this.fd = null;
};

// needed because as it will be called with arguments
// that does not match this.close() signature
function closeOnOpen(fd) {
this.close();
function closeFsStream(stream, cb, err) {
fs.close(stream.fd, (er) => {
er = er || err;
cb(er);
if (!er)
stream.emit('close');
});
}

ReadStream.prototype.close = function(cb) {
this.destroy(null, cb);
};

fs.createWriteStream = function(path, options) {
return new WriteStream(path, options);
};
Expand Down Expand Up @@ -2179,7 +2173,7 @@ function WriteStream(path, options) {
// dispose on finish.
this.once('finish', function() {
if (this.autoClose) {
this.close();
this.destroy();
}
});
}
Expand Down Expand Up @@ -2276,7 +2270,21 @@ WriteStream.prototype._writev = function(data, cb) {


WriteStream.prototype._destroy = ReadStream.prototype._destroy;
WriteStream.prototype.close = ReadStream.prototype.close;
WriteStream.prototype.close = function(cb) {
if (this._writableState.ending) {
this.on('close', cb);
return;
}

if (this._writableState.ended) {
process.nextTick(cb);
return;
}

// we use end() instead of destroy() because of
// https://github.com/nodejs/node/issues/2006
this.end(cb);
};

// There is no shutdown() for files.
WriteStream.prototype.destroySoon = WriteStream.prototype.end;
Expand Down
38 changes: 19 additions & 19 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function onStreamError(error) {
// errors in compatibility mode are
// not forwarded to the request
// and response objects. However,
// they are forwarded to 'clientError'
// they are forwarded to 'streamError'
// on the server by Http2Stream
}

Expand Down Expand Up @@ -248,9 +248,9 @@ class Http2ServerRequest extends Readable {
}

setTimeout(msecs, callback) {
const stream = this[kStream];
if (stream === undefined) return;
stream.setTimeout(msecs, callback);
if (this[kState].closed)
return;
this[kStream].setTimeout(msecs, callback);
}

[kFinish](code) {
Expand Down Expand Up @@ -445,7 +445,7 @@ class Http2ServerResponse extends Stream {

if (stream === undefined) {
const err = new errors.Error('ERR_HTTP2_STREAM_CLOSED');
if (cb)
if (typeof cb === 'function')
process.nextTick(cb, err);
else
throw err;
Expand All @@ -461,12 +461,11 @@ class Http2ServerResponse extends Stream {
if (typeof chunk === 'function') {
cb = chunk;
chunk = null;
encoding = 'utf8';
} else if (typeof encoding === 'function') {
cb = encoding;
encoding = 'utf8';
}
if (stream === undefined || stream.finished === true) {
if (this.finished === true) {
return false;
}
if (chunk !== null && chunk !== undefined) {
Expand All @@ -482,21 +481,21 @@ class Http2ServerResponse extends Stream {
}

destroy(err) {
const stream = this[kStream];
if (stream === undefined) {
// nothing to do, already closed
if (this[kState].closed)
return;
}
stream.destroy(err);
this[kStream].destroy(err);
}

setTimeout(msecs, callback) {
const stream = this[kStream];
if (stream === undefined) return;
if (this[kState].closed)
return;
stream.setTimeout(msecs, callback);
}

createPushResponse(headers, callback) {
if (typeof callback !== 'function')
throw new errors.TypeError('ERR_INVALID_CALLBACK');
const stream = this[kStream];
if (stream === undefined) {
process.nextTick(callback, new errors.Error('ERR_HTTP2_STREAM_CLOSED'));
Expand All @@ -513,12 +512,9 @@ class Http2ServerResponse extends Stream {
if (stream !== undefined &&
stream.destroyed === false &&
stream.headersSent === false) {
options = options || Object.create(null);
const state = this[kState];
const headers = this[kHeaders];
headers[HTTP2_HEADER_STATUS] = state.statusCode;
if (stream.finished === true)
options.endStream = true;
headers[HTTP2_HEADER_STATUS] = this[kState].statusCode;
options = options || Object.create(null);
options.getTrailers = (trailers) => {
Object.assign(trailers, this[kTrailers]);
};
Expand All @@ -542,7 +538,11 @@ class Http2ServerResponse extends Stream {
// TODO doesn't support callbacks
writeContinue() {
const stream = this[kStream];
if (stream === undefined) return false;
if (stream === undefined ||
stream.headersSent === true ||
stream.destroyed === true) {
return false;
}
this[kStream].additionalHeaders({
[HTTP2_HEADER_STATUS]: HTTP_STATUS_CONTINUE
});
Expand Down
2 changes: 1 addition & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ inline const struct read_result read_file(uv_file file) {
struct file_check {
bool failed = true;
uv_file file = -1;
} file_check;
};
inline const struct file_check check_file(URL search,
bool close = false,
bool allow_dir = false) {
Expand Down
45 changes: 16 additions & 29 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1339,30 +1339,6 @@ void AddPromiseHook(v8::Isolate* isolate, promise_hook_func fn, void* arg) {
env->AddPromiseHook(fn, arg);
}

class InternalCallbackScope {
public:
InternalCallbackScope(Environment* env,
Local<Object> object,
const async_context& asyncContext);
~InternalCallbackScope();
void Close();

inline bool Failed() const { return failed_; }
inline void MarkAsFailed() { failed_ = true; }
inline bool IsInnerMakeCallback() const {
return callback_scope_.in_makecallback();
}

private:
Environment* env_;
async_context async_context_;
v8::Local<v8::Object> object_;
Environment::AsyncCallbackScope callback_scope_;
bool failed_ = false;
bool pushed_ids_ = false;
bool closed_ = false;
};

CallbackScope::CallbackScope(Isolate* isolate,
Local<Object> object,
async_context asyncContext)
Expand All @@ -1381,17 +1357,21 @@ CallbackScope::~CallbackScope() {

InternalCallbackScope::InternalCallbackScope(Environment* env,
Local<Object> object,
const async_context& asyncContext)
const async_context& asyncContext,
ResourceExpectation expect)
: env_(env),
async_context_(asyncContext),
object_(object),
callback_scope_(env) {
CHECK(!object.IsEmpty());
if (expect == kRequireResource) {
CHECK(!object.IsEmpty());
}

HandleScope handle_scope(env->isolate());
// If you hit this assertion, you forgot to enter the v8::Context first.
CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());

if (env->using_domains()) {
if (env->using_domains() && !object_.IsEmpty()) {
DomainEnter(env, object_);
}

Expand All @@ -1413,6 +1393,7 @@ InternalCallbackScope::~InternalCallbackScope() {
void InternalCallbackScope::Close() {
if (closed_) return;
closed_ = true;
HandleScope handle_scope(env_->isolate());

if (pushed_ids_)
env_->async_hooks()->pop_ids(async_context_.async_id);
Expand All @@ -1423,7 +1404,7 @@ void InternalCallbackScope::Close() {
AsyncWrap::EmitAfter(env_, async_context_.async_id);
}

if (env_->using_domains()) {
if (env_->using_domains() && !object_.IsEmpty()) {
DomainExit(env_, object_);
}

Expand Down Expand Up @@ -1463,6 +1444,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,
int argc,
Local<Value> argv[],
async_context asyncContext) {
CHECK(!recv.IsEmpty());
InternalCallbackScope scope(env, recv, asyncContext);
if (scope.Failed()) {
return Undefined(env->isolate());
Expand Down Expand Up @@ -4726,9 +4708,14 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
do {
uv_run(env.event_loop(), UV_RUN_DEFAULT);

v8_platform.DrainVMTasks();

more = uv_loop_alive(env.event_loop());
if (more)
continue;

EmitBeforeExit(&env);

v8_platform.DrainVMTasks();
// Emit `beforeExit` if the loop became alive either after emitting
// event, or after running some callbacks.
more = uv_loop_alive(env.event_loop());
Expand Down
28 changes: 28 additions & 0 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,36 @@ v8::MaybeLocal<v8::Value> InternalMakeCallback(
v8::Local<v8::Value> argv[],
async_context asyncContext);

class InternalCallbackScope {
public:
// Tell the constructor whether its `object` parameter may be empty or not.
enum ResourceExpectation { kRequireResource, kAllowEmptyResource };
InternalCallbackScope(Environment* env,
v8::Local<v8::Object> object,
const async_context& asyncContext,
ResourceExpectation expect = kRequireResource);
~InternalCallbackScope();
void Close();

inline bool Failed() const { return failed_; }
inline void MarkAsFailed() { failed_ = true; }
inline bool IsInnerMakeCallback() const {
return callback_scope_.in_makecallback();
}

private:
Environment* env_;
async_context async_context_;
v8::Local<v8::Object> object_;
Environment::AsyncCallbackScope callback_scope_;
bool failed_ = false;
bool pushed_ids_ = false;
bool closed_ = false;
};

} // namespace node


#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#endif // SRC_NODE_INTERNALS_H_
7 changes: 4 additions & 3 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,14 @@ void MarkGarbageCollectionEnd(Isolate* isolate,
v8::GCCallbackFlags flags,
void* data) {
Environment* env = static_cast<Environment*>(data);
uv_async_t *async = new uv_async_t;
uv_async_t* async = new uv_async_t(); // coverity[leaked_storage]
if (uv_async_init(env->event_loop(), async, PerformanceGCCallback))
return delete async;
async->data =
new PerformanceEntry::Data(env, "gc", "gc",
performance_last_gc_start_mark_,
PERFORMANCE_NOW(), type);
uv_async_init(env->event_loop(), async, PerformanceGCCallback);
uv_async_send(async);
CHECK_EQ(0, uv_async_send(async));
}

inline void SetupGarbageCollectionTracking(Environment* env) {
Expand Down
Loading