@@ -53429,14 +53429,26 @@ static JSValue js_typed_array_get_byteOffset(JSContext *ctx,
53429
53429
return JS_NewInt32(ctx, ta->offset);
53430
53430
}
53431
53431
53432
- JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv ,
53432
+ JSValue JS_NewTypedArray(JSContext *ctx, size_t length, const void *init ,
53433
53433
JSTypedArrayEnum type)
53434
53434
{
53435
+ JSValue args[1], ret;
53436
+
53435
53437
if (type < JS_TYPED_ARRAY_UINT8C || type > JS_TYPED_ARRAY_FLOAT64)
53436
53438
return JS_ThrowRangeError(ctx, "invalid typed array type");
53437
53439
53438
- return js_typed_array_constructor(ctx, JS_UNDEFINED, argc, argv,
53439
- JS_CLASS_UINT8C_ARRAY + type);
53440
+ args[0] = JS_NewInt64(ctx, length);
53441
+ ret = js_typed_array_constructor(ctx, JS_UNDEFINED, 1, (JSValueConst *)args,
53442
+ JS_CLASS_UINT8C_ARRAY + type);
53443
+ JS_FreeValue(ctx, args[0]);
53444
+
53445
+ if (init != NULL && !JS_IsException(ret)) {
53446
+ JSObject *p = JS_VALUE_GET_OBJ(ret);
53447
+ size_t len = length * (1 << typed_array_size_log2(p->class_id));
53448
+ memcpy(p->u.array.u.ptr, init, len);
53449
+ }
53450
+
53451
+ return ret;
53440
53452
}
53441
53453
53442
53454
/* Return the buffer associated to the typed array or an exception if
0 commit comments