summaryrefslogtreecommitdiff
path: root/test/DOMTSHandler.pm
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-02-16 12:04:20 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-02-16 12:04:20 +0000
commit200e0137b1d6397af6097d9359749e09622ba83a (patch)
treed10aa8ed45d84961c277665b30e0d645da70d925 /test/DOMTSHandler.pm
parent9bb1399bac063e4daac119fc636147cbab066c9d (diff)
downloadlibdom-200e0137b1d6397af6097d9359749e09622ba83a.tar.gz
libdom-200e0137b1d6397af6097d9359749e09622ba83a.tar.bz2
DOMTSHandler: Unref nodes in for-each blocks
In order to satisfy (hopefully) the last of the sanitize checks, ensure that we unref nodes during `for-each` iterations. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'test/DOMTSHandler.pm')
-rw-r--r--test/DOMTSHandler.pm18
1 files changed, 16 insertions, 2 deletions
diff --git a/test/DOMTSHandler.pm b/test/DOMTSHandler.pm
index 81ac9b1..7c68cd4 100644
--- a/test/DOMTSHandler.pm
+++ b/test/DOMTSHandler.pm
@@ -180,6 +180,7 @@ sub new {
# The list for UNREF
unref => [],
string_unref => [],
+ block_unrefs => ["!!!"],
# The indent of current statement
indent => "",
# The variables for List/Collection
@@ -1251,7 +1252,9 @@ sub generate_control_statement {
}
case "for-each" {
- # Detect what is the collection type, if it is "string", we
+ # Push a block onto the cleanups
+ push(@{$self->{"block_unrefs"}}, "b");
+ # Detect what is the collection type, if it is "string", we
# should also do some conversion work
my $coll = $ats->{"collection"};
# The default member type is dom_node
@@ -1308,6 +1311,7 @@ sub generate_control_statement {
print "foreach_initialise_domnodelist($coll, \&iterator$iterator_index);\n";
print "while(get_next_domnodelist($coll, \&iterator$iterator_index, \&$member)) {\n";
$self->addto_cleanup($member);
+ push(@{$self->{'block_unrefs'}}, $member);
}
if ($self->{"var"}->{$coll} eq "NamedNodeMap") {
@@ -1316,6 +1320,7 @@ sub generate_control_statement {
print "foreach_initialise_domnamednodemap($coll, \&iterator$iterator_index);\n";
print "while(get_next_domnamednodemap($coll, \&iterator$iterator_index, \&$member)) {\n";
$self->addto_cleanup($member);
+ push(@{$self->{'block_unrefs'}}, $member);
}
if ($self->{"var"}->{$coll} eq "HTMLCollection") {
@@ -1324,6 +1329,7 @@ sub generate_control_statement {
print "foreach_initialise_domhtmlcollection($coll, \&iterator$iterator_index);\n";
print "while(get_next_domhtmlcollection($coll, \&iterator$iterator_index, \&$member)) {\n";
$self->addto_cleanup($member);
+ push(@{$self->{'block_unrefs'}}, $member);
}
}
}
@@ -1342,12 +1348,20 @@ sub complete_control_statement {
case [qw(if while for-each)] {
# Firstly, we should cleanup the dom_string in this block
$self->cleanup_block_domstring();
-
+ $self->pop_block_unrefs() if ($name eq 'for-each');
print "}\n";
}
}
}
+sub pop_block_unrefs {
+ my ($self) = @_;
+ while ((my $var = pop(@{$self->{'block_unrefs'}})) ne 'b') {
+ die "OMG!" if ($var eq '!!!');
+ print("if ($var != NULL) {\n dom_node_unref($var);\n $var = NULL;\n}\n");
+ }
+}
+
###############################################################################
#