diff --git a/src/ecmascript/spidermonkey.c b/src/ecmascript/spidermonkey.c index 01a66aed..ce25a93e 100644 --- a/src/ecmascript/spidermonkey.c +++ b/src/ecmascript/spidermonkey.c @@ -539,7 +539,7 @@ spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter, /* Undefined value. */ result = NULL; } else { - result = stracpy(jsval_to_string(ctx, r_rval)); + result = jsval_to_string(ctx, r_rval); } JS::LeaveRealm(ctx, comp); diff --git a/src/ecmascript/spidermonkey/console.c b/src/ecmascript/spidermonkey/console.c index 060ddd62..6b922355 100644 --- a/src/ecmascript/spidermonkey/console.c +++ b/src/ecmascript/spidermonkey/console.c @@ -106,6 +106,7 @@ console_log(JSContext *ctx, unsigned int argc, JS::Value *vp) fprintf(f, "%s\n", key); fclose(f); } + mem_free_if(key); } args.rval().setBoolean(true); diff --git a/src/ecmascript/spidermonkey/document.c b/src/ecmascript/spidermonkey/document.c index 8e9865dc..ad34c39c 100644 --- a/src/ecmascript/spidermonkey/document.c +++ b/src/ecmascript/spidermonkey/document.c @@ -292,7 +292,9 @@ document_set_property_cookie(JSContext *ctx, unsigned int argc, JS::Value *vp) if (!vs) { return false; } - set_cookie(vs->uri, jsval_to_string(ctx, args[0])); + char *text = jsval_to_string(ctx, args[0]); + set_cookie(vs->uri, text); + mem_free_if(text); return true; } @@ -751,7 +753,12 @@ document_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp) return false; } doc_view = vs->doc_view; - location_goto(doc_view, jsval_to_string(ctx, args[0])); + char *url = jsval_to_string(ctx, args[0]); + + if (url) { + location_goto(doc_view, url); + mem_free(url); + } return true; } @@ -936,7 +943,7 @@ document_set_property_title(JSContext *ctx, int argc, JS::Value *vp) } doc_view = vs->doc_view; document = doc_view->document; - mem_free_set(&document->title, stracpy(jsval_to_string(ctx, args[0]))); + mem_free_set(&document->title, jsval_to_string(ctx, args[0])); print_screen_status(doc_view->session); return true; @@ -1006,7 +1013,11 @@ document_set_property_url(JSContext *ctx, unsigned int argc, JS::Value *vp) return false; } doc_view = vs->doc_view; - location_goto(doc_view, jsval_to_string(ctx, args[0])); + char *url = jsval_to_string(ctx, args[0]); + if (url) { + location_goto(doc_view, url); + mem_free(url); + } return true; } diff --git a/src/ecmascript/spidermonkey/element.c b/src/ecmascript/spidermonkey/element.c index 81e00e13..e9f7494b 100644 --- a/src/ecmascript/spidermonkey/element.c +++ b/src/ecmascript/spidermonkey/element.c @@ -1601,10 +1601,12 @@ element_set_property_className(JSContext *ctx, unsigned int argc, JS::Value *vp) if (!el) { return true; } + char *val = jsval_to_string(ctx, args[0]); - std::string value = jsval_to_string(ctx, args[0]); + std::string value = val; el->set_attribute("class", value); interpreter->changed = true; + mem_free_if(val); return true; } @@ -1642,12 +1644,14 @@ element_set_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } - std::string value = jsval_to_string(ctx, args[0]); + char *val = jsval_to_string(ctx, args[0]); + std::string value = val; if (value == "ltr" || value == "rtl" || value == "auto") { el->set_attribute("dir", value); interpreter->changed = true; } + mem_free_if(val); return true; } @@ -1686,10 +1690,13 @@ element_set_property_id(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } - std::string value = jsval_to_string(ctx, args[0]); + char *val = jsval_to_string(ctx, args[0]); + std::string value = val; el->set_attribute("id", value); interpreter->changed = true; + mem_free_if(val); + return true; } @@ -1734,8 +1741,10 @@ element_set_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp) } std::string text = ""; - text += jsval_to_string(ctx, args[0]); + char *vv = jsval_to_string(ctx, args[0]); + text += vv; text += ""; + mem_free_if(vv); xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, NULL, HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); // Encapsulate raw libxml document in a libxml++ wrapper @@ -1798,6 +1807,7 @@ element_set_property_innerText(JSContext *ctx, unsigned int argc, JS::Value *vp) char *text = jsval_to_string(ctx, args[0]); el->add_child_text(text); interpreter->changed = true; + mem_free_if(text); return true; } @@ -1835,10 +1845,13 @@ element_set_property_lang(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } - std::string value = jsval_to_string(ctx, args[0]); + char *val = jsval_to_string(ctx, args[0]); + std::string value = val; el->set_attribute("lang", value); interpreter->changed = true; + mem_free_if(val); + return true; } @@ -1938,10 +1951,13 @@ element_set_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } - std::string value = jsval_to_string(ctx, args[0]); + char *val = jsval_to_string(ctx, args[0]); + std::string value = val; el->set_attribute("title", value); interpreter->changed = true; + mem_free_if(val); + return true; } @@ -2113,11 +2129,14 @@ element_getAttributeNode(JSContext *ctx, unsigned int argc, JS::Value *rval) args.rval().setUndefined(); return true; } - std::string v = jsval_to_string(ctx, args[0]); + char *vv = jsval_to_string(ctx, args[0]); + std::string v = vv; xmlpp::Attribute *attr = el->get_attribute(v); JSObject *obj = getAttr(ctx, attr); args.rval().setObject(*obj); + mem_free_if(vv); + return true; } @@ -2148,10 +2167,13 @@ element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval) args.rval().setBoolean(false); return true; } - std::string v = jsval_to_string(ctx, args[0]); + char *vv = jsval_to_string(ctx, args[0]); + std::string v = vv; xmlpp::Attribute *attr = el->get_attribute(v); args.rval().setBoolean((bool)attr); + mem_free_if(vv); + return true; } @@ -2406,10 +2428,14 @@ element_setAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval) } if (args[0].isString() && args[1].isString()) { - std::string attr = jsval_to_string(ctx, args[0]); - std::string value = jsval_to_string(ctx, args[1]); + char *attr_c = jsval_to_string(ctx, args[0]); + std::string attr = attr_c; + char *value_c = jsval_to_string(ctx, args[1]); + std::string value = value_c; el->set_attribute(attr, value); interpreter->changed = true; + mem_free_if(attr_c); + mem_free_if(value_c); } return true; @@ -2548,6 +2574,8 @@ htmlCollection_namedItem(JSContext *ctx, unsigned int argc, JS::Value *vp) bool ret = htmlCollection_namedItem2(ctx, hobj, str, &rval); args.rval().set(rval); + mem_free_if(str); + return ret; } @@ -2674,10 +2702,15 @@ htmlCollection_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId JS_IdToValue(ctx, id, &r_idval); char *string = jsval_to_string(ctx, r_idval); - std::string test = string; + if (string) { + std::string test = string; - if (test != "item" && test != "namedItem") { - return htmlCollection_namedItem2(ctx, hobj, string, hvp); + if (test != "item" && test != "namedItem") { + bool ret = htmlCollection_namedItem2(ctx, hobj, string, hvp); + mem_free(string); + return ret; + } + mem_free(string); } } @@ -3016,6 +3049,8 @@ attributes_getNamedItem(JSContext *ctx, unsigned int argc, JS::Value *vp) bool ret = attributes_namedItem2(ctx, hobj, str, &rval); args.rval().set(rval); + mem_free_if(str); + return ret; } diff --git a/src/ecmascript/spidermonkey/form.c b/src/ecmascript/spidermonkey/form.c index e09fbc68..862c44f2 100644 --- a/src/ecmascript/spidermonkey/form.c +++ b/src/ecmascript/spidermonkey/form.c @@ -366,7 +366,7 @@ input_set_property_alt(JSContext *ctx, unsigned int argc, JS::Value *vp) assert(fc); assert(fc->form && fs); - mem_free_set(&fc->alt, stracpy(jsval_to_string(ctx, args[0]))); + mem_free_set(&fc->alt, jsval_to_string(ctx, args[0])); return true; } @@ -780,7 +780,7 @@ input_set_property_name(JSContext *ctx, unsigned int argc, JS::Value *vp) assert(fc); assert(fc->form && fs); - mem_free_set(&fc->name, stracpy(jsval_to_string(ctx, args[0]))); + mem_free_set(&fc->name, jsval_to_string(ctx, args[0])); return true; } @@ -1136,7 +1136,7 @@ input_set_property_src(JSContext *ctx, unsigned int argc, JS::Value *vp) if (linknum >= 0) link = &document->links[linknum]; if (link) { - mem_free_set(&link->where_img, stracpy(jsval_to_string(ctx, args[0]))); + mem_free_set(&link->where_img, jsval_to_string(ctx, args[0])); } return true; @@ -1326,7 +1326,7 @@ input_set_property_value(JSContext *ctx, unsigned int argc, JS::Value *vp) assert(fc->form && fs); if (fc->type != FC_FILE) { - mem_free_set(&fs->value, stracpy(jsval_to_string(ctx, args[0]))); + mem_free_set(&fs->value, jsval_to_string(ctx, args[0])); if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) fs->state = strlen(fs->value); } @@ -1812,12 +1812,16 @@ form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h JS_IdToValue(ctx, id, &r_idval); char *string = jsval_to_string(ctx, r_idval); - std::string test = string; - if (test == "item" || test == "namedItem") { - return true; - } + if (string) { + std::string test = string; + if (test == "item" || test == "namedItem") { + mem_free(string); + return true; + } - form_elements_namedItem2(ctx, hobj, string, hvp); + form_elements_namedItem2(ctx, hobj, string, hvp); + mem_free(string); + } return true; } @@ -1974,12 +1978,11 @@ form_elements_namedItem(JSContext *ctx, unsigned int argc, JS::Value *vp) JS::RootedObject hobj(ctx, &args.thisv().toObject()); JS::RootedValue rval(ctx, val); - -// JS::Value *argv = JS_ARGV(ctx, rval); char *string = jsval_to_string(ctx, args[0]); bool ret = form_elements_namedItem2(ctx, hobj, string, &rval); args.rval().set(rval); -// JS_SET_RVAL(ctx, rval, val); + mem_free_if(string); + return ret; } @@ -2247,7 +2250,7 @@ form_set_property_action(JSContext *ctx, unsigned int argc, JS::Value *vp) assert(form); - string = stracpy(jsval_to_string(ctx, args[0])); + string = jsval_to_string(ctx, args[0]); if (form->action) { ecmascript_set_action(&form->action, string); } else { @@ -2386,6 +2389,9 @@ form_set_property_encoding(JSContext *ctx, unsigned int argc, JS::Value *vp) assert(form); string = jsval_to_string(ctx, args[0]); + if (!string) { + return true; + } if (!c_strcasecmp(string, "application/x-www-form-urlencoded")) { form->method = form->method == FORM_METHOD_GET ? FORM_METHOD_GET : FORM_METHOD_POST; @@ -2394,6 +2400,7 @@ form_set_property_encoding(JSContext *ctx, unsigned int argc, JS::Value *vp) } else if (!c_strcasecmp(string, "text/plain")) { form->method = FORM_METHOD_POST_TEXT_PLAIN; } + mem_free(string); return true; } @@ -2535,11 +2542,15 @@ form_set_property_method(JSContext *ctx, unsigned int argc, JS::Value *vp) assert(form); string = jsval_to_string(ctx, args[0]); + if (!string) { + return true; + } if (!c_strcasecmp(string, "GET")) { form->method = FORM_METHOD_GET; } else if (!c_strcasecmp(string, "POST")) { form->method = FORM_METHOD_POST; } + mem_free(string); return true; } @@ -2625,7 +2636,7 @@ form_set_property_name(JSContext *ctx, unsigned int argc, JS::Value *vp) form = find_form_by_form_view(doc_view->document, fv); assert(form); - mem_free_set(&form->name, stracpy(jsval_to_string(ctx, args[0]))); + mem_free_set(&form->name, jsval_to_string(ctx, args[0])); return true; } @@ -2709,7 +2720,7 @@ form_set_property_target(JSContext *ctx, unsigned int argc, JS::Value *vp) form = find_form_by_form_view(doc_view->document, fv); assert(form); - mem_free_set(&form->target, stracpy(jsval_to_string(ctx, args[0]))); + mem_free_set(&form->target, jsval_to_string(ctx, args[0])); return true; } @@ -3144,6 +3155,8 @@ forms_namedItem(JSContext *ctx, unsigned int argc, JS::Value *vp) find_form_by_name(ctx, doc_view, string, &rval); args.rval().set(rval.get()); + mem_free_if(string); + return true; } diff --git a/src/ecmascript/spidermonkey/localstorage.c b/src/ecmascript/spidermonkey/localstorage.c index 1793d68f..ed0969b7 100644 --- a/src/ecmascript/spidermonkey/localstorage.c +++ b/src/ecmascript/spidermonkey/localstorage.c @@ -156,8 +156,6 @@ localstorage_getitem(JSContext *ctx, unsigned int argc, JS::Value *vp) struct ecmascript_interpreter *interpreter = JS::GetRealmPrivate(comp); JS::CallArgs args = CallArgsFromVp(argc, vp); - unsigned char *key = jsval_to_string(ctx, args[0]); - //DBG("localstorage get by key: %s\n", args); if (argc != 1) { @@ -165,18 +163,19 @@ localstorage_getitem(JSContext *ctx, unsigned int argc, JS::Value *vp) return(true); } - unsigned char *val; + unsigned char *key = jsval_to_string(ctx, args[0]); + if (key) { + unsigned char *val = readFromStorage(key); - val = readFromStorage(key); + //DBG("%s %s\n", key, val); - //DBG("%s %s\n", key, val); + args.rval().setString(JS_NewStringCopyZ(ctx, val)); - args.rval().setString(JS_NewStringCopyZ(ctx, val)); - - mem_free(val); - - return(true); + mem_free(val); + mem_free(key); + } + return true; } /* @localstorage_funcs{"setItem"} */ diff --git a/src/ecmascript/spidermonkey/location.c b/src/ecmascript/spidermonkey/location.c index aa9ede4b..baff61e9 100644 --- a/src/ecmascript/spidermonkey/location.c +++ b/src/ecmascript/spidermonkey/location.c @@ -743,7 +743,12 @@ location_set_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp) return false; } doc_view = vs->doc_view; - location_goto(doc_view, jsval_to_string(ctx, args[0])); + char *url = jsval_to_string(ctx, args[0]); + + if (url) { + location_goto(doc_view, url); + mem_free(url); + } return true; } diff --git a/src/ecmascript/spidermonkey/window.c b/src/ecmascript/spidermonkey/window.c index 51b85514..45ad639c 100644 --- a/src/ecmascript/spidermonkey/window.c +++ b/src/ecmascript/spidermonkey/window.c @@ -244,11 +244,11 @@ window_alert(JSContext *ctx, unsigned int argc, JS::Value *rval) string = jsval_to_string(ctx, args[0]); - if (!*string) + if (!string) return true; info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT, - N_("JavaScript Alert"), ALIGN_CENTER, stracpy(string)); + N_("JavaScript Alert"), ALIGN_CENTER, string); args.rval().setUndefined(); return true; @@ -308,7 +308,10 @@ window_open(JSContext *ctx, unsigned int argc, JS::Value *rval) } } - url = stracpy(jsval_to_string(ctx, args[0])); + url = jsval_to_string(ctx, args[0]); + if (!url) { + return true; + } trim_chars(url, ' ', 0); url2 = join_urls(doc_view->document->uri, url); mem_free(url); @@ -316,7 +319,7 @@ window_open(JSContext *ctx, unsigned int argc, JS::Value *rval) return true; } if (argc > 1) { - frame = stracpy(jsval_to_string(ctx, args[1])); + frame = jsval_to_string(ctx, args[1]); if (!frame) { mem_free(url2); return true; @@ -406,11 +409,6 @@ window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval) if (args[0].isString()) { code = jsval_to_string(ctx, args[0]); - if (!*code) { - return true; - } - code = stracpy(code); - if (!code) { return true; } @@ -530,7 +528,7 @@ window_set_property_status(JSContext *ctx, unsigned int argc, JS::Value *vp) return true; } - mem_free_set(&vs->doc_view->session->status.window_status, stracpy(jsval_to_string(ctx, args[0]))); + mem_free_set(&vs->doc_view->session->status.window_status, jsval_to_string(ctx, args[0])); print_screen_status(vs->doc_view->session); return true;