Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOJSTimer Class Reference

#include <OOJSTimer.h>

+ Inheritance diagram for OOJSTimer:
+ Collaboration diagram for OOJSTimer:

Instance Methods

(id) - initWithDelay:interval:context:function:this: [implementation]
 
(void) - deleteJSPointers [implementation]
 
(void) - dealloc [implementation]
 
(NSString *) - descriptionComponents [implementation]
 
(NSString *) - oo_jsClassName [implementation]
 
(void) - timerFired [implementation]
 
(jsval) - oo_jsValueInContext: [implementation]
 
- Instance Methods inherited from OOScriptTimer
(id) - initWithNextTime:interval:
 
(id) - initOneShotTimerWithDelay:
 
(OOTimeAbsolute- nextTime
 
(BOOL) - setNextTime:
 
(OOTimeDelta- interval
 
(void) - setInterval:
 
(BOOL) - scheduleTimer
 
(void) - unscheduleTimer
 
(BOOL) - isScheduled
 
(BOOL) - isValidForScheduling
 
(NSComparisonResult) - compareByNextFireTime:
 

Private Attributes

jsval _function
 
JSObject * _jsThis
 
OOJSScript_owningScript
 
JSObject * _jsSelf
 

Additional Inherited Members

- Class Methods inherited from OOScriptTimer
(void) + updateTimers
 
(void) + noteGameReset
 

Detailed Description

Definition at line 33 of file OOJSTimer.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Reimplemented from OOScriptTimer.

Definition at line 444 of file OOJSTimer.m.

114{
115 [_owningScript release];
116
117 [self deleteJSPointers];
118
119 [super dealloc];
120}

References EXPECT_NOT, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, and OOScriptTimer::unscheduleTimer.

+ Here is the call graph for this function:

◆ deleteJSPointers

- (void) deleteJSPointers
implementation

Definition at line 444 of file OOJSTimer.m.

93{
94 [self unscheduleTimer];
95
96 if (_jsThis != NULL)
97 {
98 _jsThis = NULL;
99 _function = JSVAL_VOID;
100
101 JSContext *context = OOJSAcquireContext();
102 JS_RemoveObjectRoot(context, &_jsThis);
103 JS_RemoveValueRoot(context, &_function);
104 OOJSRelinquishContext(context);
105
106 [[NSNotificationCenter defaultCenter] removeObserver:self
107 name:kOOJavaScriptEngineWillResetNotification
109 }
110}
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
jsval _function
Definition OOJSTimer.h:36
JSObject * _jsThis
Definition OOJSTimer.h:37
OOJavaScriptEngine * sharedEngine()

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented from OOScriptTimer.

Definition at line 444 of file OOJSTimer.m.

124{
125 NSString *funcName = nil;
126 JSContext *context = NULL;
127
128 if (JSVAL_IS_VOID(_function) || JSVAL_IS_NULL(_function))
129 {
130 return @"invalid";
131 }
132
133 context = OOJSAcquireContext();
134 funcName = OOStringFromJSString(context, JS_GetFunctionId(JS_ValueToFunction(context, _function)));
135 OOJSRelinquishContext(context);
136
137 if (funcName == nil)
138 {
139 funcName = @"anonymous";
140 }
141
142 return [NSString stringWithFormat:@"%@, function: %@", [super descriptionComponents], funcName];
143}
NSString * OOStringFromJSString(JSContext *context, JSString *string)
return nil

◆ initWithDelay:interval:context:function:this:

- (id) initWithDelay: (OOTimeAbsolute) delay
interval: (OOTimeDelta) interval
context: (JSContext *) context
function: (jsval) function
this: (JSObject *) jsThis 
implementation

Provided by category OOJSTimer(Private).

Definition at line 444 of file OOJSTimer.m.

52 :(OOTimeAbsolute)delay
54 context:(JSContext *)context
55 function:(jsval)function
56 this:(JSObject *)jsThis
57{
58 self = [super initWithNextTime:[UNIVERSE getTime] + delay interval:interval];
59 if (self != nil)
60 {
61 NSAssert(OOJSValueIsFunction(context, function), @"Attempt to init OOJSTimer with a function that isn't.");
62
63 _jsThis = jsThis;
64 OOJSAddGCObjectRoot(context, &_jsThis, "OOJSTimer this");
65
66 _function = function;
67 OOJSAddGCValueRoot(context, &_function, "OOJSTimer function");
68
69 _jsSelf = JS_NewObject(context, &sTimerClass, sTimerPrototype, NULL);
70 if (_jsSelf != NULL)
71 {
72 if (!JS_SetPrivate(context, _jsSelf, [self retain])) _jsSelf = NULL;
73 }
74 if (_jsSelf == NULL)
75 {
76 [self release];
77 return nil;
78 }
79
81
82 [[NSNotificationCenter defaultCenter] addObserver:self
83 selector:@selector(deleteJSPointers)
84 name:kOOJavaScriptEngineWillResetNotification
86 }
87
88 return self;
89}
static JSObject * sTimerPrototype
Definition OOJSTimer.m:35
static JSClass sTimerClass
Definition OOJSTimer.m:36
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
#define OOJSAddGCObjectRoot(context, root, name)
#define OOJSAddGCValueRoot(context, root, name)
double OOTimeDelta
Definition OOTypes.h:224
double OOTimeAbsolute
Definition OOTypes.h:223
OOJSScript * currentlyRunningScript()
Definition OOJSScript.m:339
JSObject * _jsSelf
Definition OOJSTimer.h:41
OOJSScript * _owningScript
Definition OOJSTimer.h:39
OOTimeDelta interval()

◆ oo_jsClassName

- (NSString *) oo_jsClassName
implementation

Definition at line 444 of file OOJSTimer.m.

147{
148 return @"Timer";
149}

◆ oo_jsValueInContext:

- (jsval) oo_jsValueInContext: (JSContext *) context
implementation

Definition at line 444 of file OOJSTimer.m.

187 :(JSContext *)context
188{
189 return OBJECT_TO_JSVAL(_jsSelf);
190}

◆ timerFired

- (void) timerFired
implementation

Reimplemented from OOScriptTimer.

Definition at line 444 of file OOJSTimer.m.

153{
154 jsval rval = JSVAL_VOID;
155 NSString *description = nil;
156
158 JSContext *context = OOJSAcquireContext();
159
160 // stop and remove the timer if _jsThis (the first parameter in the constructor) dies.
161 id object = OOJSNativeObjectFromJSObject(context, _jsThis);
162 if (object != nil)
163 {
164 description = [object oo_jsDescription];
165 if (description == nil) description = [object description];
166 }
167
168 if (description == nil)
169 {
170 [self unscheduleTimer];
171 OOJSRelinquishContext(context);
172 return;
173 }
174
175 [OOJSScript pushScript:_owningScript];
176 [engine callJSFunction:_function
177 forObject:_jsThis
178 argc:0
179 argv:NULL
180 result:&rval];
181 [OOJSScript popScript:_owningScript];
182
183 OOJSRelinquishContext(context);
184}
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
void pushScript:(OOJSScript *script)
Definition OOJSScript.m:537
void popScript:(OOJSScript *script)
Definition OOJSScript.m:550
BOOL callJSFunction:forObject:argc:argv:result:(jsval function,[forObject] JSObject *jsThis,[argc] uintN argc,[argv] jsval *argv,[result] jsval *outResult)

Member Data Documentation

◆ _function

- (jsval) _function
private

Definition at line 36 of file OOJSTimer.h.

◆ _jsSelf

- (JSObject*) _jsSelf
private

Definition at line 41 of file OOJSTimer.h.

◆ _jsThis

- (JSObject*) _jsThis
private

Definition at line 37 of file OOJSTimer.h.

◆ _owningScript

- (OOJSScript*) _owningScript
private

Definition at line 39 of file OOJSTimer.h.


The documentation for this class was generated from the following files: