diff --git a/src/document/dom/select.c b/src/document/dom/select.c index 457a959be..c9c6717b3 100644 --- a/src/document/dom/select.c +++ b/src/document/dom/select.c @@ -376,7 +376,7 @@ parse_dom_select(struct dom_select *select, unsigned char *string, int length) struct dom_select_node sel; init_scanner(&scanner, &css_scanner_info, string, string + length); - init_dom_stack(&stack, 1); + init_dom_stack(&stack, DOM_STACK_KEEP_NODES); memset(&sel, 0, sizeof(sel)); @@ -869,11 +869,11 @@ select_dom_nodes(struct dom_select *select, struct dom_node *root) select_data.select = select;; - init_dom_stack(&stack, 1); + init_dom_stack(&stack, DOM_STACK_KEEP_NODES); add_dom_stack_context(&stack, &select_data, &dom_select_context_info); - init_dom_stack(&select_data.stack, 1); + init_dom_stack(&select_data.stack, DOM_STACK_KEEP_NODES); add_dom_stack_context(&stack, &select_data, &dom_select_data_context_info); diff --git a/src/document/dom/stack.c b/src/document/dom/stack.c index 531254257..984cb75a6 100644 --- a/src/document/dom/stack.c +++ b/src/document/dom/stack.c @@ -53,13 +53,13 @@ realloc_dom_stack_state_objects(struct dom_stack_context *context, size_t depth) } void -init_dom_stack(struct dom_stack *stack, int keep_nodes) +init_dom_stack(struct dom_stack *stack, enum dom_stack_flag flags) { assert(stack); memset(stack, 0, sizeof(*stack)); - stack->keep_nodes = !!keep_nodes; + stack->flags = flags; } void @@ -178,7 +178,7 @@ do_pop_dom_node(struct dom_stack *stack, struct dom_stack_state *parent) call_dom_stack_callbacks(stack, state, DOM_STACK_POP); - if (!stack->keep_nodes) + if (!(stack->flags & DOM_STACK_KEEP_NODES)) done_dom_node(state->node); stack->depth--; diff --git a/src/document/dom/stack.h b/src/document/dom/stack.h index 988399cc6..9162a5a44 100644 --- a/src/document/dom/stack.h +++ b/src/document/dom/stack.h @@ -53,6 +53,11 @@ struct dom_stack_state { unsigned int immutable:1; }; +enum dom_stack_flag { + /* Keep nodes when popping them or call done_dom_node() on them. */ + DOM_STACK_KEEP_NODES = 1, +}; + /* The DOM stack is a convenient way to traverse DOM trees. Also it * maintains needed state info and is therefore also a holder of the current * context since the stack is used to when the DOM tree is manipulated. */ @@ -61,8 +66,7 @@ struct dom_stack { struct dom_stack_state *states; size_t depth; - /* Keep nodes when popping them or call done_dom_node() on them. */ - unsigned int keep_nodes:1; + enum dom_stack_flag flags; /* Callbacks which should be called for the pushed and popped nodes. */ struct dom_stack_context *contexts; @@ -121,7 +125,7 @@ search_dom_stack(struct dom_stack *stack, enum dom_node_type type, /* Life cycle functions. */ -void init_dom_stack(struct dom_stack *stack, int keep_nodes); +void init_dom_stack(struct dom_stack *stack, enum dom_stack_flag flags); void done_dom_stack(struct dom_stack *stack); /* Add a callback collection to the stack. */ diff --git a/src/document/sgml/parser.c b/src/document/sgml/parser.c index 3a321f700..1f65e076f 100644 --- a/src/document/sgml/parser.c +++ b/src/document/sgml/parser.c @@ -353,6 +353,7 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype, struct uri *uri) { struct sgml_parser *parser; + enum dom_stack_flag flags = 0; parser = mem_calloc(1, sizeof(*parser)); if (!parser) return NULL; @@ -361,7 +362,10 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype, parser->uri = get_uri_reference(uri); parser->info = get_sgml_info(doctype); - init_dom_stack(&parser->stack, type != SGML_PARSER_STREAM); + if (type == SGML_PARSER_TREE) + flags |= DOM_STACK_KEEP_NODES; + + init_dom_stack(&parser->stack, flags); /* FIXME: Some sgml backend specific callbacks? Handle HTML script tags, * and feed document.write() data back to the parser. */ add_dom_stack_context(&parser->stack, parser, &sgml_parser_context_info);