From deed92cff7dec098b3ba18a1e2240730f8ff562e Mon Sep 17 00:00:00 2001 From: aburkhalter Date: Sat, 19 Dec 2009 03:49:22 -0800 Subject: [PATCH] Toll-free bridge Error to CPException. Add rhinoException in objj_exception for better error reporting. --- Foundation/CPException.j | 17 ++++++++++------- Objective-J/Runtime/exception.js | 13 ++++++++----- Tests/Foundation/CPIndexSetTest.j | 4 ++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Foundation/CPException.j b/Foundation/CPException.j index 69c34b579..9537496d2 100755 --- a/Foundation/CPException.j +++ b/Foundation/CPException.j @@ -92,7 +92,7 @@ if (input == nil) if (self) { name = aName; - reason = aReason; + message = aReason; userInfo = aUserInfo; } @@ -112,7 +112,7 @@ if (input == nil) */ - (CPString)reason { - return reason; + return message; } /*! @@ -128,7 +128,7 @@ if (input == nil) */ - (CPString)description { - return reason; + return message; } /*! @@ -145,7 +145,7 @@ if (input == nil) - (id)copy { - return [[self class] exceptionWithName:name reason:reason userInfo:userInfo]; + return [[self class] exceptionWithName:name reason:message userInfo:userInfo]; } @end @@ -168,7 +168,7 @@ var CPExceptionNameKey = "CPExceptionNameKey", if (self) { name = [aCoder decodeObjectForKey:CPExceptionNameKey]; - reason = [aCoder decodeObjectForKey:CPExceptionReasonKey]; + message = [aCoder decodeObjectForKey:CPExceptionReasonKey]; userInfo = [aCoder decodeObjectForKey:CPExceptionUserInfoKey]; } @@ -182,13 +182,16 @@ var CPExceptionNameKey = "CPExceptionNameKey", - (void)encodeWithCoder:(CPCoder)aCoder { [aCoder encodeObject:name forKey:CPExceptionNameKey]; - [aCoder encodeObject:reason forKey:CPExceptionReasonKey]; + [aCoder encodeObject:message forKey:CPExceptionReasonKey]; [aCoder encodeObject:userInfo forKey:CPExceptionUserInfoKey]; } @end -objj_exception.prototype.isa = CPException; +// toll-free bridge Error to CPException +// [CPException alloc] uses an objj_exception, which is a subclass of Error +Error.prototype.isa = CPException; + [CPException initialize]; function _CPRaiseInvalidAbstractInvocation(anObject, aSelector) diff --git a/Objective-J/Runtime/exception.js b/Objective-J/Runtime/exception.js index ef0f1b3d5..cc0aca5db 100644 --- a/Objective-J/Runtime/exception.js +++ b/Objective-J/Runtime/exception.js @@ -25,15 +25,18 @@ var OBJJ_EXCEPTION_OUTPUT_STREAM = NULL; function objj_exception(aName, aReason, aUserInfo) { this.name = aName; - this.reason = aReason; + this.message = aReason; this.userInfo = aUserInfo; this.__address = _objj_generateObjectHash(); + + // add rhinoException to get better stack traces + if (typeof Packages !== "undefined" && Packages && Packages.org) + this.rhinoException = Packages.org.mozilla.javascript.JavaScriptException(this, null, 0); } -objj_exception.prototype.toString = function() -{ - return this.reason; -} +// make objj_exception a subclass of Error +// later we toll-free bridge Error to CPException +objj_exception.prototype = new Error(); function objj_exception_throw(anException) { diff --git a/Tests/Foundation/CPIndexSetTest.j b/Tests/Foundation/CPIndexSetTest.j index b4d05ae9d..d5bd5d117 100644 --- a/Tests/Foundation/CPIndexSetTest.j +++ b/Tests/Foundation/CPIndexSetTest.j @@ -283,7 +283,7 @@ function descriptionWithoutEntity(aString) [self assert:[_set lastIndex] equals:19]; [self assert:[[CPIndexSet indexSet] lastIndex] equals:CPNotFound]; } - +/* - (void)testAddSpeed { var startTime = [CPDate date]; @@ -296,7 +296,7 @@ function descriptionWithoutEntity(aString) print([startTime timeIntervalSinceNow]); //[self assertTrue: ABS([startTime timeIntervalSinceNow]) < 2]; } - +*/ - (void)testIndexGreaterThanIndex { [self assert:[_set indexGreaterThanIndex:5] equals:10];