diff --git a/.eslintignore b/.eslintignore index 4b6e6b5e0fa94a..36833076ed8708 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ lib/internal/v8_prof_polyfill.js lib/punycode.js test/addons/??_* +test/es-module/test-esm-dynamic-import.js test/fixtures tools/eslint tools/icu diff --git a/.gitignore b/.gitignore index 190333f4b8f31a..40838bcc7fa8d7 100644 --- a/.gitignore +++ b/.gitignore @@ -106,8 +106,8 @@ deps/npm/node_modules/.bin/ # test artifacts tools/faketime -tools/remark-cli -tools/remark-preset-lint-node +tools/remark-cli/node_modules +tools/remark-preset-lint-node/node_modules icu_config.gypi *.tap diff --git a/Makefile b/Makefile index 2c62bf29cd2334..33a20983df0131 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ check: test coverage-clean: if [ -d lib_ ]; then $(RM) -r lib; mv lib_ lib; fi $(RM) -r node_modules - $(RM) -r gcovr testing + $(RM) -r gcovr build $(RM) -r out/$(BUILDTYPE)/.coverage $(RM) -r .cov_tmp $(RM) out/$(BUILDTYPE)/obj.target/node/{src,gen}/*.gcda @@ -162,11 +162,11 @@ coverage-build: all $(NODE) ./deps/npm install nyc --no-save --no-package-lock; fi if [ ! -d gcovr ]; then git clone --depth=1 \ --single-branch git://github.com/gcovr/gcovr.git; fi - if [ ! -d testing ]; then git clone --depth=1 \ - --single-branch https://github.com/nodejs/testing.git; fi + if [ ! -d build ]; then git clone --depth=1 \ + --single-branch https://github.com/nodejs/build.git; fi if [ ! -f gcovr/scripts/gcovr.orig ]; then \ (cd gcovr && patch -N -p1 < \ - "$(CURDIR)/testing/coverage/gcovr-patches.diff"); fi + "$(CURDIR)/build/jenkins/scripts/coverage/gcovr-patches.diff"); fi if [ -d lib_ ]; then $(RM) -r lib; mv lib_ lib; fi mv lib lib_ $(NODE) ./node_modules/.bin/nyc instrument --extension .js --extension .mjs lib_/ lib/ @@ -1123,7 +1123,6 @@ lint: ## Run JS, C++, MD and doc linters. @EXIT_STATUS=0 ; \ $(MAKE) lint-js || EXIT_STATUS=$$? ; \ $(MAKE) lint-cpp || EXIT_STATUS=$$? ; \ - $(MAKE) lint-md || EXIT_STATUS=$$? ; \ $(MAKE) lint-addon-docs || EXIT_STATUS=$$? ; \ $(MAKE) lint-md || EXIT_STATUS=$$? ; \ exit $$EXIT_STATUS diff --git a/benchmark/assert/deepequal-buffer.js b/benchmark/assert/deepequal-buffer.js index d4495af69b48ef..9556a81ec3b151 100644 --- a/benchmark/assert/deepequal-buffer.js +++ b/benchmark/assert/deepequal-buffer.js @@ -13,11 +13,7 @@ const bench = common.createBenchmark(main, { ] }); -function main(conf) { - const n = +conf.n; - const len = +conf.len; - var i; - +function main({ len, n, method }) { const data = Buffer.allocUnsafe(len + 1); const actual = Buffer.alloc(len); const expected = Buffer.alloc(len); @@ -26,40 +22,13 @@ function main(conf) { data.copy(expected); data.copy(expectedWrong); - switch (conf.method) { - case '': - // Empty string falls through to next line as default, mostly for tests. - case 'deepEqual': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.deepEqual(actual, expected); - } - bench.end(n); - break; - case 'deepStrictEqual': - bench.start(); - for (i = 0; i < n; ++i) { - assert.deepStrictEqual(actual, expected); - } - bench.end(n); - break; - case 'notDeepEqual': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.notDeepEqual(actual, expectedWrong); - } - bench.end(n); - break; - case 'notDeepStrictEqual': - bench.start(); - for (i = 0; i < n; ++i) { - assert.notDeepStrictEqual(actual, expectedWrong); - } - bench.end(n); - break; - default: - throw new Error('Unsupported method'); + // eslint-disable-next-line no-restricted-properties + const fn = method !== '' ? assert[method] : assert.deepEqual; + const value2 = method.includes('not') ? expectedWrong : expected; + + bench.start(); + for (var i = 0; i < n; ++i) { + fn(actual, value2); } + bench.end(n); } diff --git a/benchmark/assert/deepequal-map.js b/benchmark/assert/deepequal-map.js index 4976f2619834bf..97dd447b1adcc0 100644 --- a/benchmark/assert/deepequal-map.js +++ b/benchmark/assert/deepequal-map.js @@ -120,6 +120,6 @@ function main(conf) { benchmark(assert.notDeepEqual, n, values, values2); break; default: - throw new Error('Unsupported method'); + throw new Error(`Unsupported method ${method}`); } } diff --git a/benchmark/assert/deepequal-object.js b/benchmark/assert/deepequal-object.js index 4ad3704408384d..4c95006b3b8bc7 100644 --- a/benchmark/assert/deepequal-object.js +++ b/benchmark/assert/deepequal-object.js @@ -25,51 +25,22 @@ function createObj(source, add = '') { })); } -function main(conf) { - const size = conf.size; - // TODO: Fix this "hack" - const n = conf.n / size; - var i; +function main({ size, n, method }) { + // TODO: Fix this "hack". `n` should not be manipulated. + n = n / size; const source = Array.apply(null, Array(size)); const actual = createObj(source); const expected = createObj(source); const expectedWrong = createObj(source, '4'); - switch (conf.method) { - case '': - // Empty string falls through to next line as default, mostly for tests. - case 'deepEqual': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.deepEqual(actual, expected); - } - bench.end(n); - break; - case 'deepStrictEqual': - bench.start(); - for (i = 0; i < n; ++i) { - assert.deepStrictEqual(actual, expected); - } - bench.end(n); - break; - case 'notDeepEqual': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.notDeepEqual(actual, expectedWrong); - } - bench.end(n); - break; - case 'notDeepStrictEqual': - bench.start(); - for (i = 0; i < n; ++i) { - assert.notDeepStrictEqual(actual, expectedWrong); - } - bench.end(n); - break; - default: - throw new Error('Unsupported method'); + // eslint-disable-next-line no-restricted-properties + const fn = method !== '' ? assert[method] : assert.deepEqual; + const value2 = method.includes('not') ? expectedWrong : expected; + + bench.start(); + for (var i = 0; i < n; ++i) { + fn(actual, value2); } + bench.end(n); } diff --git a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js index 19337d7828236d..d2517a48c2437a 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js @@ -30,14 +30,19 @@ const bench = common.createBenchmark(main, { ] }); -function main(conf) { - const prim = primValues[conf.prim]; - const n = +conf.n; - const len = +conf.len; +function run(fn, n, actual, expected) { + bench.start(); + for (var i = 0; i < n; ++i) { + fn(actual, expected); + } + bench.end(n); +} + +function main({ n, len, primitive, method }) { + const prim = primValues[primitive]; const actual = []; const expected = []; const expectedWrong = []; - var i; for (var x = 0; x < len; x++) { actual.push(prim); @@ -52,70 +57,38 @@ function main(conf) { const expectedSet = new Set(expected); const expectedWrongSet = new Set(expectedWrong); - switch (conf.method) { + switch (method) { + // Empty string falls through to next line as default, mostly for tests. case '': - // Empty string falls through to next line as default, mostly for tests. case 'deepEqual_Array': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.deepEqual(actual, expected); - } - bench.end(n); + // eslint-disable-next-line no-restricted-properties + run(assert.deepEqual, n, actual, expected); break; case 'deepStrictEqual_Array': - bench.start(); - for (i = 0; i < n; ++i) { - assert.deepStrictEqual(actual, expected); - } - bench.end(n); + run(assert.deepStrictEqual, n, actual, expected); break; case 'notDeepEqual_Array': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.notDeepEqual(actual, expectedWrong); - } - bench.end(n); + // eslint-disable-next-line no-restricted-properties + run(assert.notDeepEqual, n, actual, expectedWrong); break; case 'notDeepStrictEqual_Array': - bench.start(); - for (i = 0; i < n; ++i) { - assert.notDeepStrictEqual(actual, expectedWrong); - } - bench.end(n); + run(assert.notDeepStrictEqual, n, actual, expectedWrong); break; case 'deepEqual_Set': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.deepEqual(actualSet, expectedSet); - } - bench.end(n); + // eslint-disable-next-line no-restricted-properties + run(assert.deepEqual, n, actualSet, expectedSet); break; case 'deepStrictEqual_Set': - bench.start(); - for (i = 0; i < n; ++i) { - assert.deepStrictEqual(actualSet, expectedSet); - } - bench.end(n); + run(assert.deepStrictEqual, n, actualSet, expectedSet); break; case 'notDeepEqual_Set': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.notDeepEqual(actualSet, expectedWrongSet); - } - bench.end(n); + // eslint-disable-next-line no-restricted-properties + run(assert.notDeepEqual, n, actualSet, expectedWrongSet); break; case 'notDeepStrictEqual_Set': - bench.start(); - for (i = 0; i < n; ++i) { - assert.notDeepStrictEqual(actualSet, expectedWrongSet); - } - bench.end(n); + run(assert.notDeepStrictEqual, n, actualSet, expectedWrongSet); break; default: - throw new Error('Unsupported method'); + throw new Error(`Unsupported method "${method}"`); } } diff --git a/benchmark/assert/deepequal-prims-and-objs-big-loop.js b/benchmark/assert/deepequal-prims-and-objs-big-loop.js index 4a345f27c20f0e..2bfc9d6276317a 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-loop.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-loop.js @@ -30,43 +30,14 @@ function main(conf) { const actual = prim; const expected = prim; const expectedWrong = 'b'; - var i; - // Creates new array to avoid loop invariant code motion - switch (conf.method) { - case '': - // Empty string falls through to next line as default, mostly for tests. - case 'deepEqual': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.deepEqual([actual], [expected]); - } - bench.end(n); - break; - case 'deepStrictEqual': - bench.start(); - for (i = 0; i < n; ++i) { - assert.deepStrictEqual([actual], [expected]); - } - bench.end(n); - break; - case 'notDeepEqual': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.notDeepEqual([actual], [expectedWrong]); - } - bench.end(n); - break; - case 'notDeepStrictEqual': - bench.start(); - for (i = 0; i < n; ++i) { - assert.notDeepStrictEqual([actual], [expectedWrong]); - } - bench.end(n); - break; - default: - throw new Error('Unsupported method'); + // eslint-disable-next-line no-restricted-properties + const fn = method !== '' ? assert[method] : assert.deepEqual; + const value2 = method.includes('not') ? expectedWrong : expected; + + bench.start(); + for (var i = 0; i < n; ++i) { + fn([actual], [value2]); } + bench.end(n); } diff --git a/benchmark/assert/deepequal-set.js b/benchmark/assert/deepequal-set.js index aa0ebc064886a2..ea679e2333b68a 100644 --- a/benchmark/assert/deepequal-set.js +++ b/benchmark/assert/deepequal-set.js @@ -129,6 +129,6 @@ function main(conf) { benchmark(assert.notDeepEqual, n, values, values2); break; default: - throw new Error('Unsupported method'); + throw new Error(`Unsupported method "${method}"`); } } diff --git a/benchmark/assert/deepequal-typedarrays.js b/benchmark/assert/deepequal-typedarrays.js index 8e8cc4b083a73e..e6cfb867c62162 100644 --- a/benchmark/assert/deepequal-typedarrays.js +++ b/benchmark/assert/deepequal-typedarrays.js @@ -35,42 +35,14 @@ function main(conf) { const expectedWrong = Buffer.alloc(len); const wrongIndex = Math.floor(len / 2); expectedWrong[wrongIndex] = 123; - var i; - switch (conf.method) { - case '': - // Empty string falls through to next line as default, mostly for tests. - case 'deepEqual': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.deepEqual(actual, expected); - } - bench.end(n); - break; - case 'deepStrictEqual': - bench.start(); - for (i = 0; i < n; ++i) { - assert.deepStrictEqual(actual, expected); - } - bench.end(n); - break; - case 'notDeepEqual': - bench.start(); - for (i = 0; i < n; ++i) { - // eslint-disable-next-line no-restricted-properties - assert.notDeepEqual(actual, expectedWrong); - } - bench.end(n); - break; - case 'notDeepStrictEqual': - bench.start(); - for (i = 0; i < n; ++i) { - assert.notDeepStrictEqual(actual, expectedWrong); - } - bench.end(n); - break; - default: - throw new Error('Unsupported method'); + // eslint-disable-next-line no-restricted-properties + const fn = method !== '' ? assert[method] : assert.deepEqual; + const value2 = method.includes('not') ? expectedWrong : expected; + + bench.start(); + for (var i = 0; i < n; ++i) { + fn(actual, value2); } + bench.end(n); } diff --git a/benchmark/async_hooks/gc-tracking.js b/benchmark/async_hooks/gc-tracking.js index c71c1b07aa5431..d74b2bac463e28 100644 --- a/benchmark/async_hooks/gc-tracking.js +++ b/benchmark/async_hooks/gc-tracking.js @@ -21,25 +21,24 @@ function endAfterGC(n) { }); } -function main(conf) { - const n = +conf.n; - - switch (conf.method) { +function main({ n, method }) { + var i; + switch (method) { case 'trackingEnabled': bench.start(); - for (let i = 0; i < n; i++) { + for (i = 0; i < n; i++) { new AsyncResource('foobar'); } endAfterGC(n); break; case 'trackingDisabled': bench.start(); - for (let i = 0; i < n; i++) { + for (i = 0; i < n; i++) { new AsyncResource('foobar', { requireManualDestroy: true }); } endAfterGC(n); break; default: - throw new Error('Unsupported method'); + throw new Error(`Unsupported method "${method}"`); } } diff --git a/benchmark/buffers/buffer-bytelength.js b/benchmark/buffers/buffer-bytelength.js index fc6dfcf2301eaf..24a94d731984ad 100644 --- a/benchmark/buffers/buffer-bytelength.js +++ b/benchmark/buffers/buffer-bytelength.js @@ -21,10 +21,9 @@ function main(conf) { const encoding = conf.encoding; var strings = []; - var results; + var results = [ len * 16 ]; if (encoding === 'buffer') { strings = [ Buffer.alloc(len * 16, 'a') ]; - results = [ len * 16 ]; } else { for (const string of chars) { // Strings must be built differently, depending on encoding diff --git a/benchmark/buffers/buffer-compare-offset.js b/benchmark/buffers/buffer-compare-offset.js index 96719abfbe5618..551fcd2f0cec37 100644 --- a/benchmark/buffers/buffer-compare-offset.js +++ b/benchmark/buffers/buffer-compare-offset.js @@ -8,28 +8,22 @@ const bench = common.createBenchmark(main, { }); function compareUsingSlice(b0, b1, len, iter) { - var i; - bench.start(); - for (i = 0; i < iter; i++) + for (var i = 0; i < iter; i++) Buffer.compare(b0.slice(1, len), b1.slice(1, len)); - bench.end(iter / 1e6); } function compareUsingOffset(b0, b1, len, iter) { - var i; - bench.start(); - for (i = 0; i < iter; i++) + for (var i = 0; i < iter; i++) b0.compare(b1, 1, len, 1, len); - bench.end(iter / 1e6); } -function main(conf) { - const iter = (conf.millions >>> 0) * 1e6; - const size = (conf.size >>> 0); - const method = - conf.method === 'slice' ? compareUsingSlice : compareUsingOffset; - method(Buffer.alloc(size, 'a'), - Buffer.alloc(size, 'b'), - size >> 1, - iter); +function main({ millions, size, method }) { + const iter = millions * 1e6; + const fn = method === 'slice' ? compareUsingSlice : compareUsingOffset; + bench.start(); + fn(Buffer.alloc(size, 'a'), + Buffer.alloc(size, 'b'), + size >> 1, + iter); + bench.end(millions); } diff --git a/benchmark/buffers/buffer-creation.js b/benchmark/buffers/buffer-creation.js index 4ca0a049228f6c..a7b340131eb8aa 100644 --- a/benchmark/buffers/buffer-creation.js +++ b/benchmark/buffers/buffer-creation.js @@ -15,54 +15,39 @@ const bench = common.createBenchmark(main, { n: [1024] }); -function main(conf) { - const len = +conf.len; - const n = +conf.n; - switch (conf.type) { +function main({ len, n, type }) { + let fn, i; + switch (type) { case '': case 'fast-alloc': - bench.start(); - for (let i = 0; i < n * 1024; i++) { - Buffer.alloc(len); - } - bench.end(n); + fn = Buffer.alloc; break; case 'fast-alloc-fill': bench.start(); - for (let i = 0; i < n * 1024; i++) { + for (i = 0; i < n * 1024; i++) { Buffer.alloc(len, 0); } bench.end(n); - break; + return; case 'fast-allocUnsafe': - bench.start(); - for (let i = 0; i < n * 1024; i++) { - Buffer.allocUnsafe(len); - } - bench.end(n); + fn = Buffer.allocUnsafe; break; case 'slow-allocUnsafe': - bench.start(); - for (let i = 0; i < n * 1024; i++) { - Buffer.allocUnsafeSlow(len); - } - bench.end(n); + fn = Buffer.allocUnsafeSlow; break; case 'slow': - bench.start(); - for (let i = 0; i < n * 1024; i++) { - SlowBuffer(len); - } - bench.end(n); + fn = SlowBuffer; break; case 'buffer()': - bench.start(); - for (let i = 0; i < n * 1024; i++) { - Buffer(len); - } - bench.end(n); + fn = Buffer; break; default: - assert.fail(null, null, 'Should not get here'); + assert.fail('Should not get here'); + } + + bench.start(); + for (i = 0; i < n * 1024; i++) { + fn(len); } + bench.end(n); } diff --git a/benchmark/buffers/buffer-hex.js b/benchmark/buffers/buffer-hex.js index d05bb832b3068c..110c0ebc428ac3 100644 --- a/benchmark/buffers/buffer-hex.js +++ b/benchmark/buffers/buffer-hex.js @@ -11,15 +11,16 @@ function main(conf) { const len = conf.len | 0; const n = conf.n | 0; const buf = Buffer.alloc(len); + var i; - for (let i = 0; i < buf.length; i++) + for (i = 0; i < buf.length; i++) buf[i] = i & 0xff; const hex = buf.toString('hex'); bench.start(); - for (let i = 0; i < n; i += 1) + for (i = 0; i < n; i += 1) Buffer.from(hex, 'hex'); bench.end(n); diff --git a/benchmark/buffers/buffer-iterate.js b/benchmark/buffers/buffer-iterate.js index 4e911caa72ce14..430280e0158df5 100644 --- a/benchmark/buffers/buffer-iterate.js +++ b/benchmark/buffers/buffer-iterate.js @@ -26,33 +26,23 @@ function main(conf) { methods[method](buffer, conf.n); } - function benchFor(buffer, n) { - bench.start(); - for (var k = 0; k < n; k++) { for (var i = 0; i < buffer.length; i++) { assert(buffer[i] === 0); } } - - bench.end(n); } function benchForOf(buffer, n) { - bench.start(); - for (var k = 0; k < n; k++) { for (const b of buffer) { assert(b === 0); } } - bench.end(n); } function benchIterator(buffer, n) { - bench.start(); - for (var k = 0; k < n; k++) { const iter = buffer[Symbol.iterator](); var cur = iter.next(); @@ -63,6 +53,4 @@ function benchIterator(buffer, n) { } } - - bench.end(n); } diff --git a/benchmark/buffers/buffer-read-float.js b/benchmark/buffers/buffer-read-float.js new file mode 100644 index 00000000000000..afd9edf5578308 --- /dev/null +++ b/benchmark/buffers/buffer-read-float.js @@ -0,0 +1,41 @@ +'use strict'; +const common = require('../common.js'); + +const bench = common.createBenchmark(main, { + noAssert: ['false', 'true'], + type: ['Double', 'Float'], + endian: ['BE', 'LE'], + value: ['zero', 'big', 'small', 'inf', 'nan'], + millions: [1] +}); + +function main({ noAssert, millions, type, endian, value }) { + noAssert = noAssert === 'true'; + type = type || 'Double'; + const buff = Buffer.alloc(8); + const fn = `read${type}${endian}`; + const values = { + Double: { + zero: 0, + big: 2 ** 1023, + small: 2 ** -1074, + inf: Infinity, + nan: NaN, + }, + Float: { + zero: 0, + big: 2 ** 127, + small: 2 ** -149, + inf: Infinity, + nan: NaN, + }, + }; + + buff[`write${type}${endian}`](values[type][value], 0, noAssert); + + bench.start(); + for (var i = 0; i !== millions * 1e6; i++) { + buff[fn](0, noAssert); + } + bench.end(millions); +} diff --git a/benchmark/buffers/buffer-read-with-byteLength.js b/benchmark/buffers/buffer-read-with-byteLength.js new file mode 100644 index 00000000000000..9fe5e6f4bf43ff --- /dev/null +++ b/benchmark/buffers/buffer-read-with-byteLength.js @@ -0,0 +1,32 @@ +'use strict'; +const common = require('../common.js'); + +const types = [ + 'IntBE', + 'IntLE', + 'UIntBE', + 'UIntLE' +]; + +const bench = common.createBenchmark(main, { + noAssert: ['false', 'true'], + buffer: ['fast', 'slow'], + type: types, + millions: [1], + byteLength: [1, 2, 4, 6] +}); + +function main({ millions, noAssert, buf, type, byteLength }) { + noAssert = noAssert === 'true'; + type = type || 'UInt8'; + const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer; + const buff = new clazz(8); + const fn = `read${type}`; + + buff.writeDoubleLE(0, 0, noAssert); + bench.start(); + for (var i = 0; i !== millions * 1e6; i++) { + buff[fn](0, byteLength, noAssert); + } + bench.end(millions); +} diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js index 339da75befce4d..86dd84157a2919 100644 --- a/benchmark/buffers/buffer-read.js +++ b/benchmark/buffers/buffer-read.js @@ -25,21 +25,17 @@ const bench = common.createBenchmark(main, { millions: [1] }); -function main(conf) { - const noAssert = conf.noAssert === 'true'; - const len = +conf.millions * 1e6; - const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer; +function main({ noAssert, millions, buf, type }) { + noAssert = noAssert === 'true'; + const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer; const buff = new clazz(8); const type = conf.type || 'UInt8'; const fn = `read${type}`; buff.writeDoubleLE(0, 0, noAssert); - const testFunction = new Function('buff', ` - for (var i = 0; i !== ${len}; i++) { - buff.${fn}(0, ${JSON.stringify(noAssert)}); - } - `); bench.start(); - testFunction(buff); - bench.end(len / 1e6); + for (var i = 0; i !== millions * 1e6; i++) { + buff[fn](0, noAssert); + } + bench.end(millions); } diff --git a/benchmark/buffers/buffer-write.js b/benchmark/buffers/buffer-write.js index b500a13dedcccd..6da591035ca5d4 100644 --- a/benchmark/buffers/buffer-write.js +++ b/benchmark/buffers/buffer-write.js @@ -45,39 +45,31 @@ const mod = { writeUInt32LE: UINT32 }; -function main(conf) { - const noAssert = conf.noAssert === 'true'; - const len = +conf.millions * 1e6; - const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer; +function main({ noAssert, millions, buf, type }) { + const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer; const buff = new clazz(8); const type = conf.type || 'UInt8'; const fn = `write${type}`; if (/Int/.test(fn)) - benchInt(buff, fn, len, noAssert); + benchInt(buff, fn, millions, noAssert); else - benchFloat(buff, fn, len, noAssert); + benchFloat(buff, fn, millions, noAssert); } -function benchInt(buff, fn, len, noAssert) { +function benchInt(buff, fn, millions, noAssert) { const m = mod[fn]; - const testFunction = new Function('buff', ` - for (var i = 0; i !== ${len}; i++) { - buff.${fn}(i & ${m}, 0, ${JSON.stringify(noAssert)}); - } - `); bench.start(); - testFunction(buff); - bench.end(len / 1e6); + for (var i = 0; i !== millions * 1e6; i++) { + buff[fn](i & m, 0, noAssert); + } + bench.end(millions); } -function benchFloat(buff, fn, len, noAssert) { - const testFunction = new Function('buff', ` - for (var i = 0; i !== ${len}; i++) { - buff.${fn}(i, 0, ${JSON.stringify(noAssert)}); - } - `); +function benchFloat(buff, fn, millions, noAssert) { bench.start(); - testFunction(buff); - bench.end(len / 1e6); + for (var i = 0; i !== millions * 1e6; i++) { + buff[fn](i, 0, noAssert); + } + bench.end(millions); } diff --git a/benchmark/buffers/buffer_zero.js b/benchmark/buffers/buffer_zero.js index 06ca50bbb99ee7..1263732dce8e43 100644 --- a/benchmark/buffers/buffer_zero.js +++ b/benchmark/buffers/buffer_zero.js @@ -10,14 +10,10 @@ const bench = common.createBenchmark(main, { const zeroBuffer = Buffer.alloc(0); const zeroString = ''; -function main(conf) { - const n = +conf.n; - bench.start(); - - if (conf.type === 'buffer') - for (let i = 0; i < n * 1024; i++) Buffer.from(zeroBuffer); - else if (conf.type === 'string') - for (let i = 0; i < n * 1024; i++) Buffer.from(zeroString); +function main({ n, type }) { + const data = type === 'buffer' ? zeroBuffer : zeroString; + bench.start(); + for (var i = 0; i < n * 1024; i++) Buffer.from(data); bench.end(n); } diff --git a/benchmark/crypto/aes-gcm-throughput.js b/benchmark/crypto/aes-gcm-throughput.js index 246455de78ad88..5c1e71e7280575 100644 --- a/benchmark/crypto/aes-gcm-throughput.js +++ b/benchmark/crypto/aes-gcm-throughput.js @@ -8,13 +8,13 @@ const bench = common.createBenchmark(main, { len: [1024, 4 * 1024, 16 * 1024, 64 * 1024, 256 * 1024, 1024 * 1024] }); -function main(conf) { - const message = Buffer.alloc(conf.len, 'b'); - const key = crypto.randomBytes(keylen[conf.cipher]); +function main({ n, len, cipher }) { + const message = Buffer.alloc(len, 'b'); + const key = crypto.randomBytes(keylen[cipher]); const iv = crypto.randomBytes(12); const associate_data = Buffer.alloc(16, 'z'); bench.start(); - AEAD_Bench(conf.cipher, message, associate_data, key, iv, conf.n, conf.len); + AEAD_Bench(cipher, message, associate_data, key, iv, n, len); } function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) { diff --git a/benchmark/crypto/cipher-stream.js b/benchmark/crypto/cipher-stream.js index ca36bd736d9aea..64f6ff7b7292be 100644 --- a/benchmark/crypto/cipher-stream.js +++ b/benchmark/crypto/cipher-stream.js @@ -9,8 +9,7 @@ const bench = common.createBenchmark(main, { api: ['legacy', 'stream'] }); -function main(conf) { - var api = conf.api; +function main({ api, cipher, type, len, writes }) { if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) { console.error('Crypto streams not available until v0.10'); // use the legacy, just so that we can compare them. @@ -33,25 +32,25 @@ function main(conf) { // alice_secret and bob_secret should be the same assert(alice_secret === bob_secret); - const alice_cipher = crypto.createCipher(conf.cipher, alice_secret); - const bob_cipher = crypto.createDecipher(conf.cipher, bob_secret); + const alice_cipher = crypto.createCipher(cipher, alice_secret); + const bob_cipher = crypto.createDecipher(cipher, bob_secret); var message; var encoding; - switch (conf.type) { + switch (type) { case 'asc': - message = 'a'.repeat(conf.len); + message = 'a'.repeat(len); encoding = 'ascii'; break; case 'utf': - message = 'ü'.repeat(conf.len / 2); + message = 'ü'.repeat(len / 2); encoding = 'utf8'; break; case 'buf': - message = Buffer.alloc(conf.len, 'b'); + message = Buffer.alloc(len, 'b'); break; default: - throw new Error(`unknown message type: ${conf.type}`); + throw new Error(`unknown message type: ${type}`); } const fn = api === 'stream' ? streamWrite : legacyWrite; @@ -59,7 +58,7 @@ function main(conf) { // write data as fast as possible to alice, and have bob decrypt. // use old API for comparison to v0.8 bench.start(); - fn(alice_cipher, bob_cipher, message, encoding, conf.writes); + fn(alice_cipher, bob_cipher, message, encoding, writes); } function streamWrite(alice, bob, message, encoding, writes) { diff --git a/benchmark/crypto/get-ciphers.js b/benchmark/crypto/get-ciphers.js index 3f5ad17ad38716..d4c10a2427d360 100644 --- a/benchmark/crypto/get-ciphers.js +++ b/benchmark/crypto/get-ciphers.js @@ -7,12 +7,10 @@ const bench = common.createBenchmark(main, { v: ['crypto', 'tls'] }); -function main(conf) { - const n = +conf.n; - const v = conf.v; +function main({ n, v }) { const method = require(v).getCiphers; var i = 0; - // first call to getChipers will dominate the results + // First call to getChipers will dominate the results if (n > 1) { for (; i < n; i++) method(); diff --git a/benchmark/crypto/hash-stream-creation.js b/benchmark/crypto/hash-stream-creation.js index 5ac5a4f70b5c55..faaa12a9e5d484 100644 --- a/benchmark/crypto/hash-stream-creation.js +++ b/benchmark/crypto/hash-stream-creation.js @@ -13,8 +13,7 @@ const bench = common.createBenchmark(main, { api: ['legacy', 'stream'] }); -function main(conf) { - var api = conf.api; +function main({ api, type, len, out, writes, algo }) { if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) { console.error('Crypto streams not available until v0.10'); // use the legacy, just so that we can compare them. @@ -23,26 +22,26 @@ function main(conf) { var message; var encoding; - switch (conf.type) { + switch (type) { case 'asc': - message = 'a'.repeat(conf.len); + message = 'a'.repeat(len); encoding = 'ascii'; break; case 'utf': - message = 'ü'.repeat(conf.len / 2); + message = 'ü'.repeat(len / 2); encoding = 'utf8'; break; case 'buf': - message = Buffer.alloc(conf.len, 'b'); + message = Buffer.alloc(len, 'b'); break; default: - throw new Error(`unknown message type: ${conf.type}`); + throw new Error(`unknown message type: ${type}`); } const fn = api === 'stream' ? streamWrite : legacyWrite; bench.start(); - fn(conf.algo, message, encoding, conf.writes, conf.len, conf.out); + fn(algo, message, encoding, writes, len, out); } function legacyWrite(algo, message, encoding, writes, len, outEnc) { diff --git a/benchmark/crypto/hash-stream-throughput.js b/benchmark/crypto/hash-stream-throughput.js index 21ec3c7902b367..934e7a0b11bdae 100644 --- a/benchmark/crypto/hash-stream-throughput.js +++ b/benchmark/crypto/hash-stream-throughput.js @@ -12,8 +12,7 @@ const bench = common.createBenchmark(main, { api: ['legacy', 'stream'] }); -function main(conf) { - var api = conf.api; +function main({ api, type, len, algo, writes }) { if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) { console.error('Crypto streams not available until v0.10'); // use the legacy, just so that we can compare them. @@ -22,26 +21,26 @@ function main(conf) { var message; var encoding; - switch (conf.type) { + switch (type) { case 'asc': - message = 'a'.repeat(conf.len); + message = 'a'.repeat(len); encoding = 'ascii'; break; case 'utf': - message = 'ü'.repeat(conf.len / 2); + message = 'ü'.repeat(len / 2); encoding = 'utf8'; break; case 'buf': - message = Buffer.alloc(conf.len, 'b'); + message = Buffer.alloc(len, 'b'); break; default: - throw new Error(`unknown message type: ${conf.type}`); + throw new Error(`unknown message type: ${type}`); } const fn = api === 'stream' ? streamWrite : legacyWrite; bench.start(); - fn(conf.algo, message, encoding, conf.writes, conf.len); + fn(algo, message, encoding, writes, len); } function legacyWrite(algo, message, encoding, writes, len) { diff --git a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js index edab5ae08f7d63..40b69c31f977ca 100644 --- a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js +++ b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js @@ -22,10 +22,10 @@ const bench = common.createBenchmark(main, { len: [16, 32, 64] }); -function main(conf) { - const message = Buffer.alloc(conf.len, 'b'); +function main({ len, algo, keylen, n }) { + const message = Buffer.alloc(len, 'b'); bench.start(); - StreamWrite(conf.algo, conf.keylen, message, conf.n, conf.len); + StreamWrite(algo, keylen, message, n, len); } function StreamWrite(algo, keylen, message, n, len) { diff --git a/benchmark/crypto/rsa-sign-verify-throughput.js b/benchmark/crypto/rsa-sign-verify-throughput.js index bcde3a43d4d77a..3a0373b57d0bba 100644 --- a/benchmark/crypto/rsa-sign-verify-throughput.js +++ b/benchmark/crypto/rsa-sign-verify-throughput.js @@ -23,10 +23,10 @@ const bench = common.createBenchmark(main, { len: [1024, 102400, 2 * 102400, 3 * 102400, 1024 * 1024] }); -function main(conf) { - const message = Buffer.alloc(conf.len, 'b'); +function main({ len, algo, keylen, writes }) { + const message = Buffer.alloc(len, 'b'); bench.start(); - StreamWrite(conf.algo, conf.keylen, message, conf.writes, conf.len); + StreamWrite(algo, keylen, message, writes, len); } function StreamWrite(algo, keylen, message, writes, len) { diff --git a/benchmark/dgram/bind-params.js b/benchmark/dgram/bind-params.js index 411bef98adcf7c..ea1f430eed929b 100644 --- a/benchmark/dgram/bind-params.js +++ b/benchmark/dgram/bind-params.js @@ -12,14 +12,14 @@ const configs = { const bench = common.createBenchmark(main, configs); const noop = () => {}; -function main(conf) { - const n = +conf.n; - const port = conf.port === 'true' ? 0 : undefined; - const address = conf.address === 'true' ? '0.0.0.0' : undefined; +function main({ n, port, address }) { + port = port === 'true' ? 0 : undefined; + address = address === 'true' ? '0.0.0.0' : undefined; + var i; if (port !== undefined && address !== undefined) { bench.start(); - for (let i = 0; i < n; i++) { + for (i = 0; i < n; i++) { dgram.createSocket('udp4').bind(port, address) .on('error', noop) .unref(); @@ -27,7 +27,7 @@ function main(conf) { bench.end(n); } else if (port !== undefined) { bench.start(); - for (let i = 0; i < n; i++) { + for (i = 0; i < n; i++) { dgram.createSocket('udp4') .bind(port) .on('error', noop) @@ -36,7 +36,7 @@ function main(conf) { bench.end(n); } else if (port === undefined && address === undefined) { bench.start(); - for (let i = 0; i < n; i++) { + for (i = 0; i < n; i++) { dgram.createSocket('udp4') .bind() .on('error', noop) diff --git a/benchmark/domain/domain-fn-args.js b/benchmark/domain/domain-fn-args.js index 0b98d17674064c..606b9f05816159 100644 --- a/benchmark/domain/domain-fn-args.js +++ b/benchmark/domain/domain-fn-args.js @@ -30,15 +30,6 @@ function main(conf) { bench.end(n); } -function fn(a, b, c) { - if (!a) - a = 1; - - if (!b) - b = 2; - - if (!c) - c = 3; - +function fn(a = 1, b = 2, c = 3) { return a + b + c; } diff --git a/benchmark/es/defaultparams-bench.js b/benchmark/es/defaultparams-bench.js index 1393abbe54395c..a00b50137c1af3 100644 --- a/benchmark/es/defaultparams-bench.js +++ b/benchmark/es/defaultparams-bench.js @@ -20,37 +20,31 @@ function defaultParams(x = 1, y = 2) { assert.strictEqual(y, 2); } -function runOldStyleDefaults(n) { - - var i = 0; +function runOldStyleDefaults(millions) { bench.start(); - for (; i < n; i++) + for (var i = 0; i < millions * 1e6; i++) oldStyleDefaults(); - bench.end(n / 1e6); + bench.end(millions); } -function runDefaultParams(n) { - - var i = 0; +function runDefaultParams(millions) { bench.start(); - for (; i < n; i++) + for (var i = 0; i < millions * 1e6; i++) defaultParams(); - bench.end(n / 1e6); + bench.end(millions); } -function main(conf) { - const n = +conf.millions * 1e6; - - switch (conf.method) { +function main({ millions, method }) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'withoutdefaults': - runOldStyleDefaults(n); + runOldStyleDefaults(millions); break; case 'withdefaults': - runDefaultParams(n); + runDefaultParams(millions); break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${method}"`); } } diff --git a/benchmark/es/destructuring-bench.js b/benchmark/es/destructuring-bench.js index a6c9a81ae02895..2168940bdc44f0 100644 --- a/benchmark/es/destructuring-bench.js +++ b/benchmark/es/destructuring-bench.js @@ -8,10 +8,10 @@ const bench = common.createBenchmark(main, { millions: [100] }); -function runSwapManual(n) { +function runSwapManual(millions) { var x, y, r; bench.start(); - for (var i = 0; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { x = 1, y = 2; r = x; x = y; @@ -19,34 +19,32 @@ function runSwapManual(n) { assert.strictEqual(x, 2); assert.strictEqual(y, 1); } - bench.end(n / 1e6); + bench.end(millions); } -function runSwapDestructured(n) { +function runSwapDestructured(millions) { var x, y; bench.start(); - for (var i = 0; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { x = 1, y = 2; [x, y] = [y, x]; assert.strictEqual(x, 2); assert.strictEqual(y, 1); } - bench.end(n / 1e6); + bench.end(millions); } -function main(conf) { - const n = +conf.millions * 1e6; - - switch (conf.method) { +function main({ millions, method }) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'swap': - runSwapManual(n); + runSwapManual(millions); break; case 'destructure': - runSwapDestructured(n); + runSwapDestructured(millions); break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${method}"`); } } diff --git a/benchmark/es/destructuring-object-bench.js b/benchmark/es/destructuring-object-bench.js index 63e085a2424430..a84977c59bc2cd 100644 --- a/benchmark/es/destructuring-object-bench.js +++ b/benchmark/es/destructuring-object-bench.js @@ -7,45 +7,43 @@ const bench = common.createBenchmark(main, { millions: [100] }); -function runNormal(n) { +function runNormal(millions) { var i = 0; const o = { x: 0, y: 1 }; bench.start(); - for (; i < n; i++) { + for (; i < millions * 1e6; i++) { /* eslint-disable no-unused-vars */ const x = o.x; const y = o.y; const r = o.r || 2; /* eslint-enable no-unused-vars */ } - bench.end(n / 1e6); + bench.end(millions); } -function runDestructured(n) { +function runDestructured(millions) { var i = 0; const o = { x: 0, y: 1 }; bench.start(); - for (; i < n; i++) { + for (; i < millions * 1e6; i++) { /* eslint-disable no-unused-vars */ const { x, y, r = 2 } = o; /* eslint-enable no-unused-vars */ } - bench.end(n / 1e6); + bench.end(millions); } -function main(conf) { - const n = +conf.millions * 1e6; - - switch (conf.method) { +function main({ millions, method }) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'normal': - runNormal(n); + runNormal(millions); break; case 'destructureObject': - runDestructured(n); + runDestructured(millions); break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${method}"`); } } diff --git a/benchmark/es/foreach-bench.js b/benchmark/es/foreach-bench.js index 62aa02236fc7ae..0eb19093de7e7f 100644 --- a/benchmark/es/foreach-bench.js +++ b/benchmark/es/foreach-bench.js @@ -8,58 +8,51 @@ const bench = common.createBenchmark(main, { millions: [5] }); -function useFor(n, items, count) { - var i, j; +function useFor(millions, items, count) { bench.start(); - for (i = 0; i < n; i++) { - for (j = 0; j < count; j++) { + for (var i = 0; i < millions * 1e6; i++) { + for (var j = 0; j < count; j++) { /* eslint-disable no-unused-vars */ const item = items[j]; /* esline-enable no-unused-vars */ } } - bench.end(n / 1e6); + bench.end(millions); } -function useForOf(n, items) { - var i, item; +function useForOf(millions, items) { + var item; bench.start(); - for (i = 0; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { for (item of items) {} } - bench.end(n / 1e6); + bench.end(millions); } -function useForIn(n, items) { - var i, j, item; +function useForIn(millions, items) { bench.start(); - for (i = 0; i < n; i++) { - for (j in items) { + for (var i = 0; i < millions * 1e6; i++) { + for (var j in items) { /* eslint-disable no-unused-vars */ - item = items[j]; + const item = items[j]; /* esline-enable no-unused-vars */ } } - bench.end(n / 1e6); + bench.end(millions); } -function useForEach(n, items) { - var i; +function useForEach(millions, items) { bench.start(); - for (i = 0; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { items.forEach((item) => {}); } - bench.end(n / 1e6); + bench.end(millions); } -function main(conf) { - const n = +conf.millions * 1e6; - const count = +conf.count; - +function main({ millions, count, method }) { const items = new Array(count); - var i; var fn; - for (i = 0; i < count; i++) + for (var i = 0; i < count; i++) items[i] = i; switch (conf.method) { @@ -78,7 +71,7 @@ function main(conf) { fn = useForEach; break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${method}"`); } - fn(n, items, count); + fn(millions, items, count); } diff --git a/benchmark/es/map-bench.js b/benchmark/es/map-bench.js index 035ed1a22aaf91..445031aa9831de 100644 --- a/benchmark/es/map-bench.js +++ b/benchmark/es/map-bench.js @@ -11,63 +11,59 @@ const bench = common.createBenchmark(main, { millions: [1] }); -function runObject(n) { +function runObject(millions) { const m = {}; - var i = 0; bench.start(); - for (; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { m[`i${i}`] = i; m[`s${i}`] = String(i); assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]); m[`i${i}`] = undefined; m[`s${i}`] = undefined; } - bench.end(n / 1e6); + bench.end(millions); } -function runNullProtoObject(n) { +function runNullProtoObject(millions) { const m = Object.create(null); - var i = 0; bench.start(); - for (; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { m[`i${i}`] = i; m[`s${i}`] = String(i); assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]); m[`i${i}`] = undefined; m[`s${i}`] = undefined; } - bench.end(n / 1e6); + bench.end(millions); } -function runNullProtoLiteralObject(n) { +function runNullProtoLiteralObject(millions) { const m = { __proto__: null }; - var i = 0; bench.start(); - for (; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { m[`i${i}`] = i; m[`s${i}`] = String(i); assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]); m[`i${i}`] = undefined; m[`s${i}`] = undefined; } - bench.end(n / 1e6); + bench.end(millions); } function StorageObject() {} StorageObject.prototype = Object.create(null); -function runStorageObject(n) { +function runStorageObject(millions) { const m = new StorageObject(); - var i = 0; bench.start(); - for (; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { m[`i${i}`] = i; m[`s${i}`] = String(i); assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]); m[`i${i}`] = undefined; m[`s${i}`] = undefined; } - bench.end(n / 1e6); + bench.end(millions); } function fakeMap() { @@ -80,59 +76,55 @@ function fakeMap() { }; } -function runFakeMap(n) { +function runFakeMap(millions) { const m = fakeMap(); - var i = 0; bench.start(); - for (; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { m.set(`i${i}`, i); m.set(`s${i}`, String(i)); assert.strictEqual(String(m.get(`i${i}`)), m.get(`s${i}`)); m.set(`i${i}`, undefined); m.set(`s${i}`, undefined); } - bench.end(n / 1e6); + bench.end(millions); } -function runMap(n) { +function runMap(millions) { const m = new Map(); - var i = 0; bench.start(); - for (; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { m.set(`i${i}`, i); m.set(`s${i}`, String(i)); assert.strictEqual(String(m.get(`i${i}`)), m.get(`s${i}`)); m.set(`i${i}`, undefined); m.set(`s${i}`, undefined); } - bench.end(n / 1e6); + bench.end(millions); } -function main(conf) { - const n = +conf.millions * 1e6; - - switch (conf.method) { +function main({ millions, method }) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'object': - runObject(n); + runObject(millions); break; case 'nullProtoObject': - runNullProtoObject(n); + runNullProtoObject(millions); break; case 'nullProtoLiteralObject': - runNullProtoLiteralObject(n); + runNullProtoLiteralObject(millions); break; case 'storageObject': - runStorageObject(n); + runStorageObject(millions); break; case 'fakeMap': - runFakeMap(n); + runFakeMap(millions); break; case 'map': - runMap(n); + runMap(millions); break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${method}"`); } } diff --git a/benchmark/es/restparams-bench.js b/benchmark/es/restparams-bench.js index 32fa985dedb806..6ad766f10f16f6 100644 --- a/benchmark/es/restparams-bench.js +++ b/benchmark/es/restparams-bench.js @@ -33,49 +33,39 @@ function useArguments() { assert.strictEqual(arguments[3], 'b'); } -function runCopyArguments(n) { - - var i = 0; - bench.start(); - for (; i < n; i++) +function runCopyArguments(millions) { + for (var i = 0; i < millions * 1e6; i++) copyArguments(1, 2, 'a', 'b'); - bench.end(n / 1e6); } -function runRestArguments(n) { - - var i = 0; - bench.start(); - for (; i < n; i++) +function runRestArguments(millions) { + for (var i = 0; i < millions * 1e6; i++) restArguments(1, 2, 'a', 'b'); - bench.end(n / 1e6); } -function runUseArguments(n) { - - var i = 0; - bench.start(); - for (; i < n; i++) +function runUseArguments(millions) { + for (var i = 0; i < millions * 1e6; i++) useArguments(1, 2, 'a', 'b'); - bench.end(n / 1e6); } -function main(conf) { - const n = +conf.millions * 1e6; - - switch (conf.method) { +function main({ millions, method }) { + var fn; + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'copy': - runCopyArguments(n); + fn = runCopyArguments; break; case 'rest': - runRestArguments(n); + fn = runRestArguments; break; case 'arguments': - runUseArguments(n); + fn = runUseArguments; break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${method}"`); } + bench.start(); + fn(millions); + bench.end(millions); } diff --git a/benchmark/es/spread-bench.js b/benchmark/es/spread-bench.js index b6dfb5963e7acc..06361fe8aa6310 100644 --- a/benchmark/es/spread-bench.js +++ b/benchmark/es/spread-bench.js @@ -23,11 +23,10 @@ function makeTest(count, rest) { } } -function main(conf) { - const n = +conf.millions * 1e6; - const ctx = conf.context === 'context' ? {} : null; - var fn = makeTest(conf.count, conf.rest); - const args = new Array(conf.count); +function main({ millions, context, count, rest, method }) { + const ctx = context === 'context' ? {} : null; + var fn = makeTest(count, rest); + const args = new Array(count); var i; for (i = 0; i < conf.count; i++) args[i] = i; @@ -37,25 +36,25 @@ function main(conf) { // Empty string falls through to next line as default, mostly for tests. case 'apply': bench.start(); - for (i = 0; i < n; i++) + for (i = 0; i < millions * 1e6; i++) fn.apply(ctx, args); - bench.end(n / 1e6); + bench.end(millions); break; case 'spread': if (ctx !== null) fn = fn.bind(ctx); bench.start(); - for (i = 0; i < n; i++) + for (i = 0; i < millions * 1e6; i++) fn(...args); - bench.end(n / 1e6); + bench.end(millions); break; case 'call-spread': bench.start(); - for (i = 0; i < n; i++) + for (i = 0; i < millions * 1e6; i++) fn.call(ctx, ...args); - bench.end(n / 1e6); + bench.end(millions); break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${method}"`); } } diff --git a/benchmark/es/string-concatenations.js b/benchmark/es/string-concatenations.js index b7f5c319361c6c..e381259870cdea 100644 --- a/benchmark/es/string-concatenations.js +++ b/benchmark/es/string-concatenations.js @@ -65,7 +65,7 @@ function main(conf) { bench.end(n); break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${mode}"`); } return string; diff --git a/benchmark/es/string-repeat.js b/benchmark/es/string-repeat.js index 1ddc7db78c7f86..c1c8ce8cd0ce4a 100644 --- a/benchmark/es/string-repeat.js +++ b/benchmark/es/string-repeat.js @@ -35,7 +35,7 @@ function main(conf) { bench.end(n); break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${mode}"`); } assert.strictEqual([...str].length, size); diff --git a/benchmark/fs/bench-realpath.js b/benchmark/fs/bench-realpath.js index 881bd0031f0024..9b9887f2a65129 100644 --- a/benchmark/fs/bench-realpath.js +++ b/benchmark/fs/bench-realpath.js @@ -19,10 +19,8 @@ function main(conf) { bench.start(); if (pathType === 'relative') relativePath(n); - else if (pathType === 'resolved') - resolvedPath(n); else - throw new Error(`unknown "pathType": ${pathType}`); + resolvedPath(n); } function relativePath(n) { diff --git a/benchmark/fs/bench-realpathSync.js b/benchmark/fs/bench-realpathSync.js index 2239d9748af6af..7a01bd18cb72bf 100644 --- a/benchmark/fs/bench-realpathSync.js +++ b/benchmark/fs/bench-realpathSync.js @@ -14,28 +14,11 @@ const bench = common.createBenchmark(main, { }); -function main(conf) { - const n = conf.n >>> 0; - const pathType = conf.pathType; - +function main({ n, pathType }) { + const path = pathType === 'relative' ? relative_path : resolved_path; bench.start(); - if (pathType === 'relative') - relativePath(n); - else if (pathType === 'resolved') - resolvedPath(n); - else - throw new Error(`unknown "pathType": ${pathType}`); - bench.end(n); -} - -function relativePath(n) { for (var i = 0; i < n; i++) { - fs.realpathSync(relative_path); - } -} - -function resolvedPath(n) { - for (var i = 0; i < n; i++) { - fs.realpathSync(resolved_path); + fs.realpathSync(path); } + bench.end(n); } diff --git a/benchmark/fs/write-stream-throughput.js b/benchmark/fs/write-stream-throughput.js index 08f059156f2cd9..fc15ed1a434678 100644 --- a/benchmark/fs/write-stream-throughput.js +++ b/benchmark/fs/write-stream-throughput.js @@ -39,7 +39,6 @@ function main(conf) { try { fs.unlinkSync(filename); } catch (e) {} var started = false; - var ending = false; var ended = false; var f = fs.createWriteStream(filename); @@ -55,15 +54,9 @@ function main(conf) { function write() { - // don't try to write after we end, even if a 'drain' event comes. - // v0.8 streams are so sloppy! - if (ending) - return; - if (!started) { started = true; setTimeout(function() { - ending = true; f.end(); }, dur * 1000); bench.start(); diff --git a/benchmark/http/bench-parser.js b/benchmark/http/bench-parser.js index 1bc661e7289168..d629fe67e59e76 100644 --- a/benchmark/http/bench-parser.js +++ b/benchmark/http/bench-parser.js @@ -14,10 +14,7 @@ const bench = common.createBenchmark(main, { n: [1e5], }); - -function main(conf) { - const len = conf.len >>> 0; - const n = conf.n >>> 0; +function main({ len, n }) { var header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`; for (var i = 0; i < len; i++) { @@ -28,7 +25,6 @@ function main(conf) { processHeader(Buffer.from(header), n); } - function processHeader(header, n) { const parser = newParser(REQUEST); @@ -40,7 +36,6 @@ function processHeader(header, n) { bench.end(n); } - function newParser(type) { const parser = new HTTPParser(type); diff --git a/benchmark/http/simple.js b/benchmark/http/simple.js index 544aad49688386..0d80daa82d903b 100644 --- a/benchmark/http/simple.js +++ b/benchmark/http/simple.js @@ -1,6 +1,5 @@ 'use strict'; const common = require('../common.js'); -const PORT = common.PORT; const bench = common.createBenchmark(main, { // unicode confuses ab on os x. @@ -15,7 +14,7 @@ const bench = common.createBenchmark(main, { function main(conf) { process.env.PORT = PORT; var server = require('../fixtures/simple-http-server.js') - .listen(PORT) + .listen(common.PORT) .on('listening', function() { const path = `/${conf.type}/${conf.len}/${conf.chunks}/${conf.res}/${conf.chunkedEnc}`; diff --git a/benchmark/http/upgrade.js b/benchmark/http/upgrade.js new file mode 100644 index 00000000000000..6b39323396a2e3 --- /dev/null +++ b/benchmark/http/upgrade.js @@ -0,0 +1,51 @@ +'use strict'; + +const common = require('../common.js'); +const net = require('net'); + +const bench = common.createBenchmark(main, { + n: [5, 1000] +}); + +const reqData = 'GET / HTTP/1.1\r\n' + + 'Upgrade: WebSocket\r\n' + + 'Connection: Upgrade\r\n' + + '\r\n' + + 'WjN}|M(6'; + +const resData = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' + + 'Upgrade: WebSocket\r\n' + + 'Connection: Upgrade\r\n' + + '\r\n\r\n'; + +function main({ n }) { + var server = require('../fixtures/simple-http-server.js') + .listen(common.PORT) + .on('listening', function() { + bench.start(); + doBench(server.address(), n, function() { + bench.end(n); + server.close(); + }); + }) + .on('upgrade', function(req, socket, upgradeHead) { + socket.resume(); + socket.write(resData); + socket.end(); + }); +} + +function doBench(address, count, done) { + if (count === 0) { + done(); + return; + } + + const conn = net.createConnection(address.port); + conn.write(reqData); + conn.resume(); + + conn.on('end', function() { + doBench(address, count - 1, done); + }); +} diff --git a/benchmark/http2/respond-with-fd.js b/benchmark/http2/respond-with-fd.js index 791e5f3d1e7da6..ea29c70fffc1c5 100644 --- a/benchmark/http2/respond-with-fd.js +++ b/benchmark/http2/respond-with-fd.js @@ -1,7 +1,6 @@ 'use strict'; const common = require('../common.js'); -const PORT = common.PORT; const path = require('path'); const fs = require('fs'); @@ -29,7 +28,7 @@ function main(conf) { stream.respondWithFD(fd); stream.on('error', (err) => {}); }); - server.listen(PORT, () => { + server.listen(common.PORT, () => { bench.http({ path: '/', requests: n, diff --git a/benchmark/http2/simple.js b/benchmark/http2/simple.js index e8cb3ddee2dff8..5595c289d1d9fd 100644 --- a/benchmark/http2/simple.js +++ b/benchmark/http2/simple.js @@ -1,11 +1,8 @@ 'use strict'; const common = require('../common.js'); -const PORT = common.PORT; - const path = require('path'); const fs = require('fs'); - const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html'); const bench = common.createBenchmark(main, { @@ -27,7 +24,7 @@ function main(conf) { out.pipe(stream); stream.on('error', (err) => {}); }); - server.listen(PORT, () => { + server.listen(common.PORT, () => { bench.http({ path: '/', requests: n, diff --git a/benchmark/http2/write.js b/benchmark/http2/write.js index 91b9c8f0c5c073..4793d1821ba5dd 100644 --- a/benchmark/http2/write.js +++ b/benchmark/http2/write.js @@ -1,7 +1,6 @@ 'use strict'; const common = require('../common.js'); -const PORT = common.PORT; const bench = common.createBenchmark(main, { streams: [100, 200, 1000], @@ -29,7 +28,7 @@ function main(conf) { } write(); }); - server.listen(PORT, () => { + server.listen(common.PORT, () => { bench.http({ path: '/', requests: 10000, diff --git a/benchmark/misc/freelist.js b/benchmark/misc/freelist.js index 461f4b3e4c8960..6aa5a2148ff9f5 100644 --- a/benchmark/misc/freelist.js +++ b/benchmark/misc/freelist.js @@ -13,7 +13,6 @@ function main(conf) { const n = conf.n; const poolSize = 1000; const list = new FreeList('test', poolSize, Object); - var i; var j; const used = []; @@ -24,7 +23,7 @@ function main(conf) { bench.start(); - for (i = 0; i < n; i++) { + for (var i = 0; i < n; i++) { // Return all the items to the pool for (j = 0; j < poolSize; j++) { list.free(used[j]); diff --git a/benchmark/misc/function_call/index.js b/benchmark/misc/function_call/index.js index 6a2595d2ae188d..f45abb463f3de9 100644 --- a/benchmark/misc/function_call/index.js +++ b/benchmark/misc/function_call/index.js @@ -31,12 +31,10 @@ const bench = common.createBenchmark(main, { millions: [1, 10, 50] }); -function main(conf) { - const n = +conf.millions * 1e6; - - const fn = conf.type === 'cxx' ? cxx : js; +function main({ millions, type }) { + const fn = type === 'cxx' ? cxx : js; bench.start(); - for (var i = 0; i < n; i++) { + for (var i = 0; i < millions * 1e6; i++) { fn(); } bench.end(+conf.millions); diff --git a/benchmark/misc/object-property-bench.js b/benchmark/misc/object-property-bench.js index d6afd4e9c0bcbb..f985e3ebafa5b7 100644 --- a/benchmark/misc/object-property-bench.js +++ b/benchmark/misc/object-property-bench.js @@ -78,6 +78,6 @@ function main(conf) { runSymbol(n); break; default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${method}"`); } } diff --git a/benchmark/misc/punycode.js b/benchmark/misc/punycode.js index 40bcd70302003c..4851a3bae45dac 100644 --- a/benchmark/misc/punycode.js +++ b/benchmark/misc/punycode.js @@ -55,9 +55,8 @@ function runPunycode(n, val) { } function runICU(n, val) { - var i = 0; bench.start(); - for (; i < n; i++) + for (var i = 0; i < n; i++) usingICU(val); bench.end(n); } @@ -78,6 +77,6 @@ function main(conf) { } // fallthrough default: - throw new Error('Unexpected method'); + throw new Error(`Unexpected method "${method}"`); } } diff --git a/benchmark/module/module-loader.js b/benchmark/module/module-loader.js index a0b8f7b6892633..58d4dcf81c9316 100644 --- a/benchmark/module/module-loader.js +++ b/benchmark/module/module-loader.js @@ -12,13 +12,11 @@ const bench = common.createBenchmark(main, { useCache: ['true', 'false'] }); -function main(conf) { - const n = +conf.thousands * 1e3; - +function main({ thousands, fullPath, useCache }) { tmpdir.refresh(); try { fs.mkdirSync(benchmarkDirectory); } catch (e) {} - for (var i = 0; i <= n; i++) { + for (var i = 0; i <= thousands * 1e3; i++) { fs.mkdirSync(`${benchmarkDirectory}${i}`); fs.writeFileSync( `${benchmarkDirectory}${i}/package.json`, @@ -30,38 +28,38 @@ function main(conf) { ); } - if (conf.fullPath === 'true') - measureFull(n, conf.useCache === 'true'); + if (fullPath === 'true') + measureFull(thousands, useCache === 'true'); else - measureDir(n, conf.useCache === 'true'); + measureDir(thousands, useCache === 'true'); tmpdir.refresh(); } -function measureFull(n, useCache) { +function measureFull(thousands, useCache) { var i; if (useCache) { - for (i = 0; i <= n; i++) { + for (i = 0; i <= thousands * 1e3; i++) { require(`${benchmarkDirectory}${i}/index.js`); } } bench.start(); - for (i = 0; i <= n; i++) { + for (i = 0; i <= thousands * 1e3; i++) { require(`${benchmarkDirectory}${i}/index.js`); } - bench.end(n / 1e3); + bench.end(thousands); } -function measureDir(n, useCache) { +function measureDir(thousands, useCache) { var i; if (useCache) { - for (i = 0; i <= n; i++) { + for (i = 0; i <= thousands * 1e3; i++) { require(`${benchmarkDirectory}${i}`); } } bench.start(); - for (i = 0; i <= n; i++) { + for (i = 0; i <= thousands * 1e3; i++) { require(`${benchmarkDirectory}${i}`); } - bench.end(n / 1e3); + bench.end(thousands); } diff --git a/benchmark/net/net-wrap-js-stream-passthrough.js b/benchmark/net/net-wrap-js-stream-passthrough.js new file mode 100644 index 00000000000000..bf84285e81b53a --- /dev/null +++ b/benchmark/net/net-wrap-js-stream-passthrough.js @@ -0,0 +1,107 @@ +// test the speed of .pipe() with JSStream wrapping for PassThrough streams +'use strict'; + +const common = require('../common.js'); +const { PassThrough } = require('stream'); + +const bench = common.createBenchmark(main, { + len: [102400, 1024 * 1024 * 16], + type: ['utf', 'asc', 'buf'], + dur: [5], +}, { + flags: ['--expose-internals'] +}); + +var dur; +var len; +var type; +var chunk; +var encoding; +var JSStreamWrap; // Can only require internals inside main(). + +function main(conf) { + dur = +conf.dur; + len = +conf.len; + type = conf.type; + JSStreamWrap = require('internal/wrap_js_stream'); + + switch (type) { + case 'buf': + chunk = Buffer.alloc(len, 'x'); + break; + case 'utf': + encoding = 'utf8'; + chunk = 'ü'.repeat(len / 2); + break; + case 'asc': + encoding = 'ascii'; + chunk = 'x'.repeat(len); + break; + default: + throw new Error(`invalid type: ${type}`); + } + + doBenchmark(); +} + +function Writer() { + this.received = 0; + this.writable = true; +} + +Writer.prototype.write = function(chunk, encoding, cb) { + this.received += chunk.length; + + if (typeof encoding === 'function') + encoding(); + else if (typeof cb === 'function') + cb(); + + return true; +}; + +// doesn't matter, never emits anything. +Writer.prototype.on = function() {}; +Writer.prototype.once = function() {}; +Writer.prototype.emit = function() {}; +Writer.prototype.prependListener = function() {}; + + +function flow() { + const dest = this.dest; + const res = dest.write(chunk, encoding); + if (!res) + dest.once('drain', this.flow); + else + process.nextTick(this.flow); +} + +function Reader() { + this.flow = flow.bind(this); + this.readable = true; +} + +Reader.prototype.pipe = function(dest) { + this.dest = dest; + this.flow(); + return dest; +}; + + +function doBenchmark() { + const reader = new Reader(); + const writer = new Writer(); + + // the actual benchmark. + const fakeSocket = new JSStreamWrap(new PassThrough()); + bench.start(); + reader.pipe(fakeSocket); + fakeSocket.pipe(writer); + + setTimeout(function() { + const bytes = writer.received; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); + bench.end(gbits); + process.exit(0); + }, dur * 1000); +} diff --git a/benchmark/path/basename-win32.js b/benchmark/path/basename-win32.js index 6966e4fe81e1ac..37ee891f93a39a 100644 --- a/benchmark/path/basename-win32.js +++ b/benchmark/path/basename-win32.js @@ -1,6 +1,6 @@ 'use strict'; const common = require('../common.js'); -const path = require('path'); +const { win32 } = require('path'); const bench = common.createBenchmark(main, { pathext: [ @@ -20,7 +20,6 @@ const bench = common.createBenchmark(main, { function main(conf) { const n = +conf.n; - const p = path.win32; var input = String(conf.pathext); var ext; const extIdx = input.indexOf('|'); @@ -31,7 +30,7 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i++) { - p.basename(input, ext); + win32.basename(pathext, ext); } bench.end(n); } diff --git a/benchmark/timers/set-immediate-breadth.js b/benchmark/timers/set-immediate-breadth.js index 3d8b038342634d..7b61c1521e4d41 100644 --- a/benchmark/timers/set-immediate-breadth.js +++ b/benchmark/timers/set-immediate-breadth.js @@ -9,7 +9,7 @@ function main(conf) { const N = +conf.millions * 1e6; process.on('exit', function() { - bench.end(N / 1e6); + bench.end(millions); }); function cb() {} diff --git a/benchmark/timers/set-immediate-depth-args.js b/benchmark/timers/set-immediate-depth-args.js index 1f12ae6ec73fc0..654e0df9084c12 100644 --- a/benchmark/timers/set-immediate-depth-args.js +++ b/benchmark/timers/set-immediate-depth-args.js @@ -9,7 +9,7 @@ function main(conf) { const N = +conf.millions * 1e6; process.on('exit', function() { - bench.end(N / 1e6); + bench.end(millions); }); function cb3(n, arg2, arg3) { diff --git a/benchmark/timers/timers-cancel-pooled.js b/benchmark/timers/timers-cancel-pooled.js index 2e834cc4db53fe..7e6105c4ad6c91 100644 --- a/benchmark/timers/timers-cancel-pooled.js +++ b/benchmark/timers/timers-cancel-pooled.js @@ -28,5 +28,5 @@ function main(conf) { } function cb() { - assert(false, 'Timer should not call callback'); + assert.fail('Timer should not call callback'); } diff --git a/benchmark/timers/timers-cancel-unpooled.js b/benchmark/timers/timers-cancel-unpooled.js index ca3c0dbcd92c12..8f8dee8be5aeef 100644 --- a/benchmark/timers/timers-cancel-unpooled.js +++ b/benchmark/timers/timers-cancel-unpooled.js @@ -22,5 +22,5 @@ function main(conf) { } function cb() { - assert(false, `Timer ${this._idleTimeout} should not call callback`); + assert.fail(`Timer ${this._idleTimeout} should not call callback`); } diff --git a/benchmark/timers/timers-insert-unpooled.js b/benchmark/timers/timers-insert-unpooled.js index 98415625862075..6eabdf499e14cf 100644 --- a/benchmark/timers/timers-insert-unpooled.js +++ b/benchmark/timers/timers-insert-unpooled.js @@ -23,5 +23,5 @@ function main(conf) { } function cb() { - assert(false, `Timer ${this._idleTimeout} should not call callback`); + assert.fail(`Timer ${this._idleTimeout} should not call callback`); } diff --git a/benchmark/tls/convertprotocols.js b/benchmark/tls/convertprotocols.js index 5d561455051a0c..9f4969344d1bcd 100644 --- a/benchmark/tls/convertprotocols.js +++ b/benchmark/tls/convertprotocols.js @@ -7,17 +7,16 @@ const bench = common.createBenchmark(main, { n: [1, 50000] }); -function main(conf) { - const n = +conf.n; - - var i = 0; +function main({ n }) { + const input = ['ABC', 'XYZ123', 'FOO']; var m = {}; // First call dominates results if (n > 1) { - tls.convertNPNProtocols(['ABC', 'XYZ123', 'FOO'], m); + tls.convertNPNProtocols(input, m); m = {}; } bench.start(); - for (; i < n; i++) tls.convertNPNProtocols(['ABC', 'XYZ123', 'FOO'], m); + for (var i = 0; i < n; i++) + tls.convertNPNProtocols(input, m); bench.end(n); } diff --git a/benchmark/tls/tls-connect.js b/benchmark/tls/tls-connect.js index 628b040ee88c9b..65d1b101c4102a 100644 --- a/benchmark/tls/tls-connect.js +++ b/benchmark/tls/tls-connect.js @@ -11,7 +11,6 @@ const bench = common.createBenchmark(main, { var clientConn = 0; var serverConn = 0; -var server; var dur; var concurrency; var running = true; @@ -28,7 +27,7 @@ function main(conf) { ciphers: 'AES256-GCM-SHA384' }; - server = tls.createServer(options, onConnection); + const server = tls.createServer(options, onConnection); server.listen(common.PORT, onListening); } diff --git a/benchmark/url/legacy-vs-whatwg-url-get-prop.js b/benchmark/url/legacy-vs-whatwg-url-get-prop.js index 229a4e60652b64..f55c0f5783ec73 100644 --- a/benchmark/url/legacy-vs-whatwg-url-get-prop.js +++ b/benchmark/url/legacy-vs-whatwg-url-get-prop.js @@ -78,7 +78,7 @@ function main(conf) { const input = inputs[type]; if (!input) { - throw new Error('Unknown input type'); + throw new Error(`Unknown input type "${type}"`); } var noDead; // Avoid dead code elimination. @@ -90,7 +90,7 @@ function main(conf) { noDead = useWHATWG(n, input); break; default: - throw new Error('Unknown method'); + throw new Error(`Unknown method "${method}"`); } assert.ok(noDead); diff --git a/benchmark/url/legacy-vs-whatwg-url-parse.js b/benchmark/url/legacy-vs-whatwg-url-parse.js index ec386b7b85597d..aefb70a7213646 100644 --- a/benchmark/url/legacy-vs-whatwg-url-parse.js +++ b/benchmark/url/legacy-vs-whatwg-url-parse.js @@ -38,7 +38,7 @@ function main(conf) { const input = inputs[type]; if (!input) { - throw new Error('Unknown input type'); + throw new Error(`Unknown input type "${type}"`); } var noDead; // Avoid dead code elimination. @@ -50,7 +50,7 @@ function main(conf) { noDead = useWHATWG(n, input); break; default: - throw new Error('Unknown method'); + throw new Error(`Unknown method ${method}`); } assert.ok(noDead); diff --git a/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js b/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js index b4a80af4e5eabd..c2ec24ad3a5125 100644 --- a/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js +++ b/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js @@ -35,7 +35,7 @@ function main(conf) { const input = inputs[type]; if (!input) { - throw new Error('Unknown input type'); + throw new Error(`Unknown input type "${type}"`); } switch (method) { @@ -46,6 +46,6 @@ function main(conf) { useWHATWG(n, input); break; default: - throw new Error('Unknown method'); + throw new Error(`Unknown method ${method}`); } } diff --git a/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js b/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js index 2b8d2c36a810b3..c7284572bd2f86 100644 --- a/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js +++ b/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js @@ -37,7 +37,7 @@ function main(conf) { const input = inputs[type]; if (!input) { - throw new Error('Unknown input type'); + throw new Error(`Unknown input type "${type}"`); } switch (method) { @@ -48,6 +48,6 @@ function main(conf) { useWHATWG(n, input); break; default: - throw new Error('Unknown method'); + throw new Error(`Unknown method ${method}`); } } diff --git a/benchmark/url/legacy-vs-whatwg-url-serialize.js b/benchmark/url/legacy-vs-whatwg-url-serialize.js index 35b459a10c0e0b..2d1492192c0a6a 100644 --- a/benchmark/url/legacy-vs-whatwg-url-serialize.js +++ b/benchmark/url/legacy-vs-whatwg-url-serialize.js @@ -40,7 +40,7 @@ function main(conf) { const input = inputs[type]; if (!input) { - throw new Error('Unknown input type'); + throw new Error(`Unknown input type "${type}"`); } var noDead; // Avoid dead code elimination. @@ -52,7 +52,7 @@ function main(conf) { noDead = useWHATWG(n, input); break; default: - throw new Error('Unknown method'); + throw new Error(`Unknown method ${method}`); } assert.ok(noDead); diff --git a/benchmark/url/url-searchparams-iteration.js b/benchmark/url/url-searchparams-iteration.js index 0f4b71a0a183dd..6984cf3ce3b6fc 100644 --- a/benchmark/url/url-searchparams-iteration.js +++ b/benchmark/url/url-searchparams-iteration.js @@ -56,6 +56,6 @@ function main(conf) { iterator(n); break; default: - throw new Error('Unknown method'); + throw new Error(`Unknown method ${method}`); } } diff --git a/benchmark/url/url-searchparams-read.js b/benchmark/url/url-searchparams-read.js index 762ffcca03d69d..0cf66dabbc36dc 100644 --- a/benchmark/url/url-searchparams-read.js +++ b/benchmark/url/url-searchparams-read.js @@ -10,49 +10,14 @@ const bench = common.createBenchmark(main, { const str = 'one=single&two=first&three=first&two=2nd&three=2nd&three=3rd'; -function get(n, param) { +function main({ method, param, n }) { const params = new URLSearchParams(str); + const fn = params[method]; + if (!fn) + throw new Error(`Unknown method ${method}`); bench.start(); for (var i = 0; i < n; i += 1) - params.get(param); + fn(param); bench.end(n); } - -function getAll(n, param) { - const params = new URLSearchParams(str); - - bench.start(); - for (var i = 0; i < n; i += 1) - params.getAll(param); - bench.end(n); -} - -function has(n, param) { - const params = new URLSearchParams(str); - - bench.start(); - for (var i = 0; i < n; i += 1) - params.has(param); - bench.end(n); -} - -function main(conf) { - const method = conf.method; - const param = conf.param; - const n = conf.n | 0; - - switch (method) { - case 'get': - get(n, param); - break; - case 'getAll': - getAll(n, param); - break; - case 'has': - has(n, param); - break; - default: - throw new Error('Unknown method'); - } -} diff --git a/benchmark/url/url-searchparams-sort.js b/benchmark/url/url-searchparams-sort.js index 677ce511cf3ea2..d37740b6709826 100644 --- a/benchmark/url/url-searchparams-sort.js +++ b/benchmark/url/url-searchparams-sort.js @@ -38,9 +38,8 @@ function main(conf) { const params = new URLSearchParams(); const array = getParams(input); - var i; bench.start(); - for (i = 0; i < n; i++) { + for (var i = 0; i < n; i++) { params[searchParams] = array.slice(); params.sort(); } diff --git a/benchmark/util/format.js b/benchmark/util/format.js index 6f171318ee28bf..042b8a93ccfcf2 100644 --- a/benchmark/util/format.js +++ b/benchmark/util/format.js @@ -21,7 +21,8 @@ const bench = common.createBenchmark(main, { }); function main({ n, type }) { - const [first, second] = inputs[type]; + // For testing, if supplied with an empty type, default to string. + const [first, second] = inputs[type || 'string']; bench.start(); for (var i = 0; i < n; i++) { diff --git a/benchmark/util/inspect-array.js b/benchmark/util/inspect-array.js index 751e2c3c2deb8f..8b3c54aeb942fe 100644 --- a/benchmark/util/inspect-array.js +++ b/benchmark/util/inspect-array.js @@ -23,6 +23,8 @@ function main({ n, len, type }) { opts = { showHidden: true }; arr = arr.fill('denseArray'); break; + // For testing, if supplied with an empty type, default to denseArray. + case '': case 'denseArray': arr = arr.fill('denseArray'); break; diff --git a/benchmark/v8/get-stats.js b/benchmark/v8/get-stats.js index 96de7572397161..84a0655f5db4fa 100644 --- a/benchmark/v8/get-stats.js +++ b/benchmark/v8/get-stats.js @@ -11,12 +11,9 @@ const bench = common.createBenchmark(main, { n: [1e6] }); -function main(conf) { - const n = +conf.n; - const method = conf.method; - var i = 0; +function main({ method, n }) { bench.start(); - for (; i < n; i++) + for (var i = 0; i < n; i++) v8[method](); bench.end(n); } diff --git a/benchmark/vm/run-in-context.js b/benchmark/vm/run-in-context.js index 6e26a6d0ebeb38..f249f219bebc7e 100644 --- a/benchmark/vm/run-in-context.js +++ b/benchmark/vm/run-in-context.js @@ -19,12 +19,10 @@ function main(conf) { if (withSigintListener) process.on('SIGINT', () => {}); - var i = 0; - const contextifiedSandbox = vm.createContext(); bench.start(); - for (; i < n; i++) + for (var i = 0; i < n; i++) vm.runInContext('0', contextifiedSandbox, options); bench.end(n); } diff --git a/benchmark/vm/run-in-this-context.js b/benchmark/vm/run-in-this-context.js index a0c737f46954f1..b297b7a2eb7a2d 100644 --- a/benchmark/vm/run-in-this-context.js +++ b/benchmark/vm/run-in-this-context.js @@ -19,10 +19,8 @@ function main(conf) { if (withSigintListener) process.on('SIGINT', () => {}); - var i = 0; - bench.start(); - for (; i < n; i++) + for (var i = 0; i < n; i++) vm.runInThisContext('0', options); bench.end(n); } diff --git a/common.gypi b/common.gypi index b89a8afff03a63..fd42f27d351282 100644 --- a/common.gypi +++ b/common.gypi @@ -40,29 +40,29 @@ 'conditions': [ ['GENERATOR=="ninja"', { - 'OBJ_DIR': '<(PRODUCT_DIR)/obj', - 'V8_BASE': '<(PRODUCT_DIR)/obj/deps/v8/src/libv8_base.a', + 'obj_dir': '<(PRODUCT_DIR)/obj', + 'v8_base': '<(PRODUCT_DIR)/obj/deps/v8/src/libv8_base.a', }, { - 'OBJ_DIR%': '<(PRODUCT_DIR)/obj.target', - 'V8_BASE%': '<(PRODUCT_DIR)/obj.target/deps/v8/src/libv8_base.a', + 'obj_dir%': '<(PRODUCT_DIR)/obj.target', + 'v8_base%': '<(PRODUCT_DIR)/obj.target/deps/v8/src/libv8_base.a', }], ['OS == "win"', { 'os_posix': 0, 'v8_postmortem_support%': 'false', - 'OBJ_DIR': '<(PRODUCT_DIR)/obj', - 'V8_BASE': '<(PRODUCT_DIR)/lib/v8_libbase.lib', + 'obj_dir': '<(PRODUCT_DIR)/obj', + 'v8_base': '<(PRODUCT_DIR)/lib/v8_libbase.lib', }, { 'os_posix': 1, 'v8_postmortem_support%': 'true', }], ['OS== "mac"', { - 'OBJ_DIR%': '<(PRODUCT_DIR)/obj.target', - 'V8_BASE': '<(PRODUCT_DIR)/libv8_base.a', + 'obj_dir%': '<(PRODUCT_DIR)/obj.target', + 'v8_base': '<(PRODUCT_DIR)/libv8_base.a', }], ['openssl_fips != ""', { - 'OPENSSL_PRODUCT': '<(STATIC_LIB_PREFIX)crypto<(STATIC_LIB_SUFFIX)', + 'openssl_product': '<(STATIC_LIB_PREFIX)crypto<(STATIC_LIB_SUFFIX)', }, { - 'OPENSSL_PRODUCT': '<(STATIC_LIB_PREFIX)openssl<(STATIC_LIB_SUFFIX)', + 'openssl_product': '<(STATIC_LIB_PREFIX)openssl<(STATIC_LIB_SUFFIX)', }], ['OS=="mac"', { 'clang%': 1, diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index 84c6717e6b486d..67c3d554da3ba4 100644 --- a/deps/v8/include/v8-version.h +++ b/deps/v8/include/v8-version.h @@ -11,7 +11,7 @@ #define V8_MAJOR_VERSION 6 #define V8_MINOR_VERSION 2 #define V8_BUILD_NUMBER 414 -#define V8_PATCH_LEVEL 54 +#define V8_PATCH_LEVEL 55 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index c70154fd710e0c..2691b4c9445f7b 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -104,6 +104,7 @@ class String; class StringObject; class Symbol; class SymbolObject; +class PrimitiveArray; class Private; class Uint32; class Utils; @@ -978,6 +979,48 @@ class V8_EXPORT Data { Data(); }; +/** + * This is an unfinished experimental feature, and is only exposed + * here for internal testing purposes. DO NOT USE. + * + * A container type that holds relevant metadata for module loading. + * + * This is passed back to the embedder as part of + * HostImportDynamicallyCallback for module loading. + */ +class V8_EXPORT ScriptOrModule { + public: + /** + * The name that was passed by the embedder as ResourceName to the + * ScriptOrigin. This can be either a v8::String or v8::Undefined. + */ + Local GetResourceName(); + + /** + * The options that were passed by the embedder as HostDefinedOptions to + * the ScriptOrigin. + */ + Local GetHostDefinedOptions(); +}; + +/** + * This is an unfinished experimental feature, and is only exposed + * here for internal testing purposes. DO NOT USE. + * + * An array to hold Primitive values. This is used by the embedder to + * pass host defined options to the ScriptOptions during compilation. + * + * This is passed back to the embedder as part of + * HostImportDynamicallyCallback for module loading. + * + */ +class V8_EXPORT PrimitiveArray { + public: + static Local New(Isolate* isolate, int length); + int Length() const; + void Set(int index, Local item); + Local Get(int index); +}; /** * The optional attributes of ScriptOrigin. @@ -1027,13 +1070,17 @@ class ScriptOrigin { Local source_map_url = Local(), Local resource_is_opaque = Local(), Local is_wasm = Local(), - Local is_module = Local()); + Local is_module = Local() /*, + // Backed out for ABI compatibility with V8 6.2 + Local host_defined_options = Local() */); V8_INLINE Local ResourceName() const; V8_INLINE Local ResourceLineOffset() const; V8_INLINE Local ResourceColumnOffset() const; V8_INLINE Local ScriptID() const; V8_INLINE Local SourceMapUrl() const; + // Backed out for ABI compatibility with V8 6.2 + // V8_INLINE Local HostDefinedOptions() const; V8_INLINE ScriptOriginOptions Options() const { return options_; } private: @@ -1043,6 +1090,8 @@ class ScriptOrigin { ScriptOriginOptions options_; Local script_id_; Local source_map_url_; + // Backed out for ABI compatibility with V8 6.2 + // Local host_defined_options_; }; /** @@ -1289,6 +1338,7 @@ class V8_EXPORT ScriptCompiler { Local resource_column_offset; ScriptOriginOptions resource_options; Local source_map_url; + // Local host_defined_options; // Cached data from previous compilation (if a kConsume*Cache flag is // set), or hold newly generated cache data (kProduce*Cache flags) are @@ -6156,8 +6206,8 @@ typedef void (*DeprecatedCallCompletedCallback)(); * embedder to load a module. This is used as part of the dynamic * import syntax. * - * The referrer is the name of the file which calls the dynamic - * import. The referrer can be used to resolve the module location. + * The referrer contains metadata about the script/module that calls + * import. * * The specifier is the name of the module that should be imported. * @@ -6172,7 +6222,8 @@ typedef void (*DeprecatedCallCompletedCallback)(); * that exception by returning an empty MaybeLocal. */ typedef MaybeLocal (*HostImportModuleDynamicallyCallback)( - Local context, Local referrer, Local specifier); + Local context, Local referrer, + Local specifier); /** * PromiseHook with type kInit is called when a new promise is @@ -9511,7 +9562,9 @@ ScriptOrigin::ScriptOrigin(Local resource_name, Local script_id, Local source_map_url, Local resource_is_opaque, - Local is_wasm, Local is_module) + Local is_wasm, Local is_module /*, + // Backed out for ABI compatibility with V8 6.2 + Local host_defined_options */) : resource_name_(resource_name), resource_line_offset_(resource_line_offset), resource_column_offset_(resource_column_offset), @@ -9521,10 +9574,16 @@ ScriptOrigin::ScriptOrigin(Local resource_name, !is_wasm.IsEmpty() && is_wasm->IsTrue(), !is_module.IsEmpty() && is_module->IsTrue()), script_id_(script_id), - source_map_url_(source_map_url) {} + source_map_url_(source_map_url) /*, + // Backed out for ABI compatibility with V8 6.2 + host_defined_options_(host_defined_options) */ {} Local ScriptOrigin::ResourceName() const { return resource_name_; } +// Backed out for ABI compatibility with V8 6.2 +// Local ScriptOrigin::HostDefinedOptions() const { +// return host_defined_options_; +// } Local ScriptOrigin::ResourceLineOffset() const { return resource_line_offset_; @@ -9541,7 +9600,6 @@ Local ScriptOrigin::ScriptID() const { return script_id_; } Local ScriptOrigin::SourceMapUrl() const { return source_map_url_; } - ScriptCompiler::Source::Source(Local string, const ScriptOrigin& origin, CachedData* data) : source_string(string), @@ -9550,9 +9608,10 @@ ScriptCompiler::Source::Source(Local string, const ScriptOrigin& origin, resource_column_offset(origin.ResourceColumnOffset()), resource_options(origin.Options()), source_map_url(origin.SourceMapUrl()), + // Backed out for ABI compatibility with V8 6.2 + // host_defined_options(origin.HostDefinedOptions()), cached_data(data) {} - ScriptCompiler::Source::Source(Local string, CachedData* data) : source_string(string), cached_data(data) {} diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index 76b095eb422712..e686722b4a39cc 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -278,6 +278,9 @@ static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, i::Handle script) { i::Handle scriptName(script->GetNameOrSourceURL(), isolate); i::Handle source_map_url(script->source_mapping_url(), isolate); + // Backed out for ABI compatibility with V8 6.2 + // i::Handle host_defined_options(script->host_defined_options(), + // isolate); v8::Isolate* v8_isolate = reinterpret_cast(script->GetIsolate()); ScriptOriginOptions options(script->origin_options()); @@ -290,7 +293,9 @@ static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, Utils::ToLocal(source_map_url), v8::Boolean::New(v8_isolate, options.IsOpaque()), v8::Boolean::New(v8_isolate, script->type() == i::Script::TYPE_WASM), - v8::Boolean::New(v8_isolate, options.IsModule())); + v8::Boolean::New(v8_isolate, options.IsModule()) /*, + // Backed out for ABI compatibility with V8 6.2 + Utils::ToLocal(host_defined_options) */); return origin; } @@ -2082,6 +2087,23 @@ Local Script::Run() { RETURN_TO_LOCAL_UNCHECKED(Run(context), Value); } +Local ScriptOrModule::GetResourceName() { + i::Handle obj = Utils::OpenHandle(this); + i::Isolate* isolate = obj->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + i::Handle val(obj->name(), isolate); + return ToApiHandle(val); +} + +Local ScriptOrModule::GetHostDefinedOptions() { + i::Handle obj = Utils::OpenHandle(this); + i::Isolate* isolate = obj->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + // Backed out for ABI compatibility with V8 6.2 + // i::Handle val(obj->host_defined_options(), isolate); + // return ToApiHandle(val); + return Local(); +} Local Script::GetUnboundScript() { i::Handle obj = Utils::OpenHandle(this); @@ -2089,6 +2111,46 @@ Local Script::GetUnboundScript() { i::Handle(i::JSFunction::cast(*obj)->shared())); } +// static +Local PrimitiveArray::New(Isolate* v8_isolate, int length) { + i::Isolate* isolate = reinterpret_cast(v8_isolate); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + Utils::ApiCheck(length >= 0, "v8::PrimitiveArray::New", + "length must be equal or greater than zero"); + i::Handle array = isolate->factory()->NewFixedArray(length); + return ToApiHandle(array); +} + +int PrimitiveArray::Length() const { + i::Handle array = Utils::OpenHandle(this); + i::Isolate* isolate = array->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + return array->length(); +} + +void PrimitiveArray::Set(int index, Local item) { + i::Handle array = Utils::OpenHandle(this); + i::Isolate* isolate = array->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + Utils::ApiCheck(index >= 0 && index < array->length(), + "v8::PrimitiveArray::Set", + "index must be greater than or equal to 0 and less than the " + "array length"); + i::Handle i_item = Utils::OpenHandle(*item); + array->set(index, *i_item); +} + +Local PrimitiveArray::Get(int index) { + i::Handle array = Utils::OpenHandle(this); + i::Isolate* isolate = array->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + Utils::ApiCheck(index >= 0 && index < array->length(), + "v8::PrimitiveArray::Get", + "index must be greater than or equal to 0 and less than the " + "array length"); + i::Handle i_item(array->get(index), isolate); + return ToApiHandle(i_item); +} Module::Status Module::GetStatus() const { i::Handle self = Utils::OpenHandle(this); @@ -2225,11 +2287,18 @@ MaybeLocal ScriptCompiler::CompileUnboundInternal( TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileScript"); i::Handle name_obj; i::Handle source_map_url; + // Backed out for ABI compatibility with V8 6.2 + // i::Handle host_defined_options = + // isolate->factory()->empty_fixed_array(); int line_offset = 0; int column_offset = 0; if (!source->resource_name.IsEmpty()) { name_obj = Utils::OpenHandle(*(source->resource_name)); } + // Backed out for ABI compatibility with V8 6.2 + // if (!source->host_defined_options.IsEmpty()) { + // host_defined_options = Utils::OpenHandle(*(source->host_defined_options)); + // } if (!source->resource_line_offset.IsEmpty()) { line_offset = static_cast(source->resource_line_offset->Value()); } @@ -2243,7 +2312,7 @@ MaybeLocal ScriptCompiler::CompileUnboundInternal( result = i::Compiler::GetSharedFunctionInfoForScript( str, name_obj, line_offset, column_offset, source->resource_options, source_map_url, isolate->native_context(), NULL, &script_data, options, - i::NOT_NATIVES_CODE); + i::NOT_NATIVES_CODE /*, host_defined_options */); has_pending_exception = result.is_null(); if (has_pending_exception && script_data != NULL) { // This case won't happen during normal operation; we have compiled @@ -2508,6 +2577,10 @@ MaybeLocal