mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
[ReactNative] Ignore bad inputs to parseErrorStack
This commit is contained in:
parent
972b546fc6
commit
1429b78af5
@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
require('mock-modules').autoMockOff();
|
||||||
|
|
||||||
|
var parseErrorStack = require('parseErrorStack');
|
||||||
|
|
||||||
|
function getFakeError() {
|
||||||
|
return new Error('Happy Cat');
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('parseErrorStack', function() {
|
||||||
|
|
||||||
|
it('parses error stack', function() {
|
||||||
|
var stack = parseErrorStack(getFakeError());
|
||||||
|
expect(stack.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
var firstFrame = stack[0];
|
||||||
|
expect(firstFrame.methodName).toEqual('getFakeError');
|
||||||
|
expect(firstFrame.file).toMatch(/parseErrorStack-test\.js$/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('supports framesToPop', function() {
|
||||||
|
function getWrappedError() {
|
||||||
|
var error = getFakeError();
|
||||||
|
error.framesToPop = 1;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure framesToPop == 1 causes it to ignore getFakeError
|
||||||
|
// stack frame
|
||||||
|
var stack = parseErrorStack(getWrappedError());
|
||||||
|
expect(stack[0].methodName).toEqual('getWrappedError');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignores bad inputs', function() {
|
||||||
|
expect(parseErrorStack({})).toEqual([]);
|
||||||
|
expect(parseErrorStack(null)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -28,6 +28,10 @@ function resolveSourceMaps(sourceMapInstance, stackFrame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseErrorStack(e, sourceMapInstance) {
|
function parseErrorStack(e, sourceMapInstance) {
|
||||||
|
if (!e || !e.stack) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
var stack = stacktraceParser.parse(e.stack);
|
var stack = stacktraceParser.parse(e.stack);
|
||||||
|
|
||||||
var framesToPop = e.framesToPop || 0;
|
var framesToPop = e.framesToPop || 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user