[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Add detect object recursion debug code. (#2209)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor authored and doumafang committed Mar 13, 2019
1 parent c6f65a2 commit 642fc5f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions ios/sdk/WeexSDK/Sources/Utility/WXConvertUtility.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,45 @@

NSString* const JSONSTRING_SUFFIX = @"\t\n\t\r";

#if 0

void _detectObjectRecursion(id object, NSMutableSet* nodes)
{
if (object == nil) {
return;
}
if ([object isKindOfClass:[NSString class]] ||
[object isKindOfClass:[NSNumber class]] ||
[object isKindOfClass:[NSNull class]]) {
return;
}

if ([object isKindOfClass:[NSArray class]]) {
for (id subobj in object) {
if ([nodes containsObject:subobj]) {
NSLog(@"Find recursion.");
}
[nodes addObject:subobj];
_detectObjectRecursion(subobj, nodes);
[nodes removeObject:subobj];
}
}
else if ([object isKindOfClass:[NSDictionary class]]) {
NSArray* allKeys = [object allKeys];
for (id key in allKeys) {
id subobj = object[key];
if ([nodes containsObject:subobj]) {
NSLog(@"Find recursion.");
}
[nodes addObject:subobj];
_detectObjectRecursion(subobj, nodes);
[nodes removeObject:subobj];
}
}
}

#endif

NSString* TO_JSON(id object)
{
if (object == nil) {
Expand All @@ -31,6 +70,12 @@

@try {
if ([object isKindOfClass:[NSArray class]] || [object isKindOfClass:[NSDictionary class]]) {

#if 0
NSMutableSet* nodes = [[NSMutableSet alloc] init];
_detectObjectRecursion(object, nodes);
#endif

NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:object
options:0
Expand Down

0 comments on commit 642fc5f

Please sign in to comment.