Oolite 1.91.0.7604-240417-a536cbe
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions | Variables
OOJavaScriptEngine.h File Reference
import "OOCocoa.h"
import "Universe.h"
import "PlayerEntity.h"
import "PlayerEntityLegacyScriptEngine.h"
#include <jsapi.h>
import "OOJSPropID.h"
import "OOJSEngineNativeWrappers.h"
+ Include dependency graph for OOJavaScriptEngine.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  OOJavaScriptEngine
 
category  NSObject(OOJavaScript)
 
class  OOJSValue
 
category  NSString(OOJavaScriptExtensions)
 
struct  JSFunctionPredicateParameter
 

Macros

#define OOJSENGINE_MONITOR_SUPPORT   OOLITE_DEBUG
 
#define JS_IsInRequest(context)   (((void)(context)), YES)
 
#define JS_BeginRequest(context)   do {} while (0)
 
#define JS_EndRequest(context)   do {} while (0)
 
#define OOJSSTR(str)   ({ static jsval strCache; static BOOL inited; if (EXPECT_NOT(!inited)) OOJSStrLiteralCachePRIVATE(""str, &strCache, &inited); strCache; })
 
#define DEFINE_JS_OBJECT_GETTER(NAME, JSCLASS, JSPROTO, OBJCCLASSNAME)
 
#define OOJSAddGCValueRoot(context, root, name)   JS_AddNamedValueRoot((context), (root), "" name)
 
#define OOJSAddGCStringRoot(context, root, name)   JS_AddNamedStringRoot((context), (root), "" name)
 
#define OOJSAddGCObjectRoot(context, root, name)   JS_AddNamedObjectRoot((context), (root), "" name)
 
#define OOJSAddGCThingRoot(context, root, name)   JS_AddNamedGCThingRoot((context), (root), "" name)
 
#define OOJS_PROP_READWRITE   (JSPROP_PERMANENT | JSPROP_ENUMERATE)
 
#define OOJS_PROP_READONLY   (JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY)
 
#define OOJS_PROP_HIDDEN_READWRITE   (JSPROP_PERMANENT)
 
#define OOJS_PROP_HIDDEN_READONLY   (JSPROP_PERMANENT | JSPROP_READONLY)
 
#define OOJS_METHOD_READONLY   OOJS_PROP_HIDDEN_READONLY
 
#define OOJS_PROP_READWRITE_CB   (OOJS_PROP_READWRITE | JSPROP_SHARED)
 
#define OOJS_PROP_READONLY_CB   (OOJS_PROP_READONLY | JSPROP_SHARED)
 
#define OOJS_PROP_HIDDEN_READWRITE_CB   (OOJS_PROP_HIDDEN_READWRITE | JSPROP_SHARED)
 
#define OOJS_PROP_HIDDEN_READONLY_CB   (OOJS_PROP_HIDDEN_READONLY | JSPROP_SHARED)
 
#define OOJS_THIS   JS_THIS_OBJECT(context, vp)
 
#define OOJS_ARGV   JS_ARGV(context, vp)
 
#define OOJS_RVAL   JS_RVAL(context, vp)
 
#define OOJS_SET_RVAL(v)   JS_SET_RVAL(context, vp, v)
 
#define OOJS_RETURN(v)   do { OOJS_SET_RVAL(v); return YES; } while (0)
 
#define OOJS_RETURN_JSOBJECT(o)   OOJS_RETURN(OBJECT_TO_JSVAL(o))
 
#define OOJS_RETURN_VOID   OOJS_RETURN(JSVAL_VOID)
 
#define OOJS_RETURN_NULL   OOJS_RETURN(JSVAL_NULL)
 
#define OOJS_RETURN_BOOL(v)   OOJS_RETURN(OOJSValueFromBOOL(v))
 
#define OOJS_RETURN_INT(v)   OOJS_RETURN(INT_TO_JSVAL(v))
 
#define OOJS_RETURN_OBJECT(o)   OOJS_RETURN(OOJSValueFromNativeObject(context, o))
 
#define OOJS_RETURN_WITH_HELPER(helper, value)
 
#define OOJS_RETURN_VECTOR(value)   OOJS_RETURN_WITH_HELPER(VectorToJSValue, value)
 
#define OOJS_RETURN_HPVECTOR(value)   OOJS_RETURN_WITH_HELPER(HPVectorToJSValue, value)
 
#define OOJS_RETURN_QUATERNION(value)   OOJS_RETURN_WITH_HELPER(QuaternionToJSValue, value)
 
#define OOJS_RETURN_DOUBLE(value)   OOJS_RETURN_WITH_HELPER(JS_NewNumberValue, value)
 

Typedefs

typedef id(* OOJSClassConverterCallback) (JSContext *context, JSObject *object)
 

Functions

OOINLINE JSContext * OOJSAcquireContext (void)
 
OOINLINE void OOJSRelinquishContext (JSContext *context)
 
void OOJSReportError (JSContext *context, NSString *format,...)
 
void OOJSReportErrorWithArguments (JSContext *context, NSString *format, va_list args)
 
void OOJSReportErrorForCaller (JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
 
void OOJSReportWarning (JSContext *context, NSString *format,...)
 
void OOJSReportWarningWithArguments (JSContext *context, NSString *format, va_list args)
 
void OOJSReportWarningForCaller (JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
 
void OOJSReportBadPropertySelector (JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
 
void OOJSReportBadPropertyValue (JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
 
void OOJSReportBadArguments (JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
 
void OOJSSetWarningOrErrorStackSkip (unsigned skip)
 
BOOL OOJSArgumentListGetNumber (JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)
 
BOOL OOJSArgumentListGetNumberNoError (JSContext *context, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)
 
OOINLINE jsval OOJSValueFromBOOL (int b) INLINE_CONST_FUNC
 
OOINLINE jsval OOJSValueFromNativeObject (JSContext *context, id object)
 
JSObject * OOJSObjectFromNativeObject (JSContext *context, id object)
 
void OOJSStrLiteralCachePRIVATE (const char *string, jsval *strCache, BOOL *inited)
 
NSString * OOStringFromJSString (JSContext *context, JSString *string)
 
NSString * OOStringFromJSValue (JSContext *context, jsval value)
 
NSString * OOStringFromJSValueEvenIfNull (JSContext *context, jsval value)
 
NSString * OOStringFromJSPropertyIDAndSpec (JSContext *context, jsid propID, JSPropertySpec *propertySpec)
 
NSString * OOJSDescribeValue (JSContext *context, jsval value, BOOL abbreviateObjects)
 
NSString * OOStringFromJSID (jsid propID)
 
jsid OOJSIDFromString (NSString *string)
 
BOOL JSFunctionPredicate (Entity *entity, void *parameter)
 
BOOL JSEntityIsJavaScriptVisiblePredicate (Entity *entity, void *parameter)
 
BOOL JSEntityIsJavaScriptSearchablePredicate (Entity *entity, void *parameter)
 
BOOL JSEntityIsDemoShipPredicate (Entity *entity, void *parameter)
 
id OOJSNativeObjectFromJSValue (JSContext *context, jsval value)
 
id OOJSNativeObjectFromJSObject (JSContext *context, JSObject *object)
 
id OOJSNativeObjectOfClassFromJSValue (JSContext *context, jsval value, Class requiredClass)
 
id OOJSNativeObjectOfClassFromJSObject (JSContext *context, JSObject *object, Class requiredClass)
 
OOINLINE JSClass * OOJSGetClass (JSContext *cx, JSObject *obj) ALWAYS_INLINE_FUNC
 
OOINLINE BOOL OOJSValueIsFunction (JSContext *context, jsval value)
 
OOINLINE BOOL OOJSValueIsArray (JSContext *context, jsval value)
 
NSDictionary * OOJSDictionaryFromJSValue (JSContext *context, jsval value)
 
NSDictionary * OOJSDictionaryFromJSObject (JSContext *context, JSObject *object)
 
NSDictionary * OOJSDictionaryFromStringTable (JSContext *context, jsval value)
 
BOOL OOJSObjectGetterImplPRIVATE (JSContext *context, JSObject *object, JSClass *requiredJSClass, Class requiredObjCClass, const char *name, id *outObject)
 
void OOJSRegisterSubclass (JSClass *subclass, JSClass *superclass)
 
BOOL OOJSIsSubclass (JSClass *putativeSubclass, JSClass *superclass)
 
OOINLINE BOOL OOJSIsMemberOfSubclass (JSContext *context, JSObject *object, JSClass *superclass)
 
id OOJSBasicPrivateObjectConverter (JSContext *context, JSObject *object)
 
void OOJSRegisterObjectConverter (JSClass *theClass, OOJSClassConverterCallback converter)
 
void OOJSPauseTimeLimiter (void)
 
void OOJSResumeTimeLimiter (void)
 
void OOJSDumpStack (JSContext *context)
 
NSString * OOJSDescribeLocation (JSContext *context, JSStackFrame *stackFrame)
 
void OOJSMarkConsoleEvalLocation (JSContext *context, JSStackFrame *stackFrame)
 
JSBool OOJSUnconstructableConstruct (JSContext *context, uintN argc, jsval *vp)
 
void OOJSObjectWrapperFinalize (JSContext *context, JSObject *this)
 
JSBool OOJSObjectWrapperToString (JSContext *context, uintN argc, jsval *vp)
 

Variables

NSString *const kOOJavaScriptEngineWillResetNotification
 
NSString *const kOOJavaScriptEngineDidResetNotification
 

Macro Definition Documentation

◆ DEFINE_JS_OBJECT_GETTER

#define DEFINE_JS_OBJECT_GETTER ( NAME,
JSCLASS,
JSPROTO,
OBJCCLASSNAME )
Value:
static BOOL NAME(JSContext *context, JSObject *inObject, OBJCCLASSNAME **outObject) GCC_ATTR((unused)); \
static BOOL NAME(JSContext *context, JSObject *inObject, OBJCCLASSNAME **outObject) \
{ \
NSCParameterAssert(outObject != NULL); \
static Class cls = Nil; \
if (EXPECT_NOT(cls == Nil)) cls = [OBJCCLASSNAME class]; \
return OOJSObjectGetterImplPRIVATE(context, inObject, JSCLASS, cls, #NAME, (id *)outObject); \
}
#define EXPECT_NOT(x)
#define GCC_ATTR(x)
BOOL OOJSObjectGetterImplPRIVATE(JSContext *context, JSObject *object, JSClass *requiredJSClass, Class requiredObjCClass, const char *name, id *outObject)

Definition at line 448 of file OOJavaScriptEngine.h.

448#define DEFINE_JS_OBJECT_GETTER(NAME, JSCLASS, JSPROTO, OBJCCLASSNAME) \
449static BOOL NAME(JSContext *context, JSObject *inObject, OBJCCLASSNAME **outObject) GCC_ATTR((unused)); \
450static BOOL NAME(JSContext *context, JSObject *inObject, OBJCCLASSNAME **outObject) \
451{ \
452 NSCParameterAssert(outObject != NULL); \
453 static Class cls = Nil; \
454 if (EXPECT_NOT(cls == Nil)) cls = [OBJCCLASSNAME class]; \
455 return OOJSObjectGetterImplPRIVATE(context, inObject, JSCLASS, cls, #NAME, (id *)outObject); \
456}

◆ JS_BeginRequest

#define JS_BeginRequest ( context)    do {} while (0)

Definition at line 112 of file OOJavaScriptEngine.h.

Referenced by OOJSAcquireContext().

◆ JS_EndRequest

#define JS_EndRequest ( context)    do {} while (0)

Definition at line 113 of file OOJavaScriptEngine.h.

Referenced by OOJSRelinquishContext().

◆ JS_IsInRequest

#define JS_IsInRequest ( context)    (((void)(context)), YES)

◆ OOJS_ARGV

#define OOJS_ARGV   JS_ARGV(context, vp)

Definition at line 661 of file OOJavaScriptEngine.h.

Referenced by ClockAddSeconds(), ClockClockStringForTime(), ConsoleConsoleMessage(), ConsoleDisplayMessagesInClass(), ConsoleInspectEntity(), ConsoleIsExecutableJavaScript(), ConsoleSetDisplayMessagesInClass(), OOManifest::dealloc, FontMeasureString(), DockEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, StationEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, GlobalAddFrameCallback(), GlobalAutoAIForRole(), GlobalClearExtraGuiScreenKeys(), GlobalDisplayNameForCommodity(), GlobalExpandDescription(), GlobalExpandMissionText(), GlobalGetGuiColorSettingForKey(), GlobalGetScreenBackgroundForKey(), GlobalIsValidFrameCallback(), GlobalKeyBindingDescription(), GlobalLog(), GlobalRandomInhabitantsDescription(), GlobalRemoveFrameCallback(), GlobalSetColorSaturation(), GlobalSetExtraGuiScreenKeys(), GlobalSetGuiColorSettingForKey(), GlobalSetScreenBackground(), GlobalSetScreenBackgroundForKey(), GlobalSetScreenOverlay(), GlobalTakeSnapShot(), PlayerEntity(OOJavaScriptExtensions)::javaScriptEngineWillReset:, ManifestComment(), ManifestSetComment(), ManifestShortComment(), MissionAddMessageText(), MissionMarkSystem(), MissionRunScreen(), MissionSetInstructionsInternal(), MissionUnmarkSystem(), OOEquipmentType(OOJavaScriptExtensions)::oo_clearJSSelf:, OOShipGroup(OOJavaScriptExtensions)::oo_clearJSSelf:, OOSound(OOJavaScriptExtentions)::oo_jsClassName, OoliteCompareVersion(), PlayerAddMessageToArrivalReport(), PlayerAudioMessage(), PlayerCommsMessage(), PlayerConsoleMessage(), PlayerEndScenario(), PlayerReplaceShip(), PlayerSetEscapePodDestination(), PlayerSetPlayerRole(), PlayerShipAddParcel(), PlayerShipAddPassenger(), PlayerShipAwardContract(), PlayerShipAwardEquipmentToCurrentPylon(), PlayerShipBeginGalacticHyperspaceCountdown(), PlayerShipBeginHyperspaceCountdown(), PlayerShipCancelDockingRequest(), PlayerShipEngageAutopilotToStation(), PlayerShipHideHUDSelector(), PlayerShipRemoveContract(), PlayerShipRemoveParcel(), PlayerShipRemovePassenger(), PlayerShipRequestDockingClearance(), PlayerShipSetCustomHUDDial(), PlayerShipSetCustomView(), PlayerShipSetMultiFunctionDisplay(), PlayerShipSetMultiFunctionText(), PlayerShipSetPrimedEquipment(), PlayerShipShowHUDSelector(), PlayerShipUseSpecialCargo(), QuaternionConstruct(), QuaternionDot(), QuaternionMultiply(), QuaternionRotate(), QuaternionRotateX(), QuaternionRotateY(), QuaternionRotateZ(), ShipAddCargoEntity(), ShipAddCollisionException(), ShipAddDefenseTarget(), ShipAdjustCargo(), ShipAwardEquipment(), ShipCanAwardEquipment(), ShipCheckScanner(), ShipCommsMessage(), ShipDealEnergyDamage(), ShipDumpCargo(), ShipEjectItem(), ShipEjectSpecificItem(), ShipEnterWormhole(), ShipEquipmentStatus(), ShipExitAI(), ShipExitSystem(), ShipGroupAddShip(), ShipGroupConstruct(), ShipGroupRemoveShip(), ShipHasEquipmentProviding(), ShipHasRole(), ShipOfferToEscort(), ShipPatrolReportIn(), ShipReactToAIMessage(), ShipRemove(), ShipRemoveCollisionException(), ShipRemoveDefenseTarget(), ShipRemoveEquipment(), ShipRunLegacyScriptActions(), ShipSendAIMessage(), ShipSetAI(), ShipSetBounty(), ShipSetCargo(), ShipSetCargoType(), ShipSetCrew(), ShipSetEquipmentStatus(), ShipSetMaterials(), ShipSetMaterialsInternal(), ShipSetScript(), ShipSetShaders(), ShipSpawn(), ShipStaticKeysForRole(), ShipStaticRoleIsInCategory(), ShipStaticSetShipDataForKey(), ShipStaticShipDataForKey(), ShipSwitchAI(), ShipThreatAssessment(), SoundSourcePlay(), SoundStaticLoad(), SoundStaticPlayMusic(), SpecialJSWarning(), StationAbortDockingForShip(), StationAddShipToShipyard(), StationCanDockShip(), StationLaunchShipWithRole(), StationSetInterface(), StationSetMarketPrice(), StationSetMarketQuantity(), SunGoNova(), SystemAddMoon(), SystemAddPlanet(), SystemAddShipsOrGroup(), SystemAddShipsOrGroupToRoute(), SystemAddVisualEffect(), SystemCountEntitiesWithScanClass(), SystemCountShipsWithPrimaryRole(), SystemCountShipsWithRole(), SystemEntitiesWithScanClass(), SystemFilteredEntities(), SystemInfoDistanceToSystem(), SystemInfoRouteToSystem(), SystemInfoSamplePrice(), SystemInfoSetPropertyMethod(), SystemInfoStaticFilteredSystems(), SystemInfoStaticSetInterstellarProperty(), SystemLegacyAddShips(), SystemLegacyAddShipsAt(), SystemLegacyAddShipsAtPrecisely(), SystemLegacyAddShipsWithinRadius(), SystemLegacyAddSystemShips(), SystemLegacySpawnShip(), SystemLocationFromCode(), SystemSetPopulator(), SystemSetWaypoint(), SystemShipsWithPrimaryRole(), SystemShipsWithRole(), SystemStaticInfoForSystem(), SystemStaticSystemIDForName(), SystemStaticSystemNameForID(), TimerConstruct(), VectorAdd(), VectorAngleTo(), VectorConstruct(), VectorCross(), VectorDistanceTo(), VectorDot(), VectorFromCoordinateSystem(), VectorMultiply(), VectorRotateBy(), VectorRotationTo(), VectorSquaredDistanceTo(), VectorStaticInterpolate(), VectorStaticRandom(), VectorStaticRandomDirection(), VectorStaticRandomDirectionAndLength(), VectorSubtract(), VectorToCoordinateSystem(), VectorTripleProduct(), VisualEffectScale(), VisualEffectSetMaterials(), VisualEffectSetMaterialsInternal(), and VisualEffectSetShaders().

◆ OOJS_METHOD_READONLY

#define OOJS_METHOD_READONLY   OOJS_PROP_HIDDEN_READONLY

Definition at line 647 of file OOJavaScriptEngine.h.

Referenced by InitOOJSFont(), and InitOOJSFrameCallbacks().

◆ OOJS_PROP_HIDDEN_READONLY

#define OOJS_PROP_HIDDEN_READONLY   (JSPROP_PERMANENT | JSPROP_READONLY)

Definition at line 644 of file OOJavaScriptEngine.h.

◆ OOJS_PROP_HIDDEN_READONLY_CB

#define OOJS_PROP_HIDDEN_READONLY_CB   (OOJS_PROP_HIDDEN_READONLY | JSPROP_SHARED)

Definition at line 654 of file OOJavaScriptEngine.h.

◆ OOJS_PROP_HIDDEN_READWRITE

#define OOJS_PROP_HIDDEN_READWRITE   (JSPROP_PERMANENT)

Definition at line 643 of file OOJavaScriptEngine.h.

◆ OOJS_PROP_HIDDEN_READWRITE_CB

#define OOJS_PROP_HIDDEN_READWRITE_CB   (OOJS_PROP_HIDDEN_READWRITE | JSPROP_SHARED)

Definition at line 653 of file OOJavaScriptEngine.h.

◆ OOJS_PROP_READONLY

#define OOJS_PROP_READONLY   (JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY)

◆ OOJS_PROP_READONLY_CB

#define OOJS_PROP_READONLY_CB   (OOJS_PROP_READONLY | JSPROP_SHARED)

Definition at line 651 of file OOJavaScriptEngine.h.

Referenced by WorldScriptsEnumerate().

◆ OOJS_PROP_READWRITE

#define OOJS_PROP_READWRITE   (JSPROP_PERMANENT | JSPROP_ENUMERATE)

Definition at line 639 of file OOJavaScriptEngine.h.

◆ OOJS_PROP_READWRITE_CB

#define OOJS_PROP_READWRITE_CB   (OOJS_PROP_READWRITE | JSPROP_SHARED)

Definition at line 650 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN

#define OOJS_RETURN ( v)    do { OOJS_SET_RVAL(v); return YES; } while (0)

Definition at line 665 of file OOJavaScriptEngine.h.

Referenced by ShipEquipmentStatus(), and SystemStaticInfoForSystem().

◆ OOJS_RETURN_BOOL

#define OOJS_RETURN_BOOL ( v)    OOJS_RETURN(OOJSValueFromBOOL(v))

Definition at line 669 of file OOJavaScriptEngine.h.

Referenced by ClockAddSeconds(), ConsoleDisplayMessagesInClass(), ConsoleIsExecutableJavaScript(), OOManifest::dealloc, DockEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, StationEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, OOVisualEffectEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, GlobalClearExtraGuiScreenKeys(), GlobalIsValidFrameCallback(), GlobalPauseGame(), GlobalSetExtraGuiScreenKeys(), GlobalSetGuiColorSettingForKey(), GlobalSetScreenBackground(), GlobalSetScreenBackgroundForKey(), GlobalSetScreenOverlay(), GlobalTakeSnapShot(), ManifestSetComment(), MissionRunScreen(), MissionRunShipLibrary(), MissionUnmarkSystem(), OOShipGroup(OOJavaScriptExtensions)::oo_clearJSSelf:, PlayerEndScenario(), PlayerReplaceShip(), PlayerShipAddParcel(), PlayerShipAddPassenger(), PlayerShipAwardContract(), PlayerShipAwardEquipmentToCurrentPylon(), PlayerShipBeginGalacticHyperspaceCountdown(), PlayerShipBeginHyperspaceCountdown(), PlayerShipCancelHyperspaceCountdown(), PlayerShipEngageAutopilotToStation(), PlayerShipRemoveContract(), PlayerShipRemoveParcel(), PlayerShipRemovePassenger(), PlayerShipResetCustomView(), PlayerShipSetCustomView(), PlayerShipSetMultiFunctionDisplay(), PlayerShipSetPrimedEquipment(), PlayerShipTakeInternalDamage(), ShipAbandonShip(), ShipAddCargoEntity(), ShipAdjustCargo(), ShipAwardEquipment(), ShipCanAwardEquipment(), ShipExitSystem(), ShipFireECM(), ShipGroupAddShip(), ShipGroupRemoveShip(), ShipHasEquipmentProviding(), ShipHasRole(), ShipMarkTargetForFines(), ShipOfferToEscort(), ShipRemoveEquipment(), ShipRestoreSubEntities(), ShipSetCargo(), ShipSetCargoType(), ShipSetCrew(), ShipSetEquipmentStatus(), ShipSetMaterialsInternal(), ShipSetShaders(), ShipStaticRoleIsInCategory(), ShipStaticSetShipDataForKey(), StationAddShipToShipyard(), StationCanDockShip(), StationSetMarketPrice(), StationSetMarketQuantity(), TimerStart(), VisualEffectSetMaterialsInternal(), and VisualEffectSetShaders().

◆ OOJS_RETURN_DOUBLE

#define OOJS_RETURN_DOUBLE ( value)    OOJS_RETURN_WITH_HELPER(JS_NewNumberValue, value)

◆ OOJS_RETURN_HPVECTOR

#define OOJS_RETURN_HPVECTOR ( value)    OOJS_RETURN_WITH_HELPER(HPVectorToJSValue, value)

◆ OOJS_RETURN_INT

#define OOJS_RETURN_INT ( v)    OOJS_RETURN(INT_TO_JSVAL(v))

◆ OOJS_RETURN_JSOBJECT

#define OOJS_RETURN_JSOBJECT ( o)    OOJS_RETURN(OBJECT_TO_JSVAL(o))

Definition at line 666 of file OOJavaScriptEngine.h.

Referenced by QuaternionConstruct(), and VectorConstruct().

◆ OOJS_RETURN_NULL

#define OOJS_RETURN_NULL   OOJS_RETURN(JSVAL_NULL)

◆ OOJS_RETURN_OBJECT

#define OOJS_RETURN_OBJECT ( o)    OOJS_RETURN(OOJSValueFromNativeObject(context, o))

Definition at line 671 of file OOJavaScriptEngine.h.

Referenced by ClockClockStringForTime(), ConsoleScriptStack(), GlobalAutoAIForRole(), GlobalDisplayNameForCommodity(), GlobalExpandDescription(), GlobalExpandMissionText(), GlobalGetColorSaturation(), GlobalGetGuiColorSettingForKey(), GlobalGetScreenBackgroundForKey(), GlobalKeyBindingDescription(), GlobalRandomInhabitantsDescription(), GlobalRandomName(), Entity(OODebugInspector)::inspect, JSClockToString(), ManifestComment(), ManifestShortComment(), OOEquipmentType(OOJavaScriptExtensions)::oo_clearJSSelf:, OOJSObjectWrapperToString(), QuaternionToSource(), QuaternionToString(), ShipCheckCourseToDestination(), ShipCheckScanner(), ShipDumpCargo(), ShipEjectItem(), ShipEjectSpecificItem(), ShipEquipmentStatus(), ShipFindNearestStation(), ShipFireMissile(), ShipGetMaterials(), ShipGetShaders(), ShipGroupConstruct(), ShipRecallDockingInstructions(), ShipRequestDockingInstructions(), ShipSelectNewMissile(), ShipSpawn(), ShipStaticKeys(), ShipStaticKeysForRole(), ShipStaticRoles(), ShipStaticShipDataForKey(), SoundSourceConstruct(), SoundStaticLoad(), SoundStaticMusicSoundSource(), StationLaunchDefenseShip(), StationLaunchEscort(), StationLaunchMiner(), StationLaunchPatrol(), StationLaunchPirateShip(), StationLaunchPolice(), StationLaunchScavenger(), StationLaunchShipWithRole(), StationLaunchShuttle(), SystemAddMoon(), SystemAddPlanet(), SystemAddShipsOrGroup(), SystemAddShipsOrGroupToRoute(), SystemAddVisualEffect(), SystemEntitiesWithScanClass(), SystemFilteredEntities(), SystemInfoRouteToSystem(), SystemShipsWithPrimaryRole(), SystemShipsWithRole(), SystemStaticSystemNameForID(), SystemToString(), TimerConstruct(), VectorToSource(), VectorToString(), VisualEffectGetMaterials(), and VisualEffectGetShaders().

◆ OOJS_RETURN_QUATERNION

#define OOJS_RETURN_QUATERNION ( value)    OOJS_RETURN_WITH_HELPER(QuaternionToJSValue, value)

◆ OOJS_RETURN_VECTOR

#define OOJS_RETURN_VECTOR ( value)    OOJS_RETURN_WITH_HELPER(VectorToJSValue, value)

◆ OOJS_RETURN_VOID

#define OOJS_RETURN_VOID   OOJS_RETURN(JSVAL_VOID)

Definition at line 667 of file OOJavaScriptEngine.h.

Referenced by ConsoleClearConsole(), ConsoleConsoleMessage(), ConsoleInspectEntity(), ConsoleSetDisplayMessagesInClass(), ConsoleWriteJSMemoryStats(), ConsoleWriteLogMarker(), ConsoleWriteMemoryStats(), OOJSTimer::dealloc, EntityDumpState(), StationEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, OOSunEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, OOExhaustPlumeEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, OOFlasherEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, GlobalLog(), GlobalRemoveFrameCallback(), GlobalSetColorSaturation(), MissionAddMessageText(), MissionMarkSystem(), MissionSetInstructionsInternal(), OOSound(OOJavaScriptExtentions)::oo_jsClassName, OOSoundSource(OOJavaScriptExtentions)::oo_jsClassName, OoliteCompareVersion(), PlayerAddMessageToArrivalReport(), PlayerAudioMessage(), PlayerCommsMessage(), PlayerConsoleMessage(), PlayerDecreaseContractReputation(), PlayerDecreaseParcelReputation(), PlayerDecreasePassengerReputation(), PlayerIncreaseContractReputation(), PlayerIncreaseParcelReputation(), PlayerIncreasePassengerReputation(), PlayerShipAwardEquipmentToCurrentPylon(), PlayerShipCancelDockingRequest(), PlayerShipDisengageAutopilot(), PlayerShipEngageAutopilotToStation(), PlayerShipHideHUDSelector(), PlayerShipLaunch(), PlayerShipRemoveAllCargo(), PlayerShipRequestDockingClearance(), PlayerShipResetScannerZoom(), PlayerShipSetCustomHUDDial(), PlayerShipSetMultiFunctionText(), PlayerShipShowHUDSelector(), PlayerShipUseSpecialCargo(), PlayerStopAudioMessage(), RemoveOrExplodeShip(), ShipAddCollisionException(), ShipAddDefenseTarget(), ShipBecomeCascadeExplosion(), ShipBroadcastCascadeImminent(), ShipBroadcastDistressMessage(), ShipClearDefenseTargets(), ShipCommsMessage(), ShipDealEnergyDamage(), ShipDeployEscorts(), ShipDockEscorts(), ShipEnterWormhole(), ShipExitAI(), ShipGroupAddShip(), ShipGroupRemoveShip(), ShipNotifyGroupOfWormhole(), ShipPatrolReportIn(), ShipPerformAttack(), ShipPerformCollect(), ShipPerformEscort(), ShipPerformFaceDestination(), ShipPerformFlee(), ShipPerformFlyToRangeFromDestination(), ShipPerformHold(), ShipPerformIdle(), ShipPerformIntercept(), ShipPerformLandOnPlanet(), ShipPerformMining(), ShipPerformScriptedAI(), ShipPerformScriptedAttackAI(), ShipPerformStop(), ShipPerformTumble(), ShipReactToAIMessage(), ShipRemoveCollisionException(), ShipRemoveDefenseTarget(), ShipRequestHelpFromGroup(), ShipRunLegacyScriptActions(), ShipSendAIMessage(), ShipSetAI(), ShipSetScript(), ShipSwitchAI(), ShipThrowSpark(), ShipUpdateEscortFormation(), SoundSourcePlay(), SoundSourceStop(), SoundStaticPlayMusic(), SpecialJSWarning(), SpecialMarkConsoleEntryPoint(), StationAbortAllDockings(), StationAbortDockingForShip(), StationAddShipToShipyard(), StationCanDockShip(), StationDecreaseAlertLevel(), StationDockPlayer(), StationIncreaseAlertLevel(), StationLaunchDefenseShip(), StationLaunchEscort(), StationLaunchMiner(), StationLaunchPatrol(), StationLaunchPirateShip(), StationLaunchPolice(), StationLaunchScavenger(), StationLaunchShipWithRole(), StationLaunchShuttle(), StationSetInterface(), StationSetMarketPrice(), StationSetMarketQuantity(), SunGoNova(), SystemInfoSetPropertyMethod(), SystemInfoStaticSetInterstellarProperty(), SystemLegacyAddShips(), SystemLegacyAddShipsAt(), SystemLegacyAddShipsAtPrecisely(), SystemLegacyAddShipsWithinRadius(), SystemLegacyAddSystemShips(), SystemLegacySpawnShip(), SystemSendAllShipsAway(), SystemSetPopulator(), SystemSetWaypoint(), and VisualEffectRemove().

◆ OOJS_RETURN_WITH_HELPER

#define OOJS_RETURN_WITH_HELPER ( helper,
value )
Value:
do { \
jsval jsresult; \
BOOL OK = helper(context, value, &jsresult); \
JS_SET_RVAL(context, vp, jsresult); return OK; \
} while (0)

Definition at line 673 of file OOJavaScriptEngine.h.

673#define OOJS_RETURN_WITH_HELPER(helper, value) \
674do { \
675 jsval jsresult; \
676 BOOL OK = helper(context, value, &jsresult); \
677 JS_SET_RVAL(context, vp, jsresult); return OK; \
678} while (0)

◆ OOJS_RVAL

#define OOJS_RVAL   JS_RVAL(context, vp)

Definition at line 662 of file OOJavaScriptEngine.h.

Referenced by SystemInfoSamplePrice().

◆ OOJS_SET_RVAL

#define OOJS_SET_RVAL ( v)    JS_SET_RVAL(context, vp, v)

◆ OOJS_THIS

#define OOJS_THIS   JS_THIS_OBJECT(context, vp)

Definition at line 660 of file OOJavaScriptEngine.h.

Referenced by ConsoleClearConsole(), ConsoleConsoleMessage(), OOJSTimer::dealloc, EntityDumpState(), DockEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, StationEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, OOSunEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, OOShipGroup(OOJavaScriptExtensions)::oo_clearJSSelf:, OOSoundSource(OOJavaScriptExtentions)::oo_jsClassName, OOJSObjectWrapperToString(), QuaternionConjugate(), QuaternionDot(), QuaternionMultiply(), QuaternionNormalize(), QuaternionRotate(), QuaternionRotateX(), QuaternionRotateY(), QuaternionRotateZ(), QuaternionToArray(), QuaternionToSource(), QuaternionToString(), QuaternionVectorForward(), QuaternionVectorRight(), QuaternionVectorUp(), ShipGroupAddShip(), ShipGroupRemoveShip(), SoundSourcePlay(), SoundSourceStop(), StationAbortAllDockings(), StationAbortDockingForShip(), StationAddShipToShipyard(), StationCanDockShip(), StationDecreaseAlertLevel(), StationDockPlayer(), StationIncreaseAlertLevel(), StationLaunchDefenseShip(), StationLaunchEscort(), StationLaunchMiner(), StationLaunchPatrol(), StationLaunchPirateShip(), StationLaunchPolice(), StationLaunchScavenger(), StationLaunchShipWithRole(), StationLaunchShuttle(), StationSetInterface(), StationSetMarketPrice(), StationSetMarketQuantity(), SunGoNova(), SystemInfoDistanceToSystem(), SystemInfoRouteToSystem(), SystemInfoSamplePrice(), SystemInfoSetPropertyMethod(), TimerStart(), VectorAdd(), VectorAngleTo(), VectorCross(), VectorDirection(), VectorDistanceTo(), VectorDot(), VectorFromCoordinateSystem(), VectorMagnitude(), VectorMultiply(), VectorRotateBy(), VectorRotationTo(), VectorSquaredDistanceTo(), VectorSquaredMagnitude(), VectorSubtract(), VectorToArray(), VectorToCoordinateSystem(), VectorToSource(), VectorToString(), and VectorTripleProduct().

◆ OOJSAddGCObjectRoot

#define OOJSAddGCObjectRoot ( context,
root,
name )   JS_AddNamedObjectRoot((context), (root), "" name)

◆ OOJSAddGCStringRoot

#define OOJSAddGCStringRoot ( context,
root,
name )   JS_AddNamedStringRoot((context), (root), "" name)

Definition at line 534 of file OOJavaScriptEngine.h.

◆ OOJSAddGCThingRoot

#define OOJSAddGCThingRoot ( context,
root,
name )   JS_AddNamedGCThingRoot((context), (root), "" name)

Definition at line 536 of file OOJavaScriptEngine.h.

◆ OOJSAddGCValueRoot

#define OOJSAddGCValueRoot ( context,
root,
name )   JS_AddNamedValueRoot((context), (root), "" name)

◆ OOJSENGINE_MONITOR_SUPPORT

#define OOJSENGINE_MONITOR_SUPPORT   OOLITE_DEBUG

Definition at line 33 of file OOJavaScriptEngine.h.

◆ OOJSSTR

#define OOJSSTR ( str)    ({ static jsval strCache; static BOOL inited; if (EXPECT_NOT(!inited)) OOJSStrLiteralCachePRIVATE(""str, &strCache, &inited); strCache; })

Definition at line 283 of file OOJavaScriptEngine.h.

Typedef Documentation

◆ OOJSClassConverterCallback

typedef id(* OOJSClassConverterCallback) (JSContext *context, JSObject *object)

Definition at line 512 of file OOJavaScriptEngine.h.

Function Documentation

◆ JSEntityIsDemoShipPredicate()

BOOL JSEntityIsDemoShipPredicate ( Entity * entity,
void * parameter )

Definition at line 2134 of file OOJavaScriptEngine.m.

2135{
2136 return ([entity isVisibleToScripts] && [entity isShip] && [entity status] == STATUS_COCKPIT_DISPLAY && ![entity isSubEntity]);
2137}

◆ JSEntityIsJavaScriptSearchablePredicate()

BOOL JSEntityIsJavaScriptSearchablePredicate ( Entity * entity,
void * parameter )

Definition at line 2100 of file OOJavaScriptEngine.m.

2101{
2103
2104 if (![entity isVisibleToScripts]) return NO;
2105 if ([entity isShip])
2106 {
2107 if ([entity isSubEntity]) return NO;
2108 if ([entity status] == STATUS_COCKPIT_DISPLAY) return NO; // Demo ship
2109 return YES;
2110 }
2111 else if ([entity isPlanet])
2112 {
2113 switch ([(OOPlanetEntity *)entity planetType])
2114 {
2115 case STELLAR_TYPE_MOON:
2117 case STELLAR_TYPE_SUN:
2118 return YES;
2119
2120#if !NEW_PLANETS
2122#endif
2124 return NO;
2125 }
2126 }
2127
2128 return YES; // would happen if we added a new script-visible class
2129
2131}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
@ STELLAR_TYPE_MOON
@ STELLAR_TYPE_ATMOSPHERE
@ STELLAR_TYPE_MINIATURE
@ STELLAR_TYPE_SUN
@ STELLAR_TYPE_NORMAL_PLANET

References OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, STELLAR_TYPE_ATMOSPHERE, STELLAR_TYPE_MINIATURE, STELLAR_TYPE_MOON, STELLAR_TYPE_NORMAL_PLANET, and STELLAR_TYPE_SUN.

Referenced by FindJSVisibleEntities().

+ Here is the caller graph for this function:

◆ JSEntityIsJavaScriptVisiblePredicate()

BOOL JSEntityIsJavaScriptVisiblePredicate ( Entity * entity,
void * parameter )

Definition at line 2090 of file OOJavaScriptEngine.m.

2091{
2093
2094 return [entity isVisibleToScripts];
2095
2097}

References Entity::isVisibleToScripts, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

+ Here is the call graph for this function:

◆ JSFunctionPredicate()

BOOL JSFunctionPredicate ( Entity * entity,
void * parameter )

Definition at line 2047 of file OOJavaScriptEngine.m.

2048{
2050
2051 JSFunctionPredicateParameter *param = parameter;
2052 jsval args[1];
2053 jsval rval = JSVAL_VOID;
2054 JSBool result = NO;
2055
2056 NSCParameterAssert(entity != nil && param != NULL);
2057 NSCParameterAssert(param->context != NULL && JS_IsInRequest(param->context));
2058 NSCParameterAssert(OOJSValueIsFunction(param->context, param->function));
2059
2060 if (EXPECT_NOT(param->errorFlag)) return NO;
2061
2062 args[0] = [entity oo_jsValueInContext:param->context]; // entity is required to be non-nil (asserted above), so oo_jsValueInContext: is safe.
2063
2066 BOOL success = JS_CallFunctionValue(param->context, param->jsThis, param->function, 1, args, &rval);
2069
2070 if (success)
2071 {
2072 if (!JS_ValueToBoolean(param->context, rval, &result)) result = NO;
2073 if (JS_IsExceptionPending(param->context))
2074 {
2075 JS_ReportPendingException(param->context);
2076 param->errorFlag = YES;
2077 }
2078 }
2079 else
2080 {
2081 param->errorFlag = YES;
2082 }
2083
2084 return result;
2085
2087}
#define OOJSStopTimeLimiter()
#define OOJSStartTimeLimiter()
void OOJSPauseTimeLimiter(void)
#define JS_IsInRequest(context)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
void OOJSResumeTimeLimiter(void)
return nil

References EXPECT_NOT, JS_IsInRequest, nil, Entity::oo_jsValueInContext:, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSPauseTimeLimiter(), OOJSResumeTimeLimiter(), OOJSStartTimeLimiter, OOJSStopTimeLimiter, and OOJSValueIsFunction().

Referenced by SystemFilteredEntities().

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

◆ OOJSAcquireContext()

OOINLINE JSContext * OOJSAcquireContext ( void )

Definition at line 118 of file OOJavaScriptEngine.h.

119{
120 extern JSContext *gOOJSMainThreadContext;
121 NSCAssert(gOOJSMainThreadContext != NULL, @"Attempt to use JavaScript context before JavaScript engine is initialized.");
124}
#define JS_BeginRequest(context)
JSContext * gOOJSMainThreadContext

References gOOJSMainThreadContext, and JS_BeginRequest.

Referenced by JSValueToStrDbg(), MissionRunCallback(), OOJSFrameCallbacksInvoke(), OOJSFrameCallbacksRemoveAll(), OOJSIDFromString(), OOJSInitJSIDCachePRIVATE(), OOJSStrLiteralCachePRIVATE(), OOStringFromDeciCredits(), OOStringFromJSID(), and SyntaxIssue().

+ Here is the caller graph for this function:

◆ OOJSArgumentListGetNumber()

BOOL OOJSArgumentListGetNumber ( JSContext * context,
NSString * scriptClass,
NSString * function,
uintN argc,
jsval * argv,
double * outNumber,
uintN * outConsumed )

Definition at line 1162 of file OOJavaScriptEngine.m.

1163{
1164 if (OOJSArgumentListGetNumberNoError(context, argc, argv, outNumber, outConsumed))
1165 {
1166 return YES;
1167 }
1168 else
1169 {
1170 OOJSReportBadArguments(context, scriptClass, function, argc, argv,
1171 @"Expected number, got", NULL);
1172 return NO;
1173 }
1174}
BOOL OOJSArgumentListGetNumberNoError(JSContext *context, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)

References OOJSArgumentListGetNumberNoError(), and OOJSReportBadArguments().

Referenced by QuaternionRotate(), QuaternionRotateX(), QuaternionRotateY(), QuaternionRotateZ(), SoundStaticPlayMusic(), VectorMultiply(), VectorRotationTo(), and VectorStaticInterpolate().

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

◆ OOJSArgumentListGetNumberNoError()

BOOL OOJSArgumentListGetNumberNoError ( JSContext * context,
uintN argc,
jsval * argv,
double * outNumber,
uintN * outConsumed )

Definition at line 1177 of file OOJavaScriptEngine.m.

1178{
1180
1181 double value;
1182
1183 NSCParameterAssert(context != NULL && (argv != NULL || argc == 0) && outNumber != NULL);
1184
1185 // Get value, if possible.
1186 if (EXPECT_NOT(!JS_ValueToNumber(context, argv[0], &value) || isnan(value)))
1187 {
1188 if (outConsumed != NULL) *outConsumed = 0;
1189 return NO;
1190 }
1191
1192 // Success.
1193 *outNumber = value;
1194 if (outConsumed != NULL) *outConsumed = 1;
1195 return YES;
1196
1198}

References EXPECT_NOT, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by OOJSArgumentListGetNumber(), VectorStaticRandom(), VectorStaticRandomDirection(), and VectorStaticRandomDirectionAndLength().

+ Here is the caller graph for this function:

◆ OOJSBasicPrivateObjectConverter()

id OOJSBasicPrivateObjectConverter ( JSContext * context,
JSObject * object )

Definition at line 2441 of file OOJavaScriptEngine.m.

2442{
2443 id result;
2444
2445 /* This will do the right thing - for non-OOWeakReferences,
2446 weakRefUnderlyingObject returns the object itself. For nil, of course,
2447 it returns nil.
2448 */
2449 result = JS_GetPrivate(context, object);
2450 return [result weakRefUnderlyingObject];
2451}

Referenced by InitOOJSConsole(), InitOOJSDock(), InitOOJSEntity(), InitOOJSEquipmentInfo(), InitOOJSExhaustPlume(), InitOOJSFlasher(), InitOOJSManifest(), InitOOJSPlanet(), InitOOJSPlayer(), InitOOJSPlayerShip(), InitOOJSScript(), InitOOJSShip(), InitOOJSShipGroup(), InitOOJSSound(), InitOOJSSoundSource(), InitOOJSStation(), InitOOJSSun(), InitOOJSSystemInfo(), InitOOJSTimer(), InitOOJSVisualEffect(), InitOOJSWaypoint(), and InitOOJSWormhole().

+ Here is the caller graph for this function:

◆ OOJSDescribeLocation()

NSString * OOJSDescribeLocation ( JSContext * context,
JSStackFrame * stackFrame )

Definition at line 894 of file OOJavaScriptEngine.m.

895{
896 NSCParameterAssert(context != NULL && stackFrame != NULL);
897
898 const char *fileName;
899 NSUInteger lineNo;
900 GetLocationNameAndLine(context, stackFrame, &fileName, &lineNo);
901 if (fileName == NULL) return nil;
902
903 // If this stops working, we probably need to switch to strcmp().
904 if (fileName == sConsoleScriptName && lineNo >= sConsoleEvalLineNo) return @"<console input>";
905
906 // Objectify it.
907 NSString *fileNameObj = [NSString stringWithUTF8String:fileName];
908 if (fileNameObj == nil) fileNameObj = [NSString stringWithCString:fileName encoding:NSISOLatin1StringEncoding];
909 if (fileNameObj == nil) return nil;
910
911 NSString *shortFileName = [fileNameObj lastPathComponent];
912 if (![[shortFileName lowercaseString] isEqualToString:@"script.js"]) fileNameObj = shortFileName;
913
914 return [NSString stringWithFormat:@"%@:%lu", fileNameObj, lineNo];
915}
static NSUInteger sConsoleEvalLineNo
static const char * sConsoleScriptName
static void GetLocationNameAndLine(JSContext *context, JSStackFrame *stackFrame, const char **name, NSUInteger *line)

References GetLocationNameAndLine(), nil, sConsoleEvalLineNo, and sConsoleScriptName.

Referenced by OOJSDumpStack().

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

◆ OOJSDescribeValue()

NSString * OOJSDescribeValue ( JSContext * context,
jsval value,
BOOL abbreviateObjects )

Definition at line 1736 of file OOJavaScriptEngine.m.

1737{
1738 return DescribeValue(context, value, abbreviateObjects, NO);
1739}
static NSString * DescribeValue(JSContext *context, jsval value, BOOL abbreviateObjects, BOOL recursing)

References DescribeValue().

Referenced by DumpVariable(), and OOJSReportBadPropertyValue().

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

◆ OOJSDictionaryFromJSObject()

NSDictionary * OOJSDictionaryFromJSObject ( JSContext * context,
JSObject * object )

Definition at line 2247 of file OOJavaScriptEngine.m.

2248{
2250
2251 JSIdArray *ids = NULL;
2252 jsint i;
2253 NSMutableDictionary *result = nil;
2254 jsval value = JSVAL_VOID;
2255 id objKey = nil;
2256 id objValue = nil;
2257
2258 ids = JS_Enumerate(context, object);
2259 if (EXPECT_NOT(ids == NULL))
2260 {
2261 return nil;
2262 }
2263
2264 result = [NSMutableDictionary dictionaryWithCapacity:ids->length];
2265 for (i = 0; i != ids->length; ++i)
2266 {
2267 jsid thisID = ids->vector[i];
2268
2269 if (JSID_IS_STRING(thisID))
2270 {
2271 objKey = OOStringFromJSString(context, JSID_TO_STRING(thisID));
2272 }
2273 else if (JSID_IS_INT(thisID))
2274 {
2275 /* this causes problems with native functions which expect string keys
2276 * e.g. in mission.runScreen with the 'choices' parameter
2277 * should this instead be making the objKey a string?
2278 * is there anything that relies on the current behaviour?
2279 * - CIM 15/2/13 */
2280 objKey = [NSNumber numberWithInt:JSID_TO_INT(thisID)];
2281 }
2282 else
2283 {
2284 objKey = nil;
2285 }
2286
2287 value = JSVAL_VOID;
2288 if (objKey != nil && !JS_LookupPropertyById(context, object, thisID, &value)) value = JSVAL_VOID;
2289
2290 if (objKey != nil && !JSVAL_IS_VOID(value))
2291 {
2292 objValue = OOJSNativeObjectFromJSValue(context, value);
2293 if (objValue != nil)
2294 {
2295 [result setObject:objValue forKey:objKey];
2296 }
2297 }
2298 }
2299
2300 JS_DestroyIdArray(context, ids);
2301 return result;
2302
2304}
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
NSString * OOStringFromJSString(JSContext *context, JSString *string)

References EXPECT_NOT, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSNativeObjectFromJSValue(), and OOStringFromJSString().

Referenced by OOJSDictionaryFromJSValue().

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

◆ OOJSDictionaryFromJSValue()

NSDictionary * OOJSDictionaryFromJSValue ( JSContext * context,
jsval value )

Definition at line 2232 of file OOJavaScriptEngine.m.

2233{
2235
2236 JSObject *object = NULL;
2237 if (EXPECT_NOT(!JS_ValueToObject(context, value, &object) || object == NULL))
2238 {
2239 return nil;
2240 }
2241 return OOJSDictionaryFromJSObject(context, object);
2242
2244}
NSDictionary * OOJSDictionaryFromJSObject(JSContext *context, JSObject *object)

References EXPECT_NOT, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJSDictionaryFromJSObject().

+ Here is the call graph for this function:

◆ OOJSDictionaryFromStringTable()

NSDictionary * OOJSDictionaryFromStringTable ( JSContext * context,
jsval value )

Definition at line 2307 of file OOJavaScriptEngine.m.

2308{
2310
2311 JSObject *tableObject = NULL;
2312 JSIdArray *ids;
2313 jsint i;
2314 NSMutableDictionary *result = nil;
2315 jsval value = JSVAL_VOID;
2316 id objKey = nil;
2317 id objValue = nil;
2318
2319 if (EXPECT_NOT(JSVAL_IS_NULL(tableValue) || !JS_ValueToObject(context, tableValue, &tableObject)))
2320 {
2321 return nil;
2322 }
2323
2324 ids = JS_Enumerate(context, tableObject);
2325 if (EXPECT_NOT(ids == NULL))
2326 {
2327 return nil;
2328 }
2329
2330 result = [NSMutableDictionary dictionaryWithCapacity:ids->length];
2331 for (i = 0; i != ids->length; ++i)
2332 {
2333 jsid thisID = ids->vector[i];
2334
2335 if (JSID_IS_STRING(thisID))
2336 {
2337 objKey = OOStringFromJSString(context, JSID_TO_STRING(thisID));
2338 }
2339 else
2340 {
2341 objKey = nil;
2342 }
2343
2344 value = JSVAL_VOID;
2345 if (objKey != nil && !JS_LookupPropertyById(context, tableObject, thisID, &value)) value = JSVAL_VOID;
2346
2347 if (objKey != nil && !JSVAL_IS_VOID(value))
2348 {
2349 objValue = OOStringFromJSValueEvenIfNull(context, value);
2350
2351 if (objValue != nil)
2352 {
2353 [result setObject:objValue forKey:objKey];
2354 }
2355 }
2356 }
2357
2358 JS_DestroyIdArray(context, ids);
2359 return result;
2360
2362}
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)

References EXPECT_NOT, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOStringFromJSString(), and OOStringFromJSValueEvenIfNull().

Referenced by GlobalExpandDescription(), and GlobalExpandMissionText().

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

◆ OOJSDumpStack()

void OOJSDumpStack ( JSContext * context)

Definition at line 737 of file OOJavaScriptEngine.m.

738{
739 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
740
741 @try
742 {
743 JSStackFrame *frame = NULL;
744 unsigned idx = 0;
745 unsigned skip = sErrorHandlerStackSkip;
746
747 while (JS_FrameIterator(context, &frame) != NULL)
748 {
749 JSScript *script = JS_GetFrameScript(context, frame);
750 NSString *desc = nil;
751 JSPropertyDescArray properties = { 0 , NULL };
752 BOOL gotProperties = NO;
753
754 idx++;
755
756 if (!JS_IsScriptFrame(context, frame))
757 {
758 continue;
759 }
760
761 if (skip != 0)
762 {
763 skip--;
764 continue;
765 }
766
767 if (script != NULL)
768 {
769 NSString *location = OOJSDescribeLocation(context, frame);
770 JSObject *scope = JS_GetFrameScopeChain(context, frame);
771
772 if (scope != NULL) gotProperties = JS_GetPropertyDescArray(context, scope, &properties);
773
774 NSString *funcDesc = nil;
775 JSFunction *function = JS_GetFrameFunction(context, frame);
776 if (function != NULL)
777 {
778 JSString *funcName = JS_GetFunctionId(function);
779 if (funcName != NULL)
780 {
781 funcDesc = OOStringFromJSString(context, funcName);
782 if (!JS_IsConstructorFrame(context, frame))
783 {
784 funcDesc = [funcDesc stringByAppendingString:@"()"];
785 }
786 else
787 {
788 funcDesc = [NSString stringWithFormat:@"new %@()", funcDesc];
789 }
790
791 }
792 else
793 {
794 funcDesc = @"<anonymous function>";
795 }
796 }
797 else
798 {
799 funcDesc = @"<not a function frame>";
800 }
801
802 desc = [NSString stringWithFormat:@"(%@) %@", location, funcDesc];
803 }
804 else if (JS_IsDebuggerFrame(context, frame))
805 {
806 desc = @"<debugger frame>";
807 }
808 else
809 {
810 desc = @"<Oolite native>";
811 }
812
813 OOLog(@"script.javaScript.stackTrace", @"%2u %@", idx - 1, desc);
814
815 if (gotProperties)
816 {
817 jsval this;
818 if (JS_GetFrameThis(context, frame, &this))
819 {
820 static BOOL haveThis = NO;
821 static jsval thisAtom;
822 if (EXPECT_NOT(!haveThis))
823 {
824 thisAtom = STRING_TO_JSVAL(JS_InternString(context, "this"));
825 haveThis = YES;
826 }
827 JSPropertyDesc thisDesc = { .id = thisAtom, .value = this };
828 DumpVariable(context, &thisDesc);
829 }
830
831 // Dump arguments.
832 unsigned i;
833 for (i = 0; i < properties.length; i++)
834 {
835 JSPropertyDesc *prop = &properties.array[i];
836 if (prop->flags & JSPD_ARGUMENT) DumpVariable(context, prop);
837 }
838
839 // Dump locals.
840 for (i = 0; i < properties.length; i++)
841 {
842 JSPropertyDesc *prop = &properties.array[i];
843 if (prop->flags & JSPD_VARIABLE) DumpVariable(context, prop);
844 }
845
846 // Dump anything else.
847 for (i = 0; i < properties.length; i++)
848 {
849 JSPropertyDesc *prop = &properties.array[i];
850 if (!(prop->flags & (JSPD_ARGUMENT | JSPD_VARIABLE))) DumpVariable(context, prop);
851 }
852
853 JS_PutPropertyDescArray(context, &properties);
854 }
855 }
856 }
857 @catch (NSException *exception)
858 {
859 OOLog(kOOLogException, @"Exception during JavaScript stack trace: %@:%@", [exception name], [exception reason]);
860 }
861
862 [pool release];
863}
static void DumpVariable(JSContext *context, JSPropertyDesc *prop)
static unsigned sErrorHandlerStackSkip
NSString * OOJSDescribeLocation(JSContext *context, JSStackFrame *stackFrame)
NSString *const kOOLogException
Definition OOLogging.m:651
#define OOLog(class, format,...)
Definition OOLogging.h:88

References DumpVariable(), EXPECT_NOT, kOOLogException, nil, OOJSDescribeLocation(), OOLog, OOStringFromJSString(), and sErrorHandlerStackSkip.

Referenced by NSString(OOJavaScriptExtensions)::concatenationOfStringsFromJavaScriptValues:count:separator:inContext:, OperationCallback(), and ReportJSError().

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

◆ OOJSGetClass()

OOINLINE JSClass * OOJSGetClass ( JSContext * cx,
JSObject * obj )

Definition at line 367 of file OOJavaScriptEngine.h.

368{
369#if JS_THREADSAFE
370 return JS_GetClass(cx, obj);
371#else
372 return JS_GetClass(obj);
373#endif
374}

Referenced by DescribeValue(), JSIDToStrSafeDbg(), JSValueTypeDbg(), OOJSIsMemberOfSubclass(), OOJSNativeObjectFromJSObject(), OOJSObjectGetterImplPRIVATE(), OOJSObjectWrapperToString(), OOJSReportBadPropertySelector(), and OOJSReportBadPropertyValue().

+ Here is the caller graph for this function:

◆ OOJSIDFromString()

jsid OOJSIDFromString ( NSString * string)

Definition at line 943 of file OOJavaScriptEngine.m.

944{
945 if (EXPECT_NOT(string == nil)) return JSID_VOID;
946
947 JSContext *context = OOJSAcquireContext();
948
949 enum { kStackBufSize = 1024 };
950 unichar stackBuf[kStackBufSize];
951 unichar *buffer;
952 size_t length = [string length];
953 if (length < kStackBufSize)
954 {
955 buffer = stackBuf;
956 }
957 else
958 {
959 buffer = malloc(sizeof (unichar) * length);
960 if (EXPECT_NOT(buffer == NULL)) return JSID_VOID;
961 }
962 [string getCharacters:buffer];
963
964 JSString *jsString = JS_InternUCStringN(context, buffer, length);
965
966 if (EXPECT_NOT(buffer != stackBuf)) free(buffer);
967
968 OOJSRelinquishContext(context);
969
970 if (EXPECT(jsString != NULL)) return INTERNED_STRING_TO_JSID(jsString);
971 else return JSID_VOID;
972}
#define EXPECT(x)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)

References EXPECT, EXPECT_NOT, nil, OOJSAcquireContext(), and OOJSRelinquishContext().

Referenced by JSObjectFromNSDictionary().

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

◆ OOJSIsMemberOfSubclass()

OOINLINE BOOL OOJSIsMemberOfSubclass ( JSContext * context,
JSObject * object,
JSClass * superclass )

Definition at line 494 of file OOJavaScriptEngine.h.

495{
496 return OOJSIsSubclass(OOJSGetClass(context, object), superclass);
497}
BOOL OOJSIsSubclass(JSClass *putativeSubclass, JSClass *superclass)
OOINLINE JSClass * OOJSGetClass(JSContext *cx, JSObject *obj) ALWAYS_INLINE_FUNC

References OOJSGetClass(), and OOJSIsSubclass().

Referenced by JSObjectGetQuaternion(), and JSObjectGetVector().

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

◆ OOJSIsSubclass()

BOOL OOJSIsSubclass ( JSClass * putativeSubclass,
JSClass * superclass )

Definition at line 2163 of file OOJavaScriptEngine.m.

2164{
2165 NSCParameterAssert(putativeSubclass != NULL && superclass != NULL);
2166 NSCAssert(sRegisteredSubClasses != NULL, @"OOJSIsSubclass() called before any subclasses registered (disallowed for hot path efficiency).");
2167
2168 do
2169 {
2170 if (putativeSubclass == superclass) return YES;
2171
2172 putativeSubclass = NSMapGet(sRegisteredSubClasses, putativeSubclass);
2173 }
2174 while (putativeSubclass != NULL);
2175
2176 return NO;
2177}
static NSMapTable * sRegisteredSubClasses

References sRegisteredSubClasses.

Referenced by OOJSIsMemberOfSubclass(), and OOJSObjectGetterImplPRIVATE().

+ Here is the caller graph for this function:

◆ OOJSMarkConsoleEvalLocation()

void OOJSMarkConsoleEvalLocation ( JSContext * context,
JSStackFrame * stackFrame )

Definition at line 918 of file OOJavaScriptEngine.m.

919{
921}

References GetLocationNameAndLine(), sConsoleEvalLineNo, and sConsoleScriptName.

Referenced by SpecialMarkConsoleEntryPoint().

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

◆ OOJSNativeObjectFromJSObject()

id OOJSNativeObjectFromJSObject ( JSContext * context,
JSObject * object )

Definition at line 2400 of file OOJavaScriptEngine.m.

2401{
2403
2404 NSValue *wrappedClass = nil;
2405 NSValue *wrappedConverter = nil;
2406 OOJSClassConverterCallback converter = NULL;
2407 JSClass *class = NULL;
2408
2409 if (tableObject == NULL) return nil;
2410
2411 class = OOJSGetClass(context, tableObject);
2412 wrappedClass = [NSValue valueWithPointer:class];
2413 if (wrappedClass != nil) wrappedConverter = [sObjectConverters objectForKey:wrappedClass];
2414 if (wrappedConverter != nil)
2415 {
2416 converter = [wrappedConverter pointerValue];
2417 return converter(context, tableObject);
2418 }
2419 return nil;
2420
2422}
id(* OOJSClassConverterCallback)(JSContext *context, JSObject *object)
static NSMutableDictionary * sObjectConverters

References nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJSGetClass().

Referenced by ConsoleClearConsole(), ConsoleSettingsDeleteProperty(), ConsoleSettingsGetProperty(), ConsoleSettingsSetProperty(), GetParameterDictionary(), GlobalSetExtraGuiScreenKeys(), MissionMarkSystem(), MissionUnmarkSystem(), OOJSNativeObjectFromJSValue(), OOJSNativeObjectOfClassFromJSObject(), OOJSObjectWrapperToString(), ShipSetCrew(), ShipSetMaterialsInternal(), ShipStaticSetShipDataForKey(), StationAddShipToShipyard(), SystemSetPopulator(), and VisualEffectSetMaterialsInternal().

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

◆ OOJSNativeObjectFromJSValue()

id OOJSNativeObjectFromJSValue ( JSContext * context,
jsval value )

Definition at line 2368 of file OOJavaScriptEngine.m.

2369{
2371
2372 if (JSVAL_IS_NULL(value) || JSVAL_IS_VOID(value)) return nil;
2373
2374 if (JSVAL_IS_INT(value))
2375 {
2376 return [NSNumber numberWithInt:JSVAL_TO_INT(value)];
2377 }
2378 if (JSVAL_IS_DOUBLE(value))
2379 {
2380 return [NSNumber numberWithDouble:JSVAL_TO_DOUBLE(value)];
2381 }
2382 if (JSVAL_IS_BOOLEAN(value))
2383 {
2384 return [NSNumber numberWithBool:JSVAL_TO_BOOLEAN(value)];
2385 }
2386 if (JSVAL_IS_STRING(value))
2387 {
2388 return OOStringFromJSValue(context, value);
2389 }
2390 if (JSVAL_IS_OBJECT(value))
2391 {
2392 return OOJSNativeObjectFromJSObject(context, JSVAL_TO_OBJECT(value));
2393 }
2394 return nil;
2395
2397}
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *tableObject)
NSString * OOStringFromJSValue(JSContext *context, jsval value)

References nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSNativeObjectFromJSObject(), and OOStringFromJSValue().

Referenced by ConsoleSettingsSetProperty(), JSArrayConverter(), JSValueToEquipmentKeyRelaxed(), MissionSetInstructionsInternal(), OOJSDictionaryFromJSObject(), OOJSNativeObjectOfClassFromJSValue(), OoliteCompareVersion(), PlayerSetEscapePodDestination(), PlayerShipSetCustomHUDDial(), ShipRunLegacyScriptActions(), SystemInfoSetPropertyMethod(), and SystemInfoStaticSetInterstellarProperty().

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

◆ OOJSNativeObjectOfClassFromJSObject()

id OOJSNativeObjectOfClassFromJSObject ( JSContext * context,
JSObject * object,
Class requiredClass )

Definition at line 2433 of file OOJavaScriptEngine.m.

2434{
2435 id result = OOJSNativeObjectFromJSObject(context, object);
2436 if (![result isKindOfClass:requiredClass]) result = nil;
2437 return result;
2438}

References nil, and OOJSNativeObjectFromJSObject().

Referenced by ConsoleConsoleMessage(), ScriptAddProperty(), SystemInfoGetProperty(), and SystemInfoSetProperty().

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

◆ OOJSNativeObjectOfClassFromJSValue()

id OOJSNativeObjectOfClassFromJSValue ( JSContext * context,
jsval value,
Class requiredClass )

Definition at line 2425 of file OOJavaScriptEngine.m.

2426{
2427 id result = OOJSNativeObjectFromJSValue(context, value);
2428 if (![result isKindOfClass:requiredClass]) result = nil;
2429 return result;
2430}

References nil, and OOJSNativeObjectFromJSValue().

Referenced by OOShipGroup(OOJavaScriptExtensions)::oo_clearJSSelf:, PlayerShipCancelDockingRequest(), PlayerShipEngageAutopilotToStation(), PlayerShipRequestDockingClearance(), ShipGroupAddShip(), ShipGroupConstruct(), ShipGroupRemoveShip(), ShipGroupSetProperty(), ShipSetProperty(), and SoundFromJSValue().

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

◆ OOJSObjectFromNativeObject()

JSObject * OOJSObjectFromNativeObject ( JSContext * context,
id object )

Definition at line 1442 of file OOJavaScriptEngine.m.

1443{
1444 jsval value = OOJSValueFromNativeObject(context, object);
1445 JSObject *result = NULL;
1446 if (JS_ValueToObject(context, value, &result)) return result;
1447 return NULL;
1448}
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)

References OOJSValueFromNativeObject().

+ Here is the call graph for this function:

◆ OOJSObjectGetterImplPRIVATE()

BOOL OOJSObjectGetterImplPRIVATE ( JSContext * context,
JSObject * object,
JSClass * requiredJSClass,
Class requiredObjCClass,
const char * name,
id * outObject )

Definition at line 2180 of file OOJavaScriptEngine.m.

2185{
2186#ifndef NDEBUG
2187 OOJS_PROFILE_ENTER_NAMED(name)
2188 NSCParameterAssert(requiredObjCClass != Nil);
2189 NSCParameterAssert(context != NULL && object != NULL && requiredJSClass != NULL && outObject != NULL);
2190#else
2192#endif
2193
2194 /*
2195 Ensure it's a valid type of JS object. This is absolutely necessary,
2196 because if we don't check it we'll crash trying to get the private
2197 field of something that isn't an ObjC object wrapper - for example,
2198 Ship.setAI.call(new Vector3D, "") is valid JavaScript.
2199
2200 Alternatively, we could abuse JSCLASS_PRIVATE_IS_NSISUPPORTS as a
2201 flag for ObjC object wrappers (SpiderMonkey only uses it internally
2202 in a debug function we don't use), but we'd still need to do an
2203 Objective-C class test, and I don't think that's any faster.
2204 TODO: profile.
2205 */
2206 JSClass *actualClass = OOJSGetClass(context, object);
2207 if (EXPECT_NOT(!OOJSIsSubclass(actualClass, requiredJSClass)))
2208 {
2209 OOJSReportError(context, @"Native method expected %s, got %@.", requiredJSClass->name, OOStringFromJSValue(context, OBJECT_TO_JSVAL(object)));
2210 return NO;
2211 }
2212 NSCAssert(actualClass->flags & JSCLASS_HAS_PRIVATE, @"Native object accessor requires JS class with private storage.");
2213
2214 // Get the underlying object.
2215 *outObject = [(id)JS_GetPrivate(context, object) weakRefUnderlyingObject];
2216
2217#ifndef NDEBUG
2218 // Double-check that the underlying object is of the expected ObjC class.
2219 if (EXPECT_NOT(*outObject != nil && ![*outObject isKindOfClass:requiredObjCClass]))
2220 {
2221 OOJSReportError(context, @"Native method expected %@ from %s and got correct JS type but incorrect native object %@", requiredObjCClass, requiredJSClass->name, *outObject);
2222 return NO;
2223 }
2224#endif
2225
2226 return YES;
2227
2229}
void OOJSReportError(JSContext *context, NSString *format,...)
BOOL OOJSIsSubclass(JSClass *putativeSubclass, JSClass *superclass)

References EXPECT_NOT, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSGetClass(), OOJSIsSubclass(), OOJSReportError(), and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ OOJSObjectWrapperFinalize()

void OOJSObjectWrapperFinalize ( JSContext * context,
JSObject * this )

Definition at line 2001 of file OOJavaScriptEngine.m.

2002{
2004
2005 id object = JS_GetPrivate(context, this);
2006 if (object != nil)
2007 {
2008 [[object weakRefUnderlyingObject] oo_clearJSSelf:this];
2009 [object release];
2010 JS_SetPrivate(context, this, nil);
2011 }
2012
2014}
#define OOJS_PROFILE_EXIT_VOID

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT_VOID.

◆ OOJSObjectWrapperToString()

JSBool OOJSObjectWrapperToString ( JSContext * context,
uintN argc,
jsval * vp )

Definition at line 2017 of file OOJavaScriptEngine.m.

2018{
2019 OOJS_NATIVE_ENTER(context)
2020
2021 id object = nil;
2022 NSString *description = nil;
2023 JSClass *jsClass = NULL;
2024
2025 object = OOJSNativeObjectFromJSObject(context, OOJS_THIS);
2026 if (object != nil)
2027 {
2028 description = [object oo_jsDescription];
2029 if (description == nil) description = [object description];
2030 }
2031 if (description == nil)
2032 {
2033 jsClass = OOJSGetClass(context, OOJS_THIS);
2034 if (jsClass != NULL)
2035 {
2036 description = [NSString stringWithFormat:@"[object %@]", [NSString stringWithUTF8String:jsClass->name]];
2037 }
2038 }
2039 if (description == nil) description = @"[object]";
2040
2041 OOJS_RETURN_OBJECT(description);
2042
2044}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_THIS
#define OOJS_RETURN_OBJECT(o)

References nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJS_THIS, OOJSGetClass(), and OOJSNativeObjectFromJSObject().

+ Here is the call graph for this function:

◆ OOJSPauseTimeLimiter()

void OOJSPauseTimeLimiter ( void )

◆ OOJSRegisterObjectConverter()

void OOJSRegisterObjectConverter ( JSClass * theClass,
OOJSClassConverterCallback converter )

Definition at line 2454 of file OOJavaScriptEngine.m.

2455{
2456 NSValue *wrappedClass = nil;
2457 NSValue *wrappedConverter = nil;
2458
2459 if (theClass == NULL) return;
2460 if (sObjectConverters == nil) sObjectConverters = [[NSMutableDictionary alloc] init];
2461
2462 wrappedClass = [NSValue valueWithPointer:theClass];
2463 if (converter != NULL)
2464 {
2465 wrappedConverter = [NSValue valueWithPointer:converter];
2466 [sObjectConverters setObject:wrappedConverter forKey:wrappedClass];
2467 }
2468 else
2469 {
2470 [sObjectConverters removeObjectForKey:wrappedClass];
2471 }
2472}

References nil, and sObjectConverters.

Referenced by InitOOJSConsole(), InitOOJSDock(), InitOOJSEntity(), InitOOJSEquipmentInfo(), InitOOJSExhaustPlume(), InitOOJSFlasher(), InitOOJSManifest(), InitOOJSMissionVariables(), InitOOJSPlanet(), InitOOJSPlayer(), InitOOJSPlayerShip(), InitOOJSScript(), InitOOJSShip(), InitOOJSShipGroup(), InitOOJSSound(), InitOOJSSoundSource(), InitOOJSStation(), InitOOJSSun(), InitOOJSSystemInfo(), InitOOJSTimer(), InitOOJSVisualEffect(), InitOOJSWaypoint(), and InitOOJSWormhole().

+ Here is the caller graph for this function:

◆ OOJSRegisterSubclass()

void OOJSRegisterSubclass ( JSClass * subclass,
JSClass * superclass )

Definition at line 2141 of file OOJavaScriptEngine.m.

2142{
2143 NSCParameterAssert(subclass != NULL && superclass != NULL);
2144
2145 if (sRegisteredSubClasses == NULL)
2146 {
2147 sRegisteredSubClasses = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0);
2148 }
2149
2150 NSCAssert(NSMapGet(sRegisteredSubClasses, subclass) == NULL, @"A JS class cannot be registered as a subclass of multiple classes.");
2151
2152 NSMapInsertKnownAbsent(sRegisteredSubClasses, subclass, superclass);
2153}

References sRegisteredSubClasses.

Referenced by InitOOJSDock(), InitOOJSExhaustPlume(), InitOOJSFlasher(), InitOOJSPlanet(), InitOOJSPlayerShip(), InitOOJSShip(), InitOOJSStation(), InitOOJSSun(), InitOOJSVisualEffect(), InitOOJSWaypoint(), and InitOOJSWormhole().

+ Here is the caller graph for this function:

◆ OOJSRelinquishContext()

OOINLINE void OOJSRelinquishContext ( JSContext * context)

Definition at line 128 of file OOJavaScriptEngine.h.

129{
130#ifndef NDEBUG
131 extern JSContext *gOOJSMainThreadContext;
132 NSCParameterAssert(context == gOOJSMainThreadContext && JS_IsInRequest(context));
133#endif
134 JS_EndRequest(context);
135}
#define JS_EndRequest(context)

References gOOJSMainThreadContext, JS_EndRequest, and JS_IsInRequest.

Referenced by JSValueToStrDbg(), MissionRunCallback(), OOJSFrameCallbacksInvoke(), OOJSFrameCallbacksRemoveAll(), OOJSIDFromString(), OOJSInitJSIDCachePRIVATE(), OOJSStrLiteralCachePRIVATE(), OOStringFromDeciCredits(), OOStringFromJSID(), and SyntaxIssue().

+ Here is the caller graph for this function:

◆ OOJSReportBadArguments()

void OOJSReportBadArguments ( JSContext * context,
NSString * scriptClass,
NSString * function,
uintN argc,
jsval * argv,
NSString * message,
NSString * expectedArgsDescription )

Definition at line 1139 of file OOJavaScriptEngine.m.

1140{
1141 @try
1142 {
1143 if (message == nil) message = @"Invalid arguments";
1144 message = [NSString stringWithFormat:@"%@ %@", message, [NSString stringWithJavaScriptParameters:argv count:argc inContext:context]];
1145 if (expectedArgsDescription != nil) message = [NSString stringWithFormat:@"%@ -- expected %@", message, expectedArgsDescription];
1146
1147 OOJSReportErrorForCaller(context, scriptClass, function, @"%@.", message);
1148 }
1149 @catch (id exception)
1150 {
1151 // Squash any secondary errors during error handling.
1152 }
1153}
void OOJSReportErrorForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
unsigned count

References nil, and OOJSReportErrorForCaller().

Referenced by ClockAddSeconds(), ClockClockStringForTime(), OOManifest::dealloc, FontMeasureString(), DockEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, StationEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, GetRelativeToAndRange(), GetThisQuaternion(), GetThisVector(), GlobalAddFrameCallback(), GlobalAutoAIForRole(), GlobalClearExtraGuiScreenKeys(), GlobalDisplayNameForCommodity(), GlobalExpandDescription(), GlobalExpandMissionText(), GlobalGetGuiColorSettingForKey(), GlobalGetScreenBackgroundForKey(), GlobalIsValidFrameCallback(), GlobalKeyBindingDescription(), GlobalRandomInhabitantsDescription(), GlobalRemoveFrameCallback(), GlobalSetExtraGuiScreenKeys(), GlobalSetGuiColorSettingForKey(), GlobalSetScreenBackground(), GlobalSetScreenBackgroundForKey(), GlobalSetScreenOverlay(), GlobalTakeSnapShot(), PlayerEntity(OOJavaScriptExtensions)::javaScriptEngineWillReset:, ManifestComment(), ManifestSetComment(), ManifestShortComment(), MissionMarkSystem(), MissionRunScreen(), MissionSetInstructionsInternal(), MissionUnmarkSystem(), OOEquipmentType(OOJavaScriptExtensions)::oo_clearJSSelf:, OOShipGroup(OOJavaScriptExtensions)::oo_clearJSSelf:, OOSound(OOJavaScriptExtentions)::oo_jsClassName, OOJSArgumentListGetNumber(), PlayerAddMessageToArrivalReport(), PlayerAudioMessage(), PlayerCommsMessage(), PlayerConsoleMessage(), PlayerEndScenario(), PlayerReplaceShip(), PlayerSetEscapePodDestination(), PlayerSetPlayerRole(), PlayerShipAddParcel(), PlayerShipAddPassenger(), PlayerShipAwardContract(), PlayerShipAwardEquipmentToCurrentPylon(), PlayerShipBeginGalacticHyperspaceCountdown(), PlayerShipBeginHyperspaceCountdown(), PlayerShipCancelDockingRequest(), PlayerShipEngageAutopilotToStation(), PlayerShipHideHUDSelector(), PlayerShipRemoveContract(), PlayerShipRemoveParcel(), PlayerShipRemovePassenger(), PlayerShipRequestDockingClearance(), PlayerShipSetCustomHUDDial(), PlayerShipSetCustomView(), PlayerShipSetMultiFunctionDisplay(), PlayerShipSetMultiFunctionText(), PlayerShipSetPrimedEquipment(), PlayerShipShowHUDSelector(), PlayerShipUseSpecialCargo(), QuaternionConstruct(), QuaternionFromArgumentList(), ShipAddCargoEntity(), ShipAddCollisionException(), ShipAddDefenseTarget(), ShipAdjustCargo(), ShipAwardEquipment(), ShipCanAwardEquipment(), ShipCheckScanner(), ShipCommsMessage(), ShipDealEnergyDamage(), ShipDumpCargo(), ShipEjectItem(), ShipEjectSpecificItem(), ShipEnterWormhole(), ShipEquipmentStatus(), ShipExitSystem(), ShipGroupAddShip(), ShipGroupConstruct(), ShipGroupRemoveShip(), ShipHasEquipmentProviding(), ShipHasRole(), ShipOfferToEscort(), ShipPatrolReportIn(), ShipReactToAIMessage(), ShipRemove(), ShipRemoveCollisionException(), ShipRemoveDefenseTarget(), ShipRemoveEquipment(), ShipRunLegacyScriptActions(), ShipSendAIMessage(), ShipSetAI(), ShipSetBounty(), ShipSetCargo(), ShipSetCargoType(), ShipSetCrew(), ShipSetEquipmentStatus(), ShipSetMaterials(), ShipSetScript(), ShipSetShaders(), ShipSpawn(), ShipStaticKeysForRole(), ShipStaticRoleIsInCategory(), ShipStaticSetShipDataForKey(), ShipStaticShipDataForKey(), ShipSwitchAI(), ShipThreatAssessment(), SoundSourcePlay(), SoundStaticLoad(), SoundStaticPlayMusic(), SpecialJSWarning(), StationAbortDockingForShip(), StationAddShipToShipyard(), StationCanDockShip(), StationLaunchShipWithRole(), StationSetInterface(), StationSetMarketPrice(), StationSetMarketQuantity(), SystemAddMoon(), SystemAddPlanet(), SystemAddShipsOrGroup(), SystemAddShipsOrGroupToRoute(), SystemAddVisualEffect(), SystemCountEntitiesWithScanClass(), SystemCountShipsWithPrimaryRole(), SystemCountShipsWithRole(), SystemEntitiesWithScanClass(), SystemFilteredEntities(), SystemInfoDistanceToSystem(), SystemInfoRouteToSystem(), SystemInfoSamplePrice(), SystemInfoSetPropertyMethod(), SystemInfoStaticFilteredSystems(), SystemInfoStaticSetInterstellarProperty(), SystemLegacyAddShips(), SystemLegacyAddShipsAt(), SystemLegacyAddShipsAtPrecisely(), SystemLegacyAddShipsWithinRadius(), SystemLegacyAddSystemShips(), SystemLegacySpawnShip(), SystemLocationFromCode(), SystemSetPopulator(), SystemSetWaypoint(), SystemShipsWithPrimaryRole(), SystemShipsWithRole(), SystemStaticInfoForSystem(), SystemStaticSystemIDForName(), SystemStaticSystemNameForID(), TimerConstruct(), VectorConstruct(), VectorFromArgumentList(), VectorFromCoordinateSystem(), VectorStaticInterpolate(), VectorToCoordinateSystem(), VisualEffectScale(), VisualEffectSetMaterials(), and VisualEffectSetShaders().

+ Here is the call graph for this function:

◆ OOJSReportBadPropertySelector()

void OOJSReportBadPropertySelector ( JSContext * context,
JSObject * thisObj,
jsid propID,
JSPropertySpec * propertySpec )

Definition at line 1120 of file OOJavaScriptEngine.m.

1121{
1122 NSString *propName = OOStringFromJSPropertyIDAndSpec(context, propID, propertySpec);
1123 const char *className = OOJSGetClass(context, thisObj)->name;
1124
1125 OOJSReportError(context, @"Invalid property identifier %@ for instance of %s.", propName, className);
1126}
NSString * OOStringFromJSPropertyIDAndSpec(JSContext *context, jsid propID, JSPropertySpec *propertySpec)

References OOJSGetClass(), OOJSReportError(), and OOStringFromJSPropertyIDAndSpec().

Referenced by ClockGetProperty(), ConsoleGetProperty(), ConsoleSetProperty(), DockGetProperty(), DockSetProperty(), EntityGetProperty(), EntitySetProperty(), EquipmentInfoGetProperty(), EquipmentInfoSetProperty(), ExhaustPlumeGetProperty(), ExhaustPlumeSetProperty(), FlasherGetProperty(), FlasherSetProperty(), OOPlanetEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, OOWaypointEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, WormholeEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, GlobalGetProperty(), GlobalSetProperty(), ManifestGetProperty(), MissionGetProperty(), MissionSetProperty(), OoliteGetProperty(), PlanetGetProperty(), PlayerGetProperty(), PlayerSetProperty(), PlayerShipGetProperty(), PlayerShipSetProperty(), QuaternionGetProperty(), QuaternionSetProperty(), ShipGetProperty(), ShipGroupGetProperty(), ShipGroupSetProperty(), ShipSetProperty(), SoundGetProperty(), SoundSourceGetProperty(), SoundSourceSetProperty(), StationGetProperty(), StationSetProperty(), SunGetProperty(), SystemGetProperty(), SystemInfoGetProperty(), SystemSetProperty(), TimerGetProperty(), TimerSetProperty(), VectorGetProperty(), VectorSetProperty(), VisualEffectGetProperty(), VisualEffectSetProperty(), WaypointGetProperty(), and WormholeGetProperty().

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

◆ OOJSReportBadPropertyValue()

void OOJSReportBadPropertyValue ( JSContext * context,
JSObject * thisObj,
jsid propID,
JSPropertySpec * propertySpec,
jsval value )

Definition at line 1129 of file OOJavaScriptEngine.m.

1130{
1131 NSString *propName = OOStringFromJSPropertyIDAndSpec(context, propID, propertySpec);
1132 const char *className = OOJSGetClass(context, thisObj)->name;
1133 NSString *valueDesc = OOJSDescribeValue(context, value, YES);
1134
1135 OOJSReportError(context, @"Cannot set property %@ of instance of %s to invalid value %@.", propName, className, valueDesc);
1136}
NSString * OOJSDescribeValue(JSContext *context, jsval value, BOOL abbreviateObjects)

References OOJSDescribeValue(), OOJSGetClass(), OOJSReportError(), and OOStringFromJSPropertyIDAndSpec().

Referenced by DockSetProperty(), EntitySetProperty(), EquipmentInfoSetProperty(), ExhaustPlumeSetProperty(), FlasherSetProperty(), OOPlanetEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, OOWaypointEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, WormholeEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, GlobalSetProperty(), ManifestSetProperty(), MissionSetProperty(), PlayerSetProperty(), PlayerShipSetProperty(), QuaternionSetProperty(), ShipGroupSetProperty(), ShipSetProperty(), SoundSourceSetProperty(), StationSetProperty(), SystemSetProperty(), TimerSetProperty(), VectorSetProperty(), and VisualEffectSetProperty().

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

◆ OOJSReportError()

void OOJSReportError ( JSContext * context,
NSString * format,
... )

Definition at line 1000 of file OOJavaScriptEngine.m.

1001{
1002 va_list args;
1003
1004 va_start(args, format);
1005 OOJSReportErrorWithArguments(context, format, args);
1006 va_end(args);
1007}
void OOJSReportErrorWithArguments(JSContext *context, NSString *format, va_list args)

References OOJSReportErrorWithArguments().

Referenced by ConsoleClearConsole(), ConsoleConsoleMessage(), ConsoleSettingsDeleteProperty(), ConsoleSettingsGetProperty(), ConsoleSettingsSetProperty(), EntitySetProperty(), GlobalAddFrameCallback(), MissionVariablesSetProperty(), OOJSCallObjCObjectMethod(), OOJSObjectGetterImplPRIVATE(), OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOJSReportErrorForCaller(), OOJSReportWrappedException(), OOJSUnconstructableConstruct(), PlayerReplaceShip(), PlayerSetEscapePodDestination(), PlayerShipRemoveAllCargo(), PlayerShipResetCustomView(), PlayerShipSetCustomView(), PlayerShipSetProperty(), RemoveOrExplodeShip(), ShipAdjustCargo(), ShipEnterWormhole(), ShipGroupConstruct(), ShipRemove(), ShipSetProperty(), SoundSourceConstruct(), SystemInfoGetProperty(), and TimerConstruct().

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

◆ OOJSReportErrorForCaller()

void OOJSReportErrorForCaller ( JSContext * context,
NSString * scriptClass,
NSString * function,
NSString * format,
... )

Definition at line 1010 of file OOJavaScriptEngine.m.

1011{
1012 va_list args;
1013 NSString *msg = nil;
1014
1015 @try
1016 {
1017 va_start(args, format);
1018 msg = [[NSString alloc] initWithFormat:format arguments:args];
1019 va_end(args);
1020
1021 OOJSReportError(context, @"%@%@", CallerPrefix(scriptClass, function), msg);
1022 }
1023 @catch (id exception)
1024 {
1025 // Squash any secondary errors during error handling.
1026 }
1027 [msg release];
1028}
static NSString * CallerPrefix(NSString *scriptClass, NSString *function)

References CallerPrefix(), nil, and OOJSReportError().

Referenced by OOJSReportBadArguments(), ShipExitAI(), ShipExitSystem(), ShipReactToAIMessage(), ShipSendAIMessage(), ShipSetAI(), ShipSetEquipmentStatus(), ShipSetScript(), ShipSwitchAI(), SystemInfoDistanceToSystem(), SystemInfoRouteToSystem(), and SystemInfoSamplePrice().

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

◆ OOJSReportErrorWithArguments()

void OOJSReportErrorWithArguments ( JSContext * context,
NSString * format,
va_list args )

Definition at line 1031 of file OOJavaScriptEngine.m.

1032{
1033 NSString *msg = nil;
1034
1035 NSCParameterAssert(JS_IsInRequest(context));
1036
1037 @try
1038 {
1039 msg = [[NSString alloc] initWithFormat:format arguments:args];
1040 JS_ReportError(context, "%s", [msg UTF8String]);
1041 }
1042 @catch (id exception)
1043 {
1044 // Squash any secondary errors during error handling.
1045 }
1046 [msg release];
1047}

References JS_IsInRequest, and nil.

Referenced by OOJSReportError().

+ Here is the caller graph for this function:

◆ OOJSReportWarning()

void OOJSReportWarning ( JSContext * context,
NSString * format,
... )

Definition at line 1072 of file OOJavaScriptEngine.m.

1073{
1074 va_list args;
1075
1076 va_start(args, format);
1077 OOJSReportWarningWithArguments(context, format, args);
1078 va_end(args);
1079}
void OOJSReportWarningWithArguments(JSContext *context, NSString *format, va_list args)

References OOJSReportWarningWithArguments().

Referenced by ConsoleConsoleMessage(), ConsoleSettingsSetProperty(), EntityFromArgumentList(), EquipmentInfoSetProperty(), OOPlanetEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, GetJSSystemInfoForSystem(), GlobalRemoveFrameCallback(), GlobalSetScreenBackground(), GlobalSetScreenOverlay(), GlobalTakeSnapShot(), ManifestSetProperty(), MissionRunScreen(), MissionRunShipLibrary(), MissionSetInstructionsInternal(), OOJSReportWarningForCaller(), PlayerShipSetProperty(), ScriptAddProperty(), ShipFireECM(), ShipSetMaterialsInternal(), ShipSetShaders(), SpecialJSWarning(), TimerSetProperty(), VisualEffectSetMaterialsInternal(), and VisualEffectSetShaders().

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

◆ OOJSReportWarningForCaller()

void OOJSReportWarningForCaller ( JSContext * context,
NSString * scriptClass,
NSString * function,
NSString * format,
... )

Definition at line 1082 of file OOJavaScriptEngine.m.

1083{
1084 va_list args;
1085 NSString *msg = nil;
1086
1087 @try
1088 {
1089 va_start(args, format);
1090 msg = [[NSString alloc] initWithFormat:format arguments:args];
1091 va_end(args);
1092
1093 OOJSReportWarning(context, @"%@%@", CallerPrefix(scriptClass, function), msg);
1094 }
1095 @catch (id exception)
1096 {
1097 // Squash any secondary errors during error handling.
1098 }
1099 [msg release];
1100}
void OOJSReportWarning(JSContext *context, NSString *format,...)

References CallerPrefix(), nil, and OOJSReportWarning().

Referenced by StationEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, ShipAddCargoEntity(), ShipDumpCargo(), ShipExitAI(), ShipGroupAddShip(), ShipSetEquipmentStatus(), and StationAddShipToShipyard().

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

◆ OOJSReportWarningWithArguments()

void OOJSReportWarningWithArguments ( JSContext * context,
NSString * format,
va_list args )

Definition at line 1103 of file OOJavaScriptEngine.m.

1104{
1105 NSString *msg = nil;
1106
1107 @try
1108 {
1109 msg = [[NSString alloc] initWithFormat:format arguments:args];
1110 JS_ReportWarning(context, "%s", [msg UTF8String]);
1111 }
1112 @catch (id exception)
1113 {
1114 // Squash any secondary errors during error handling.
1115 }
1116 [msg release];
1117}

References nil.

Referenced by OOJSReportWarning(), and SyntaxIssue().

+ Here is the caller graph for this function:

◆ OOJSResumeTimeLimiter()

void OOJSResumeTimeLimiter ( void )

Definition at line 143 of file OOJSEngineTimeManagement.m.

144{
145 if (--sLimiterPauseDepth == 0)
146
147 {
151
152 sLimiterTimeLimit += elapsed;
153 }
154}
static double sLimiterTimeLimit
OOTimeDelta OOHighResTimeDeltaInSeconds(OOHighResTimeValue startTime, OOHighResTimeValue endTime)
uint64_t OOHighResTimeValue
double OOTimeDelta
Definition OOTypes.h:224

References OODisposeHighResTime, OOGetHighResTime, OOHighResTimeDeltaInSeconds(), sLimiterPauseDepth, sLimiterPauseStart, and sLimiterTimeLimit.

Referenced by NSString(OOJavaScriptExtensions)::concatenationOfStringsFromJavaScriptValues:count:separator:inContext:, ConsoleConsoleMessage(), ConsoleIsExecutableJavaScript(), ConsoleSettingsSetProperty(), OOPlanetEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, JSFunctionPredicate(), MissionRunScreen(), ReportJSError(), SoundFromJSValue(), SystemFilteredEntities(), and SystemInfoStaticFilteredSystems().

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

◆ OOJSSetWarningOrErrorStackSkip()

void OOJSSetWarningOrErrorStackSkip ( unsigned skip)

Definition at line 1156 of file OOJavaScriptEngine.m.

1157{
1159}

References sErrorHandlerStackSkip.

Referenced by SpecialJSWarning().

+ Here is the caller graph for this function:

◆ OOJSStrLiteralCachePRIVATE()

void OOJSStrLiteralCachePRIVATE ( const char * string,
jsval * strCache,
BOOL * inited )

Definition at line 1543 of file OOJavaScriptEngine.m.

1544{
1545 NSCParameterAssert(string != NULL && strCache != NULL && inited != NULL && !*inited);
1546
1547 JSContext *context = OOJSAcquireContext();
1548
1549 JSString *jsString = JS_InternString(context, string);
1550 if (EXPECT_NOT(string == NULL))
1551 {
1552 [NSException raise:NSGenericException format:@"Failed to initialize JavaScript string literal cache for \"%@\".", [[NSString stringWithUTF8String:string] escapedForJavaScriptLiteral]];
1553 }
1554
1555 *strCache = STRING_TO_JSVAL(jsString);
1556 *inited = YES;
1557
1558 OOJSRelinquishContext(context);
1559}

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

+ Here is the call graph for this function:

◆ OOJSUnconstructableConstruct()

JSBool OOJSUnconstructableConstruct ( JSContext * context,
uintN argc,
jsval * vp )

Definition at line 1987 of file OOJavaScriptEngine.m.

1988{
1989 OOJS_NATIVE_ENTER(context)
1990
1991 JSFunction *function = JS_ValueToFunction(context, JS_CALLEE(context, vp));
1992 NSString *name = OOStringFromJSString(context, JS_GetFunctionId(function));
1993
1994 OOJSReportError(context, @"%@ cannot be used as a constructor.", name);
1995 return NO;
1996
1998}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportError(), and OOStringFromJSString().

Referenced by InitOOJSClock(), InitOOJSConsole(), InitOOJSDock(), InitOOJSEntity(), InitOOJSEquipmentInfo(), InitOOJSExhaustPlume(), InitOOJSFlasher(), InitOOJSManifest(), InitOOJSMission(), InitOOJSOolite(), InitOOJSPlanet(), InitOOJSPlayer(), InitOOJSPlayerShip(), InitOOJSScript(), InitOOJSShip(), InitOOJSSound(), InitOOJSStation(), InitOOJSSun(), InitOOJSSystem(), InitOOJSSystemInfo(), InitOOJSVisualEffect(), InitOOJSWaypoint(), and InitOOJSWormhole().

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

◆ OOJSValueFromBOOL()

OOINLINE jsval OOJSValueFromBOOL ( int b)

Definition at line 189 of file OOJavaScriptEngine.h.

190{
191 return BOOLEAN_TO_JSVAL(b != NO);
192}

Referenced by ClockGetProperty(), ConsoleGetProperty(), DockGetProperty(), EntityGetProperty(), EquipmentInfoGetProperty(), FlasherGetProperty(), OOStringFromDeciCredits(), PlanetGetProperty(), PlayerGetProperty(), PlayerShipGetProperty(), ShipGetProperty(), SoundSourceGetProperty(), StationGetProperty(), SunGetProperty(), SystemGetProperty(), TimerGetProperty(), and VisualEffectGetProperty().

+ Here is the caller graph for this function:

◆ OOJSValueFromNativeObject()

OOINLINE jsval OOJSValueFromNativeObject ( JSContext * context,
id object )

◆ OOJSValueIsArray()

OOINLINE BOOL OOJSValueIsArray ( JSContext * context,
jsval value )

Definition at line 397 of file OOJavaScriptEngine.h.

398{
399 return JSVAL_IS_OBJECT(value) && !JSVAL_IS_NULL(value) && JS_IsArrayObject(context, JSVAL_TO_OBJECT(value));
400}

◆ OOJSValueIsFunction()

OOINLINE BOOL OOJSValueIsFunction ( JSContext * context,
jsval value )

Definition at line 383 of file OOJavaScriptEngine.h.

384{
385 return JSVAL_IS_OBJECT(value) && !JSVAL_IS_NULL(value) && JS_ObjectIsFunction(context, JSVAL_TO_OBJECT(value));
386}

Referenced by DescribeValue(), GlobalAddFrameCallback(), GlobalSetExtraGuiScreenKeys(), JSFunctionPredicate(), MissionRunScreen(), StationSetInterface(), SystemFilteredEntities(), and SystemInfoStaticFilteredSystems().

+ Here is the caller graph for this function:

◆ OOStringFromJSID()

NSString * OOStringFromJSID ( jsid propID)

Definition at line 975 of file OOJavaScriptEngine.m.

976{
977 JSContext *context = OOJSAcquireContext();
978
979 jsval value;
980 NSString *result = nil;
981 if (JS_IdToValue(context, propID, &value))
982 {
983 result = OOStringFromJSString(context, JS_ValueToString(context, value));
984 }
985
986 OOJSRelinquishContext(context);
987
988 return result;
989}

References nil, OOJSAcquireContext(), OOJSRelinquishContext(), and OOStringFromJSString().

Referenced by MissionVariablesSetProperty().

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

◆ OOStringFromJSPropertyIDAndSpec()

NSString * OOStringFromJSPropertyIDAndSpec ( JSContext * context,
jsid propID,
JSPropertySpec * propertySpec )

Definition at line 1611 of file OOJavaScriptEngine.m.

1612{
1613 if (JSID_IS_STRING(propID))
1614 {
1615 return OOStringFromJSString(context, JSID_TO_STRING(propID));
1616 }
1617 else if (JSID_IS_INT(propID) && propertySpec != NULL)
1618 {
1619 int tinyid = JSID_TO_INT(propID);
1620
1621 while (propertySpec->name != NULL)
1622 {
1623 if (propertySpec->tinyid == tinyid) return [NSString stringWithUTF8String:propertySpec->name];
1624 propertySpec++;
1625 }
1626 }
1627
1628 jsval value;
1629 if (!JS_IdToValue(context, propID, &value)) return @"unknown";
1630 return OOStringFromJSString(context, JS_ValueToString(context, value));
1631}

References OOStringFromJSString().

Referenced by OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), and ShipSetProperty().

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

◆ OOStringFromJSString()

NSString * OOStringFromJSString ( JSContext * context,
JSString * string )

Definition at line 1562 of file OOJavaScriptEngine.m.

1563{
1565
1566 if (EXPECT_NOT(string == NULL)) return nil;
1567
1568 size_t length;
1569 const jschar *chars = JS_GetStringCharsAndLength(context, string, &length);
1570
1571 if (EXPECT(chars != NULL))
1572 {
1573 return [NSString stringWithCharacters:chars length:length];
1574 }
1575 else
1576 {
1577 return nil;
1578 }
1579
1581}

References EXPECT, EXPECT_NOT, nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by ConsoleSettingsDeleteProperty(), ConsoleSettingsGetProperty(), ConsoleSettingsSetProperty(), KeyForPropertyID(), ManifestGetProperty(), ManifestSetProperty(), OOJSDictionaryFromJSObject(), OOJSDictionaryFromStringTable(), OOJSDumpStack(), OOJSUnconstructableConstruct(), OOStringFromJSID(), OOStringFromJSPropertyIDAndSpec(), OOStringFromJSValueEvenIfNull(), SystemInfoGetProperty(), SystemInfoSetProperty(), and WorldScriptsGetProperty().

+ Here is the caller graph for this function:

◆ OOStringFromJSValue()

NSString * OOStringFromJSValue ( JSContext * context,
jsval value )

Definition at line 1597 of file OOJavaScriptEngine.m.

1598{
1600
1601 if (EXPECT(!JSVAL_IS_NULL(value) && !JSVAL_IS_VOID(value)))
1602 {
1603 return OOStringFromJSValueEvenIfNull(context, value);
1604 }
1605 return nil;
1606
1608}

References EXPECT, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOStringFromJSValueEvenIfNull().

Referenced by ConsoleConsoleMessage(), ConsoleDisplayMessagesInClass(), ConsoleIsExecutableJavaScript(), ConsoleSetDisplayMessagesInClass(), ConsoleSetProperty(), ConsoleSettingsSetProperty(), OOManifest::dealloc, FontMeasureString(), OOPlanetEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, OOWaypointEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, GetParameterString(), GlobalAutoAIForRole(), GlobalClearExtraGuiScreenKeys(), GlobalDisplayNameForCommodity(), GlobalExpandDescription(), GlobalExpandMissionText(), GlobalGetGuiColorSettingForKey(), GlobalGetScreenBackgroundForKey(), GlobalKeyBindingDescription(), GlobalLog(), GlobalSetExtraGuiScreenKeys(), GlobalSetGuiColorSettingForKey(), GlobalSetScreenBackgroundForKey(), GlobalTakeSnapShot(), JSStringConverter(), JSValueToEquipmentType(), ManifestComment(), ManifestSetComment(), ManifestShortComment(), MissionAddMessageText(), MissionRunScreen(), MissionSetInstructionsInternal(), MissionVariablesSetProperty(), OOEquipmentType(OOJavaScriptExtensions)::oo_clearJSSelf:, OOSound(OOJavaScriptExtentions)::oo_jsClassName, OOJSCallObjCObjectMethod(), OOJSNativeObjectFromJSValue(), OOJSObjectGetterImplPRIVATE(), OOStringFromDeciCredits(), PlayerAddMessageToArrivalReport(), PlayerAudioMessage(), PlayerCommsMessage(), PlayerConsoleMessage(), PlayerEndScenario(), PlayerReplaceShip(), PlayerSetPlayerRole(), PlayerSetProperty(), PlayerShipAddParcel(), PlayerShipAddPassenger(), PlayerShipAwardContract(), PlayerShipHideHUDSelector(), PlayerShipRemoveContract(), PlayerShipRemoveParcel(), PlayerShipRemovePassenger(), PlayerShipSetCustomHUDDial(), PlayerShipSetCustomView(), PlayerShipSetMultiFunctionDisplay(), PlayerShipSetMultiFunctionText(), PlayerShipSetPrimedEquipment(), PlayerShipSetProperty(), PlayerShipShowHUDSelector(), PlayerShipUseSpecialCargo(), ShipAdjustCargo(), ShipCanAwardEquipment(), ShipCommsMessage(), ShipDumpCargo(), ShipEjectItem(), ShipEjectSpecificItem(), ShipExitAI(), ShipGroupConstruct(), ShipHasEquipmentProviding(), ShipHasRole(), ShipReactToAIMessage(), ShipSendAIMessage(), ShipSetAI(), ShipSetBounty(), ShipSetCargo(), ShipSetCargoType(), ShipSetEquipmentStatus(), ShipSetProperty(), ShipSetScript(), ShipSpawn(), ShipStaticKeysForRole(), ShipStaticRoleIsInCategory(), ShipStaticSetShipDataForKey(), ShipStaticShipDataForKey(), ShipSwitchAI(), SoundFromJSValue(), SoundStaticLoad(), SoundStaticPlayMusic(), SpecialJSWarning(), StationLaunchShipWithRole(), StationSetInterface(), StationSetMarketPrice(), StationSetMarketQuantity(), StationSetProperty(), SystemAddMoon(), SystemAddPlanet(), SystemAddShipsOrGroup(), SystemAddShipsOrGroupToRoute(), SystemAddVisualEffect(), SystemCountShipsWithPrimaryRole(), SystemCountShipsWithRole(), SystemInfoRouteToSystem(), SystemInfoSamplePrice(), SystemInfoSetPropertyMethod(), SystemInfoStaticSetInterstellarProperty(), SystemLegacyAddShips(), SystemLegacyAddShipsAt(), SystemLegacyAddShipsAtPrecisely(), SystemLegacyAddShipsWithinRadius(), SystemLegacyAddSystemShips(), SystemLegacySpawnShip(), SystemLocationFromCode(), SystemSetPopulator(), SystemSetProperty(), SystemSetWaypoint(), SystemShipsWithPrimaryRole(), SystemShipsWithRole(), SystemStaticSystemIDForName(), VectorFromCoordinateSystem(), VectorToCoordinateSystem(), and VisualEffectSetProperty().

+ Here is the call graph for this function:

◆ OOStringFromJSValueEvenIfNull()

NSString * OOStringFromJSValueEvenIfNull ( JSContext * context,
jsval value )

Definition at line 1584 of file OOJavaScriptEngine.m.

1585{
1587
1588 NSCParameterAssert(context != NULL && JS_IsInRequest(context));
1589
1590 JSString *string = JS_ValueToString(context, value); // Calls the value's toString method if needed.
1591 return OOStringFromJSString(context, string);
1592
1594}

References JS_IsInRequest, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOStringFromJSString().

Referenced by DescribeValue(), DumpVariable(), GlobalLog(), MissionSetInstructionsInternal(), OOJSDictionaryFromStringTable(), OOStringFromJSValue(), ShipSetMaterialsInternal(), ShipSetShaders(), VisualEffectSetMaterialsInternal(), and VisualEffectSetShaders().

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

Variable Documentation

◆ kOOJavaScriptEngineDidResetNotification

NSString* const kOOJavaScriptEngineDidResetNotification
extern

Definition at line 101 of file OOJavaScriptEngine.m.

◆ kOOJavaScriptEngineWillResetNotification

NSString* const kOOJavaScriptEngineWillResetNotification
extern

Definition at line 100 of file OOJavaScriptEngine.m.