diff --git a/src/Core/Scripting/OOJSOolite.m b/src/Core/Scripting/OOJSOolite.m index 08944316..ffbc1d3f 100644 --- a/src/Core/Scripting/OOJSOolite.m +++ b/src/Core/Scripting/OOJSOolite.m @@ -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]]) { diff --git a/src/Core/Scripting/OOJSQuaternion.m b/src/Core/Scripting/OOJSQuaternion.m index 3a1ffd1b..33e40ef1 100644 --- a/src/Core/Scripting/OOJSQuaternion.m +++ b/src/Core/Scripting/OOJSQuaternion.m @@ -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); diff --git a/src/Core/Scripting/OOJSVector.m b/src/Core/Scripting/OOJSVector.m index 5dede29c..8d036629 100644 --- a/src/Core/Scripting/OOJSVector.m +++ b/src/Core/Scripting/OOJSVector.m @@ -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; }