Converted all unguarded oo_jsValueInContext:s to OOJSValueFromNativeObject().
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4356 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
fdd4e8b447
commit
2e788a219d
@ -314,11 +314,12 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsid propID
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
case kConsole_shaderMode:
|
case kConsole_shaderMode:
|
||||||
*value = [OOStringFromShaderSetting([UNIVERSE shaderEffectsLevel]) oo_jsValueInContext:context];
|
// EMMSTRAN: if still relevant, OOConstToJSString-ify.
|
||||||
|
*value = OOJSValueFromNativeObject(context, OOStringFromShaderSetting([UNIVERSE shaderEffectsLevel]));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kConsole_maximumShaderMode:
|
case kConsole_maximumShaderMode:
|
||||||
*value = [OOStringFromShaderSetting([[OOOpenGLExtensionManager sharedManager] maximumShaderSetting]) oo_jsValueInContext:context];
|
*value = OOJSValueFromNativeObject(context, OOStringFromShaderSetting([[OOOpenGLExtensionManager sharedManager] maximumShaderSetting]));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kConsole_reducedDetailMode:
|
case kConsole_reducedDetailMode:
|
||||||
@ -330,7 +331,7 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsid propID
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kConsole_platformDescription:
|
case kConsole_platformDescription:
|
||||||
*value = [OOPlatformDescription() oo_jsValueInContext:context];
|
*value = OOJSValueFromNativeObject(context, OOPlatformDescription());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kConsole_pedanticMode:
|
case kConsole_pedanticMode:
|
||||||
@ -353,11 +354,11 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsid propID
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kConsole_glVendorString:
|
case kConsole_glVendorString:
|
||||||
*value = [[[OOOpenGLExtensionManager sharedManager] vendorString] oo_jsValueInContext:context];
|
*value = OOJSValueFromNativeObject(context, [[OOOpenGLExtensionManager sharedManager] vendorString]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kConsole_glRendererString:
|
case kConsole_glRendererString:
|
||||||
*value = [[[OOOpenGLExtensionManager sharedManager] rendererString] oo_jsValueInContext:context];
|
*value = OOJSValueFromNativeObject(context, [[OOOpenGLExtensionManager sharedManager] rendererString]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kConsole_glFixedFunctionTextureUnitCount:
|
case kConsole_glFixedFunctionTextureUnitCount:
|
||||||
@ -991,7 +992,7 @@ static JSBool ConsoleProfile(JSContext *context, uintN argc, jsval *vp)
|
|||||||
JSBool result = PerformProfiling(context, @"profile", argc, OOJS_ARGV, NULL, NO, &profile);
|
JSBool result = PerformProfiling(context, @"profile", argc, OOJS_ARGV, NULL, NO, &profile);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
OOJS_SET_RVAL([[profile description] oo_jsValueInContext:context]);
|
OOJS_SET_RVAL(OOJSValueFromNativeObject(context, [profile description]));
|
||||||
}
|
}
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
@ -1019,7 +1020,7 @@ static JSBool ConsoleGetProfile(JSContext *context, uintN argc, jsval *vp)
|
|||||||
JSBool result = PerformProfiling(context, @"getProfile", argc, OOJS_ARGV, NULL, NO, &profile);
|
JSBool result = PerformProfiling(context, @"getProfile", argc, OOJS_ARGV, NULL, NO, &profile);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
OOJS_SET_RVAL([profile oo_jsValueInContext:context]);
|
OOJS_SET_RVAL(OOJSValueFromNativeObject(context, profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
@ -1071,8 +1072,8 @@ static JSBool PerformProfiling(JSContext *context, NSString *nominalFunction, ui
|
|||||||
if (argc > 1) this = argv[1];
|
if (argc > 1) this = argv[1];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jsval debugConsole = [[OODebugMonitor sharedDebugMonitor] oo_jsValueInContext:context];
|
jsval debugConsole = OOJSValueFromNativeObject(context, [OODebugMonitor sharedDebugMonitor]);
|
||||||
assert(JSVAL_IS_OBJECT(debugConsole));
|
assert(JSVAL_IS_OBJECT(debugConsole) && !JSVAL_IS_NULL(debugConsole));
|
||||||
JS_GetProperty(context, JSVAL_TO_OBJECT(debugConsole), "script", &this);
|
JS_GetProperty(context, JSVAL_TO_OBJECT(debugConsole), "script", &this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2023,7 +2023,12 @@ static WormholeEntity *whole = nil;
|
|||||||
|
|
||||||
if (function != nil)
|
if (function != nil)
|
||||||
{
|
{
|
||||||
JSFunctionPredicateParameter param = { context, OBJECT_TO_JSVAL(JS_GetFunctionObject([function function])), JSVAL_TO_OBJECT([self oo_jsValueInContext:context]), NO };
|
JSFunctionPredicateParameter param =
|
||||||
|
{
|
||||||
|
.context = context,
|
||||||
|
.function = [function functionValue],
|
||||||
|
.jsThis = OOJSObjectFromNativeObject(context, self)
|
||||||
|
};
|
||||||
[self scanForNearestShipWithPredicate:JSFunctionPredicate parameter:¶m];
|
[self scanForNearestShipWithPredicate:JSFunctionPredicate parameter:¶m];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1006,7 +1006,7 @@ static NSDictionary* instructions(int station_id, Vector coords, float speed, fl
|
|||||||
|
|
||||||
JSContext *context = OOJSAcquireContext();
|
JSContext *context = OOJSAcquireContext();
|
||||||
jsval rval = JSVAL_VOID;
|
jsval rval = JSVAL_VOID;
|
||||||
jsval args[] = { [ship oo_jsValueInContext:context] };
|
jsval args[] = { OOJSValueFromNativeObject(context, ship) };
|
||||||
JSBool permit = YES;
|
JSBool permit = YES;
|
||||||
|
|
||||||
BOOL OK = [[self script] callMethod:OOJSID("permitDocking") inContext:context withArguments:args count:1 result:&rval];
|
BOOL OK = [[self script] callMethod:OOJSID("permitDocking") inContext:context withArguments:args count:1 result:&rval];
|
||||||
|
@ -735,7 +735,7 @@ static void UpdateProfileForFrame(OOHighResTimeValue now, OOJSProfileStackFrame
|
|||||||
|
|
||||||
- (jsval) oo_jsValueInContext:(JSContext *)context
|
- (jsval) oo_jsValueInContext:(JSContext *)context
|
||||||
{
|
{
|
||||||
return [[self propertyListRepresentation] oo_jsValueInContext:context];
|
return OOJSValueFromNativeObject(context, [self propertyListRepresentation]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -968,7 +968,7 @@ static void UpdateProfileForFrame(OOHighResTimeValue now, OOJSProfileStackFrame
|
|||||||
|
|
||||||
- (jsval) oo_jsValueInContext:(JSContext *)context
|
- (jsval) oo_jsValueInContext:(JSContext *)context
|
||||||
{
|
{
|
||||||
return [[self propertyListRepresentation] oo_jsValueInContext:context];
|
return OOJSValueFromNativeObject(context, [self propertyListRepresentation]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ static JSBool EquipmentInfoGetAllEqipment(JSContext *context, JSObject *this, js
|
|||||||
{
|
{
|
||||||
OOJS_NATIVE_ENTER(context)
|
OOJS_NATIVE_ENTER(context)
|
||||||
|
|
||||||
*value = [[OOEquipmentType allEquipmentTypes] oo_jsValueInContext:context];
|
*value = OOJSValueFromNativeObject(context, [OOEquipmentType allEquipmentTypes]);
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
OOJS_NATIVE_EXIT
|
OOJS_NATIVE_EXIT
|
||||||
|
@ -461,7 +461,7 @@ static void RunDeferredOperations(JSContext *context)
|
|||||||
OOJSValue *callbackObj = [operation objectForKey:@"value"];
|
OOJSValue *callbackObj = [operation objectForKey:@"value"];
|
||||||
NSString *errorString = nil;
|
NSString *errorString = nil;
|
||||||
|
|
||||||
if (!AddCallback(context, [callbackObj oo_jsValueInContext:context], trackingID, &errorString))
|
if (!AddCallback(context, OOJSValueFromNativeObject(context, callbackObj), trackingID, &errorString))
|
||||||
{
|
{
|
||||||
OOLogWARN(@"script.frameCallback.deferredAdd.failed", @"Deferred frame callback insertion failed: %@", errorString);
|
OOLogWARN(@"script.frameCallback.deferredAdd.failed", @"Deferred frame callback insertion failed: %@", errorString);
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ MA 02110-1301, USA.
|
|||||||
|
|
||||||
- (NSString *) name;
|
- (NSString *) name;
|
||||||
- (JSFunction *) function;
|
- (JSFunction *) function;
|
||||||
|
- (jsval) functionValue;
|
||||||
|
|
||||||
// Raw evaluation. Context may not be NULL and must be in a request.
|
// Raw evaluation. Context may not be NULL and must be in a request.
|
||||||
- (BOOL) evaluateWithContext:(JSContext *)context
|
- (BOOL) evaluateWithContext:(JSContext *)context
|
||||||
|
@ -160,6 +160,20 @@ MA 02110-1301, USA.
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (jsval) functionValue
|
||||||
|
{
|
||||||
|
if (EXPECT(_function != NULL))
|
||||||
|
{
|
||||||
|
return OBJECT_TO_JSVAL(JS_GetFunctionObject(_function));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return JSVAL_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL) evaluateWithContext:(JSContext *)context
|
- (BOOL) evaluateWithContext:(JSContext *)context
|
||||||
scope:(JSObject *)jsThis
|
scope:(JSObject *)jsThis
|
||||||
argc:(uintN)argc
|
argc:(uintN)argc
|
||||||
|
@ -347,7 +347,7 @@ static JSBool MissionRunScreen(JSContext *context, uintN argc, jsval *vp)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sCallbackThis = [sCallbackScript oo_jsValueInContext:context];
|
sCallbackThis = OOJSValueFromNativeObject(context, sCallbackScript);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,11 +194,11 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsid propID,
|
|||||||
return JS_NewNumberValue(context, [player creditBalance], value);
|
return JS_NewNumberValue(context, [player creditBalance], value);
|
||||||
|
|
||||||
case kPlayer_rank:
|
case kPlayer_rank:
|
||||||
*value = [OODisplayRatingStringFromKillCount([player score]) oo_jsValueInContext:context];
|
*value = OOJSValueFromNativeObject(context, OODisplayRatingStringFromKillCount([player score]));
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
case kPlayer_legalStatus:
|
case kPlayer_legalStatus:
|
||||||
*value = [OODisplayStringFromLegalStatus([player bounty]) oo_jsValueInContext:context];
|
*value = OOJSValueFromNativeObject(context, OODisplayStringFromLegalStatus([player bounty]));
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
case kPlayer_alertCondition:
|
case kPlayer_alertCondition:
|
||||||
@ -237,7 +237,8 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsid propID,
|
|||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
case kPlayer_dockingClearanceStatus:
|
case kPlayer_dockingClearanceStatus:
|
||||||
*value = [DockingClearanceStatusToString([player getDockingClearanceStatus]) oo_jsValueInContext:context];
|
// EMMSTRAN: OOConstToJSString-ify this.
|
||||||
|
*value = OOJSValueFromNativeObject(context, DockingClearanceStatusToString([player getDockingClearanceStatus]));
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
case kPlayer_bounty:
|
case kPlayer_bounty:
|
||||||
|
@ -304,7 +304,7 @@ jsval GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID
|
|||||||
OOJSReportWarning(context, @"Could not create system info object for galaxy %u, system %i.", galaxy, system);
|
OOJSReportWarning(context, @"Could not create system info object for galaxy %u, system %i.", galaxy, system);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = info ? [info oo_jsValueInContext:context] : JSVAL_NULL;
|
result = OOJSValueFromNativeObject(context, info);
|
||||||
|
|
||||||
// Cache is not a root; we clear it in finalize if necessary.
|
// Cache is not a root; we clear it in finalize if necessary.
|
||||||
sCachedSystemInfo = JSVAL_TO_OBJECT(result);
|
sCachedSystemInfo = JSVAL_TO_OBJECT(result);
|
||||||
@ -599,14 +599,14 @@ static JSBool SystemInfoStaticFilteredSystems(JSContext *context, uintN argc, js
|
|||||||
OOJSPauseTimeLimiter();
|
OOJSPauseTimeLimiter();
|
||||||
|
|
||||||
// Iterate over systems.
|
// Iterate over systems.
|
||||||
BOOL OK = YES;
|
BOOL OK = result != nil;
|
||||||
OOGalaxyID galaxy = [PLAYER currentGalaxyID];
|
OOGalaxyID galaxy = [PLAYER currentGalaxyID];
|
||||||
OOSystemID system;
|
OOSystemID system;
|
||||||
for (system = 0; system <= kOOMaximumSystemID; system++)
|
for (system = 0; system <= kOOMaximumSystemID; system++)
|
||||||
{
|
{
|
||||||
// NOTE: this deliberately bypasses the cache, since it's inherently unfriendly to a single-item cache.
|
// NOTE: this deliberately bypasses the cache, since iteration is inherently unfriendly to a single-item cache.
|
||||||
OOSystemInfo *info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
|
OOSystemInfo *info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
|
||||||
jsval args[1] = { [info oo_jsValueInContext:context] };
|
jsval args[1] = { OOJSValueFromNativeObject(context, info) };
|
||||||
|
|
||||||
jsval rval = JSVAL_VOID;
|
jsval rval = JSVAL_VOID;
|
||||||
OOJSResumeTimeLimiter();
|
OOJSResumeTimeLimiter();
|
||||||
|
@ -198,8 +198,13 @@ OOINLINE jsval OOJSValueFromBOOL(int b)
|
|||||||
|
|
||||||
Return the JavaScript value representation of an object. The default
|
Return the JavaScript value representation of an object. The default
|
||||||
implementation returns JSVAL_VOID.
|
implementation returns JSVAL_VOID.
|
||||||
Note that sending this to nil does not return JSVAL_NULL. For that
|
|
||||||
behaviour, use OOJSValueFromNativeObject() below.
|
SAFETY NOTE: if this message is sent to nil, the return value depends on
|
||||||
|
the platform and whether JS_USE_JSVAL_JSID_STRUCT_TYPES is set. If the
|
||||||
|
receiver may be nil, use OOJSValueFromNativeObject() instead.
|
||||||
|
|
||||||
|
One case where it is safe to use oo_jsValueInContext: is with objects
|
||||||
|
retrieved from Foundation collections, as they can never be nil.
|
||||||
|
|
||||||
Requires a request on context.
|
Requires a request on context.
|
||||||
*/
|
*/
|
||||||
@ -237,6 +242,15 @@ OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* OOJSObjectFromNativeObject()
|
||||||
|
Return a JavaScript object representation of an object, or null if passed
|
||||||
|
nil. The value is boxed if necessary.
|
||||||
|
|
||||||
|
Requires a request on context.
|
||||||
|
*/
|
||||||
|
JSObject *OOJSObjectFromNativeObject(JSContext *context, id object);
|
||||||
|
|
||||||
|
|
||||||
/* OOJSValue: an object whose purpose in life is to hold a JavaScript value.
|
/* OOJSValue: an object whose purpose in life is to hold a JavaScript value.
|
||||||
This is somewhat useful for putting JavaScript objects in ObjC collections,
|
This is somewhat useful for putting JavaScript objects in ObjC collections,
|
||||||
for instance to pass as properties to script loaders. The value is
|
for instance to pass as properties to script loaders. The value is
|
||||||
@ -658,7 +672,7 @@ JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp);
|
|||||||
#define OOJS_RETURN_NULL OOJS_RETURN(JSVAL_NULL)
|
#define OOJS_RETURN_NULL OOJS_RETURN(JSVAL_NULL)
|
||||||
#define OOJS_RETURN_BOOL(v) OOJS_RETURN(OOJSValueFromBOOL(v))
|
#define OOJS_RETURN_BOOL(v) OOJS_RETURN(OOJSValueFromBOOL(v))
|
||||||
#define OOJS_RETURN_INT(v) OOJS_RETURN(INT_TO_JSVAL(v))
|
#define OOJS_RETURN_INT(v) OOJS_RETURN(INT_TO_JSVAL(v))
|
||||||
#define OOJS_RETURN_OBJECT(o) do { id o_ = (o); OOJS_RETURN(o_ ? [o_ oo_jsValueInContext:context] : JSVAL_NULL); } while (0)
|
#define OOJS_RETURN_OBJECT(o) OOJS_RETURN(OOJSValueFromNativeObject(context, o))
|
||||||
|
|
||||||
#define OOJS_RETURN_WITH_HELPER(helper, value) \
|
#define OOJS_RETURN_WITH_HELPER(helper, value) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -1347,6 +1347,15 @@ static BOOL JSNewNSDictionaryValue(JSContext *context, NSDictionary *dictionary,
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
JSObject *OOJSObjectFromNativeObject(JSContext *context, id object)
|
||||||
|
{
|
||||||
|
jsval value = OOJSValueFromNativeObject(context, object);
|
||||||
|
JSObject *result = NULL;
|
||||||
|
if (JS_ValueToObject(context, value, &result)) return result;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@implementation OOJSValue
|
@implementation OOJSValue
|
||||||
|
|
||||||
+ (id) valueWithJSValue:(jsval)value inContext:(JSContext *)context
|
+ (id) valueWithJSValue:(jsval)value inContext:(JSContext *)context
|
||||||
@ -1967,13 +1976,13 @@ BOOL JSFunctionPredicate(Entity *entity, void *parameter)
|
|||||||
jsval rval = JSVAL_VOID;
|
jsval rval = JSVAL_VOID;
|
||||||
JSBool result = NO;
|
JSBool result = NO;
|
||||||
|
|
||||||
NSCParameterAssert(entity != NULL && param != NULL);
|
NSCParameterAssert(entity != nil && param != NULL);
|
||||||
NSCParameterAssert(param->context != NULL && JS_IsInRequest(param->context));
|
NSCParameterAssert(param->context != NULL && JS_IsInRequest(param->context));
|
||||||
NSCParameterAssert(OOJSValueIsFunction(param->context, param->function));
|
NSCParameterAssert(OOJSValueIsFunction(param->context, param->function));
|
||||||
|
|
||||||
if (EXPECT_NOT(param->errorFlag)) return NO;
|
if (EXPECT_NOT(param->errorFlag)) return NO;
|
||||||
|
|
||||||
args[0] = [entity oo_jsValueInContext:param->context];
|
args[0] = [entity oo_jsValueInContext:param->context]; // entity is required to be non-nil (asserted above), so oo_jsValueInContext: is safe.
|
||||||
|
|
||||||
OOJSStartTimeLimiter();
|
OOJSStartTimeLimiter();
|
||||||
OOJSResumeTimeLimiter();
|
OOJSResumeTimeLimiter();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user