@@ -1008,6 +1008,7 @@ uc_filter(uc_vm_t *vm, size_t nargs)
10081008 return NULL ;
10091009
10101010 arr = ucv_array_new (vm );
1011+ uc_vm_stack_push (vm , ucv_get (arr ));
10111012
10121013 for (arrlen = ucv_array_length (obj ), arridx = 0 ; arridx < arrlen ; arridx ++ ) {
10131014 uc_vm_ctx_push (vm );
@@ -1030,6 +1031,8 @@ uc_filter(uc_vm_t *vm, size_t nargs)
10301031 ucv_put (rv );
10311032 }
10321033
1034+ ucv_put (uc_vm_stack_pop (vm ));
1035+
10331036 return arr ;
10341037}
10351038
@@ -1301,6 +1304,7 @@ uc_map(uc_vm_t *vm, size_t nargs)
13011304 return NULL ;
13021305
13031306 arr = ucv_array_new (vm );
1307+ uc_vm_stack_push (vm , ucv_get (arr ));
13041308
13051309 for (arrlen = ucv_array_length (obj ), arridx = 0 ; arridx < arrlen ; arridx ++ ) {
13061310 uc_vm_ctx_push (vm );
@@ -1320,6 +1324,8 @@ uc_map(uc_vm_t *vm, size_t nargs)
13201324 ucv_array_push (arr , rv );
13211325 }
13221326
1327+ ucv_put (uc_vm_stack_pop (vm ));
1328+
13231329 return arr ;
13241330}
13251331
@@ -3543,17 +3549,17 @@ uc_json_from_object(uc_vm_t *vm, uc_value_t *obj, json_object **jso)
35433549{
35443550 bool trail = false, eof = false;
35453551 enum json_tokener_error err ;
3546- struct json_tokener * tok ;
3547- uc_value_t * rfn , * rbuf ;
3552+ struct json_tokener * tok = NULL ;
3553+ uc_value_t * rfn , * rbuf = NULL ;
35483554 uc_stringbuf_t * buf ;
35493555
3550- rfn = ucv_property_get (obj , "read" );
3556+ rfn = ucv_get ( ucv_property_get (obj , "read" ) );
35513557
35523558 if (!ucv_is_callable (rfn )) {
35533559 uc_vm_raise_exception (vm , EXCEPTION_TYPE ,
35543560 "Input object does not implement read() method" );
35553561
3556- return NULL ;
3562+ goto out ;
35573563 }
35583564
35593565 tok = xjs_new_tokener ();
@@ -3563,11 +3569,8 @@ uc_json_from_object(uc_vm_t *vm, uc_value_t *obj, json_object **jso)
35633569 uc_vm_stack_push (vm , ucv_get (rfn ));
35643570 uc_vm_stack_push (vm , ucv_int64_new (1024 ));
35653571
3566- if (uc_vm_call (vm , true, 1 ) != EXCEPTION_NONE ) {
3567- json_tokener_free (tok );
3568-
3569- return NULL ;
3570- }
3572+ if (uc_vm_call (vm , true, 1 ) != EXCEPTION_NONE )
3573+ goto fail ;
35713574
35723575 rbuf = uc_vm_stack_pop (vm );
35733576
@@ -3576,8 +3579,6 @@ uc_json_from_object(uc_vm_t *vm, uc_value_t *obj, json_object **jso)
35763579
35773580 /* on EOF, stop parsing unless trailing garbage was detected which handled below */
35783581 if (eof && !trail ) {
3579- ucv_put (rbuf );
3580-
35813582 /* Didn't parse a complete object yet, possibly a non-delimited atomic value
35823583 such as `null`, `true` etc. - nudge parser by sending final zero byte.
35833584 See json-c issue #681 <https://github.com/json-c/json-c/issues/681> */
@@ -3591,10 +3592,7 @@ uc_json_from_object(uc_vm_t *vm, uc_value_t *obj, json_object **jso)
35913592 uc_vm_raise_exception (vm , EXCEPTION_SYNTAX ,
35923593 "Trailing garbage after JSON data" );
35933594
3594- json_tokener_free (tok );
3595- ucv_put (rbuf );
3596-
3597- return NULL ;
3595+ goto fail ;
35983596 }
35993597
36003598 if (ucv_type (rbuf ) != UC_STRING ) {
@@ -3616,13 +3614,24 @@ uc_json_from_object(uc_vm_t *vm, uc_value_t *obj, json_object **jso)
36163614 }
36173615
36183616 ucv_put (rbuf );
3617+ rbuf = NULL ;
36193618
36203619 err = json_tokener_get_error (tok );
36213620
36223621 if (err != json_tokener_success && err != json_tokener_continue )
36233622 break ;
36243623 }
36253624
3625+ goto out ;
3626+
3627+ fail :
3628+ json_tokener_free (tok );
3629+ tok = NULL ;
3630+
3631+ out :
3632+ ucv_put (rfn );
3633+ ucv_put (rbuf );
3634+
36263635 return tok ;
36273636}
36283637
@@ -5833,7 +5842,7 @@ static uc_value_t *
58335842uc_callfunc (uc_vm_t * vm , size_t nargs )
58345843{
58355844 size_t argoff = vm -> stack .count - nargs , i ;
5836- uc_value_t * fn_scope , * prev_scope , * res ;
5845+ uc_value_t * fn_scope , * prev_scope = NULL , * res ;
58375846 uc_value_t * fn = uc_fn_arg (0 );
58385847 uc_value_t * this = uc_fn_arg (1 );
58395848 uc_value_t * scope = uc_fn_arg (2 );
@@ -5859,24 +5868,27 @@ uc_callfunc(uc_vm_t *vm, size_t nargs)
58595868 fn_scope = NULL ;
58605869 }
58615870
5871+ if (fn_scope ) {
5872+ prev_scope = ucv_get (uc_vm_scope_get (vm ));
5873+ uc_vm_stack_push (vm , ucv_get (prev_scope ));
5874+ uc_vm_scope_set (vm , fn_scope );
5875+ }
5876+
58625877 uc_vm_stack_push (vm , ucv_get (this ));
58635878 uc_vm_stack_push (vm , ucv_get (fn ));
58645879
58655880 for (i = 3 ; i < nargs ; i ++ )
58665881 uc_vm_stack_push (vm , ucv_get (vm -> stack .entries [3 + argoff ++ ]));
58675882
5868- if (fn_scope ) {
5869- prev_scope = ucv_get (uc_vm_scope_get (vm ));
5870- uc_vm_scope_set (vm , fn_scope );
5871- }
5872-
58735883 if (uc_vm_call (vm , true, i - 3 ) == EXCEPTION_NONE )
58745884 res = uc_vm_stack_pop (vm );
58755885 else
58765886 res = NULL ;
58775887
5878- if (fn_scope )
5888+ if (fn_scope ) {
58795889 uc_vm_scope_set (vm , prev_scope );
5890+ ucv_put (uc_vm_stack_pop (vm ));
5891+ }
58805892
58815893 return res ;
58825894}
0 commit comments