Skip to content

Commit

Permalink
Merge pull request #8 from hansemannn/TIMOB-20416
Browse files Browse the repository at this point in the history
[TIMOB-20416] Correct #ifdef statements, add "window" property
  • Loading branch information
pec1985 committed Apr 1, 2016
2 parents 53177ab + ce7d4b9 commit 12b5f6d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
5 changes: 3 additions & 2 deletions iphone/src/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

#define RELEASE_AND_CHECK(s) { if (s) { s = nil; } }

#if defined(DEBUG) && defined(TARGET_IPHONE_SIMULATOR)
#if defined(DEBUG)
#if TARGET_OS_SIMULATOR
#define REMEMBER(p) { HyperloopTrackAddObject((__bridge void *)(p), [NSString stringWithFormat:@"%p (%@) (%s:%d)\n%@", p, [p class], __FILE__, __LINE__, [[NSThread callStackSymbols] componentsJoinedByString:@"\n"]]); }
#define FORGET(p) HyperloopTrackRemoveObject((__bridge void *)(p))
void HyperloopTrackAddObject (void * p, id description);
Expand All @@ -42,7 +43,7 @@ void HyperloopTrackDumpAll();
#define REMEMBER(p)
#define FORGET(p)
#endif

#endif

#define ARCRetain(...) { void *retainedThing = (__bridge_retained void *)__VA_ARGS__; retainedThing = retainedThing; }

Expand Down
8 changes: 6 additions & 2 deletions iphone/src/utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,12 @@ +(void)invokeCallback:(id)callback args:(NSArray *)args thisObject:(id)thisObjec
TiValueProtect(context, function);
TiValueProtect(context, thisRef);
TiObjectCallAsFunction(context, function, thisObjectRef, [args count], jsArgs, &exception);
#if defined(TIMODULE) && defined(TARGET_IPHONE_SIMULATOR)
#if defined(TIMODULE)
#if TARGET_OS_SIMULATOR
if (exception) {
NSLog(@"[ERROR] JS exception encountered calling callback: %@", [Hyperloop JSValueRefToNSException:exception]);
}
#endif
#endif
if (args) {
for (size_t c = 0; c < [args count]; c++) {
Expand Down Expand Up @@ -430,10 +432,12 @@ +(id)invokeCustomCallback:(NSArray *)args identifier:(NSString *)identifier this
TiValueProtect(context, function);
TiObjectRef thisObject = HyperloopGetWrapperForId(sender);
TiValueRef jsResult = TiObjectCallAsFunction(context, function, thisObject, [args count], jsArgs, &exception);
#if defined(TIMODULE) && defined(TARGET_IPHONE_SIMULATOR)
#if defined(TIMODULE)
#if TARGET_OS_SIMULATOR
if (exception) {
NSLog(@"[ERROR] JS exception encountered calling callback: %@", [Hyperloop JSValueRefToNSException:exception]);
}
#endif
#endif
if (exception == NULL) {
result = TiValueRefToId(context, jsResult, NULL);
Expand Down
24 changes: 12 additions & 12 deletions iphone/titanium/HyperloopModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ -(TiObjectRef) propsObject;
@end
#endif

#ifdef TARGET_OS_SIMULATOR
// extern void JSSynchronousGarbageCollectForDebugging(TiContextRef);
#if TARGET_OS_SIMULATOR
extern void JSSynchronousGarbageCollectForDebugging(TiContextRef);
#endif

static TiClassRef classClassRef;
Expand Down Expand Up @@ -629,11 +629,11 @@ static TiObjectRef Constructor (TiContextRef ctx, TiObjectRef constructor, size_
/**
* forces a garbage collection, this is called from JavaScript, `Hyperloop.garbageCollect()`
*/
#ifdef TARGET_OS_SIMULATOR
#if TARGET_OS_SIMULATOR
JS_CALLBACK(GarbageCollect)
// NSLog(@"[HYPERLOOP] 🚚\tGarbage Collection");
// JSSynchronousGarbageCollectForDebugging(ctx);
// return TiValueMakeUndefined(ctx);
NSLog(@"[HYPERLOOP] 🚚\tGarbage Collection");
JSSynchronousGarbageCollectForDebugging(ctx);
return TiValueMakeUndefined(ctx);
JS_CALLBACK_END
#endif

Expand Down Expand Up @@ -1053,7 +1053,7 @@ @implementation Hyperloop
* this method is called before Titanium loads to allow Hyperloop to bootstrap into the JS VM
*/
+(void)willStartNewContext:(KrollContext *)kroll bridge:(KrollBridge *)krollbridge {
#ifdef TARGET_IPHONE_SIMULATOR
#if TARGET_OS_SIMULATOR
NSLog(@"[HYPERLOOP] willStartNewContext %@", kroll);
#endif

Expand All @@ -1064,7 +1064,7 @@ +(void)willStartNewContext:(KrollContext *)kroll bridge:(KrollBridge *)krollbrid
NSLog(@"[WARN] Hyperloop is running in DEMO mode. This application will not run in production. To register this application with the Appcelerator Platform, run the command: appc new --import");
} else {
NSLog(@"[ERROR] Hyperloop is not currently supported because this application has not been registered. To register this application with the Appcelerator Platform, run the command: appc new --import");
#ifdef TARGET_IPHONE_SIMULATOR
#if TARGET_OS_SIMULATOR
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Hyperloop"
message:@"Hyperloop is not currently supported because this application has not been registered. To register this application with the Appcelerator Platform, run the command: appc new --import"
delegate:nil
Expand Down Expand Up @@ -1133,7 +1133,7 @@ +(void)willStartNewContext:(KrollContext *)kroll bridge:(KrollBridge *)krollbrid
// add our implementations


#ifdef TARGET_OS_SIMULATOR
#if TARGET_OS_SIMULATOR
MAKECALLBACK(garbageCollect, GarbageCollect);
#endif
MAKECALLBACK(getWrapper, GetWrapper);
Expand Down Expand Up @@ -1187,7 +1187,7 @@ +(void)willStartNewContext:(KrollContext *)kroll bridge:(KrollBridge *)krollbrid
* this method is called after Titanium starts the context
*/
+(void)didStartNewContext:(KrollContext *)kroll bridge:(KrollBridge *)bridge{
#ifdef TARGET_IPHONE_SIMULATOR
#if TARGET_OS_SIMULATOR
NSLog(@"[HYPERLOOP] didStartNewContext %@", kroll);
#endif
}
Expand All @@ -1197,7 +1197,7 @@ +(void)didStartNewContext:(KrollContext *)kroll bridge:(KrollBridge *)bridge{
* this method is called before Titanium shuts down the context
*/
+(void)willStopNewContext:(KrollContext *)kroll bridge:(KrollBridge *)bridge{
#ifdef TARGET_IPHONE_SIMULATOR
#if TARGET_OS_SIMULATOR
NSLog(@"[HYPERLOOP] willStopNewContext %@", kroll);
#endif
if (context) {
Expand Down Expand Up @@ -1230,7 +1230,7 @@ +(void)willStopNewContext:(KrollContext *)kroll bridge:(KrollBridge *)bridge{
* this method is called after Titanium stops the context
*/
+(void)didStopNewContext:(KrollContext *)kroll bridge:(KrollBridge *)bridge{
#ifdef TARGET_IPHONE_SIMULATOR
#if TARGET_OS_SIMULATOR
NSLog(@"[HYPERLOOP] didStopNewContext %@", kroll);
#endif
}
Expand Down
9 changes: 9 additions & 0 deletions metabase/ios/templates/builtins/titanium.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ module.exports = function (json, callback) {
value: 'NSString *'
}
},
window: {
name: 'window',
attributes: ['readonly'],
type: {
type: 'obj_interface',
encoding: '@',
value: 'UIWindow *'
}
},
userAgent: {
name: 'sessionId',
attributes: ['readonly'],
Expand Down

0 comments on commit 12b5f6d

Please sign in to comment.