1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-28 01:35:32 +00:00

[spidermonkey] jsval_to_string everywhere

Replace JS_EncodeString by jsval_to_string. It will allow easier
changes in the future. In smjs nullptr everywhere.
In ecmascript arrays don't work. For example
document.getElementsByTagName("H1")[0]

smjs even does not start.

Plan is to bump mozjs version, and later back to fixing bugs.
This commit is contained in:
Witold Filipczyk 2021-08-27 19:46:05 +02:00
parent 630696da59
commit 47224921de
20 changed files with 193 additions and 180 deletions

View File

@ -538,7 +538,7 @@ spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
/* Undefined value. */
result = NULL;
} else {
result = stracpy(JS_EncodeString(ctx, r_rval.toString()));
result = stracpy(jsval_to_string(ctx, r_rval));
}
JS_LeaveCompartment(ctx, comp);
JS_EndRequest(ctx);

View File

@ -101,7 +101,7 @@ console_log(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (get_opt_bool("ecmascript.enable_console_log", NULL))
{
unsigned char *key = JS_EncodeString(ctx, args[0].toString());
unsigned char *key = jsval_to_string(ctx, args[0]);
FILE *f = fopen(console_log_filename, "a");

View File

@ -291,7 +291,7 @@ document_set_property_cookie(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!vs) {
return false;
}
set_cookie(vs->uri, JS_EncodeString(ctx, args[0].toString()));
set_cookie(vs->uri, jsval_to_string(ctx, args[0]));
return true;
}
@ -750,7 +750,7 @@ document_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}
@ -935,7 +935,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(JS_EncodeString(ctx, args[0].toString())));
mem_free_set(&document->title, stracpy(jsval_to_string(ctx, args[0])));
print_screen_status(doc_view->session);
return true;
@ -1005,7 +1005,7 @@ document_set_property_url(JSContext *ctx, int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}

View File

@ -1602,7 +1602,7 @@ element_set_property_className(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
std::string value = JS_EncodeString(ctx, args[0].toString());
std::string value = jsval_to_string(ctx, args[0]);
el->set_attribute("class", value);
interpreter->changed = true;
@ -1642,7 +1642,7 @@ element_set_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
std::string value = JS_EncodeString(ctx, args[0].toString());
std::string value = jsval_to_string(ctx, args[0]);
if (value == "ltr" || value == "rtl" || value == "auto") {
el->set_attribute("dir", value);
@ -1686,7 +1686,7 @@ element_set_property_id(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
std::string value = JS_EncodeString(ctx, args[0].toString());
std::string value = jsval_to_string(ctx, args[0]);
el->set_attribute("id", value);
interpreter->changed = true;
@ -1734,7 +1734,7 @@ element_set_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp)
}
std::string text = "<root>";
text += JS_EncodeString(ctx, args[0].toString());
text += jsval_to_string(ctx, args[0]);
text += "</root>";
xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, NULL, HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING);
@ -1795,7 +1795,7 @@ element_set_property_innerText(JSContext *ctx, unsigned int argc, JS::Value *vp)
xmlpp::Node::remove_node(*it);
}
char *text = JS_EncodeString(ctx, args[0].toString());
char *text = jsval_to_string(ctx, args[0]);
el->add_child_text(text);
interpreter->changed = true;
@ -1835,7 +1835,7 @@ element_set_property_lang(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
std::string value = JS_EncodeString(ctx, args[0].toString());
std::string value = jsval_to_string(ctx, args[0]);
el->set_attribute("lang", value);
interpreter->changed = true;
@ -1938,7 +1938,7 @@ element_set_property_title(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
std::string value = JS_EncodeString(ctx, args[0].toString());
std::string value = jsval_to_string(ctx, args[0]);
el->set_attribute("title", value);
interpreter->changed = true;
@ -2113,7 +2113,7 @@ element_getAttributeNode(JSContext *ctx, unsigned int argc, JS::Value *rval)
args.rval().setUndefined();
return true;
}
std::string v = JS_EncodeString(ctx, args[0].toString());
std::string v = jsval_to_string(ctx, args[0]);
xmlpp::Attribute *attr = el->get_attribute(v);
JSObject *obj = getAttr(ctx, attr);
args.rval().setObject(*obj);
@ -2148,7 +2148,7 @@ element_hasAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval)
args.rval().setBoolean(false);
return true;
}
std::string v = JS_EncodeString(ctx, args[0].toString());
std::string v = jsval_to_string(ctx, args[0]);
xmlpp::Attribute *attr = el->get_attribute(v);
args.rval().setBoolean((bool)attr);
@ -2406,8 +2406,8 @@ element_setAttribute(JSContext *ctx, unsigned int argc, JS::Value *rval)
}
if (args[0].isString() && args[1].isString()) {
std::string attr = JS_EncodeString(ctx, args[0].toString());
std::string value = JS_EncodeString(ctx, args[1].toString());
std::string attr = jsval_to_string(ctx, args[0]);
std::string value = jsval_to_string(ctx, args[1]);
el->set_attribute(attr, value);
interpreter->changed = true;
}
@ -2543,7 +2543,7 @@ htmlCollection_namedItem(JSContext *ctx, unsigned int argc, JS::Value *vp)
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedValue rval(ctx, val);
char *str = JS_EncodeString(ctx, args[0].toString());
char *str = jsval_to_string(ctx, args[0]);
rval.setNull();
bool ret = htmlCollection_namedItem2(ctx, hobj, str, &rval);
args.rval().set(rval);
@ -2672,7 +2672,7 @@ htmlCollection_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId
if (JSID_IS_STRING(id)) {
JS::RootedValue r_idval(ctx, idval);
JS_IdToValue(ctx, id, &r_idval);
char *string = JS_EncodeString(ctx, r_idval.toString());
char *string = jsval_to_string(ctx, r_idval);
std::string test = string;
@ -3012,7 +3012,7 @@ attributes_getNamedItem(JSContext *ctx, unsigned int argc, JS::Value *vp)
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JS::RootedValue rval(ctx, val);
char *str = JS_EncodeString(ctx, args[0].toString());
char *str = jsval_to_string(ctx, args[0]);
bool ret = attributes_namedItem2(ctx, hobj, str, &rval);
args.rval().set(rval);
@ -3143,7 +3143,7 @@ attributes_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid,
if (JSID_IS_STRING(id)) {
JS::RootedValue r_idval(ctx, idval);
JS_IdToValue(ctx, id, &r_idval);
char *string = JS_EncodeString(ctx, r_idval.toString());
char *string = jsval_to_string(ctx, r_idval);
return attributes_namedItem2(ctx, hobj, string, hvp);
}

View File

@ -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(JS_EncodeString(ctx, args[0].toString())));
mem_free_set(&fc->alt, stracpy(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(JS_EncodeString(ctx, args[0].toString())));
mem_free_set(&fc->name, stracpy(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(JS_EncodeString(ctx, args[0].toString())));
mem_free_set(&link->where_img, stracpy(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(JS_EncodeString(ctx, args[0].toString())));
mem_free_set(&fs->value, stracpy(jsval_to_string(ctx, args[0])));
if (fc->type == FC_TEXT || fc->type == FC_PASSWORD)
fs->state = strlen(fs->value);
}
@ -1809,7 +1809,7 @@ form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
if (JSID_IS_STRING(id)) {
JS::RootedValue r_idval(ctx, idval);
JS_IdToValue(ctx, id, &r_idval);
char *string = JS_EncodeString(ctx, r_idval.toString());
char *string = jsval_to_string(ctx, r_idval);
std::string test = string;
if (test == "item" || test == "namedItem") {
@ -1975,7 +1975,7 @@ form_elements_namedItem(JSContext *ctx, unsigned int argc, JS::Value *vp)
// JS::Value *argv = JS_ARGV(ctx, rval);
char *string = JS_EncodeString(ctx, args[0].toString());
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);
@ -2247,7 +2247,7 @@ form_set_property_action(JSContext *ctx, unsigned int argc, JS::Value *vp)
assert(form);
string = stracpy(JS_EncodeString(ctx, args[0].toString()));
string = stracpy(jsval_to_string(ctx, args[0]));
if (form->action) {
ecmascript_set_action(&form->action, string);
} else {
@ -2385,7 +2385,7 @@ form_set_property_encoding(JSContext *ctx, unsigned int argc, JS::Value *vp)
assert(form);
string = JS_EncodeString(ctx, args[0].toString());
string = jsval_to_string(ctx, args[0]);
if (!c_strcasecmp(string, "application/x-www-form-urlencoded")) {
form->method = form->method == FORM_METHOD_GET ? FORM_METHOD_GET
: FORM_METHOD_POST;
@ -2534,7 +2534,7 @@ form_set_property_method(JSContext *ctx, unsigned int argc, JS::Value *vp)
assert(form);
string = JS_EncodeString(ctx, args[0].toString());
string = jsval_to_string(ctx, args[0]);
if (!c_strcasecmp(string, "GET")) {
form->method = FORM_METHOD_GET;
} else if (!c_strcasecmp(string, "POST")) {
@ -2625,7 +2625,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(JS_EncodeString(ctx, args[0].toString())));
mem_free_set(&form->name, stracpy(jsval_to_string(ctx, args[0])));
return true;
}
@ -2709,7 +2709,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(JS_EncodeString(ctx, args[0].toString())));
mem_free_set(&form->target, stracpy(jsval_to_string(ctx, args[0])));
return true;
}
@ -3136,7 +3136,7 @@ forms_namedItem(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (argc != 1)
return true;
char *string = JS_EncodeString(ctx, args[0].toString());
char *string = jsval_to_string(ctx, args[0]);
JS::RootedValue rval(ctx, val);
rval.setNull();

View File

@ -160,7 +160,7 @@ localstorage_getitem(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(comp);
JS::CallArgs args = CallArgsFromVp(argc, vp);
unsigned char *key = JS_EncodeString(ctx, args[0].toString());
unsigned char *key = jsval_to_string(ctx, args[0]);
//DBG("localstorage get by key: %s\n", args);
if (argc != 1)

View File

@ -637,7 +637,7 @@ location_set_property_hash(JSContext *ctx, unsigned int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
// location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
// location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}
@ -673,7 +673,7 @@ location_set_property_host(JSContext *ctx, unsigned int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
// location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
// location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}
@ -708,7 +708,7 @@ location_set_property_hostname(JSContext *ctx, unsigned int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
// location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
// location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}
@ -743,7 +743,7 @@ location_set_property_href(JSContext *ctx, unsigned int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}
@ -778,7 +778,7 @@ location_set_property_pathname(JSContext *ctx, unsigned int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
// location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
// location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}
@ -813,7 +813,7 @@ location_set_property_port(JSContext *ctx, unsigned int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
// location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
// location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}
@ -848,7 +848,7 @@ location_set_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
// location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
// location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}
@ -883,7 +883,7 @@ location_set_property_search(JSContext *ctx, unsigned int argc, JS::Value *vp)
return false;
}
doc_view = vs->doc_view;
// location_goto(doc_view, JS_EncodeString(ctx, args[0].toString()));
// location_goto(doc_view, jsval_to_string(ctx, args[0]));
return true;
}

View File

@ -242,9 +242,7 @@ window_alert(JSContext *ctx, unsigned int argc, JS::Value *rval)
if (argc != 1)
return true;
JSString *str = JS::ToString(ctx, args[0]);
string = JS_EncodeString(ctx, str);
string = jsval_to_string(ctx, args[0]);
if (!*string)
return true;
@ -533,7 +531,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(JS_EncodeString(ctx, args[0].toString())));
mem_free_set(&vs->doc_view->session->status.window_status, stracpy(jsval_to_string(ctx, args[0])));
print_screen_status(vs->doc_view->session);
return true;

View File

@ -176,7 +176,7 @@ action_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
hvp.setNull();
JS_IdToValue(ctx, id, &rval);
action_str = JS_EncodeString(ctx, rval.toString());
action_str = jsval_to_string(ctx, rval);
if (!action_str) return true;
action_fn = smjs_get_action_fn_object(action_str);
@ -188,9 +188,17 @@ action_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
}
static JSClassOps action_ops = {
nullptr, nullptr,
action_get_property, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass action_class = {

View File

@ -33,9 +33,17 @@ static const JSClass bookmark_class = {
};
static JSClassOps bookmark_folder_ops = {
nullptr, nullptr,
bookmark_folder_get_property, nullptr,
nullptr, nullptr, nullptr, bookmark_finalize,
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass bookmark_folder_class = {
@ -137,16 +145,7 @@ bookmark_string_to_jsval(JSContext *ctx, const char *str, JS::Value *vp)
static bool
jsval_to_bookmark_string(JSContext *ctx, JS::HandleValue val, char **result)
{
char *str;
JSString *jsstr = val.toString();
if (jsstr == NULL) {
return false;
}
JS::RootedString r_jsstr(ctx, jsstr);
str = JS_EncodeStringToUTF8(ctx, r_jsstr);
char *str = jsval_to_string(ctx, val);
if (str == NULL) {
return false;

View File

@ -110,7 +110,6 @@ cache_entry_set_property_content(JSContext *ctx, unsigned int argc, JS::Value *v
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct cache_entry *cached;
JSString *jsstr;
char *str;
size_t len;
@ -133,9 +132,8 @@ cache_entry_set_property_content(JSContext *ctx, unsigned int argc, JS::Value *v
* eventually unlock the object. */
object_lock(cached);
jsstr = args[0].toString();
str = JS_EncodeString(smjs_ctx, jsstr);
len = JS_GetStringLength(jsstr);
str = jsval_to_string(smjs_ctx, args[0]);
len = strlen(str);
add_fragment(cached, 0, str, len);
normalize_cache_entry(cached, len);
@ -182,7 +180,6 @@ cache_entry_set_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp)
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct cache_entry *cached;
JSString *jsstr;
char *str;
/* This can be called if @obj if not itself an instance of the
@ -204,8 +201,7 @@ cache_entry_set_property_type(JSContext *ctx, unsigned int argc, JS::Value *vp)
* eventually unlock the object. */
object_lock(cached);
jsstr = args[0].toString();
str = JS_EncodeString(smjs_ctx, jsstr);
str = jsval_to_string(smjs_ctx, args[0]);
mem_free_set(&cached->content_type, stracpy(str));
object_unlock(cached);
@ -371,7 +367,6 @@ cache_entry_set_property_head(JSContext *ctx, unsigned int argc, JS::Value *vp)
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct cache_entry *cached;
JSString *jsstr;
char *str;
/* This can be called if @obj if not itself an instance of the
@ -393,8 +388,7 @@ cache_entry_set_property_head(JSContext *ctx, unsigned int argc, JS::Value *vp)
* eventually unlock the object. */
object_lock(cached);
jsstr = args[0].toString();
str = JS_EncodeString(smjs_ctx, jsstr);
str = jsval_to_string(smjs_ctx, args[0]);
mem_free_set(&cached->head, stracpy(str));
object_unlock(cached);

View File

@ -214,8 +214,7 @@ smjs_do_file_wrapper(JSContext *ctx, unsigned int argc, JS::Value *rval)
{
JS::CallArgs args = CallArgsFromVp(argc, rval);
JSString *jsstr = args[0].toString();
char *path = JS_EncodeString(smjs_ctx, jsstr);
char *path = jsval_to_string(smjs_ctx, args[0]);
if (smjs_do_file(path))
return true;

View File

@ -43,7 +43,7 @@ elinks_alert(JSContext *ctx, unsigned int argc, JS::Value *rval)
if (argc != 1)
return true;
string = JS_EncodeString(ctx, args[0].toString());
string = jsval_to_string(ctx, args[0]);
if (!*string)
return true;
@ -78,7 +78,7 @@ elinks_execute(JSContext *ctx, unsigned int argc, JS::Value *rval)
if (argc != 1)
return true;
string = JS_EncodeString(ctx, args[0].toString());
string = jsval_to_string(ctx, args[0]);
if (!*string)
return true;
@ -109,9 +109,17 @@ static bool elinks_get_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
static bool elinks_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp);
static const JSClassOps elinks_ops = {
nullptr, nullptr,
elinks_get_property, elinks_set_property,
nullptr, nullptr, nullptr, nullptr
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass elinks_class = {
@ -198,15 +206,11 @@ elinks_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
switch (JSID_TO_INT(id)) {
case ELINKS_LOCATION: {
JSString *jsstr;
char *url;
if (!smjs_ses) return false;
jsstr = hvp.toString();
if (!jsstr) return false;
url = JS_EncodeString(smjs_ctx, jsstr);
url = jsval_to_string(smjs_ctx, hvp);
if (!url) return false;
goto_url(smjs_ses, url);
@ -322,7 +326,6 @@ elinks_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
JS::CallArgs args = CallArgsFromVp(argc, vp);
JS::RootedObject hobj(ctx, &args.thisv().toObject());
JSString *jsstr;
char *url;
/* This can be called if @obj if not itself an instance of the
@ -333,10 +336,7 @@ elinks_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
if (!smjs_ses) return false;
jsstr = args[0].toString();
if (!jsstr) return false;
url = JS_EncodeString(smjs_ctx, jsstr);
url = jsval_to_string(smjs_ctx, args[0]);
if (!url) return false;
goto_url(smjs_ses, url);

View File

@ -18,10 +18,17 @@ static bool smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hob
static void smjs_globhist_item_finalize(JSFreeOp *op, JSObject *obj);
static const JSClassOps smjs_globhist_item_ops = {
nullptr, nullptr,
smjs_globhist_item_get_property, smjs_globhist_item_set_property,
nullptr, nullptr, nullptr,
smjs_globhist_item_finalize,
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass smjs_globhist_item_class = {
@ -160,16 +167,14 @@ smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
switch (JSID_TO_INT(id)) {
case GLOBHIST_TITLE: {
JSString *jsstr = hvp.toString();
char *str = JS_EncodeString(smjs_ctx, jsstr);
char *str = jsval_to_string(smjs_ctx, hvp);
mem_free_set(&history_item->title, stracpy(str));
return true;
}
case GLOBHIST_URL: {
JSString *jsstr = hvp.toString();
char *str = JS_EncodeString(smjs_ctx, jsstr);
char *str = jsval_to_string(smjs_ctx, hvp);
mem_free_set(&history_item->url, stracpy(str));
@ -228,7 +233,7 @@ smjs_globhist_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
if (!JS_IdToValue(ctx, id, &r_tmp))
goto ret_null;
uri_string = JS_EncodeString(ctx, r_tmp.toString());
uri_string = jsval_to_string(ctx, r_tmp);
if (!uri_string) goto ret_null;
history_item = get_global_history_item(uri_string);
@ -248,9 +253,17 @@ ret_null:
}
static const JSClassOps smjs_globhist_ops = {
nullptr, nullptr,
smjs_globhist_get_property, nullptr,
nullptr, nullptr, nullptr, nullptr
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass smjs_globhist_class = {
@ -320,7 +333,6 @@ smjs_globhist_item_set_property_title(JSContext *ctx, unsigned int argc, JS::Val
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct global_history_item *history_item;
JSString *jsstr;
char *str;
/* This can be called if @obj if not itself an instance of the
@ -335,8 +347,7 @@ smjs_globhist_item_set_property_title(JSContext *ctx, unsigned int argc, JS::Val
if (!history_item) return false;
jsstr = args[0].toString();
str = JS_EncodeString(smjs_ctx, jsstr);
str = jsval_to_string(smjs_ctx, args[0]);
mem_free_set(&history_item->title, stracpy(str));
return true;
@ -374,7 +385,6 @@ smjs_globhist_item_set_property_url(JSContext *ctx, unsigned int argc, JS::Value
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct global_history_item *history_item;
JSString *jsstr;
char *str;
/* This can be called if @obj if not itself an instance of the
@ -389,8 +399,7 @@ smjs_globhist_item_set_property_url(JSContext *ctx, unsigned int argc, JS::Value
if (!history_item) return false;
jsstr = args[0].toString();
str = JS_EncodeString(smjs_ctx, jsstr);
str = jsval_to_string(smjs_ctx, args[0]);
mem_free_set(&history_item->url, stracpy(str));
return true;

View File

@ -44,8 +44,7 @@ script_hook_url(va_list ap, void *data)
if (false == (r_rval.toBoolean()))
ret = EVENT_HOOK_STATUS_LAST;
} else {
JSString *jsstr = r_rval.toString();
char *str = JS_EncodeString(smjs_ctx, jsstr);
char *str = jsval_to_string(smjs_ctx, r_rval);
mem_free_set(url, stracpy(str));
}

View File

@ -18,9 +18,17 @@ static bool keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
static void keymap_finalize(JSFreeOp *op, JSObject *obj);
static const JSClassOps keymap_ops = {
nullptr, nullptr,
keymap_get_property, keymap_set_property,
nullptr, nullptr, nullptr, keymap_finalize,
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass keymap_class = {
@ -55,7 +63,7 @@ keymap_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
if (!JS_IdToValue(ctx, id, &r_tmp))
goto ret_null;
keystroke_str = JS_EncodeString(ctx, r_tmp.toString());
keystroke_str = jsval_to_string(ctx, r_tmp);
if (!keystroke_str) goto ret_null;
action_str = get_action_name_from_keystroke((enum keymap_id) *data,
@ -126,14 +134,14 @@ keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
JS::RootedValue rval(ctx);
JS_IdToValue(ctx, id, &rval);
keystroke_str = JS_EncodeString(ctx, rval.toString());
keystroke_str = jsval_to_string(ctx, rval);
if (!keystroke_str) return false;
if (hvp.isString()) {
char *action_str;
action_str = JS_EncodeString(ctx, hvp.toString());
action_str = jsval_to_string(ctx, hvp);
if (!action_str) return false;
if (bind_do(keymap_str, keystroke_str, action_str, 0))

View File

@ -76,15 +76,13 @@ smjs_load_uri(JSContext *ctx, unsigned int argc, JS::Value *rval)
struct smjs_load_uri_hop *hop;
struct download *download;
JSString *jsstr;
protocol_external_handler_T *external_handler;
char *uri_string;
struct uri *uri;
if (argc < 2) return false;
jsstr = args[0].toString();
uri_string = JS_EncodeString(smjs_ctx, jsstr);
uri_string = jsval_to_string(smjs_ctx, args[0]);
if (!uri_string || !*uri_string) return false;
uri = get_uri(uri_string, 0);

View File

@ -59,9 +59,17 @@ static bool smjs_location_array_get_property(JSContext *ctx, JS::HandleObject ho
static void smjs_location_array_finalize(JSFreeOp *op, JSObject *obj);
static const JSClassOps location_array_ops = {
nullptr, nullptr,
smjs_location_array_get_property, nullptr,
nullptr, nullptr, nullptr, smjs_location_array_finalize,
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook{
};
static const JSClass location_array_class = {
@ -682,13 +690,7 @@ session_set_property_search_direction(JSContext *ctx, unsigned int argc, JS::Val
(JSClass *) &session_class, NULL);
if (!ses) return false;
char *str;
JSString *jsstr;
jsstr = args[0].toString();
if (!jsstr) return true;
str = JS_EncodeString(ctx, jsstr);
char *str = jsval_to_string(ctx, args[0]);
if (!str) return true;
if (!strcmp(str, "up"))
@ -742,13 +744,7 @@ session_set_property_mark(JSContext *ctx, unsigned int argc, JS::Value *vp)
(JSClass *) &session_class, NULL);
if (!ses) return false;
char *str;
JSString *jsstr;
jsstr = args[0].toString();
if (!jsstr) return true;
str = JS_EncodeString(ctx, jsstr);
char *str = jsval_to_string(ctx, args[0]);
if (!str) return true;
if (!strcmp(str, "nothing"))
@ -781,13 +777,7 @@ session_set_property_insert_mode(JSContext *ctx, unsigned int argc, JS::Value *v
(JSClass *) &session_class, NULL);
if (!ses) return false;
char *str;
JSString *jsstr;
jsstr = args[0].toString();
if (!jsstr) return true;
str = JS_EncodeString(ctx, jsstr);
char *str = jsval_to_string(ctx, args[0]);
if (!str) return true;
if (!strcmp(str, "disabled"))
@ -820,13 +810,7 @@ session_set_property_navigate_mode(JSContext *ctx, unsigned int argc, JS::Value
(JSClass *) &session_class, NULL);
if (!ses) return false;
char *str;
JSString *jsstr;
jsstr = args[0].toString();
if (!jsstr) return true;
str = JS_EncodeString(ctx, jsstr);
char *str = jsval_to_string(ctx, args[0]);
if (!str) return true;
if (!strcmp(str, "cursor"))
@ -857,13 +841,7 @@ session_set_property_search_word(JSContext *ctx, unsigned int argc, JS::Value *v
(JSClass *) &session_class, NULL);
if (!ses) return false;
char *str;
JSString *jsstr;
jsstr = args[0].toString();
if (!jsstr) return true;
str = JS_EncodeString(ctx, jsstr);
char *str = jsval_to_string(ctx, args[0]);
if (!str) return true;
mem_free_set(&ses->search_word, str);
@ -889,13 +867,7 @@ session_set_property_last_search_word(JSContext *ctx, unsigned int argc, JS::Val
(JSClass *) &session_class, NULL);
if (!ses) return false;
char *str;
JSString *jsstr;
jsstr = args[0].toString();
if (!jsstr) return true;
str = JS_EncodeString(ctx, jsstr);
char *str = jsval_to_string(ctx, args[0]);
if (!str) return true;
mem_free_set(&ses->last_search_word, str);
@ -1093,9 +1065,17 @@ session_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
}
static const JSClassOps session_array_ops = {
nullptr, nullptr,
session_array_get_property, nullptr,
nullptr, nullptr, nullptr
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass session_array_class = {
@ -1164,10 +1144,7 @@ smjs_session_goto_url(JSContext *ctx, unsigned int argc, JS::Value *rval)
(JSClass *) &session_class, NULL);
if (!ses) return false; /* detached */
jsstr = args[0].toString();
if (!jsstr) return false;
url = JS_EncodeString(ctx, jsstr);
url = jsval_to_string(ctx, args[0]);
if (!url) return false;
uri = get_uri(url, 0);

View File

@ -21,9 +21,17 @@ static bool terminal_get_property(JSContext *ctx, JS::HandleObject hobj, JS::Han
static void terminal_finalize(JSFreeOp *op, JSObject *obj);
static const JSClassOps terminal_ops = {
nullptr, nullptr,
terminal_get_property, nullptr,
nullptr, nullptr, nullptr, terminal_finalize
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass terminal_class = {
@ -192,9 +200,17 @@ terminal_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId
}
static const JSClassOps terminal_array_ops = {
nullptr, nullptr,
terminal_array_get_property, nullptr,
nullptr, nullptr, nullptr, nullptr
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass terminal_array_class = {

View File

@ -25,9 +25,17 @@ static bool view_state_set_property(JSContext *ctx, JS::HandleObject hobj, JS::H
static void view_state_finalize(JSFreeOp *op, JSObject *obj);
static const JSClassOps view_state_ops = {
nullptr, nullptr,
view_state_get_property, view_state_set_property,
nullptr, nullptr, nullptr, view_state_finalize
nullptr, // addProperty
nullptr, // deleteProperty
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
nullptr // trace JS_GlobalObjectTraceHook
};
static const JSClass view_state_class = {