31#define kMinInterval 0.25
36@interface OOJSTimer (Private)
40 context:(JSContext*)context
41 function:(jsval)function
42 this:(JSObject*)jsThis;
50 context:(JSContext*)context
51 function:(jsval)function
52 this:(JSObject*)jsThis
56 NSAssert(
OOJSValueIsFunction(context,
function),
@"Attempt to init OOJSTimer with a function that isn't.");
65 if (_jsSelf != NULL) {
66 if (!JS_SetPrivate(context, _jsSelf, [
self retain]))
69 if (_jsSelf == NULL) {
77 selector:@selector(deleteJSPointers)
78 name:kOOJavaScriptEngineWillResetNotification
94 JS_RemoveObjectRoot(context, &
_jsThis);
99 name:kOOJavaScriptEngineWillResetNotification
115 NSString* funcName =
nil;
116 JSContext* context = NULL;
126 if (funcName ==
nil) {
127 funcName =
@"anonymous";
140 jsval rval = JSVAL_VOID;
141 NSString* description =
nil;
149 description = [
object oo_jsDescription];
150 if (description ==
nil)
151 description = [
object description];
154 if (description ==
nil) {
171- (jsval)oo_jsValueInContext:(JSContext*)context
173 return OBJECT_TO_JSVAL(
_jsSelf);
178static JSBool
TimerGetProperty(JSContext* context, JSObject*
this, jsid propID, jsval* value);
179static JSBool
TimerSetProperty(JSContext* context, JSObject*
this, jsid propID, JSBool strict, jsval* value);
180static void TimerFinalize(JSContext* context, JSObject*
this);
181static JSBool
TimerConstruct(JSContext* context, uintN argc, jsval* vp);
184static JSBool
TimerStart(JSContext* context, uintN argc, jsval* vp);
185static JSBool
TimerStop(JSContext* context, uintN argc, jsval* vp);
199 JSCLASS_NO_OPTIONAL_MEMBERS
233static JSBool
TimerGetProperty(JSContext* context, JSObject*
this, jsid propID, jsval* value)
235 if (!JSID_IS_INT(propID))
242 if (
EXPECT_NOT(!JSTimerGetTimer(context,
this, &timer)))
245 switch (JSID_TO_INT(propID)) {
247 return JS_NewNumberValue(context, [timer nextTime], value);
250 return JS_NewNumberValue(context, [timer interval], value);
264static JSBool
TimerSetProperty(JSContext* context, JSObject*
this, jsid propID, JSBool strict, jsval* value)
266 if (!JSID_IS_INT(propID))
274 if (
EXPECT_NOT(!JSTimerGetTimer(context,
this, &timer)))
277 switch (JSID_TO_INT(propID)) {
279 if (JS_ValueToNumber(context, *value, &fValue)) {
280 if (![timer setNextTime:fValue]) {
281 OOJSReportWarning(context,
@"Ignoring attempt to change next fire time for running timer %@.", timer);
288 if (JS_ValueToNumber(context, *value, &fValue)) {
313 if ([timer isScheduled]) {
314 OOLogWARN(
@"script.javaScript.unrootedTimer",
@"Timer %@ is being garbage-collected while still running. You must keep a reference to all running timers, or they will stop unpredictably!", timer);
317 JS_SetPrivate(context,
this, NULL);
328 jsval
function = JSVAL_VOID;
330 double interval = -1.0;
332 JSObject* callbackThis = NULL;
334 if (
EXPECT_NOT(!JS_IsConstructing(context, vp))) {
335 OOJSReportError(context,
@"Timer() cannot be called as a function, it must be used as a constructor (as in new Timer(...)).");
345 if (!JS_ValueToObject(context,
OOJS_ARGV[0], &callbackThis)) {
352 if (JS_ValueToFunction(context,
function) == NULL) {
357 if (!JS_ValueToNumber(context,
OOJS_ARGV[2], &delay) || isnan(delay)) {
363 if (3 < argc && !JS_ValueToNumber(context,
OOJS_ARGV[3], &interval))
370 timer = [[
OOJSTimer alloc] initWithDelay:delay
391static JSBool
TimerStart(JSContext* context, uintN argc, jsval* vp)
406static JSBool
TimerStop(JSContext* context, uintN argc, jsval* vp)
#define OOJS_PROFILE_EXIT_VOID
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_PROFILE_ENTER
static JSBool TimerSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSObject * sTimerPrototype
static JSBool TimerGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSPropertySpec sTimerProperties[]
static JSClass sTimerClass
static JSBool TimerConstruct(JSContext *context, uintN argc, jsval *vp)
static JSBool TimerStart(JSContext *context, uintN argc, jsval *vp)
static void TimerFinalize(JSContext *context, JSObject *this)
static JSFunctionSpec sTimerMethods[]
static JSBool TimerStop(JSContext *context, uintN argc, jsval *vp)
void OOJSReportWarning(JSContext *context, NSString *format,...)
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READWRITE_CB
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
#define DEFINE_JS_OBJECT_GETTER(NAME, JSCLASS, JSPROTO, OBJCCLASSNAME)
#define OOJS_RETURN_OBJECT(o)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
#define OOJS_RETURN_BOOL(v)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
OOINLINE JSContext * OOJSAcquireContext(void)
void OOJSReportError(JSContext *context, NSString *format,...)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
#define OOJSAddGCObjectRoot(context, root, name)
OOINLINE void OOJSRelinquishContext(JSContext *context)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_PROP_READONLY_CB
#define OOJSAddGCValueRoot(context, root, name)
NSString * OOStringFromJSString(JSContext *context, JSString *string)
#define OOLogWARN(class, format,...)
static JSValue TimerStart(OOJS_NATIVE_ARGS)
static JSValue TimerGetProperty(OOJS_GETTER_ARGS)
void InitOOJSTimer(JSContext *context, JSValueConst global)
static JSValue TimerSetProperty(OOJS_SETTER_ARGS)
static JSValue TimerStop(OOJS_NATIVE_ARGS)
static void TimerFinalize(JSRuntime *runtime, JSValueConst this)
static JSValue TimerConstruct(OOJS_NATIVE_ARGS)
static JSClassDef sTimerClass
void pushScript:(OOJSScript *script)
OOJSScript * currentlyRunningScript()
void popScript:(OOJSScript *script)
NSString * descriptionComponents()
NSString * oo_jsClassName()
BOOL callJSFunction:forObject:argc:argv:result:(jsval function,[forObject] JSObject *jsThis,[argc] uintN argc,[argv] jsval *argv,[result] jsval *outResult)
OOJavaScriptEngine * sharedEngine()
void setInterval:(OOTimeDelta interval)
NSString * descriptionComponents()
id initWithNextTime:interval:(OOTimeAbsolute nextTime,[interval] OOTimeDelta interval)