Skip to content

Commit

Permalink
set prototype in JSON.parse; fixes #578
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Aug 11, 2023
1 parent d4d6bd1 commit c94c898
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions devs/run-tests/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,14 @@ function testInstanceOf() {
const obj = {}
isEq(obj instanceof Object, true)
isEq(obj instanceof Error, false)

const json = JSON.parse("{}")
isEq(json instanceof Object, true)
isEq(json instanceof Error, false)

const foo = new Foo(12)
isEq(foo instanceof Object, true)
isEq(foo instanceof Foo, true)
}

class Foo {
Expand Down
3 changes: 2 additions & 1 deletion runtime/devicescript/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ static value_t parse_array(parser_t *state) {

static value_t parse_object(parser_t *state) {
devs_ctx_t *ctx = state->ctx;
devs_map_t *arr = devs_map_try_alloc(ctx, 0);
devs_map_t *arr =
devs_map_try_alloc(ctx, devs_get_builtin_object(ctx, DEVS_BUILTIN_OBJECT_OBJECT_PROTOTYPE));
if (!arr)
return devs_undefined;
value_t ret = devs_value_from_gc_obj(ctx, arr);
Expand Down

0 comments on commit c94c898

Please sign in to comment.