JS: Second batch of OFW PR changes

This commit is contained in:
Willy-JL
2024-10-19 01:17:22 +01:00
parent 2353871ab7
commit bb6c015235
15 changed files with 78 additions and 63 deletions

View File

@@ -475,6 +475,22 @@ static int getprop_builtin_string(
return 0;
}
static int getprop_builtin_number(
struct mjs* mjs,
mjs_val_t val,
const char* name,
size_t name_len,
mjs_val_t* res) {
if(strcmp(name, "toString") == 0) {
*res = mjs_mk_foreign_func(mjs, (mjs_func_ptr_t)mjs_number_to_string);
return 1;
}
(void)val;
(void)name_len;
return 0;
}
static int getprop_builtin_array(
struct mjs* mjs,
mjs_val_t val,
@@ -589,6 +605,8 @@ static int getprop_builtin(struct mjs* mjs, mjs_val_t val, mjs_val_t name, mjs_v
} else if(s != NULL && n == 5 && strncmp(s, "apply", n) == 0) {
*res = mjs_mk_foreign_func(mjs, (mjs_func_ptr_t)mjs_apply_);
handled = 1;
} else if(mjs_is_number(val)) {
handled = getprop_builtin_number(mjs, val, s, n, res);
} else if(mjs_is_array(val)) {
handled = getprop_builtin_array(mjs, val, s, n, res);
} else if(mjs_is_foreign(val)) {