Merge 9c2a19eaac5d1a2b79e924f480fd0a4f3500b525 into 8807fedec55bc4dbdf7b4780d36bfc4b4fd6e5e2

This commit is contained in:
Dmitry Volyntsev 2025-09-24 17:43:38 -04:00 committed by GitHub
commit 92330d9edf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View File

@ -54936,14 +54936,26 @@ static JSValue js_typed_array_get_byteOffset(JSContext *ctx,
return JS_NewUint32(ctx, ta->offset);
}
JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
JSValue JS_NewTypedArray(JSContext *ctx, size_t length, const void *init,
JSTypedArrayEnum type)
{
JSValue args[1], ret;
if (type < JS_TYPED_ARRAY_UINT8C || type > JS_TYPED_ARRAY_FLOAT64)
return JS_ThrowRangeError(ctx, "invalid typed array type");
return js_typed_array_constructor(ctx, JS_UNDEFINED, argc, argv,
JS_CLASS_UINT8C_ARRAY + type);
args[0] = JS_NewInt64(ctx, length);
ret = js_typed_array_constructor(ctx, JS_UNDEFINED, 1, (JSValueConst *)args,
JS_CLASS_UINT8C_ARRAY + type);
JS_FreeValue(ctx, args[0]);
if (init != NULL && !JS_IsException(ret)) {
JSObject *p = JS_VALUE_GET_OBJ(ret);
size_t len = length * (1 << typed_array_size_log2(p->class_id));
memcpy(p->u.array.u.ptr, init, len);
}
return ret;
}
/* Return the buffer associated to the typed array or an exception if

View File

@ -882,8 +882,8 @@ typedef enum JSTypedArrayEnum {
JS_TYPED_ARRAY_FLOAT64,
} JSTypedArrayEnum;
JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
JSTypedArrayEnum array_type);
JSValue JS_NewTypedArray(JSContext *ctx, size_t length, const void *init,
JSTypedArrayEnum type);
JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
size_t *pbyte_offset,
size_t *pbyte_length,