Oolite 1.91.0.7645-241119-222d325
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(OOMonitorSupportInternal)
 
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   32
 

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   32

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

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

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

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

◆ JSEntityIsDemoShipPredicate()

BOOL JSEntityIsDemoShipPredicate ( Entity * entity,
void * parameter )

Definition at line 2134 of file OOJavaScriptEngine.m.

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

◆ JSEntityIsJavaScriptSearchablePredicate()

BOOL JSEntityIsJavaScriptSearchablePredicate ( Entity * entity,
void * parameter )

Definition at line 2100 of file OOJavaScriptEngine.m.

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

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

Referenced by FindJSVisibleEntities().

+ Here is the caller graph for this function:

◆ JSEntityIsJavaScriptVisiblePredicate()

BOOL JSEntityIsJavaScriptVisiblePredicate ( Entity * entity,
void * parameter )

Definition at line 2090 of file OOJavaScriptEngine.m.

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

References Entity::isVisibleToScripts, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

+ Here is the call graph for this function:

◆ JSFunctionPredicate()

BOOL JSFunctionPredicate ( Entity * entity,
void * parameter )

Definition at line 2047 of file OOJavaScriptEngine.m.

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

1360{
1362
1363 JSObject *object = NULL;
1364 BOOL OK = YES;
1365
1366 if (value == NULL) return NO;
1367
1368 // NOTE: should be called within a local root scope or have *value be a set root for GC reasons.
1369 if (!JS_EnterLocalRootScope(context)) return NO;
1370
1371 object = JSObjectFromNSDictionary(context, dictionary);
1372 if (object == NULL)
1373 {
1374 *value = JSVAL_VOID;
1375 OK = NO;
1376 }
1377 else
1378 {
1379 *value = OBJECT_TO_JSVAL(object);
1380 }
1381
1382 JS_LeaveLocalRootScopeWithResult(context, *value);
1383 return OK;
1384
1386}
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 2520 of file OOJavaScriptEngine.m.

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

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

References EXPECT_NOT, 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 2514 of file OOJavaScriptEngine.m.

2515{
2516 return OOStringFromJSValue(context, OBJECT_TO_JSVAL(object));
2517}
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 2441 of file OOJavaScriptEngine.m.

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

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

+ Here is the caller graph for this function:

◆ OOJSDescribeLocation()

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

Definition at line 894 of file OOJavaScriptEngine.m.

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

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

Referenced by OOJSDumpStack().

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

◆ OOJSDescribeValue()

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

Definition at line 1736 of file OOJavaScriptEngine.m.

1737{
1738 return DescribeValue(context, value, abbreviateObjects, NO);
1739}

References DescribeValue().

Referenced by DumpVariable(), and OOJSReportBadPropertyValue().

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

◆ OOJSDictionaryFromJSObject()

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

Definition at line 2247 of file OOJavaScriptEngine.m.

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

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

Referenced by OOJSDictionaryFromJSValue().

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

◆ OOJSDictionaryFromJSValue()

NSDictionary * OOJSDictionaryFromJSValue ( JSContext * context,
jsval value )

Definition at line 2232 of file OOJavaScriptEngine.m.

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

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

+ Here is the call graph for this function:

◆ OOJSDictionaryFromStringTable()

NSDictionary * OOJSDictionaryFromStringTable ( JSContext * context,
jsval tableValue )

Definition at line 2307 of file OOJavaScriptEngine.m.

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

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

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

References sRegisteredSubClasses.

Referenced by OOJSIsMemberOfSubclass(), and OOJSObjectGetterImplPRIVATE().

+ Here is the caller graph for this function:

◆ OOJSMarkConsoleEvalLocation()

void OOJSMarkConsoleEvalLocation ( JSContext * context,
JSStackFrame * stackFrame )

Definition at line 918 of file OOJavaScriptEngine.m.

919{
921}

References GetLocationNameAndLine(), sConsoleEvalLineNo, and sConsoleScriptName.

Referenced by SpecialMarkConsoleEntryPoint().

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

◆ OOJSNativeObjectFromJSObject()

id OOJSNativeObjectFromJSObject ( JSContext * context,
JSObject * tableObject )

Definition at line 2400 of file OOJavaScriptEngine.m.

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

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

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

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

◆ OOJSNativeObjectFromJSValue()

id OOJSNativeObjectFromJSValue ( JSContext * context,
jsval value )

Definition at line 2368 of file OOJavaScriptEngine.m.

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

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

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

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

◆ OOJSNativeObjectOfClassFromJSObject()

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

Definition at line 2433 of file OOJavaScriptEngine.m.

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

References nil, and OOJSNativeObjectFromJSObject().

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

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

◆ OOJSNativeObjectOfClassFromJSValue()

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

Definition at line 2425 of file OOJavaScriptEngine.m.

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

References nil, and OOJSNativeObjectFromJSValue().

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

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

◆ OOJSObjectFromNativeObject()

JSObject * OOJSObjectFromNativeObject ( JSContext * context,
id object )

Definition at line 1442 of file OOJavaScriptEngine.m.

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

References OOJSValueFromNativeObject().

+ Here is the call graph for this function:

◆ OOJSObjectGetterImplPRIVATE()

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

Definition at line 2180 of file OOJavaScriptEngine.m.

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

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

+ Here is the call graph for this function:

◆ OOJSObjectWrapperFinalize()

void OOJSObjectWrapperFinalize ( JSContext * context,
JSObject * this )

Definition at line 2001 of file OOJavaScriptEngine.m.

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

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT_VOID.

◆ OOJSObjectWrapperToString()

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

Definition at line 2017 of file OOJavaScriptEngine.m.

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

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

+ Here is the call graph for this function:

◆ OOJSRegisterObjectConverter()

void OOJSRegisterObjectConverter ( JSClass * theClass,
OOJSClassConverterCallback converter )

Definition at line 2454 of file OOJavaScriptEngine.m.

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

References nil, and sObjectConverters.

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

+ Here is the caller graph for this function:

◆ OOJSRegisterSubclass()

void OOJSRegisterSubclass ( JSClass * subclass,
JSClass * superclass )

Definition at line 2141 of file OOJavaScriptEngine.m.

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

References sRegisteredSubClasses.

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

+ Here is the caller graph for this function:

◆ 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(), Entity(OODebugInspector)::inspect, PlayerEntity(OOJavaScriptExtensions)::javaScriptEngineWillReset:, ManifestComment(), ManifestSetComment(), ManifestShortComment(), MissionMarkSystem(), MissionRunScreen(), MissionSetInstructionsInternal(), MissionUnmarkSystem(), OOEquipmentType(OOJavaScriptExtensions)::oo_clearJSSelf:, OOShipGroup(OOJavaScriptExtensions)::oo_clearJSSelf:, OOSound(OOJavaScriptExtentions)::oo_jsClassName, OOJSArgumentListGetNumber(), PlayerAddMessageToArrivalReport(), PlayerAudioMessage(), PlayerCommsMessage(), PlayerConsoleMessage(), PlayerEndScenario(), PlayerReplaceShip(), PlayerSetEscapePodDestination(), PlayerSetPlayerRole(), PlayerShipAddParcel(), PlayerShipAddPassenger(), PlayerShipAwardContract(), PlayerShipAwardEquipmentToCurrentPylon(), PlayerShipBeginGalacticHyperspaceCountdown(), PlayerShipBeginHyperspaceCountdown(), PlayerShipCancelDockingRequest(), PlayerShipEngageAutopilotToStation(), PlayerShipHideHUDSelector(), PlayerShipRemoveContract(), PlayerShipRemoveParcel(), PlayerShipRemovePassenger(), PlayerShipRequestDockingClearance(), PlayerShipSetCustomHUDDial(), PlayerShipSetCustomView(), PlayerShipSetMultiFunctionDisplay(), PlayerShipSetMultiFunctionText(), PlayerShipSetPrimedEquipment(), PlayerShipShowHUDSelector(), PlayerShipUseSpecialCargo(), QuaternionConstruct(), QuaternionFromArgumentList(), ShipAddCargoEntity(), ShipAddCollisionException(), ShipAddDefenseTarget(), ShipAdjustCargo(), ShipAwardEquipment(), ShipCanAwardEquipment(), ShipCheckScanner(), ShipCommsMessage(), ShipDealEnergyDamage(), ShipDumpCargo(), ShipEjectItem(), ShipEjectSpecificItem(), ShipEnterWormhole(), ShipEquipmentStatus(), ShipExitSystem(), ShipGroupAddShip(), ShipGroupConstruct(), ShipGroupRemoveShip(), ShipHasEquipmentProviding(), ShipHasRole(), ShipOfferToEscort(), ShipPatrolReportIn(), ShipReactToAIMessage(), ShipRemove(), ShipRemoveCollisionException(), ShipRemoveDefenseTarget(), ShipRemoveEquipment(), ShipRunLegacyScriptActions(), ShipSendAIMessage(), ShipSetAI(), ShipSetBounty(), ShipSetCargo(), ShipSetCargoType(), ShipSetCrew(), ShipSetEquipmentStatus(), ShipSetMaterials(), ShipSetScript(), ShipSetShaders(), ShipSpawn(), ShipStaticKeysForRole(), ShipStaticRoleIsInCategory(), ShipStaticSetShipDataForKey(), ShipStaticShipDataForKey(), ShipSwitchAI(), ShipThreatAssessment(), SoundSourcePlay(), SoundStaticLoad(), SoundStaticPlayMusic(), SpecialJSWarning(), StationAbortDockingForShip(), StationAddShipToShipyard(), StationCanDockShip(), StationLaunchShipWithRole(), StationSetInterface(), StationSetMarketPrice(), StationSetMarketQuantity(), SystemAddMoon(), SystemAddPlanet(), SystemAddShipsOrGroup(), SystemAddShipsOrGroupToRoute(), SystemAddVisualEffect(), SystemCountEntitiesWithScanClass(), SystemCountShipsWithPrimaryRole(), SystemCountShipsWithRole(), SystemEntitiesWithScanClass(), SystemFilteredEntities(), SystemInfoDistanceToSystem(), SystemInfoRouteToSystem(), SystemInfoSamplePrice(), SystemInfoSetPropertyMethod(), SystemInfoStaticFilteredSystems(), SystemInfoStaticSetInterstellarProperty(), SystemLegacyAddShips(), SystemLegacyAddShipsAt(), SystemLegacyAddShipsAtPrecisely(), SystemLegacyAddShipsWithinRadius(), SystemLegacyAddSystemShips(), SystemLegacySpawnShip(), SystemLocationFromCode(), SystemSetPopulator(), SystemSetWaypoint(), SystemShipsWithPrimaryRole(), SystemShipsWithRole(), SystemStaticInfoForSystem(), SystemStaticSystemIDForName(), SystemStaticSystemNameForID(), TimerConstruct(), VectorConstruct(), VectorFromArgumentList(), VectorFromCoordinateSystem(), VectorStaticInterpolate(), VectorToCoordinateSystem(), VisualEffectScale(), VisualEffectSetMaterials(), and VisualEffectSetShaders().

+ Here is the call graph for this function:

◆ OOJSReportBadPropertySelector()

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

Definition at line 1120 of file OOJavaScriptEngine.m.

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

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

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

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

◆ OOJSReportBadPropertyValue()

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

Definition at line 1129 of file OOJavaScriptEngine.m.

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

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

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

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

◆ OOJSReportError()

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

Definition at line 1000 of file OOJavaScriptEngine.m.

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

References OOJSReportErrorWithArguments().

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

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

◆ OOJSReportErrorForCaller()

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

Definition at line 1010 of file OOJavaScriptEngine.m.

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

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

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

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

◆ OOJSReportErrorWithArguments()

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

Definition at line 1031 of file OOJavaScriptEngine.m.

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

References JS_IsInRequest, and nil.

Referenced by OOJSReportError().

+ Here is the caller graph for this function:

◆ OOJSReportWarning()

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

Definition at line 1072 of file OOJavaScriptEngine.m.

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

References OOJSReportWarningWithArguments().

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

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

◆ OOJSReportWarningForCaller()

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

Definition at line 1082 of file OOJavaScriptEngine.m.

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

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

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

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

◆ OOJSReportWarningWithArguments()

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

Definition at line 1103 of file OOJavaScriptEngine.m.

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

References nil.

Referenced by OOJSReportWarning(), and SyntaxIssue().

+ Here is the caller graph for this function:

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

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

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

+ Here is the call graph for this function:

◆ OOJSUnconstructableConstruct()

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

Definition at line 1987 of file OOJavaScriptEngine.m.

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

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

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

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

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

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

References OOStringFromJSString().

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

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

◆ OOStringFromJSString()

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

Definition at line 1562 of file OOJavaScriptEngine.m.

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

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

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

+ Here is the caller graph for this function:

◆ OOStringFromJSValue()

NSString * OOStringFromJSValue ( JSContext * context,
jsval value )

Definition at line 1597 of file OOJavaScriptEngine.m.

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

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

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

+ Here is the call graph for this function:

◆ OOStringFromJSValueEvenIfNull()

NSString * OOStringFromJSValueEvenIfNull ( JSContext * context,
jsval value )

Definition at line 1584 of file OOJavaScriptEngine.m.

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

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

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

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

◆ 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(), OOJavaScriptEngine::sendMonitorError:withMessage:inContext:, 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 2475 of file OOJavaScriptEngine.m.

2476{
2478}
#define DESTROY(x)
Definition OOCocoa.h:77

References DESTROY, and sObjectConverters.

◆ UnregisterSubclasses()

static void UnregisterSubclasses ( void )
static

Definition at line 2156 of file OOJavaScriptEngine.m.

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

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.