diff --git a/src/Core/Debug/OOJSConsole.m b/src/Core/Debug/OOJSConsole.m index 84be14d4..0d8184b8 100644 --- a/src/Core/Debug/OOJSConsole.m +++ b/src/Core/Debug/OOJSConsole.m @@ -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 } diff --git a/src/Core/Scripting/OOJSEngineTimeManagement.m b/src/Core/Scripting/OOJSEngineTimeManagement.m index 80bcf684..69484f49 100644 --- a/src/Core/Scripting/OOJSEngineTimeManagement.m +++ b/src/Core/Scripting/OOJSEngineTimeManagement.m @@ -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; } diff --git a/src/Core/Scripting/OOJSSystem.m b/src/Core/Scripting/OOJSSystem.m index 6b2c30d3..92536725 100644 --- a/src/Core/Scripting/OOJSSystem.m +++ b/src/Core/Scripting/OOJSSystem.m @@ -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 } diff --git a/src/Core/Scripting/OOJSSystemInfo.h b/src/Core/Scripting/OOJSSystemInfo.h index 9c288a01..b7a00a25 100644 --- a/src/Core/Scripting/OOJSSystemInfo.h +++ b/src/Core/Scripting/OOJSSystemInfo.h @@ -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); diff --git a/src/Core/Scripting/OOJSSystemInfo.m b/src/Core/Scripting/OOJSSystemInfo.m index f9ba5d89..2d4f909a 100644 --- a/src/Core/Scripting/OOJSSystemInfo.m +++ b/src/Core/Scripting/OOJSSystemInfo.m @@ -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 }