mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
ECMAScript: Preserve all of Unicode when reading the accessKey property.
Setting the property does not yet support Unicode.
This commit is contained in:
parent
245c8cb020
commit
00a5b88371
@ -182,15 +182,15 @@ input_get(struct SEE_interpreter *interp, struct SEE_object *o,
|
|||||||
SEE_SET_UNDEFINED(res);
|
SEE_SET_UNDEFINED(res);
|
||||||
|
|
||||||
if (p == s_accessKey) {
|
if (p == s_accessKey) {
|
||||||
struct string keystr;
|
struct SEE_string *keystr;
|
||||||
if (!link)
|
if (!link)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
init_string(&keystr);
|
keystr = SEE_string_new(interp, 0);
|
||||||
add_accesskey_to_string(&keystr, link->accesskey);
|
if (link->accesskey)
|
||||||
str = string_to_SEE_string(interp, keystr.source);
|
append_unicode_to_SEE_string(interp, keystr,
|
||||||
|
link->accesskey);
|
||||||
SEE_SET_STRING(res, str);
|
SEE_SET_STRING(res, str);
|
||||||
done_string(&keystr);
|
|
||||||
} else if (p == s_alt) {
|
} else if (p == s_alt) {
|
||||||
str = string_to_SEE_string(interp, fc->alt);
|
str = string_to_SEE_string(interp, fc->alt);
|
||||||
SEE_SET_STRING(res, str);
|
SEE_SET_STRING(res, str);
|
||||||
|
@ -101,3 +101,25 @@ string_to_SEE_string(struct SEE_interpreter *interp, unsigned char *s)
|
|||||||
str->data[i] = s[i];
|
str->data[i] = s[i];
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
append_unicode_to_SEE_string(struct SEE_interpreter *interp,
|
||||||
|
struct SEE_string *str,
|
||||||
|
unicode_val_T u)
|
||||||
|
{
|
||||||
|
if (u <= 0xFFFF) {
|
||||||
|
/* TODO: Should this reject code points in the
|
||||||
|
* surrogate range? */
|
||||||
|
SEE_string_addch(str, u);
|
||||||
|
} else if (u <= 0x10FFFF) {
|
||||||
|
SEE_string_addch(0xD800 + ((u - 0x10000) >> 10));
|
||||||
|
SEE_string_addch(0xDC00 + (u & 0x3FF));
|
||||||
|
} else {
|
||||||
|
/* str->interpreter exists but is not documented, so don't
|
||||||
|
* use it; use a separate @interp parameter instead.
|
||||||
|
* Also, SEE does not support "%lX". */
|
||||||
|
SEE_error_throw(interp, interp->RangeError,
|
||||||
|
"UTF-16 cannot encode U+%.4X",
|
||||||
|
(unsigned int) u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,5 +9,7 @@ struct SEE_input *SEE_input_elinks(struct SEE_interpreter *, unsigned char *);
|
|||||||
unsigned char *SEE_string_to_unsigned_char(struct SEE_string *);
|
unsigned char *SEE_string_to_unsigned_char(struct SEE_string *);
|
||||||
unsigned char *SEE_value_to_unsigned_char(struct SEE_interpreter *, struct SEE_value *);
|
unsigned char *SEE_value_to_unsigned_char(struct SEE_interpreter *, struct SEE_value *);
|
||||||
struct SEE_string *string_to_SEE_string(struct SEE_interpreter *, unsigned char *);
|
struct SEE_string *string_to_SEE_string(struct SEE_interpreter *, unsigned char *);
|
||||||
|
void append_unicode_to_SEE_string(struct SEE_interpreter *, struct SEE_string *,
|
||||||
|
unicode_val_T);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -117,6 +117,8 @@ static const JSFunctionSpec input_funcs[] = {
|
|||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static JSString *unicode_to_jsstring(JSContext *ctx, unicode_val_T u);
|
||||||
|
|
||||||
static JSBool
|
static JSBool
|
||||||
input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
||||||
{
|
{
|
||||||
@ -146,14 +148,19 @@ input_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
|||||||
switch (JSVAL_TO_INT(id)) {
|
switch (JSVAL_TO_INT(id)) {
|
||||||
case JSP_INPUT_ACCESSKEY:
|
case JSP_INPUT_ACCESSKEY:
|
||||||
{
|
{
|
||||||
struct string keystr;
|
JSString *keystr;
|
||||||
|
|
||||||
if (!link) break;
|
if (!link) break;
|
||||||
|
|
||||||
init_string(&keystr);
|
if (!link->accesskey) {
|
||||||
add_accesskey_to_string(&keystr, link->accesskey);
|
*vp = JS_GetEmptyStringValue(ctx);
|
||||||
string_to_jsval(ctx, vp, keystr.source);
|
} else {
|
||||||
done_string(&keystr);
|
keystr = unicode_to_jsstring(ctx, link->accesskey);
|
||||||
|
if (keystr)
|
||||||
|
*vp = STRING_TO_JSVAL(keystr);
|
||||||
|
else
|
||||||
|
return JS_FALSE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case JSP_INPUT_ALT:
|
case JSP_INPUT_ALT:
|
||||||
@ -970,3 +977,27 @@ forms_namedItem(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *r
|
|||||||
|
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static JSString *
|
||||||
|
unicode_to_jsstring(JSContext *ctx, unicode_val_T u)
|
||||||
|
{
|
||||||
|
jschar buf[2];
|
||||||
|
|
||||||
|
/* If JS_NewUCStringCopyN hits a null character, it truncates
|
||||||
|
* the string there and pads it with more nulls. However,
|
||||||
|
* that is not a problem here, because if there is a null
|
||||||
|
* character in buf[], then it must be the only character. */
|
||||||
|
if (u <= 0xFFFF) {
|
||||||
|
/* TODO: Should this reject code points in the
|
||||||
|
* surrogate range? */
|
||||||
|
buf[0] = u;
|
||||||
|
return JS_NewUCStringCopyN(ctx, buf, 1);
|
||||||
|
} else if (u <= 0x10FFFF) {
|
||||||
|
buf[0] = 0xD800 + ((u - 0x10000) >> 10);
|
||||||
|
buf[1] = 0xDC00 + (u & 0x3FF);
|
||||||
|
return JS_NewUCStringCopyN(ctx, buf, 2);
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user