Oolite 1.91.0.7668-250429-8542c40
All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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:
 
(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
 

Additional Inherited Members

- Protected Attributes inherited from OOWeakRefObject
OOWeakReferenceweakSelf
 

Detailed Description

Definition at line 30 of file OOJSPopulatorDefinition.h.

Method Documentation

◆ callback

- (jsval) callback

Definition at line 74 of file OOJSPopulatorDefinition.m.

75{
76 return _callback;
77}

References _callback, and callback.

Referenced by callback, and setCallback:.

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

◆ callbackThis

- (JSObject *) callbackThis

Definition at line 90 of file OOJSPopulatorDefinition.m.

91{
92 return _callbackThis;
93}

References _callbackThis, and callbackThis.

Referenced by callbackThis, and setCallbackThis:.

+ Here is the call graph for this function:
+ Here is the caller 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 48 of file OOJSPopulatorDefinition.m.

49{
50
51 JSContext *context = OOJSAcquireContext();
52 _callback = JSVAL_VOID;
53 _callbackThis = NULL;
54 JS_RemoveValueRoot(context, &_callback);
55 JS_RemoveObjectRoot(context, &_callbackThis);
56
57 OOJSRelinquishContext(context);
58
59 [[NSNotificationCenter defaultCenter] removeObserver:self
60 name:kOOJavaScriptEngineWillResetNotification
62
63}
OOINLINE JSContext * OOJSAcquireContext(void)
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.

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

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:

- (void) runCallback: (HPVector) location

Definition at line 106 of file OOJSPopulatorDefinition.m.

106 :(HPVector)location
107{
108 OOJavaScriptEngine *engine = [OOJavaScriptEngine sharedEngine];
109 JSContext *context = OOJSAcquireContext();
110 jsval loc, rval = JSVAL_VOID;
111
112 VectorToJSValue(context, HPVectorToVector(location), &loc);
113
114 OOJSScript *owner = [_owningScript retain]; // local copy needed
115 [OOJSScript pushScript:owner];
116
117 [engine callJSFunction:_callback
118 forObject:_callbackThis
119 argc:1
120 argv:&loc
121 result:&rval];
122
123 [OOJSScript popScript:owner];
124 [owner release];
125
126 OOJSRelinquishContext(context);
127}
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:185
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)

References OOJavaScriptEngine::callJSFunction:forObject:argc:argv:result:, 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:

◆ setCallback:

- (void) setCallback: (jsval) callback

Definition at line 80 of file OOJSPopulatorDefinition.m.

80 :(jsval)callback
81{
82 JSContext *context = OOJSAcquireContext();
83 JS_RemoveValueRoot(context, &_callback);
85 OOJSAddGCValueRoot(context, &_callback, "OOJSPopulatorDefinition callback function");
86 OOJSRelinquishContext(context);
87}
#define OOJSAddGCValueRoot(context, root, name)

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

Referenced by SystemSetPopulator().

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

◆ setCallbackThis:

- (void) setCallbackThis: (JSObject *) callbackthis

Definition at line 96 of file OOJSPopulatorDefinition.m.

96 :(JSObject *)callbackThis
97{
98 JSContext *context = OOJSAcquireContext();
99 JS_RemoveObjectRoot(context, &_callbackThis);
101 OOJSAddGCObjectRoot(context, &_callbackThis, "OOJSPopulatorDefinition callback this");
102 OOJSRelinquishContext(context);
103}
#define OOJSAddGCObjectRoot(context, root, name)

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

+ Here is the call graph for this function:

Member Data Documentation

◆ _callback

- (jsval) _callback
private

Definition at line 33 of file OOJSPopulatorDefinition.h.

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

◆ _callbackThis

- (JSObject*) _callbackThis
private

Definition at line 34 of file OOJSPopulatorDefinition.h.

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

◆ _owningScript

- (OOJSScript*) _owningScript
private

Definition at line 35 of file OOJSPopulatorDefinition.h.

Referenced by init.


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