| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d10d39e commit e08649c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,23 +45,21 @@ | |||
| 45 | 45 | const { | |
| 46 | 46 | ArrayPrototypeAt, | |
| 47 | 47 | ArrayPrototypeFilter, | |
| 48 | - ArrayPrototypeFindIndex, | ||
| 48 | + ArrayPrototypeFindLastIndex, | ||
| 49 | 49 | ArrayPrototypeForEach, | |
| 50 | 50 | ArrayPrototypeIncludes, | |
| 51 | 51 | ArrayPrototypeJoin, | |
| 52 | 52 | ArrayPrototypeMap, | |
| 53 | 53 | ArrayPrototypePop, | |
| 54 | 54 | ArrayPrototypePush, | |
| 55 | 55 | ArrayPrototypePushApply, | |
| 56 | - ArrayPrototypeReverse, | ||
| 57 | 56 | ArrayPrototypeShift, | |
| 58 | 57 | ArrayPrototypeSlice, | |
| 59 | 58 | ArrayPrototypeSome, | |
| 60 | 59 | ArrayPrototypeSort, | |
| 61 | - ArrayPrototypeSplice, | ||
| 62 | 60 | ArrayPrototypeUnshift, | |
| 63 | 61 | Boolean, | |
| 64 | - Error, | ||
| 62 | + Error: MainContextError, | ||
| 65 | 63 | FunctionPrototypeBind, | |
| 66 | 64 | JSONStringify, | |
| 67 | 65 | MathMaxApply, | |
@@ -630,10 +628,10 @@ function REPLServer(prompt, | |||
| 630 | 628 | if (self.breakEvalOnSigint) { | |
| 631 | 629 | const interrupt = new Promise((resolve, reject) => { | |
| 632 | 630 | sigintListener = () => { | |
| 633 | - const tmp = Error.stackTraceLimit; | ||
| 634 | - if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0; | ||
| 631 | + const tmp = MainContextError.stackTraceLimit; | ||
| 632 | + if (isErrorStackTraceLimitWritable()) MainContextError.stackTraceLimit = 0; | ||
| 635 | 633 | const err = new ERR_SCRIPT_EXECUTION_INTERRUPTED(); | |
| 636 | - if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = tmp; | ||
| 634 | + if (isErrorStackTraceLimitWritable()) MainContextError.stackTraceLimit = tmp; | ||
| 637 | 635 | reject(err); | |
| 638 | 636 | }; | |
| 639 | 637 | prioritizedSigintQueue.add(sigintListener); | |
@@ -679,23 +677,23 @@ function REPLServer(prompt, | |||
| 679 | 677 | if (typeof stackFrames === 'object') { | |
| 680 | 678 | // Search from the bottom of the call stack to | |
| 681 | 679 | // find the first frame with a null function name | |
| 682 | - const idx = ArrayPrototypeFindIndex( | ||
| 683 | - ArrayPrototypeReverse(stackFrames), | ||
| 680 | + const idx = ArrayPrototypeFindLastIndex( | ||
| 681 | + stackFrames, | ||
| 684 | 682 | (frame) => frame.getFunctionName() === null, | |
| 685 | 683 | ); | |
| 686 | 684 | // If found, get rid of it and everything below it | |
| 687 | - frames = ArrayPrototypeSplice(stackFrames, idx + 1); | ||
| 685 | + frames = ArrayPrototypeSlice(stackFrames, 0, idx); | ||
| 688 | 686 | } else { | |
| 689 | 687 | frames = stackFrames; | |
| 690 | 688 | } | |
| 691 | 689 | // FIXME(devsnek): this is inconsistent with the checks | |
| 692 | 690 | // that the real prepareStackTrace dispatch uses in | |
| 693 | 691 | // lib/internal/errors.js. | |
| 694 | - if (typeof Error.prepareStackTrace === 'function') { | ||
| 695 | - return Error.prepareStackTrace(error, frames); | ||
| 692 | + if (typeof MainContextError.prepareStackTrace === 'function') { | ||
| 693 | + return MainContextError.prepareStackTrace(error, frames); | ||
| 696 | 694 | } | |
| 697 | - ArrayPrototypePush(frames, error); | ||
| 698 | - return ArrayPrototypeJoin(ArrayPrototypeReverse(frames), '\n at '); | ||
| 695 | + ArrayPrototypeUnshift(frames, error); | ||
| 696 | + return ArrayPrototypeJoin(frames, '\n at '); | ||
| 699 | 697 | }); | |
| 700 | 698 | decorateErrorStack(e); | |
| 701 | 699 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,8 +42,9 @@ const origPrepareStackTrace = Error.prepareStackTrace; | |||
| 42 | 42 | Error.prepareStackTrace = (err, stack) => { | |
| 43 | 43 | if (err instanceof SyntaxError) | |
| 44 | 44 | return err.toString(); | |
| 45 | - stack.push(err); | ||
| 46 | - return stack.reverse().join('--->\n'); | ||
| 45 | + // Insert the error at the beginning of the stack | ||
| 46 | + stack.unshift(err); | ||
| 47 | + return stack.join('--->\n'); | ||
| 47 | 48 | }; | |
| 48 | 49 | ||
| 49 | 50 | process.on('uncaughtException', (e) => { | |
@@ -78,3 +79,10 @@ const tests = [ | |||
| 78 | 79 | ]; | |
| 79 | 80 | ||
| 80 | 81 | tests.forEach(run); | |
| 82 | + | ||
| 83 | + // Verify that the stack can be generated when Error.prepareStackTrace is deleted. | ||
| 84 | + delete Error.prepareStackTrace; | ||
| 85 | + run({ | ||
| 86 | + command: 'throw new TypeError(\'Whoops!\')', | ||
| 87 | + expected: 'Uncaught TypeError: Whoops!\n' | ||
| 88 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments