From bea7a2e9ed89049306db0825c19e6cf2faddaaf4 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 11 Jun 2025 12:56:27 -0400 Subject: [PATCH] core: Use JS_NewTypedArray. --- src/util.js.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/util.js.c b/src/util.js.c index 866613bb..cf917d1d 100644 --- a/src/util.js.c +++ b/src/util.js.c @@ -500,11 +500,13 @@ void tf_util_document_settings(const char* line_prefix) JSValue tf_util_new_uint8_array(JSContext* context, const uint8_t* data, size_t size) { JSValue array_buffer = JS_NewArrayBufferCopy(context, data, size); - JSValue global = JS_GetGlobalObject(context); - JSValue constructor = JS_GetPropertyStr(context, global, "Uint8Array"); - JSValue result = JS_CallConstructor(context, constructor, 1, &array_buffer); - JS_FreeValue(context, constructor); - JS_FreeValue(context, global); + JSValue args[] = + { + array_buffer, + JS_NewInt64(context, 0), + JS_NewInt64(context, size), + }; + JSValue result = JS_NewTypedArray(context, tf_countof(args), args, JS_TYPED_ARRAY_UINT8C); JS_FreeValue(context, array_buffer); return result; }