Skip to content

Commit c94c898

Browse files
committed
set prototype in JSON.parse; fixes #578
1 parent d4d6bd1 commit c94c898

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

devs/run-tests/basic.ts

+8
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ function testInstanceOf() {
503503
const obj = {}
504504
isEq(obj instanceof Object, true)
505505
isEq(obj instanceof Error, false)
506+
507+
const json = JSON.parse("{}")
508+
isEq(json instanceof Object, true)
509+
isEq(json instanceof Error, false)
510+
511+
const foo = new Foo(12)
512+
isEq(foo instanceof Object, true)
513+
isEq(foo instanceof Foo, true)
506514
}
507515

508516
class Foo {

runtime/devicescript/json.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ static value_t parse_array(parser_t *state) {
270270

271271
static value_t parse_object(parser_t *state) {
272272
devs_ctx_t *ctx = state->ctx;
273-
devs_map_t *arr = devs_map_try_alloc(ctx, 0);
273+
devs_map_t *arr =
274+
devs_map_try_alloc(ctx, devs_get_builtin_object(ctx, DEVS_BUILTIN_OBJECT_OBJECT_PROTOTYPE));
274275
if (!arr)
275276
return devs_undefined;
276277
value_t ret = devs_value_from_gc_obj(ctx, arr);

0 commit comments

Comments
 (0)