Found the random combination of documentation and source code comments that makes it clear that DOUBLE_TO_JSVAL is invalid when value may be an integer, and switched everything to JS_NewNumberValue() (which is like JS_NewDoubleValue() only different, since JS_NewDoubleValue() was also invalid for potentially-integer values).
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4196 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
177ffb9baf
commit
c997498109
@ -718,26 +718,28 @@ NSString *OOStringFromDeciCredits(OOCreditsQuantity tenthsOfCredits, BOOL includ
|
||||
JSObject *fakeRoot;
|
||||
jsval method;
|
||||
jsval rval;
|
||||
NSString *result = @"<error>";
|
||||
NSString *result = nil;
|
||||
|
||||
if (JS_GetMethodById(context, global, OOJSID("formatCredits"), &fakeRoot, &method))
|
||||
{
|
||||
jsval args[3] =
|
||||
jsval args[3];
|
||||
if (JS_NewNumberValue(context, tenthsOfCredits * 0.1, &args[0]))
|
||||
{
|
||||
DOUBLE_TO_JSVAL(tenthsOfCredits * 0.1),
|
||||
OOJSValueFromBOOL(includeDecimal),
|
||||
OOJSValueFromBOOL(includeSymbol)
|
||||
};
|
||||
|
||||
OOJSStartTimeLimiter();
|
||||
JS_CallFunctionValue(context, global, method, 3, args, &rval);
|
||||
OOJSStopTimeLimiter();
|
||||
|
||||
result = OOStringFromJSValue(context, rval);
|
||||
args[1] = OOJSValueFromBOOL(includeDecimal);
|
||||
args[2] = OOJSValueFromBOOL(includeSymbol);
|
||||
|
||||
OOJSStartTimeLimiter();
|
||||
JS_CallFunctionValue(context, global, method, 3, args, &rval);
|
||||
OOJSStopTimeLimiter();
|
||||
|
||||
result = OOStringFromJSValue(context, rval);
|
||||
}
|
||||
}
|
||||
|
||||
OOJSRelinquishContext(context);
|
||||
|
||||
if (EXPECT_NOT(result == nil)) result = [NSString stringWithFormat:@"%li", (long)(tenthsOfCredits) / 10];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -117,28 +117,24 @@ static JSBool ClockGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
PlayerEntity *player = nil;
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
double clockTime;
|
||||
|
||||
player = OOPlayerForScripting();
|
||||
clockTime = [player clockTime];
|
||||
|
||||
switch (JSID_TO_INT(propID))
|
||||
{
|
||||
case kClock_absoluteSeconds:
|
||||
*value = DOUBLE_TO_JSVAL([UNIVERSE getTime]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [UNIVERSE getTime], value);
|
||||
|
||||
case kClock_seconds:
|
||||
*value = DOUBLE_TO_JSVAL(clockTime);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, clockTime, value);
|
||||
|
||||
case kClock_minutes:
|
||||
*value = DOUBLE_TO_JSVAL(floor(clockTime / 60.0));
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, floor(clockTime / 60.0), value);
|
||||
|
||||
case kClock_hours:
|
||||
*value = DOUBLE_TO_JSVAL(floor(clockTime / 3600.0));
|
||||
return JS_NewNumberValue(context, floor(clockTime /3600.0), value);
|
||||
return YES;
|
||||
|
||||
case kClock_secondsComponent:
|
||||
@ -167,8 +163,7 @@ static JSBool ClockGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
return YES;
|
||||
|
||||
case kClock_legacy_scriptTimer:
|
||||
*value = DOUBLE_TO_JSVAL([OOPlayerForScripting() scriptTimer]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [player scriptTimer], value);
|
||||
|
||||
default:
|
||||
OOJSReportBadPropertySelector(context, this, propID, sClockProperties);
|
||||
|
@ -31,14 +31,6 @@ MA 02110-1301, USA.
|
||||
/***** Transitional compatibility stuff - remove when switching to OO_NEW_JS permanently. *****/
|
||||
|
||||
|
||||
// Before removing, switch to DOUBLE_TOJSVAL() everywhere.
|
||||
OOINLINE JSBool JS_NewDoubleValue(JSContext *cx, jsdouble d, jsval *rval)
|
||||
{
|
||||
NSCParameterAssert(rval != NULL);
|
||||
*rval = DOUBLE_TO_JSVAL(d);
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -173,7 +173,6 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
BOOL OK = NO;
|
||||
Entity *entity = nil;
|
||||
id result = nil;
|
||||
|
||||
@ -188,20 +187,16 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
switch (JSID_TO_INT(propID))
|
||||
{
|
||||
case kEntity_collisionRadius:
|
||||
OK = JS_NewDoubleValue(context, [entity collisionRadius], value);
|
||||
break;
|
||||
return JS_NewNumberValue(context, [entity collisionRadius], value);
|
||||
|
||||
case kEntity_position:
|
||||
OK = VectorToJSValue(context, [entity position], value);
|
||||
break;
|
||||
return VectorToJSValue(context, [entity position], value);
|
||||
|
||||
case kEntity_orientation:
|
||||
OK = QuaternionToJSValue(context, [entity normalOrientation], value);
|
||||
break;
|
||||
return QuaternionToJSValue(context, [entity normalOrientation], value);
|
||||
|
||||
case kEntity_heading:
|
||||
OK = VectorToJSValue(context, vector_forward_from_quaternion([entity normalOrientation]), value);
|
||||
break;
|
||||
return VectorToJSValue(context, vector_forward_from_quaternion([entity normalOrientation]), value);
|
||||
|
||||
case kEntity_status:
|
||||
*value = OOJSValueFromEntityStatus(context, [entity status]);
|
||||
@ -212,8 +207,7 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
return YES;
|
||||
|
||||
case kEntity_mass:
|
||||
*value = DOUBLE_TO_JSVAL([entity mass]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity mass], value);
|
||||
|
||||
case kEntity_owner:
|
||||
result = [entity owner];
|
||||
@ -222,12 +216,10 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
break;
|
||||
|
||||
case kEntity_energy:
|
||||
*value = DOUBLE_TO_JSVAL([entity energy]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity energy], value);
|
||||
|
||||
case kEntity_maxEnergy:
|
||||
*value = DOUBLE_TO_JSVAL([entity maxEnergy]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity maxEnergy], value);
|
||||
|
||||
case kEntity_isValid:
|
||||
*value = JSVAL_TRUE;
|
||||
@ -258,23 +250,17 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
return YES;
|
||||
|
||||
case kEntity_distanceTravelled:
|
||||
*value = DOUBLE_TO_JSVAL([entity distanceTravelled]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity distanceTravelled], value);
|
||||
|
||||
case kEntity_spawnTime:
|
||||
*value = DOUBLE_TO_JSVAL([entity spawnTime]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity spawnTime], value);
|
||||
|
||||
default:
|
||||
OOJSReportBadPropertySelector(context, this, propID, sEntityProperties);
|
||||
}
|
||||
|
||||
if (result != nil)
|
||||
{
|
||||
*value = [result oo_jsValueInContext:context];
|
||||
return YES;
|
||||
}
|
||||
return OK;
|
||||
*value = OOJSValueFromNativeObject(context, result);
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ void OOJSFrameCallbacksInvoke(OOTimeDelta delta)
|
||||
jsval deltaVal, result;
|
||||
OOUInteger i;
|
||||
|
||||
if (EXPECT_NOT(!JS_NewDoubleValue(context, delta, &deltaVal))) return;
|
||||
if (EXPECT_NOT(!JS_NewNumberValue(context, delta, &deltaVal))) return;
|
||||
|
||||
// Block mutations.
|
||||
sRunning = YES;
|
||||
|
@ -165,22 +165,20 @@ static JSBool GlobalGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
id result = nil;
|
||||
|
||||
switch (JSID_TO_INT(propID))
|
||||
{
|
||||
case kGlobal_galaxyNumber:
|
||||
*value = INT_TO_JSVAL([player currentGalaxyID]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kGlobal_guiScreen:
|
||||
*value = OOJSValueFromGUIScreenID(context, [player guiScreen]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
#ifndef NDEBUG
|
||||
case kGlobal_timeAccelerationFactor:
|
||||
JS_NewDoubleValue(context, [UNIVERSE timeAccelerationFactor], value);
|
||||
break;
|
||||
return JS_NewNumberValue(context, [UNIVERSE timeAccelerationFactor], value);
|
||||
#endif
|
||||
|
||||
default:
|
||||
@ -188,9 +186,6 @@ static JSBool GlobalGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (result != nil) *value = [result oo_jsValueInContext:context];
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
@ -127,30 +127,15 @@ static JSBool MissionVariablesGetProperty(JSContext *context, JSObject *this, js
|
||||
|
||||
id mvar = [player missionVariableForKey:key];
|
||||
|
||||
*value = JSVAL_VOID;
|
||||
if ([mvar isKindOfClass:[NSString class]]) // Currently there should only be strings, but we may want to change this.
|
||||
{
|
||||
if (OOIsNumberLiteral(mvar, YES))
|
||||
{
|
||||
BOOL OK = JS_NewDoubleValue(context, [mvar doubleValue], value);
|
||||
if (!OK) *value = JSVAL_VOID;
|
||||
return JS_NewNumberValue(context, [mvar doubleValue], value);
|
||||
}
|
||||
}
|
||||
|
||||
if (mvar != nil && JSVAL_IS_VOID(*value))
|
||||
{
|
||||
*value = [mvar oo_jsValueInContext:context];
|
||||
}
|
||||
|
||||
if (JSVAL_IS_VOID(*value))
|
||||
{
|
||||
/* "undefined" is the normal JS expectation, but "null" is easier
|
||||
to deal with. For instance, foo = missionVaraibles.undefinedThing
|
||||
is an error if JSVAL_VOID is used, but fine if JSVAL_NULL is
|
||||
used.
|
||||
*/
|
||||
*value = JSVAL_NULL;
|
||||
}
|
||||
*value = OOJSValueFromNativeObject(context, mvar);
|
||||
}
|
||||
return YES;
|
||||
|
||||
|
@ -128,7 +128,6 @@ static JSBool PlanetGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
BOOL OK = NO;
|
||||
OOPlanetEntity *planet = nil;
|
||||
if (!JSPlanetGetPlanetEntity(context, this, &planet)) return NO;
|
||||
|
||||
@ -136,35 +135,29 @@ static JSBool PlanetGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
{
|
||||
case kPlanet_isMainPlanet:
|
||||
*value = OOJSValueFromBOOL(planet == (id)[UNIVERSE planet]);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlanet_radius:
|
||||
OK = JS_NewDoubleValue(context, [planet radius], value);
|
||||
break;
|
||||
return JS_NewNumberValue(context, [planet radius], value);
|
||||
|
||||
case kPlanet_hasAtmosphere:
|
||||
*value = OOJSValueFromBOOL([planet hasAtmosphere]);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlanet_texture:
|
||||
*value = [[planet textureFileName] oo_jsValueInContext:context];
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlanet_orientation:
|
||||
OK = QuaternionToJSValue(context, [planet normalOrientation], value);
|
||||
break;
|
||||
return QuaternionToJSValue(context, [planet normalOrientation], value);
|
||||
|
||||
case kPlanet_rotationalVelocity:
|
||||
OK = JS_NewDoubleValue(context, [planet rotationalVelocity], value);
|
||||
break;
|
||||
return JS_NewNumberValue(context, [planet rotationalVelocity], value);
|
||||
|
||||
default:
|
||||
OOJSReportBadPropertySelector(context, this, propID, sPlanetProperties);
|
||||
return NO;
|
||||
}
|
||||
return OK;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
@ -181,7 +181,6 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
BOOL OK = NO;
|
||||
id result = nil;
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
|
||||
@ -189,91 +188,75 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
{
|
||||
case kPlayer_name:
|
||||
result = [player playerName];
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_score:
|
||||
*value = INT_TO_JSVAL([player score]);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_credits:
|
||||
OK = JS_NewDoubleValue(context, [player creditBalance], value);
|
||||
break;
|
||||
return JS_NewNumberValue(context, [player creditBalance], value);
|
||||
|
||||
case kPlayer_rank:
|
||||
*value = [OODisplayRatingStringFromKillCount([player score]) oo_jsValueInContext:context];
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_legalStatus:
|
||||
*value = [OODisplayStringFromLegalStatus([player bounty]) oo_jsValueInContext:context];
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_alertCondition:
|
||||
*value = INT_TO_JSVAL([player alertCondition]);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_alertTemperature:
|
||||
*value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_TEMP);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_alertMassLocked:
|
||||
*value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_MASS_LOCK);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_alertAltitude:
|
||||
*value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_ALT);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_alertEnergy:
|
||||
*value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_ENERGY);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_alertHostiles:
|
||||
*value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_HOSTILES);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_trumbleCount:
|
||||
OK = JS_NewNumberValue(context, [player trumbleCount], value);
|
||||
break;
|
||||
return JS_NewNumberValue(context, [player trumbleCount], value);
|
||||
|
||||
case kPlayer_contractReputation:
|
||||
*value = INT_TO_JSVAL([player contractReputation]);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kPlayer_passengerReputation:
|
||||
*value = INT_TO_JSVAL([player passengerReputation]);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
#if DOCKING_CLEARANCE_ENABLED
|
||||
case kPlayer_dockingClearanceStatus:
|
||||
*value = [DockingClearanceStatusToString([player getDockingClearanceStatus]) oo_jsValueInContext:context];
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
#endif
|
||||
|
||||
case kPlayer_bounty:
|
||||
*value = INT_TO_JSVAL([player legalStatus]);
|
||||
OK = YES;
|
||||
break;
|
||||
return YES;
|
||||
|
||||
default:
|
||||
OOJSReportBadPropertySelector(context, this, propID, sPlayerProperties);
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (OK && result != nil) *value = [result oo_jsValueInContext:context];
|
||||
return OK;
|
||||
*value = OOJSValueFromNativeObject(context, result);
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
@ -217,15 +217,13 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid pro
|
||||
|
||||
if (EXPECT_NOT(OOIsPlayerStale() || this == sPlayerShipPrototype)) { *value = JSVAL_VOID; return YES; }
|
||||
|
||||
BOOL OK = NO;
|
||||
id result = nil;
|
||||
PlayerEntity *player = OOPlayerShipForScripting();
|
||||
|
||||
switch (JSID_TO_INT(propID))
|
||||
{
|
||||
case kPlayerShip_fuelLeakRate:
|
||||
*value = DOUBLE_TO_JSVAL([player fuelLeakRate]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [player fuelLeakRate], value);
|
||||
|
||||
case kPlayerShip_docked:
|
||||
*value = OOJSValueFromBOOL([player isDocked]);
|
||||
@ -233,7 +231,6 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid pro
|
||||
|
||||
case kPlayerShip_dockedStation:
|
||||
result = [player dockedStation];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kPlayerShip_specialCargo:
|
||||
@ -249,38 +246,30 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid pro
|
||||
return YES;
|
||||
|
||||
case kPlayerShip_galacticHyperspaceFixedCoords:
|
||||
OK = NSPointToVectorJSValue(context, [player galacticHyperspaceFixedCoords], value);
|
||||
break;
|
||||
return NSPointToVectorJSValue(context, [player galacticHyperspaceFixedCoords], value);
|
||||
|
||||
case kPlayerShip_forwardShield:
|
||||
*value = DOUBLE_TO_JSVAL([player forwardShieldLevel]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [player forwardShieldLevel], value);
|
||||
|
||||
case kPlayerShip_aftShield:
|
||||
*value = DOUBLE_TO_JSVAL([player aftShieldLevel]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [player aftShieldLevel], value);
|
||||
|
||||
case kPlayerShip_maxForwardShield:
|
||||
*value = DOUBLE_TO_JSVAL([player maxForwardShieldLevel]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [player maxForwardShieldLevel], value);
|
||||
|
||||
case kPlayerShip_maxAftShield:
|
||||
*value = DOUBLE_TO_JSVAL([player maxAftShieldLevel]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [player maxAftShieldLevel], value);
|
||||
|
||||
case kPlayerShip_forwardShieldRechargeRate:
|
||||
case kPlayerShip_aftShieldRechargeRate:
|
||||
// No distinction made internally
|
||||
*value = DOUBLE_TO_JSVAL([player shieldRechargeRate]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [player shieldRechargeRate], value);
|
||||
|
||||
case kPlayerShip_galaxyCoordinates:
|
||||
OK = NSPointToVectorJSValue(context, [player galaxy_coordinates], value);
|
||||
break;
|
||||
return NSPointToVectorJSValue(context, [player galaxy_coordinates], value);
|
||||
|
||||
case kPlayerShip_cursorCoordinates:
|
||||
OK = NSPointToVectorJSValue(context, [player cursor_coordinates], value);
|
||||
break;
|
||||
return NSPointToVectorJSValue(context, [player cursor_coordinates], value);
|
||||
|
||||
case kPlayerShip_targetSystem:
|
||||
*value = INT_TO_JSVAL([UNIVERSE findSystemNumberAtCoords:[player cursor_coordinates] withGalaxySeed:[player galaxy_seed]]);
|
||||
@ -322,12 +311,8 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsid pro
|
||||
OOJSReportBadPropertySelector(context, this, propID, sPlayerShipProperties);
|
||||
}
|
||||
|
||||
if (result != nil)
|
||||
{
|
||||
*value = [result oo_jsValueInContext:context];
|
||||
OK = YES;
|
||||
}
|
||||
return OK;
|
||||
*value = OOJSValueFromNativeObject(context, result);
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ static JSBool QuaternionGetProperty(JSContext *context, JSObject *this, jsid pro
|
||||
return NO;
|
||||
}
|
||||
|
||||
return JS_NewDoubleValue(context, fValue, value);
|
||||
return JS_NewNumberValue(context, fValue, value);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
|
@ -356,7 +356,6 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
BOOL OK = NO;
|
||||
ShipEntity *entity = nil;
|
||||
id result = nil;
|
||||
|
||||
@ -394,12 +393,10 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
break;
|
||||
|
||||
case kShip_fuel:
|
||||
*value = DOUBLE_TO_JSVAL([entity fuel] * 0.1);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity fuel] * 0.1, value);
|
||||
|
||||
case kShip_fuelChargeRate:
|
||||
*value = DOUBLE_TO_JSVAL([entity fuelChargeRate]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity fuelChargeRate], value);
|
||||
|
||||
case kShip_bounty:
|
||||
*value = INT_TO_JSVAL([entity bounty]);
|
||||
@ -407,7 +404,6 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
|
||||
case kShip_subEntities:
|
||||
result = [entity subEntitiesForScript];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_subEntityCapacity:
|
||||
@ -420,7 +416,6 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
|
||||
case kShip_target:
|
||||
result = [entity primaryTarget];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_escorts:
|
||||
@ -431,25 +426,20 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
|
||||
case kShip_group:
|
||||
result = [entity group];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_escortGroup:
|
||||
result = [entity escortGroup];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_temperature:
|
||||
*value = DOUBLE_TO_JSVAL([entity temperature] / SHIP_MAX_CABIN_TEMP);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity temperature] / SHIP_MAX_CABIN_TEMP, value);
|
||||
|
||||
case kShip_heatInsulation:
|
||||
*value = DOUBLE_TO_JSVAL([entity heatInsulation]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity heatInsulation], value);
|
||||
|
||||
case kShip_heading:
|
||||
OK = VectorToJSValue(context, [entity forwardVector], value);
|
||||
break;
|
||||
return VectorToJSValue(context, [entity forwardVector], value);
|
||||
|
||||
case kShip_entityPersonality:
|
||||
*value = INT_TO_JSVAL([entity entityPersonalityInt]);
|
||||
@ -461,7 +451,6 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
|
||||
case kShip_beaconCode:
|
||||
result = [entity beaconCode];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_isFrangible:
|
||||
@ -482,7 +471,6 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
|
||||
case kShip_potentialCollider:
|
||||
result = [entity proximity_alert];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_hasHostileTarget:
|
||||
@ -494,12 +482,10 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
return YES;
|
||||
|
||||
case kShip_weaponRange:
|
||||
*value = DOUBLE_TO_JSVAL([entity weaponRange]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity weaponRange], value);
|
||||
|
||||
case kShip_scannerRange:
|
||||
*value = DOUBLE_TO_JSVAL([entity scannerRange]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity scannerRange], value);
|
||||
|
||||
case kShip_reportAIMessages:
|
||||
*value = OOJSValueFromBOOL([entity reportAIMessages]);
|
||||
@ -522,24 +508,19 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
return YES;
|
||||
|
||||
case kShip_speed:
|
||||
*value = DOUBLE_TO_JSVAL([entity flightSpeed]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity flightSpeed], value);
|
||||
|
||||
case kShip_cruiseSpeed:
|
||||
*value = DOUBLE_TO_JSVAL([entity cruiseSpeed]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity cruiseSpeed], value);
|
||||
|
||||
case kShip_desiredSpeed:
|
||||
*value = DOUBLE_TO_JSVAL([entity desiredSpeed]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity desiredSpeed], value);
|
||||
|
||||
case kShip_maxSpeed:
|
||||
*value = DOUBLE_TO_JSVAL([entity maxFlightSpeed]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity maxFlightSpeed], value);
|
||||
|
||||
case kShip_script:
|
||||
result = [entity shipScript];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_isPirate:
|
||||
@ -620,12 +601,10 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
return YES;
|
||||
|
||||
case kShip_missileLoadTime:
|
||||
*value = DOUBLE_TO_JSVAL([entity missileLoadTime]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity missileLoadTime], value);
|
||||
|
||||
case kShip_savedCoordinates:
|
||||
OK = VectorToJSValue(context, [entity coordinates], value);
|
||||
break;
|
||||
return VectorToJSValue(context, [entity coordinates], value);
|
||||
|
||||
case kShip_equipment:
|
||||
result = [entity equipmentListForScripting];
|
||||
@ -633,22 +612,18 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
|
||||
case kShip_forwardWeapon:
|
||||
result = [entity weaponTypeForFacing:WEAPON_FACING_FORWARD];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_aftWeapon:
|
||||
result = [entity weaponTypeForFacing:WEAPON_FACING_AFT];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_portWeapon: // for future expansion
|
||||
result = [entity weaponTypeForFacing:WEAPON_FACING_PORT];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_starboardWeapon: // for future expansion
|
||||
result = [entity weaponTypeForFacing:WEAPON_FACING_STARBOARD];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_missiles:
|
||||
@ -665,58 +640,44 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
||||
|
||||
case kShip_scannerDisplayColor1:
|
||||
result = [[entity scannerDisplayColor1] normalizedArray];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_scannerDisplayColor2:
|
||||
result = [[entity scannerDisplayColor2] normalizedArray];
|
||||
if (result == nil) result = [NSNull null];
|
||||
break;
|
||||
|
||||
case kShip_maxThrust:
|
||||
*value = DOUBLE_TO_JSVAL([entity maxThrust]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity maxThrust], value);
|
||||
|
||||
case kShip_thrust:
|
||||
*value = DOUBLE_TO_JSVAL([entity thrust]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [entity thrust], value);
|
||||
|
||||
case kShip_lightsActive:
|
||||
*value = OOJSValueFromBOOL([entity lightsActive]);
|
||||
return YES;
|
||||
|
||||
case kShip_vectorRight:
|
||||
OK = VectorToJSValue(context, [entity rightVector], value);
|
||||
break;
|
||||
return VectorToJSValue(context, [entity rightVector], value);
|
||||
|
||||
case kShip_vectorForward:
|
||||
OK = VectorToJSValue(context, [entity forwardVector], value);
|
||||
break;
|
||||
return VectorToJSValue(context, [entity forwardVector], value);
|
||||
|
||||
case kShip_vectorUp:
|
||||
OK = VectorToJSValue(context, [entity upVector], value);
|
||||
break;
|
||||
return VectorToJSValue(context, [entity upVector], value);
|
||||
|
||||
case kShip_velocity:
|
||||
OK = VectorToJSValue(context, [entity velocity], value);
|
||||
break;
|
||||
return VectorToJSValue(context, [entity velocity], value);
|
||||
|
||||
case kShip_thrustVector:
|
||||
OK = VectorToJSValue(context, [entity thrustVector], value);
|
||||
break;
|
||||
return VectorToJSValue(context, [entity thrustVector], value);
|
||||
|
||||
default:
|
||||
OOJSReportBadPropertySelector(context, this, propID, sShipProperties);
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (result != nil)
|
||||
{
|
||||
*value = [result oo_jsValueInContext:context];
|
||||
OK = YES;
|
||||
}
|
||||
|
||||
return OK;
|
||||
*value = OOJSValueFromNativeObject(context, result);
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
@ -185,59 +185,57 @@ static JSBool StationGetProperty(JSContext *context, JSObject *this, jsid propID
|
||||
{
|
||||
case kStation_isMainStation:
|
||||
*value = OOJSValueFromBOOL(entity == [UNIVERSE station]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kStation_hasNPCTraffic:
|
||||
*value = OOJSValueFromBOOL([entity hasNPCTraffic]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kStation_alertCondition:
|
||||
*value = INT_TO_JSVAL([entity alertLevel]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
#if DOCKING_CLEARANCE_ENABLED
|
||||
case kStation_requiresDockingClearance:
|
||||
*value = OOJSValueFromBOOL([entity requiresDockingClearance]);
|
||||
break;
|
||||
return YES;
|
||||
#endif
|
||||
|
||||
case kStation_allowsFastDocking:
|
||||
*value = OOJSValueFromBOOL([entity allowsFastDocking]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kStation_allowsAutoDocking:
|
||||
*value = OOJSValueFromBOOL([entity allowsAutoDocking]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kStation_dockedContractors:
|
||||
*value = INT_TO_JSVAL([entity dockedContractors]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kStation_dockedPolice:
|
||||
*value = INT_TO_JSVAL([entity dockedPolice]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kStation_dockedDefenders:
|
||||
*value = INT_TO_JSVAL([entity dockedDefenders]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kStation_equivalentTechLevel:
|
||||
*value = INT_TO_JSVAL([entity equivalentTechLevel]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
case kStation_equipmentPriceFactor:
|
||||
*value = DOUBLE_TO_JSVAL([entity equipmentPriceFactor]);
|
||||
break;
|
||||
return JS_NewNumberValue(context, [entity equipmentPriceFactor], value);
|
||||
|
||||
case kStation_suppressArrivalReports:
|
||||
*value = OOJSValueFromBOOL([entity suppressArrivalReports]);
|
||||
break;
|
||||
return YES;
|
||||
|
||||
default:
|
||||
OOJSReportBadPropertySelector(context, this, propID, sStationProperties);
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
@ -130,8 +130,7 @@ static JSBool SunGetProperty(JSContext *context, JSObject *this, jsid propID, js
|
||||
switch (JSID_TO_INT(propID))
|
||||
{
|
||||
case kSun_radius:
|
||||
*value = DOUBLE_TO_JSVAL([sun radius]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [sun radius], value);
|
||||
|
||||
case kSun_hasGoneNova:
|
||||
*value = OOJSValueFromBOOL([sun goneNova]);
|
||||
|
@ -259,8 +259,7 @@ static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
return YES;
|
||||
|
||||
case kSystem_pseudoRandomNumber:
|
||||
*value = DOUBLE_TO_JSVAL([player systemPseudoRandomFloat]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [player systemPseudoRandomFloat], value);
|
||||
|
||||
case kSystem_pseudoRandom100:
|
||||
*value = INT_TO_JSVAL([player systemPseudoRandom100]);
|
||||
|
@ -475,7 +475,7 @@ static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsid pro
|
||||
{
|
||||
if ([propValue isKindOfClass:[NSNumber class]] || OOIsNumberLiteral(propValue, YES))
|
||||
{
|
||||
BOOL OK = JS_NewDoubleValue(context, [propValue doubleValue], value);
|
||||
BOOL OK = JS_NewNumberValue(context, [propValue doubleValue], value);
|
||||
if (!OK)
|
||||
{
|
||||
*value = JSVAL_VOID;
|
||||
|
@ -242,12 +242,10 @@ static JSBool TimerGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
switch (JSID_TO_INT(propID))
|
||||
{
|
||||
case kTimer_nextTime:
|
||||
*value = DOUBLE_TO_JSVAL([timer nextTime]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [timer nextTime], value);
|
||||
|
||||
case kTimer_interval:
|
||||
*value = DOUBLE_TO_JSVAL([timer interval]);
|
||||
return YES;
|
||||
return JS_NewNumberValue(context, [timer interval], value);
|
||||
|
||||
case kTimer_isRunning:
|
||||
*value = OOJSValueFromBOOL([timer isScheduled]);
|
||||
|
@ -484,7 +484,7 @@ static JSBool VectorGetProperty(JSContext *context, JSObject *this, jsid propID,
|
||||
return NO;
|
||||
}
|
||||
|
||||
return JS_NewDoubleValue(context, fValue, value);
|
||||
return JS_NewNumberValue(context, fValue, value);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
|
@ -636,6 +636,7 @@ JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp);
|
||||
|
||||
#define OOJS_RETURN_VECTOR(value) do { jsval jsresult; BOOL OK = VectorToJSValue(context, value, &jsresult); JS_SET_RVAL(context, vp, jsresult); return OK; } while (0)
|
||||
#define OOJS_RETURN_QUATERNION(value) do { jsval jsresult; BOOL OK = QuaternionToJSValue(context, value, &jsresult); JS_SET_RVAL(context, vp, jsresult); return OK; } while (0)
|
||||
#define OOJS_RETURN_DOUBLE(value) do { jsval jsresult; BOOL OK = JS_NewNumberValue(context, value, &jsresult); JS_SET_RVAL(context, vp, jsresult); return OK; } while (0)
|
||||
|
||||
#define OOJS_RETURN(v) do { OOJS_SET_RVAL(v); return YES; } while (0)
|
||||
#define OOJS_RETURN_JSOBJECT(o) OOJS_RETURN(OBJECT_TO_JSVAL(o))
|
||||
@ -643,7 +644,6 @@ JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp);
|
||||
#define OOJS_RETURN_NULL OOJS_RETURN(JSVAL_NULL)
|
||||
#define OOJS_RETURN_BOOL(v) OOJS_RETURN(OOJSValueFromBOOL(v))
|
||||
#define OOJS_RETURN_INT(v) OOJS_RETURN(INT_TO_JSVAL(v))
|
||||
#define OOJS_RETURN_DOUBLE(v) OOJS_RETURN(DOUBLE_TO_JSVAL(v))
|
||||
#define OOJS_RETURN_OBJECT(o) do { id o_ = (o); OOJS_RETURN(o_ ? [o_ oo_jsValueInContext:context] : JSVAL_NULL); } while (0)
|
||||
|
||||
|
||||
|
@ -1832,7 +1832,7 @@ NSString *OOJSDescribeValue(JSContext *context, jsval value, BOOL abbreviateObje
|
||||
|
||||
if (isFloat)
|
||||
{
|
||||
if (!JS_NewDoubleValue(context, [self doubleValue], &result)) result = JSVAL_VOID;
|
||||
if (!JS_NewNumberValue(context, [self doubleValue], &result)) result = JSVAL_VOID;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user