Oolite 1.91.0.7658-250404-b1488af
All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
OOJSScript Class Reference

#include <OOJSScript.h>

+ Inheritance diagram for OOJSScript:
+ Collaboration diagram for OOJSScript:

Instance Methods

(id) - initWithPath:properties:
 
(BOOL) - callMethod:inContext:withArguments:count:result:
 
(id) - propertyWithID:inContext:
 
(BOOL) - setProperty:withID:inContext:
 
(BOOL) - defineProperty:withID:inContext:
 
(id) - propertyNamed:
 
(BOOL) - setProperty:named:
 
(BOOL) - defineProperty:named:
 
(void) - dealloc [implementation]
 
(NSString *) - oo_jsClassName [implementation]
 
(NSString *) - descriptionComponents [implementation]
 
(void) - javaScriptEngineWillReset: [implementation]
 
(id) - weakRetain [implementation]
 
(void) - weakRefDied: [implementation]
 
(NSString *) - scriptDescription [implementation]
 
(void) - runWithTarget: [implementation]
 
(jsval) - oo_jsValueInContext: [implementation]
 
(NSString *) - scriptNameFromPath: [implementation]
 
(NSDictionary *) - defaultPropertiesFromPath: [implementation]
 
- Instance Methods inherited from OOScript
(NSString *) - name
 
(NSString *) - version
 
(NSString *) - displayName
 
(BOOL) - requiresTickle
 
- Instance Methods inherited from <OOWeakReferenceSupport>
(id) - OO_RETURNS_RETAINED
 

Class Methods

(id) + scriptWithPath:properties:
 
(OOJSScript *) + currentlyRunningScript
 
(NSArray *) + scriptStack
 
(void) + pushScript:
 
(void) + popScript:
 
- Class Methods inherited from OOScript
(NSArray *) + worldScriptsAtPath:
 
(NSArray *) + scriptsFromFileNamed:
 
(NSArray *) + scriptsFromList:
 
(NSArray *) + scriptsFromFileAtPath:
 
(id) + jsScriptFromFileNamed:properties:
 
(id) + jsAIScriptFromFileNamed:properties:
 

Private Attributes

JSObject * _jsSelf
 
NSString * name
 
NSString * description
 
NSString * version
 
NSString * filePath
 
OOWeakReferenceweakSelf
 

Detailed Description

Definition at line 31 of file OOJSScript.h.

Method Documentation

◆ callMethod:inContext:withArguments:count:result:

- (BOOL) callMethod: (jsid) methodID
inContext: (JSContext *) context
withArguments: (jsval *) argv
count: (intN) argc
result: (jsval *) outResult 

Reimplemented from OOScript.

Definition at line 395 of file OOJSScript.m.

395 :(jsid)methodID
396 inContext:(JSContext *)context
397 withArguments:(jsval *)argv count:(intN)argc
398 result:(jsval *)outResult
399{
400 NSParameterAssert(name != NULL && (argv != NULL || argc == 0) && context != NULL && JS_IsInRequest(context));
401 if (_jsSelf == NULL) return NO;
402
403 JSObject *root = NULL;
404 BOOL OK = NO;
405 jsval method;
406 jsval ignoredResult = JSVAL_VOID;
407
408 if (outResult == NULL) outResult = &ignoredResult;
409 OOJSAddGCObjectRoot(context, &root, "OOJSScript method root");
410
411 if (EXPECT(JS_GetMethodById(context, _jsSelf, methodID, &root, &method) && !JSVAL_IS_VOID(method)))
412 {
413#ifndef NDEBUG
414 if (JS_IsExceptionPending(context))
415 {
416 OOLog(@"script.internalBug", @"Exception pending on context before calling method in %s, clearing. This is an internal error, please report it.", __PRETTY_FUNCTION__);
417 JS_ClearPendingException(context);
418 }
419
420 OOLog(@"script.javaScript.call", @"Calling [%@].%@()", [self name], OOStringFromJSID(methodID));
421 OOLogIndentIf(@"script.javaScript.call");
422#endif
423
424 // Push self on stack of running scripts.
425 RunningStack stackElement =
426 {
427 .back = sRunningStack,
428 .current = self
429 };
430 sRunningStack = &stackElement;
431
432 // Call the method.
434 OK = JS_CallFunctionValue(context, _jsSelf, method, argc, argv, outResult);
436
437 if (JS_IsExceptionPending(context))
438 {
439 JS_ReportPendingException(context);
440 OK = NO;
441 }
442
443 // Pop running scripts stack
444 sRunningStack = stackElement.back;
445
446#ifndef NDEBUG
447 OOLogOutdentIf(@"script.javaScript.call");
448#endif
449 }
450
451 JS_RemoveObjectRoot(context, &root);
452
453 return OK;
454}
#define EXPECT(x)
#define OOJSStopTimeLimiter()
#define OOJSStartTimeLimiter()
static RunningStack * sRunningStack
Definition OOJSScript.m:60
struct RunningStack RunningStack
Definition OOJSScript.m:51
#define JS_IsInRequest(context)
NSString * OOStringFromJSID(jsid propID)
#define OOJSAddGCObjectRoot(context, root, name)
#define OOLogOutdentIf(class)
Definition OOLogging.h:102
#define OOLog(class, format,...)
Definition OOLogging.h:88
#define OOLogIndentIf(class)
Definition OOLogging.h:101
unsigned count
JSObject * _jsSelf
Definition OOJSScript.h:35
NSString * name
Definition OOJSScript.m:369
RunningStack * back
Definition OOJSScript.m:54
OOJSScript * current
Definition OOJSScript.m:55

References _jsSelf, RunningStack::back, EXPECT, JS_IsInRequest, name, OOJSAddGCObjectRoot, OOJSStartTimeLimiter, OOJSStopTimeLimiter, OOLog, OOLogIndentIf, OOLogOutdentIf, OOStringFromJSID(), and sRunningStack.

Referenced by StationEntity::acceptDockingClearanceRequestFrom:, PlayerEntity::activatePrimableEquipment:withMode:, PlayerEntity::adjustPriceByScriptForEqKey:withCurrent:, DockEntity::allowsLaunchingOf:, ShipEntity::behaviour_scripted_ai:, DockEntity::canAcceptShipForDocking:, Universe::canInstantiateShip:, StationEntity::dockingInstructionsForShip:, OOCharacter::doScriptEvent:, OOVisualEffectEntity::doScriptEvent:, ShipEntity::doScriptEvent:inContext:withArguments:count:, ShipEntity::equipmentValidToAdd:whileLoading:inContext:, OOShipRegistry(OODataLoader)::loadDemoShips, OODebugMonitor::performJSConsoleCommand:, and Universe::shipsForSaleForSystem:withTL:atTime:.

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

◆ currentlyRunningScript

+ (OOJSScript *) currentlyRunningScript

Definition at line 339 of file OOJSScript.m.

340{
341 if (sRunningStack == NULL) return NULL;
342 return sRunningStack->current;
343}

References currentlyRunningScript, and sRunningStack.

Referenced by currentlyRunningScript, OOJSGuiScreenKeyDefinition::init, OOJSInterfaceDefinition::init, OOJSPopulatorDefinition::init, OOJSTimer(Private)::initWithDelay:interval:context:function:this:, OODebugMonitor(Private)::jsEngine:context:error:stackSkip:showingLocation:withMessage:, MissionRunScreen(), MissionSetInstructionsInternal(), ReportJSError(), OOSystemInfo::setValue:forKey:, SystemInfoSetPropertyMethod(), SystemInfoStaticSetInterstellarProperty(), and SystemSetProperty().

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

◆ dealloc

- (void) dealloc
implementation

Definition at line 286 of file OOJSScript.m.

287{
288 [[NSNotificationCenter defaultCenter] removeObserver:self
289 name:kOOJavaScriptEngineWillResetNotification
291
292 DESTROY(name);
296
297 if (_jsSelf != NULL)
298 {
299 JSContext *context = OOJSAcquireContext();
300
301 OOJSObjectWrapperFinalize(context, _jsSelf); // Release weakref to self
302 JS_RemoveObjectRoot(context, &_jsSelf); // Unroot jsSelf
303
304 OOJSRelinquishContext(context);
305 }
306
307 [weakSelf weakRefDrop];
308
309 [super dealloc];
310}
#define DESTROY(x)
Definition OOCocoa.h:77
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
NSString * version
Definition OOJSScript.m:383
NSString * description
Definition OOJSScript.h:38
NSString * filePath
Definition OOJSScript.h:40
OOJavaScriptEngine * sharedEngine()

References _jsSelf, dealloc, description, DESTROY, filePath, name, OOJSAcquireContext(), OOJSObjectWrapperFinalize(), OOJSRelinquishContext(), OOJavaScriptEngine::sharedEngine, version, and OOWeakReference::weakRefDrop.

Referenced by dealloc.

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

◆ defaultPropertiesFromPath:

- (NSDictionary *) defaultPropertiesFromPath: (NSString *) path
implementation

Provided by category OOJSScript(OOPrivate).

Definition at line 616 of file OOJSScript.m.

616 :(NSString *)path
617{
618 // remove file name, remove OXP subfolder, add manifest.plist
619 NSString *manifestPath = [[[path stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"manifest.plist"];
620 NSDictionary *manifest = OODictionaryFromFile(manifestPath);
621 NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithCapacity:3];
622 /* __oolite.tmp.* is allocated for OXPs without manifests. Its
623 * values are meaningless and shouldn't be used here */
624 if (manifest != nil && ![[manifest oo_stringForKey:kOOManifestIdentifier] hasPrefix:@"__oolite.tmp."])
625 {
626 if ([manifest objectForKey:kOOManifestVersion] != nil)
627 {
628 [properties setObject:[manifest oo_stringForKey:kOOManifestVersion] forKey:@"version"];
629 }
630 if ([manifest objectForKey:kOOManifestIdentifier] != nil)
631 {
632 // used for system info
633 [properties setObject:[manifest oo_stringForKey:kOOManifestIdentifier] forKey:kLocalManifestProperty];
634 }
635 if ([manifest objectForKey:kOOManifestAuthor] != nil)
636 {
637 [properties setObject:[manifest oo_stringForKey:kOOManifestAuthor] forKey:@"author"];
638 }
639 if ([manifest objectForKey:kOOManifestLicense] != nil)
640 {
641 [properties setObject:[manifest oo_stringForKey:kOOManifestLicense] forKey:@"license"];
642 }
643 }
644 return properties;
645}
static NSString *const kOOManifestLicense
static NSString *const kOOManifestIdentifier
static NSString *const kOOManifestVersion
static NSString *const kOOManifestAuthor
NSDictionary * OODictionaryFromFile(NSString *path)
return nil

Referenced by initWithPath:properties:.

+ Here is the caller graph for this function:

◆ defineProperty:named:

- (BOOL) defineProperty: (id) value
named: (NSString *) name 

Definition at line 517 of file OOJSScript.m.

517 :(id)value named:(NSString *)propName
518{
519 if (value == nil || propName == nil) return NO;
520 if (_jsSelf == NULL) return NO;
521
522 JSContext *context = OOJSAcquireContext();
523 BOOL result = [self defineProperty:value withID:OOJSIDFromString(propName) inContext:context];
524 OOJSRelinquishContext(context);
525
526 return result;
527}

References _jsSelf, defineProperty:withID:inContext:, nil, OOJSAcquireContext(), and OOJSRelinquishContext().

Referenced by initWithPath:properties:.

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

◆ defineProperty:withID:inContext:

- (BOOL) defineProperty: (id) value
withID: (jsid) propID
inContext: (JSContext *) context 

Definition at line 481 of file OOJSScript.m.

481 :(id)value withID:(jsid)propID inContext:(JSContext *)context
482{
483 NSParameterAssert(context != NULL && JS_IsInRequest(context));
484 if (_jsSelf == NULL) return NO;
485
486 jsval jsValue = OOJSValueFromNativeObject(context, value);
487 return JS_DefinePropertyById(context, _jsSelf, propID, jsValue, NULL, NULL, OOJS_PROP_READONLY);
488}
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
#define OOJS_PROP_READONLY

References _jsSelf, JS_IsInRequest, OOJS_PROP_READONLY, and OOJSValueFromNativeObject().

Referenced by defineProperty:named:.

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

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented from OOScript.

Definition at line 319 of file OOJSScript.m.

320{
321 if (_jsSelf != NULL) return [super descriptionComponents];
322 else return @"invalid script";
323}

References _jsSelf, descriptionComponents, and OOScript::descriptionComponents.

Referenced by descriptionComponents.

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

◆ initWithPath:properties:

- (id) initWithPath: (NSString *) path
properties: (NSDictionary *) properties 

Definition at line 118 of file OOJSScript.m.

118 :(NSString *)path properties:(NSDictionary *)properties
119{
120 JSContext *context = NULL;
121 NSString *problem = nil; // Acts as error flag.
122 JSScript *script = NULL;
123 JSObject *scriptObject = NULL;
124 jsval returnValue = JSVAL_VOID;
125 NSEnumerator *keyEnum = nil;
126 NSString *key = nil;
127 id property = nil;
128
129 self = [super init];
130 if (self == nil) problem = @"allocation failure";
131 else
132 {
133 context = OOJSAcquireContext();
134
135 if (JS_IsExceptionPending(context))
136 {
137 JS_ClearPendingException(context);
138 OOLogERR(@"script.javaScript.load.waitingException", @"Prior to loading script %@, there was a pending JavaScript exception, which has been cleared. This is an internal error, please report it.", path);
139 }
140
141 // Set up JS object
142 if (!problem)
143 {
144 _jsSelf = JS_NewObject(context, &sScriptClass, sScriptPrototype, NULL);
145 if (_jsSelf == NULL) problem = @"allocation failure";
146 }
147
148 if (!problem && !OOJSAddGCObjectRoot(context, &_jsSelf, "Script object"))
149 {
150 problem = @"could not add JavaScript root object";
151 }
152
153 if (!problem && !OOJSAddGCObjectRoot(context, &scriptObject, "Script GC holder"))
154 {
155 problem = @"could not add JavaScript root object";
156 }
157
158 if (!problem)
159 {
160 if (!JS_SetPrivate(context, _jsSelf, OOConsumeReference([self weakRetain])))
161 {
162 problem = @"could not set private backreference";
163 }
164 }
165
166 // Push self on stack of running scripts.
167 RunningStack stackElement =
168 {
169 .back = sRunningStack,
170 .current = self
171 };
172 sRunningStack = &stackElement;
173
174 filePath = [path retain];
175
176 if (!problem)
177 {
178 OOLog(@"script.javaScript.willLoad", @"About to load JavaScript %@", path);
179 script = LoadScriptWithName(context, path, _jsSelf, &scriptObject, &problem);
180 }
181 OOLogIndentIf(@"script.javaScript.willLoad");
182
183 // Set default properties from manifest.plist
184 NSDictionary *defaultProperties = [self defaultPropertiesFromPath:path];
185 for (keyEnum = [defaultProperties keyEnumerator]; (key = [keyEnum nextObject]); )
186 {
187 if ([key isKindOfClass:[NSString class]])
188 {
189 property = [defaultProperties objectForKey:key];
190 if ([key isEqualToString:kLocalManifestProperty])
191 {
192 // this must not be editable
193 [self defineProperty:property named:key];
194 }
195 else
196 {
197 // can be overwritten by script itself
198 [self setProperty:property named:key];
199 }
200 }
201 }
202
203 // Set properties. (read-only)
204 if (!problem && properties != nil)
205 {
206 for (keyEnum = [properties keyEnumerator]; (key = [keyEnum nextObject]); )
207 {
208 if ([key isKindOfClass:[NSString class]])
209 {
210 property = [properties objectForKey:key];
211 [self defineProperty:property named:key];
212 }
213 }
214 }
215
216 /* Set initial name (in case of script error during initial run).
217 The "name" ivar is not set here, so the property can be fetched from JS
218 if we fail during setup. However, the "name" ivar is set later so that
219 the script object can't be renamed after the initial run. This could
220 probably also be achieved by fiddling with JS property attributes.
221 */
222 jsid nameID = OOJSID("name");
223 [self setProperty:[self scriptNameFromPath:path] withID:nameID inContext:context];
224
225 // Run the script (allowing it to set up the properties we need, as well as setting up those event handlers)
226 if (!problem)
227 {
229 if (!JS_ExecuteScript(context, _jsSelf, script, &returnValue))
230 {
231 problem = @"could not run script";
232 }
234
235 // We don't need the script any more - the event handlers hang around as long as the JS object exists.
236 JS_DestroyScript(context, script);
237 }
238
239 JS_RemoveObjectRoot(context, &scriptObject);
240
241 sRunningStack = stackElement.back;
242
243 if (!problem)
244 {
245 // Get display attributes from script
246 DESTROY(name);
247 name = [StrippedName([[self propertyWithID:nameID inContext:context] description]) copy];
248 if (name == nil)
249 {
250 name = [[self scriptNameFromPath:path] retain];
251 [self setProperty:name withID:nameID inContext:context];
252 }
253
254 version = [[[self propertyWithID:OOJSID("version") inContext:context] description] copy];
255 description = [[[self propertyWithID:OOJSID("description") inContext:context] description] copy];
256
257 OOLog(@"script.javaScript.load.success", @"Loaded JavaScript: %@ -- %@", [self displayName], description ? description : (NSString *)@"(no description)");
258 }
259
260 OOLogOutdentIf(@"script.javaScript.willLoad");
261
262 DESTROY(filePath); // Only used for error reporting during startup.
263 }
264
265 if (problem)
266 {
267 OOLog(@"script.javaScript.load.failed", @"***** Error loading JavaScript script %@ -- %@", path, problem);
268 JS_ReportPendingException(context);
269 DESTROY(self);
270 }
271
272 OOJSRelinquishContext(context);
273
274 if (self != nil)
275 {
276 [[NSNotificationCenter defaultCenter] addObserver:self
277 selector:@selector(javaScriptEngineWillReset:)
278 name:kOOJavaScriptEngineWillResetNotification
280 }
281
282 return self;
283}
id OOConsumeReference(id OO_NS_CONSUMED value)
Definition OOCocoa.m:93
#define kOOJSLongTimeLimit
#define OOJSStartTimeLimiterWithTimeLimit(limit)
#define OOJSID(str)
Definition OOJSPropID.h:38
static NSString *const kLocalManifestProperty
Definition OOJSScript.h:29
static JSObject * sScriptPrototype
Definition OOJSScript.m:59
static JSClass sScriptClass
Definition OOJSScript.m:78
static JSScript * LoadScriptWithName(JSContext *context, NSString *path, JSObject *object, JSObject **outScriptObject, NSString **outErrorMessage)
Definition OOJSScript.m:698
#define OOLogERR(class, format,...)
Definition OOLogging.h:112
NSString * displayName()
Definition OOScript.m:277

References _jsSelf, RunningStack::back, defaultPropertiesFromPath:, defineProperty:named:, description, DESTROY, OOScript::displayName, filePath, kLocalManifestProperty, kOOJSLongTimeLimit, LoadScriptWithName(), name, nil, OOConsumeReference(), OOJSAcquireContext(), OOJSAddGCObjectRoot, OOJSID, OOJSRelinquishContext(), OOJSStartTimeLimiterWithTimeLimit, OOJSStopTimeLimiter, OOLog, OOLogERR, OOLogIndentIf, OOLogOutdentIf, propertyWithID:inContext:, scriptNameFromPath:, setProperty:named:, setProperty:withID:inContext:, OOJavaScriptEngine::sharedEngine, sRunningStack, sScriptClass, sScriptPrototype, version, and weakRetain.

+ Here is the call graph for this function:

◆ javaScriptEngineWillReset:

- (void) javaScriptEngineWillReset: (NSNotification *) notification
implementation

Definition at line 326 of file OOJSScript.m.

326 :(NSNotification *)notification
327{
328 // All scripts become invalid when the JS engine resets.
329 if (_jsSelf != NULL)
330 {
331 _jsSelf = NULL;
332 JSContext *context = OOJSAcquireContext();
333 JS_RemoveObjectRoot(context, &_jsSelf);
334 OOJSRelinquishContext(context);
335 }
336}

References _jsSelf, OOJSAcquireContext(), and OOJSRelinquishContext().

+ Here is the call graph for this function:

◆ oo_jsClassName

- (NSString *) oo_jsClassName
implementation

Definition at line 313 of file OOJSScript.m.

314{
315 return @"Script";
316}

References oo_jsClassName.

Referenced by oo_jsClassName.

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

◆ oo_jsValueInContext:

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

Definition at line 530 of file OOJSScript.m.

530 :(JSContext *)context
531{
532 if (_jsSelf == NULL) return JSVAL_VOID;
533 return OBJECT_TO_JSVAL(_jsSelf);
534}

References _jsSelf.

◆ popScript:

+ (void) popScript: (OOJSScript *) script

Definition at line 550 of file OOJSScript.m.

550 :(OOJSScript *)script
551{
552 RunningStack *element = NULL;
553
554 assert(sRunningStack->current == script);
555
556 element = sRunningStack;
558 free(element);
559}

References sRunningStack.

Referenced by OOJSFunction::evaluateWithContext:scope:argc:argv:result:, MissionRunCallback(), OOJSGuiScreenKeyDefinition::runCallback:, OOJSInterfaceDefinition::runCallback:, OOJSPopulatorDefinition::runCallback:, and OOJSTimer::timerFired.

+ Here is the caller graph for this function:

◆ propertyNamed:

- (id) propertyNamed: (NSString *) name

Definition at line 491 of file OOJSScript.m.

491 :(NSString *)propName
492{
493 if (propName == nil) return nil;
494 if (_jsSelf == NULL) return nil;
495
496 JSContext *context = OOJSAcquireContext();
497 id result = [self propertyWithID:OOJSIDFromString(propName) inContext:context];
498 OOJSRelinquishContext(context);
499
500 return result;
501}

References _jsSelf, nil, OOJSAcquireContext(), OOJSRelinquishContext(), and propertyWithID:inContext:.

Referenced by OOSystemInfo::setValue:forKey:, SystemInfoSetPropertyMethod(), SystemInfoStaticSetInterstellarProperty(), and SystemSetProperty().

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

◆ propertyWithID:inContext:

- (id) propertyWithID: (jsid) propID
inContext: (JSContext *) context 

Definition at line 457 of file OOJSScript.m.

457 :(jsid)propID inContext:(JSContext *)context
458{
459 NSParameterAssert(context != NULL && JS_IsInRequest(context));
460 if (_jsSelf == NULL) return nil;
461
462 jsval jsValue = JSVAL_VOID;
463 if (JS_GetPropertyById(context, _jsSelf, propID, &jsValue))
464 {
465 return OOJSNativeObjectFromJSValue(context, jsValue);
466 }
467 return nil;
468}
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)

References _jsSelf, JS_IsInRequest, nil, and OOJSNativeObjectFromJSValue().

Referenced by initWithPath:properties:, and propertyNamed:.

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

◆ pushScript:

+ (void) pushScript: (OOJSScript *) script

Definition at line 537 of file OOJSScript.m.

537 :(OOJSScript *)script
538{
539 RunningStack *element = NULL;
540
541 element = malloc(sizeof *element);
542 if (element == NULL) exit(EXIT_FAILURE);
543
544 element->back = sRunningStack;
545 element->current = script;
546 sRunningStack = element;
547}

References RunningStack::back, RunningStack::current, and sRunningStack.

Referenced by OOJSFunction::evaluateWithContext:scope:argc:argv:result:, MissionRunCallback(), OOJSGuiScreenKeyDefinition::runCallback:, OOJSInterfaceDefinition::runCallback:, OOJSPopulatorDefinition::runCallback:, and OOJSTimer::timerFired.

+ Here is the caller graph for this function:

◆ runWithTarget:

- (void) runWithTarget: (Entity *) target
implementation

Reimplemented from OOScript.

Definition at line 389 of file OOJSScript.m.

389 :(Entity *)target
390{
391
392}

◆ scriptDescription

- (NSString *) scriptDescription
implementation

Reimplemented from OOScript.

Definition at line 377 of file OOJSScript.m.

378{
379 return description;
380}

References description, and scriptDescription.

Referenced by scriptDescription.

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

◆ scriptNameFromPath:

- (NSString *) scriptNameFromPath: (NSString *) path
implementation

Provided by category OOJSScript(OOPrivate).

Definition at line 582 of file OOJSScript.m.

582 :(NSString *)path
583{
584 NSString *lastComponent = nil;
585 NSString *truncatedPath = nil;
586 NSString *theName = nil;
587
588 if (path == nil) theName = [NSString stringWithFormat:@"%p", self];
589 else
590 {
591 lastComponent = [path lastPathComponent];
592 if (![lastComponent hasPrefix:@"script."]) theName = lastComponent;
593 else
594 {
595 truncatedPath = [path stringByDeletingLastPathComponent];
596 if (NSOrderedSame == [[truncatedPath lastPathComponent] caseInsensitiveCompare:@"Config"])
597 {
598 truncatedPath = [truncatedPath stringByDeletingLastPathComponent];
599 }
600 if (NSOrderedSame == [[truncatedPath pathExtension] caseInsensitiveCompare:@"oxp"])
601 {
602 truncatedPath = [truncatedPath stringByDeletingPathExtension];
603 }
604
605 lastComponent = [truncatedPath lastPathComponent];
606 theName = lastComponent;
607 }
608 }
609
610 if (0 == [theName length]) theName = path;
611
612 return StrippedName([theName stringByAppendingString:@".anon-script"]);
613}
static NSString * StrippedName(NSString *string)
Definition OOJSScript.m:817

Referenced by initWithPath:properties:.

+ Here is the caller graph for this function:

◆ scriptStack

+ (NSArray *) scriptStack

Definition at line 346 of file OOJSScript.m.

347{
348 NSMutableArray *result = nil;
349
350 result = [NSMutableArray array];
352 return result;
353}
static void AddStackToArrayReversed(NSMutableArray *array, RunningStack *stack)
Definition OOJSScript.m:688

References AddStackToArrayReversed(), nil, scriptStack, and sRunningStack.

Referenced by scriptStack.

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

◆ scriptWithPath:properties:

+ (id) scriptWithPath: (NSString *) path
properties: (NSDictionary *) properties 

Definition at line 112 of file OOJSScript.m.

112 :(NSString *)path properties:(NSDictionary *)properties
113{
114 return [[[self alloc] initWithPath:path properties:properties] autorelease];
115}

Referenced by OOScript::jsAIScriptFromFileNamed:properties:, OOScript::jsScriptFromFileNamed:properties:, OOCheckJSSyntaxVerifierStage::run, OOScript::scriptsFromFileAtPath:, OODebugMonitor(Private)::setUpDebugConsoleScript, and OOScript::worldScriptsAtPath:.

+ Here is the caller graph for this function:

◆ setProperty:named:

- (BOOL) setProperty: (id) value
named: (NSString *) name 

Definition at line 504 of file OOJSScript.m.

504 :(id)value named:(NSString *)propName
505{
506 if (value == nil || propName == nil) return NO;
507 if (_jsSelf == NULL) return NO;
508
509 JSContext *context = OOJSAcquireContext();
510 BOOL result = [self setProperty:value withID:OOJSIDFromString(propName) inContext:context];
511 OOJSRelinquishContext(context);
512
513 return result;
514}

References _jsSelf, nil, OOJSAcquireContext(), OOJSRelinquishContext(), and setProperty:withID:inContext:.

Referenced by initWithPath:properties:.

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

◆ setProperty:withID:inContext:

- (BOOL) setProperty: (id) value
withID: (jsid) propID
inContext: (JSContext *) context 

Definition at line 471 of file OOJSScript.m.

471 :(id)value withID:(jsid)propID inContext:(JSContext *)context
472{
473 NSParameterAssert(context != NULL && JS_IsInRequest(context));
474 if (_jsSelf == NULL) return NO;
475
476 jsval jsValue = OOJSValueFromNativeObject(context, value);
477 return JS_SetPropertyById(context, _jsSelf, propID, &jsValue);
478}

References _jsSelf, JS_IsInRequest, and OOJSValueFromNativeObject().

Referenced by initWithPath:properties:, and setProperty:named:.

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

◆ weakRefDied:

- (void) weakRefDied: (OOWeakReference *) weakRef
implementation

Reimplemented from <OOWeakReferenceSupport>.

Definition at line 363 of file OOJSScript.m.

363 :(OOWeakReference *)weakRef
364{
365 if (weakRef == weakSelf) weakSelf = nil;
366}
OOWeakReference * weakSelf
Definition OOJSScript.h:42

References nil, and weakSelf.

◆ weakRetain

- (id) weakRetain
implementation

Definition at line 356 of file OOJSScript.m.

357{
359 return [weakSelf retain];
360}
id weakRefWithObject:(id< OOWeakReferenceSupport > object)

References nil, OOWeakReference::weakRefWithObject:, weakRetain, and weakSelf.

Referenced by OOJSGuiScreenKeyDefinition::init, OOJSInterfaceDefinition::init, OOJSPopulatorDefinition::init, OOJSTimer(Private)::initWithDelay:interval:context:function:this:, initWithPath:properties:, OODebugMonitor(Private)::jsEngine:context:error:stackSkip:showingLocation:withMessage:, ReportJSError(), and weakRetain.

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

Member Data Documentation

◆ _jsSelf

◆ description

- (NSString*) description
private

Definition at line 38 of file OOJSScript.h.

Referenced by dealloc, initWithPath:properties:, and scriptDescription.

◆ filePath

- (NSString*) filePath
private

Definition at line 40 of file OOJSScript.h.

Referenced by dealloc, and initWithPath:properties:.

◆ name

- (NSString *) name
private

Definition at line 369 of file OOJSScript.m.

370{
371 if (name == nil) name = [[self propertyNamed:@"name"] copy];
372 if (name == nil) return [self scriptNameFromPath:filePath]; // Special case for parse errors during load.
373 return name;
374}
return self

Referenced by callMethod:inContext:withArguments:count:result:, dealloc, initWithPath:properties:, MissionSetInstructionsInternal(), and OOShipDebugInspectorModule::update.

◆ version

- (NSString *) version
private

Definition at line 383 of file OOJSScript.m.

384{
385 return version;
386}

Referenced by dealloc, and initWithPath:properties:.

◆ weakSelf

- (OOWeakReference*) weakSelf
private

Definition at line 42 of file OOJSScript.h.

Referenced by weakRefDied:, and weakRetain.


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