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

Commit 197665e

Browse files
committed
meta: merge node/master into node-chakracore/master
Merge 3549d9c as of 2017-12-05 This commit was automatically generated. For any problems, please contact jackhorton Reviewed-By: Taylor Woll <taylor.woll@microsoft.com>
2 parents fb3330b + 3549d9c commit 197665e

21 files changed

+403
-96
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ release.
5353
<a href="doc/changelogs/CHANGELOG_V8.md#8.0.0">8.0.0</a><br/>
5454
</td>
5555
<td valign="top">
56-
<b><a href="doc/changelogs/CHANGELOG_V6.md#6.12.0">6.12.0</a></b><br/>
56+
<b><a href="doc/changelogs/CHANGELOG_V6.md#6.12.1">6.12.1</a></b><br/>
57+
<a href="doc/changelogs/CHANGELOG_V6.md#6.12.0">6.12.0</a><br/>
5758
<a href="doc/changelogs/CHANGELOG_V6.md#6.11.5">6.11.5</a><br/>
5859
<a href="doc/changelogs/CHANGELOG_V6.md#6.11.4">6.11.4</a><br/>
5960
<a href="doc/changelogs/CHANGELOG_V6.md#6.11.3">6.11.3</a><br/>

doc/api/buffer.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,11 @@ console.log(buf2.toString());
510510
### Class Method: Buffer.alloc(size[, fill[, encoding]])
511511
<!-- YAML
512512
added: v5.10.0
513+
changes:
514+
- version: REPLACEME
515+
pr-url: https://github.com/nodejs/node/pull/17428
516+
description: Specifying an invalid string for `fill` now results in a
517+
zero-filled buffer.
513518
-->
514519

515520
* `size` {integer} The desired length of the new `Buffer`.
@@ -1254,6 +1259,19 @@ Example: Fill a `Buffer` with a two-byte character
12541259
console.log(Buffer.allocUnsafe(3).fill('\u0222'));
12551260
```
12561261

1262+
If `value` contains invalid characters, it is truncated; if no valid
1263+
fill data remains, no filling is performed:
1264+
1265+
```js
1266+
const buf = Buffer.allocUnsafe(5);
1267+
// Prints: <Buffer 61 61 61 61 61>
1268+
console.log(buf.fill('a'));
1269+
// Prints: <Buffer aa aa aa aa aa>
1270+
console.log(buf.fill('aazz', 'hex'));
1271+
// Prints: <Buffer aa aa aa aa aa>
1272+
console.log(buf.fill('zz', 'hex'));
1273+
```
1274+
12571275
### buf.includes(value[, byteOffset][, encoding])
12581276
<!-- YAML
12591277
added: v5.3.0

doc/changelogs/CHANGELOG_V6.md

Lines changed: 282 additions & 0 deletions
Large diffs are not rendered by default.

lib/buffer.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const {
2727
compare: _compare,
2828
compareOffset,
2929
createFromString,
30-
fill: _fill,
30+
fill: bindingFill,
3131
indexOfBuffer,
3232
indexOfNumber,
3333
indexOfString,
@@ -277,7 +277,9 @@ Buffer.alloc = function alloc(size, fill, encoding) {
277277
// be interpreted as a start offset.
278278
if (typeof encoding !== 'string')
279279
encoding = undefined;
280-
return createUnsafeBuffer(size).fill(fill, encoding);
280+
const ret = createUnsafeBuffer(size);
281+
if (fill_(ret, fill, encoding) > 0)
282+
return ret;
281283
}
282284
return new FastBuffer(size);
283285
};
@@ -852,15 +854,20 @@ Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
852854
// buffer.fill(buffer[, offset[, end]])
853855
// buffer.fill(string[, offset[, end]][, encoding])
854856
Buffer.prototype.fill = function fill(val, start, end, encoding) {
857+
fill_(this, val, start, end, encoding);
858+
return this;
859+
};
860+
861+
function fill_(buf, val, start, end, encoding) {
855862
// Handle string cases:
856863
if (typeof val === 'string') {
857864
if (typeof start === 'string') {
858865
encoding = start;
859866
start = 0;
860-
end = this.length;
867+
end = buf.length;
861868
} else if (typeof end === 'string') {
862869
encoding = end;
863-
end = this.length;
870+
end = buf.length;
864871
}
865872

866873
if (encoding !== undefined && typeof encoding !== 'string') {
@@ -889,19 +896,17 @@ Buffer.prototype.fill = function fill(val, start, end, encoding) {
889896
}
890897

891898
// Invalid ranges are not set to a default, so can range check early.
892-
if (start < 0 || end > this.length)
899+
if (start < 0 || end > buf.length)
893900
throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE');
894901

895902
if (end <= start)
896-
return this;
903+
return 0;
897904

898905
start = start >>> 0;
899-
end = end === undefined ? this.length : end >>> 0;
906+
end = end === undefined ? buf.length : end >>> 0;
900907

901-
_fill(this, val, start, end, encoding);
902-
903-
return this;
904-
};
908+
return bindingFill(buf, val, start, end, encoding);
909+
}
905910

906911

907912
Buffer.prototype.write = function write(string, offset, length, encoding) {

src/node_buffer.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
620620
THROW_AND_RETURN_IF_OOB(start <= end);
621621
THROW_AND_RETURN_IF_OOB(fill_length + start <= ts_obj_length);
622622

623+
args.GetReturnValue().Set(static_cast<double>(fill_length));
624+
623625
// First check if Buffer has been passed.
624626
if (Buffer::HasInstance(args[1])) {
625627
SPREAD_BUFFER_ARG(args[1], fill_obj);
@@ -652,8 +654,10 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
652654
enc == UTF8 ? str_obj->Utf8Length() :
653655
enc == UCS2 ? str_obj->Length() * sizeof(uint16_t) : str_obj->Length();
654656

655-
if (str_length == 0)
657+
if (str_length == 0) {
658+
args.GetReturnValue().Set(0);
656659
return;
660+
}
657661

658662
// Can't use StringBytes::Write() in all cases. For example if attempting
659663
// to write a two byte character into a one byte Buffer.
@@ -687,7 +691,7 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
687691
TTD_NATIVE_BUFFER_ACCESS_NOTIFY("Fill Questionable Case");
688692
#endif
689693

690-
return;
694+
return args.GetReturnValue().Set(0);
691695
}
692696
}
693697

test/async-hooks/test-graph.tcp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const server = net
1515
.createServer(common.mustCall(onconnection))
1616
.on('listening', common.mustCall(onlistening));
1717

18-
server.listen(common.PORT);
18+
server.listen(0);
1919

2020
net.connect({ port: server.address().port, host: '::1' },
2121
common.mustCall(onconnected));

test/async-hooks/test-graph.tls-write.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ const server = tls
2525
})
2626
.on('listening', common.mustCall(onlistening))
2727
.on('secureConnection', common.mustCall(onsecureConnection))
28-
.listen(common.PORT);
28+
.listen(0);
2929

3030
function onlistening() {
3131
//
3232
// Creating client and connecting it to server
3333
//
3434
tls
35-
.connect(common.PORT, { rejectUnauthorized: false })
35+
.connect(server.address().port, { rejectUnauthorized: false })
3636
.on('secureConnect', common.mustCall(onsecureConnect));
3737
}
3838

test/async-hooks/test-tcpwrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const server = net
2424

2525
// Calling server.listen creates a TCPWRAP synchronously
2626
{
27-
server.listen(common.PORT);
27+
server.listen(0);
2828
const tcpsservers = hooks.activitiesOfTypes('TCPSERVERWRAP');
2929
const tcpconnects = hooks.activitiesOfTypes('TCPCONNECTWRAP');
3030
assert.strictEqual(tcpsservers.length, 1);

test/async-hooks/test-writewrap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const server = tls
2323
})
2424
.on('listening', common.mustCall(onlistening))
2525
.on('secureConnection', common.mustCall(onsecureConnection))
26-
.listen(common.PORT);
26+
.listen(0);
2727

2828
assert.strictEqual(hooks.activitiesOfTypes('WRITEWRAP').length, 0);
2929

@@ -33,7 +33,7 @@ function onlistening() {
3333
// Creating client and connecting it to server
3434
//
3535
tls
36-
.connect(common.PORT, { rejectUnauthorized: false })
36+
.connect(server.address().port, { rejectUnauthorized: false })
3737
.on('secureConnect', common.mustCall(onsecureConnect));
3838

3939
assert.strictEqual(hooks.activitiesOfTypes('WRITEWRAP').length, 0);

test/common/README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ Tests whether `name` and `expected` are part of a raised warning.
118118

119119
Checks if `pathname` exists
120120

121-
### fires(promise, [error], [timeoutMs])
122-
* promise [&lt;Promise]
123-
* error [&lt;String] default = 'timeout'
124-
* timeoutMs [&lt;Number] default = 100
125-
126-
Returns a new promise that will propagate `promise` resolution or rejection if
127-
that happens within the `timeoutMs` timespan, or rejects with `error` as
128-
a reason otherwise.
129-
130121
### getArrayBufferViews(buf)
131122
* `buf` [&lt;Buffer>]
132123
* return [&lt;ArrayBufferView&#91;&#93;>]

0 commit comments

Comments
 (0)