Work on JavaScript API update: began work on meeting thread-safe API requirements. Game now loads and runs with trunk libjs.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3861 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-12-17 14:45:55 +00:00
parent e83e9a42db
commit cf81db538f
5 changed files with 23 additions and 5 deletions

View File

@ -50,8 +50,6 @@ _JS_ResolveStub
_OOReportJSBadPropertySelector
_OOReportJSError
_JS_InternString
_JS_AddNamedRoot
_JS_RemoveRoot
_JSValueToObject
_JS_ValueToNumber
_JS_SetProperty

View File

@ -129,7 +129,12 @@ void CreateOOJSGlobal(JSContext *context, JSObject **outGlobal)
{
assert(outGlobal != NULL);
#if OO_NEW_JS
*outGlobal = JS_NewCompartmentAndGlobalObject(context, &sGlobalClass, NULL);
#else
*outGlobal = JS_NewObject(context, &sGlobalClass, NULL, NULL);
#endif
JS_SetGlobalObject(context, *outGlobal);
JS_DefineProperty(context, *outGlobal, "global", OBJECT_TO_JSVAL(*outGlobal), NULL, NULL, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY);
}

View File

@ -105,13 +105,13 @@ static JSFunctionSpec sScriptMethods[] =
@implementation OOJSScript
+ (id)scriptWithPath:(NSString *)path properties:(NSDictionary *)properties
+ (id) scriptWithPath:(NSString *)path properties:(NSDictionary *)properties
{
return [[[self alloc] initWithPath:path properties:properties] autorelease];
}
- (id)initWithPath:(NSString *)path properties:(NSDictionary *)properties
- (id) initWithPath:(NSString *)path properties:(NSDictionary *)properties
{
OOJavaScriptEngine *engine = nil;
JSContext *context = NULL;
@ -127,6 +127,7 @@ static JSFunctionSpec sScriptMethods[] =
engine = [OOJavaScriptEngine sharedEngine];
context = [engine acquireContext];
JS_BeginRequest(context);
// Set up JS object
if (!problem)
@ -226,8 +227,9 @@ static JSFunctionSpec sScriptMethods[] =
self = nil;
}
JS_EndRequest(context);
[engine releaseContext:context];
return self;
// Analyzer: object leaked. [Expected, object is retained by JS object.]
}
@ -241,8 +243,12 @@ static JSFunctionSpec sScriptMethods[] =
DESTROY(filePath);
JSContext *context = [[OOJavaScriptEngine sharedEngine] acquireContext];
JS_BeginRequest(context);
JSObjectWrapperFinalize(context, _jsSelf); // Release weakref to self
JS_RemoveObjectRoot(context, &_jsSelf); // Unroot jsSelf
JS_EndRequest(context);
[[OOJavaScriptEngine sharedEngine] releaseContext:context];
[weakSelf weakRefDrop];

View File

@ -568,4 +568,7 @@ static inline void JS_RemoveStringRoot(JSContext *cx, JSString **rp) { JS_Remove
static inline void JS_RemoveObjectRoot(JSContext *cx, JSObject **rp) { JS_RemoveRoot(cx, rp); }
static inline void JS_RemoveGCThingRoot(JSContext *cx, void **rp) { JS_RemoveRoot(cx, rp); }
#define JS_BeginRequest(cx) do {} while (0)
#define JS_EndRequest(cx) do {} while (0)
#endif

View File

@ -264,6 +264,8 @@ static void ReportJSError(JSContext *context, const char *message, JSErrorReport
exit(1);
}
JS_BeginRequest(mainContext);
JS_SetOptions(mainContext, OOJSENGINE_CONTEXT_OPTIONS);
JS_SetVersion(mainContext, OOJSENGINE_JSVERSION);
@ -314,6 +316,8 @@ static void ReportJSError(JSContext *context, const char *message, JSErrorReport
InitOOJSEquipmentInfo(mainContext, globalObject);
InitOOJSShipGroup(mainContext, globalObject);
JS_EndRequest(mainContext);
sSharedEngine = self;
// Run prefix script.
@ -1117,7 +1121,9 @@ static BOOL JSNewNSDictionaryValue(JSContext *context, NSDictionary *dictionary,
}
_val = value;
JS_BeginRequest(context);
JS_AddNamedValueRoot(context, &_val, "OOJSValue");
JS_EndRequest(context);
if (tempCtxt) [[OOJavaScriptEngine sharedEngine] releaseContext:context];
}