(input, callback)
| 300 | |
| 301 | // This returns a code preview for arbitrary input code. |
| 302 | function getInputPreview(input, callback) { |
| 303 | // For similar reasons as `defaultEval`, wrap expressions starting with a |
| 304 | // curly brace with parenthesis. |
| 305 | if (!wrapped && input[0] === '{' && input[input.length - 1] !== ';' && isValidSyntax(input)) { |
| 306 | input = `(${input})`; |
| 307 | wrapped = true; |
| 308 | } |
| 309 | sendInspectorCommand((session) => { |
| 310 | session.post('Runtime.evaluate', { |
| 311 | expression: input, |
| 312 | throwOnSideEffect: true, |
| 313 | timeout: 333, |
| 314 | contextId: repl[contextSymbol], |
| 315 | }, (error, preview) => { |
| 316 | if (error) { |
| 317 | callback(error); |
| 318 | return; |
| 319 | } |
| 320 | const { result } = preview; |
| 321 | if (result.value !== undefined) { |
| 322 | callback(null, inspect(result.value, previewOptions)); |
| 323 | // Ignore EvalErrors, SyntaxErrors and ReferenceErrors. It is not clear |
| 324 | // where they came from and if they are recoverable or not. Other errors |
| 325 | // may be inspected. |
| 326 | } else if (preview.exceptionDetails && |
| 327 | (result.className === 'EvalError' || |
| 328 | result.className === 'SyntaxError' || |
| 329 | // Report ReferenceError in case the strict mode is active |
| 330 | // for input that has no completions. |
| 331 | (result.className === 'ReferenceError' && |
| 332 | (hasCompletions || !isInStrictMode(repl))))) { |
| 333 | callback(null, null); |
| 334 | } else if (result.objectId) { |
| 335 | // The writer options might change and have influence on the inspect |
| 336 | // output. The user might change e.g., `showProxy`, `getters` or |
| 337 | // `showHidden`. Use `inspect` instead of `JSON.stringify` to keep |
| 338 | // `Infinity` and similar intact. |
| 339 | const inspectOptions = inspect({ |
| 340 | ...repl.writer.options, |
| 341 | colors: false, |
| 342 | depth: 1, |
| 343 | compact: true, |
| 344 | breakLength: Infinity, |
| 345 | }, previewOptions); |
| 346 | session.post('Runtime.callFunctionOn', { |
| 347 | functionDeclaration: |
| 348 | `(v) => |
| 349 | Reflect |
| 350 | .getOwnPropertyDescriptor(globalThis, 'util') |
| 351 | .get().inspect(v, ${inspectOptions})`, |
| 352 | objectId: result.objectId, |
| 353 | arguments: [result], |
| 354 | }, (error, preview) => { |
| 355 | if (error) { |
| 356 | callback(error); |
| 357 | } else { |
| 358 | callback(null, preview.result.value); |
| 359 | } |
no test coverage detected
searching dependent graphs…