(options /* or: stdout, stderr, ignoreErrors = true */)
| 100 | |
| 101 | const optionsMap = new SafeWeakMap(); |
| 102 | function Console(options /* or: stdout, stderr, ignoreErrors = true */) { |
| 103 | // We have to test new.target here to see if this function is called |
| 104 | // with new, because we need to define a custom instanceof to accommodate |
| 105 | // the global console. |
| 106 | if (new.target === undefined) { |
| 107 | return ReflectConstruct(Console, arguments); |
| 108 | } |
| 109 | |
| 110 | if (!options || typeof options.write === 'function') { |
| 111 | options = { |
| 112 | stdout: options, |
| 113 | stderr: arguments[1], |
| 114 | ignoreErrors: arguments[2], |
| 115 | }; |
| 116 | } |
| 117 | |
| 118 | const { |
| 119 | stdout, |
| 120 | stderr = stdout, |
| 121 | ignoreErrors = true, |
| 122 | colorMode = 'auto', |
| 123 | inspectOptions, |
| 124 | groupIndentation, |
| 125 | } = options; |
| 126 | |
| 127 | if (!stdout || typeof stdout.write !== 'function') { |
| 128 | throw new ERR_CONSOLE_WRITABLE_STREAM('stdout'); |
| 129 | } |
| 130 | if (!stderr || typeof stderr.write !== 'function') { |
| 131 | throw new ERR_CONSOLE_WRITABLE_STREAM('stderr'); |
| 132 | } |
| 133 | |
| 134 | validateOneOf(colorMode, 'colorMode', ['auto', true, false]); |
| 135 | |
| 136 | if (groupIndentation !== undefined) { |
| 137 | validateInteger(groupIndentation, 'groupIndentation', |
| 138 | 0, kMaxGroupIndentation); |
| 139 | } |
| 140 | |
| 141 | if (inspectOptions !== undefined) { |
| 142 | validateObject(inspectOptions, 'options.inspectOptions'); |
| 143 | |
| 144 | const inspectOptionsMap = isMap(inspectOptions) ? |
| 145 | inspectOptions : new SafeMap([ |
| 146 | [stdout, inspectOptions], |
| 147 | [stderr, inspectOptions], |
| 148 | ]); |
| 149 | |
| 150 | for (const inspectOptions of MapPrototypeValues(inspectOptionsMap)) { |
| 151 | if (inspectOptions.colors !== undefined && |
| 152 | options.colorMode !== undefined) { |
| 153 | throw new ERR_INCOMPATIBLE_OPTION_PAIR( |
| 154 | 'options.inspectOptions.color', 'colorMode'); |
| 155 | } |
| 156 | } |
| 157 | optionsMap.set(this, inspectOptionsMap); |
| 158 | } |
| 159 |
no test coverage detected
searching dependent graphs…