diff --git a/libs/http/request.b b/libs/http/request.b index 62a9a94a..12634c30 100644 --- a/libs/http/request.b +++ b/libs/http/request.b @@ -1216,11 +1216,17 @@ class HttpRequest { return http_response } - @to_string() { + /** + * Returns the request as a string. + */ + to_string() { return '' } - @to_json() { + /** + * Returns the request as a JSON object. + */ + to_json() { return { request_uri: self.request_uri, path: self.path, @@ -1230,8 +1236,16 @@ class HttpRequest { headers: self.headers, queries: self.queries, cookies: self.cookies, - body: self.body, + body: to_string(self.body), } } + + @to_string() { + return self.to_string() + } + + @to_json() { + return self.to_json() + } } diff --git a/libs/http/response.b b/libs/http/response.b index 477a9849..e44a04d7 100644 --- a/libs/http/response.b +++ b/libs/http/response.b @@ -229,12 +229,18 @@ class HttpResponse { self.headers.set('Content-Type', mimetype) } - @to_string() { + /** + * Returns the response details in a string + */ + to_string() { return '' + ' ${self.time_taken}, redirects: ${self.redirects}, responder: ${self.responder}>' } - @to_json() { + /** + * Returns the response as a JSON object + */ + to_json() { return { status: self.status, version: self.version, @@ -243,7 +249,15 @@ class HttpResponse { responder: self.responder, headers: self.headers, cookies: self.cookies, - body: self.body + body: self.body, } } + + @to_string() { + return self.to_string() + } + + @to_json() { + return self.to_json() + } } diff --git a/src/memory.c b/src/memory.c index cd477a19..bd43beaf 100644 --- a/src/memory.c +++ b/src/memory.c @@ -400,6 +400,15 @@ void free_objects(b_vm *vm) { vm->gray_stack = NULL; } +void free_error_stacks(b_vm *vm) { + for(int index = vm->error_top - vm->errors; index < ERRORS_MAX && vm->errors[index] != NULL; index++) { + if(vm->errors[index]) { + free(vm->errors[index]); + vm->errors[index] = NULL; + } + } +} + void collect_garbage(b_vm *vm) { #if defined(DEBUG_GC) && DEBUG_GC printf("-- gc begins\n"); @@ -414,6 +423,7 @@ void collect_garbage(b_vm *vm) { table_remove_whites(vm, &vm->strings); table_remove_whites(vm, &vm->modules); sweep(vm); + free_error_stacks(vm); vm->next_gc = vm->bytes_allocated * GC_HEAP_GROWTH_FACTOR; vm->mark_value = !vm->mark_value;