string indexing

This commit is contained in:
2026-02-09 11:17:42 -06:00
parent e04ab4c30c
commit bc87fe5f70
2 changed files with 19 additions and 3 deletions

View File

@@ -3193,6 +3193,9 @@ JSValue JS_GetPropertyValue (JSContext *ctx, JSValue this_obj, JSValue prop) {
}
JSValue JS_SetPropertyNumber (JSContext *js, JSValue obj, int idx, JSValue val) {
if (JS_IsText (obj)) {
return JS_ThrowTypeError (js, "strings are immutable");
}
if (!JS_IsArray (obj)) {
return JS_ThrowInternalError (js,
"cannot set with a number on a non array");
@@ -3225,7 +3228,7 @@ JSValue JS_GetPropertyNumber (JSContext *js, JSValue obj, int idx) {
if (JS_IsText (obj)) {
uint32_t len = js_string_get_length (obj);
if (idx < 0 || (uint32_t)idx >= len) { return JS_NULL; }
return js_sub_string (js, JS_VALUE_GET_STRING (obj), idx, idx + 1);
return js_sub_string_val (js, obj, idx, idx + 1);
}
return JS_NULL;