1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-13 05:06:30 +04:00

JS: Update and fix docs, fix Number.toString() with decimals (#4168)

* Update and fix JS docs

This could really use some automation, atleast for API reference
There are TypeScript definitions and typedocs, we don't need to be monkeys copying and reformatting this to API reference by hand

* Fix bugged character

* JS: Fix Number.toString() with decimals

* Fix

* Forgot this one

* docs: mention per-view child format

* Added @portasynthinca3 to docs' codeowners

* Updated CODEOWNERS

---------

Co-authored-by: Anna Antonenko <portasynthinca3@gmail.com>
Co-authored-by: hedger <hedger@nanode.su>
Co-authored-by: hedger <hedger@users.noreply.github.com>
This commit is contained in:
WillyJL
2025-04-01 11:02:12 +00:00
committed by GitHub
parent 933134ed94
commit d34ff3310d
19 changed files with 675 additions and 45 deletions

View File

@@ -9,6 +9,8 @@
#include "mjs_string_public.h"
#include "mjs_util.h"
#include <float.h>
mjs_val_t mjs_mk_null(void) {
return MJS_NULL;
}
@@ -94,7 +96,7 @@ int mjs_is_boolean(mjs_val_t v) {
}
#define MJS_IS_POINTER_LEGIT(n) \
(((n)&MJS_TAG_MASK) == 0 || ((n)&MJS_TAG_MASK) == (~0 & MJS_TAG_MASK))
(((n) & MJS_TAG_MASK) == 0 || ((n) & MJS_TAG_MASK) == (~0 & MJS_TAG_MASK))
MJS_PRIVATE mjs_val_t mjs_pointer_to_value(struct mjs* mjs, void* p) {
uint64_t n = ((uint64_t)(uintptr_t)p);
@@ -165,13 +167,13 @@ MJS_PRIVATE void mjs_number_to_string(struct mjs* mjs) {
mjs_val_t ret = MJS_UNDEFINED;
mjs_val_t base_v = MJS_UNDEFINED;
int32_t base = 10;
int32_t num;
double num;
/* get number from `this` */
if(!mjs_check_arg(mjs, -1 /*this*/, "this", MJS_TYPE_NUMBER, NULL)) {
goto clean;
}
num = mjs_get_int32(mjs, mjs->vals.this_obj);
num = mjs_get_double(mjs, mjs->vals.this_obj);
if(mjs_nargs(mjs) >= 1) {
/* get base from arg 0 */
@@ -181,9 +183,20 @@ MJS_PRIVATE void mjs_number_to_string(struct mjs* mjs) {
base = mjs_get_int(mjs, base_v);
}
char tmp_str[] = "-2147483648";
itoa(num, tmp_str, base);
ret = mjs_mk_string(mjs, tmp_str, ~0, true);
if(base != 10 || floor(num) == num) {
char tmp_str[] = "-2147483648";
itoa((int32_t)num, tmp_str, base);
ret = mjs_mk_string(mjs, tmp_str, ~0, true);
} else {
char tmp_str[] = "2.22514337200000e-308";
snprintf(tmp_str, sizeof(tmp_str), "%.*g", DBL_DIG, num);
size_t len = strlen(tmp_str);
while(len && tmp_str[len - 1] == '0') {
len--;
}
tmp_str[len] = '\0';
ret = mjs_mk_string(mjs, tmp_str, ~0, true);
}
clean:
mjs_return(mjs, ret);