Set iterator and range detach operations to noop
Leave the housekeeping to the NSHashTable itself, which should purge null-references automatically (not necessarily right away) Also update tests accordingly: Use `allObjects.count` instead of simply `count` on the NSHashTable, since `allObjects.count` returns non-null references. This should fix #36
This commit is contained in:
@@ -141,7 +141,7 @@
|
||||
|
||||
- (void)detachNodeIterator:(HTMLNodeIterator *)iterator
|
||||
{
|
||||
[_nodeIterators removeObject:iterator];
|
||||
// NOOP
|
||||
}
|
||||
|
||||
#pragma mark - Ranges
|
||||
@@ -153,7 +153,7 @@
|
||||
|
||||
- (void)detachRange:(HTMLRange *)range
|
||||
{
|
||||
[_ranges removeObject:range];
|
||||
// NOOP
|
||||
}
|
||||
|
||||
- (void)didRemoveCharacterDataInNode:(HTMLCharacterData *)node atOffset:(NSUInteger)offset withLength:(NSUInteger)length
|
||||
|
||||
@@ -580,19 +580,20 @@ static HTMLNode * (^ LastDescendant)(HTMLNode *) = ^ HTMLNode * (HTMLNode *node)
|
||||
XCTAssertNotNil(body);
|
||||
|
||||
// iterator should be deallocated and detached at this point
|
||||
XCTAssertEqual(0, nodeIterators.count);
|
||||
XCTAssertEqual(0, nodeIterators.allObjects.count);
|
||||
|
||||
// iterator should be autoreleased, deallocated and detached after autoreleasepool
|
||||
@autoreleasepool {
|
||||
HTMLNodeIterator *iterator = [[HTMLNodeIterator alloc] initWithNode:body];
|
||||
[iterator nextNode];
|
||||
XCTAssertEqual(1, nodeIterators.count);
|
||||
XCTAssertEqual(1, nodeIterators.allObjects.count);
|
||||
}
|
||||
|
||||
XCTAssertEqual(0, nodeIterators.count);
|
||||
XCTAssertEqual(0, nodeIterators.allObjects.count);
|
||||
}
|
||||
|
||||
- (void)testBugFix_Issue_22 {
|
||||
- (void)testBugFix_Issue_22
|
||||
{
|
||||
// The issue is applicable only for devices. On simulator the test is passed.
|
||||
HTMLDocument *document = [HTMLDocument documentWithString:@"<div id=\"id\"></div>"];
|
||||
|
||||
@@ -608,7 +609,8 @@ static HTMLNode * (^ LastDescendant)(HTMLNode *) = ^ HTMLNode * (HTMLNode *node)
|
||||
XCTAssertTrue([element.elementId isEqualToString:divId]);
|
||||
}
|
||||
|
||||
- (void)testBugFix_Issue_28 {
|
||||
- (void)testBugFix_Issue_28
|
||||
{
|
||||
HTMLDocument *document = self.document;
|
||||
HTMLNodeIterator *iterator = document.body.nodeIterator;
|
||||
|
||||
|
||||
@@ -2112,10 +2112,10 @@
|
||||
@autoreleasepool {
|
||||
HTMLRange *range = [[HTMLRange alloc] initWithDocument:document];
|
||||
[range cloneContents];
|
||||
XCTAssertEqual(1, ranges.count);
|
||||
XCTAssertEqual(1, ranges.allObjects.count);
|
||||
}
|
||||
|
||||
XCTAssertEqual(0, ranges.count);
|
||||
XCTAssertEqual(0, ranges.allObjects.count);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user