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

Debian bug 534835: Don't assert ecmascript_reset_state succeeds

After the recent ecmascript_get_interpreter change, I got an assertion
failure in render_document, which calls ecmascript_reset_state and
then asserts that it has set vs->ecmascript != NULL.
ecmascript_reset_state cannot guarantee that because there might not
even be enough free memory for mem_calloc(1, sizeof(struct
ecmascript_interpreter).  So, replace the assertion in render_document
with error handling, and likewise in call_onsubmit_and_submit.
This commit is contained in:
Kalle Olavi Niemitalo 2009-06-28 11:17:06 +03:00 committed by Kalle Olavi Niemitalo
parent 11c0cb859b
commit e452420d5f
2 changed files with 25 additions and 11 deletions

View File

@ -392,17 +392,23 @@ render_document(struct view_state *vs, struct document_view *doc_view,
&& vs->ecmascript->onload_snippets_cache_id
&& document->cache_id != vs->ecmascript->onload_snippets_cache_id))
ecmascript_reset_state(vs);
assert(vs->ecmascript);
vs->ecmascript->onload_snippets_cache_id = document->cache_id;
/* If ecmascript_reset_state cannot construct a new
* ECMAScript interpreter, it sets vs->ecmascript =
* NULL and vs->ecmascript_fragile = 1. */
if (vs->ecmascript) {
vs->ecmascript->onload_snippets_cache_id = document->cache_id;
/* Passing of the onload_snippets pointers gives *_snippets()
* some feeling of universality, shall we ever get any other
* snippets (?). */
add_snippets(vs->ecmascript,
&document->onload_snippets,
&vs->ecmascript->onload_snippets);
process_snippets(vs->ecmascript, &vs->ecmascript->onload_snippets,
&vs->ecmascript->current_onload_snippet);
/* Passing of the onload_snippets pointers
* gives *_snippets() some feeling of
* universality, shall we ever get any other
* snippets (?). */
add_snippets(vs->ecmascript,
&document->onload_snippets,
&vs->ecmascript->onload_snippets);
process_snippets(vs->ecmascript,
&vs->ecmascript->onload_snippets,
&vs->ecmascript->current_onload_snippet);
}
}
#endif

View File

@ -923,7 +923,15 @@ call_onsubmit_and_submit(struct session *ses, struct document_view *doc_view,
if (vs->ecmascript_fragile)
ecmascript_reset_state(vs);
interpreter = vs->ecmascript;
assert(interpreter);
/* If there is an onsubmit script and we want
* to run it, but the ECMAScript interpreter
* cannot be initialized, then don't submit. */
if (!interpreter) {
done_string(&code);
/* See the comment below for the
* return value. */
return 1;
}
add_to_string(&code, fc->form->onsubmit);
res = ecmascript_eval_boolback(interpreter, &code);