A bunch of JS callback cleanup, mostly explicit void returns.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3953 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2011-01-01 17:46:53 +00:00
parent e7ddfb7adf
commit 4caf9301ae
14 changed files with 48 additions and 36 deletions

View File

@ -193,7 +193,9 @@ static JSBool ClockGetProperty(OOJS_PROP_ARGS)
static JSBool JSClockToString(OOJS_NATIVE_ARGS)
{
OOJS_NATIVE_ENTER(context)
OOJS_RETURN_OBJECT([OOPlayerForScripting() dial_clock]);
OOJS_NATIVE_EXIT
}
@ -208,6 +210,7 @@ static JSBool ClockClockStringForTime(OOJS_NATIVE_ARGS)
if (EXPECT_NOT(!JS_ValueToNumber(context, OOJS_ARG(0), &time))) return NO;
OOJS_RETURN_OBJECT(ClockToString(time, NO));
OOJS_NATIVE_EXIT
}
@ -230,5 +233,6 @@ static JSBool ClockAddSeconds(OOJS_NATIVE_ARGS)
[OOPlayerForScripting() addToAdjustTime:time];
OOJS_RETURN_BOOL(YES);
OOJS_NATIVE_EXIT
}

View File

@ -177,12 +177,11 @@ static JSBool EntityGetProperty(OOJS_PROP_ARGS)
Entity *entity = nil;
id result = nil;
OOJSEntityGetEntity(context, this, &entity);
if (entity == nil)
if (EXPECT_NOT(!OOJSEntityGetEntity(context, this, &entity))) return NO;
if (OOIsStaleEntity(entity))
{
if (OOJS_PROPID_INT == kEntity_isValid) *value = JSVAL_FALSE;
else *value = JSVAL_VOID;
else { *value = JSVAL_VOID; }
return YES;
}
@ -300,7 +299,8 @@ static JSBool EntitySetProperty(OOJS_PROP_ARGS)
Vector vValue;
Quaternion qValue;
if (EXPECT_NOT(!OOJSEntityGetEntity(context, this, &entity))) return YES; // Do nothing.
if (EXPECT_NOT(!OOJSEntityGetEntity(context, this, &entity))) return NO;
if (OOIsStaleEntity(entity)) return YES;
switch (OOJS_PROPID_INT)
{

View File

@ -241,7 +241,7 @@ static JSBool GlobalLog(OOJS_NATIVE_ARGS)
#endif
OOJSResumeTimeLimiter();
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -438,7 +438,7 @@ static JSBool GlobalTakeSnapShot(OOJS_NATIVE_ARGS)
if (freeSpace < 1073741824) // less than 1 GB free on disk?
{
OOReportJSWarning(context, @"takeSnapShot: function disabled when free disk space is less than 1GB.");
return YES;
OOJS_RETURN_BOOL(NO);
}
}

View File

@ -163,7 +163,7 @@ static JSBool MissionMarkSystem(OOJS_NATIVE_ARGS)
params = [NSString concatenationOfStringsFromJavaScriptValues:OOJS_ARGV count:argc separator:@" " inContext:context];
[player addMissionDestination:params];
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -180,7 +180,7 @@ static JSBool MissionUnmarkSystem(OOJS_NATIVE_ARGS)
params = [NSString concatenationOfStringsFromJavaScriptValues:OOJS_ARGV count:argc separator:@" " inContext:context];
[player removeMissionDestination:params];
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -199,7 +199,7 @@ static JSBool MissionAddMessageText(OOJS_NATIVE_ARGS)
text = JSValToNSString(context, OOJS_ARG(0));
[player addLiteralMissionText:text];
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -254,7 +254,7 @@ static JSBool MissionSetInstructionsInternal(OOJS_NATIVE_ARGS, BOOL isKey)
[player clearMissionDescriptionForMission:missionKey];
}
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}

View File

@ -193,8 +193,5 @@ static JSBool OoliteCompareVersion(OOJS_NATIVE_ARGS)
OOJS_RETURN_VOID;
}
return YES;
OOJS_NATIVE_EXIT
}

View File

@ -211,7 +211,7 @@ static JSBool PlayerShipGetProperty(OOJS_PROP_ARGS)
OOJS_NATIVE_ENTER(context)
if (EXPECT_NOT([UNIVERSE blockJSPlayerShipProps])) { *value = JSVAL_VOID; return YES; }
if (EXPECT_NOT(!OOJS_PROPID_IS_INT)) return YES;
if (!OOJS_PROPID_IS_INT) return YES;
BOOL OK = NO;
id result = nil;
@ -344,7 +344,7 @@ static JSBool PlayerShipSetProperty(OOJS_PROP_ARGS)
OOJS_NATIVE_ENTER(context)
if (EXPECT_NOT([UNIVERSE blockJSPlayerShipProps])) return YES;
if (EXPECT_NOT(!OOJS_PROPID_IS_INT)) return YES;
if (!OOJS_PROPID_IS_INT) return YES;
BOOL OK = NO;
PlayerEntity *player = OOPlayerShipForScripting();

View File

@ -538,7 +538,6 @@ static JSBool QuaternionConstruct(OOJS_NATIVE_ARGS)
{
this = JS_NewObject(context, &sQuaternionClass, NULL, NULL);
if (this == NULL) return NO;
OOJS_SET_RVAL(OBJECT_TO_JSVAL(this));
}
else
{
@ -567,7 +566,7 @@ static JSBool QuaternionConstruct(OOJS_NATIVE_ARGS)
return NO;
}
return YES;
OOJS_RETURN_JSOBJECT(this);
OOJS_PROFILE_EXIT
}

View File

@ -766,7 +766,7 @@ static JSBool ShipSetProperty(OOJS_PROP_ARGS)
OOColor *colorForScript = nil;
if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity))) return NO;
if (OOIsStaleEntity(entity)) { *value = JSVAL_VOID; return YES; }
if (OOIsStaleEntity(entity)) return YES;
switch (OOJS_PROPID_INT)
{

View File

@ -72,7 +72,8 @@ static JSBool SpecialJSWarning(OOJS_NATIVE_ARGS)
OOSetJSWarningOrErrorStackSkip(1);
OOReportJSWarning(context, @"%@", [NSString stringWithJavaScriptValue:OOJS_ARG(0) inContext:context]);
OOSetJSWarningOrErrorStackSkip(0);
return YES;
OOJS_RETURN_VOID;
OOJS_PROFILE_EXIT
}

View File

@ -178,7 +178,8 @@ static JSBool StationGetProperty(OOJS_PROP_ARGS)
StationEntity *entity = nil;
if (!JSStationGetStationEntity(context, this, &entity)) return NO;
if (!JSStationGetStationEntity(context, this, &entity)) return NO;
if (entity == nil) { *value = JSVAL_VOID; return YES; }
switch (OOJS_PROPID_INT)
{
@ -254,6 +255,7 @@ static JSBool StationSetProperty(OOJS_PROP_ARGS)
int32 iValue;
if (!JSStationGetStationEntity(context, this, &entity)) return NO;
if (entity == nil) return YES;
switch (OOJS_PROPID_INT)
{

View File

@ -503,8 +503,6 @@ static JSBool SystemAddMoon(OOJS_NATIVE_ARGS)
OOJS_RETURN_OBJECT(planet);
return YES;
OOJS_NATIVE_EXIT
}
@ -517,7 +515,7 @@ static JSBool SystemSendAllShipsAway(OOJS_NATIVE_ARGS)
PlayerEntity *player = OOPlayerForScripting();
[player sendAllShipsAway];
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -819,7 +817,7 @@ static JSBool SystemLegacyAddShips(OOJS_NATIVE_ARGS)
while (count--) [UNIVERSE witchspaceShipWithPrimaryRole:role];
OOJSResumeTimeLimiter();
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -849,7 +847,7 @@ static JSBool SystemLegacyAddSystemShips(OOJS_NATIVE_ARGS)
while (count--) [UNIVERSE addShipWithRole:role nearRouteOneAt:position];
OOJSResumeTimeLimiter();
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -885,7 +883,7 @@ static JSBool SystemLegacyAddShipsAt(OOJS_NATIVE_ARGS)
[player addShipsAt:arg];
OOJSResumeTimeLimiter();
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -921,7 +919,7 @@ static JSBool SystemLegacyAddShipsAtPrecisely(OOJS_NATIVE_ARGS)
[player addShipsAtPrecisely:arg];
OOJSResumeTimeLimiter();
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -960,7 +958,7 @@ static JSBool SystemLegacyAddShipsWithinRadius(OOJS_NATIVE_ARGS)
[player addShipsWithinRadius:arg];
OOJSResumeTimeLimiter();
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
@ -985,7 +983,7 @@ static JSBool SystemLegacySpawnShip(OOJS_NATIVE_ARGS)
[UNIVERSE spawnShip:key];
OOJSResumeTimeLimiter();
return YES;
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}

View File

@ -578,6 +578,11 @@ static JSBool SystemInfoStaticFilteredSystems(OOJS_NATIVE_ARGS)
{
OOJS_SET_RVAL([result javaScriptValueInContext:context]);
}
else
{
OOJS_SET_RVAL(JSVAL_VOID);
}
[pool release];
OOJSResumeTimeLimiter();

View File

@ -449,12 +449,13 @@ BOOL VectorFromArgumentListNoError(JSContext *context, uintN argc, jsval *argv,
static JSBool VectorGetProperty(OOJS_PROP_ARGS)
{
if (!OOJS_PROPID_IS_INT) return YES;
OOJS_PROFILE_ENTER
Vector vector;
GLfloat fValue;
if (!OOJS_PROPID_IS_INT) return YES;
if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector))) return NO;
switch (OOJS_PROPID_INT)
@ -484,12 +485,13 @@ static JSBool VectorGetProperty(OOJS_PROP_ARGS)
static JSBool VectorSetProperty(OOJS_PROP_ARGS)
{
if (!OOJS_PROPID_IS_INT) return YES;
OOJS_PROFILE_ENTER
Vector vector;
jsdouble dval;
if (!OOJS_PROPID_IS_INT) return YES;
if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector))) return NO;
if (EXPECT_NOT(!JS_ValueToNumber(context, *value, &dval)))
{
@ -553,7 +555,6 @@ static JSBool VectorConstruct(OOJS_NATIVE_ARGS)
{
this = JS_NewObject(context, &sVectorClass, NULL, NULL);
if (this == NULL) return NO;
OOJS_SET_RVAL(OBJECT_TO_JSVAL(this));
}
else
{
@ -582,7 +583,7 @@ static JSBool VectorConstruct(OOJS_NATIVE_ARGS)
return NO;
}
return YES;
OOJS_RETURN_JSOBJECT(this);
OOJS_PROFILE_EXIT
}
@ -913,7 +914,7 @@ static JSBool VectorToArray(OOJS_NATIVE_ARGS)
result = JS_NewArrayObject(context, 0, NULL);
if (result != NULL)
{
// We do this at the top because *outResult is a GC root.
// We do this at the top because the return value slot is a GC root.
OOJS_SET_RVAL(OBJECT_TO_JSVAL(result));
if (JS_NewNumberValue(context, thisv.x, &nVal) && JS_SetElement(context, result, 0, &nVal) &&

View File

@ -232,6 +232,9 @@ void JSObjectWrapperFinalize(JSContext *context, JSObject *this);
@end
OOINLINE NSString *JSValToNSString(JSContext *context, jsval value) ALWAYS_INLINE_FUNC;
OOINLINE NSString *JSObjectToNSString(JSContext *context, JSObject *object) ALWAYS_INLINE_FUNC;
OOINLINE NSString *JSValToNSString(JSContext *context, jsval value)
{
return [NSString stringOrNilWithJavaScriptValue:value inContext:context];
@ -269,6 +272,7 @@ id JSObjectToObject(JSContext *context, JSObject *object);
id JSValueToObjectOfClass(JSContext *context, jsval value, Class requiredClass);
id JSObjectToObjectOfClass(JSContext *context, JSObject *object, Class requiredClass);
OOINLINE JSClass *OOJS_GetClass(JSContext *cx, JSObject *obj) ALWAYS_INLINE_FUNC;
OOINLINE JSClass *OOJS_GetClass(JSContext *cx, JSObject *obj)
{
@ -577,6 +581,7 @@ void OOJSDumpStack(NSString *logMessageClass, JSContext *context);
#define OOJS_ARG(n) (OOJS_ARGV[(n)])
#define OOJS_RETURN(v) do { OOJS_SET_RVAL(v); return YES; } while (0)
#define OOJS_RETURN_JSOBJECT(o) OOJS_RETURN(OBJECT_TO_JSVAL(o))
#define OOJS_RETURN_VOID OOJS_RETURN(JSVAL_VOID)
#define OOJS_RETURN_NULL OOJS_RETURN(JSVAL_NULL)
#define OOJS_RETURN_BOOL(v) OOJS_RETURN(BOOLToJSVal(v))