Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 6972x 6972x 6972x 6972x 6x 6x 6x 6x 6x 6972x 26x 58x 58x 1x 1x 57x 57x 57x 57x 58x 26x 713x 713x 713x 713x 713x 713x 713x 713x 713x 713x 713x 713x 713x 713x 713x 713x 713x 713x 710x 710x 710x 710x 710x 710x 710x 710x 710x 710x 710x 710x 710x 710x 710x 710x 2x 2x 2x 710x 710x 104x 104x 104x 646x 646x 646x 713x 713x 713x 3x 3x 707x 713x 26x 26x 26x 26x 26x 26x 33086x 33086x 23726x 23726x 23726x 23726x 23726x 33086x 1x 1x 28715x 1x 1x 9358x 9358x 9358x 9358x 9358x 33086x 26x 282x 282x 282x 26x 1211x 26x 26x 26x 26x 26x 26x 26x 26x 26x 740x 740x 740x 740x 740x 1532x 1532x 1532x 1532x 1532x 1532x 1532x 1108x 1530x 297x 297x 297x 297x 296x 296x 296x 296x 297x 297x 297x 1225x 1225x 1225x 1225x 1225x 1225x 1226x 1113x 2072x 2072x 2072x 1111x 1111x 1113x 1113x 1225x 1225x 1225x 1225x 1225x 740x 740x 26x 26x 26x 26x 26x 26x 25x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x | 'use strict'; const { RegExpPrototypeExec, globalThis, } = primordials; const path = require('path'); const { codes: { ERR_INVALID_ARG_TYPE, ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET, ERR_EVAL_ESM_CANNOT_PRINT, }, } = require('internal/errors'); const { exitCodes: { kGenericUserError } } = internalBinding('errors'); const { executionAsyncId, clearDefaultTriggerAsyncId, clearAsyncIdStack, hasAsyncIdStack, afterHooksExist, emitAfter, popAsyncContext, } = require('internal/async_hooks'); // shouldAbortOnUncaughtToggle is a typed array for faster // communication with JS. const { shouldAbortOnUncaughtToggle } = internalBinding('util'); function tryGetCwd() { try { return process.cwd(); } catch { // getcwd(3) can fail if the current working directory has been deleted. // Fall back to the directory name of the (absolute) executable path. // It's not really correct but what are the alternatives? return path.dirname(process.execPath); } } function evalModule(source, print) { if (print) { throw new ERR_EVAL_ESM_CANNOT_PRINT(); } const { loadESM } = require('internal/process/esm_loader'); const { handleMainPromise } = require('internal/modules/run_main'); RegExpPrototypeExec(/^/, ''); // Necessary to reset RegExp statics before user code runs. return handleMainPromise(loadESM((loader) => loader.eval(source))); } function evalScript(name, body, breakFirstLine, print, shouldLoadESM = false) { const CJSModule = require('internal/modules/cjs/loader').Module; const { kVmBreakFirstLineSymbol } = require('internal/util'); const { pathToFileURL } = require('url'); const cwd = tryGetCwd(); const origModule = globalThis.module; // Set e.g. when called from the REPL. const module = new CJSModule(name); module.filename = path.join(cwd, name); module.paths = CJSModule._nodeModulePaths(cwd); const { handleMainPromise } = require('internal/modules/run_main'); const asyncESM = require('internal/process/esm_loader'); const baseUrl = pathToFileURL(module.filename).href; const { loadESM } = asyncESM; const runScript = () => { // Create wrapper for cache entry const script = ` globalThis.module = module; globalThis.exports = exports; globalThis.__dirname = __dirname; globalThis.require = require; return (main) => main(); `; globalThis.__filename = name; RegExpPrototypeExec(/^/, ''); // Necessary to reset RegExp statics before user code runs. const result = module._compile(script, `${name}-wrapper`)(() => require('vm').runInThisContext(body, { filename: name, displayErrors: true, [kVmBreakFirstLineSymbol]: !!breakFirstLine, importModuleDynamically(specifier, _, importAssertions) { const loader = asyncESM.esmLoader; return loader.import(specifier, baseUrl, importAssertions); } })); if (print) { const { log } = require('internal/console/global'); log(result); } if (origModule !== undefined) globalThis.module = origModule; }; if (shouldLoadESM) { return handleMainPromise(loadESM(runScript)); } return runScript(); } const exceptionHandlerState = { captureFn: null, reportFlag: false }; function setUncaughtExceptionCaptureCallback(fn) { if (fn === null) { exceptionHandlerState.captureFn = fn; shouldAbortOnUncaughtToggle[0] = 1; process.report.reportOnUncaughtException = exceptionHandlerState.reportFlag; return; } if (typeof fn !== 'function') { throw new ERR_INVALID_ARG_TYPE('fn', ['Function', 'null'], fn); } if (exceptionHandlerState.captureFn !== null) { throw new ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET(); } exceptionHandlerState.captureFn = fn; shouldAbortOnUncaughtToggle[0] = 0; exceptionHandlerState.reportFlag = process.report.reportOnUncaughtException === true; process.report.reportOnUncaughtException = false; } function hasUncaughtExceptionCaptureCallback() { return exceptionHandlerState.captureFn !== null; } function noop() {} // XXX(joyeecheung): for some reason this cannot be defined at the top-level // and exported to be written to process._fatalException, it has to be // returned as an *anonymous function* wrapped inside a factory function, // otherwise it breaks the test-timers.setInterval async hooks test - // this may indicate that node::errors::TriggerUncaughtException() should // fix up the callback scope before calling into process._fatalException, // or this function should take extra care of the async hooks before it // schedules a setImmediate. function createOnGlobalUncaughtException() { // The C++ land node::errors::TriggerUncaughtException() will // exit the process if it returns false, and continue execution if it // returns true (which indicates that the exception is handled by the user). return (er, fromPromise) => { // It's possible that defaultTriggerAsyncId was set for a constructor // call that threw and was never cleared. So clear it now. clearDefaultTriggerAsyncId(); const type = fromPromise ? 'unhandledRejection' : 'uncaughtException'; process.emit('uncaughtExceptionMonitor', er, type); if (exceptionHandlerState.captureFn !== null) { exceptionHandlerState.captureFn(er); } else if (!process.emit('uncaughtException', er, type)) { // If someone handled it, then great. Otherwise, die in C++ land // since that means that we'll exit the process, emit the 'exit' event. try { if (!process._exiting) { process._exiting = true; process.exitCode = kGenericUserError; process.emit('exit', kGenericUserError); } } catch { // Nothing to be done about it at this point. } return false; } // If we handled an error, then make sure any ticks get processed // by ensuring that the next Immediate cycle isn't empty. require('timers').setImmediate(noop); // Emit the after() hooks now that the exception has been handled. if (afterHooksExist()) { do { const asyncId = executionAsyncId(); if (asyncId === 0) popAsyncContext(0); else emitAfter(asyncId); } while (hasAsyncIdStack()); } // And completely empty the id stack, including anything that may be // cached on the native side. clearAsyncIdStack(); return true; }; } function readStdin(callback) { process.stdin.setEncoding('utf8'); let code = ''; process.stdin.on('data', (d) => { code += d; }); process.stdin.on('end', () => { callback(code); }); } module.exports = { readStdin, tryGetCwd, evalModule, evalScript, onGlobalUncaughtException: createOnGlobalUncaughtException(), setUncaughtExceptionCaptureCallback, hasUncaughtExceptionCaptureCallback }; |