@@ -53429,14 +53429,26 @@ static JSValue js_typed_array_get_byteOffset(JSContext *ctx,
5342953429 return JS_NewInt32(ctx, ta->offset);
5343053430}
5343153431
53432- JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv ,
53432+ JSValue JS_NewTypedArray(JSContext *ctx, size_t length, const void *init ,
5343353433 JSTypedArrayEnum type)
5343453434{
53435+ JSValue args[1], ret;
53436+
5343553437 if (type < JS_TYPED_ARRAY_UINT8C || type > JS_TYPED_ARRAY_FLOAT64)
5343653438 return JS_ThrowRangeError(ctx, "invalid typed array type");
5343753439
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;
5344053452}
5344153453
5344253454/* Return the buffer associated to the typed array or an exception if
0 commit comments