Oolite
Loading...
Searching...
No Matches
OOJavaScriptEngine.m File Reference
#include <jsdbgapi.h>
import "OOJavaScriptEngine.h"
import "OOJSEngineTimeManagement.h"
import "OOJSScript.h"
import "OOCollectionExtractors.h"
import "Universe.h"
import "OOPlanetEntity.h"
import "NSStringOOExtensions.h"
import "OOWeakReference.h"
import "EntityOOJavaScriptExtensions.h"
import "ResourceManager.h"
import "NSNumberOOExtensions.h"
import "OOConstToJSString.h"
import "OOVisualEffectEntity.h"
import "OOWaypointEntity.h"
import "OOJSGlobal.h"
import "OOJSMissionVariables.h"
import "OOJSMission.h"
import "OOJSVector.h"
import "OOJSQuaternion.h"
import "OOJSEntity.h"
import "OOJSShip.h"
import "OOJSStation.h"
import "OOJSDock.h"
import "OOJSVisualEffect.h"
import "OOJSExhaustPlume.h"
import "OOJSFlasher.h"
import "OOJSWormhole.h"
import "OOJSWaypoint.h"
import "OOJSPlayer.h"
import "OOJSPlayerShip.h"
import "OOJSManifest.h"
import "OOJSPlanet.h"
import "OOJSSystem.h"
import "OOJSOolite.h"
import "OOJSTimer.h"
import "OOJSClock.h"
import "OOJSSun.h"
import "OOJSWorldScripts.h"
import "OOJSSound.h"
import "OOJSSoundSource.h"
import "OOJSSpecialFunctions.h"
import "OOJSSystemInfo.h"
import "OOJSEquipmentInfo.h"
import "OOJSShipGroup.h"
import "OOJSFrameCallbacks.h"
import "OOJSFont.h"
import "OOProfilingStopwatch.h"
import "OOLoggingExtended.h"
#include <stdlib.h>
+ Include dependency graph for OOJavaScriptEngine.m:

Go to the source code of this file.

Classes

category  OOJavaScriptEngine(Private)
 

Macros

#define OOJSENGINE_JSVERSION   JSVERSION_ECMA_5
 
#define JIT_OPTIONS   JSOPTION_JIT | JSOPTION_METHODJIT | JSOPTION_PROFILING
 
#define OOJSENGINE_CONTEXT_OPTIONS   JSOPTION_VAROBJFIX | JSOPTION_RELIMIT | JSOPTION_ANONFUNFIX | JIT_OPTIONS
 
#define OOJS_STACK_SIZE   8192
 
#define OOJS_RUNTIME_SIZE_MiB   256
 

Functions

static void ReportJSError (JSContext *context, const char *message, JSErrorReport *report)
 
static id JSArrayConverter (JSContext *context, JSObject *object)
 
static id JSStringConverter (JSContext *context, JSObject *object)
 
static id JSNumberConverter (JSContext *context, JSObject *object)
 
static id JSBooleanConverter (JSContext *context, JSObject *object)
 
static void UnregisterObjectConverters (void)
 
static void UnregisterSubclasses (void)
 
static void DumpVariable (JSContext *context, JSPropertyDesc *prop)
 
void OOJSDumpStack (JSContext *context)
 
static void GetLocationNameAndLine (JSContext *context, JSStackFrame *stackFrame, const char **name, NSUInteger *line)
 
NSString * OOJSDescribeLocation (JSContext *context, JSStackFrame *stackFrame)
 
void OOJSMarkConsoleEvalLocation (JSContext *context, JSStackFrame *stackFrame)
 
void OOJSInitJSIDCachePRIVATE (const char *name, jsid *idCache)
 
jsid OOJSIDFromString (NSString *string)
 
NSString * OOStringFromJSID (jsid propID)
 
static NSString * CallerPrefix (NSString *scriptClass, NSString *function)
 
void OOJSReportError (JSContext *context, NSString *format,...)
 
void OOJSReportErrorForCaller (JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
 
void OOJSReportErrorWithArguments (JSContext *context, NSString *format, va_list args)
 
void OOJSReportWrappedException (JSContext *context, id exception)
 
void OOJSUnreachable (const char *function, const char *file, unsigned line)
 
void OOJSReportWarning (JSContext *context, NSString *format,...)
 
void OOJSReportWarningForCaller (JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
 
void OOJSReportWarningWithArguments (JSContext *context, NSString *format, va_list args)
 
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)
 
static JSObject * JSArrayFromNSArray (JSContext *context, NSArray *array)
 
static BOOL JSNewNSArrayValue (JSContext *context, NSArray *array, jsval *value)
 
static JSObject * JSObjectFromNSDictionary (JSContext *context, NSDictionary *dictionary)
 
static BOOL JSNewNSDictionaryValue (JSContext *context, NSDictionary *dictionary, jsval *value)
 
JSObject * OOJSObjectFromNativeObject (JSContext *context, id object)
 
void OOJSStrLiteralCachePRIVATE (const char *string, jsval *strCache, BOOL *inited)
 
NSString * OOStringFromJSString (JSContext *context, JSString *string)
 
NSString * OOStringFromJSValueEvenIfNull (JSContext *context, jsval value)
 
NSString * OOStringFromJSValue (JSContext *context, jsval value)
 
NSString * OOStringFromJSPropertyIDAndSpec (JSContext *context, jsid propID, JSPropertySpec *propertySpec)
 
static NSString * DescribeValue (JSContext *context, jsval value, BOOL abbreviateObjects, BOOL recursing)
 
NSString * OOJSDescribeValue (JSContext *context, jsval value, BOOL abbreviateObjects)
 
JSBool OOJSUnconstructableConstruct (JSContext *context, uintN argc, jsval *vp)
 
void OOJSObjectWrapperFinalize (JSContext *context, JSObject *this)
 
JSBool OOJSObjectWrapperToString (JSContext *context, uintN argc, jsval *vp)
 
BOOL JSFunctionPredicate (Entity *entity, void *parameter)
 
BOOL JSEntityIsJavaScriptVisiblePredicate (Entity *entity, void *parameter)
 
BOOL JSEntityIsJavaScriptSearchablePredicate (Entity *entity, void *parameter)
 
BOOL JSEntityIsDemoShipPredicate (Entity *entity, void *parameter)
 
void OOJSRegisterSubclass (JSClass *subclass, JSClass *superclass)
 
BOOL OOJSIsSubclass (JSClass *putativeSubclass, JSClass *superclass)
 
BOOL OOJSObjectGetterImplPRIVATE (JSContext *context, JSObject *object, JSClass *requiredJSClass, Class requiredObjCClass, const char *name, id *outObject)
 
NSDictionary * OOJSDictionaryFromJSValue (JSContext *context, jsval value)
 
NSDictionary * OOJSDictionaryFromJSObject (JSContext *context, JSObject *object)
 
NSDictionary * OOJSDictionaryFromStringTable (JSContext *context, jsval tableValue)
 
id OOJSNativeObjectFromJSValue (JSContext *context, jsval value)
 
id OOJSNativeObjectFromJSObject (JSContext *context, JSObject *tableObject)
 
id OOJSNativeObjectOfClassFromJSValue (JSContext *context, jsval value, Class requiredClass)
 
id OOJSNativeObjectOfClassFromJSObject (JSContext *context, JSObject *object, Class requiredClass)
 
id OOJSBasicPrivateObjectConverter (JSContext *context, JSObject *object)
 
void OOJSRegisterObjectConverter (JSClass *theClass, OOJSClassConverterCallback converter)
 

Variables

static OOJavaScriptEnginesSharedEngine = nil
 
static unsigned sErrorHandlerStackSkip = 0
 
JSContext * gOOJSMainThreadContext = NULL
 
NSString *const kOOJavaScriptEngineWillResetNotification = @"org.aegidian.oolite OOJavaScriptEngine will reset"
 
NSString *const kOOJavaScriptEngineDidResetNotification = @"org.aegidian.oolite OOJavaScriptEngine did reset"
 
static const char * sConsoleScriptName
 
static NSUInteger sConsoleEvalLineNo
 
static NSMapTable * sRegisteredSubClasses
 
static NSMutableDictionary * sObjectConverters
 

Macro Definition Documentation

◆ JIT_OPTIONS

#define JIT_OPTIONS   JSOPTION_JIT | JSOPTION_METHODJIT | JSOPTION_PROFILING

Definition at line 85 of file OOJavaScriptEngine.m.

◆ OOJS_RUNTIME_SIZE_MiB

#define OOJS_RUNTIME_SIZE_MiB   256

Definition at line 91 of file OOJavaScriptEngine.m.

◆ OOJS_STACK_SIZE

#define OOJS_STACK_SIZE   8192

Definition at line 90 of file OOJavaScriptEngine.m.

◆ OOJSENGINE_CONTEXT_OPTIONS

#define OOJSENGINE_CONTEXT_OPTIONS   JSOPTION_VAROBJFIX | JSOPTION_RELIMIT | JSOPTION_ANONFUNFIX | JIT_OPTIONS

Definition at line 87 of file OOJavaScriptEngine.m.

◆ OOJSENGINE_JSVERSION

#define OOJSENGINE_JSVERSION   JSVERSION_ECMA_5

Definition at line 81 of file OOJavaScriptEngine.m.

Function Documentation

◆ CallerPrefix()

static NSString * CallerPrefix ( NSString *  scriptClass,
NSString *  function 
)
static

Definition at line 992 of file OOJavaScriptEngine.m.

993{
994 if (function == nil) return @"";
995 if (scriptClass == nil) return [function stringByAppendingString:@": "];
996 return [NSString stringWithFormat:@"%@.%@: ", scriptClass, function];
997}
return nil

References nil.

Referenced by OOJSReportErrorForCaller(), and OOJSReportWarningForCaller().

+ Here is the caller graph for this function:

◆ DescribeValue()

static NSString * DescribeValue ( JSContext *  context,
jsval  value,
BOOL  abbreviateObjects,
BOOL  recursing 
)
static

Definition at line 1633 of file OOJavaScriptEngine.m.

1634{
1636
1637 NSCParameterAssert(context != NULL && JS_IsInRequest(context));
1638
1639 if (OOJSValueIsFunction(context, value))
1640 {
1641 JSString *name = JS_GetFunctionId(JS_ValueToFunction(context, value));
1642 if (name != NULL) return [NSString stringWithFormat:@"function %@", OOStringFromJSString(context, name)];
1643 else return @"function";
1644 }
1645
1646 NSString *result = nil;
1647 JSClass *class = NULL;
1648 OOJavaScriptEngine *jsEng = [OOJavaScriptEngine sharedEngine];
1649
1650 if (JSVAL_IS_OBJECT(value) && !JSVAL_IS_NULL(value))
1651 {
1652 class = OOJSGetClass(context, JSVAL_TO_OBJECT(value));
1653 }
1654
1655 // Convert String objects to strings.
1656 if (class == [jsEng stringClass])
1657 {
1658 value = STRING_TO_JSVAL(JS_ValueToString(context, value));
1659 }
1660
1661 if (JSVAL_IS_STRING(value))
1662 {
1663 enum { kMaxLength = 200 };
1664
1665 JSString *string = JSVAL_TO_STRING(value);
1666 size_t length;
1667 const jschar *chars = JS_GetStringCharsAndLength(context, string, &length);
1668
1669 result = [NSString stringWithCharacters:chars length:MIN(length, (size_t)kMaxLength)];
1670 result = [NSString stringWithFormat:@"\"%@%@\"", [result escapedForJavaScriptLiteral], (length > kMaxLength) ? @"..." : @""];
1671 }
1672 else if (class == [jsEng arrayClass])
1673 {
1674 // Descibe up to four elements of an array.
1675 jsuint count;
1676 JSObject *obj = JSVAL_TO_OBJECT(value);
1677 if (JS_GetArrayLength(context, obj, &count))
1678 {
1679 if (!recursing)
1680 {
1681 NSMutableString *arrayDesc = [NSMutableString stringWithString:@"["];
1682 jsuint i, effectiveCount = MIN(count, (jsuint)4);
1683 for (i = 0; i < effectiveCount; i++)
1684 {
1685 jsval item;
1686 NSString *itemDesc = @"?";
1687 if (JS_GetElement(context, obj, i, &item))
1688 {
1689 itemDesc = DescribeValue(context, item, YES /* always abbreviate objects in arrays */, YES);
1690 }
1691 if (i != 0) [arrayDesc appendString:@", "];
1692 [arrayDesc appendString:itemDesc];
1693 }
1694 if (effectiveCount != count)
1695 {
1696 [arrayDesc appendFormat:@", ... <%u items total>]", count];
1697 }
1698 else
1699 {
1700 [arrayDesc appendString:@"]"];
1701 }
1702
1703 result = arrayDesc;
1704 }
1705 else
1706 {
1707 result = [NSString stringWithFormat:@"[<%u items>]", count];
1708 }
1709 }
1710 else
1711 {
1712 result = @"[...]";
1713 }
1714
1715 }
1716
1717 if (result == nil)
1718 {
1719 result = OOStringFromJSValueEvenIfNull(context, value);
1720
1721 if (abbreviateObjects && class == [jsEng objectClass] && [result isEqualToString:@"[object Object]"])
1722 {
1723 result = @"{...}";
1724 }
1725
1726 if (result == nil) result = @"?";
1727 }
1728
1729 return result;
1730
1732}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
#define JS_IsInRequest(context)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
OOINLINE JSClass * OOJSGetClass(JSContext *cx, JSObject *obj) ALWAYS_INLINE_FUNC
static NSString * DescribeValue(JSContext *context, jsval value, BOOL abbreviateObjects, BOOL recursing)
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)
NSString * OOStringFromJSString(JSContext *context, JSString *string)
#define MIN(A, B)
Definition OOMaths.h:111
unsigned count

References count, DescribeValue(), JS_IsInRequest, MIN, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSGetClass(), OOJSValueIsFunction(), OOStringFromJSValueEvenIfNull(), and OOJavaScriptEngine::sharedEngine.

Referenced by DescribeValue(), and OOJSDescribeValue().

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

◆ DumpVariable()

static void DumpVariable ( JSContext *  context,
JSPropertyDesc *  prop 
)
static

Definition at line 711 of file OOJavaScriptEngine.m.

712{
713 NSString *name = OOStringFromJSValueEvenIfNull(context, prop->id);
714 NSString *value = OOJSDescribeValue(context, prop->value, YES);
715
716 enum
717 {
718 kInterestingFlags = ~(JSPD_ENUMERATE | JSPD_PERMANENT | JSPD_VARIABLE | JSPD_ARGUMENT)
719 };
720
721 NSString *flagStr = @"";
722 if ((prop->flags & kInterestingFlags) != 0)
723 {
724 NSMutableArray *flags = [NSMutableArray array];
725 if (prop->flags & JSPD_READONLY) [flags addObject:@"read-only"];
726 if (prop->flags & JSPD_ALIAS) [flags addObject:[NSString stringWithFormat:@"alias (%@)", OOJSDescribeValue(context, prop->alias, YES)]];
727 if (prop->flags & JSPD_EXCEPTION) [flags addObject:@"exception"];
728 if (prop->flags & JSPD_ERROR) [flags addObject:@"error"];
729
730 flagStr = [NSString stringWithFormat:@" [%@]", [flags componentsJoinedByString:@", "]];
731 }
732
733 OOLog(@"script.javaScript.stackTrace", @" %@: %@%@", name, value, flagStr);
734}
NSString * OOJSDescribeValue(JSContext *context, jsval value, BOOL abbreviateObjects)
#define OOLog(class, format,...)
Definition OOLogging.h:88

References OOJSDescribeValue(), OOLog, and OOStringFromJSValueEvenIfNull().

Referenced by OOJSDumpStack().

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

◆ GetLocationNameAndLine()

static void GetLocationNameAndLine ( JSContext *  context,
JSStackFrame *  stackFrame,
const char **  name,
NSUInteger *  line 
)
static

Definition at line 870 of file OOJavaScriptEngine.m.

871{
872 NSCParameterAssert(context != NULL && stackFrame != NULL && name != NULL && line != NULL);
873
874 *name = NULL;
875 *line = 0;
876
877 JSScript *script = JS_GetFrameScript(context, stackFrame);
878 if (script != NULL)
879 {
880 *name = JS_GetScriptFilename(context, script);
881 if (name != NULL)
882 {
883 jsbytecode *PC = JS_GetFramePC(context, stackFrame);
884 *line = JS_PCToLineNumber(context, script, PC);
885 }
886 }
887 else if (JS_IsDebuggerFrame(context, stackFrame))
888 {
889 *name = "<debugger frame>";
890 }
891}

Referenced by OOJSDescribeLocation(), and OOJSMarkConsoleEvalLocation().

+ Here is the caller graph for this function:

◆ JSArrayConverter()

static id JSArrayConverter ( JSContext *  context,
JSObject *  object 
)
static

Definition at line 2480 of file OOJavaScriptEngine.m.

2481{
2482 jsuint i, count;
2483 id *values = NULL;
2484 jsval value = JSVAL_VOID;
2485 id object = nil;
2486 NSArray *result = nil;
2487
2488 // Convert a JS array to an NSArray by calling OOJSNativeObjectFromJSValue() on all its elements.
2489 if (!JS_IsArrayObject(context, array)) return nil;
2490 if (!JS_GetArrayLength(context, array, &count)) return nil;
2491
2492 if (count == 0) return [NSArray array];
2493
2494 values = calloc(count, sizeof *values);
2495 if (values == NULL) return nil;
2496
2497 for (i = 0; i != count; ++i)
2498 {
2499 value = JSVAL_VOID;
2500 if (!JS_GetElement(context, array, i, &value)) value = JSVAL_VOID;
2501
2502 object = OOJSNativeObjectFromJSValue(context, value);
2503 if (object == nil) object = [NSNull null];
2504 values[i] = object;
2505 }
2506
2507 result = [NSArray arrayWithObjects:values count:count];
2508 free(values);
2509 return result;
2510}
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)

References count, nil, and OOJSNativeObjectFromJSValue().

+ Here is the call graph for this function:

◆ JSArrayFromNSArray()

static JSObject * JSArrayFromNSArray ( JSContext *  context,
NSArray *  array 
)
static

Definition at line 1201 of file OOJavaScriptEngine.m.

1202{
1204
1205 JSObject *result = NULL;
1206
1207 if (array == nil) return NULL;
1208
1209 @try
1210 {
1211 NSUInteger fullCount = [array count];
1212 if (EXPECT_NOT(fullCount > INT32_MAX))
1213 {
1214 return NULL;
1215 }
1216
1217 uint32_t i, count = (int32_t)fullCount;
1218
1219 result = JS_NewArrayObject(context, 0, NULL);
1220 if (result != NULL)
1221 {
1222 for (i = 0; i != count; ++i)
1223 {
1224 jsval value = [[array objectAtIndex:i] oo_jsValueInContext:context];
1225 BOOL OK = JS_SetElement(context, result, i, &value);
1226
1227 if (EXPECT_NOT(!OK))
1228 {
1229 result = NULL;
1230 break;
1231 }
1232 }
1233 }
1234 }
1235 @catch (id ex)
1236 {
1237 result = NULL;
1238 }
1239
1240 return (JSObject *)result;
1241
1243}
#define EXPECT_NOT(x)

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

Referenced by JSNewNSArrayValue().

+ Here is the caller graph for this function:

◆ JSBooleanConverter()

static id JSBooleanConverter ( JSContext *  context,
JSObject *  object 
)
static

Definition at line 2530 of file OOJavaScriptEngine.m.

2531{
2532 /* Fun With JavaScript: Boolean(false) is a truthy value, since it's a
2533 non-null object. JS_ValueToBoolean() therefore reports true.
2534 However, Boolean objects are transformed to numbers sanely, so this
2535 works.
2536 */
2537 jsdouble value;
2538 if (JS_ValueToNumber(context, OBJECT_TO_JSVAL(object), &value))
2539 {
2540 return [NSNumber numberWithBool:(value != 0)];
2541 }
2542 return nil;
2543}

◆ 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}
@ 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)
void OOJSResumeTimeLimiter(void)

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:

◆ JSNewNSArrayValue()

static BOOL JSNewNSArrayValue ( JSContext *  context,
NSArray *  array,
jsval *  value 
)
static

Definition at line 1246 of file OOJavaScriptEngine.m.

1247{
1249
1250 JSObject *object = NULL;
1251 BOOL OK = YES;
1252
1253 if (value == NULL) return NO;
1254
1255 // NOTE: should be called within a local root scope or have *value be a set root for GC reasons.
1256 if (!JS_EnterLocalRootScope(context)) return NO;
1257
1258 object = JSArrayFromNSArray(context, array);
1259 if (object == NULL)
1260 {
1261 *value = JSVAL_VOID;
1262 OK = NO;
1263 }
1264 else
1265 {
1266 *value = OBJECT_TO_JSVAL(object);
1267 }
1268
1269 JS_LeaveLocalRootScopeWithResult(context, *value);
1270 return OK;
1271
1273}
static JSObject * JSArrayFromNSArray(JSContext *context, NSArray *array)

References JSArrayFromNSArray(), OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

+ Here is the call graph for this function:

◆ JSNewNSDictionaryValue()

static BOOL JSNewNSDictionaryValue ( JSContext *  context,
NSDictionary *  dictionary,
jsval *  value 
)
static

Definition at line 1358 of file OOJavaScriptEngine.m.

1359{
1361
1362 JSObject *object = NULL;
1363 BOOL OK = YES;
1364
1365 if (value == NULL) return NO;
1366
1367 // NOTE: should be called within a local root scope or have *value be a set root for GC reasons.
1368 if (!JS_EnterLocalRootScope(context)) return NO;
1369
1370 object = JSObjectFromNSDictionary(context, dictionary);
1371 if (object == NULL)
1372 {
1373 *value = JSVAL_VOID;
1374 OK = NO;
1375 }
1376 else
1377 {
1378 *value = OBJECT_TO_JSVAL(object);
1379 }
1380
1381 JS_LeaveLocalRootScopeWithResult(context, *value);
1382 return OK;
1383
1385}
static JSObject * JSObjectFromNSDictionary(JSContext *context, NSDictionary *dictionary)

References JSObjectFromNSDictionary(), OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

+ Here is the call graph for this function:

◆ JSNumberConverter()

static id JSNumberConverter ( JSContext *  context,
JSObject *  object 
)
static

Definition at line 2519 of file OOJavaScriptEngine.m.

2520{
2521 jsdouble value;
2522 if (JS_ValueToNumber(context, OBJECT_TO_JSVAL(object), &value))
2523 {
2524 return [NSNumber numberWithDouble:value];
2525 }
2526 return nil;
2527}

References nil.

◆ JSObjectFromNSDictionary()

static JSObject * JSObjectFromNSDictionary ( JSContext *  context,
NSDictionary *  dictionary 
)
static

Definition at line 1280 of file OOJavaScriptEngine.m.

1281{
1283
1284 JSObject *result = NULL;
1285 BOOL OK = YES;
1286 id key = nil;
1287 jsval value;
1288 jsint index;
1289
1290 if (dictionary == nil) return NULL;
1291
1292 @try
1293 {
1294 result = JS_NewObject(context, NULL, NULL, NULL); // create object of class Object
1295 if (result != NULL)
1296 {
1297 foreachkey (key, dictionary)
1298 {
1299 if ([key isKindOfClass:[NSString class]] && [key length] != 0)
1300 {
1301#ifndef __GNUC__
1302 value = [[dictionary objectForKey:key] oo_jsValueInContext:context];
1303#else
1304#if __GNUC__ > 4 || __GNUC_MINOR__ > 6
1305 value = [[dictionary objectForKey:key] oo_jsValueInContext:context];
1306#else
1307 // GCC before 4.7 seems to have problems with this
1308 // bit if the object is a weakref, causing crashes
1309 // in docking code.
1310 id tmp = [dictionary objectForKey:key];
1311 if ([tmp respondsToSelector:@selector(weakRefUnderlyingObject)])
1312 {
1313 tmp = [tmp weakRefUnderlyingObject];
1314 }
1315 value = [tmp oo_jsValueInContext:context];
1316#endif
1317#endif
1318 if (!JSVAL_IS_VOID(value))
1319 {
1320 OK = JS_SetPropertyById(context, result, OOJSIDFromString(key), &value);
1321 if (EXPECT_NOT(!OK)) break;
1322 }
1323 }
1324 else if ([key isKindOfClass:[NSNumber class]])
1325 {
1326 index = [key intValue];
1327 if (0 < index)
1328 {
1329 value = [[dictionary objectForKey:key] oo_jsValueInContext:context];
1330 if (!JSVAL_IS_VOID(value))
1331 {
1332 OK = JS_SetElement(context, (JSObject *)result, index, &value);
1333 if (EXPECT_NOT(!OK)) break;
1334 }
1335 }
1336 }
1337
1338 if (EXPECT_NOT(!OK)) break;
1339 }
1340 }
1341 }
1342 @catch (id exception)
1343 {
1344 OK = NO;
1345 }
1346
1347 if (EXPECT_NOT(!OK))
1348 {
1349 result = NULL;
1350 }
1351
1352 return (JSObject *)result;
1353
1355}
#define foreachkey(VAR, DICT)
Definition OOCocoa.h:353
jsid OOJSIDFromString(NSString *string)

References EXPECT_NOT, foreachkey, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJSIDFromString().

Referenced by JSNewNSDictionaryValue().

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

◆ JSStringConverter()

static id JSStringConverter ( JSContext *  context,
JSObject *  object 
)
static

Definition at line 2513 of file OOJavaScriptEngine.m.

2514{
2515 return OOStringFromJSValue(context, OBJECT_TO_JSVAL(object));
2516}
NSString * OOStringFromJSValue(JSContext *context, jsval value)

References OOStringFromJSValue().

+ Here is the call 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}

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}

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

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}

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

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:

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

◆ OOJSInitJSIDCachePRIVATE()

void OOJSInitJSIDCachePRIVATE ( const char *  name,
jsid *  idCache 
)

Definition at line 925 of file OOJavaScriptEngine.m.

926{
927 NSCParameterAssert(name != NULL && name[0] != '\0' && idCache != NULL);
928
929 JSContext *context = OOJSAcquireContext();
930
931 JSString *string = JS_InternString(context, name);
932 if (EXPECT_NOT(string == NULL))
933 {
934 [NSException raise:NSGenericException format:@"Failed to initialize JS ID cache for \"%s\".", name];
935 }
936
937 *idCache = INTERNED_STRING_TO_JSID(string);
938
939 OOJSRelinquishContext(context);
940}

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

+ Here is the call 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 *  tableObject 
)

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)

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:

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

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

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}

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:

◆ OOJSReportWrappedException()

void OOJSReportWrappedException ( JSContext *  context,
id  exception 
)

Definition at line 1050 of file OOJavaScriptEngine.m.

1051{
1052 if (!JS_IsExceptionPending(context))
1053 {
1054 if ([exception isKindOfClass:[NSException class]]) OOJSReportError(context, @"Native exception: %@", [exception reason]);
1055 else OOJSReportError(context, @"Unidentified native exception");
1056 }
1057 // Else, let the pending exception propagate.
1058}

References OOJSReportError().

+ Here is the call 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:

◆ OOJSUnreachable()

void OOJSUnreachable ( const char *  function,
const char *  file,
unsigned  line 
)

Definition at line 1063 of file OOJavaScriptEngine.m.

1064{
1065 OOLog(@"fatal.unreachable", @"Supposedly unreachable statement reached in %s (%@:%u) -- terminating.", function, OOLogAbbreviatedFileName(file), line);
1066 abort();
1067}
NSString * OOLogAbbreviatedFileName(const char *inName)
Definition OOLogging.m:839

References OOLog, and OOLogAbbreviatedFileName().

+ Here is the call 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:

◆ ReportJSError()

static void ReportJSError ( JSContext *  context,
const char *  message,
JSErrorReport *  report 
)
static

Definition at line 144 of file OOJavaScriptEngine.m.

145{
146 NSString *severity = @"error";
147 NSString *messageText = nil;
148 NSString *lineBuf = nil;
149 NSString *messageClass = nil;
150 NSString *highlight = @"*****";
151 NSString *activeScript = nil;
152 OOJavaScriptEngine *jsEng = [OOJavaScriptEngine sharedEngine];
153 BOOL showLocation = [jsEng showErrorLocations];
154
155 // Not OOJS_BEGIN_FULL_NATIVE() - we use JSAPI while paused.
157
158 jschar empty[1] = { 0 };
159 JSErrorReport blankReport =
160 {
161 .filename = "<unspecified file>",
162 .linebuf = "",
163 .uclinebuf = empty,
164 .uctokenptr = empty,
165 .ucmessage = empty
166 };
167 if (EXPECT_NOT(report == NULL)) report = &blankReport;
168 if (EXPECT_NOT(message == NULL || *message == '\0')) message = "<unspecified error>";
169
170 // Type of problem: error, warning or exception? (Strict flag wilfully ignored.)
171 if (report->flags & JSREPORT_EXCEPTION) severity = @"exception";
172 else if (report->flags & JSREPORT_WARNING)
173 {
174 severity = @"warning";
175 highlight = @"-----";
176 }
177
178 // The error message itself
179 messageText = [NSString stringWithUTF8String:message];
180
181 // Get offending line, if present, and trim trailing line breaks
182 lineBuf = [NSString stringWithUTF16String:report->uclinebuf];
183 while ([lineBuf hasSuffix:@"\n"] || [lineBuf hasSuffix:@"\r"]) lineBuf = [lineBuf substringToIndex:[lineBuf length] - 1];
184
185 // Get string for error number, for useful log message classes
186 NSDictionary *errorNames = [ResourceManager dictionaryFromFilesNamed:@"javascript-errors.plist" inFolder:@"Config" andMerge:YES];
187 NSString *errorNumberStr = [NSString stringWithFormat:@"%u", report->errorNumber];
188 NSString *errorName = [errorNames oo_stringForKey:errorNumberStr];
189 if (errorName == nil) errorName = errorNumberStr;
190
191 // Log message class
192 messageClass = [NSString stringWithFormat:@"script.javaScript.%@.%@", severity, errorName];
193
194 // Skip the rest if this is a warning being ignored.
195 if ((report->flags & JSREPORT_WARNING) == 0 || OOLogWillDisplayMessagesInClass(messageClass))
196 {
197 // First line: problem description
198 // avoid windows DEP exceptions!
199 OOJSScript *thisScript = [[OOJSScript currentlyRunningScript] weakRetain];
200 activeScript = [[thisScript weakRefUnderlyingObject] displayName];
201 [thisScript release];
202
203 if (activeScript == nil) activeScript = @"<unidentified script>";
204 OOLog(messageClass, @"%@ JavaScript %@ (%@): %@", highlight, severity, activeScript, messageText);
205
206 if (showLocation && sErrorHandlerStackSkip == 0 && report->filename != NULL)
207 {
208 // Second line: where error occured, and line if provided. (The line is only provided for compile-time errors, not run-time errors.)
209 if ([lineBuf length] != 0)
210 {
211 OOLog(messageClass, @" %s, line %d: %@", report->filename, report->lineno, lineBuf);
212 }
213 else
214 {
215 OOLog(messageClass, @" %s, line %d.", report->filename, report->lineno);
216 }
217 }
218
219#ifndef NDEBUG
220 BOOL dump;
221 if (report->flags & JSREPORT_WARNING) dump = [jsEng dumpStackForWarnings];
222 else dump = [jsEng dumpStackForErrors];
223 if (dump) OOJSDumpStack(context);
224#endif
225
226#if OOJSENGINE_MONITOR_SUPPORT
227 JSExceptionState *exState = JS_SaveExceptionState(context);
228 [[OOJavaScriptEngine sharedEngine] sendMonitorError:report
229 withMessage:messageText
230 inContext:context];
231 JS_RestoreExceptionState(context, exState);
232#endif
233 }
234
236}
void OOJSDumpStack(JSContext *context)
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
Definition OOLogging.m:144

References OOJSScript::currentlyRunningScript, ResourceManager::dictionaryFromFilesNamed:inFolder:andMerge:, OOJavaScriptEngine::dumpStackForErrors, OOJavaScriptEngine::dumpStackForWarnings, EXPECT_NOT, nil, OOJSDumpStack(), OOJSPauseTimeLimiter(), OOJSResumeTimeLimiter(), OOLog, OOLogWillDisplayMessagesInClass(), sErrorHandlerStackSkip, OOJavaScriptEngine::sharedEngine, OOJavaScriptEngine::showErrorLocations, and OOJSScript::weakRetain.

+ Here is the call graph for this function:

◆ UnregisterObjectConverters()

static void UnregisterObjectConverters ( void  )
static

Definition at line 2474 of file OOJavaScriptEngine.m.

2475{
2477}
#define DESTROY(x)
Definition OOCocoa.h:75

References DESTROY, and sObjectConverters.

◆ UnregisterSubclasses()

static void UnregisterSubclasses ( void  )
static

Definition at line 2155 of file OOJavaScriptEngine.m.

2156{
2157 NSFreeMapTable(sRegisteredSubClasses);
2158 sRegisteredSubClasses = NULL;
2159}

References sRegisteredSubClasses.

Variable Documentation

◆ gOOJSMainThreadContext

JSContext* gOOJSMainThreadContext = NULL

Definition at line 97 of file OOJavaScriptEngine.m.

Referenced by OOJSAcquireContext(), and OOJSRelinquishContext().

◆ kOOJavaScriptEngineDidResetNotification

NSString* const kOOJavaScriptEngineDidResetNotification = @"org.aegidian.oolite OOJavaScriptEngine did reset"

Definition at line 101 of file OOJavaScriptEngine.m.

◆ kOOJavaScriptEngineWillResetNotification

NSString* const kOOJavaScriptEngineWillResetNotification = @"org.aegidian.oolite OOJavaScriptEngine will reset"

Definition at line 100 of file OOJavaScriptEngine.m.

◆ sConsoleEvalLineNo

NSUInteger sConsoleEvalLineNo
static

Definition at line 867 of file OOJavaScriptEngine.m.

Referenced by OOJSDescribeLocation(), and OOJSMarkConsoleEvalLocation().

◆ sConsoleScriptName

const char* sConsoleScriptName
static

Definition at line 866 of file OOJavaScriptEngine.m.

Referenced by OOJSDescribeLocation(), and OOJSMarkConsoleEvalLocation().

◆ sErrorHandlerStackSkip

unsigned sErrorHandlerStackSkip = 0
static

◆ sObjectConverters

NSMutableDictionary* sObjectConverters
static

◆ sRegisteredSubClasses

NSMapTable* sRegisteredSubClasses
static

◆ sSharedEngine

OOJavaScriptEngine* sSharedEngine = nil
static

Definition at line 94 of file OOJavaScriptEngine.m.