@@ -40441,6 +40441,36 @@ static JSValue js_string___isSpace(JSContext *ctx, JSValueConst this_val,
40441
40441
}
40442
40442
#endif
40443
40443
40444
+ static JSValue js_string_at(JSContext *ctx, JSValueConst this_val,
40445
+ int argc, JSValueConst *argv)
40446
+ {
40447
+ JSValue val, ret;
40448
+ JSString *p;
40449
+ int idx, c;
40450
+
40451
+ val = JS_ToStringCheckObject(ctx, this_val);
40452
+ if (JS_IsException(val))
40453
+ return val;
40454
+ p = JS_VALUE_GET_STRING(val);
40455
+ if (JS_ToInt32Sat(ctx, &idx, argv[0])) {
40456
+ JS_FreeValue(ctx, val);
40457
+ return JS_EXCEPTION;
40458
+ }
40459
+ if (idx < 0)
40460
+ idx = p->len + idx;
40461
+ if (idx < 0 || idx >= p->len) {
40462
+ ret = JS_UNDEFINED;
40463
+ } else {
40464
+ if (p->is_wide_char)
40465
+ c = p->u.str16[idx];
40466
+ else
40467
+ c = p->u.str8[idx];
40468
+ ret = js_new_string_char(ctx, c);
40469
+ }
40470
+ JS_FreeValue(ctx, val);
40471
+ return ret;
40472
+ }
40473
+
40444
40474
static JSValue js_string_charCodeAt(JSContext *ctx, JSValueConst this_val,
40445
40475
int argc, JSValueConst *argv)
40446
40476
{
@@ -41744,6 +41774,7 @@ static const JSCFunctionListEntry js_string_funcs[] = {
41744
41774
41745
41775
static const JSCFunctionListEntry js_string_proto_funcs[] = {
41746
41776
JS_PROP_INT32_DEF("length", 0, JS_PROP_CONFIGURABLE ),
41777
+ JS_CFUNC_DEF("at", 1, js_string_at ),
41747
41778
JS_CFUNC_DEF("charCodeAt", 1, js_string_charCodeAt ),
41748
41779
JS_CFUNC_DEF("charAt", 1, js_string_charAt ),
41749
41780
JS_CFUNC_DEF("concat", 1, js_string_concat ),
0 commit comments