39#ifndef DEBUG_FCB_SIMPLE_TRACKING_IDS
40#define DEBUG_FCB_SIMPLE_TRACKING_IDS 0
43#ifndef DEBUG_FCB_VERBOSE_LOGGING
44#define DEBUG_FCB_VERBOSE_LOGGING 0
47#if defined(NDEBUG) && DEBUG_FCB_SIMPLE_TRACKING_IDS
48#error Deployment builds may not be built with DEBUG_FCB_SIMPLE_TRACKING_IDS.
51#if DEBUG_FCB_VERBOSE_LOGGING
53#define FCBLogIndentIf OOLogIndentIf
54#define FCBLogOutdentIf OOLogOutdentIf
59#define FCBLogIndentIf(key) \
62#define FCBLogOutdentIf(key) \
70#if DEBUG_FCB_SIMPLE_TRACKING_IDS
100static BOOL
AddCallback(JSContext* context, jsval callback, uint32 trackingID, NSString** errorString);
119#if DEBUG_FCB_SIMPLE_TRACKING_IDS
123 sNextID = [[NSDate date] timeIntervalSinceReferenceDate];
129 NSCAssert1(!
sRunning,
@"%s cannot be called while frame callbacks are running.", __PRETTY_FUNCTION__);
132 const OOTimeDelta delta = inDeltaT * [UNIVERSE timeAccelerationFactor];
134 jsval deltaVal, result;
137 if (
EXPECT(JS_NewNumberValue(context, delta, &deltaVal))) {
147 for (i = 0; i <
sCount; i++) {
149 JS_CallFunctionValue(context, NULL,
sCallbacks[i].callback, 1, &deltaVal, &result);
150 JS_ReportPendingException(context);
167 NSCAssert1(!
sRunning,
@"%s cannot be called while frame callbacks are running.", __PRETTY_FUNCTION__);
197 NSString* errorString =
nil;
204 FCBLog(
@"script.frameCallback.debug.add.deferred",
@"Deferring addition of frame callback with tracking ID %u.", trackingID);
232 FCBLog(
@"script.frameCallback.debug.remove.deferred",
@"Deferring removal of frame callback with tracking ID %u.", trackingID);
265static BOOL
AddCallback(JSContext* context, jsval callback, uint32 trackingID, NSString** errorString)
268 NSCParameterAssert(errorString != NULL);
269 NSCAssert1(!
sRunning,
@"%s cannot be called while frame callbacks are running.", __PRETTY_FUNCTION__);
276 FCBLog(
@"script.frameCallback.debug.add",
@"Adding frame callback with tracking ID %u.", trackingID);
283 *errorString =
@"Failed to add GC root for frame callback.";
299 NSCParameterAssert(errorString != NULL);
304 if (newCallbacks == NULL)
310 NSUInteger newHighWaterMark =
sCount;
312 for (i = 0; i < newHighWaterMark; i++) {
316 for (j = 0; j < i; j++) {
317 JS_RemoveValueRoot(context, &newCallbacks[j].callback);
321 *errorString =
@"Failed to add GC root for frame callback.";
324 newCallbacks[i] = oldCallbacks[i];
329 JS_RemoveValueRoot(context, &oldCallbacks[i].callback);
345 NSCParameterAssert(outIndex != NULL);
353 for (i = 0; i <
sCount; i++) {
366 NSCAssert1(!
sRunning,
@"%s cannot be called while frame callbacks are running.", __PRETTY_FUNCTION__);
368 NSUInteger index = 0;
381 NSCAssert1(!
sRunning,
@"%s cannot be called while frame callbacks are running.", __PRETTY_FUNCTION__);
383 FCBLog(
@"script.frameCallback.debug.remove",
@"Removing frame callback with tracking ID %u.",
sCallbacks[index].trackingID);
390#if DEBUG_FCB_SIMPLE_TRACKING_IDS
392 OOLog(
@"script.frameCallback.debug.reset",
@"All frame callbacks removed, resetting next ID to 1.");
400 NSCAssert1(
sRunning,
@"%s can only be called while frame callbacks are running.", __PRETTY_FUNCTION__);
404 [sDeferredOps addObject:[NSDictionary dictionaryWithObjectsAndKeys:
405 opType, @"operation",
406 [NSNumber numberWithInt:trackingID], @"trackingID",
413 NSDictionary* operation =
nil;
415 FCBLog(
@"script.frameCallback.debug.run-deferred",
@"Running %zu deferred frame callback operations.", (
long)[
sDeferredOps count]);
419 NSString* opType = [operation objectForKey:@"operation"];
420 uint32 trackingID = [operation oo_intForKey:@"trackingID"];
422 if ([opType isEqualToString:
@"add"]) {
423 OOJSValue* callbackObj = [operation objectForKey:@"value"];
424 NSString* errorString =
nil;
427 OOLogWARN(
@"script.frameCallback.deferredAdd.failed",
@"Deferred frame callback insertion failed: %@", errorString);
429 }
else if ([opType isEqualToString:
@"remove"]) {
#define OOJS_NATIVE_ENTER(cx)
#define OOJSStopTimeLimiter()
#define OOJSStartTimeLimiterWithTimeLimit(limit)
void InitOOJSFrameCallbacks(JSContext *context, JSObject *global)
static JSBool GlobalAddFrameCallback(JSContext *context, uintN argc, jsval *vp)
static void RemoveCallbackAtIndex(JSContext *context, NSUInteger index)
#define FCBLogOutdentIf(key)
static BOOL RemoveCallbackWithTrackingID(JSContext *context, uint32 trackingID)
static BOOL GetIndexForTrackingID(uint32 trackingID, NSUInteger *outIndex)
void OOJSFrameCallbacksRemoveAll(void)
static NSUInteger sHighWaterMark
static void QueueDeferredOperation(NSString *opType, uint32 trackingID, OOJSValue *value)
#define FCBLogIndentIf(key)
void OOJSFrameCallbacksInvoke(OOTimeDelta inDeltaT)
static CallbackEntry * sCallbacks
static BOOL AddCallback(JSContext *context, jsval callback, uint32 trackingID, NSString **errorString)
static JSBool GlobalRemoveFrameCallback(JSContext *context, uintN argc, jsval *vp)
static BOOL GrowCallbackList(JSContext *context, NSString **errorString)
static void RunDeferredOperations(JSContext *context)
static NSMutableArray * sDeferredOps
static JSBool GlobalIsValidFrameCallback(JSContext *context, uintN argc, jsval *vp)
void OOJSReportWarning(JSContext *context, NSString *format,...)
#define JS_IsInRequest(context)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
#define OOJS_RETURN_BOOL(v)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
OOINLINE JSContext * OOJSAcquireContext(void)
void OOJSReportError(JSContext *context, NSString *format,...)
OOINLINE void OOJSRelinquishContext(JSContext *context)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJSAddGCValueRoot(context, root, name)
#define OOJS_RETURN_INT(v)
#define OOJS_METHOD_READONLY
#define OOLogWARN(class, format,...)
#define OOLog(class, format,...)