diff --git a/src/js/quickjs/input.c b/src/js/quickjs/input.c index 1f19f1573..980a6d469 100644 --- a/src/js/quickjs/input.c +++ b/src/js/quickjs/input.c @@ -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;