1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[js] document is already parsed. No need to check

This commit is contained in:
Witold Filipczyk 2023-09-23 18:58:21 +02:00
parent 1b9983c543
commit b3e77ef53e
7 changed files with 11 additions and 242 deletions

View File

@ -66,20 +66,14 @@ document_parse_text(const char *charset, char *data, size_t length)
}
void *
document_parse(struct document *document)
document_parse(struct document *document, struct string *source)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct cache_entry *cached = document->cached;
struct fragment *f = get_cache_fragment(cached);
const char *charset = document->cp >= 0 ? get_cp_mime_name(document->cp) : "";
if (!f || !f->length) {
return NULL;
}
return document_parse_text(charset, f->data, f->length);
return document_parse_text(charset, source->source, source->length);
}
void

View File

@ -9,7 +9,7 @@ struct document;
struct string;
void *document_parse_text(const char *charset, char *data, size_t length);
void *document_parse(struct document *document);
void *document_parse(struct document *document, struct string *source);
void free_document(void *doc);
#ifdef __cplusplus

View File

@ -244,7 +244,7 @@ render_source_document_cxx(struct cache_entry *cached, struct document *document
&document->cp_status,
document->options.hard_assume);
document->dom = document_parse(document);
document->dom = document_parse(document, buffer);
}
if (!document->dom) {

View File

@ -267,6 +267,7 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str
void *mapa = NULL;
void *mapa_rev = NULL;
static int initialised = 0;
int first = 0;
if (!initialised) {
corestrings_init();
@ -288,8 +289,8 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str
&document->cp,
&document->cp_status,
document->options.hard_assume);
memset(buffer, 0, sizeof(*buffer));
document->dom = document_parse(document);
document->dom = document_parse(document, buffer);
first = 1;
}
if (!document->dom) {
@ -311,7 +312,7 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str
return;
}
if (!buffer->length) {
if (first) {
struct string tt;
if (!init_string(&tt)) {
@ -340,8 +341,10 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str
//dom_node_unref(doc);
return;
}
*buffer = tt;
document->text = tt.source;
dom_node_unref(root);
render_html_document(cached, document, &tt);
return;
}
dom_node_unref(root);
render_html_document(cached, document, buffer);

View File

@ -74,10 +74,6 @@ mjs_document_get_property_anchors(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -135,10 +131,6 @@ mjs_document_get_property_body(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -242,10 +234,6 @@ mjs_document_get_property_charset(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -273,10 +261,6 @@ mjs_document_get_property_childNodes(js_State *J)
}
struct document *document = vs->doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -311,10 +295,6 @@ mjs_document_get_property_doctype(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushundefined(J);
return;
@ -336,10 +316,6 @@ mjs_document_get_property_documentElement(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -425,10 +401,6 @@ mjs_document_get_property_forms(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -454,10 +426,6 @@ mjs_document_get_property_head(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -490,10 +458,6 @@ mjs_document_get_property_images(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -519,10 +483,6 @@ mjs_document_get_property_implementation(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -540,10 +500,6 @@ mjs_document_get_property_links(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -645,10 +601,6 @@ mjs_document_get_property_scripts(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -984,10 +936,6 @@ mjs_document_createDocumentFragment(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -1088,10 +1036,6 @@ mjs_document_getElementById(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -1132,10 +1076,6 @@ mjs_document_getElementsByClassName(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -1177,10 +1117,6 @@ mjs_document_getElementsByName(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -1224,10 +1160,6 @@ mjs_document_getElementsByTagName(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -1268,10 +1200,6 @@ mjs_document_querySelector(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;
@ -1318,10 +1246,6 @@ mjs_document_querySelectorAll(js_State *J)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
js_pushnull(J);
return;

View File

@ -54,10 +54,6 @@ js_document_get_property_anchors(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -121,10 +117,6 @@ js_document_get_property_body(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -240,10 +232,6 @@ js_document_get_property_charset(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -275,10 +263,6 @@ js_document_get_property_childNodes(JSContext *ctx, JSValueConst this_val)
}
struct document *document = vs->doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -313,10 +297,6 @@ js_document_get_property_doctype(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -340,10 +320,6 @@ js_document_get_property_documentElement(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -436,10 +412,6 @@ js_document_get_property_forms(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -469,10 +441,6 @@ js_document_get_property_head(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -495,10 +463,6 @@ js_document_get_property_images(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -527,10 +491,6 @@ js_document_get_property_implementation(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -550,10 +510,6 @@ js_document_get_property_links(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -711,10 +667,6 @@ js_document_get_property_scripts(JSContext *ctx, JSValueConst this_val)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -1084,10 +1036,6 @@ js_document_createDocumentFragment(JSContext *ctx, JSValueConst this_val, int ar
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -1208,10 +1156,6 @@ js_document_getElementById(JSContext *ctx, JSValueConst this_val, int argc, JSVa
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -1258,10 +1202,6 @@ js_document_getElementsByClassName(JSContext *ctx, JSValueConst this_val, int ar
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -1315,10 +1255,6 @@ js_document_getElementsByName(JSContext *ctx, JSValueConst this_val, int argc, J
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -1372,10 +1308,6 @@ js_document_getElementsByTagName(JSContext *ctx, JSValueConst this_val, int argc
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -1424,10 +1356,6 @@ js_document_querySelector(JSContext *ctx, JSValueConst this_val, int argc, JSVal
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}
@ -1482,10 +1410,6 @@ js_document_querySelectorAll(JSContext *ctx, JSValueConst this_val, int argc, JS
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
return JS_NULL;
}

View File

@ -110,10 +110,6 @@ document_get_property_anchors(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -200,10 +196,6 @@ document_get_property_body(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -329,10 +321,6 @@ document_get_property_charset(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -384,10 +372,6 @@ document_get_property_childNodes(JSContext *ctx, unsigned int argc, JS::Value *v
struct document *document = vs->doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -429,10 +413,6 @@ document_get_property_doctype(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -461,10 +441,6 @@ document_get_property_documentElement(JSContext *ctx, unsigned int argc, JS::Val
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -601,10 +577,6 @@ document_get_property_forms(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -636,10 +608,6 @@ document_get_property_head(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -662,10 +630,6 @@ document_get_property_images(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -697,10 +661,6 @@ document_get_property_implementation(JSContext *ctx, unsigned int argc, JS::Valu
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -728,10 +688,6 @@ document_get_property_links(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -933,10 +889,6 @@ document_get_property_scripts(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -1395,10 +1347,6 @@ document_createDocumentFragment(JSContext *ctx, unsigned int argc, JS::Value *vp
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -1539,10 +1487,6 @@ document_getElementById(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -1599,10 +1543,6 @@ document_getElementsByClassName(JSContext *ctx, unsigned int argc, JS::Value *vp
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -1632,10 +1572,6 @@ document_getElementsByName(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -1665,10 +1601,6 @@ document_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -1724,10 +1656,6 @@ document_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
@ -1756,10 +1684,6 @@ document_querySelectorAll(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;