0
0
mirror of https://github.com/rkd77/elinks.git synced 2025-06-30 22:19:29 -04:00

[quickjs] Try to convert to normal string

String can be of type STRING_ROPE, so make some conversion first.
This commit is contained in:
Witold Filipczyk 2025-05-19 12:59:27 +02:00
parent 3c4dd230ca
commit 344bb68236

View File

@ -104,15 +104,20 @@ string_get(const JSString *p, int idx)
/* Convert the string *@vp to an access key. Return 0 for no access
* key, UCS_NO_CHAR on error, or the access key otherwise. */
static unicode_val_T
js_value_to_accesskey(JSValueConst val)
js_value_to_accesskey(JSContext *ctx, JSValueConst val)
{
ELOG
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(val);
unicode_val_T ret = UCS_NO_CHAR; /* which the caller will reject */
JSString *p = JS_VALUE_GET_STRING(val);
const char *str = JS_ToCString(ctx, val);
JSValue new_val = JS_NewString(ctx, str);
JS_FreeCString(ctx, str);
JSString *p = JS_VALUE_GET_STRING(new_val);
size_t len;
uint16_t chr[2];
@ -120,21 +125,26 @@ js_value_to_accesskey(JSValueConst val)
len = p->len;
/* This implementation ignores extra characters in the string. */
if (len < 1)
return 0; /* which means no access key */
if (len < 1) {
ret = 0; /* which means no access key */
goto end;
}
chr[0] = string_get(p, 0);
if (!is_utf16_surrogate(chr[0])) {
return chr[0];
ret = chr[0];
goto end;
}
if (len >= 2) {
chr[1] = string_get(p, 1);
if (is_utf16_high_surrogate(chr[0])
&& is_utf16_low_surrogate(chr[1])) {
return join_utf16_surrogates(chr[0], chr[1]);
ret = join_utf16_surrogates(chr[0], chr[1]);
}
}
return UCS_NO_CHAR; /* which the caller will reject */
end:
JS_FreeValue(ctx, new_val);
return ret;
}
static JSValue
@ -244,7 +254,7 @@ js_input_set_property_accessKey(JSContext *ctx, JSValueConst this_val, JSValue v
#endif
return JS_NULL;
}
accesskey = js_value_to_accesskey(val);
accesskey = js_value_to_accesskey(ctx, val);
if (link) {
link->accesskey = accesskey;