mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[quickjs] Check return value of init_string
This commit is contained in:
parent
0477e45e05
commit
d60bdd0fad
@ -902,7 +902,9 @@ js_document_write_do(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon
|
||||
struct string *ret = interpreter->ret;
|
||||
struct string code;
|
||||
|
||||
init_string(&code);
|
||||
if (!init_string(&code)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
if (argc >= 1)
|
||||
{
|
||||
@ -1004,8 +1006,13 @@ js_document_replace(JSContext *ctx, JSValueConst this_val, int argc, JSValueCons
|
||||
struct string needle;
|
||||
struct string heystack;
|
||||
|
||||
init_string(&needle);
|
||||
init_string(&heystack);
|
||||
if (!init_string(&needle)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
if (!init_string(&heystack)) {
|
||||
done_string(&needle);
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
const char *str;
|
||||
size_t len;
|
||||
@ -1036,23 +1043,27 @@ js_document_replace(JSContext *ctx, JSValueConst this_val, int argc, JSValueCons
|
||||
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);
|
||||
|
@ -734,7 +734,9 @@ js_element_get_property_innerHtml(JSContext *ctx, JSValueConst this_val)
|
||||
return JS_NULL;
|
||||
}
|
||||
struct string buf;
|
||||
init_string(&buf);
|
||||
if (!init_string(&buf)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
walk_tree(&buf, el);
|
||||
JSValue ret = JS_NewStringLen(ctx, buf.source, buf.length);
|
||||
done_string(&buf);
|
||||
@ -754,7 +756,9 @@ js_element_get_property_outerHtml(JSContext *ctx, JSValueConst this_val)
|
||||
return JS_NULL;
|
||||
}
|
||||
struct string buf;
|
||||
init_string(&buf);
|
||||
if (!init_string(&buf)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
walk_tree(&buf, el, false);
|
||||
JSValue ret = JS_NewStringLen(ctx, buf.source, buf.length);
|
||||
done_string(&buf);
|
||||
@ -774,7 +778,9 @@ js_element_get_property_textContent(JSContext *ctx, JSValueConst this_val)
|
||||
return JS_NULL;
|
||||
}
|
||||
struct string buf;
|
||||
init_string(&buf);
|
||||
if (!init_string(&buf)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
walk_tree_content(&buf, el);
|
||||
JSValue ret = JS_NewStringLen(ctx, buf.source, buf.length);
|
||||
done_string(&buf);
|
||||
@ -1422,8 +1428,13 @@ js_element_isEqualNode(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
|
||||
struct string first;
|
||||
struct string second;
|
||||
|
||||
init_string(&first);
|
||||
init_string(&second);
|
||||
if (!init_string(&first)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
if (!init_string(&second)) {
|
||||
done_string(&first);
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
walk_tree(&first, el, false, true);
|
||||
walk_tree(&second, el2, false, true);
|
||||
|
@ -64,7 +64,9 @@ js_location_get_property_hash(JSContext *ctx, JSValueConst this_val)
|
||||
}
|
||||
|
||||
struct string fragment;
|
||||
init_string(&fragment);
|
||||
if (!init_string(&fragment)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
if (vs->uri->fragmentlen) {
|
||||
add_bytes_to_string(&fragment, vs->uri->fragment, vs->uri->fragmentlen);
|
||||
@ -217,7 +219,9 @@ js_location_get_property_pathname(JSContext *ctx, JSValueConst this_val)
|
||||
}
|
||||
|
||||
struct string pathname;
|
||||
init_string(&pathname);
|
||||
if (!init_string(&pathname)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
const char *query = memchr(vs->uri->data, '?', vs->uri->datalen);
|
||||
int len = (query ? query - vs->uri->data : vs->uri->datalen);
|
||||
@ -247,7 +251,9 @@ js_location_get_property_port(JSContext *ctx, JSValueConst this_val)
|
||||
}
|
||||
|
||||
struct string port;
|
||||
init_string(&port);
|
||||
if (!init_string(&port)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
if (vs->uri->portlen) {
|
||||
add_bytes_to_string(&port, vs->uri->port, vs->uri->portlen);
|
||||
}
|
||||
@ -275,7 +281,9 @@ js_location_get_property_protocol(JSContext *ctx, JSValueConst this_val)
|
||||
}
|
||||
|
||||
struct string proto;
|
||||
init_string(&proto);
|
||||
if (!init_string(&proto)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
/* Custom or unknown keep the URI untouched. */
|
||||
if (vs->uri->protocol == PROTOCOL_UNKNOWN) {
|
||||
@ -308,7 +316,9 @@ js_location_get_property_search(JSContext *ctx, JSValueConst this_val)
|
||||
}
|
||||
|
||||
struct string search;
|
||||
init_string(&search);
|
||||
if (!init_string(&search)) {
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
const char *query = memchr(vs->uri->data, '?', vs->uri->datalen);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user