diff --git a/deps/chakrashim/lib/chakra_shim.js b/deps/chakrashim/lib/chakra_shim.js index c73d5370e13..1ecb18f6b65 100644 --- a/deps/chakrashim/lib/chakra_shim.js +++ b/deps/chakrashim/lib/chakra_shim.js @@ -54,7 +54,7 @@ }; StackFrame.prototype.getTypeName = function() { - //TODO : Fix this + // TODO : Fix this return this.functionName; }; diff --git a/lib/assert.js b/lib/assert.js index 66e198ac774..73abf3cee67 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -54,7 +54,7 @@ const meta = [ const escapeFn = (str) => meta[str.charCodeAt(0)]; -const trace_mgr = require('trace_mgr'); //ENABLE_TTD +const trace_mgr = require('trace_mgr'); // ENABLE_TTD const ERR_DIFF_DEACTIVATED = 0; const ERR_DIFF_NOT_EQUAL = 1; @@ -83,7 +83,7 @@ function innerFail(obj) { } function fail(actual, expected, message, operator, stackStartFn) { - trace_mgr.emitTrace('emitOnAssert'); //ENABLE_TTD + trace_mgr.emitTrace('emitOnAssert'); // ENABLE_TTD const argsLen = arguments.length; diff --git a/lib/console.js b/lib/console.js index d9b6a152526..9e8b8649ba7 100644 --- a/lib/console.js +++ b/lib/console.js @@ -36,7 +36,7 @@ const { isTypedArray, isSet, isMap, isSetIterator, isMapIterator, } = util.types; const kCounts = Symbol('counts'); -const trace_mgr = require('trace_mgr'); //ENABLE_TTD +const trace_mgr = require('trace_mgr'); // ENABLE_TTD const { keys: ObjectKeys, @@ -166,7 +166,7 @@ Console.prototype.warn = function warn(...args) { this._stderrErrorHandler, this[kGroupIndent]); - trace_mgr.emitTrace('emitOnLogWarn'); //ENABLE_TTD + trace_mgr.emitTrace('emitOnLogWarn'); // ENABLE_TTD }; Console.prototype.error = function error(...args) { write(this._ignoreErrors, @@ -174,7 +174,7 @@ Console.prototype.error = function error(...args) { util.format.apply(null, args), this._stderrErrorHandler, this[kGroupIndent]); - trace_mgr.emitTrace('emitOnLogError'); //ENABLE_TTD + trace_mgr.emitTrace('emitOnLogError'); // ENABLE_TTD }; Console.prototype.dir = function dir(object, options) { diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 3b724e0d5b7..7ef7f4f63fe 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -49,7 +49,6 @@ } - setupV8(); setupProcessICUVersions(); @@ -86,7 +85,7 @@ NativeModule.require('internal/trace_events_async_hooks').setup(); NativeModule.require('internal/inspector_async_hook').setup(); - NativeModule.require('trace_mgr'); //ENABLE_TTD; + NativeModule.require('trace_mgr'); // ENABLE_TTD; _process.setupChannel(); _process.setupRawDebug(); @@ -455,7 +454,7 @@ if (exceptionHandlerState.captureFn !== null) { exceptionHandlerState.captureFn(er); } else if (!process.emit('uncaughtException', er)) { - //ENABLE_TTD + // ENABLE_TTD NativeModule.require('trace_mgr').onUncaughtExceptionHandler(); // If someone handled it, then great. otherwise, die in C++ land diff --git a/lib/internal/process.js b/lib/internal/process.js index 1ca48614aa6..e593634fd25 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -164,7 +164,7 @@ function setupKillAndExit() { process.emit('exit', process.exitCode || 0); } - require('trace_mgr').onExitHandler(process.exitCode || 0); //ENABLE_TTD + require('trace_mgr').onExitHandler(process.exitCode || 0); // ENABLE_TTD process.reallyExit(process.exitCode || 0); }; @@ -214,10 +214,10 @@ function setupSignalHandlers() { wrap.unref(); if (type === 'SIGINT' && global.enabledDiagnosticsTrace) { - //TODO: this is probably a little over complicated + // TODO: this is probably a little over complicated // -- should unify this and ttdSigIntHandler setup below // -- ttdSigIntHandler will emit event after it runs - wrap.onsignal = function() { }; //ENABLE_TTD + wrap.onsignal = function() { }; // ENABLE_TTD } else { wrap.onsignal = process.emit.bind(process, type, type); } @@ -240,7 +240,7 @@ function setupSignalHandlers() { } }); - //ENABLE_TTD + // ENABLE_TTD if (global.enabledDiagnosticsTrace) { (function() { const type = 'SIGINT'; diff --git a/lib/trace_mgr.js b/lib/trace_mgr.js index 13d7cc08a00..83e9f8b2e81 100644 --- a/lib/trace_mgr.js +++ b/lib/trace_mgr.js @@ -1,15 +1,15 @@ 'use strict'; -//Disable trace handling inside trace handler to avoid recursion -//Set to true to prevent action till loading is complete -- set to false at end +// Disable trace handling inside trace handler to avoid recursion +// Set to true to prevent action till loading is complete -- set to false at end let reentrantDisable = true; let lazyloadDone = false; let path; let fs; -/////////////////////////////// -//Trace calls +// ///////////////////////////// +// Trace calls /* *Check and emit time travel trace @@ -21,9 +21,9 @@ let fs; function emitTrace(emitKind, optInfo) { const res = emitTrace_helper(emitKind, optInfo); if (res.flag === 'success') { - //This is an intentional programatic breakpoint + // This is an intentional programatic breakpoint // -- it is only triggerable in --replay-debug mode - debugger; /*TTD_DEBUG_BREAKPOINT*/ // eslint-disable-line no-debugger + debugger; /* TTD_DEBUG_BREAKPOINT */ // eslint-disable-line no-debugger } res.action(); } @@ -56,7 +56,7 @@ function emitTrace_helper(emitKind, optInfo) { lazyloadDone = true; } - //Process a synchronous write action for a unique trace bin + // Process a synchronous write action for a unique trace bin // -- otherwise a async action on a multiple trace bin let sampleRes = buildTraceResult('no-sample'); if (emitKind === 'emitOnExit' || @@ -80,16 +80,16 @@ function emitTrace_helper(emitKind, optInfo) { } } -//// -//Helpers for trace calls +// // +// Helpers for trace calls function emitSyncTraceKind(emitKind, optInfo) { - //build up trace name + // build up trace name let traceName = emitKind; if (emitKind === 'emitOnExit') { traceName += ('_code-' + optInfo); } - //invoke the trace writer and remote manager if needed + // invoke the trace writer and remote manager if needed const resolvedPath = createTraceLogTarget(traceName); if (!resolvedPath) { return buildTraceResult('fail'); @@ -113,19 +113,19 @@ function emitSyncTraceKind(emitKind, optInfo) { } function emitAsyncTraceKind(emitKind) { - //get trace stack and check if we want to emit + // get trace stack and check if we want to emit const stk = generateFuzzyStack(emitKind); const entry = checkBinShouldEmit(stk); if (!entry) { return buildTraceResult('no-sample'); } - //build up trace name + // build up trace name const traceBucketName = `${emitKind}_${stk.fbin}_bucket-${entry.bucketId}`; const traceDirName = `trace-${entry.traceCtr}`; const traceName = path.join(traceBucketName, traceDirName); - //invoke the trace writer and remote manager if needed + // invoke the trace writer and remote manager if needed const resolvedPath = createTraceLogTarget(traceName); if (!resolvedPath) { return buildTraceResult('fail'); @@ -145,12 +145,12 @@ function emitAsyncTraceKind(emitKind) { } } - //update the bin stats as needed + // update the bin stats as needed updateEmitInfo(entry, resolvedPath); return buildTraceResult('success', action); } -//create a directory for emitting the trace (if possible) and return it +// create a directory for emitting the trace (if possible) and return it function createTraceLogTarget(tracename) { const traceRootDir = emitOptions.localTraceDirectory || path.dirname(process.mainModule.filename); @@ -161,7 +161,7 @@ function createTraceLogTarget(tracename) { const resolvedTracePath = path.resolve(traceRootDir, '_diagnosticTraces', tracename); - //ensure directory exists and is empty... + // ensure directory exists and is empty... const ok = ensureTraceTarget(resolvedTracePath); if (!ok) { return undefined; @@ -170,9 +170,9 @@ function createTraceLogTarget(tracename) { return resolvedTracePath; } -//ensure directory exists and is empty... +// ensure directory exists and is empty... function ensureTraceTarget(pth) { - //I don't like this and don't want it to be happening so I am going to bail + // I don't like this and don't want it to be happening so I am going to bail if (!path.isAbsolute(pth)) { return false; } @@ -186,7 +186,7 @@ function ensureTraceTarget(pth) { } function createTargetDirectory(pth) { - //see if it just exists and, if so, just return true + // see if it just exists and, if so, just return true const accessok = fs.constants.R_OK | fs.constants.W_OK | fs.constants.X_OK; try { fs.accessSync(pth, accessok); @@ -195,18 +195,18 @@ function createTargetDirectory(pth) { } } catch (ei) { } - //walk up the directory to see where the first valid part of the path is + // walk up the directory to see where the first valid part of the path is let prefixPath = pth; const suffixPaths = []; let baseFound = false; do { - //check for bad prefix + // check for bad prefix if (prefixPath === path.dirname(prefixPath)) { process.stderr.write(`Failed prefix: ${pth} -> ${prefixPath}\n`); return false; } - suffixPaths.push(path.basename(prefixPath)); //reverse order + suffixPaths.push(path.basename(prefixPath)); // reverse order prefixPath = path.dirname(prefixPath); try { @@ -215,7 +215,7 @@ function createTargetDirectory(pth) { } catch (ei) { } } while (!baseFound); - //now extend the prefix with all the suffix parts + // now extend the prefix with all the suffix parts while (suffixPaths.length > 0) { try { prefixPath = path.resolve(prefixPath, suffixPaths.pop()); @@ -245,7 +245,7 @@ function deleteTargetDirectoryContents(pth) { fs.rmdirSync(fpath); } else { - return false; //something strange in here. + return false; // something strange in here. } } } catch (ex) { @@ -256,7 +256,7 @@ function deleteTargetDirectoryContents(pth) { return true; } -//after we take a sample update the sampling stats +// after we take a sample update the sampling stats function updateGlobalSampleStats(eventKind) { currentSampleRate[eventKind] *= emitOptions.backoffFactors[eventKind]; @@ -269,46 +269,46 @@ function updateGlobalSampleStats(eventKind) { } } -/////////////////////////////// -//Trace emit manager code +// ///////////////////////////// +// Trace emit manager code const emitOptions = { - emitOnExit: 'error', //emit a trace on exit -- off, error, all - emitOnException: true, //emit a trace on uncaught execption - emitOnSigInt: true, //emit a trace on sigint - emitOnLogWarn: true, //check for trace emit on console.warn - emitOnLogError: true, //check for trace emit on console.error - emitOnAssert: true, //check for trace emit on console.assert or assert + emitOnExit: 'error', // emit a trace on exit -- off, error, all + emitOnException: true, // emit a trace on uncaught execption + emitOnSigInt: true, // emit a trace on sigint + emitOnLogWarn: true, // check for trace emit on console.warn + emitOnLogError: true, // check for trace emit on console.error + emitOnAssert: true, // check for trace emit on console.assert or assert - globalMinInterval: 500, //min interval between console/assert trace emits - globalBackoffCancelInterval: 5000, //time when we reset the backoff interval + globalMinInterval: 500, // min interval between console/assert trace emits + globalBackoffCancelInterval: 5000, // time when we reset the backoff interval - //The probability that we sample on the first warn/error/assert encountered + // The probability that we sample on the first warn/error/assert encountered initialRates: { emitOnLogWarn: 0.25, emitOnLogError: 0.25, emitOnAssert: 1.0 }, - //The baseline background probability that we sample traces + // The baseline background probability that we sample traces baselineRates: { emitOnLogWarn: 0.25, emitOnLogError: 0.25, emitOnAssert: 1.0 }, - //backoff factor to apply + // backoff factor to apply backoffFactors: { emitOnLogWarn: 0.25, emitOnLogError: 0.5, emitOnAssert: 0.5 }, - binMaxSampled: 10, //Max number of traces to take per stack bin - binBackoffFactor: 0.5, //sample probability #preserved * binBackoffFactor + binMaxSampled: 10, // Max number of traces to take per stack bin + binBackoffFactor: 0.5, // sample probability #preserved * binBackoffFactor - localTraceDirectory: undefined, //The root directory for storing traces - remoteTraceManagerObj: undefined //manager object for remote trace support + localTraceDirectory: undefined, // The root directory for storing traces + remoteTraceManagerObj: undefined // manager object for remote trace support }; const callStackEmitInfoMap = new Map(); @@ -330,7 +330,7 @@ for (const srp in emitOptions.initialRates) { */ function setOptions(optionsObj) { for (const opt in optionsObj) { - //TODO: need more error checking on the validity of the option values + // TODO: need more error checking on the validity of the option values emitOptions[opt] = optionsObj[opt]; } @@ -347,7 +347,7 @@ exports.setOptions = setOptions; *@result true if we may want to sample false if we definitely do not */ function checkGlobalShouldEmit(emitKind, optInfo) { - //Check if the flag is enabled + // Check if the flag is enabled if (emitKind === 'emitOnExit') { if (emitOptions.emitOnExit === 'all') { return true; @@ -363,19 +363,19 @@ function checkGlobalShouldEmit(emitKind, optInfo) { const sampleInterval = new Date() - emitMinTimeValue[emitKind]; - //Don't sample too often no matter what (or we can basically live lock) + // Don't sample too often no matter what (or we can basically live lock) if (sampleInterval < emitOptions.globalMinInterval) { return false; } - //Relax our global rate if it has been a while + // Relax our global rate if it has been a while if (sampleInterval >= emitOptions.globalBackoffCancelInterval) { const currRate = currentSampleRate[emitKind]; const blRate = emitOptions.baselineRates[emitKind]; currentSampleRate[emitKind] = Math.max(currRate, blRate); } - //Probabalistic check if we want to do sample new trace + // Probabalistic check if we want to do sample new trace return Math.random() < currentSampleRate[emitKind]; } } @@ -388,12 +388,12 @@ function checkGlobalShouldEmit(emitKind, optInfo) { function checkBinShouldEmit(fuzzyStack) { const entry = resolveStackEntry(fuzzyStack); - //stop sampling after max sampled values -- e.g. we don't need 100 repros + // stop sampling after max sampled values -- e.g. we don't need 100 repros if (entry.traceCtr > emitOptions.binMaxSampled) { return undefined; } - //check if we want to sample on this entry -- we don't need every hit on this + // check if we want to sample on this entry -- we don't need every hit on this const sampleProb = Math.pow(emitOptions.binBackoffFactor, entry.traceCtr); return (Math.random() < sampleProb) ? entry : undefined; } @@ -408,8 +408,8 @@ function updateEmitInfo(sampleEntry, sampleName) { sampleEntry.samples.push(sampleName); } -//// -//Helpers for emit manager code +// // +// Helpers for emit manager code function resolveStackEntry(fuzzyStack) { if (!callStackEmitInfoMap.has(fuzzyStack.hash)) { callStackEmitInfoMap.set(fuzzyStack.hash, []); @@ -431,10 +431,10 @@ function resolveStackEntry(fuzzyStack) { return stackList[stackList.length - 1]; } -/////////////////////////////// -//Fuzzy stack code +// ///////////////////////////// +// Fuzzy stack code -//Helper hashcode computation function (dbj2 variant) +// Helper hashcode computation function (dbj2 variant) function djbHash(str, hash) { for (var i = 0; i < str.length; i++) { hash = (hash * 33) ^ str.charCodeAt(i); @@ -442,22 +442,22 @@ function djbHash(str, hash) { return hash; } -//helper is absolute path copied from path -- avoid neededing to require it +// helper is absolute path copied from path -- avoid neededing to require it function directIsAbsoluteW32(pth) { const len = pth.length; if (len === 0) return false; let code = pth.charCodeAt(0); - if (code === 47/*/*/ || code === 92/*\*/) { + if (code === 47/* / */ || code === 92/* \ */) { return true; - } else if ((code >= 65/*A*/ && code <= 90/*Z*/) || - (code >= 97/*a*/ && code <= 122/*z*/)) { + } else if ((code >= 65/* A */ && code <= 90/* Z */) || + (code >= 97/* a */ && code <= 122/* z */)) { // Possible device root - if (len > 2 && pth.charCodeAt(1) === 58/*:*/) { + if (len > 2 && pth.charCodeAt(1) === 58/* : */) { code = pth.charCodeAt(2); - if (code === 47/*/*/ || code === 92/*\*/) + if (code === 47/* / */ || code === 92/* \ */) return true; } } @@ -465,7 +465,7 @@ function directIsAbsoluteW32(pth) { } function directIsAbsolutePosix(pth) { - return pth.length > 0 && pth.charCodeAt(0) === 47/*/*/; + return pth.length > 0 && pth.charCodeAt(0) === 47/* / */; } const directIsAbsolute = (process.platform === 'win32') ? @@ -494,7 +494,7 @@ function generateFuzzyStack(eventKind) { .replace('.js:', '_line-') .replace(':', '_column-'); - //Identify which frames are recursive (appear multiple times in the stack) + // Identify which frames are recursive (appear multiple times in the stack) const recFrames = new Map(); let hasRecFrames = false; for (var i = 0; i < errstk.length; ++i) { @@ -507,7 +507,7 @@ function generateFuzzyStack(eventKind) { } if (hasRecFrames) { - //Compress any recursive frames + // Compress any recursive frames let cpos = 0; let fpos = 0; while (fpos < errstk.length) { @@ -589,8 +589,8 @@ function eqFuzzyStacks(s1, s2) { return true; } -/////////////////////////////// -//Bind handlers +// ///////////////////////////// +// Bind handlers function onExitHandler(code) { emitTrace('emitOnExit', code); @@ -606,7 +606,7 @@ function onSigIntHandler(hasUserHandler) { emitTrace('emitOnSigInt'); if (!hasUserHandler) { - //Really exit without triggering any other events + // Really exit without triggering any other events process.reallyExit(0); } } diff --git a/test/parallel/test-buffer-concat.js b/test/parallel/test-buffer-concat.js index 0f1190057e6..2e2fbeca30e 100644 --- a/test/parallel/test-buffer-concat.js +++ b/test/parallel/test-buffer-concat.js @@ -45,13 +45,13 @@ assert.strictEqual(flatLong.toString(), check); assert.strictEqual(flatLongLen.toString(), check); [undefined, null, Buffer.from('hello')].forEach((value) => { - assert.throws(() => { - Buffer.concat(value); - }, { - code: 'ERR_INVALID_ARG_TYPE', - message: 'The "list" argument must be one of type Array, Buffer, ' + + assert.throws(() => { + Buffer.concat(value); + }, { + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "list" argument must be one of type Array, Buffer, ' + `or Uint8Array. Received type ${typeof value}` - }); + }); }); diff --git a/test/parallel/test-console-table.js b/test/parallel/test-console-table.js index 868175cd1c0..7b3ed368913 100644 --- a/test/parallel/test-console-table.js +++ b/test/parallel/test-console-table.js @@ -109,7 +109,7 @@ test([{ a: 1, b: 2 }, { a: 3, c: 4 }], ['a'], ` // BUGBUG: https://github.com/nodejs/node-chakracore/issues/510 - need to // re-enable for Chakra when previewMapIterator is implemented if (!common.isChakraEngine) { -test(new Map([[1, 1], [2, 2], [3, 3]]).entries(), ` + test(new Map([[1, 1], [2, 2], [3, 3]]).entries(), ` ┌───────────────────┬─────┬────────┐ │ (iteration index) │ Key │ Values │ ├───────────────────┼─────┼────────┤ @@ -120,10 +120,10 @@ test(new Map([[1, 1], [2, 2], [3, 3]]).entries(), ` `); } -// BUGBUG: https://github.com/nodejs/node-chakracore/issues/510 - need to +// BUGBUG: https://github.com/nodejs/node-chakracore/issues/510 - need to // re-enable for Chakra when previewMapIterator is implemented if (!common.isChakraEngine) { -test(new Set([1, 2, 3]).values(), ` + test(new Set([1, 2, 3]).values(), ` ┌───────────────────┬────────┐ │ (iteration index) │ Values │ ├───────────────────┼────────┤ diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 97e8326df64..89486293396 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -27,6 +27,7 @@ const JSStream = process.binding('js_stream').JSStream; const util = require('util'); const vm = require('vm'); if (!common.isChakraEngine) { + // eslint-disable-next-line no-unused-vars const { previewMapIterator } = require('internal/v8'); } @@ -457,17 +458,16 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); } if (!common.isChakraEngine) { - { - const map = new Map(); - map.set(1, 2); - const vals = previewMapIterator(map.entries()); - const valsOutput = []; - for (const o of vals) { - valsOutput.push(o); - } - - assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]'); + const map = new Map(); + map.set(1, 2); + // eslint-disable-next-line no-undef + const vals = previewMapIterator(map.entries()); + const valsOutput = []; + for (const o of vals) { + valsOutput.push(o); } + + assert.strictEqual(util.inspect(valsOutput), '[ [ 1, 2 ] ]'); } // Test for other constructors in different context. @@ -943,10 +943,8 @@ if (typeof Symbol !== 'undefined') { global.Promise = oldPromise; } -if (!common.isChakraEngine) -{ -// Test Map iterators. -{ +if (!common.isChakraEngine) { + // Test Map iterators. const map = new Map([['foo', 'bar']]); assert.strictEqual(util.inspect(map.keys()), '[Map Iterator] { \'foo\' }'); assert.strictEqual(util.inspect(map.values()), '[Map Iterator] { \'bar\' }'); @@ -961,12 +959,9 @@ if (!common.isChakraEngine) util.inspect(keys, { maxArrayLength: 0 }), '[Map Iterator] { ... more items, extra: true }'); } -} -if (!common.isChakraEngine) -{ -// Test Set iterators. -{ +if (!common.isChakraEngine) { + // Test Set iterators. const aSet = new Set([1, 3]); assert.strictEqual(util.inspect(aSet.keys()), '[Set Iterator] { 1, 3 }'); assert.strictEqual(util.inspect(aSet.values()), '[Set Iterator] { 1, 3 }'); @@ -980,8 +975,6 @@ if (!common.isChakraEngine) assert.strictEqual( util.inspect(keys, { maxArrayLength: 1 }), '[Set Iterator] { 1, ... more items, extra: true }'); - -} } // Test alignment of items in container. @@ -1395,9 +1388,8 @@ util.inspect(process); assert.strictEqual(out, expect); } -if (!common.isChakraEngine) -{ -{ // Test WeakMap +if (!common.isChakraEngine) { + // Test WeakMap const obj = {}; const arr = []; const weakMap = new WeakMap([[obj, arr], [arr, obj]]); @@ -1418,14 +1410,12 @@ if (!common.isChakraEngine) // It is not possible to determine the output reliable. expect = 'WeakMap { [ [length]: 0 ] => {}, ... more items, extra: true }'; const expectAlt = 'WeakMap { {} => [ [length]: 0 ], ... more items, ' + - 'extra: true }'; + 'extra: true }'; assert(out === expect || out === expectAlt); } -} -if (!common.isChakraEngine) -{ -{ // Test WeakSet +if (!common.isChakraEngine) { + // Test WeakSet const weakSet = new WeakSet([{}, [1]]); let out = util.inspect(weakSet, { showHidden: true }); let expect = 'WeakSet { [ 1, [length]: 1 ], {} }'; @@ -1444,7 +1434,6 @@ if (!common.isChakraEngine) // It is not possible to determine the output reliable. expect = 'WeakSet { {}, ... more items, extra: true }'; const expectAlt = 'WeakSet { [ 1, [length]: 1 ], ... more items, ' + - 'extra: true }'; + 'extra: true }'; assert(out === expect || out === expectAlt); } -} \ No newline at end of file