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();
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();
return result;
OOJS_SET_RVAL(result);
return OK;
OOJS_NATIVE_EXIT
}

View File

@ -44,6 +44,8 @@ static int sLimiterPauseDepth;
static OOHighResTimeValue sLimiterStart;
static OOHighResTimeValue sLimiterPauseStart;
static double sLimiterTimeLimit;
#if !OO_NEW_JS
static unsigned long sBranchCount;
enum
{
@ -56,6 +58,7 @@ enum
kMaxBranchCount = (1 << 18) // 262144
#endif
};
#endif
#if OOJS_DEBUG_LIMITER
#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)
{
// This will be called a _lot_. Efficiency is important.
@ -202,14 +206,18 @@ static JSBool BranchCallback(JSContext *context, JSScript *script)
return NO;
}
#endif
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)
{
JS_SetBranchCallback(context, BranchCallback);
}
#endif
return YES;
}

View File

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

View File

@ -32,5 +32,5 @@ MA 02110-1301, USA.
void InitOOJSSystemInfo(JSContext *context, JSObject *global);
BOOL GetJSSystemInfoForCurrentSystem(JSContext *context, jsval *outInfo);
BOOL GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID system, jsval *outInfo);
// Returns JSVAL_NULL on failure (with a JS warning, but no exception).
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)
{
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)
jsval GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID system)
{
OOJS_PROFILE_ENTER
@ -288,33 +274,28 @@ BOOL GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID
sCachedGalaxy == galaxy &&
sCachedSystem == system)
{
*outInfo = OBJECT_TO_JSVAL(sCachedSystemInfo);
return YES;
return OBJECT_TO_JSVAL(sCachedSystemInfo);
}
// If not, create a new one.
OOJSPauseTimeLimiter();
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();
if (info == nil)
{
OOReportJSError(context, @"Could not create system info object for galaxy %u, system %i.", galaxy, system);
return NO;
}
// Cache is not a root; we clear it in finalize if necessary.
sCachedSystemInfo = JSVAL_TO_OBJECT(result);
sCachedGalaxy = galaxy;
sCachedSystem = system;
if (JSVAL_IS_OBJECT(*outInfo) && !JSVAL_IS_NULL(*outInfo))
{
// 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;
return result;
OOJS_PROFILE_EXIT
OOJS_PROFILE_EXIT_JSVAL
}