Skip to content

Commit

Permalink
[TIMOB-26179] Check for property exitence using hasProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
janvennemann committed Jul 3, 2018
1 parent 5b9431a commit 466235a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions iphone/Classes/KrollObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,36 @@ void KrollInitializer(TiContextRef ctx, TiObjectRef object)
}
}

bool KrollHasProperty(TiContextRef jsContext, TiObjectRef object, TiStringRef propertyName)
{
waitForMemoryPanicCleared();

// Debugger may actually try to get properties off global Kroll property (which is a special case KrollContext singleton)
id privateObject = (id)TiObjectGetPrivate(object);
if ([privateObject isKindOfClass:[KrollContext class]]) {
return false;
}

if (TiStringIsEqual(propertyName, kTiStringTiPropertyKey)) {
return false;
}

KrollObject *o = (KrollObject *)privateObject;
TiObjectRef exports = [o objectForTiString:kTiStringExportsKey context:jsContext];
if ((exports != NULL) && TiObjectHasProperty(jsContext, exports, propertyName)) {
return true;
}

NSString *name = (NSString *)TiStringCopyCFString(kCFAllocatorDefault, propertyName);
[name autorelease];
id result = [o valueForKey:name];
if (result != nil) {
return true;
}

return false;
}

//
// callback for handling retrieving an objects property (in JS land)
//
Expand Down Expand Up @@ -374,6 +404,7 @@ + (void)initialize
classDef.className = "Object";
classDef.initialize = KrollInitializer;
classDef.finalize = KrollFinalizer;
classDef.hasProperty = KrollHasProperty;
classDef.setProperty = KrollSetProperty;
classDef.getProperty = KrollGetProperty;
classDef.deleteProperty = KrollDeleteProperty;
Expand Down

0 comments on commit 466235a

Please sign in to comment.