Oolite 1.91.0.7647-241230-5e1c242
Loading...
Searching...
No Matches
OOJavaScriptEngine(Private) Category Reference

Instance Methods

(BOOL) - lookUpStandardClassPointers
 
(void) - registerStandardObjectConverters
 
(void) - createMainThreadContext
 
(void) - destroyMainThreadContext
 

Detailed Description

Definition at line 121 of file OOJavaScriptEngine.m.

Method Documentation

◆ createMainThreadContext

- (void) createMainThreadContext

Extends class OOJavaScriptEngine.

Definition at line 301 of file OOJavaScriptEngine.m.

302{
303 NSAssert(gOOJSMainThreadContext == NULL, @"-[OOJavaScriptEngine createMainThreadContext] called while the main thread context exists.");
304
305 // create a context and associate it with the JS runtime.
306 gOOJSMainThreadContext = JS_NewContext(_runtime, OOJS_STACK_SIZE);
307
308 // if context creation failed, end the program here.
309 if (gOOJSMainThreadContext == NULL)
310 {
311 OOLog(@"script.javaScript.init.error", @"%@", @"***** FATAL ERROR: failed to create JavaScript context.");
312 exit(1);
313 }
314
316
319
320#if JS_GC_ZEAL
321 uint8_t gcZeal = [[NSUserDefaults standardUserDefaults] oo_unsignedCharForKey:@"js-gc-zeal"];
322 if (gcZeal > 0)
323 {
324 // Useful js-gc-zeal values are 0 (off), 1 and 2.
325 OOLog(@"script.javaScript.debug.gcZeal", @"Setting JavaScript garbage collector zeal to %u.", gcZeal);
326 JS_SetGCZeal(gOOJSMainThreadContext, gcZeal);
327 }
328#endif
329
330 JS_SetErrorReporter(gOOJSMainThreadContext, ReportJSError);
331
332 // Create the global object.
334
335 // Initialize the built-in JS objects and the global object.
336 JS_InitStandardClasses(gOOJSMainThreadContext, _globalObject);
337 if (![self lookUpStandardClassPointers])
338 {
339 OOLog(@"script.javaScript.init.error", @"%@", @"***** FATAL ERROR: failed to look up standard JavaScript classes.");
340 exit(1);
341 }
342 [self registerStandardObjectConverters];
343
346
347 // Initialize Oolite classes.
355 InitOOJSShip(gOOJSMainThreadContext, _globalObject);
357 InitOOJSDock(gOOJSMainThreadContext, _globalObject);
366 InitOOJSSun(gOOJSMainThreadContext, _globalObject);
379 InitOOJSFont(gOOJSMainThreadContext, _globalObject);
380
381 // Run prefix scripts.
382 [OOJSScript jsScriptFromFileNamed:@"oolite-global-prefix.js"
383 properties:[NSDictionary dictionaryWithObject:JSSpecialFunctionsObjectWrapper(gOOJSMainThreadContext)
384 forKey:@"special"]];
385
387
388 OOLog(@"script.javaScript.init.success", @"%@", @"Set up JavaScript context.");
389}
void OOConstToJSStringInit(JSContext *context)
void InitOOJSClock(JSContext *context, JSObject *global)
Definition OOJSClock.m:109
void InitOOJSDock(JSContext *context, JSObject *global)
Definition OOJSDock.m:94
void InitOOJSEntity(JSContext *context, JSObject *global)
Definition OOJSEntity.m:139
void InitOOJSEquipmentInfo(JSContext *context, JSObject *global)
void InitOOJSExhaustPlume(JSContext *context, JSObject *global)
void InitOOJSFlasher(JSContext *context, JSObject *global)
Definition OOJSFlasher.m:96
void InitOOJSFont(JSContext *context, JSObject *global)
Definition OOJSFont.m:38
void InitOOJSFrameCallbacks(JSContext *context, JSObject *global)
void CreateOOJSGlobal(JSContext *context, JSObject **outGlobal)
Definition OOJSGlobal.m:166
void SetUpOOJSGlobal(JSContext *context, JSObject *global)
Definition OOJSGlobal.m:177
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:92
void InitOOJSPlanet(JSContext *context, JSObject *global)
Definition OOJSPlanet.m:99
void InitOOJSPlayerShip(JSContext *context, JSObject *global)
void InitOOJSPlayer(JSContext *context, JSObject *global)
Definition OOJSPlayer.m:163
void InitOOJSQuaternion(JSContext *context, JSObject *global)
void InitOOJSScript(JSContext *context, JSObject *global)
Definition OOJSScript.m:663
void InitOOJSShipGroup(JSContext *context, JSObject *global)
void InitOOJSShip(JSContext *context, JSObject *global)
Definition OOJSShip.m:587
void InitOOJSSoundSource(JSContext *context, JSObject *global)
void InitOOJSSound(JSContext *context, JSObject *global)
Definition OOJSSound.m:104
void InitOOJSSpecialFunctions(JSContext *context, JSObject *global)
void InitOOJSStation(JSContext *context, JSObject *global)
void InitOOJSSun(JSContext *context, JSObject *global)
Definition OOJSSun.m:91
void InitOOJSSystemInfo(JSContext *context, JSObject *global)
void InitOOJSSystem(JSContext *context, JSObject *global)
Definition OOJSSystem.m:227
void InitOOJSTimer(JSContext *context, JSObject *global)
Definition OOJSTimer.m:254
void InitOOJSVector(JSContext *context, JSObject *global)
Definition OOJSVector.m:153
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:88
id jsScriptFromFileNamed:properties:(NSString *fileName,[properties] NSDictionary *properties)
Definition OOScript.m:192

References 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:, lookUpStandardClassPointers, OOConstToJSStringInit(), OOJS_STACK_SIZE, OOJSENGINE_CONTEXT_OPTIONS, OOJSENGINE_JSVERSION, OOLog, OOJavaScriptEngine::registerStandardObjectConverters, ReportJSError(), and SetUpOOJSGlobal().

Referenced by createMainThreadContext, OOJavaScriptEngine::init, and OOJavaScriptEngine::reset.

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

◆ destroyMainThreadContext

- (void) destroyMainThreadContext

Extends class OOJavaScriptEngine.

Definition at line 392 of file OOJavaScriptEngine.m.

393{
394 if (gOOJSMainThreadContext != NULL)
395 {
396 JSContext *context = OOJSAcquireContext();
397 JS_ClearScope(gOOJSMainThreadContext, _globalObject);
398
399 _globalObject = NULL;
400 _objectClass = NULL;
401 _stringClass = NULL;
402 _arrayClass = NULL;
403 _numberClass = NULL;
404 _booleanClass = NULL;
405
409
410 OOJSRelinquishContext(context);
411
412 _globalObject = NULL;
413 JS_DestroyContext(gOOJSMainThreadContext); // Forces unconditional GC.
415 }
416}
void OOConstToJSStringDestroy(void)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
static void UnregisterSubclasses(void)
static void UnregisterObjectConverters(void)

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

Referenced by OOJavaScriptEngine::dealloc, destroyMainThreadContext, and OOJavaScriptEngine::reset.

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

◆ lookUpStandardClassPointers

- (BOOL) lookUpStandardClassPointers

Extends class OOJavaScriptEngine.

Definition at line 586 of file OOJavaScriptEngine.m.

587{
588 JSObject *templateObject = NULL;
589
590 templateObject = JS_NewObject(gOOJSMainThreadContext, NULL, NULL, NULL);
591 if (EXPECT_NOT(templateObject == NULL)) return NO;
592 _objectClass = OOJSGetClass(gOOJSMainThreadContext, templateObject);
593
594 if (EXPECT_NOT(!JS_ValueToObject(gOOJSMainThreadContext, JS_GetEmptyStringValue(gOOJSMainThreadContext), &templateObject))) return NO;
595 _stringClass = OOJSGetClass(gOOJSMainThreadContext, templateObject);
596
597 templateObject = JS_NewArrayObject(gOOJSMainThreadContext, 0, NULL);
598 if (EXPECT_NOT(templateObject == NULL)) return NO;
599 _arrayClass = OOJSGetClass(gOOJSMainThreadContext, templateObject);
600
601 if (EXPECT_NOT(!JS_ValueToObject(gOOJSMainThreadContext, INT_TO_JSVAL(0), &templateObject))) return NO;
602 _numberClass = OOJSGetClass(gOOJSMainThreadContext, templateObject);
603
604 if (EXPECT_NOT(!JS_ValueToObject(gOOJSMainThreadContext, JSVAL_FALSE, &templateObject))) return NO;
605 _booleanClass = OOJSGetClass(gOOJSMainThreadContext, templateObject);
606
607 return YES;
608}
#define EXPECT_NOT(x)
OOINLINE JSClass * OOJSGetClass(JSContext *cx, JSObject *obj) ALWAYS_INLINE_FUNC

References EXPECT_NOT, gOOJSMainThreadContext, lookUpStandardClassPointers, and OOJSGetClass().

Referenced by createMainThreadContext, and lookUpStandardClassPointers.

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

◆ registerStandardObjectConverters

- (void) registerStandardObjectConverters

Extends class OOJavaScriptEngine.

Definition at line 611 of file OOJavaScriptEngine.m.

612{
618}
id(* OOJSClassConverterCallback)(JSContext *context, JSObject *object)
static id JSNumberConverter(JSContext *context, JSObject *object)
static id JSStringConverter(JSContext *context, JSObject *object)
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
static id JSArrayConverter(JSContext *context, JSObject *object)
NSDictionary * OOJSDictionaryFromJSObject(JSContext *context, JSObject *object)
static id JSBooleanConverter(JSContext *context, JSObject *object)

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

Referenced by createMainThreadContext, and registerStandardObjectConverters.

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

The documentation for this category was generated from the following file: