33#define OOJSENGINE_MONITOR_SUPPORT OOLITE_DEBUG
39@protocol OOJavaScriptEngineMonitor;
59#if OOJSENGINE_MONITOR_SUPPORT
60 id<OOJavaScriptEngineMonitor> _monitor;
66- (JSObject *) globalObject;
68- (void) runMissionCallback;
76- (BOOL) callJSFunction:(jsval)function
77 forObject:(JSObject *)jsThis
80 result:(jsval *)outResult;
82- (void) removeGCObjectRoot:(JSObject **)rootPtr;
83- (void) removeGCValueRoot:(jsval *)rootPtr;
85- (void) garbageCollectionOpportunity:(BOOL)force;
87- (BOOL) showErrorLocations;
88- (void) setShowErrorLocations:(BOOL)value;
90- (JSClass *) objectClass;
91- (JSClass *) stringClass;
92- (JSClass *) arrayClass;
93- (JSClass *) numberClass;
94- (JSClass *) booleanClass;
97- (BOOL) dumpStackForErrors;
98- (void) setDumpStackForErrors:(BOOL)value;
100- (BOOL) dumpStackForWarnings;
101- (void) setDumpStackForWarnings:(BOOL)value;
104- (void) enableDebuggerStatement;
111#define JS_IsInRequest(context) (((void)(context)), YES)
112#define JS_BeginRequest(context) do {} while (0)
113#define JS_EndRequest(context) do {} while (0)
121 NSCAssert(
gOOJSMainThreadContext != NULL,
@"Attempt to use JavaScript context before JavaScript engine is initialized.");
157void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value);
158void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription);
178BOOL
OOJSArgumentListGetNumber(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv,
double *outNumber, uintN *outConsumed);
191 return BOOLEAN_TO_JSVAL(b != NO);
195@interface NSObject (OOJavaScript)
211- (jsval) oo_jsValueInContext:(JSContext *)context;
220- (NSString *) oo_jsDescriptionWithClassName:(NSString *)className;
227- (void) oo_clearJSSelf:(JSObject *)selfVal;
240 if (
object !=
nil)
return [object oo_jsValueInContext:context];
267+ (id) valueWithJSValue:(jsval)value inContext:(JSContext *)context;
268+ (id) valueWithJSObject:(JSObject *)object inContext:(JSContext *)context;
270- (id) initWithJSValue:(jsval)value inContext:(JSContext *)context;
271- (id) initWithJSObject:(JSObject *)object inContext:(JSContext *)context;
283#define OOJSSTR(str) ({ static jsval strCache; static BOOL inited; if (EXPECT_NOT(!inited)) OOJSStrLiteralCachePRIVATE(""str, &strCache, &inited); strCache; })
313NSString *
OOJSDescribeValue(JSContext *context, jsval value, BOOL abbreviateObjects);
323@interface NSString (OOJavaScriptExtensions)
326+ (NSString *) stringWithJavaScriptParameters:(jsval *)params count:(uintN)count inContext:(JSContext *)context;
329+ (NSString *) concatenationOfStringsFromJavaScriptValues:(jsval *)values count:(
size_t)count separator:(NSString *)separator inContext:(JSContext *)context;
332- (NSString *) escapedForJavaScriptLiteral;
370 return JS_GetClass(cx, obj);
372 return JS_GetClass(obj);
385 return JSVAL_IS_OBJECT(value) && !JSVAL_IS_NULL(value) && JS_ObjectIsFunction(context, JSVAL_TO_OBJECT(value));
399 return JSVAL_IS_OBJECT(value) && !JSVAL_IS_NULL(value) && JS_IsArrayObject(context, JSVAL_TO_OBJECT(value));
448#define DEFINE_JS_OBJECT_GETTER(NAME, JSCLASS, JSPROTO, OBJCCLASSNAME) \
449static BOOL NAME(JSContext *context, JSObject *inObject, OBJCCLASSNAME **outObject) GCC_ATTR((unused)); \
450static BOOL NAME(JSContext *context, JSObject *inObject, OBJCCLASSNAME **outObject) \
452 NSCParameterAssert(outObject != NULL); \
453 static Class cls = Nil; \
454 if (EXPECT_NOT(cls == Nil)) cls = [OBJCCLASSNAME class]; \
455 return OOJSObjectGetterImplPRIVATE(context, inObject, JSCLASS, cls, #NAME, (id *)outObject); \
458#define DEFINE_JS_OBJECT_GETTER(NAME, JSCLASS, JSPROTO, OBJCCLASSNAME) \
459OOINLINE BOOL NAME(JSContext *context, JSObject *inObject, OBJCCLASSNAME **outObject) \
461 return OOJSObjectGetterImplPRIVATE(context, inObject, JSCLASS, (id *)outObject); \
467BOOL
OOJSObjectGetterImplPRIVATE(JSContext *context, JSObject *
object, JSClass *requiredJSClass, Class requiredObjCClass,
const char *name,
id *outObject);
493BOOL
OOJSIsSubclass(JSClass *putativeSubclass, JSClass *superclass);
528#define OOJSAddGCValueRoot(context, root, name) JS_AddValueRoot((context), (root))
529#define OOJSAddGCStringRoot(context, root, name) JS_AddStringRoot((context), (root))
530#define OOJSAddGCObjectRoot(context, root, name) JS_AddObjectRoot((context), (root))
531#define OOJSAddGCThingRoot(context, root, name) JS_AddGCThingRoot((context), (root))
533#define OOJSAddGCValueRoot(context, root, name) JS_AddNamedValueRoot((context), (root), "" name)
534#define OOJSAddGCStringRoot(context, root, name) JS_AddNamedStringRoot((context), (root), "" name)
535#define OOJSAddGCObjectRoot(context, root, name) JS_AddNamedObjectRoot((context), (root), "" name)
536#define OOJSAddGCThingRoot(context, root, name) JS_AddNamedGCThingRoot((context), (root), "" name)
540#if OOJSENGINE_MONITOR_SUPPORT
547@protocol OOJavaScriptEngineMonitor <NSObject>
551 context:(in JSContext *)context
552 error:(in JSErrorReport *)errorReport
553 stackSkip:(in
unsigned)stackSkip
554 showingLocation:(in BOOL)showLocation
555 withMessage:(in NSString *)message;
559 context:(in JSContext *)context
560 logMessage:(in NSString *)message
561 ofClass:(in NSString *)messageClass;
566@interface OOJavaScriptEngine (OOMonitorSupport)
568- (void)setMonitor:(
id<OOJavaScriptEngineMonitor>)monitor;
600#define OOJSDumpStack(cx) do {} while (0)
601#define OOJSDescribeLocation(cx, frame) do {} while (0)
602#define OOJSMarkConsoleEvalLocation(cx, frame) do {} while (0)
639#define OOJS_PROP_READWRITE (JSPROP_PERMANENT | JSPROP_ENUMERATE)
640#define OOJS_PROP_READONLY (JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY)
643#define OOJS_PROP_HIDDEN_READWRITE (JSPROP_PERMANENT)
644#define OOJS_PROP_HIDDEN_READONLY (JSPROP_PERMANENT | JSPROP_READONLY)
647#define OOJS_METHOD_READONLY OOJS_PROP_HIDDEN_READONLY
650#define OOJS_PROP_READWRITE_CB (OOJS_PROP_READWRITE | JSPROP_SHARED)
651#define OOJS_PROP_READONLY_CB (OOJS_PROP_READONLY | JSPROP_SHARED)
653#define OOJS_PROP_HIDDEN_READWRITE_CB (OOJS_PROP_HIDDEN_READWRITE | JSPROP_SHARED)
654#define OOJS_PROP_HIDDEN_READONLY_CB (OOJS_PROP_HIDDEN_READONLY | JSPROP_SHARED)
660#define OOJS_THIS JS_THIS_OBJECT(context, vp)
661#define OOJS_ARGV JS_ARGV(context, vp)
662#define OOJS_RVAL JS_RVAL(context, vp)
663#define OOJS_SET_RVAL(v) JS_SET_RVAL(context, vp, v)
665#define OOJS_RETURN(v) do { OOJS_SET_RVAL(v); return YES; } while (0)
666#define OOJS_RETURN_JSOBJECT(o) OOJS_RETURN(OBJECT_TO_JSVAL(o))
667#define OOJS_RETURN_VOID OOJS_RETURN(JSVAL_VOID)
668#define OOJS_RETURN_NULL OOJS_RETURN(JSVAL_NULL)
669#define OOJS_RETURN_BOOL(v) OOJS_RETURN(OOJSValueFromBOOL(v))
670#define OOJS_RETURN_INT(v) OOJS_RETURN(INT_TO_JSVAL(v))
671#define OOJS_RETURN_OBJECT(o) OOJS_RETURN(OOJSValueFromNativeObject(context, o))
673#define OOJS_RETURN_WITH_HELPER(helper, value) \
676 BOOL OK = helper(context, value, &jsresult); \
677 JS_SET_RVAL(context, vp, jsresult); return OK; \
680#define OOJS_RETURN_VECTOR(value) OOJS_RETURN_WITH_HELPER(VectorToJSValue, value)
681#define OOJS_RETURN_HPVECTOR(value) OOJS_RETURN_WITH_HELPER(HPVectorToJSValue, value)
682#define OOJS_RETURN_QUATERNION(value) OOJS_RETURN_WITH_HELPER(QuaternionToJSValue, value)
683#define OOJS_RETURN_DOUBLE(value) OOJS_RETURN_WITH_HELPER(JS_NewNumberValue, value)
#define ALWAYS_INLINE_FUNC
#define INLINE_CONST_FUNC
void OOJSPauseTimeLimiter(void)
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
jsid OOJSIDFromString(NSString *string)
BOOL JSEntityIsDemoShipPredicate(Entity *entity, void *parameter)
BOOL OOJSArgumentListGetNumberNoError(JSContext *context, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)
void OOJSReportWarning(JSContext *context, NSString *format,...)
BOOL OOJSArgumentListGetNumber(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)
BOOL OOJSObjectGetterImplPRIVATE(JSContext *context, JSObject *object, JSClass *requiredJSClass, Class requiredObjCClass, const char *name, id *outObject)
BOOL JSEntityIsJavaScriptSearchablePredicate(Entity *entity, void *parameter)
NSString *const kOOJavaScriptEngineWillResetNotification
void OOJSReportWarningWithArguments(JSContext *context, NSString *format, va_list args)
NSString *const kOOJavaScriptEngineDidResetNotification
NSString * OOStringFromJSPropertyIDAndSpec(JSContext *context, jsid propID, JSPropertySpec *propertySpec)
#define JS_IsInRequest(context)
NSString * OOStringFromJSID(jsid propID)
OOINLINE BOOL OOJSValueIsArray(JSContext *context, jsval value)
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
void OOJSSetWarningOrErrorStackSkip(unsigned skip)
BOOL JSFunctionPredicate(Entity *entity, void *parameter)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE BOOL OOJSIsMemberOfSubclass(JSContext *context, JSObject *object, JSClass *superclass)
NSDictionary * OOJSDictionaryFromJSValue(JSContext *context, jsval value)
void OOJSReportWarningForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
void OOJSReportErrorForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
NSDictionary * OOJSDictionaryFromJSObject(JSContext *context, JSObject *object)
void OOJSMarkConsoleEvalLocation(JSContext *context, JSStackFrame *stackFrame)
id OOJSNativeObjectOfClassFromJSValue(JSContext *context, jsval value, Class requiredClass)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
void OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
JSObject * OOJSObjectFromNativeObject(JSContext *context, id object)
OOINLINE JSContext * OOJSAcquireContext(void)
NSString * OOJSDescribeValue(JSContext *context, jsval value, BOOL abbreviateObjects)
void OOJSReportError(JSContext *context, NSString *format,...)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
#define JS_BeginRequest(context)
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)
OOINLINE void OOJSRelinquishContext(JSContext *context)
id(* OOJSClassConverterCallback)(JSContext *context, JSObject *object)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define JS_EndRequest(context)
NSDictionary * OOJSDictionaryFromStringTable(JSContext *context, jsval value)
void OOJSReportErrorWithArguments(JSContext *context, NSString *format, va_list args)
void OOJSResumeTimeLimiter(void)
BOOL JSEntityIsJavaScriptVisiblePredicate(Entity *entity, void *parameter)
NSString * OOJSDescribeLocation(JSContext *context, JSStackFrame *stackFrame)
BOOL OOJSIsSubclass(JSClass *putativeSubclass, JSClass *superclass)
void OOJSDumpStack(JSContext *context)
NSString * OOStringFromJSString(JSContext *context, JSString *string)
OOINLINE JSClass * OOJSGetClass(JSContext *cx, JSObject *obj) ALWAYS_INLINE_FUNC
void OOJSStrLiteralCachePRIVATE(const char *string, jsval *strCache, BOOL *inited)
id OOJSNativeObjectOfClassFromJSObject(JSContext *context, JSObject *object, Class requiredClass)
JSContext * gOOJSMainThreadContext
NSString * oo_jsDescription()
NSString * oo_jsClassName()
BOOL _dumpStackForWarnings