Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOJSMission.h File Reference
import <Foundation/Foundation.h>
#include <jsapi.h>
+ Include dependency graph for OOJSMission.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void InitOOJSMission (JSContext *context, JSObject *global)
 
void MissionRunCallback (void)
 

Function Documentation

◆ InitOOJSMission()

void InitOOJSMission ( JSContext * context,
JSObject * global )

Definition at line 108 of file OOJSMission.m.

109{
110 sCallbackFunction = JSVAL_NULL;
111 sCallbackThis = JSVAL_NULL;
112
113 JSObject *missionPrototype = JS_InitClass(context, global, NULL, &sMissionClass, OOJSUnconstructableConstruct, 0, sMissionProperties, sMissionMethods, NULL, NULL);
114 sMissionObject = JS_DefineObject(context, global, "mission", &sMissionClass, missionPrototype, OOJS_PROP_READONLY);
115
116 // Ensure JS objects are rooted.
117 OOJSAddGCValueRoot(context, &sCallbackFunction, "Pending mission callback function");
118 OOJSAddGCValueRoot(context, &sCallbackThis, "Pending mission callback this");
119}
static jsval sCallbackThis
Definition OOJSMission.m:55
static JSFunctionSpec sMissionMethods[]
Definition OOJSMission.m:94
static JSClass sMissionClass
Definition OOJSMission.m:60
static jsval sCallbackFunction
Definition OOJSMission.m:54
static JSPropertySpec sMissionProperties[]
Definition OOJSMission.m:84
static JSObject * sMissionObject
Definition OOJSMission.m:58
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
#define OOJSAddGCValueRoot(context, root, name)

References OOJS_PROP_READONLY, OOJSAddGCValueRoot, OOJSUnconstructableConstruct(), sCallbackFunction, sCallbackThis, sMissionClass, sMissionMethods, sMissionObject, and sMissionProperties.

+ Here is the call graph for this function:

◆ MissionRunCallback()

void MissionRunCallback ( void )

Definition at line 122 of file OOJSMission.m.

123{
124 // don't do anything if we don't have a function.
125 if (JSVAL_IS_NULL(sCallbackFunction) || JSVAL_IS_VOID(sCallbackFunction)) return;
126
127 jsval argval = JSVAL_VOID;
128 jsval argval2 = JSVAL_VOID;
129 jsval rval = JSVAL_VOID;
131 OOJavaScriptEngine *engine = [OOJavaScriptEngine sharedEngine];
132 JSContext *context = OOJSAcquireContext();
133
134 /* Create temporarily-rooted local copies of sCallbackFunction and
135 sCallbackThis, then clear the statics. This must be done in advance
136 since the callback might call runScreen() and clobber the statics.
137 */
138 jsval cbFunction = JSVAL_VOID;
139 JSObject *cbThis = NULL;
140 OOJSScript *cbScript = sCallbackScript;
141
142 OOJSAddGCValueRoot(context, &cbFunction, "Mission callback function");
143 OOJSAddGCObjectRoot(context, &cbThis, "Mission callback this");
144 cbFunction = sCallbackFunction;
145 cbScript = sCallbackScript;
146 JS_ValueToObject(context, sCallbackThis, &cbThis);
147
149 sCallbackFunction = JSVAL_NULL;
150 sCallbackThis = JSVAL_NULL;
151
152 jsval args[2];
153 argval = OOJSValueFromNativeObject(context, [player missionChoice_string]);
154 argval2 = OOJSValueFromNativeObject(context, [player missionKeyPress_string]);
155 args[0] = argval;
156 args[1] = argval2;
157
158 // now reset the mission choice silently, before calling the callback script.
159 [player setMissionChoice:nil keyPress:@"" withEvent:NO];
160
161 // Call the callback.
162 @try
163 {
164 [OOJSScript pushScript:cbScript];
165 [engine callJSFunction:cbFunction
166 forObject:cbThis
167 argc:2
168 argv:args
169 result:&rval];
170 }
171 @catch (NSException *exception)
172 {
173 // Squash any exception, allow cleanup to happen and so forth.
174 OOLog(kOOLogException, @"Ignoring exception %@:%@ during handling of mission screen completion callback.", [exception name], [exception reason]);
175 }
176 [OOJSScript popScript:cbScript];
177
178 // Manage that memory.
179 [cbScript release];
180 JS_RemoveValueRoot(context, &cbFunction);
181 JS_RemoveObjectRoot(context, &cbThis);
182
183 OOJSRelinquishContext(context);
184}
static OOJSScript * sCallbackScript
Definition OOJSMission.m:56
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:191
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
OOINLINE JSContext * OOJSAcquireContext(void)
#define OOJSAddGCObjectRoot(context, root, name)
OOINLINE void OOJSRelinquishContext(JSContext *context)
NSString *const kOOLogException
Definition OOLogging.m:651
#define OOLog(class, format,...)
Definition OOLogging.h:88
return nil

References OOJavaScriptEngine::callJSFunction:forObject:argc:argv:result:, kOOLogException, nil, OOJSAcquireContext(), OOJSAddGCObjectRoot, OOJSAddGCValueRoot, OOJSRelinquishContext(), OOJSValueFromNativeObject(), OOLog, OOPlayerForScripting(), OOJSScript::popScript:, OOJSScript::pushScript:, sCallbackFunction, sCallbackScript, sCallbackThis, PlayerEntity::setMissionChoice:keyPress:withEvent:, and OOJavaScriptEngine::sharedEngine.

+ Here is the call graph for this function: