Skip to content

Commit

Permalink
Merge pull request #7334 from jhaynie/master
Browse files Browse the repository at this point in the history
[TIMOB-19768] iOS: changes related to Hyperloop
  • Loading branch information
pec1985 committed Oct 27, 2015
2 parents 8652766 + e5e0117 commit 7138293
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
22 changes: 21 additions & 1 deletion iphone/Classes/KrollBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@ -(void)gc

-(void)willStartNewContext:(KrollContext*)kroll
{
// Start Hyperloop engine if present
Class cls = NSClassFromString(@"Hyperloop");
if (cls) {
[cls performSelector:@selector(willStartNewContext:bridge:) withObject:kroll withObject:self];
}
[self retain]; // Hold onto ourselves as long as the context needs us
}

Expand Down Expand Up @@ -608,12 +613,23 @@ -(void)didStartNewContext:(KrollContext*)kroll
TiBindingRunLoopAnnounceStart(kroll);
[self evalFile:[startURL absoluteString] callback:self selector:@selector(booted)];
}


Class cls = NSClassFromString(@"Hyperloop");
if (cls) {
[cls performSelector:@selector(didStartNewContext:bridge:) withObject:kroll withObject:self];
}

[pool release];
}

-(void)willStopNewContext:(KrollContext*)kroll
{
// Stop Hyperloop engine if present
Class cls = NSClassFromString(@"Hyperloop");
if (cls) {
[cls performSelector:@selector(willStopNewContext:bridge:) withObject:kroll withObject:self];
}

if (shutdown==NO)
{
shutdown = YES;
Expand Down Expand Up @@ -641,6 +657,10 @@ -(void)didStopNewContext:(KrollContext*)kroll
RELEASE_TO_NIL(console);
RELEASE_TO_NIL(context);
RELEASE_TO_NIL(preload);
Class cls = NSClassFromString(@"Hyperloop");
if (cls) {
[cls performSelector:@selector(didStopNewContext:bridge:) withObject:kroll withObject:self];
}
[self autorelease]; // Safe to release now that the context is done
}

Expand Down
26 changes: 26 additions & 0 deletions iphone/Classes/TiBindingTiValue.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@
}
[jsonkey release];
}

// if this looks like a JS Error object, get the message
if ([dict objectForKey:@"line"] != nil && [dict objectForKey:@"column"] != nil) {
TiStringRef prop = TiStringCreateWithUTF8CString("message");
TiValueRef val = TiObjectGetProperty(jsContext, obj, prop, NULL);
id value = TiBindingTiValueToNSObject(jsContext, val);
if (value && ![value isEqual:[NSNull null]]) {
[dict setObject:value forKey:@"message"];
}
TiStringRelease(prop);
}

TiPropertyNameArrayRelease(props);

Expand Down Expand Up @@ -113,6 +124,21 @@ BOOL TiValueIsDate(JSContextRef js_context_ref, JSValueRef js_value_ref) {
if ([privateObject isKindOfClass:[KrollObject class]]) {
return [privateObject target];
}
if ([privateObject isKindOfClass:[TiProxy class]]) {
return privateObject;
}
// this is a special hyperloop wrapped object, unwrap it
if (privateObject == nil) {
TiStringRef jsString = TiStringCreateWithUTF8CString("$native");
TiValueRef jsValue = TiObjectGetProperty(jsContext, obj, jsString, NULL);
TiStringRelease(jsString);
if (TiValueIsObject(jsContext, jsValue)) {
privateObject = (id)TiObjectGetPrivate(TiValueToObject(jsContext, jsValue, NULL));
if (privateObject != nil) {
return privateObject;
}
}
}
if (TiValueIsArray(jsContext,obj)) {
TiValueRef length = TiObjectGetProperty(jsContext, obj, kTiStringLength, NULL);
double len = TiValueToNumber(jsContext, length, NULL);
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiToJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#define TiObjectSetPrivate JSObjectSetPrivate
#define TiObjectSetProperty JSObjectSetProperty
#define TiObjectSetPropertyAtIndex JSObjectSetPropertyAtIndex
#define TiObjectGetPrototype JSObjectGetPrototype
#define TiPropertyNameAccumulatorAddName JSPropertyNameAccumulatorAddName
#define TiPropertyNameAccumulatorRef JSPropertyNameAccumulatorRef
#define TiPropertyNameArrayGetCount JSPropertyNameArrayGetCount
Expand Down
6 changes: 6 additions & 0 deletions iphone/Classes/TiViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ -(void)add:(id)arg
position = [TiUtils intValue:[arg objectForKey:@"position"] def:-1];
} else if([arg isKindOfClass:[TiViewProxy class]]) {
childView = arg;
} else if ([arg isKindOfClass:[UIView class]] || [arg respondsToSelector:@selector(nativeObject)]) {
Class hyperloopViewProxy = NSClassFromString(@"HyperloopViewProxy");
if (hyperloopViewProxy != nil) {
childView = [(TiViewProxy*)[[hyperloopViewProxy alloc] _initWithPageContext:[self executionContext]] autorelease];
[childView performSelector:@selector(setNativeView:) withObject:arg];
}
}

if(childView == nil) {
Expand Down

0 comments on commit 7138293

Please sign in to comment.