Oolite
Loading...
Searching...
No Matches
OOJSPopulatorDefinition Class Reference

#include <OOJSPopulatorDefinition.h>

Inheritance diagram for OOJSPopulatorDefinition:
Collaboration diagram for OOJSPopulatorDefinition:

Instance Methods

(jsval) - callback
(void) - setCallback:
(JSObject *) - callbackThis
(void) - setCallbackThis:
(void) - runCallback:
(JSValue) - callback
(void) - setCallback:
(JSValue) - callbackThis
(void) - setCallbackThis:
(void) - runCallback:
(id) - init [implementation]
(void) - deleteJSPointers [implementation]
(void) - dealloc [implementation]
Instance Methods inherited from OOWeakRefObject
(id) - weakSelf
(id) - weakRetain [implementation]
(void) - weakRefDied: [implementation]
Instance Methods inherited from <OOWeakReferenceSupport>
(id) - OO_RETURNS_RETAINED

Private Attributes

jsval _callback
JSObject * _callbackThis
OOJSScript * _owningScript
JSValue _callback
JSValue _callbackThis

Additional Inherited Members

Protected Attributes inherited from OOWeakRefObject
OOWeakReference * weakSelf

Detailed Description

Definition at line 30 of file OOJSPopulatorDefinition.h.

Method Documentation

◆ callback [1/2]

- (JSValue) callback

Definition at line 73 of file OOJSPopulatorDefinition.m.

74{
75 return JS_DupValue(OOJSAcquireContext(), _callback);
76}
OOINLINE JSContext * OOJSAcquireContext(void)

References _callback, callback, and OOJSAcquireContext().

Referenced by callback, runCallback:, and setCallback:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback [2/2]

- (JSValue) callback

References callback.

Here is the call graph for this function:

◆ callbackThis [1/2]

- (JSValue) callbackThis

Definition at line 87 of file OOJSPopulatorDefinition.m.

88{
89 return JS_DupValue(OOJSAcquireContext(), _callbackThis);
90}

References _callbackThis, callbackThis, and OOJSAcquireContext().

Referenced by callbackThis, runCallback:, and setCallbackThis:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ callbackThis [2/2]

- (JSValue) callbackThis

References callbackThis.

Here is the call graph for this function:

◆ dealloc

- (void) dealloc
implementation

Reimplemented from OOWeakRefObject.

Definition at line 65 of file OOJSPopulatorDefinition.m.

66{
67 [_owningScript release];
68
69 [self deleteJSPointers];
70
71 [super dealloc];
72}

References dealloc, OOWeakRefObject::dealloc, and deleteJSPointers.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteJSPointers

- (void) deleteJSPointers
implementation

Definition at line 49 of file OOJSPopulatorDefinition.m.

50{
51
52 JSContext* context = OOJSAcquireContext();
53 _callback = JSVAL_VOID;
54 _callbackThis = NULL;
55 JS_RemoveValueRoot(context, &_callback);
56 JS_RemoveObjectRoot(context, &_callbackThis);
57
58 OOJSRelinquishContext(context);
59
60 [[NSNotificationCenter defaultCenter] removeObserver:self
61 name:kOOJavaScriptEngineWillResetNotification
63}
OOINLINE void OOJSRelinquishContext(JSContext *context)
OOJavaScriptEngine * sharedEngine()

References _callback, _callbackThis, deleteJSPointers, OOJSAcquireContext(), OOJSRelinquishContext(), and OOJavaScriptEngine::sharedEngine.

Referenced by dealloc, and deleteJSPointers.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init

- (id) init
implementation

Definition at line 33 of file OOJSPopulatorDefinition.m.

34{
35 self = [super init];
36 _callback = JSVAL_VOID;
37 _callbackThis = NULL;
38
40
41 [[NSNotificationCenter defaultCenter] addObserver:self
42 selector:@selector(deleteJSPointers)
43 name:kOOJavaScriptEngineWillResetNotification
45
46 return self;
47}
OOJSScript * currentlyRunningScript()
Definition OOJSScript.m:101

References _callback, _callbackThis, _owningScript, OOJSScript::currentlyRunningScript, init, OOJavaScriptEngine::sharedEngine, and OOJSScript::weakRetain.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ runCallback: [1/2]

- (void) runCallback: (HPVector) location

Definition at line 101 of file OOJSPopulatorDefinition.m.

101 :(HPVector)location
102{
103 OOJavaScriptEngine* engine = [OOJavaScriptEngine sharedEngine];
104 JSContext* context = OOJSAcquireContext();
105 JSValue rval = JS_UNDEFINED;
106
107 if (!JS_IsFunction(context, _callback)) {
108 // The callback was released by an engine reset.
109 OOJSRelinquishContext(context);
110 return;
111 }
112
113 JSValue loc = JS_UNDEFINED;
114 VectorToJSValue(context, HPVectorToVector(location), &loc);
115
116 OOJSScript* owner = [_owningScript retain]; // local copy needed
117 [OOJSScript pushScript:owner];
118
119 // Hold our own references in case the callback replaces them.
120 JSValue callback = JS_DupValue(context, _callback);
121 JSValue callbackThis = JS_IsObject(_callbackThis) ? JS_DupValue(context, _callbackThis) : JS_UNDEFINED;
122 [engine callJSFunction:callback
123 forObject:callbackThis
124 argc:1
125 argv:&loc
126 result:&rval];
127 JS_FreeValue(context, callback);
128 JS_FreeValue(context, callbackThis);
129
130 [OOJSScript popScript:owner];
131 [owner release];
132
133 JS_FreeValue(context, rval);
134 JS_FreeValue(context, loc);
135 OOJSRelinquishContext(context);
136}
struct HPVector HPVector
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
Definition OOHPVector.h:175
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:264
void pushScript:(OOJSScript *script)
Definition OOJSScript.m:480
void popScript:(OOJSScript *script)
Definition OOJSScript.m:493
BOOL callJSFunction:forObject:argc:argv:result:(jsval function,[forObject] JSObject *jsThis,[argc] uintN argc,[argv] jsval *argv,[result] jsval *outResult)

References _callback, _callbackThis, callback, callbackThis, OOJavaScriptEngine::callJSFunction:forObject:argc:argv:result:, HPVectorToVector(), OOJSAcquireContext(), OOJSRelinquishContext(), OOJSScript::popScript:, OOJSScript::pushScript:, OOJavaScriptEngine::sharedEngine, and VectorToJSValue().

Referenced by Universe::populateSystemFromDictionariesWithSun:andPlanet:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ runCallback: [2/2]

- (void) runCallback: (HPVector) location

◆ setCallback: [1/2]

- (void) setCallback: (jsval) callback

Definition at line 78 of file OOJSPopulatorDefinition.m.

78 :(JSValueConst)callback
79{
80 JSContext* context = OOJSAcquireContext();
81 JSValue old = _callback;
82 _callback = JS_DupValue(context, callback);
83 JS_FreeValue(context, old);
84 OOJSRelinquishContext(context);
85}

References _callback, callback, OOJSAcquireContext(), and OOJSRelinquishContext().

Referenced by SystemSetPopulator(), and SystemSetPopulator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCallback: [2/2]

- (void) setCallback: (JSValueConst) callback

Definition at line 78 of file OOJSPopulatorDefinition.m.

78 :(JSValueConst)callback
79{
80 JSContext* context = OOJSAcquireContext();
81 JSValue old = _callback;
82 _callback = JS_DupValue(context, callback);
83 JS_FreeValue(context, old);
84 OOJSRelinquishContext(context);
85}

◆ setCallbackThis: [1/2]

- (void) setCallbackThis: (JSObject*) callbackthis

Definition at line 92 of file OOJSPopulatorDefinition.m.

92 :(JSValueConst)callbackThis
93{
94 JSContext* context = OOJSAcquireContext();
95 JSValue old = _callbackThis;
96 _callbackThis = JS_DupValue(context, callbackThis);
97 JS_FreeValue(context, old);
98 OOJSRelinquishContext(context);
99}

References _callbackThis, callbackThis, OOJSAcquireContext(), and OOJSRelinquishContext().

Here is the call graph for this function:

◆ setCallbackThis: [2/2]

- (void) setCallbackThis: (JSValueConst) callbackthis

Definition at line 92 of file OOJSPopulatorDefinition.m.

92 :(JSValueConst)callbackThis
93{
94 JSContext* context = OOJSAcquireContext();
95 JSValue old = _callbackThis;
96 _callbackThis = JS_DupValue(context, callbackThis);
97 JS_FreeValue(context, old);
98 OOJSRelinquishContext(context);
99}

Member Data Documentation

◆ _callback [1/2]

- (jsval) _callback
private

Definition at line 32 of file OOJSPopulatorDefinition.h.

Referenced by callback, deleteJSPointers, init, runCallback:, and setCallback:.

◆ _callback [2/2]

- (JSValue) _callback
private

Definition at line 35 of file OOJSPopulatorDefinition.h.

◆ _callbackThis [1/2]

- (JSObject*) _callbackThis
private

Definition at line 33 of file OOJSPopulatorDefinition.h.

Referenced by callbackThis, deleteJSPointers, init, runCallback:, and setCallbackThis:.

◆ _callbackThis [2/2]

- (JSValue) _callbackThis
private

Definition at line 36 of file OOJSPopulatorDefinition.h.

◆ _owningScript

- (OOJSScript *) _owningScript
private

Definition at line 34 of file OOJSPopulatorDefinition.h.

Referenced by init.


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