[ReactNative] Back out D2014163 entirely

This commit is contained in:
Philipp von Weitershausen 2015-04-23 11:34:25 -07:00
parent 24095fcc2d
commit e88ba1a6a3
5 changed files with 29 additions and 43 deletions

View File

@ -69,7 +69,7 @@ var AppRegistry = {
'Running application "' + appKey + '" with appParams: ' +
JSON.stringify(appParameters) + '. ' +
'__DEV__ === ' + __DEV__ +
', development-level warnings are ' + (__DEV__ ? 'ON' : 'OFF') +
', development-level warning are ' + (__DEV__ ? 'ON' : 'OFF') +
', performance optimizations are ' + (__DEV__ ? 'OFF' : 'ON')
);
invariant(

View File

@ -25,11 +25,17 @@ type Exception = {
message: string;
}
function reportException(e: Exception, stack?: any) {
function handleException(e: Exception) {
var stack = parseErrorStack(e);
console.error(
'Err0r: ' +
'\n stack: \n' + stackToString(stack) +
'\n URL: ' + e.sourceURL +
'\n line: ' + e.line +
'\n message: ' + e.message
);
if (RCTExceptionsManager) {
if (!stack) {
stack = parseErrorStack(e);
}
RCTExceptionsManager.reportUnhandledException(e.message, stack);
if (__DEV__) {
(sourceMapPromise = sourceMapPromise || loadSourceMap())
@ -44,18 +50,6 @@ function reportException(e: Exception, stack?: any) {
}
}
function handleException(e: Exception) {
var stack = parseErrorStack(e);
console.log(
'Error: ' +
'\n stack: \n' + stackToString(stack) +
'\n URL: ' + e.sourceURL +
'\n line: ' + e.line +
'\n message: ' + e.message
);
reportException(e, stack);
}
function stackToString(stack) {
var maxLength = Math.max.apply(null, stack.map(frame => frame.methodName.length));
return stack.map(frame => stackFrameToString(frame, maxLength)).join('\n');
@ -77,4 +71,4 @@ function fillSpaces(n) {
return new Array(n + 1).join(' ');
}
module.exports = { handleException, reportException };
module.exports = { handleException };

View File

@ -77,7 +77,6 @@ function handleErrorWithRedBox(e) {
function setupRedBoxErrorHandler() {
var ErrorUtils = require('ErrorUtils');
ErrorUtils.setGlobalHandler(handleErrorWithRedBox);
GLOBAL.reportException = require('ExceptionsManager').reportException;
}
/**
@ -135,8 +134,8 @@ function setupGeolocation() {
}
setupDocumentShim();
setupRedBoxErrorHandler();
setupTimers();
setupRedBoxErrorHandler(); // needs to happen after setupTimers
setupAlert();
setupPromise();
setupXHR();

View File

@ -74,12 +74,12 @@
static JSValueRef RCTNativeLoggingHook(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
{
if (argumentCount > 0) {
JSStringRef messageRef = JSValueToStringCopy(context, arguments[0], exception);
if (!messageRef) {
JSStringRef string = JSValueToStringCopy(context, arguments[0], exception);
if (!string) {
return JSValueMakeUndefined(context);
}
NSString *message = (__bridge_transfer NSString *)JSStringCopyCFString(kCFAllocatorDefault, messageRef);
JSStringRelease(messageRef);
NSString *message = (__bridge_transfer NSString *)JSStringCopyCFString(kCFAllocatorDefault, string);
JSStringRelease(string);
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:
@"( stack: )?([_a-z0-9]*)@?(http://|file:///)[a-z.0-9:/_-]+/([a-z0-9_]+).includeRequire.runModule.bundle(:[0-9]+:[0-9]+)"
options:NSRegularExpressionCaseInsensitive
@ -89,11 +89,14 @@ static JSValueRef RCTNativeLoggingHook(JSContextRef context, JSObjectRef object,
range:(NSRange){0, message.length}
withTemplate:@"[$4$5] \t$2"];
// TODO: it would be good if log level was sent as a param, instead of this hack
RCTLogLevel level = RCTLogLevelInfo;
if (argumentCount > 1) {
level = MAX(level, JSValueToNumber(context, arguments[1], exception) - 1);
if ([message rangeOfString:@"error" options:NSCaseInsensitiveSearch].length) {
level = RCTLogLevelError;
} else if ([message rangeOfString:@"warning" options:NSCaseInsensitiveSearch].length) {
level = RCTLogLevelWarning;
}
RCTGetLogFunction()(level, nil, nil, message);
_RCTLogFormat(level, NULL, -1, @"%@", message);
}
return JSValueMakeUndefined(context);

View File

@ -23,7 +23,7 @@
log: 1,
info: 2,
warn: 3,
error: 4,
error: 4
};
function setupConsole(global) {
@ -35,10 +35,8 @@
function getNativeLogFunction(level) {
return function() {
var str = Array.prototype.map.call(arguments, function(arg) {
if (arg === undefined) {
return 'undefined';
} else if (arg === null) {
return 'null';
if (arg == null) {
return arg === null ? 'null' : 'undefined';
} else if (typeof arg === 'string') {
return '"' + arg + '"';
} else {
@ -50,22 +48,14 @@
if (typeof arg.toString === 'function') {
try {
return arg.toString();
} catch (E) {}
} catch (E) {
return 'unknown';
}
}
return '["' + typeof arg + '" failed to stringify]';
}
}
}).join(', ');
global.nativeLoggingHook(str, level);
if (global.reportException && level === LOG_LEVELS.error) {
var error = new Error(str);
error.framesToPop = 1;
// TODO(sahrens): re-enable this when we have a way to turn
// it off by default for MAdMan/Android, and/or all
// consumers of console.error() are fixed, including
// CatalystErrorHandlerModuleTestCase
// global.reportException(error);
}
};
}