Work on JavaScript API update. Milestone: compiles with new JS, but won't link due to dependency issues.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3860 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-12-17 13:02:45 +00:00
parent 10639d6f52
commit e83e9a42db
5 changed files with 30 additions and 43 deletions

View File

@ -678,10 +678,12 @@ static JSBool ConsoleCallObjCMethod(OOJS_NATIVE_ARGS)
} }
OOJSPauseTimeLimiter(); OOJSPauseTimeLimiter();
BOOL result = OOJSCallObjCObjectMethod(context, object, [object jsClassName], argc, OOJS_ARGV, outResult); jsval result;
BOOL OK = OOJSCallObjCObjectMethod(context, object, [object jsClassName], argc, OOJS_ARGV, &result);
OOJSResumeTimeLimiter(); OOJSResumeTimeLimiter();
return result; OOJS_SET_RVAL(result);
return OK;
OOJS_NATIVE_EXIT OOJS_NATIVE_EXIT
} }

View File

@ -44,6 +44,8 @@ static int sLimiterPauseDepth;
static OOHighResTimeValue sLimiterStart; static OOHighResTimeValue sLimiterStart;
static OOHighResTimeValue sLimiterPauseStart; static OOHighResTimeValue sLimiterPauseStart;
static double sLimiterTimeLimit; static double sLimiterTimeLimit;
#if !OO_NEW_JS
static unsigned long sBranchCount; static unsigned long sBranchCount;
enum enum
{ {
@ -56,6 +58,7 @@ enum
kMaxBranchCount = (1 << 18) // 262144 kMaxBranchCount = (1 << 18) // 262144
#endif #endif
}; };
#endif
#if OOJS_DEBUG_LIMITER #if OOJS_DEBUG_LIMITER
#define OOJS_TIME_LIMIT (0.05) // seconds #define OOJS_TIME_LIMIT (0.05) // seconds
@ -167,6 +170,7 @@ void OOJSSetTimeLimiterLimit(OOTimeDelta limit)
#if !OO_NEW_JS
static JSBool BranchCallback(JSContext *context, JSScript *script) static JSBool BranchCallback(JSContext *context, JSScript *script)
{ {
// This will be called a _lot_. Efficiency is important. // This will be called a _lot_. Efficiency is important.
@ -202,14 +206,18 @@ static JSBool BranchCallback(JSContext *context, JSScript *script)
return NO; return NO;
} }
#endif
JSBool OOJSContextCallback(JSContext *context, uintN contextOp) JSBool OOJSContextCallback(JSContext *context, uintN contextOp)
{ {
#if !OO_NEW_JS
// FIXME: new API has an equivalent, but it needs some work.
if (contextOp == JSCONTEXT_NEW) if (contextOp == JSCONTEXT_NEW)
{ {
JS_SetBranchCallback(context, BranchCallback); JS_SetBranchCallback(context, BranchCallback);
} }
#endif
return YES; return YES;
} }

View File

@ -306,7 +306,7 @@ static JSBool SystemGetProperty(OOJS_PROP_ARGS)
break; break;
case kSystem_info: case kSystem_info:
if (!GetJSSystemInfoForCurrentSystem(context, value)) return NO; *value = GetJSSystemInfoForSystem(context, [player currentGalaxyID], [player currentSystemID]);
break; break;
case kSystem_pseudoRandomNumber: case kSystem_pseudoRandomNumber:
@ -1062,11 +1062,7 @@ static JSBool SystemStaticInfoForSystem(OOJS_NATIVE_ARGS)
return NO; return NO;
} }
OOJSPauseTimeLimiter(); OOJS_RETURN(GetJSSystemInfoForSystem(context, galaxyID, systemID));
BOOL result = GetJSSystemInfoForSystem(context, galaxyID, systemID, outResult);
OOJSResumeTimeLimiter();
return result;
OOJS_NATIVE_EXIT OOJS_NATIVE_EXIT
} }

View File

@ -32,5 +32,5 @@ MA 02110-1301, USA.
void InitOOJSSystemInfo(JSContext *context, JSObject *global); void InitOOJSSystemInfo(JSContext *context, JSObject *global);
BOOL GetJSSystemInfoForCurrentSystem(JSContext *context, jsval *outInfo); // Returns JSVAL_NULL on failure (with a JS warning, but no exception).
BOOL GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID system, jsval *outInfo); jsval GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID system);

View File

@ -265,21 +265,7 @@ void InitOOJSSystemInfo(JSContext *context, JSObject *global)
} }
BOOL GetJSSystemInfoForCurrentSystem(JSContext *context, jsval *outInfo) jsval GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID system)
{
OOJS_PROFILE_ENTER
OOJSPauseTimeLimiter();
PlayerEntity *player = [PlayerEntity sharedPlayer];
BOOL result = GetJSSystemInfoForSystem(context, [player currentGalaxyID], [player currentSystemID], outInfo);
OOJSResumeTimeLimiter();
return result;
OOJS_PROFILE_EXIT
}
BOOL GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID system, jsval *outInfo)
{ {
OOJS_PROFILE_ENTER OOJS_PROFILE_ENTER
@ -288,33 +274,28 @@ BOOL GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID
sCachedGalaxy == galaxy && sCachedGalaxy == galaxy &&
sCachedSystem == system) sCachedSystem == system)
{ {
*outInfo = OBJECT_TO_JSVAL(sCachedSystemInfo); return OBJECT_TO_JSVAL(sCachedSystemInfo);
return YES;
} }
// If not, create a new one. // If not, create a new one.
OOJSPauseTimeLimiter(); OOJSPauseTimeLimiter();
OOSystemInfo *info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease]; OOSystemInfo *info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
*outInfo = [info javaScriptValueInContext:context]; if (EXPECT_NOT(info == nil))
{
OOReportJSWarning(context, @"Could not create system info object for galaxy %u, system %i.", galaxy, system);
}
jsval result = info ? [info javaScriptValueInContext:context] : JSVAL_NULL;
OOJSResumeTimeLimiter(); OOJSResumeTimeLimiter();
if (info == nil) // Cache is not a root; we clear it in finalize if necessary.
{ sCachedSystemInfo = JSVAL_TO_OBJECT(result);
OOReportJSError(context, @"Could not create system info object for galaxy %u, system %i.", galaxy, system); sCachedGalaxy = galaxy;
return NO; sCachedSystem = system;
}
if (JSVAL_IS_OBJECT(*outInfo) && !JSVAL_IS_NULL(*outInfo)) return result;
{
// Cache is not a root; we clear it in finalize if necessary.
sCachedSystemInfo = JSVAL_TO_OBJECT(*outInfo);
sCachedGalaxy = galaxy;
sCachedSystem = system;
return YES;
}
return NO;
OOJS_PROFILE_EXIT OOJS_PROFILE_EXIT_JSVAL
} }