core: Add a helper for getting a property by string as a string. I've typed this too much.

This commit is contained in:
2025-12-06 14:04:27 -05:00
parent 3a3b889196
commit d84b06f814
5 changed files with 81 additions and 46 deletions

View File

@@ -502,6 +502,24 @@ int tf_util_get_length(JSContext* context, JSValue value)
return result;
}
const char* tf_util_get_property_as_string(JSContext* context, JSValue object, const char* key)
{
if (!JS_IsObject(object))
{
return NULL;
}
JSValue value = JS_GetPropertyStr(context, object, key);
if (JS_IsUndefined(value))
{
return NULL;
}
const char* string = JS_ToCString(context, value);
JS_FreeValue(context, value);
return string;
}
int tf_util_insert_index(const void* key, const void* base, size_t count, size_t size, int (*compare)(const void*, const void*))
{
int lower = 0;