forked from microsoft/devicescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimpl_json.c
More file actions
29 lines (22 loc) · 843 Bytes
/
impl_json.c
File metadata and controls
29 lines (22 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "devs_internal.h"
void fun2_JSON_parse(devs_ctx_t *ctx) {
value_t str = devs_arg(ctx, 0);
value_t reviver = devs_arg(ctx, 1);
if (!devs_is_nullish(reviver))
devs_throw_not_supported_error(ctx, "JSON.parse reviver");
str = devs_value_to_string(ctx, str);
devs_value_pin(ctx, str);
unsigned sz;
const char *data = devs_string_get_utf8(ctx, str, &sz);
if (data != NULL)
devs_ret(ctx, devs_json_parse(ctx, data, sz, true));
devs_value_unpin(ctx, str);
}
void fun3_JSON_stringify(devs_ctx_t *ctx) {
value_t obj = devs_arg(ctx, 0);
value_t repl = devs_arg(ctx, 1);
int indent = devs_arg_int(ctx, 2);
if (!devs_is_nullish(repl))
devs_throw_not_supported_error(ctx, "JSON.stringify replacer");
devs_ret(ctx, devs_json_stringify(ctx, obj, indent, true));
}