406{
408
409 JSValueConst function = JS_UNDEFINED;
410 double delay;
411 double interval = -1.0;
413 JSValue callbackThis = JS_NULL;
414
416 OOJSReportError(context,
@"Timer() cannot be called as a function, it must be used as a constructor (as in new Timer(...)).");
417 return JS_EXCEPTION;
418 }
419
420 if (argc < 3) {
422 return JS_EXCEPTION;
423 }
424
426 callbackThis = JS_ToObject(context,
OOJS_ARGV[0]);
427 if (JS_IsException(callbackThis)) {
428 JS_FreeValue(context, JS_GetException(context));
430 return JS_EXCEPTION;
431 }
432 }
433
435 if (!JS_IsFunction(context, function)) {
436 JS_FreeValue(context, callbackThis);
438 return JS_EXCEPTION;
439 }
440
441 if (JS_ToFloat64(context, &delay,
OOJS_ARGV[2]) < 0 || isnan(delay)) {
442 if (JS_HasException(context))
443 JS_FreeValue(context, JS_GetException(context));
444 JS_FreeValue(context, callbackThis);
446 return JS_EXCEPTION;
447 }
448
449
450 if (3 < argc && JS_ToFloat64(context, &interval,
OOJS_ARGV[3]) < 0) {
451 JS_FreeValue(context, JS_GetException(context));
452 interval = -1;
453 }
454
455
458
459 timer = [[
OOJSTimer alloc] initWithDelay:delay
460 interval:interval
461 context:context
462 function:function
463 this:callbackThis];
464 JS_FreeValue(context, callbackThis);
467
468 if (delay >= 0)
469 {
470 [timer scheduleTimer];
471 }
472 JSValue result = [timer transferJSSelf];
473 [timer autorelease];
474 return result;
475
477}
#define OOJS_NATIVE_ENTER(cx)
void OOJSReportError(JSContext *context, NSString *format,...)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_IS_CONSTRUCTING
JSValue OOJSNativeFailure(JSContext *context)