1
0
Fork 0

[ecmascript] Treat document.write in <head> as new document.

This commit is contained in:
Witold Filipczyk 2022-11-23 16:15:42 +01:00
parent 3c8e625956
commit af190c57cc
1 changed files with 16 additions and 0 deletions

View File

@ -50,6 +50,7 @@
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
#include <algorithm>
#include <map>
std::map<struct timer *, bool> map_timer;
@ -359,6 +360,15 @@ delayed_reload(void *data)
mem_free(rel);
}
static bool
iequals(const std::string& a, const std::string& b)
{
return std::equal(a.begin(), a.end(),
b.begin(), b.end(), [](char a, char b) {
return toupper(a) == toupper(b);
});
}
void
check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text)
{
@ -381,6 +391,11 @@ check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text)
if (element != (*mapa).end()) {
xmlpp::Element *el = element->second;
const xmlpp::Element *parent = el->get_parent();
if (!parent || iequals(parent->get_name(), "HEAD")) goto fromstart;
xmlpp::ustring text = "<root>";
text += interpreter->writecode.source;
text += "</root>";
@ -404,6 +419,7 @@ check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text)
}
} else {
if (interpreter->writecode.length) {
fromstart:
add_fragment(cached, 0, interpreter->writecode.source, interpreter->writecode.length);
document->ecmascript_counter++;
}