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

#include <OOJavaScriptEngine.h>

Inheritance diagram for OOJavaScriptEngine:
Collaboration diagram for OOJavaScriptEngine:

Instance Methods

(JSObject *) - globalObject
(void) - runMissionCallback
(BOOL) - reset
(BOOL) - callJSFunction:forObject:argc:argv:result:
(void) - removeGCObjectRoot:
(void) - removeGCValueRoot:
(void) - garbageCollectionOpportunity:
(BOOL) - showErrorLocations
(void) - setShowErrorLocations:
(JSClass *) - objectClass
(JSClass *) - stringClass
(JSClass *) - arrayClass
(JSClass *) - numberClass
(JSClass *) - booleanClass
(JSContext *) - context
(JSValueConst) - globalObject
(void) - runMissionCallback
(BOOL) - reset
(BOOL) - callJSFunction:forObject:argc:argv:result:
(void) - garbageCollectionOpportunity:
(BOOL) - showErrorLocations
(void) - setShowErrorLocations:
(NSUInteger) - shutDown
(id) - init [implementation]
(void) - createMainThreadContext [implementation]
(void) - destroyMainThreadContext [implementation]
(void) - dealloc [implementation]
(BOOL) - lookUpStandardClassPointers [implementation]
(void) - registerStandardObjectConverters [implementation]
(void) - watchdogTimerThread [implementation]

Class Methods

(OOJavaScriptEngine *) + sharedEngine
(OOJavaScriptEngine *) + sharedEngine
(static BOOL) + IsRunningJavaScript [implementation]

Private Attributes

JSRuntime * _runtime
JSObject * _globalObject
BOOL _showErrorLocations
JSClass * _objectClass
JSClass * _stringClass
JSClass * _arrayClass
JSClass * _numberClass
JSClass * _booleanClass
JSContext * _context
JSValue _globalObject

Detailed Description

Definition at line 39 of file OOJavaScriptEngine.h.

Method Documentation

◆ arrayClass

- (JSClass *) arrayClass

Definition at line 535 of file OOJavaScriptEngine.m.

536{
537 return _arrayClass;
538}

References _arrayClass, and arrayClass.

Referenced by arrayClass.

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

◆ booleanClass

- (JSClass *) booleanClass

Definition at line 545 of file OOJavaScriptEngine.m.

546{
547 return _booleanClass;
548}

References _booleanClass, and booleanClass.

Referenced by booleanClass.

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

◆ callJSFunction:forObject:argc:argv:result: [1/2]

- (BOOL) callJSFunction: (jsval) function
forObject: (JSObject*) jsThis
argc: (uintN) argc
argv: (jsval*) argv
result: (jsval*) outResult 

Definition at line 153 of file OOJavaScriptEnginePoc.m.

153 :(JSValueConst)function
154 forObject:(JSValueConst)jsThis
155 argc:(int)argc
156 argv:(JSValueConst*)argv
157 result:(JSValue*)outResult
158{
159 NSParameterAssert(JS_IsFunction(_context, function));
160
162 JSValue result = JS_Call(_context, function, jsThis, argc, argv);
164
165 if (JS_IsException(result)) {
167 if (outResult != NULL)
168 *outResult = JS_UNDEFINED;
169 return NO;
170 }
171
172 if (outResult != NULL)
173 *outResult = result;
174 else
175 JS_FreeValue(_context, result);
176 return YES;
177}
void OOJSReportPendingException(JSContext *context)
#define OOJSStartTimeLimiter()
void OOJSStopTimeLimiter(void)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

References _context, OOJSReportPendingException(), OOJSStartTimeLimiter, and OOJSStopTimeLimiter().

Referenced by OOJSScript::callMethodNamed:withArguments:count:result:, MissionRunCallback(), MissionRunCallback(), OOJSGuiScreenKeyDefinition::runCallback:, OOJSInterfaceDefinition::runCallback:, OOJSPopulatorDefinition::runCallback:, and OOJSTimer::timerFired.

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

◆ callJSFunction:forObject:argc:argv:result: [2/2]

- (BOOL) callJSFunction: (JSValueConst) function
forObject: (JSValueConst) jsThis
argc: (int) argc
argv: (JSValueConst*) argv
result: (JSValue*) outResult 

Definition at line 369 of file OOJavaScriptEngine.m.

369 :(JSValueConst)function
370 forObject:(JSValueConst)jsThis
371 argc:(int)argc
372 argv:(JSValueConst*)argv
373 result:(JSValue*)outResult
374{
375 NSParameterAssert(JS_IsFunction(_context, function));
376
378 JSValue result = JS_Call(_context, function, jsThis, argc, argv);
380
381 if (JS_IsException(result)) {
383 if (outResult != NULL)
384 *outResult = JS_UNDEFINED;
385 return NO;
386 }
387
388 if (outResult != NULL)
389 *outResult = result;
390 else
391 JS_FreeValue(_context, result);
392 return YES;
393}

References _context, OOJSReportPendingException(), OOJSStartTimeLimiter, and OOJSStopTimeLimiter.

Here is the call graph for this function:

◆ context

- (JSContext *) context

Definition at line 143 of file OOJavaScriptEnginePoc.m.

144{
145 return _context;
146}

References _context, and context.

Referenced by context, GlobalLog(), IsRunningJavaScript, OOJSNativeFailure(), removeGCObjectRoot:, removeGCValueRoot:, and sharedEngine.

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

◆ createMainThreadContext

- (void) createMainThreadContext
implementation

Provided by category OOJavaScriptEngine(Private).

Definition at line 291 of file OOJavaScriptEngine.m.

292{
293 NSAssert(gOOJSMainThreadContext == NULL, @"-[OOJavaScriptEngine createMainThreadContext] called while the main thread context exists.");
294
295 // create a context and associate it with the JS runtime.
297
298 // if context creation failed, end the program here.
299 if (gOOJSMainThreadContext == NULL) {
300 OOLog(@"script.javaScript.init.error", @"%@", @"***** FATAL ERROR: failed to create JavaScript context.");
301 exit(1);
302 }
303
305
308
309#if JS_GC_ZEAL
310 uint8_t gcZeal = [[NSUserDefaults standardUserDefaults] oo_unsignedCharForKey:@"js-gc-zeal"];
311 if (gcZeal > 0) {
312 // Useful js-gc-zeal values are 0 (off), 1 and 2.
313 OOLog(@"script.javaScript.debug.gcZeal", @"Setting JavaScript garbage collector zeal to %u.", gcZeal);
314 JS_SetGCZeal(gOOJSMainThreadContext, gcZeal);
315 }
316#endif
317
318 JS_SetErrorReporter(gOOJSMainThreadContext, ReportJSError);
319
320 // Create the global object.
322
323 // Initialize the built-in JS objects and the global object.
324 JS_InitStandardClasses(gOOJSMainThreadContext, _globalObject);
325 if (![self lookUpStandardClassPointers]) {
326 OOLog(@"script.javaScript.init.error", @"%@", @"***** FATAL ERROR: failed to look up standard JavaScript classes.");
327 exit(1);
328 }
329 [self registerStandardObjectConverters];
330
333
334 // Initialize Oolite classes.
367
368 // Run prefix scripts.
369 [OOJSScript jsScriptFromFileNamed:@"oolite-global-prefix.js"
370 properties:[NSDictionary dictionaryWithObject:JSSpecialFunctionsObjectWrapper(gOOJSMainThreadContext)
371 forKey:@"special"]];
372
374
375 OOLog(@"script.javaScript.init.success", @"%@", @"Set up JavaScript context.");
376}
void OOConstToJSStringInit(JSContext *context)
void InitOOJSClock(JSContext *context, JSObject *global)
Definition OOJSClock.m:100
void InitOOJSDock(JSContext *context, JSObject *global)
Definition OOJSDock.m:82
void InitOOJSEntity(JSContext *context, JSObject *global)
Definition OOJSEntity.m:127
void InitOOJSEquipmentInfo(JSContext *context, JSObject *global)
void InitOOJSExhaustPlume(JSContext *context, JSObject *global)
void InitOOJSFlasher(JSContext *context, JSObject *global)
Definition OOJSFlasher.m:85
void InitOOJSFont(JSContext *context, JSObject *global)
Definition OOJSFont.m:36
void InitOOJSFrameCallbacks(JSContext *context, JSObject *global)
void CreateOOJSGlobal(JSContext *context, JSObject **outGlobal)
Definition OOJSGlobal.m:151
void SetUpOOJSGlobal(JSContext *context, JSObject *global)
Definition OOJSGlobal.m:161
void InitOOJSManifest(JSContext *context, JSObject *global)
void InitOOJSMissionVariables(JSContext *context, JSObject *global)
void InitOOJSMission(JSContext *context, JSObject *global)
void InitOOJSOolite(JSContext *context, JSObject *global)
Definition OOJSOolite.m:100
void InitOOJSPlanet(JSContext *context, JSObject *global)
Definition OOJSPlanet.m:87
void InitOOJSPlayerShip(JSContext *context, JSObject *global)
void InitOOJSPlayer(JSContext *context, JSObject *global)
Definition OOJSPlayer.m:151
void InitOOJSQuaternion(JSContext *context, JSObject *global)
void InitOOJSScript(JSContext *context, JSObject *global)
Definition OOJSScript.m:614
void InitOOJSShipGroup(JSContext *context, JSObject *global)
void InitOOJSShip(JSContext *context, JSObject *global)
Definition OOJSShip.m:575
void InitOOJSSoundSource(JSContext *context, JSObject *global)
void InitOOJSSound(JSContext *context, JSObject *global)
Definition OOJSSound.m:108
void InitOOJSSpecialFunctions(JSContext *context, JSObject *global)
void InitOOJSStation(JSContext *context, JSObject *global)
void InitOOJSSun(JSContext *context, JSObject *global)
Definition OOJSSun.m:79
void InitOOJSSystemInfo(JSContext *context, JSObject *global)
void InitOOJSSystem(JSContext *context, JSObject *global)
Definition OOJSSystem.m:214
void InitOOJSTimer(JSContext *context, JSObject *global)
Definition OOJSTimer.m:227
void InitOOJSVector(JSContext *context, JSObject *global)
Definition OOJSVector.m:231
void InitOOJSVisualEffect(JSContext *context, JSObject *global)
void InitOOJSWaypoint(JSContext *context, JSObject *global)
void InitOOJSWorldScripts(JSContext *context, JSObject *global)
void InitOOJSWormhole(JSContext *context, JSObject *global)
#define JS_BeginRequest(context)
#define JS_EndRequest(context)
#define OOJSENGINE_JSVERSION
static void ReportJSError(JSContext *context, const char *message, JSErrorReport *report)
#define OOJSENGINE_CONTEXT_OPTIONS
JSContext * gOOJSMainThreadContext
#define OOJS_STACK_SIZE
#define OOLog(class, format,...)
Definition OOLogging.h:84
id jsScriptFromFileNamed:properties:(NSString *fileName,[properties] NSDictionary *properties)
Definition OOScript.m:177

References OOJavaScriptEngine(Private)::createMainThreadContext, CreateOOJSGlobal(), gOOJSMainThreadContext, InitOOJSClock(), InitOOJSDock(), InitOOJSEntity(), InitOOJSEquipmentInfo(), InitOOJSExhaustPlume(), InitOOJSFlasher(), InitOOJSFont(), InitOOJSFrameCallbacks(), InitOOJSManifest(), InitOOJSMission(), InitOOJSMissionVariables(), InitOOJSOolite(), InitOOJSPlanet(), InitOOJSPlayer(), InitOOJSPlayerShip(), InitOOJSQuaternion(), InitOOJSScript(), InitOOJSShip(), InitOOJSShipGroup(), InitOOJSSound(), InitOOJSSoundSource(), InitOOJSSpecialFunctions(), InitOOJSStation(), InitOOJSSun(), InitOOJSSystem(), InitOOJSSystemInfo(), InitOOJSTimer(), InitOOJSVector(), InitOOJSVisualEffect(), InitOOJSWaypoint(), InitOOJSWorldScripts(), InitOOJSWormhole(), JS_BeginRequest, JS_EndRequest, OOScript::jsScriptFromFileNamed:properties:, OOJavaScriptEngine(Private)::lookUpStandardClassPointers, OOConstToJSStringInit(), OOJS_STACK_SIZE, OOJSENGINE_CONTEXT_OPTIONS, OOJSENGINE_JSVERSION, OOLog, registerStandardObjectConverters, ReportJSError(), and SetUpOOJSGlobal().

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext, init, and reset.

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

◆ dealloc

- (void) dealloc
implementation

Definition at line 450 of file OOJavaScriptEngine.m.

451{
453
455
456 [self destroyMainThreadContext];
457 JS_DestroyRuntime(_runtime);
458
459 [super dealloc];
460}
void OOJSFrameCallbacksRemoveAll(void)
static OOJavaScriptEngine * sSharedEngine
return nil

References _runtime, dealloc, destroyMainThreadContext, nil, OOJSFrameCallbacksRemoveAll(), and sSharedEngine.

Referenced by dealloc.

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

◆ destroyMainThreadContext

- (void) destroyMainThreadContext
implementation

Provided by category OOJavaScriptEngine(Private).

Definition at line 378 of file OOJavaScriptEngine.m.

379{
380 if (gOOJSMainThreadContext != NULL) {
381 JSContext* context = OOJSAcquireContext();
383
384 _globalObject = NULL;
385 _objectClass = NULL;
386 _stringClass = NULL;
387 _arrayClass = NULL;
388 _numberClass = NULL;
389 _booleanClass = NULL;
390
394
396
397 _globalObject = NULL;
398 JS_DestroyContext(gOOJSMainThreadContext); // Forces unconditional GC.
400 }
401}
void OOConstToJSStringDestroy(void)
static void UnregisterSubclasses(void)
static void UnregisterObjectConverters(void)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)

References OOJavaScriptEngine(Private)::destroyMainThreadContext, gOOJSMainThreadContext, OOConstToJSStringDestroy(), OOJSAcquireContext(), OOJSRelinquishContext(), UnregisterObjectConverters(), and UnregisterSubclasses().

Referenced by dealloc, OOJavaScriptEngine(Private)::destroyMainThreadContext, and reset.

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

◆ garbageCollectionOpportunity: [1/2]

- (void) garbageCollectionOpportunity: (BOOL) force

Definition at line 395 of file OOJavaScriptEngine.m.

395 :(BOOL)force
396{
397 /* Reference counting frees most objects immediately, and QuickJS runs its
398 cycle collector by allocation threshold, so only forced collections
399 need doing here.
400 */
401 if (force)
402 JS_RunGC(_runtime);
403}

References _runtime.

Referenced by PlayerEntity::docked, PlayerEntity::leaveWitchspace, PlayerEntity(LoadSave)::loadPlayerFromFile:asNew:, reset, and Universe::update:.

Here is the caller graph for this function:

◆ garbageCollectionOpportunity: [2/2]

- (void) garbageCollectionOpportunity: (BOOL) force

◆ globalObject [1/2]

- (JSValueConst) globalObject

Definition at line 148 of file OOJavaScriptEnginePoc.m.

149{
150 return _globalObject;
151}

References _globalObject, and globalObject.

Referenced by globalObject, and OOStringFromDeciCredits().

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

◆ globalObject [2/2]

- (JSValueConst) globalObject

References globalObject.

Here is the call graph for this function:

◆ init

- (id) init
implementation

Definition at line 250 of file OOJavaScriptEngine.m.

251{
252 NSAssert(sSharedEngine == nil, @"Attempt to create multiple OOJavaScriptEngines.");
253
254 if (!(self = [super init]))
255 return nil;
256 sSharedEngine = self;
257
258 JS_SetCStringsAreUTF8();
259
260 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
261#ifdef OO_DEBUG_MONITOR_ENABLED
262 /* Set stack trace preferences from preferences. These will be overriden
263 by the debug OXP script if installed, but being able to enable traces
264 without setting up the debug console could be useful for debugging
265 users' problems.
266 */
267 [self setDumpStackForErrors:[defaults boolForKey:@"dump-stack-for-errors"]];
268 [self setDumpStackForWarnings:[defaults boolForKey:@"dump-stack-for-warnings"]];
269#endif
270
271 assert(sizeof(jschar) == sizeof(unichar));
272
273 // initialize the JS run time, and return result in runtime.
274 uint32_t jsRuntimeInMiB = [defaults oo_intForKey:@"jsruntime-size-mib" defaultValue:OOJS_RUNTIME_SIZE_MiB];
275 _runtime = JS_NewRuntime(jsRuntimeInMiB * 1024L * 1024L);
276
277 // if runtime creation failed, end the program here.
278 if (_runtime == NULL) {
279 OOLog(@"script.javaScript.init.error", @"***** FATAL ERROR: failed to create JavaScript runtime with size %uMiB.", jsRuntimeInMiB);
280 exit(1);
281 }
282
283 // OOJSTimeManagementInit() must be called before any context is created!
285
286 [self createMainThreadContext];
287
288 return self;
289}
void OOJSTimeManagementInit(OOJavaScriptEngine *engine, JSRuntime *runtime)

References _runtime, createMainThreadContext, init, nil, OOJSTimeManagementInit(), OOLog, and sSharedEngine.

Referenced by init.

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

◆ IsRunningJavaScript

+ (BOOL) IsRunningJavaScript (JSContext *) context
implementation

Definition at line 301 of file OOJavaScriptEngine.m.

302{
303 if (context == NULL)
304 return NO;
305 for (int level = 0; level < 16; level++) {
306 JSAtom name = JS_GetScriptOrModuleName(context, level);
307 if (name != JS_ATOM_NULL) {
308 JS_FreeAtom(context, name);
309 return YES;
310 }
311 }
312 return NO;
313}

References context.

Here is the call graph for this function:

◆ lookUpStandardClassPointers

- (BOOL) lookUpStandardClassPointers
implementation

Provided by category OOJavaScriptEngine(Private).

Definition at line 550 of file OOJavaScriptEngine.m.

551{
552 JSObject* templateObject = NULL;
553
554 templateObject = JS_NewObject(gOOJSMainThreadContext, NULL, NULL, NULL);
555 if (EXPECT_NOT(templateObject == NULL))
556 return NO;
558
559 if (EXPECT_NOT(!JS_ValueToObject(gOOJSMainThreadContext, JS_GetEmptyStringValue(gOOJSMainThreadContext), &templateObject)))
560 return NO;
562
563 templateObject = JS_NewArrayObject(gOOJSMainThreadContext, 0, NULL);
564 if (EXPECT_NOT(templateObject == NULL))
565 return NO;
567
568 if (EXPECT_NOT(!JS_ValueToObject(gOOJSMainThreadContext, INT_TO_JSVAL(0), &templateObject)))
569 return NO;
571
572 if (EXPECT_NOT(!JS_ValueToObject(gOOJSMainThreadContext, JSVAL_FALSE, &templateObject)))
573 return NO;
575
576 return YES;
577}
#define EXPECT_NOT(x)
OOINLINE JSClass * OOJSGetClass(JSContext *cx, JSObject *obj) ALWAYS_INLINE_FUNC

References EXPECT_NOT, gOOJSMainThreadContext, OOJavaScriptEngine(Private)::lookUpStandardClassPointers, and OOJSGetClass().

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext, and OOJavaScriptEngine(Private)::lookUpStandardClassPointers.

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

◆ numberClass

- (JSClass *) numberClass

Definition at line 540 of file OOJavaScriptEngine.m.

541{
542 return _numberClass;
543}

References _numberClass, and numberClass.

Referenced by numberClass.

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

◆ objectClass

- (JSClass *) objectClass

Definition at line 525 of file OOJavaScriptEngine.m.

526{
527 return _objectClass;
528}

References _objectClass, and objectClass.

Referenced by objectClass.

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

◆ registerStandardObjectConverters

- (void) registerStandardObjectConverters
implementation

Provided by category OOJavaScriptEngine(Private).

Definition at line 579 of file OOJavaScriptEngine.m.

580{
586}
static id JSNumberConverter(JSContext *context, JSObject *object)
static id JSStringConverter(JSContext *context, JSObject *object)
static id JSArrayConverter(JSContext *context, JSObject *object)
static id JSBooleanConverter(JSContext *context, JSObject *object)
void OOJSRegisterObjectConverter(JSClassID classID, OOJSClassConverterCallback converter)
id(* OOJSClassConverterCallback)(JSContext *context, JSValueConst object)
NSDictionary * OOJSDictionaryFromJSObject(JSContext *context, JSValueConst object)

References JSArrayConverter(), JSBooleanConverter(), JSNumberConverter(), JSStringConverter(), OOJSDictionaryFromJSObject(), OOJSRegisterObjectConverter(), and OOJavaScriptEngine(Private)::registerStandardObjectConverters.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext, and OOJavaScriptEngine(Private)::registerStandardObjectConverters.

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

◆ removeGCObjectRoot:

- (void) removeGCObjectRoot: (JSObject**) rootPtr

Definition at line 490 of file OOJavaScriptEngine.m.

490 :(JSObject**)rootPtr
491{
492 JSContext* context = OOJSAcquireContext();
493 JS_RemoveObjectRoot(context, rootPtr);
495}

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

Here is the call graph for this function:

◆ removeGCValueRoot:

- (void) removeGCValueRoot: (jsval*) rootPtr

Definition at line 497 of file OOJavaScriptEngine.m.

497 :(jsval*)rootPtr
498{
499 JSContext* context = OOJSAcquireContext();
500 JS_RemoveValueRoot(context, rootPtr);
502}

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

Here is the call graph for this function:

◆ reset [1/2]

- (BOOL) reset

Definition at line 282 of file OOJavaScriptEngine.m.

283{
284 NSAssert(gOOJSMainThreadContext != NULL, @"JavaScript engine not active. Can't reset.");
285
287
288 [[NSNotificationCenter defaultCenter] postNotificationName:kOOJavaScriptEngineWillResetNotification object:self];
289
290 [self destroyMainThreadContext];
291 [self createMainThreadContext];
292
293 [[NSNotificationCenter defaultCenter] postNotificationName:kOOJavaScriptEngineDidResetNotification object:self];
294
295 [self garbageCollectionOpportunity:YES];
296 OOLog(@"script.javascript.init", @"%@", @"JavaScript reset successful.");
297 return YES;
298}

References createMainThreadContext, destroyMainThreadContext, garbageCollectionOpportunity:, gOOJSMainThreadContext, OOJSFrameCallbacksRemoveAll(), OOLog, and reset.

Referenced by reset.

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

◆ reset [2/2]

- (BOOL) reset

References reset.

Here is the call graph for this function:

◆ runMissionCallback [1/2]

- (void) runMissionCallback

Definition at line 141 of file OOJavaScriptEngine.m.

142{
144}
void MissionRunCallback(void)

References MissionRunCallback(), and runMissionCallback.

Referenced by PlayerEntity(Scripting)::doMissionCallback, and runMissionCallback.

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

◆ runMissionCallback [2/2]

- (void) runMissionCallback

References runMissionCallback.

Here is the call graph for this function:

◆ setShowErrorLocations: [1/2]

- (void) setShowErrorLocations: (BOOL) value

Definition at line 184 of file OOJavaScriptEnginePoc.m.

184 :(BOOL)value
185{
186 _showErrorLocations = !!value;
187}

References _showErrorLocations.

Referenced by OOCheckJSSyntaxVerifierStage::run.

Here is the caller graph for this function:

◆ setShowErrorLocations: [2/2]

- (void) setShowErrorLocations: (BOOL) value

References shutDown.

Here is the call graph for this function:

◆ sharedEngine [1/2]

+ (OOJavaScriptEngine *) sharedEngine

Definition at line 56 of file OOJavaScriptEnginePoc.m.

57{
58 if (sSharedEngine == nil)
59 sSharedEngine = [[self alloc] init];
60
61 return sSharedEngine;
62}

References nil, sharedEngine, and sSharedEngine.

Referenced by OOJSScript::callMethodNamed:withArguments:count:result:, OOJSScript::dealloc, OOJSGuiScreenKeyDefinition::deleteJSPointers, OOJSInterfaceDefinition::deleteJSPointers, OOJSPopulatorDefinition::deleteJSPointers, OOJSTimer::deleteJSPointers, Entity(OOJavaScriptExtensions)::deleteJSSelf, OOJSFunction::deleteJSValue, OOJSValue::deleteJSValue, DescribeValue(), PlayerEntity::docked, PlayerEntity(Scripting)::doMissionCallback, GlobalLog(), GlobalLog(), OOJSGuiScreenKeyDefinition::init, OOJSInterfaceDefinition::init, OOJSPopulatorDefinition::init, OORegExpMatcher::init, OOJSTimer::initWithDelay:interval:context:function:this:, OOJSTimer(Private)::initWithDelay:interval:context:function:this:, OOJSFunction::initWithFunction:context:, OOJSValue::initWithJSValue:inContext:, OOJSScript::initWithPath:properties:, PlayerEntity(OOJavaScriptExtensions)::javaScriptEngineWillReset:, PlayerEntity::leaveWitchspace, PlayerEntity(LoadSave)::loadPlayerFromFile:asNew:, LogProblem(), main(), MissionRunCallback(), MissionRunCallback(), Entity(OOJavaScriptExtensions)::oo_jsValueInContext:, OOStringFromDeciCredits(), OOJSTimer(Private)::releaseJSValues, ReportJSError(), OOCheckJSSyntaxVerifierStage::run, OOJSGuiScreenKeyDefinition::runCallback:, OOJSInterfaceDefinition::runCallback:, OOJSPopulatorDefinition::runCallback:, PlayerEntity(OOJavaScriptExtensions)::setJSSelf:context:, sharedEngine, OOJSTimer::timerFired, and Universe::update:.

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

◆ sharedEngine [2/2]

+ (OOJavaScriptEngine *) sharedEngine

References context, and sharedEngine.

Here is the call graph for this function:

◆ showErrorLocations [1/2]

- (BOOL) showErrorLocations

Definition at line 179 of file OOJavaScriptEnginePoc.m.

180{
181 return _showErrorLocations;
182}

References _showErrorLocations, and showErrorLocations.

Referenced by ReportJSError(), and showErrorLocations.

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

◆ showErrorLocations [2/2]

- (BOOL) showErrorLocations

References showErrorLocations.

Here is the call graph for this function:

◆ shutDown

- (NSUInteger) shutDown

Definition at line 106 of file OOJavaScriptEnginePoc.m.

107{
108 if (_context == NULL)
109 return 0;
110
111 JS_FreeValue(_context, _globalObject);
112 _globalObject = JS_UNDEFINED;
113 JS_FreeContext(_context);
114 _context = NULL;
116
117 JS_RunGC(_runtime);
118 JSMemoryUsage usage;
119 JS_ComputeMemoryUsage(_runtime, &usage);
120 if (usage.obj_count != 0) {
121 /* JS_FreeRuntime() would assert. Dump what is left and abandon the
122 runtime instead, so the leak can be reported.
123 */
124 OOLog(@"script.javaScript.shutDown.leak", @"***** JavaScript runtime shut down with %lli objects still alive; something is holding a JSValue it does not own, or has not freed one it does.", (long long)usage.obj_count);
125 JS_DumpMemoryUsage(stdout, &usage, _runtime);
126 _runtime = NULL;
127 return (NSUInteger)usage.obj_count;
128 }
129
130 JS_FreeRuntime(_runtime);
131 _runtime = NULL;
132 return 0;
133}

References _context, _globalObject, _runtime, gOOJSMainThreadContext, OOLog, and shutDown.

Referenced by main(), setShowErrorLocations:, and shutDown.

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

◆ stringClass

- (JSClass *) stringClass

Definition at line 530 of file OOJavaScriptEngine.m.

531{
532 return _stringClass;
533}

References _stringClass, and stringClass.

Referenced by stringClass.

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

◆ watchdogTimerThread

- (void) watchdogTimerThread
implementation

Provided by category OOJavaScriptEngine(WatchdogTimer).

Definition at line 177 of file OOJSEngineTimeManagement.m.

178{
179 for (;;) {
180#if OOLITE_WINDOWS
181 Sleep(OOJS_TIME_LIMIT * 1000);
182#else
183 usleep(OOJS_TIME_LIMIT * 1000000);
184#endif
185
187 continue; // Most of the time, a script isn't running.
188
189 // Note: if you add logging here, you need a manual autorelease pool.
190
194
195 if (EXPECT_NOT(elapsed > sLimiterTimeLimit)) {
196 sStop = YES;
197 JS_TriggerAllOperationCallbacks(_runtime);
198 }
199 }
200}
#define EXPECT(x)
#define OOJS_TIME_LIMIT
static BOOL sStop
static double sLimiterTimeLimit
static int sLimiterPauseDepth
static unsigned sLimiterStartDepth
static OOHighResTimeValue sLimiterStart
OOTimeDelta OOHighResTimeDeltaInSeconds(OOHighResTimeValue startTime, OOHighResTimeValue endTime)
uint64_t OOHighResTimeValue
#define OOGetHighResTime
#define OODisposeHighResTime(time)
double OOTimeDelta
Definition OOTypes.h:193

Member Data Documentation

◆ _arrayClass

- (JSClass*) _arrayClass
private

Definition at line 47 of file OOJavaScriptEngine.h.

Referenced by arrayClass.

◆ _booleanClass

- (JSClass*) _booleanClass
private

Definition at line 49 of file OOJavaScriptEngine.h.

Referenced by booleanClass.

◆ _context

- (JSContext*) _context
private

◆ _globalObject [1/2]

- (JSObject*) _globalObject
private

Definition at line 42 of file OOJavaScriptEngine.h.

Referenced by globalObject, and shutDown.

◆ _globalObject [2/2]

- (JSValue) _globalObject
private

Definition at line 104 of file OOJavaScriptEngine.h.

◆ _numberClass

- (JSClass*) _numberClass
private

Definition at line 48 of file OOJavaScriptEngine.h.

Referenced by numberClass.

◆ _objectClass

- (JSClass*) _objectClass
private

Definition at line 45 of file OOJavaScriptEngine.h.

Referenced by objectClass.

◆ _runtime

- (JSRuntime *) _runtime
private

Definition at line 41 of file OOJavaScriptEngine.h.

Referenced by dealloc, garbageCollectionOpportunity:, init, and shutDown.

◆ _showErrorLocations

- (BOOL) _showErrorLocations
private

Definition at line 43 of file OOJavaScriptEngine.h.

Referenced by setShowErrorLocations:, and showErrorLocations.

◆ _stringClass

- (JSClass*) _stringClass
private

Definition at line 46 of file OOJavaScriptEngine.h.

Referenced by stringClass.


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