mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] Check for NULL in init_string
This commit is contained in:
parent
87f18b53a0
commit
0477e45e05
@ -590,8 +590,13 @@ ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, i
|
||||
{
|
||||
assert(interpreter && interpreter->vs->doc_view->document);
|
||||
if (!code) return nullptr;
|
||||
done_string(&interpreter->code);
|
||||
init_string(&interpreter->code);
|
||||
if (interpreter->code.source) {
|
||||
done_string(&interpreter->code);
|
||||
}
|
||||
if (!init_string(&interpreter->code)) {
|
||||
mem_free(code);
|
||||
return nullptr;
|
||||
}
|
||||
add_to_string(&interpreter->code, code);
|
||||
mem_free(code);
|
||||
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
|
||||
@ -607,8 +612,13 @@ timer_id_T
|
||||
ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout)
|
||||
{
|
||||
assert(interpreter && interpreter->vs->doc_view->document);
|
||||
done_string(&interpreter->code);
|
||||
init_string(&interpreter->code);
|
||||
if (interpreter->code.source) {
|
||||
done_string(&interpreter->code);
|
||||
}
|
||||
|
||||
if (!init_string(&interpreter->code)) {
|
||||
return TIMER_ID_UNDEF;
|
||||
}
|
||||
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
|
||||
kill_timer(&interpreter->vs->doc_view->document->timeout);
|
||||
}
|
||||
@ -625,8 +635,12 @@ timer_id_T
|
||||
ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValueConst fun, int timeout)
|
||||
{
|
||||
assert(interpreter && interpreter->vs->doc_view->document);
|
||||
done_string(&interpreter->code);
|
||||
init_string(&interpreter->code);
|
||||
if (interpreter->code.source) {
|
||||
done_string(&interpreter->code);
|
||||
}
|
||||
if (!init_string(&interpreter->code)) {
|
||||
return TIMER_ID_UNDEF;
|
||||
}
|
||||
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
|
||||
kill_timer(&interpreter->vs->doc_view->document->timeout);
|
||||
}
|
||||
@ -694,7 +708,9 @@ document_parse(struct document *document)
|
||||
}
|
||||
|
||||
struct string str;
|
||||
init_string(&str);
|
||||
if (!init_string(&str)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
add_bytes_to_string(&str, f->data, f->length);
|
||||
|
||||
|
@ -1379,7 +1379,9 @@ document_write_do(JSContext *ctx, unsigned int argc, JS::Value *rval, int newlin
|
||||
|
||||
struct string code;
|
||||
|
||||
init_string(&code);
|
||||
if (!init_string(&code)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (argc >= 1)
|
||||
{
|
||||
@ -1477,8 +1479,13 @@ document_replace(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
struct string needle;
|
||||
struct string heystack;
|
||||
|
||||
init_string(&needle);
|
||||
init_string(&heystack);
|
||||
if (!init_string(&needle)) {
|
||||
return false;
|
||||
}
|
||||
if (!init_string(&heystack)) {
|
||||
done_string(&needle);
|
||||
return false;
|
||||
}
|
||||
|
||||
jshandle_value_to_char_string(&needle, ctx, args[0]);
|
||||
jshandle_value_to_char_string(&heystack, ctx, args[1]);
|
||||
@ -1496,23 +1503,27 @@ document_replace(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
fd_len=f->length;
|
||||
|
||||
struct string f_data;
|
||||
init_string(&f_data);
|
||||
add_to_string(&f_data,f->data);
|
||||
if (init_string(&f_data)) {
|
||||
add_to_string(&f_data,f->data);
|
||||
|
||||
struct string nu_str;
|
||||
init_string(&nu_str);
|
||||
string_replace(&nu_str,&f_data,&needle,&heystack);
|
||||
nu_len=nu_str.length;
|
||||
delete_entry_content(cached);
|
||||
/* This is very ugly, indeed. And Yes fd_len isn't
|
||||
* logically correct. But using nu_len will cause
|
||||
* the document to render improperly.
|
||||
* TBD: somehow better rerender the document
|
||||
* now it's places on the session level in doc_loading_callback */
|
||||
int ret = add_fragment(cached,0,nu_str.source,fd_len);
|
||||
normalize_cache_entry(cached,nu_len);
|
||||
document->ecmascript_counter++;
|
||||
//DBG("doc replace %s %s\n", needle.source, heystack.source);
|
||||
struct string nu_str;
|
||||
if (init_string(&nu_str)) {
|
||||
string_replace(&nu_str,&f_data,&needle,&heystack);
|
||||
nu_len=nu_str.length;
|
||||
delete_entry_content(cached);
|
||||
/* This is very ugly, indeed. And Yes fd_len isn't
|
||||
* logically correct. But using nu_len will cause
|
||||
* the document to render improperly.
|
||||
* TBD: somehow better rerender the document
|
||||
* now it's places on the session level in doc_loading_callback */
|
||||
int ret = add_fragment(cached,0,nu_str.source,fd_len);
|
||||
normalize_cache_entry(cached,nu_len);
|
||||
document->ecmascript_counter++;
|
||||
done_string(&nu_str);
|
||||
}
|
||||
//DBG("doc replace %s %s\n", needle.source, heystack.source);
|
||||
done_string(&f_data);
|
||||
}
|
||||
}
|
||||
|
||||
done_string(&needle);
|
||||
@ -1554,7 +1565,9 @@ document_createComment(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string idstr;
|
||||
init_string(&idstr);
|
||||
if (!init_string(&idstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&idstr, ctx, args[0]);
|
||||
xmlpp::ustring text = idstr.source;
|
||||
done_string(&idstr);
|
||||
@ -1648,7 +1661,9 @@ document_createElement(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string idstr;
|
||||
init_string(&idstr);
|
||||
if (!init_string(&idstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&idstr, ctx, args[0]);
|
||||
xmlpp::ustring text = idstr.source;
|
||||
done_string(&idstr);
|
||||
@ -1697,7 +1712,9 @@ document_createTextNode(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string idstr;
|
||||
init_string(&idstr);
|
||||
if (!init_string(&idstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&idstr, ctx, args[0]);
|
||||
xmlpp::ustring text = idstr.source;
|
||||
done_string(&idstr);
|
||||
@ -1747,7 +1764,9 @@ document_getElementById(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
|
||||
struct string idstr;
|
||||
|
||||
init_string(&idstr);
|
||||
if (!init_string(&idstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&idstr, ctx, args[0]);
|
||||
xmlpp::ustring id = idstr.source;
|
||||
|
||||
@ -1809,7 +1828,9 @@ document_getElementsByClassName(JSContext *ctx, unsigned int argc, JS::Value *vp
|
||||
|
||||
struct string idstr;
|
||||
|
||||
init_string(&idstr);
|
||||
if (!init_string(&idstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&idstr, ctx, args[0]);
|
||||
xmlpp::ustring id = idstr.source;
|
||||
|
||||
@ -1866,7 +1887,9 @@ document_getElementsByName(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
|
||||
struct string idstr;
|
||||
|
||||
init_string(&idstr);
|
||||
if (!init_string(&idstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&idstr, ctx, args[0]);
|
||||
xmlpp::ustring id = idstr.source;
|
||||
|
||||
@ -1924,7 +1947,9 @@ document_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
|
||||
struct string idstr;
|
||||
|
||||
init_string(&idstr);
|
||||
if (!init_string(&idstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&idstr, ctx, args[0]);
|
||||
xmlpp::ustring id = idstr.source;
|
||||
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
|
||||
@ -1981,7 +2006,9 @@ document_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
|
||||
struct string cssstr;
|
||||
|
||||
init_string(&cssstr);
|
||||
if (!init_string(&cssstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&cssstr, ctx, args[0]);
|
||||
xmlpp::ustring css = cssstr.source;
|
||||
|
||||
@ -2048,7 +2075,9 @@ document_querySelectorAll(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
|
||||
struct string cssstr;
|
||||
|
||||
init_string(&cssstr);
|
||||
if (!init_string(&cssstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&cssstr, ctx, args[0]);
|
||||
xmlpp::ustring css = cssstr.source;
|
||||
|
||||
|
@ -1730,7 +1730,9 @@ element_get_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
struct string buf;
|
||||
init_string(&buf);
|
||||
if (!init_string(&buf)) {
|
||||
return false;
|
||||
}
|
||||
walk_tree(&buf, el);
|
||||
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, buf.source));
|
||||
@ -1785,7 +1787,9 @@ element_get_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
struct string buf;
|
||||
init_string(&buf);
|
||||
if (!init_string(&buf)) {
|
||||
return false;
|
||||
}
|
||||
walk_tree(&buf, el, false);
|
||||
|
||||
args.rval().setString(JS_NewStringCopyZ(ctx, buf.source));
|
||||
@ -1840,7 +1844,9 @@ element_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *v
|
||||
}
|
||||
|
||||
struct string buf;
|
||||
init_string(&buf);
|
||||
if (!init_string(&buf)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
walk_tree_content(&buf, el);
|
||||
|
||||
@ -2538,7 +2544,9 @@ element_closest(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string cssstr;
|
||||
init_string(&cssstr);
|
||||
if (!init_string(&cssstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&cssstr, ctx, args[0]);
|
||||
xmlpp::ustring css = cssstr.source;
|
||||
xmlpp::ustring xpath = css2xpath(css);
|
||||
@ -2929,8 +2937,13 @@ element_isEqualNode(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
struct string first;
|
||||
struct string second;
|
||||
|
||||
init_string(&first);
|
||||
init_string(&second);
|
||||
if (!init_string(&first)) {
|
||||
return false;
|
||||
}
|
||||
if (!init_string(&second)) {
|
||||
done_string(&first);
|
||||
return false;
|
||||
}
|
||||
|
||||
walk_tree(&first, el, false, true);
|
||||
walk_tree(&second, el2, false, true);
|
||||
@ -3014,7 +3027,9 @@ element_matches(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string cssstr;
|
||||
init_string(&cssstr);
|
||||
if (!init_string(&cssstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&cssstr, ctx, args[0]);
|
||||
xmlpp::ustring css = cssstr.source;
|
||||
xmlpp::ustring xpath = css2xpath(css);
|
||||
@ -3069,7 +3084,9 @@ element_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string cssstr;
|
||||
init_string(&cssstr);
|
||||
if (!init_string(&cssstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&cssstr, ctx, args[0]);
|
||||
xmlpp::ustring css = cssstr.source;
|
||||
xmlpp::ustring xpath = css2xpath(css);
|
||||
@ -3131,7 +3148,9 @@ element_querySelectorAll(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
|
||||
struct string cssstr;
|
||||
|
||||
init_string(&cssstr);
|
||||
if (!init_string(&cssstr)) {
|
||||
return false;
|
||||
}
|
||||
jshandle_value_to_char_string(&cssstr, ctx, args[0]);
|
||||
xmlpp::ustring css = cssstr.source;
|
||||
xmlpp::ustring xpath = css2xpath(css);
|
||||
|
@ -246,8 +246,13 @@ localstorage_setitem(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
struct string key;
|
||||
struct string val;
|
||||
|
||||
init_string(&key);
|
||||
init_string(&val);
|
||||
if (!init_string(&key)) {
|
||||
return false;
|
||||
}
|
||||
if (!init_string(&val)) {
|
||||
done_string(&key);
|
||||
return false;
|
||||
}
|
||||
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
|
@ -152,7 +152,9 @@ location_get_property_hash(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string fragment;
|
||||
init_string(&fragment);
|
||||
if (!init_string(&fragment)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vs->uri->fragmentlen) {
|
||||
add_bytes_to_string(&fragment, vs->uri->fragment, vs->uri->fragmentlen);
|
||||
@ -420,7 +422,9 @@ location_get_property_pathname(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string pathname;
|
||||
init_string(&pathname);
|
||||
if (!init_string(&pathname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *query = memchr(vs->uri->data, '?', vs->uri->datalen);
|
||||
int len = (query ? query - vs->uri->data : vs->uri->datalen);
|
||||
@ -469,7 +473,9 @@ location_get_property_port(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string port;
|
||||
init_string(&port);
|
||||
if (!init_string(&port)) {
|
||||
return false;
|
||||
}
|
||||
if (vs->uri->portlen) {
|
||||
add_bytes_to_string(&port, vs->uri->port, vs->uri->portlen);
|
||||
}
|
||||
@ -519,7 +525,9 @@ location_get_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string proto;
|
||||
init_string(&proto);
|
||||
if (!init_string(&proto)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Custom or unknown keep the URI untouched. */
|
||||
if (vs->uri->protocol == PROTOCOL_UNKNOWN) {
|
||||
@ -575,7 +583,9 @@ location_get_property_search(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
|
||||
struct string search;
|
||||
init_string(&search);
|
||||
if (!init_string(&search)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *query = memchr(vs->uri->data, '?', vs->uri->datalen);
|
||||
|
||||
|
@ -43,7 +43,9 @@ jsval_to_boolean(JSContext *ctx, JS::Value *vp)
|
||||
void
|
||||
jshandle_value_to_char_string(struct string *string, JSContext *ctx, JS::HandleValue obj)
|
||||
{
|
||||
init_string(string);
|
||||
if (!init_string(string)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj.isString())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user