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 1329844 as of 2018-03-17
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
  • Loading branch information
chakrabot committed Mar 20, 2018
2 parents 5a55cfb + 1329844 commit b7d8e8f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 12 deletions.
11 changes: 9 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1967,8 +1967,7 @@ function ReadStream(path, options) {
this.flags = options.flags === undefined ? 'r' : options.flags;
this.mode = options.mode === undefined ? 0o666 : options.mode;

this.start = typeof this.fd !== 'number' && options.start === undefined ?
0 : options.start;
this.start = options.start;
this.end = options.end;
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
this.pos = undefined;
Expand All @@ -1993,6 +1992,12 @@ function ReadStream(path, options) {
this.pos = this.start;
}

// Backwards compatibility: Make sure `end` is a number regardless of `start`.
// TODO(addaleax): Make the above typecheck not depend on `start` instead.
// (That is a semver-major change).
if (typeof this.end !== 'number')
this.end = Infinity;

if (typeof this.fd !== 'number')
this.open();

Expand Down Expand Up @@ -2047,6 +2052,8 @@ ReadStream.prototype._read = function(n) {

if (this.pos !== undefined)
toRead = Math.min(this.end - this.pos + 1, toRead);
else
toRead = Math.min(this.end - this.bytesRead + 1, toRead);

// already read everything we were supposed to read!
// treat as EOF.
Expand Down
12 changes: 9 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,10 @@ inspect.colors = Object.assign(Object.create(null), {
});

// Don't use 'blue' not visible on cmd.exe
const windows = process.platform === 'win32';
inspect.styles = Object.assign(Object.create(null), {
'special': 'cyan',
'number': windows ? 'yellow' : 'blue',
'bigint': windows ? 'yellow' : 'blue',
'number': 'yellow',
'bigint': 'yellow',
'boolean': 'yellow',
'undefined': 'grey',
'null': 'bold',
Expand Down Expand Up @@ -580,6 +579,13 @@ function formatValue(ctx, value, recurseTimes, ln) {
if (keyLength === 0)
return ctx.stylize(`[Boolean: ${formatted}]`, 'boolean');
base = `[Boolean: ${formatted}]`;
// eslint-disable-next-line valid-typeof
} else if (typeof raw === 'bigint') {
// Make boxed primitive BigInts look like such
const formatted = formatPrimitive(stylizeNoColor, raw);
if (keyLength === 0)
return ctx.stylize(`[BigInt: ${formatted}]`, 'bigint');
base = `[BigInt: ${formatted}]`;
} else if (typeof raw === 'symbol') {
const formatted = formatPrimitive(stylizeNoColor, raw);
return ctx.stylize(`[Symbol: ${formatted}]`, 'symbol');
Expand Down
12 changes: 8 additions & 4 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2801,11 +2801,15 @@ napi_status napi_make_callback(napi_env env,
isolate, v8recv, v8func, argc,
reinterpret_cast<v8::Local<v8::Value>*>(const_cast<napi_value*>(argv)),
*node_async_context);
CHECK_MAYBE_EMPTY(env, callback_result, napi_generic_failure);

if (result != nullptr) {
*result = v8impl::JsValueFromV8LocalValue(
callback_result.ToLocalChecked());
if (try_catch.HasCaught()) {
return napi_set_last_error(env, napi_pending_exception);
} else {
CHECK_MAYBE_EMPTY(env, callback_result, napi_generic_failure);
if (result != nullptr) {
*result = v8impl::JsValueFromV8LocalValue(
callback_result.ToLocalChecked());
}
}

return GET_RETURN_STATUS(env);
Expand Down
15 changes: 14 additions & 1 deletion test/addons-napi/test_make_callback_recurse/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@ napi_value MakeCallback(napi_env env, napi_callback_info info) {
napi_value recv = args[0];
napi_value func = args[1];

napi_make_callback(env, nullptr /* async_context */,
napi_status status = napi_make_callback(env, nullptr /* async_context */,
recv, func, 0 /* argc */, nullptr /* argv */, nullptr /* result */);

bool isExceptionPending;
NAPI_CALL(env, napi_is_exception_pending(env, &isExceptionPending));
if (isExceptionPending && !(status == napi_pending_exception)) {
// if there is an exception pending we don't expect any
// other error
napi_value pending_error;
status = napi_get_and_clear_last_exception(env, &pending_error);
NAPI_CALL(env,
napi_throw_error((env),
nullptr,
"error when only pending exception expected"));
}

return recv;
}

Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-fs-read-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');

const child_process = require('child_process');
const assert = require('assert');
const fs = require('fs');
const fixtures = require('../common/fixtures');
Expand Down Expand Up @@ -178,6 +180,31 @@ common.expectsError(
}));
}

if (!common.isWindows) {
// Verify that end works when start is not specified, and we do not try to
// use positioned reads. This makes sure that this keeps working for
// non-seekable file descriptors.
tmpdir.refresh();
const filename = `${tmpdir.path}/foo.pipe`;
const mkfifoResult = child_process.spawnSync('mkfifo', [filename]);
if (!mkfifoResult.error) {
child_process.exec(`echo "xyz foobar" > '${filename}'`);
const stream = new fs.createReadStream(filename, { end: 1 });
stream.data = '';

stream.on('data', function(chunk) {
stream.data += chunk;
});

stream.on('end', common.mustCall(function() {
assert.strictEqual('xy', stream.data);
fs.unlinkSync(filename);
}));
} else {
common.printSkipMessage('mkfifo not available');
}
}

{
// pause and then resume immediately.
const pauseRes = fs.createReadStream(rangeFile);
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-stream-buffer-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ assert.deepStrictEqual(list, new BufferList());

const tmp = util.inspect.defaultOptions.colors;
util.inspect.defaultOptions = { colors: true };
const color = util.inspect.colors[util.inspect.styles.number];
assert.strictEqual(
util.inspect(list),
`BufferList { length: \u001b[${color[0]}m0\u001b[${color[1]}m }`);
'BufferList { length: \u001b[33m0\u001b[39m }');
util.inspect.defaultOptions = { colors: tmp };
2 changes: 2 additions & 0 deletions test/parallel/test-util-inspect-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ const assert = require('assert');
const { inspect } = require('util');

assert.strictEqual(inspect(1n), '1n');
assert.strictEqual(inspect(Object(-1n)), '[BigInt: -1n]');
assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]');

0 comments on commit b7d8e8f

Please sign in to comment.