JS audit: OOJSOolite, OOJSQuaternion and OOJSVector.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4319 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2011-02-11 21:06:13 +00:00
parent bbf14a048e
commit 63ea1cc222
3 changed files with 16 additions and 17 deletions

View File

@ -105,25 +105,22 @@ static JSBool OoliteGetProperty(JSContext *context, JSObject *this, jsid propID,
{
case kOolite_version:
result = VersionComponents();
if (result == nil) result = [NSNull null];
break;
case kOolite_versionString:
result = VersionString();
if (result == nil) result = [NSNull null];
break;
case kOolite_jsVersion:
*value = INT_TO_JSVAL(JS_GetVersion(context));
break;
return YES;
case kOolite_jsVersionString:
*value = STRING_TO_JSVAL(JS_NewStringCopyZ(context, JS_VersionToString(JS_GetVersion(context))));
break;
return YES;
case kOolite_gameSettings:
result = [UNIVERSE gameSettings];
if (result == nil) result = [NSNull null];
break;
default:
@ -131,7 +128,7 @@ static JSBool OoliteGetProperty(JSContext *context, JSObject *this, jsid propID,
return NO;
}
if (result != nil) *value = [result oo_jsValueInContext:context];
*value = OOJSValueFromNativeObject(context, result);
return YES;
OOJS_NATIVE_EXIT
@ -165,6 +162,8 @@ static JSBool OoliteCompareVersion(JSContext *context, uintN argc, jsval *vp)
NSEnumerator *componentEnum = nil;
id component = nil;
if (argc == 0) OOJS_RETURN_VOID; // Backwards-compatibility: be overly lenient.
components = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[0]);
if ([components isKindOfClass:[NSArray class]])
{

View File

@ -415,6 +415,7 @@ static BOOL QuaternionFromArgumentListNoErrorInternal(JSContext *context, uintN
}
// EMMSTRAN: remove outConsumed, since it can only be 1 except in failure (constructor is an exception, but it uses QuaternionFromArgumentListNoErrorInternal() directly).
BOOL QuaternionFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, Quaternion *outQuaternion, uintN *outConsumed)
{
if (QuaternionFromArgumentListNoErrorInternal(context, argc, argv, outQuaternion, outConsumed, NO)) return YES;
@ -753,7 +754,7 @@ static JSBool QuaternionVectorForward(JSContext *context, uintN argc, jsval *vp)
Quaternion thisq;
Vector result;
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"vectorForward()"))) return NO;
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"vectorForward"))) return NO;
result = vector_forward_from_quaternion(thisq);

View File

@ -433,6 +433,7 @@ static BOOL VectorFromArgumentListNoErrorInternal(JSContext *context, uintN argc
}
// EMMSTRAN: remove outConsumed, since it can only be 1 except in failure (constructor is an exception, but it uses VectorFromArgumentListNoErrorInternal() directly).
BOOL VectorFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, Vector *outVector, uintN *outConsumed)
{
if (VectorFromArgumentListNoErrorInternal(context, argc, argv, outVector, outConsumed, NO)) return YES;
@ -941,12 +942,11 @@ static JSBool VectorToCoordinateSystem(JSContext *context, uintN argc, jsval *vp
Vector result;
if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toCoordinateSystem"))) return NO;
coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0]);
if (EXPECT_NOT(coordScheme == nil ||
argc < 1 ))
if (EXPECT_NOT(argc < 1 ||
(coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0])) == nil))
{
OOJSReportBadArguments(context, @"Vector3D", @"toCoordinateSystem", argc, OOJS_ARGV, nil, @"coordinate system");
OOJSReportBadArguments(context, @"Vector3D", @"toCoordinateSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"coordinate system");
return NO;
}
@ -970,12 +970,11 @@ static JSBool VectorFromCoordinateSystem(JSContext *context, uintN argc, jsval *
Vector result;
if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"fromCoordinateSystem"))) return NO;
coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0]);
if (EXPECT_NOT(coordScheme == nil ||
argc < 1 ))
if (EXPECT_NOT(argc < 1 ||
(coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0])) == nil))
{
OOJSReportBadArguments(context, @"Vector3D", @"fromCoordinateSystem", argc, OOJS_ARGV, nil, @"coordinate system");
OOJSReportBadArguments(context, @"Vector3D", @"fromCoordinateSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"coordinate system");
return NO;
}