Oolite
Loading...
Searching...
No Matches
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.

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.

◆ JS_EndRequest

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

Definition at line 113 of file OOJavaScriptEngine.h.

◆ JS_IsInRequest

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

Definition at line 111 of file OOJavaScriptEngine.h.

◆ OOJS_ARGV

#define OOJS_ARGV   JS_ARGV(context, vp)

Definition at line 661 of file OOJavaScriptEngine.h.

◆ OOJS_METHOD_READONLY

#define OOJS_METHOD_READONLY   OOJS_PROP_HIDDEN_READONLY

Definition at line 647 of file OOJavaScriptEngine.h.

◆ 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)

Definition at line 640 of file OOJavaScriptEngine.h.

◆ OOJS_PROP_READONLY_CB

#define OOJS_PROP_READONLY_CB   (OOJS_PROP_READONLY | JSPROP_SHARED)

Definition at line 651 of file OOJavaScriptEngine.h.

◆ 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.

◆ OOJS_RETURN_BOOL

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

Definition at line 669 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN_DOUBLE

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

Definition at line 683 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN_HPVECTOR

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

Definition at line 681 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN_INT

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

Definition at line 670 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN_JSOBJECT

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

Definition at line 666 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN_NULL

#define OOJS_RETURN_NULL   OOJS_RETURN(JSVAL_NULL)

Definition at line 668 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN_OBJECT

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

Definition at line 671 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN_QUATERNION

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

Definition at line 682 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN_VECTOR

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

Definition at line 680 of file OOJavaScriptEngine.h.

◆ OOJS_RETURN_VOID

#define OOJS_RETURN_VOID   OOJS_RETURN(JSVAL_VOID)

Definition at line 667 of file OOJavaScriptEngine.h.

◆ 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.

674 { \
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.

◆ OOJS_SET_RVAL

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

Definition at line 663 of file OOJavaScriptEngine.h.

◆ OOJS_THIS

#define OOJS_THIS   JS_THIS_OBJECT(context, vp)

Definition at line 660 of file OOJavaScriptEngine.h.

◆ OOJSAddGCObjectRoot

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

Definition at line 535 of file OOJavaScriptEngine.h.

◆ 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)

Definition at line 533 of file OOJavaScriptEngine.h.

◆ 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 2133 of file OOJavaScriptEngine.m.

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

◆ JSEntityIsJavaScriptSearchablePredicate()

BOOL JSEntityIsJavaScriptSearchablePredicate ( Entity entity,
void *  parameter 
)

Definition at line 2099 of file OOJavaScriptEngine.m.

2100{
2102
2103 if (![entity isVisibleToScripts]) return NO;
2104 if ([entity isShip])
2105 {
2106 if ([entity isSubEntity]) return NO;
2107 if ([entity status] == STATUS_COCKPIT_DISPLAY) return NO; // Demo ship
2108 return YES;
2109 }
2110 else if ([entity isPlanet])
2111 {
2112 switch ([(OOPlanetEntity *)entity planetType])
2113 {
2114 case STELLAR_TYPE_MOON:
2116 case STELLAR_TYPE_SUN:
2117 return YES;
2118
2119#if !NEW_PLANETS
2121#endif
2123 return NO;
2124 }
2125 }
2126
2127 return YES; // would happen if we added a new script-visible class
2128
2130}
#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 2089 of file OOJavaScriptEngine.m.

2090{
2092
2093 return [entity isVisibleToScripts];
2094
2096}

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 2046 of file OOJavaScriptEngine.m.

2047{
2049
2050 JSFunctionPredicateParameter *param = parameter;
2051 jsval args[1];
2052 jsval rval = JSVAL_VOID;
2053 JSBool result = NO;
2054
2055 NSCParameterAssert(entity != nil && param != NULL);
2056 NSCParameterAssert(param->context != NULL && JS_IsInRequest(param->context));
2057 NSCParameterAssert(OOJSValueIsFunction(param->context, param->function));
2058
2059 if (EXPECT_NOT(param->errorFlag)) return NO;
2060
2061 args[0] = [entity oo_jsValueInContext:param->context]; // entity is required to be non-nil (asserted above), so oo_jsValueInContext: is safe.
2062
2065 BOOL success = JS_CallFunctionValue(param->context, param->jsThis, param->function, 1, args, &rval);
2068
2069 if (success)
2070 {
2071 if (!JS_ValueToBoolean(param->context, rval, &result)) result = NO;
2072 if (JS_IsExceptionPending(param->context))
2073 {
2074 JS_ReportPendingException(param->context);
2075 param->errorFlag = YES;
2076 }
2077 }
2078 else
2079 {
2080 param->errorFlag = YES;
2081 }
2082
2083 return result;
2084
2086}
#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 2440 of file OOJavaScriptEngine.m.

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

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:@"%@:%llu", 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 1735 of file OOJavaScriptEngine.m.

1736{
1737 return DescribeValue(context, value, abbreviateObjects, NO);
1738}
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 2246 of file OOJavaScriptEngine.m.

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

2232{
2234
2235 JSObject *object = NULL;
2236 if (EXPECT_NOT(!JS_ValueToObject(context, value, &object) || object == NULL))
2237 {
2238 return nil;
2239 }
2240 return OOJSDictionaryFromJSObject(context, object);
2241
2243}
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 2306 of file OOJavaScriptEngine.m.

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

2163{
2164 NSCParameterAssert(putativeSubclass != NULL && superclass != NULL);
2165 NSCAssert(sRegisteredSubClasses != NULL, @"OOJSIsSubclass() called before any subclasses registered (disallowed for hot path efficiency).");
2166
2167 do
2168 {
2169 if (putativeSubclass == superclass) return YES;
2170
2171 putativeSubclass = NSMapGet(sRegisteredSubClasses, putativeSubclass);
2172 }
2173 while (putativeSubclass != NULL);
2174
2175 return NO;
2176}
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 2399 of file OOJavaScriptEngine.m.

2400{
2402
2403 NSValue *wrappedClass = nil;
2404 NSValue *wrappedConverter = nil;
2405 OOJSClassConverterCallback converter = NULL;
2406 JSClass *class = NULL;
2407
2408 if (tableObject == NULL) return nil;
2409
2410 class = OOJSGetClass(context, tableObject);
2411 wrappedClass = [NSValue valueWithPointer:class];
2412 if (wrappedClass != nil) wrappedConverter = [sObjectConverters objectForKey:wrappedClass];
2413 if (wrappedConverter != nil)
2414 {
2415 converter = [wrappedConverter pointerValue];
2416 return converter(context, tableObject);
2417 }
2418 return nil;
2419
2421}
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 2367 of file OOJavaScriptEngine.m.

2368{
2370
2371 if (JSVAL_IS_NULL(value) || JSVAL_IS_VOID(value)) return nil;
2372
2373 if (JSVAL_IS_INT(value))
2374 {
2375 return [NSNumber numberWithInt:JSVAL_TO_INT(value)];
2376 }
2377 if (JSVAL_IS_DOUBLE(value))
2378 {
2379 return [NSNumber numberWithDouble:JSVAL_TO_DOUBLE(value)];
2380 }
2381 if (JSVAL_IS_BOOLEAN(value))
2382 {
2383 return [NSNumber numberWithBool:JSVAL_TO_BOOLEAN(value)];
2384 }
2385 if (JSVAL_IS_STRING(value))
2386 {
2387 return OOStringFromJSValue(context, value);
2388 }
2389 if (JSVAL_IS_OBJECT(value))
2390 {
2391 return OOJSNativeObjectFromJSObject(context, JSVAL_TO_OBJECT(value));
2392 }
2393 return nil;
2394
2396}
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 2432 of file OOJavaScriptEngine.m.

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

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 2424 of file OOJavaScriptEngine.m.

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

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 1441 of file OOJavaScriptEngine.m.

1442{
1443 jsval value = OOJSValueFromNativeObject(context, object);
1444 JSObject *result = NULL;
1445 if (JS_ValueToObject(context, value, &result)) return result;
1446 return NULL;
1447}
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 2179 of file OOJavaScriptEngine.m.

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

2001{
2003
2004 id object = JS_GetPrivate(context, this);
2005 if (object != nil)
2006 {
2007 [[object weakRefUnderlyingObject] oo_clearJSSelf:this];
2008 [object release];
2009 JS_SetPrivate(context, this, nil);
2010 }
2011
2013}
#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 2016 of file OOJavaScriptEngine.m.

2017{
2018 OOJS_NATIVE_ENTER(context)
2019
2020 id object = nil;
2021 NSString *description = nil;
2022 JSClass *jsClass = NULL;
2023
2024 object = OOJSNativeObjectFromJSObject(context, OOJS_THIS);
2025 if (object != nil)
2026 {
2027 description = [object oo_jsDescription];
2028 if (description == nil) description = [object description];
2029 }
2030 if (description == nil)
2031 {
2032 jsClass = OOJSGetClass(context, OOJS_THIS);
2033 if (jsClass != NULL)
2034 {
2035 description = [NSString stringWithFormat:@"[object %@]", [NSString stringWithUTF8String:jsClass->name]];
2036 }
2037 }
2038 if (description == nil) description = @"[object]";
2039
2040 OOJS_RETURN_OBJECT(description);
2041
2043}
#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 2453 of file OOJavaScriptEngine.m.

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

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 2140 of file OOJavaScriptEngine.m.

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

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(), OoliteSetProperty(), 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(), OoliteSetProperty(), 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(), OoliteSetProperty(), 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 1542 of file OOJavaScriptEngine.m.

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

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 1986 of file OOJavaScriptEngine.m.

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

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()

◆ 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 1610 of file OOJavaScriptEngine.m.

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

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 1561 of file OOJavaScriptEngine.m.

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

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 1596 of file OOJavaScriptEngine.m.

1597{
1599
1600 if (EXPECT(!JSVAL_IS_NULL(value) && !JSVAL_IS_VOID(value)))
1601 {
1602 return OOStringFromJSValueEvenIfNull(context, value);
1603 }
1604 return nil;
1605
1607}

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(), OoliteSetProperty(), 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 1583 of file OOJavaScriptEngine.m.

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

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.