@@ -51864,6 +51864,61 @@ static JSValue js_typed_array_set_internal(JSContext *ctx,
51864
51864
return JS_EXCEPTION;
51865
51865
}
51866
51866
51867
+ static JSValue js_typed_array_at(JSContext *ctx, JSValueConst this_val,
51868
+ int argc, JSValueConst *argv)
51869
+ {
51870
+ JSObject *p;
51871
+ int64_t idx, len;
51872
+
51873
+ p = get_typed_array(ctx, this_val, /*is_dataview*/0);
51874
+ if (!p)
51875
+ return JS_EXCEPTION;
51876
+
51877
+ if (typed_array_is_detached(ctx, p)) {
51878
+ JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
51879
+ return JS_EXCEPTION;
51880
+ }
51881
+
51882
+ if (JS_ToInt64Sat(ctx, &idx, argv[0]))
51883
+ return JS_EXCEPTION;
51884
+
51885
+ len = p->u.array.count;
51886
+ if (idx < 0)
51887
+ idx = len + idx;
51888
+
51889
+ if (idx < 0 || idx >= len)
51890
+ return JS_UNDEFINED;
51891
+
51892
+ switch (p->class_id) {
51893
+ case JS_CLASS_INT8_ARRAY:
51894
+ return JS_NewInt32(ctx, p->u.array.u.int8_ptr[idx]);
51895
+ case JS_CLASS_UINT8C_ARRAY:
51896
+ case JS_CLASS_UINT8_ARRAY:
51897
+ return JS_NewInt32(ctx, p->u.array.u.uint8_ptr[idx]);
51898
+ case JS_CLASS_INT16_ARRAY:
51899
+ return JS_NewInt32(ctx, p->u.array.u.int16_ptr[idx]);
51900
+ case JS_CLASS_UINT16_ARRAY:
51901
+ return JS_NewInt32(ctx, p->u.array.u.uint16_ptr[idx]);
51902
+ case JS_CLASS_INT32_ARRAY:
51903
+ return JS_NewInt32(ctx, p->u.array.u.int32_ptr[idx]);
51904
+ case JS_CLASS_UINT32_ARRAY:
51905
+ return JS_NewUint32(ctx, p->u.array.u.uint32_ptr[idx]);
51906
+ case JS_CLASS_FLOAT32_ARRAY:
51907
+ return __JS_NewFloat64(ctx, p->u.array.u.float_ptr[idx]);
51908
+ case JS_CLASS_FLOAT64_ARRAY:
51909
+ return __JS_NewFloat64(ctx, p->u.array.u.double_ptr[idx]);
51910
+ #ifdef CONFIG_BIGNUM
51911
+ case JS_CLASS_BIG_INT64_ARRAY:
51912
+ return JS_NewBigInt64(ctx, p->u.array.u.int64_ptr[idx]);
51913
+ case JS_CLASS_BIG_UINT64_ARRAY:
51914
+ return JS_NewBigUint64(ctx, p->u.array.u.uint64_ptr[idx]);
51915
+ #endif
51916
+ }
51917
+
51918
+ abort(); /* unreachable */
51919
+ return JS_UNDEFINED;
51920
+ }
51921
+
51867
51922
static JSValue js_typed_array_set(JSContext *ctx,
51868
51923
JSValueConst this_val,
51869
51924
int argc, JSValueConst *argv)
@@ -53054,6 +53109,7 @@ static const JSCFunctionListEntry js_typed_array_base_funcs[] = {
53054
53109
53055
53110
static const JSCFunctionListEntry js_typed_array_base_proto_funcs[] = {
53056
53111
JS_CGETSET_DEF("length", js_typed_array_get_length, NULL ),
53112
+ JS_CFUNC_DEF("at", 1, js_typed_array_at ),
53057
53113
JS_CGETSET_MAGIC_DEF("buffer", js_typed_array_get_buffer, NULL, 0 ),
53058
53114
JS_CGETSET_MAGIC_DEF("byteLength", js_typed_array_get_byteLength, NULL, 0 ),
53059
53115
JS_CGETSET_MAGIC_DEF("byteOffset", js_typed_array_get_byteOffset, NULL, 0 ),
0 commit comments