Oolite
Loading...
Searching...
No Matches
OOJavaScriptEngine.m File Reference
Include dependency graph for OOJavaScriptEngine.m:

Go to the source code of this file.

Classes

category  OOJavaScriptEngine(Private)

Macros

#define OOJS_RUNTIME_SIZE_MiB   256
#define OOJS_STACK_SIZE   (1024 * 1024)
#define OOJS_TIME_LIMIT   (1)

Functions

static int InterruptHandler (OOJSInterruptHandlerArg *arg, void *opaque)
static void RegisterStandardObjectConverters (JSContext *context)
static void RemoveNonSpiderMonkeyGlobals (JSContext *context, JSValueConst global)
static void LoadCompatibilityScript (JSContext *context)
JSValueConst OOJSLegacyConstRewriter (void)
NSString * OOJSWrapScriptSource (NSString *source)
BOOL OOJSValueToBOOL (JSContext *context, JSValueConst value)
BOOL OOJSValueToInt32 (JSContext *context, JSValueConst value, int32_t *outValue)
static double MonotonicTime (void)
void OOJSStartTimeLimiterWithTimeLimit (OOTimeDelta limit)
void OOJSStopTimeLimiter (void)
void OOJSPauseTimeLimiter (void)
void OOJSResumeTimeLimiter (void)
void OOJSResetTimeLimiter (void)
OOTimeDelta OOJSGetTimeLimiterLimit (void)
void OOJSSetTimeLimiterLimit (OOTimeDelta limit)
static BOOL GetLocationFromStack (NSString *stack, NSString **outFile, unsigned *outLine)
static NSString * StackOfValue (JSContext *context, JSValueConst value)
static NSString * CurrentStack (JSContext *context)
static void LogProblem (JSContext *context, NSString *severity, NSString *errorName, NSString *message, NSString *stack)
void OOJSReportPendingException (JSContext *context)
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)
JSValue OOJSNativeFailure (JSContext *context)
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)
NSString * OOStringFromJSPropertyMagic (int magic, const JSCFunctionListEntry *list, size_t count)
void OOJSReportBadPropertySelector (JSContext *context, JSValueConst thisObj, int magic, const JSCFunctionListEntry *list, size_t count)
void OOJSReportBadPropertyValue (JSContext *context, JSValueConst thisObj, int magic, const JSCFunctionListEntry *list, size_t count, JSValueConst value)
void OOJSReportBadArguments (JSContext *context, NSString *scriptClass, NSString *function, int argc, JSValueConst *argv, NSString *message, NSString *expectedArgsDescription)
void OOJSSetWarningOrErrorStackSkip (unsigned skip)
BOOL OOJSArgumentListGetNumber (JSContext *context, NSString *scriptClass, NSString *function, int argc, JSValueConst *argv, double *outNumber, int *outConsumed)
BOOL OOJSArgumentListGetNumberNoError (JSContext *context, int argc, JSValueConst *argv, double *outNumber, int *outConsumed)
JSAtom OOJSInternAtomPRIVATE (const char *name)
JSAtom OOJSIDFromString (NSString *string)
NSString * OOStringFromJSID (JSAtom propID)
static JSValue JSArrayFromNSArray (JSContext *context, NSArray *array)
static JSValue JSObjectFromNSDictionary (JSContext *context, NSDictionary *dictionary)
JSValue OOJSObjectFromNativeObject (JSContext *context, id object)
NSString * OOStringFromJSValueEvenIfNull (JSContext *context, JSValueConst value)
NSString * OOStringFromJSValue (JSContext *context, JSValueConst value)
NSString * OOJSClassNameOfValue (JSContext *context, JSValueConst value)
static NSString * DescribeValue (JSContext *context, JSValueConst value, BOOL abbreviateObjects, BOOL recursing)
NSString * OOJSDescribeValue (JSContext *context, JSValueConst value, BOOL abbreviateObjects)
JSValue OOJSUnconstructableConstruct (JSContext *context, JSValueConst this, int argc, JSValueConst *argv)
void OOJSObjectWrapperFinalize (JSRuntime *runtime, JSValueConst this)
JSValue OOJSObjectWrapperToString (JSContext *context, JSValueConst this, int argc, JSValueConst *argv)
BOOL JSFunctionPredicate (Entity *entity, void *parameter)
BOOL JSEntityIsJavaScriptVisiblePredicate (Entity *entity, void *parameter)
BOOL JSEntityIsJavaScriptSearchablePredicate (Entity *entity, void *parameter)
BOOL JSEntityIsDemoShipPredicate (Entity *entity, void *parameter)
BOOL OOJSObjectGetterImplPRIVATE (JSContext *context, JSValueConst object, JSClassID requiredClassID, Class requiredObjCClass, const char *name, id *outObject)
NSDictionary * OOJSDictionaryFromJSValue (JSContext *context, JSValueConst value)
static id KeyForAtom (JSContext *context, JSAtom atom)
NSDictionary * OOJSDictionaryFromJSObject (JSContext *context, JSValueConst object)
NSDictionary * OOJSDictionaryFromStringTable (JSContext *context, JSValueConst tableValue)
id OOJSNativeObjectFromJSValue (JSContext *context, JSValueConst value)
id OOJSNativeObjectFromJSObject (JSContext *context, JSValueConst object)
id OOJSNativeObjectOfClassFromJSValue (JSContext *context, JSValueConst value, Class requiredClass)
id OOJSNativeObjectOfClassFromJSObject (JSContext *context, JSValueConst object, Class requiredClass)
id OOJSBasicPrivateObjectConverter (JSContext *context, JSValueConst object)
void OOJSRegisterObjectConverter (JSClassID classID, OOJSClassConverterCallback converter)
static id JSArrayConverter (JSContext *context, JSValueConst array)
static id JSStringConverter (JSContext *context, JSValueConst object)
static id JSNumberConverter (JSContext *context, JSValueConst object)
static id JSBooleanConverter (JSContext *context, JSValueConst object)
static id JSObjectConverter (JSContext *context, JSValueConst object)

Variables

static OOJavaScriptEngine * sSharedEngine = nil
static unsigned sErrorHandlerStackSkip = 0
JSContext * gOOJSMainThreadContext = NULL
static JSValue sLegacyConstRewriter = JS_UNDEFINED
NSString *const kOOJavaScriptEngineWillResetNotification = @"org.aegidian.oolite OOJavaScriptEngine will reset"
NSString *const kOOJavaScriptEngineDidResetNotification = @"org.aegidian.oolite OOJavaScriptEngine did reset"
static unsigned sLimiterStartDepth
static int sLimiterPauseDepth
static double sLimiterStart
static double sLimiterPauseStart
static double sLimiterTimeLimit
static OOJSClassConverterCallback sObjectConverters [kOOJSMaxClassID]
JSClassID gOOJSObjectClassID
JSClassID gOOJSStringClassID
JSClassID gOOJSArrayClassID
JSClassID gOOJSNumberClassID
JSClassID gOOJSBooleanClassID

Macro Definition Documentation

◆ OOJS_RUNTIME_SIZE_MiB

#define OOJS_RUNTIME_SIZE_MiB   256

Definition at line 78 of file OOJavaScriptEngine.m.

◆ OOJS_STACK_SIZE

#define OOJS_STACK_SIZE   (1024 * 1024)

◆ OOJS_TIME_LIMIT

#define OOJS_TIME_LIMIT   (1)

Definition at line 84 of file OOJavaScriptEngine.m.

Function Documentation

◆ CallerPrefix()

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

Definition at line 833 of file OOJavaScriptEngine.m.

834{
835 if (function == nil)
836 return @"";
837 if (scriptClass == nil)
838 return [function stringByAppendingString:@": "];
839 return [NSString stringWithFormat:@"%@.%@: ", scriptClass, function];
840}
return nil

References nil.

◆ CurrentStack()

NSString * CurrentStack ( JSContext * context)
static

Definition at line 753 of file OOJavaScriptEngine.m.

754{
755 // A fresh Error object captures the current JS stack.
756 JSValue error = JS_NewError(context);
757 NSString* result = StackOfValue(context, error);
758 JS_FreeValue(context, error);
759 return result;
760}
static NSString * StackOfValue(JSContext *context, JSValueConst value)

References StackOfValue().

Referenced by OOJSReportWarningWithArguments().

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

◆ DescribeValue()

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

Definition at line 1330 of file OOJavaScriptEngine.m.

1331{
1333
1334 if (JS_IsFunction(context, value)) {
1335 JSValue nameVal = JS_GetPropertyStr(context, value, "name");
1336 NSString* name = OOStringFromJSValue(context, nameVal);
1337 JS_FreeValue(context, nameVal);
1338 if ([name length] != 0)
1339 return [NSString stringWithFormat:@"function %@", name];
1340 else
1341 return @"function";
1342 }
1343
1344 NSString* result = nil;
1345 JSClassID classID = JS_GetClassID(value);
1346
1347 if (JS_IsString(value) || (classID != JS_INVALID_CLASS_ID && classID == gOOJSStringClassID)) {
1348 enum { kMaxLength = 200 };
1349
1350 NSString* string = OOStringFromJSValueEvenIfNull(context, value);
1351 NSUInteger length = [string length];
1352 result = [string substringToIndex:MIN(length, (NSUInteger)kMaxLength)];
1353 result = [NSString stringWithFormat:@"\"%@%@\"", [result escapedForJavaScriptLiteral], (length > kMaxLength) ? @"..." : @""];
1354 } else if (JS_IsArray(value)) {
1355 // Descibe up to four elements of an array.
1356 int64_t count;
1357 if (JS_GetLength(context, value, &count) == 0) {
1358 if (!recursing) {
1359 NSMutableString* arrayDesc = [NSMutableString stringWithString:@"["];
1360 int64_t i, effectiveCount = MIN(count, (int64_t)4);
1361 for (i = 0; i < effectiveCount; i++) {
1362 JSValue item = JS_GetPropertyUint32(context, value, (uint32_t)i);
1363 NSString* itemDesc = @"?";
1364 if (!JS_IsException(item)) {
1365 itemDesc = DescribeValue(context, item, YES /* always abbreviate objects in arrays */, YES);
1366 }
1367 JS_FreeValue(context, item);
1368 if (i != 0)
1369 [arrayDesc appendString:@", "];
1370 [arrayDesc appendString:itemDesc];
1371 }
1372 if (effectiveCount != count) {
1373 [arrayDesc appendFormat:@", ... <%lli items total>]", (long long)count];
1374 } else {
1375 [arrayDesc appendString:@"]"];
1376 }
1377
1378 result = arrayDesc;
1379 } else {
1380 result = [NSString stringWithFormat:@"[<%lli items>]", (long long)count];
1381 }
1382 } else {
1383 JS_FreeValue(context, JS_GetException(context));
1384 result = @"[...]";
1385 }
1386 }
1387
1388 if (result == nil) {
1389 result = OOStringFromJSValueEvenIfNull(context, value);
1390
1391 if (abbreviateObjects && classID == gOOJSObjectClassID && [result isEqualToString:@"[object Object]"]) {
1392 result = @"{...}";
1393 }
1394
1395 if (result == nil)
1396 result = @"?";
1397 }
1398
1399 return result;
1400
1402}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
static NSString * DescribeValue(JSContext *context, jsval value, BOOL abbreviateObjects, BOOL recursing)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)
#define MIN(A, B)
Definition OOMaths.h:91
unsigned count
JSClassID gOOJSStringClassID
JSClassID gOOJSObjectClassID
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque

References count, DescribeValue(), gOOJSObjectClassID, gOOJSStringClassID, MIN, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOStringFromJSValue(), and OOStringFromJSValueEvenIfNull().

Here is the call graph for this function:

◆ GetLocationFromStack()

BOOL GetLocationFromStack ( NSString * stack,
NSString ** outFile,
unsigned * outLine )
static

Definition at line 717 of file OOJavaScriptEngine.m.

718{
719 for (NSString* frame in [stack componentsSeparatedByString:@"\n"]) {
720 frame = [frame stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
721 if (![frame hasPrefix:@"at "])
722 continue;
723 frame = [frame substringFromIndex:3];
724
725 // The first "(" opens the location: the path may itself contain parentheses ("Program Files (x86)").
726 NSRange open = [frame rangeOfString:@"("];
727 if (open.location != NSNotFound && [frame hasSuffix:@")"]) {
728 frame = [frame substringWithRange:NSMakeRange(open.location + 1, [frame length] - open.location - 2)];
729 }
730
731 NSArray* parts = [frame componentsSeparatedByString:@":"];
732 if ([parts count] < 3)
733 continue; // Native frame, e.g. "at log (native)".
734
735 NSUInteger count = [parts count];
736 *outFile = [[parts subarrayWithRange:NSMakeRange(0, count - 2)] componentsJoinedByString:@":"];
737 *outLine = (unsigned)[[parts objectAtIndex:count - 2] intValue];
738 return YES;
739 }
740 return NO;
741}

References count.

Referenced by LogProblem().

Here is the caller graph for this function:

◆ InterruptHandler()

int InterruptHandler ( OOJSInterruptHandlerArg * arg,
void * opaque )
static

Definition at line 693 of file OOJavaScriptEngine.m.

694{
696 return 0;
697
698 double elapsed = MonotonicTime() - sLimiterStart;
699 if (elapsed <= sLimiterTimeLimit)
700 return 0;
701
702 OOLogERR(@"script.javaScript.timeLimit", @"Script \"%@\" ran for %g seconds and has been terminated.", [[OOJSScript currentlyRunningScript] name], elapsed);
703#ifdef OO_DEBUG_MONITOR_ENABLED
705#endif
706 return 1;
707}
#define EXPECT(x)
static double sLimiterTimeLimit
static int sLimiterPauseDepth
static unsigned sLimiterStartDepth
static OOHighResTimeValue sLimiterStart
#define OOJSDumpStack(cx)
JSContext * gOOJSMainThreadContext
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
static double MonotonicTime(void)

References EXPECT, gOOJSMainThreadContext, MonotonicTime(), OOJSDumpStack, OOLogERR, sLimiterPauseDepth, sLimiterStart, sLimiterStartDepth, and sLimiterTimeLimit.

Here is the call graph for this function:

◆ JSArrayConverter()

id JSArrayConverter ( JSContext * context,
JSValueConst array )
static

Definition at line 1969 of file OOJavaScriptEngine.m.

1970{
1971 int64_t i, count;
1972
1973 // Convert a JS array to an NSArray by calling OOJSNativeObjectFromJSValue() on all its elements.
1974 if (!JS_IsArray(array))
1975 return nil;
1976 if (JS_GetLength(context, array, &count) < 0) {
1977 JS_FreeValue(context, JS_GetException(context));
1978 return nil;
1979 }
1980
1981 NSMutableArray* result = [NSMutableArray arrayWithCapacity:(NSUInteger)count];
1982 for (i = 0; i != count; ++i) {
1983 JSValue value = JS_GetPropertyUint32(context, array, (uint32_t)i);
1984 if (JS_IsException(value)) {
1985 JS_FreeValue(context, JS_GetException(context));
1986 value = JS_UNDEFINED;
1987 }
1988
1989 id object = OOJSNativeObjectFromJSValue(context, value);
1990 JS_FreeValue(context, value);
1991 if (object == nil)
1992 object = [NSNull null];
1993 [result addObject:object];
1994 }
1995
1996 return result;
1997}
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)

References count, nil, and OOJSNativeObjectFromJSValue().

Referenced by OOJavaScriptEngine(Private)::registerStandardObjectConverters.

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

◆ JSArrayFromNSArray()

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

Definition at line 1091 of file OOJavaScriptEngine.m.

1092{
1094
1095 if (array == nil)
1096 return JS_UNDEFINED;
1097
1098 JSValue result = JS_NewArray(context);
1099 if (JS_IsException(result))
1100 return JS_UNDEFINED;
1101
1102 @try {
1103 NSUInteger i, count = [array count];
1104 for (i = 0; i != count; ++i) {
1105 // JS_SetPropertyUint32() takes ownership of the value.
1106 JSValue value = [[array objectAtIndex:i] oo_jsValueInContext:context];
1107 if (EXPECT_NOT(JS_SetPropertyUint32(context, result, (uint32_t)i, value) < 0)) {
1108 JS_FreeValue(context, result);
1109 return JS_UNDEFINED;
1110 }
1111 }
1112 }
1113 @catch (id ex) {
1114 JS_FreeValue(context, result);
1115 return JS_UNDEFINED;
1116 }
1117
1118 return result;
1119
1121}
#define EXPECT_NOT(x)

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

◆ JSBooleanConverter()

id JSBooleanConverter ( JSContext * context,
JSValueConst object )
static

Definition at line 2014 of file OOJavaScriptEngine.m.

2015{
2016 /* Fun With JavaScript: Boolean(false) is a truthy value, since it's a
2017 non-null object. However, Boolean objects are transformed to numbers
2018 sanely, so this works.
2019 */
2020 double value;
2021 if (JS_ToFloat64(context, &value, object) == 0) {
2022 return [NSNumber numberWithBool:(value != 0)];
2023 }
2024 JS_FreeValue(context, JS_GetException(context));
2025 return nil;
2026}

References nil.

Referenced by OOJavaScriptEngine(Private)::registerStandardObjectConverters.

Here is the caller graph for this function:

◆ JSEntityIsDemoShipPredicate()

BOOL JSEntityIsDemoShipPredicate ( Entity * entity,
void * parameter )

Definition at line 1721 of file OOJavaScriptEngine.m.

1722{
1723 return ([entity isVisibleToScripts] && [entity isShip] && [entity status] == STATUS_COCKPIT_DISPLAY && ![entity isSubEntity]);
1724}

◆ JSEntityIsJavaScriptSearchablePredicate()

BOOL JSEntityIsJavaScriptSearchablePredicate ( Entity * entity,
void * parameter )

Definition at line 1689 of file OOJavaScriptEngine.m.

1690{
1692
1693 if (![entity isVisibleToScripts])
1694 return NO;
1695 if ([entity isShip]) {
1696 if ([entity isSubEntity])
1697 return NO;
1698 if ([entity status] == STATUS_COCKPIT_DISPLAY)
1699 return NO; // Demo ship
1700 return YES;
1701 } else if ([entity isPlanet]) {
1702 switch ([(OOPlanetEntity*)entity planetType]) {
1703 case STELLAR_TYPE_MOON:
1705 case STELLAR_TYPE_SUN:
1706 return YES;
1707
1708#if !NEW_PLANETS
1710#endif
1712 return NO;
1713 }
1714 }
1715
1716 return YES; // would happen if we added a new script-visible class
1717
1719}
@ 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 1680 of file OOJavaScriptEngine.m.

1681{
1683
1684 return [entity isVisibleToScripts];
1685
1687}

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

1644{
1646
1647 JSFunctionPredicateParameter* param = parameter;
1648 BOOL result = NO;
1649
1650 NSCParameterAssert(entity != nil && param != NULL);
1651 NSCParameterAssert(param->context != NULL);
1652 NSCParameterAssert(OOJSValueIsFunction(param->context, param->function));
1653
1654 if (EXPECT_NOT(param->errorFlag))
1655 return NO;
1656
1657 JSValue arg = [entity oo_jsValueInContext:param->context]; // entity is required to be non-nil (asserted above), so oo_jsValueInContext: is safe.
1658
1661 JSValue rval = JS_Call(param->context, param->function, param->jsThis, 1, (JSValueConst*)&arg);
1664
1665 JS_FreeValue(param->context, arg);
1666
1667 if (!JS_IsException(rval)) {
1668 result = OOJSValueToBOOL(param->context, rval);
1669 JS_FreeValue(param->context, rval);
1670 } else {
1671 OOJSReportPendingException(param->context);
1672 param->errorFlag = YES;
1673 }
1674
1675 return result;
1676
1678}
#define OOJSStopTimeLimiter()
#define OOJSStartTimeLimiter()
void OOJSPauseTimeLimiter(void)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
void OOJSResumeTimeLimiter(void)
void OOJSReportPendingException(JSContext *context)
BOOL OOJSValueToBOOL(JSContext *context, JSValueConst value)

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

Referenced by SystemFilteredEntities(), and SystemFilteredEntities().

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

◆ JSNumberConverter()

id JSNumberConverter ( JSContext * context,
JSValueConst object )
static

Definition at line 2004 of file OOJavaScriptEngine.m.

2005{
2006 double value;
2007 if (JS_ToFloat64(context, &value, object) == 0) {
2008 return [NSNumber numberWithDouble:value];
2009 }
2010 JS_FreeValue(context, JS_GetException(context));
2011 return nil;
2012}

References nil.

Referenced by OOJavaScriptEngine(Private)::registerStandardObjectConverters.

Here is the caller graph for this function:

◆ JSObjectConverter()

id JSObjectConverter ( JSContext * context,
JSValueConst object )
static

Definition at line 2028 of file OOJavaScriptEngine.m.

2029{
2030 /* SpiderMonkey's global object had a class of its own, with no converter,
2031 so it converted to nil. QuickJS's is a plain object, and converting it
2032 as one recurses until the stack overflows, since its global property
2033 refers to itself; a Timer whose this is the global object did that on firing.
2034 */
2035 JSValue global = JS_GetGlobalObject(context);
2036 BOOL isGlobal = JS_IsStrictEqual(context, global, object);
2037 JS_FreeValue(context, global);
2038 if (isGlobal)
2039 return nil;
2040
2041 return OOJSDictionaryFromJSObject(context, object);
2042}
NSDictionary * OOJSDictionaryFromJSObject(JSContext *context, JSObject *object)

References nil, and OOJSDictionaryFromJSObject().

Referenced by RegisterStandardObjectConverters().

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

◆ JSObjectFromNSDictionary()

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

Definition at line 1127 of file OOJavaScriptEngine.m.

1128{
1130
1131 if (dictionary == nil)
1132 return JS_UNDEFINED;
1133
1134 JSValue result = JS_NewObject(context);
1135 if (JS_IsException(result))
1136 return JS_UNDEFINED;
1137
1138 BOOL OK = YES;
1139 @try {
1140 id key = nil;
1141 foreachkey(key, dictionary)
1142 {
1143 JSValue value = JS_UNDEFINED;
1144 if ([key isKindOfClass:[NSString class]] && [key length] != 0) {
1145 value = [[dictionary objectForKey:key] oo_jsValueInContext:context];
1146 if (!JS_IsUndefined(value)) {
1147 OK = JS_SetProperty(context, result, OOJSIDFromString(key), value) >= 0;
1148 }
1149 } else if ([key isKindOfClass:[NSNumber class]]) {
1150 int index = [key intValue];
1151 if (0 < index) {
1152 value = [[dictionary objectForKey:key] oo_jsValueInContext:context];
1153 if (!JS_IsUndefined(value)) {
1154 OK = JS_SetPropertyUint32(context, result, (uint32_t)index, value) >= 0;
1155 }
1156 }
1157 }
1158
1159 if (EXPECT_NOT(!OK))
1160 break;
1161 }
1162 }
1163 @catch (id exception) {
1164 OK = NO;
1165 }
1166
1167 if (EXPECT_NOT(!OK)) {
1168 JS_FreeValue(context, result);
1169 return JS_UNDEFINED;
1170 }
1171
1172 return result;
1173
1175}
#define foreachkey(VAR, DICT)
jsid OOJSIDFromString(NSString *string)

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

Here is the call graph for this function:

◆ JSStringConverter()

id JSStringConverter ( JSContext * context,
JSValueConst object )
static

Definition at line 1999 of file OOJavaScriptEngine.m.

2000{
2001 return OOStringFromJSValue(context, object);
2002}

References OOStringFromJSValue().

Referenced by OOJavaScriptEngine(Private)::registerStandardObjectConverters.

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

◆ KeyForAtom()

id KeyForAtom ( JSContext * context,
JSAtom atom )
static

Definition at line 1781 of file OOJavaScriptEngine.m.

1782{
1783 NSString* key = OOStringFromJSID(atom);
1784 if ([key length] != 0 && [key length] < 10) {
1785 unichar first = [key characterAtIndex:0];
1786 if ((first >= '1' && first <= '9') || [key isEqualToString:@"0"]) {
1787 NSScanner* scanner = [NSScanner scannerWithString:key];
1788 int intValue;
1789 if ([scanner scanInt:&intValue] && [scanner isAtEnd]) {
1790 return [NSNumber numberWithInt:intValue];
1791 }
1792 }
1793 }
1794 return key;
1795}
NSString * OOStringFromJSID(JSAtom propID)

References OOStringFromJSID().

Referenced by OOJSDictionaryFromJSObject().

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

◆ LoadCompatibilityScript()

void LoadCompatibilityScript ( JSContext * context)
static

Definition at line 529 of file OOJavaScriptEngine.m.

530{
531 NSString* path = [ResourceManager pathForFileNamed:@"oolite-quickjs-compat.js" inFolder:@"Scripts"];
532 NSString* source = (path != nil) ? [NSString stringWithContentsOfUnicodeFile:path] : nil;
533 if (source == nil) {
534 OOLogERR(@"script.javaScript.init.error", @"%@", @"Could not load oolite-quickjs-compat.js; SpiderMonkey compatibility functions such as toSource() will be missing.");
535 return;
536 }
537
538 NSData* utf8 = [source dataUsingEncoding:NSUTF8StringEncoding];
539 NSMutableData* terminated = [NSMutableData dataWithData:utf8];
540 [terminated appendBytes:"" length:1]; // JS_Eval requires a terminating NUL.
541
542 JSValue result = JS_Eval(context, [terminated bytes], [utf8 length], [path UTF8String], JS_EVAL_TYPE_GLOBAL);
543 if (JS_IsException(result))
545 else if (JS_IsFunction(context, result))
546 sLegacyConstRewriter = JS_DupValue(context, result);
547 JS_FreeValue(context, result);
548
549 /* The bundled QuickJS-ng is patched (subprojects/packagefiles/quickjs-ng)
550 for SpiderMonkey behaviour OXPs rely on. Warn if this one isn't, e.g.
551 a system library.
552 */
553 static BOOL checked = NO;
554 if (!checked) {
555 checked = YES;
556 const char* test = "(function () { 'use strict'; try { 'x'.oolite = 1; new Math.max(); return true; } catch (e) { return false; } })()";
557 JSValue patched = JS_Eval(context, test, strlen(test), "<compatibility check>", JS_EVAL_TYPE_GLOBAL);
558 if (!JS_IsException(patched) && !OOJSValueToBOOL(context, patched)) {
559 OOLogWARN(@"script.javaScript.init.unpatchedEngine", @"%@", @"This QuickJS-ng library lacks Oolite's compatibility patches; some OXPs that worked with SpiderMonkey may fail. Build with the bundled QuickJS-ng subproject.");
560 }
561 if (JS_IsException(patched))
562 JS_FreeValue(context, JS_GetException(context));
563 JS_FreeValue(context, patched);
564 }
565}
#define OOLogWARN(class, format,...)
Definition OOLogging.h:126
static JSValue sLegacyConstRewriter
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)

References nil, OOJSReportPendingException(), OOJSValueToBOOL(), OOLogERR, OOLogWARN, ResourceManager::pathForFileNamed:inFolder:, and sLegacyConstRewriter.

Here is the call graph for this function:

◆ LogProblem()

void LogProblem ( JSContext * context,
NSString * severity,
NSString * errorName,
NSString * message,
NSString * stack )
static

Definition at line 762 of file OOJavaScriptEngine.m.

763{
764 NSString* messageClass = [NSString stringWithFormat:@"script.javaScript.%@.%@", severity, errorName];
765 NSString* highlight = [severity isEqualToString:@"warning"] ? @"-----" : @"*****";
766 OOJavaScriptEngine* jsEng = [OOJavaScriptEngine sharedEngine];
767
768 // Skip the rest if this is a warning being ignored. Errors and exceptions always go to the debug monitor.
769 if ([severity isEqualToString:@"warning"] && !OOLogWillDisplayMessagesInClass(messageClass))
770 return;
771
772 // avoid windows DEP exceptions!
773 OOJSScript* thisScript = [[OOJSScript currentlyRunningScript] weakRetain];
774 NSString* activeScript = [[thisScript weakRefUnderlyingObject] displayName];
775 [thisScript release];
776 if (activeScript == nil)
777 activeScript = @"<unidentified script>";
778 OOLog(messageClass, @"%@ JavaScript %@ (%@): %@", highlight, severity, activeScript, message);
779
780 NSString* file = nil;
781 unsigned line = 0;
782 if ([jsEng showErrorLocations] && sErrorHandlerStackSkip == 0 && GetLocationFromStack(stack, &file, &line)) {
783 OOLog(messageClass, @" %@, line %u.", file, line);
784 }
785
786#ifdef OO_DEBUG_MONITOR_ENABLED
787 BOOL dump = [severity isEqualToString:@"warning"] ? [jsEng dumpStackForWarnings] : [jsEng dumpStackForErrors];
788 if (dump && stack != nil)
789 OOLog(@"script.javaScript.stackTrace", @"%@", stack);
790#endif
791
792#if OOJSENGINE_MONITOR_SUPPORT
793 if (file == nil)
794 GetLocationFromStack(stack, &file, &line);
795 [jsEng sendMonitorProblemOfSeverity:severity
796 inFile:file
797 line:line
798 withMessage:message
799 inContext:context];
800#endif
801}
static unsigned sErrorHandlerStackSkip
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
Definition OOLogging.m:136
#define OOLog(class, format,...)
Definition OOLogging.h:84
static BOOL GetLocationFromStack(NSString *stack, NSString **outFile, unsigned *outLine)

References OOJSScript::currentlyRunningScript, GetLocationFromStack(), nil, OOLog, OOLogWillDisplayMessagesInClass(), sErrorHandlerStackSkip, OOJavaScriptEngine::sharedEngine, and OOJSScript::weakRetain.

Referenced by OOJSReportPendingException(), and OOJSReportWarningWithArguments().

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

◆ MonotonicTime()

double MonotonicTime ( void )
static

Definition at line 610 of file OOJavaScriptEngine.m.

611{
612#if OOLITE_WINDOWS
613 static LARGE_INTEGER frequency;
614 LARGE_INTEGER counter;
615 if (frequency.QuadPart == 0)
616 QueryPerformanceFrequency(&frequency);
617 QueryPerformanceCounter(&counter);
618 return (double)counter.QuadPart / (double)frequency.QuadPart;
619#else
620 struct timespec now;
621 clock_gettime(CLOCK_MONOTONIC, &now);
622 return now.tv_sec + now.tv_nsec * 1e-9;
623#endif
624}

Referenced by InterruptHandler(), OOJSPauseTimeLimiter(), OOJSResetTimeLimiter(), OOJSResumeTimeLimiter(), and OOJSStartTimeLimiterWithTimeLimit().

Here is the caller graph for this function:

◆ OOJSArgumentListGetNumber()

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

Definition at line 1004 of file OOJavaScriptEngine.m.

1005{
1006 if (OOJSArgumentListGetNumberNoError(context, argc, argv, outNumber, outConsumed)) {
1007 return YES;
1008 } else {
1009 OOJSReportBadArguments(context, scriptClass, function, argc, argv,
1010 @"Expected number, got", NULL);
1011 return NO;
1012 }
1013}
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)

◆ OOJSArgumentListGetNumberNoError()

BOOL OOJSArgumentListGetNumberNoError ( JSContext * context,
int argc,
JSValueConst * argv,
double * outNumber,
int * outConsumed )

Definition at line 1015 of file OOJavaScriptEngine.m.

1016{
1018
1019 double value;
1020
1021 NSCParameterAssert(context != NULL && (argv != NULL || argc == 0) && outNumber != NULL);
1022
1023 // Get value, if possible.
1024 if (EXPECT_NOT(argc < 1 || JS_ToFloat64(context, &value, argv[0]) < 0 || isnan(value))) {
1025 // ToNumber can throw (e.g. for a Symbol); this variant must not leave an exception pending.
1026 if (JS_HasException(context))
1027 JS_FreeValue(context, JS_GetException(context));
1028 if (outConsumed != NULL)
1029 *outConsumed = 0;
1030 return NO;
1031 }
1032
1033 // Success.
1034 *outNumber = value;
1035 if (outConsumed != NULL)
1036 *outConsumed = 1;
1037 return YES;
1038
1040}

◆ OOJSBasicPrivateObjectConverter()

id OOJSBasicPrivateObjectConverter ( JSContext * context,
JSValueConst object )

Definition at line 1951 of file OOJavaScriptEngine.m.

1952{
1953 /* This will do the right thing - for non-OOWeakReferences,
1954 weakRefUnderlyingObject returns the object itself. For nil, of course,
1955 it returns nil.
1956 */
1957 JSClassID ignored;
1958 id result = JS_GetAnyOpaque(object, &ignored);
1959 return [result weakRefUnderlyingObject];
1960}

◆ OOJSClassNameOfValue()

NSString * OOJSClassNameOfValue ( JSContext * context,
JSValueConst value )

Definition at line 1313 of file OOJavaScriptEngine.m.

1314{
1315 if (!JS_IsObject(value))
1316 return @"primitive";
1317
1318 const char* registered = OOJSClassName(JS_GetClassID(value));
1319 if (registered != NULL)
1320 return [NSString stringWithUTF8String:registered];
1321
1322 JSValue ctor = JS_GetPropertyStr(context, value, "constructor");
1323 JSValue name = JS_IsObject(ctor) ? JS_GetPropertyStr(context, ctor, "name") : JS_UNDEFINED;
1324 NSString* result = OOStringFromJSValue(context, name);
1325 JS_FreeValue(context, name);
1326 JS_FreeValue(context, ctor);
1327 return result ?: @"Object";
1328}
const char * OOJSClassName(JSClassID classID)
Definition OOJSClasses.m:89

◆ OOJSDescribeValue()

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

Definition at line 1404 of file OOJavaScriptEngine.m.

1405{
1406 return DescribeValue(context, value, abbreviateObjects, NO);
1407}

◆ OOJSDictionaryFromJSObject()

NSDictionary * OOJSDictionaryFromJSObject ( JSContext * context,
JSValueConst object )

Definition at line 1797 of file OOJavaScriptEngine.m.

1798{
1800
1801 JSPropertyEnum* properties = NULL;
1802 uint32_t i, count;
1803
1804 if (JS_GetOwnPropertyNames(context, &properties, &count, object, JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0) {
1805 JS_FreeValue(context, JS_GetException(context));
1806 return nil;
1807 }
1808
1809 NSMutableDictionary* result = [NSMutableDictionary dictionaryWithCapacity:count];
1810 for (i = 0; i != count; ++i) {
1811 id objKey = KeyForAtom(context, properties[i].atom);
1812 JSValue value = JS_GetProperty(context, object, properties[i].atom);
1813 if (JS_IsException(value)) {
1814 JS_FreeValue(context, JS_GetException(context));
1815 continue;
1816 }
1817
1818 if (objKey != nil && !JS_IsUndefined(value)) {
1819 id objValue = OOJSNativeObjectFromJSValue(context, value);
1820 if (objValue != nil) {
1821 [result setObject:objValue forKey:objKey];
1822 }
1823 }
1824 JS_FreeValue(context, value);
1825 }
1826
1827 JS_FreePropertyEnum(context, properties, count);
1828 return result;
1829
1831}
static id KeyForAtom(JSContext *context, JSAtom atom)

References count, KeyForAtom(), nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJSNativeObjectFromJSValue().

Referenced by OOJavaScriptEngine(Private)::registerStandardObjectConverters.

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

◆ OOJSDictionaryFromJSValue()

NSDictionary * OOJSDictionaryFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 1768 of file OOJavaScriptEngine.m.

1769{
1771
1772 if (EXPECT_NOT(!JS_IsObject(value))) {
1773 return nil;
1774 }
1775 return OOJSDictionaryFromJSObject(context, value);
1776
1778}

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

Definition at line 1833 of file OOJavaScriptEngine.m.

1834{
1836
1837 JSPropertyEnum* properties = NULL;
1838 uint32_t i, count;
1839
1840 if (EXPECT_NOT(JS_IsNull(tableValue) || JS_IsUndefined(tableValue))) {
1841 return nil;
1842 }
1843
1844 JSValue tableObject = JS_ToObject(context, tableValue);
1845 if (JS_IsException(tableObject)) {
1846 JS_FreeValue(context, JS_GetException(context));
1847 return nil;
1848 }
1849
1850 if (JS_GetOwnPropertyNames(context, &properties, &count, tableObject, JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0) {
1851 JS_FreeValue(context, JS_GetException(context));
1852 JS_FreeValue(context, tableObject);
1853 return nil;
1854 }
1855
1856 NSMutableDictionary* result = [NSMutableDictionary dictionaryWithCapacity:count];
1857 for (i = 0; i != count; ++i) {
1858 NSString* objKey = OOStringFromJSID(properties[i].atom);
1859 JSValue value = JS_GetProperty(context, tableObject, properties[i].atom);
1860 if (JS_IsException(value)) {
1861 JS_FreeValue(context, JS_GetException(context));
1862 continue;
1863 }
1864
1865 if (objKey != nil && !JS_IsUndefined(value)) {
1866 NSString* objValue = OOStringFromJSValueEvenIfNull(context, value);
1867 if (objValue != nil) {
1868 [result setObject:objValue forKey:objKey];
1869 }
1870 }
1871 JS_FreeValue(context, value);
1872 }
1873
1874 JS_FreePropertyEnum(context, properties, count);
1875 JS_FreeValue(context, tableObject);
1876 return result;
1877
1879}

References count, EXPECT_NOT, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOStringFromJSID(), and OOStringFromJSValueEvenIfNull().

Here is the call graph for this function:

◆ OOJSGetTimeLimiterLimit()

OOTimeDelta OOJSGetTimeLimiterLimit ( void )

Definition at line 666 of file OOJavaScriptEngine.m.

667{
668 return sLimiterTimeLimit;
669}

References sLimiterTimeLimit.

◆ OOJSIDFromString()

JSAtom OOJSIDFromString ( NSString * string)

Definition at line 1057 of file OOJavaScriptEngine.m.

1058{
1059 static NSMutableDictionary* sAtomCache = nil;
1060
1061 if (EXPECT_NOT(string == nil))
1062 return JS_ATOM_NULL;
1063
1064 NSNumber* cached = [sAtomCache objectForKey:string];
1065 if (cached != nil)
1066 return (JSAtom)[cached unsignedIntValue];
1067
1068 NSData* utf8 = [string dataUsingEncoding:NSUTF8StringEncoding];
1069 JSAtom atom = JS_NewAtomLen(OOJSAcquireContext(), [utf8 bytes], [utf8 length]);
1070 if (EXPECT(atom != JS_ATOM_NULL)) {
1071 if (sAtomCache == nil)
1072 sAtomCache = [[NSMutableDictionary alloc] init];
1073 [sAtomCache setObject:[NSNumber numberWithUnsignedInt:atom] forKey:string];
1074 }
1075 return atom;
1076}
OOINLINE JSContext * OOJSAcquireContext(void)

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

Here is the call graph for this function:

◆ OOJSInternAtomPRIVATE()

JSAtom OOJSInternAtomPRIVATE ( const char * name)

Definition at line 1046 of file OOJavaScriptEngine.m.

1047{
1048 NSCParameterAssert(name != NULL && name[0] != '\0');
1049
1050 JSAtom atom = JS_NewAtom(OOJSAcquireContext(), name);
1051 if (EXPECT_NOT(atom == JS_ATOM_NULL)) {
1052 [NSException raise:NSGenericException format:@"Failed to initialize JS ID cache for \"%s\".", name];
1053 }
1054 return atom;
1055}

References EXPECT_NOT, and OOJSAcquireContext().

Here is the call graph for this function:

◆ OOJSLegacyConstRewriter()

JSValueConst OOJSLegacyConstRewriter ( void )

Definition at line 520 of file OOJavaScriptEngine.m.

521{
523}

References sLegacyConstRewriter.

Referenced by RewriteLegacyConst().

Here is the caller graph for this function:

◆ OOJSNativeFailure()

JSValue OOJSNativeFailure ( JSContext * context)

Definition at line 894 of file OOJavaScriptEngine.m.

895{
896 if (JS_HasException(context))
897 return JS_EXCEPTION;
898
899 // Uncatchable errors are not reported by OOJSReportPendingException().
900 JSValue error = JS_NewError(context);
901 JS_SetUncatchableError(context, error);
902 return JS_Throw(context, error);
903}

◆ OOJSNativeObjectFromJSObject()

id OOJSNativeObjectFromJSObject ( JSContext * context,
JSValueConst object )

Definition at line 1918 of file OOJavaScriptEngine.m.

1919{
1921
1922 if (!JS_IsObject(object))
1923 return nil;
1924
1925 JSClassID classID = JS_GetClassID(object);
1926 OOJSClassConverterCallback converter = (classID < kOOJSMaxClassID) ? sObjectConverters[classID] : NULL;
1927 if (converter != NULL) {
1928 return converter(context, object);
1929 }
1930 return nil;
1931
1933}
id(* OOJSClassConverterCallback)(JSContext *context, JSObject *object)
static NSMutableDictionary * sObjectConverters
@ kOOJSMaxClassID

References kOOJSMaxClassID, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and sObjectConverters.

◆ OOJSNativeObjectFromJSValue()

id OOJSNativeObjectFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 1886 of file OOJavaScriptEngine.m.

1887{
1889
1890 if (JS_IsNull(value) || JS_IsUndefined(value))
1891 return nil;
1892
1893 int32_t intValue;
1894 double doubleValue;
1895
1896 if (JS_VALUE_GET_TAG(value) == JS_TAG_INT) {
1897 JS_ToInt32(context, &intValue, value);
1898 return [NSNumber numberWithInt:intValue];
1899 }
1900 if (JS_IsNumber(value)) {
1901 JS_ToFloat64(context, &doubleValue, value);
1902 return [NSNumber numberWithDouble:doubleValue];
1903 }
1904 if (JS_IsBool(value)) {
1905 return [NSNumber numberWithBool:JS_VALUE_GET_BOOL(value)];
1906 }
1907 if (JS_IsString(value)) {
1908 return OOStringFromJSValue(context, value);
1909 }
1910 if (JS_IsObject(value)) {
1911 return OOJSNativeObjectFromJSObject(context, value);
1912 }
1913 return nil;
1914
1916}
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *tableObject)

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

Here is the call graph for this function:

◆ OOJSNativeObjectOfClassFromJSObject()

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

Definition at line 1943 of file OOJavaScriptEngine.m.

1944{
1945 id result = OOJSNativeObjectFromJSObject(context, object);
1946 if (![result isKindOfClass:requiredClass])
1947 result = nil;
1948 return result;
1949}

References nil, and OOJSNativeObjectFromJSObject().

Here is the call graph for this function:

◆ OOJSNativeObjectOfClassFromJSValue()

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

Definition at line 1935 of file OOJavaScriptEngine.m.

1936{
1937 id result = OOJSNativeObjectFromJSValue(context, value);
1938 if (![result isKindOfClass:requiredClass])
1939 result = nil;
1940 return result;
1941}

References nil, and OOJSNativeObjectFromJSValue().

Here is the call graph for this function:

◆ OOJSObjectFromNativeObject()

JSValue OOJSObjectFromNativeObject ( JSContext * context,
id object )

Definition at line 1218 of file OOJavaScriptEngine.m.

1219{
1220 JSValue value = OOJSValueFromNativeObject(context, object);
1221 if (JS_IsObject(value) || JS_IsException(value))
1222 return value;
1223
1224 JSValue result = JS_ToObject(context, value);
1225 JS_FreeValue(context, value);
1226 return result;
1227}
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)

References OOJSValueFromNativeObject().

Referenced by ShipEntity(PureAI)::scanForNearestShipMatchingPredicate:.

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

◆ OOJSObjectGetterImplPRIVATE()

BOOL OOJSObjectGetterImplPRIVATE ( JSContext * context,
JSValueConst object,
JSClassID requiredClassID,
Class requiredObjCClass,
const char * name,
id * outObject )

Definition at line 1732 of file OOJavaScriptEngine.m.

1733{
1734 NSCParameterAssert(requiredObjCClass != Nil);
1735 NSCParameterAssert(context != NULL && requiredClassID != 0 && outObject != NULL);
1736
1737 /*
1738 Ensure it's a valid type of JS object. This is absolutely necessary,
1739 because if we don't check it we'll crash trying to get the private
1740 field of something that isn't an ObjC object wrapper - for example,
1741 Ship.setAI.call(new Vector3D, "") is valid JavaScript.
1742 */
1743 JSClassID actualClassID = JS_GetClassID(object);
1744 if (EXPECT_NOT(!OOJSIsSubclass(actualClassID, requiredClassID))) {
1745 OOJSReportError(context, @"Native method expected %s, got %@.", OOJSClassName(requiredClassID), OOStringFromJSValue(context, object));
1746 return NO;
1747 }
1748
1749 // Get the underlying object.
1750 JSClassID ignored;
1751 *outObject = [(id)JS_GetAnyOpaque(object, &ignored) weakRefUnderlyingObject];
1752
1753#ifndef NDEBUG
1754 // Double-check that the underlying object is of the expected ObjC class.
1755 if (EXPECT_NOT(*outObject != nil && ![*outObject isKindOfClass:requiredObjCClass])) {
1756 OOJSReportError(context, @"Native method expected %@ from %s and got correct JS type but incorrect native object %@", requiredObjCClass, OOJSClassName(requiredClassID), *outObject);
1757 return NO;
1758 }
1759#endif
1760
1761 return YES;
1762}
void OOJSReportError(JSContext *context, NSString *format,...)
BOOL OOJSIsSubclass(JSClass *putativeSubclass, JSClass *superclass)

References EXPECT_NOT, nil, OOJSClassName(), OOJSIsSubclass(), OOJSReportError(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ OOJSObjectWrapperFinalize()

void OOJSObjectWrapperFinalize ( JSRuntime * runtime,
JSValueConst this )

Definition at line 1597 of file OOJavaScriptEngine.m.

1598{
1600
1601 JSClassID classID;
1602 id object = JS_GetAnyOpaque(this, &classID);
1603 if (object != nil) {
1604 [[object weakRefUnderlyingObject] oo_clearJSSelf:this];
1605 [object release];
1606 JS_SetOpaque(this, NULL);
1607 }
1608
1610}

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

◆ OOJSObjectWrapperToString()

JSValue OOJSObjectWrapperToString ( JSContext * context,
JSValueConst this,
int argc,
JSValueConst * argv )

Definition at line 1612 of file OOJavaScriptEngine.m.

1613{
1614 OOJS_NATIVE_ENTER(context)
1615
1616 id object = nil;
1617 NSString* description = nil;
1618
1619 object = OOJSNativeObjectFromJSObject(context, this);
1620 if (object != nil) {
1621 description = [object oo_jsDescription];
1622 if (description == nil)
1623 description = [object description];
1624 }
1625 if (description == nil) {
1626 const char* className = OOJSClassName(JS_GetClassID(this));
1627 if (className != NULL) {
1628 description = [NSString stringWithFormat:@"[object %@]", [NSString stringWithUTF8String:className]];
1629 }
1630 }
1631 if (description == nil)
1632 description = @"[object]";
1633
1634 OOJS_RETURN_OBJECT(description);
1635
1637}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_RETURN_OBJECT(o)

References nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSClassName(), and OOJSNativeObjectFromJSObject().

Here is the call graph for this function:

◆ OOJSPauseTimeLimiter()

void OOJSPauseTimeLimiter ( void )

Definition at line 648 of file OOJavaScriptEngine.m.

649{
650 if (sLimiterPauseDepth++ == 0)
652}
static OOHighResTimeValue sLimiterPauseStart

References MonotonicTime(), sLimiterPauseDepth, and sLimiterPauseStart.

Here is the call graph for this function:

◆ OOJSRegisterObjectConverter()

void OOJSRegisterObjectConverter ( JSClassID classID,
OOJSClassConverterCallback converter )

Definition at line 1962 of file OOJavaScriptEngine.m.

1963{
1964 if (classID == 0 || classID >= kOOJSMaxClassID)
1965 return;
1966 sObjectConverters[classID] = converter;
1967}

References kOOJSMaxClassID, and sObjectConverters.

◆ OOJSReportBadArguments()

void OOJSReportBadArguments ( JSContext * context,
NSString * scriptClass,
NSString * function,
int argc,
JSValueConst * argv,
NSString * message,
NSString * expectedArgsDescription )

Definition at line 975 of file OOJavaScriptEngine.m.

976{
977 @try {
978 if (message == nil)
979 message = @"Invalid arguments";
980 message = [NSString stringWithFormat:@"%@ %@", message, [NSString stringWithJavaScriptParameters:argv count:argc inContext:context]];
981 if (expectedArgsDescription != nil)
982 message = [NSString stringWithFormat:@"%@ -- expected %@", message, expectedArgsDescription];
983
984 OOJSReportErrorForCaller(context, scriptClass, function, @"%@.", message);
985 }
986 @catch (id exception) {
987 // Squash any secondary errors during error handling.
988 }
989}
void OOJSReportErrorForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)

◆ OOJSReportBadPropertySelector()

void OOJSReportBadPropertySelector ( JSContext * context,
JSValueConst thisObj,
int magic,
const JSCFunctionListEntry * list,
size_t count )

Definition at line 958 of file OOJavaScriptEngine.m.

959{
960 NSString* propName = OOStringFromJSPropertyMagic(magic, list, count);
961 NSString* className = OOJSClassNameOfValue(context, thisObj);
962
963 OOJSReportError(context, @"Invalid property identifier %@ for instance of %@.", propName, className);
964}
NSString * OOJSClassNameOfValue(JSContext *context, JSValueConst value)
NSString * OOStringFromJSPropertyMagic(int magic, const JSCFunctionListEntry *list, size_t count)

◆ OOJSReportBadPropertyValue()

void OOJSReportBadPropertyValue ( JSContext * context,
JSValueConst thisObj,
int magic,
const JSCFunctionListEntry * list,
size_t count,
JSValueConst value )

Definition at line 966 of file OOJavaScriptEngine.m.

967{
968 NSString* propName = OOStringFromJSPropertyMagic(magic, list, count);
969 NSString* className = OOJSClassNameOfValue(context, thisObj);
970 NSString* valueDesc = OOJSDescribeValue(context, value, YES);
971
972 OOJSReportError(context, @"Cannot set property %@ of instance of %@ to invalid value %@.", propName, className, valueDesc);
973}
NSString * OOJSDescribeValue(JSContext *context, jsval value, BOOL abbreviateObjects)

◆ OOJSReportError()

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

Definition at line 842 of file OOJavaScriptEngine.m.

843{
844 va_list args;
845
846 va_start(args, format);
847 OOJSReportErrorWithArguments(context, format, args);
848 va_end(args);
849}
void OOJSReportErrorWithArguments(JSContext *context, NSString *format, va_list args)

References OOJSReportErrorWithArguments().

Here is the call graph for this function:

◆ OOJSReportErrorForCaller()

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

Definition at line 851 of file OOJavaScriptEngine.m.

852{
853 va_list args;
854 NSString* msg = nil;
855
856 @try {
857 va_start(args, format);
858 msg = [[NSString alloc] initWithFormat:format arguments:args];
859 va_end(args);
860
861 OOJSReportError(context, @"%@%@", CallerPrefix(scriptClass, function), msg);
862 }
863 @catch (id exception) {
864 // Squash any secondary errors during error handling.
865 }
866 [msg release];
867}
static NSString * CallerPrefix(NSString *scriptClass, NSString *function)

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

Here is the call graph for this function:

◆ OOJSReportErrorWithArguments()

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

Definition at line 869 of file OOJavaScriptEngine.m.

870{
871 NSString* msg = nil;
872
873 @try {
874 msg = [[NSString alloc] initWithFormat:format arguments:args];
875 JS_ThrowPlainError(context, "%s", [msg UTF8String]);
876 }
877 @catch (id exception) {
878 // Squash any secondary errors during error handling.
879 }
880 [msg release];
881}

References nil.

◆ OOJSReportPendingException()

void OOJSReportPendingException ( JSContext * context)

Definition at line 803 of file OOJavaScriptEngine.m.

804{
805 JSValue exception = JS_GetException(context);
806
807 // The time limiter has already logged a termination.
808 if (JS_IsUncatchableError(exception)) {
809 JS_FreeValue(context, exception);
810 return;
811 }
812
814
815 NSString* errorName = @"exception";
816 if (JS_IsError(exception)) {
817 JSValue name = JS_GetPropertyStr(context, exception, "name");
818 errorName = OOStringFromJSValue(context, name) ?: errorName;
819 JS_FreeValue(context, name);
820 }
821
822 NSString* message = OOStringFromJSValueEvenIfNull(context, exception);
823 if (!JS_IsError(exception)) {
824 message = [@"uncaught exception: " stringByAppendingString:message ?: @"?"];
825 }
826
827 LogProblem(context, @"exception", errorName, message, StackOfValue(context, exception));
828
829 JS_FreeValue(context, exception);
831}
static void LogProblem(JSContext *context, NSString *severity, NSString *errorName, NSString *message, NSString *stack)

References LogProblem(), OOJSPauseTimeLimiter(), OOJSResumeTimeLimiter(), OOStringFromJSValue(), OOStringFromJSValueEvenIfNull(), and StackOfValue().

Here is the call graph for this function:

◆ OOJSReportWarning()

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

Definition at line 905 of file OOJavaScriptEngine.m.

906{
907 va_list args;
908
909 va_start(args, format);
910 OOJSReportWarningWithArguments(context, format, args);
911 va_end(args);
912}
void OOJSReportWarningWithArguments(JSContext *context, NSString *format, va_list args)

References OOJSReportWarningWithArguments().

Here is the call graph for this function:

◆ OOJSReportWarningForCaller()

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

Definition at line 914 of file OOJavaScriptEngine.m.

915{
916 va_list args;
917 NSString* msg = nil;
918
919 @try {
920 va_start(args, format);
921 msg = [[NSString alloc] initWithFormat:format arguments:args];
922 va_end(args);
923
924 OOJSReportWarning(context, @"%@%@", CallerPrefix(scriptClass, function), msg);
925 }
926 @catch (id exception) {
927 // Squash any secondary errors during error handling.
928 }
929 [msg release];
930}
void OOJSReportWarning(JSContext *context, NSString *format,...)

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

Here is the call graph for this function:

◆ OOJSReportWarningWithArguments()

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

Definition at line 932 of file OOJavaScriptEngine.m.

933{
934 NSString* msg = nil;
935
936 @try {
937 msg = [[NSString alloc] initWithFormat:format arguments:args];
939 // SpiderMonkey reported Oolite's own warnings as error number 206, "ooliteDefined" in javascript-errors.plist.
940 LogProblem(context, @"warning", @"ooliteDefined", msg, CurrentStack(context));
942 }
943 @catch (id exception) {
944 // Squash any secondary errors during error handling.
945 }
946 [msg release];
947}
static NSString * CurrentStack(JSContext *context)

References CurrentStack(), LogProblem(), nil, OOJSPauseTimeLimiter(), and OOJSResumeTimeLimiter().

Here is the call graph for this function:

◆ OOJSReportWrappedException()

void OOJSReportWrappedException ( JSContext * context,
id exception )

Definition at line 883 of file OOJavaScriptEngine.m.

884{
885 if (!JS_HasException(context)) {
886 if ([exception isKindOfClass:[NSException class]])
887 OOJSReportError(context, @"Native exception: %@", [exception reason]);
888 else
889 OOJSReportError(context, @"Unidentified native exception");
890 }
891 // Else, let the pending exception propagate.
892}

References OOJSReportError().

Here is the call graph for this function:

◆ OOJSResetTimeLimiter()

void OOJSResetTimeLimiter ( void )

Definition at line 661 of file OOJavaScriptEngine.m.

662{
664}

References MonotonicTime(), and sLimiterStart.

Here is the call graph for this function:

◆ OOJSResumeTimeLimiter()

void OOJSResumeTimeLimiter ( void )

Definition at line 654 of file OOJavaScriptEngine.m.

References MonotonicTime(), sLimiterPauseDepth, sLimiterPauseStart, and sLimiterTimeLimit.

Here is the call graph for this function:

◆ OOJSSetTimeLimiterLimit()

void OOJSSetTimeLimiterLimit ( OOTimeDelta limit)

Definition at line 671 of file OOJavaScriptEngine.m.

672{
673 sLimiterTimeLimit = limit;
674}

References sLimiterTimeLimit.

◆ OOJSSetWarningOrErrorStackSkip()

void OOJSSetWarningOrErrorStackSkip ( unsigned skip)

Definition at line 991 of file OOJavaScriptEngine.m.

992{
994}

References sErrorHandlerStackSkip.

Referenced by SpecialJSWarning(), and SpecialJSWarning().

Here is the caller graph for this function:

◆ OOJSStartTimeLimiterWithTimeLimit()

void OOJSStartTimeLimiterWithTimeLimit ( OOTimeDelta limit)

Definition at line 626 of file OOJavaScriptEngine.m.

627{
628 if (sLimiterStartDepth++ == 0) {
629 if (limit <= 0.0)
630 limit = OOJS_TIME_LIMIT;
631 sLimiterTimeLimit = limit;
634 }
635}
#define OOJS_TIME_LIMIT

◆ OOJSStopTimeLimiter()

void OOJSStopTimeLimiter ( void )

Definition at line 637 of file OOJavaScriptEngine.m.

638{
639 if (sLimiterStartDepth == 0) {
640 OOLog(@"bug.javaScript.limiterDepth", @"%@", @"Attempt to stop JavaScript time limiter while it is already fully stopped. This is an internal bug, please report it.");
641 return;
642 }
643
644 if (--sLimiterStartDepth == 0)
645 sLimiterTimeLimit = 0.0;
646}

◆ OOJSUnconstructableConstruct()

JSValue OOJSUnconstructableConstruct ( JSContext * context,
JSValueConst this,
int argc,
JSValueConst * argv )

Definition at line 1586 of file OOJavaScriptEngine.m.

1587{
1588 // For constructors, this is new.target, i.e. the constructor function itself.
1589 JSValue nameVal = JS_GetPropertyStr(context, this, "name");
1590 NSString* name = OOStringFromJSValue(context, nameVal);
1591 JS_FreeValue(context, nameVal);
1592
1593 OOJSReportError(context, @"%@ cannot be used as a constructor.", name);
1594 return JS_EXCEPTION;
1595}

References OOJSReportError(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ OOJSValueToBOOL()

BOOL OOJSValueToBOOL ( JSContext * context,
JSValueConst value )

Definition at line 574 of file OOJavaScriptEngine.m.

575{
576 int result = JS_ToBool(context, value);
577 if (result < 0) {
578 JS_FreeValue(context, JS_GetException(context));
579 return NO;
580 }
581 return result != 0;
582}

◆ OOJSValueToInt32()

BOOL OOJSValueToInt32 ( JSContext * context,
JSValueConst value,
int32_t * outValue )

Definition at line 584 of file OOJavaScriptEngine.m.

585{
586 double number;
587 if (JS_ToFloat64(context, &number, value) < 0)
588 return NO;
589
590 number = floor(number + 0.5);
591 if (isnan(number) || number < INT32_MIN || number > INT32_MAX) {
592 OOJSReportError(context, @"can't convert %@ to an integer", OOStringFromJSValueEvenIfNull(context, value));
593 return NO;
594 }
595
596 *outValue = (int32_t)number;
597 return YES;
598}

References OOJSReportError(), and OOStringFromJSValueEvenIfNull().

Here is the call graph for this function:

◆ OOJSWrapScriptSource()

NSString * OOJSWrapScriptSource ( NSString * source)

Definition at line 567 of file OOJavaScriptEngine.m.

568{
569 // A newline before the closing part is needed if the last line is a // comment.
570 NSString* lineEnd = [source hasSuffix:@"\n"] ? @"" : @"\n";
571 return [NSString stringWithFormat:@"with(this){(function(){%@%@}).call(this)}", source, lineEnd];
572}

◆ OOStringFromJSID()

NSString * OOStringFromJSID ( JSAtom propID)

Definition at line 1078 of file OOJavaScriptEngine.m.

1079{
1080 JSContext* context = OOJSAcquireContext();
1081 JSValue value = JS_AtomToString(context, propID);
1082 NSString* result = OOStringFromJSValue(context, value);
1083 JS_FreeValue(context, value);
1084 return result;
1085}

References OOJSAcquireContext(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ OOStringFromJSPropertyMagic()

NSString * OOStringFromJSPropertyMagic ( int magic,
const JSCFunctionListEntry * list,
size_t count )

Definition at line 949 of file OOJavaScriptEngine.m.

950{
951 for (size_t i = 0; i < count; i++) {
952 if (list[i].def_type == JS_DEF_CGETSET_MAGIC && list[i].magic == magic)
953 return [NSString stringWithUTF8String:list[i].name];
954 }
955 return [NSString stringWithFormat:@"%i", magic];
956}

References count.

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

Here is the caller graph for this function:

◆ OOStringFromJSValue()

NSString * OOStringFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 1301 of file OOJavaScriptEngine.m.

1302{
1304
1305 if (EXPECT(!JS_IsNull(value) && !JS_IsUndefined(value))) {
1306 return OOStringFromJSValueEvenIfNull(context, value);
1307 }
1308 return nil;
1309
1311}

◆ OOStringFromJSValueEvenIfNull()

NSString * OOStringFromJSValueEvenIfNull ( JSContext * context,
JSValueConst value )

Definition at line 1283 of file OOJavaScriptEngine.m.

1284{
1286
1287 size_t length;
1288 const char* chars = JS_ToCStringLen(context, &length, value); // Calls the value's toString method if needed.
1289 if (chars == NULL) {
1290 JS_FreeValue(context, JS_GetException(context));
1291 return nil;
1292 }
1293
1294 NSString* result = [[[NSString alloc] initWithBytes:chars length:length encoding:NSUTF8StringEncoding] autorelease];
1295 JS_FreeCString(context, chars);
1296 return result;
1297
1299}

◆ RegisterStandardObjectConverters()

void RegisterStandardObjectConverters ( JSContext * context)
static

Definition at line 2044 of file OOJavaScriptEngine.m.

2045{
2046 if (gOOJSObjectClassID == 0) {
2047 // The standard class IDs are not part of the QuickJS API, so look them up from instances.
2048 const char* source = "[{}, new String(''), [], new Number(0), new Boolean(false)]";
2049 JSValue templates = JS_Eval(context, source, strlen(source), "<init>", JS_EVAL_TYPE_GLOBAL);
2051 for (uint32_t i = 0; i < OOJS_COUNT(ids); i++) {
2052 JSValue item = JS_GetPropertyUint32(context, templates, i);
2053 *ids[i] = JS_GetClassID(item);
2054 JS_FreeValue(context, item);
2055 }
2056 JS_FreeValue(context, templates);
2057 }
2058
2064}
static id JSNumberConverter(JSContext *context, JSObject *object)
static id JSStringConverter(JSContext *context, JSObject *object)
static id JSArrayConverter(JSContext *context, JSObject *object)
static id JSBooleanConverter(JSContext *context, JSObject *object)
JSClassID gOOJSArrayClassID
JSClassID gOOJSNumberClassID
JSClassID gOOJSBooleanClassID
#define OOJS_COUNT(array)
void OOJSRegisterObjectConverter(JSClassID classID, OOJSClassConverterCallback converter)
static id JSObjectConverter(JSContext *context, JSValueConst object)

References gOOJSArrayClassID, gOOJSBooleanClassID, gOOJSNumberClassID, gOOJSObjectClassID, gOOJSStringClassID, JSArrayConverter(), JSBooleanConverter(), JSNumberConverter(), JSObjectConverter(), JSStringConverter(), OOJS_COUNT, and OOJSRegisterObjectConverter().

Here is the call graph for this function:

◆ RemoveNonSpiderMonkeyGlobals()

void RemoveNonSpiderMonkeyGlobals ( JSContext * context,
JSValueConst global )
static

Definition at line 489 of file OOJavaScriptEngine.m.

490{
491 static const char* const kSpiderMonkeyGlobals[] = {
492 "undefined", "NaN", "Infinity", "eval", "isNaN", "isFinite", "parseFloat", "parseInt",
493 "escape", "unescape", "decodeURI", "encodeURI", "decodeURIComponent", "encodeURIComponent",
494 "Object", "Function", "Array", "Boolean", "Number", "String", "Date", "RegExp", "Math", "JSON",
495 "Error", "InternalError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError",
496 "ArrayBuffer", "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array",
497 "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "Proxy"
498 };
499
500 JSPropertyEnum* properties = NULL;
501 uint32_t count = 0;
502 if (JS_GetOwnPropertyNames(context, &properties, &count, global, JS_GPN_STRING_MASK) < 0) {
503 JS_FreeValue(context, JS_GetException(context));
504 return;
505 }
506
507 for (uint32_t i = 0; i < count; i++) {
508 const char* name = JS_AtomToCString(context, properties[i].atom);
509 BOOL keep = (name == NULL);
510 for (size_t j = 0; !keep && j < sizeof kSpiderMonkeyGlobals / sizeof *kSpiderMonkeyGlobals; j++) {
511 keep = (strcmp(name, kSpiderMonkeyGlobals[j]) == 0);
512 }
513 JS_FreeCString(context, name);
514 if (!keep)
515 JS_DeleteProperty(context, global, properties[i].atom, 0);
516 }
517 JS_FreePropertyEnum(context, properties, count);
518}

References count.

◆ StackOfValue()

NSString * StackOfValue ( JSContext * context,
JSValueConst value )
static

Definition at line 743 of file OOJavaScriptEngine.m.

744{
745 if (!JS_IsObject(value))
746 return nil;
747 JSValue stack = JS_GetPropertyStr(context, value, "stack");
748 NSString* result = OOStringFromJSValue(context, stack);
749 JS_FreeValue(context, stack);
750 return result;
751}

References nil, and OOStringFromJSValue().

Referenced by CurrentStack(), and OOJSReportPendingException().

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

Variable Documentation

◆ gOOJSArrayClassID

JSClassID gOOJSArrayClassID

Definition at line 1884 of file OOJavaScriptEngine.m.

◆ gOOJSBooleanClassID

JSClassID gOOJSBooleanClassID

Definition at line 1884 of file OOJavaScriptEngine.m.

◆ gOOJSMainThreadContext

◆ gOOJSNumberClassID

JSClassID gOOJSNumberClassID

Definition at line 1884 of file OOJavaScriptEngine.m.

◆ gOOJSObjectClassID

JSClassID gOOJSObjectClassID

Definition at line 1884 of file OOJavaScriptEngine.m.

Referenced by DescribeValue(), and RegisterStandardObjectConverters().

◆ gOOJSStringClassID

JSClassID gOOJSStringClassID

Definition at line 1884 of file OOJavaScriptEngine.m.

◆ kOOJavaScriptEngineDidResetNotification

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

Definition at line 113 of file OOJavaScriptEngine.m.

◆ kOOJavaScriptEngineWillResetNotification

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

Definition at line 112 of file OOJavaScriptEngine.m.

◆ sErrorHandlerStackSkip

unsigned sErrorHandlerStackSkip = 0
static

Definition at line 106 of file OOJavaScriptEngine.m.

◆ sLegacyConstRewriter

JSValue sLegacyConstRewriter = JS_UNDEFINED
static

Definition at line 110 of file OOJavaScriptEngine.m.

Referenced by LoadCompatibilityScript(), and OOJSLegacyConstRewriter().

◆ sLimiterPauseDepth

int sLimiterPauseDepth
static

Definition at line 605 of file OOJavaScriptEngine.m.

◆ sLimiterPauseStart

double sLimiterPauseStart
static

Definition at line 607 of file OOJavaScriptEngine.m.

◆ sLimiterStart

double sLimiterStart
static

Definition at line 606 of file OOJavaScriptEngine.m.

◆ sLimiterStartDepth

unsigned sLimiterStartDepth
static

Definition at line 604 of file OOJavaScriptEngine.m.

◆ sLimiterTimeLimit

double sLimiterTimeLimit
static

Definition at line 608 of file OOJavaScriptEngine.m.

◆ sObjectConverters

OOJSClassConverterCallback sObjectConverters[kOOJSMaxClassID]
static

Definition at line 1882 of file OOJavaScriptEngine.m.

◆ sSharedEngine

OOJavaScriptEngine* sSharedEngine = nil
static