[njs] Splitting njs_vm_value_to_ext_string().

Dmitry Volyntsev xeioex at nginx.com
Wed Jul 3 17:39:39 UTC 2019


details:   https://hg.nginx.org/njs/rev/e03f3e12589e
branches:  
changeset: 1030:e03f3e12589e
user:      hongzhidao <hongzhidao at gmail.com>
date:      Tue Jul 02 22:18:56 2019 -0400
description:
Splitting njs_vm_value_to_ext_string().

Into njs_vm_value_to_string() and njs_vm_backtrace_dump().

diffstat:

 nginx/ngx_http_js_module.c      |   18 +-
 nginx/ngx_stream_js_module.c    |   22 +-
 njs/njs.c                       |  163 +++++++++++++++++++++++++++-
 njs/njs.h                       |   16 ++-
 njs/njs_json.c                  |    2 +-
 njs/njs_object_property.c       |    2 +-
 njs/njs_vm.c                    |  231 ++++++++-------------------------------
 njs/test/njs_benchmark.c        |    4 +-
 njs/test/njs_interactive_test.c |    6 +-
 njs/test/njs_unit_test.c        |   22 +--
 10 files changed, 258 insertions(+), 228 deletions(-)

diffs (787 lines):

diff -r 5a7de2ee74ba -r e03f3e12589e nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Tue Jul 02 22:10:19 2019 -0400
+++ b/nginx/ngx_http_js_module.c	Tue Jul 02 22:18:56 2019 -0400
@@ -561,7 +561,7 @@ ngx_http_js_content_event_handler(ngx_ht
     ctx->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
 
     if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->request), 1) != NJS_OK) {
-        njs_vm_retval_to_ext_string(ctx->vm, &exception);
+        njs_vm_retval_string(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                       "js exception: %*s", exception.length, exception.start);
@@ -693,7 +693,7 @@ ngx_http_js_variable(ngx_http_request_t 
     pending = njs_vm_pending(ctx->vm);
 
     if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->request), 1) != NJS_OK) {
-        njs_vm_retval_to_ext_string(ctx->vm, &exception);
+        njs_vm_retval_string(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                       "js exception: %*s", exception.length, exception.start);
@@ -702,7 +702,7 @@ ngx_http_js_variable(ngx_http_request_t 
         return NGX_OK;
     }
 
-    if (njs_vm_retval_to_ext_string(ctx->vm, &value) != NJS_OK) {
+    if (njs_vm_retval_string(ctx->vm, &value) != NJS_OK) {
         return NGX_ERROR;
     }
 
@@ -767,7 +767,7 @@ ngx_http_js_init_vm(ngx_http_request_t *
     cln->data = ctx;
 
     if (njs_vm_start(ctx->vm) == NJS_ERROR) {
-        njs_vm_retval_to_ext_string(ctx->vm, &exception);
+        njs_vm_retval_string(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                       "js exception: %*s", exception.length, exception.start);
@@ -1371,7 +1371,7 @@ ngx_http_js_ext_log_core(njs_vm_t *vm, n
 
     c = r->connection;
 
-    if (njs_vm_value_to_ext_string(vm, &msg, njs_arg(args, nargs, 1), 0)
+    if (njs_vm_value_to_string(vm, &msg, njs_arg(args, nargs, 1))
         == NJS_ERROR)
     {
         return NJS_ERROR;
@@ -1797,7 +1797,7 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm,
     arg = njs_arg(args, nargs, 2);
 
     if (njs_value_is_string(arg)) {
-        if (njs_vm_value_to_ext_string(vm, &args_arg, arg, 0) != NJS_OK) {
+        if (njs_vm_value_to_string(vm, &args_arg, arg) != NJS_OK) {
             njs_vm_error(vm, "failed to convert args");
             return NJS_ERROR;
         }
@@ -2172,7 +2172,7 @@ ngx_http_js_handle_event(ngx_http_reques
     rc = njs_vm_run(ctx->vm);
 
     if (rc == NJS_ERROR) {
-        njs_vm_retval_to_ext_string(ctx->vm, &exception);
+        njs_vm_retval_string(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                       "js exception: %*s", exception.length, exception.start);
@@ -2190,7 +2190,7 @@ static njs_ret_t
 ngx_http_js_string(njs_vm_t *vm, const njs_value_t *value, nxt_str_t *str)
 {
     if (!njs_value_is_null_or_undefined(value)) {
-        if (njs_vm_value_to_ext_string(vm, str, value, 0) == NJS_ERROR) {
+        if (njs_vm_value_to_string(vm, str, value) == NJS_ERROR) {
             return NJS_ERROR;
         }
 
@@ -2342,7 +2342,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_
     rc = njs_vm_compile(jmcf->vm, &start, end);
 
     if (rc != NJS_OK) {
-        njs_vm_retval_to_ext_string(jmcf->vm, &text);
+        njs_vm_retval_string(jmcf->vm, &text);
 
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "%*s, included",
diff -r 5a7de2ee74ba -r e03f3e12589e nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c	Tue Jul 02 22:10:19 2019 -0400
+++ b/nginx/ngx_stream_js_module.c	Tue Jul 02 22:18:56 2019 -0400
@@ -489,7 +489,7 @@ ngx_stream_js_phase_handler(ngx_stream_s
 
 exception:
 
-    njs_vm_retval_to_ext_string(ctx->vm, &exception);
+    njs_vm_retval_string(ctx->vm, &exception);
 
     ngx_log_error(NGX_LOG_ERR, c->log, 0, "js exception: %*s",
                   exception.length, exception.start);
@@ -615,7 +615,7 @@ ngx_stream_js_body_filter(ngx_stream_ses
 
 exception:
 
-    njs_vm_retval_to_ext_string(ctx->vm, &exception);
+    njs_vm_retval_string(ctx->vm, &exception);
 
     ngx_log_error(NGX_LOG_ERR, c->log, 0, "js exception: %*s",
                   exception.length, exception.start);
@@ -666,7 +666,7 @@ ngx_stream_js_variable(ngx_stream_sessio
     pending = njs_vm_pending(ctx->vm);
 
     if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->args), 1) != NJS_OK) {
-        njs_vm_retval_to_ext_string(ctx->vm, &exception);
+        njs_vm_retval_string(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
                       "js exception: %*s", exception.length, exception.start);
@@ -675,7 +675,7 @@ ngx_stream_js_variable(ngx_stream_sessio
         return NGX_OK;
     }
 
-    if (njs_vm_retval_to_ext_string(ctx->vm, &value) != NJS_OK) {
+    if (njs_vm_retval_string(ctx->vm, &value) != NJS_OK) {
         return NGX_ERROR;
     }
 
@@ -740,7 +740,7 @@ ngx_stream_js_init_vm(ngx_stream_session
     cln->data = ctx;
 
     if (njs_vm_start(ctx->vm) == NJS_ERROR) {
-        njs_vm_retval_to_ext_string(ctx->vm, &exception);
+        njs_vm_retval_string(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
                       "js exception: %*s", exception.length, exception.start);
@@ -1016,7 +1016,7 @@ ngx_stream_js_ext_log_core(njs_vm_t *vm,
 
     c = s->connection;
 
-    if (njs_vm_value_to_ext_string(vm, &msg, njs_arg(args, nargs, 1), 0)
+    if (njs_vm_value_to_string(vm, &msg, njs_arg(args, nargs, 1))
         == NJS_ERROR)
     {
         return NJS_ERROR;
@@ -1047,7 +1047,7 @@ ngx_stream_js_ext_on(njs_vm_t *vm, njs_v
         return NJS_ERROR;
     }
 
-    if (njs_vm_value_to_ext_string(vm, &name, njs_arg(args, nargs, 1), 0)
+    if (njs_vm_value_to_string(vm, &name, njs_arg(args, nargs, 1))
         == NJS_ERROR)
     {
         njs_vm_error(vm, "failed to convert event arg");
@@ -1093,7 +1093,7 @@ ngx_stream_js_ext_off(njs_vm_t *vm, njs_
         return NJS_ERROR;
     }
 
-    if (njs_vm_value_to_ext_string(vm, &name, njs_arg(args, nargs, 1), 0)
+    if (njs_vm_value_to_string(vm, &name, njs_arg(args, nargs, 1))
         == NJS_ERROR)
     {
         njs_vm_error(vm, "failed to convert event arg");
@@ -1362,7 +1362,7 @@ ngx_stream_js_handle_event(ngx_stream_se
     rc = njs_vm_run(ctx->vm);
 
     if (rc == NJS_ERROR) {
-        njs_vm_retval_to_ext_string(ctx->vm, &exception);
+        njs_vm_retval_string(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
                       "js exception: %*s", exception.length, exception.start);
@@ -1380,7 +1380,7 @@ static njs_ret_t
 ngx_stream_js_string(njs_vm_t *vm, const njs_value_t *value, nxt_str_t *str)
 {
     if (!njs_value_is_null_or_undefined(value)) {
-        if (njs_vm_value_to_ext_string(vm, str, value, 0) == NJS_ERROR) {
+        if (njs_vm_value_to_string(vm, str, value) == NJS_ERROR) {
             return NJS_ERROR;
         }
 
@@ -1533,7 +1533,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ng
     rc = njs_vm_compile(jmcf->vm, &start, end);
 
     if (rc != NJS_OK) {
-        njs_vm_retval_to_ext_string(jmcf->vm, &text);
+        njs_vm_retval_string(jmcf->vm, &text);
 
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "%*s, included",
diff -r 5a7de2ee74ba -r e03f3e12589e njs/njs.c
--- a/njs/njs.c	Tue Jul 02 22:10:19 2019 -0400
+++ b/njs/njs.c	Tue Jul 02 22:18:56 2019 -0400
@@ -838,8 +838,167 @@ njs_vm_memory_error(njs_vm_t *vm)
 }
 
 
+nxt_array_t *
+njs_vm_backtrace(njs_vm_t *vm)
+{
+    if (vm->backtrace != NULL && !nxt_array_is_empty(vm->backtrace)) {
+        return vm->backtrace;
+    }
+
+    return NULL;
+}
+
+
+static njs_ret_t
+njs_vm_backtrace_dump(njs_vm_t *vm, nxt_str_t *dst, const njs_value_t *src)
+{
+    u_char                 *p, *start, *end;
+    size_t                 len, count;
+    nxt_uint_t             i;
+    nxt_array_t            *backtrace;
+    njs_backtrace_entry_t  *be, *prev;
+
+    backtrace = njs_vm_backtrace(vm);
+
+    len = dst->length + 1;
+
+    count = 0;
+    prev = NULL;
+
+    be = backtrace->start;
+
+    for (i = 0; i < backtrace->items; i++) {
+        if (i != 0 && prev->name.start == be->name.start
+            && prev->line == be->line)
+        {
+            count++;
+
+        } else {
+
+            if (count != 0) {
+                len += nxt_length("      repeats  times\n")
+                       + NXT_INT_T_LEN;
+                count = 0;
+            }
+
+            len += be->name.length + nxt_length("    at  ()\n");
+
+            if (be->line != 0) {
+                len += be->file.length + NXT_INT_T_LEN + 1;
+
+            } else {
+                len += nxt_length("native");
+            }
+        }
+
+        prev = be;
+        be++;
+    }
+
+    p = nxt_mp_alloc(vm->mem_pool, len);
+    if (p == NULL) {
+        njs_memory_error(vm);
+        return NXT_ERROR;
+    }
+
+    start = p;
+    end = start + len;
+
+    p = nxt_cpymem(p, dst->start, dst->length);
+    *p++ = '\n';
+
+    count = 0;
+    prev = NULL;
+
+    be = backtrace->start;
+
+    for (i = 0; i < backtrace->items; i++) {
+        if (i != 0 && prev->name.start == be->name.start
+            && prev->line == be->line)
+        {
+            count++;
+
+        } else {
+            if (count != 0) {
+                p = nxt_sprintf(p, end, "      repeats %uz times\n",
+                                count);
+                count = 0;
+            }
+
+            p = nxt_sprintf(p, end, "    at %V ", &be->name);
+
+            if (be->line != 0) {
+                p = nxt_sprintf(p, end, "(%V:%uD)\n", &be->file,
+                                be->line);
+
+            } else {
+                p = nxt_sprintf(p, end, "(native)\n");
+            }
+        }
+
+        prev = be;
+        be++;
+    }
+
+    dst->start = start;
+    dst->length = p - dst->start;
+
+    return NXT_OK;
+}
+
+
 njs_ret_t
-njs_vm_retval_to_ext_string(njs_vm_t *vm, nxt_str_t *dst)
+njs_vm_value_string(njs_vm_t *vm, nxt_str_t *dst, const njs_value_t *src)
+{
+    njs_ret_t   ret;
+    nxt_uint_t  exception;
+
+    if (nxt_slow_path(src->type == NJS_NUMBER
+                      && njs_number(src) == 0
+                      && signbit(njs_number(src))))
+    {
+        njs_string_get(&njs_string_minus_zero, dst);
+        return NXT_OK;
+    }
+
+    exception = 1;
+
+again:
+
+    ret = njs_vm_value_to_string(vm, dst, src);
+
+    if (nxt_fast_path(ret == NXT_OK)) {
+
+        if (njs_vm_backtrace(vm) != NULL) {
+            ret = njs_vm_backtrace_dump(vm, dst, src);
+            if (nxt_slow_path(ret != NXT_OK)) {
+                return NXT_ERROR;
+            }
+        }
+
+        return NXT_OK;
+    }
+
+    if (exception) {
+        exception = 0;
+
+        /* value evaluation threw an exception. */
+
+        vm->top_frame->trap_tries = 0;
+
+        src = &vm->retval;
+        goto again;
+    }
+
+    dst->length = 0;
+    dst->start = NULL;
+
+    return NXT_ERROR;
+}
+
+
+njs_ret_t
+njs_vm_retval_string(njs_vm_t *vm, nxt_str_t *dst)
 {
     if (vm->top_frame == NULL) {
         /* An exception was thrown during compilation. */
@@ -847,7 +1006,7 @@ njs_vm_retval_to_ext_string(njs_vm_t *vm
         njs_vm_init(vm);
     }
 
-    return njs_vm_value_to_ext_string(vm, dst, &vm->retval, 1);
+    return njs_vm_value_string(vm, dst, &vm->retval);
 }
 
 
diff -r 5a7de2ee74ba -r e03f3e12589e njs/njs.h
--- a/njs/njs.h	Tue Jul 02 22:10:19 2019 -0400
+++ b/njs/njs.h	Tue Jul 02 22:18:56 2019 -0400
@@ -249,9 +249,19 @@ NXT_EXPORT u_char *njs_vm_value_string_a
     uint32_t size);
 NXT_EXPORT nxt_int_t njs_vm_value_string_copy(njs_vm_t *vm, nxt_str_t *retval,
     const njs_value_t *value, uintptr_t *next);
-NXT_EXPORT njs_ret_t njs_vm_value_to_ext_string(njs_vm_t *vm, nxt_str_t *dst,
-    const njs_value_t *src, nxt_uint_t handle_exception);
-NXT_EXPORT njs_ret_t njs_vm_retval_to_ext_string(njs_vm_t *vm, nxt_str_t *dst);
+
+/*
+ * Converts a value to string.
+ */
+NXT_EXPORT njs_ret_t njs_vm_value_to_string(njs_vm_t *vm, nxt_str_t *dst,
+    const njs_value_t *src);
+
+/*
+ * Calls njs_vm_value_to_string(), if exception was thrown adds backtrace.
+ */
+NXT_EXPORT njs_ret_t njs_vm_value_string(njs_vm_t *vm, nxt_str_t *dst,
+    const njs_value_t *src);
+NXT_EXPORT njs_ret_t njs_vm_retval_string(njs_vm_t *vm, nxt_str_t *dst);
 
 NXT_EXPORT njs_ret_t njs_vm_value_dump(njs_vm_t *vm, nxt_str_t *dst,
     const njs_value_t *value, nxt_uint_t console, nxt_uint_t indent);
diff -r 5a7de2ee74ba -r e03f3e12589e njs/njs_json.c
--- a/njs/njs_json.c	Tue Jul 02 22:10:19 2019 -0400
+++ b/njs/njs_json.c	Tue Jul 02 22:18:56 2019 -0400
@@ -2566,7 +2566,7 @@ memory_error:
 
 exception:
 
-    njs_vm_value_to_ext_string(vm, retval, &vm->retval, 1);
+    njs_vm_value_string(vm, retval, &vm->retval);
 
     return NXT_OK;
 }
diff -r 5a7de2ee74ba -r e03f3e12589e njs/njs_object_property.c
--- a/njs/njs_object_property.c	Tue Jul 02 22:10:19 2019 -0400
+++ b/njs/njs_object_property.c	Tue Jul 02 22:18:56 2019 -0400
@@ -437,7 +437,7 @@ njs_external_property_set(njs_vm_t *vm, 
     pq = (njs_property_query_t *) vm->stash;
 
     if (!njs_is_null_or_undefined(setval)) {
-        ret = njs_vm_value_to_ext_string(vm, &s, setval, 0);
+        ret = njs_vm_value_to_string(vm, &s, setval);
         if (nxt_slow_path(ret != NXT_OK)) {
             return ret;
         }
diff -r 5a7de2ee74ba -r e03f3e12589e njs/njs_vm.c
--- a/njs/njs_vm.c	Tue Jul 02 22:10:19 2019 -0400
+++ b/njs/njs_vm.c	Tue Jul 02 22:18:56 2019 -0400
@@ -3086,184 +3086,58 @@ njs_value_own_enumerate(njs_vm_t *vm, co
 
 
 njs_ret_t
-njs_vm_value_to_ext_string(njs_vm_t *vm, nxt_str_t *dst, const njs_value_t *src,
-    nxt_uint_t handle_exception)
+njs_vm_value_to_string(njs_vm_t *vm, nxt_str_t *dst, const njs_value_t *src)
 {
-    u_char                 *p, *start, *end;
-    size_t                 len, size, count;
-    njs_ret_t              ret;
-    nxt_uint_t             i, exception;
-    nxt_array_t            *backtrace;
-    njs_value_t            value;
-    njs_backtrace_entry_t  *be, *prev;
-
-    exception = handle_exception;
-
-again:
-
-    if (nxt_fast_path(src != NULL)) {
-
-        if (nxt_slow_path(src->type == NJS_OBJECT_INTERNAL_ERROR)) {
-
-            /* MemoryError is a nonextensible internal error. */
-
-            if (!src->data.u.object->extensible) {
-                njs_string_get(&njs_string_memory_error, dst);
-                return NXT_OK;
-            }
-        }
-
-        value = *src;
-
-        if (nxt_slow_path(!njs_is_primitive(&value))) {
-
-            ret = njs_object_value_to_string(vm, &value);
-
-            if (nxt_slow_path(ret != NXT_OK)) {
-                goto fail;
-            }
-        }
-
-        if (nxt_slow_path((value.type == NJS_NUMBER
-                            && value.data.u.number == 0
-                            && signbit(value.data.u.number))))
-        {
-            value = njs_string_minus_zero;
-            ret = NXT_OK;
-
-        } else {
-            ret = njs_primitive_value_to_string(vm, &value, &value);
-        }
-
-        if (nxt_fast_path(ret == NXT_OK)) {
-            size = value.short_string.size;
-
-            if (size != NJS_STRING_LONG) {
-                start = nxt_mp_alloc(vm->mem_pool, size);
-                if (nxt_slow_path(start == NULL)) {
-                    njs_memory_error(vm);
-                    return NXT_ERROR;
-                }
-
-                memcpy(start, value.short_string.start, size);
-
-            } else {
-                size = value.long_string.size;
-                start = value.long_string.data->start;
-            }
-
-            dst->length = size;
-            dst->start = start;
-
-            if (exception && njs_vm_backtrace(vm) != NULL) {
-
-                backtrace = njs_vm_backtrace(vm);
-
-                len = dst->length + 1;
-
-                count = 0;
-                prev = NULL;
-
-                be = backtrace->start;
-
-                for (i = 0; i < backtrace->items; i++) {
-                    if (i != 0 && prev->name.start == be->name.start
-                        && prev->line == be->line)
-                    {
-                        count++;
-
-                    } else {
-
-                        if (count != 0) {
-                            len += nxt_length("      repeats  times\n")
-                                   + NXT_INT_T_LEN;
-                            count = 0;
-                        }
-
-                        len += be->name.length + nxt_length("    at  ()\n");
-
-                        if (be->line != 0) {
-                            len += be->file.length + NXT_INT_T_LEN + 1;
-
-                        } else {
-                            len += nxt_length("native");
-                        }
-                    }
-
-                    prev = be;
-                    be++;
-                }
-
-                p = nxt_mp_alloc(vm->mem_pool, len);
-                if (p == NULL) {
-                    njs_memory_error(vm);
-                    return NXT_ERROR;
-                }
-
-                start = p;
-                end = start + len;
-
-                p = nxt_cpymem(p, dst->start, dst->length);
-                *p++ = '\n';
-
-                count = 0;
-                prev = NULL;
-
-                be = backtrace->start;
-
-                for (i = 0; i < backtrace->items; i++) {
-                    if (i != 0 && prev->name.start == be->name.start
-                        && prev->line == be->line)
-                    {
-                        count++;
-
-                    } else {
-                        if (count != 0) {
-                            p = nxt_sprintf(p, end, "      repeats %uz times\n",
-                                            count);
-                            count = 0;
-                        }
-
-                        p = nxt_sprintf(p, end, "    at %V ", &be->name);
-
-                        if (be->line != 0) {
-                            p = nxt_sprintf(p, end, "(%V:%uD)\n", &be->file,
-                                            be->line);
-
-                        } else {
-                            p = nxt_sprintf(p, end, "(native)\n");
-                        }
-                    }
-
-                    prev = be;
-                    be++;
-                }
-
-                dst->start = start;
-                dst->length = p - dst->start;
-            }
-
+    u_char       *start;
+    size_t       size;
+    njs_ret_t    ret;
+    njs_value_t  value;
+
+    if (nxt_slow_path(src == NULL)) {
+        return NXT_ERROR;
+    }
+
+    if (nxt_slow_path(src->type == NJS_OBJECT_INTERNAL_ERROR)) {
+        /* MemoryError is a nonextensible internal error. */
+        if (!src->data.u.object->extensible) {
+            njs_string_get(&njs_string_memory_error, dst);
             return NXT_OK;
         }
     }
 
-fail:
-
-    if (handle_exception) {
-        handle_exception = 0;
-
-        /* value evaluation threw an exception. */
-
-        vm->top_frame->trap_tries = 0;
-
-        src = &vm->retval;
-        goto again;
+    value = *src;
+
+    if (nxt_slow_path(!njs_is_primitive(&value))) {
+        ret = njs_object_value_to_string(vm, &value);
+        if (nxt_slow_path(ret != NXT_OK)) {
+            return ret;
+        }
     }
 
-    dst->length = 0;
-    dst->start = NULL;
-
-    return NXT_ERROR;
+    ret = njs_primitive_value_to_string(vm, &value, &value);
+
+    if (nxt_fast_path(ret == NXT_OK)) {
+        size = value.short_string.size;
+
+        if (size != NJS_STRING_LONG) {
+            start = nxt_mp_alloc(vm->mem_pool, size);
+            if (nxt_slow_path(start == NULL)) {
+                njs_memory_error(vm);
+                return NXT_ERROR;
+            }
+
+            memcpy(start, value.short_string.start, size);
+
+        } else {
+            size = value.long_string.size;
+            start = value.long_string.data->start;
+        }
+
+        dst->length = size;
+        dst->start = start;
+    }
+
+    return ret;
 }
 
 
@@ -3299,7 +3173,7 @@ njs_object_value_to_string(njs_vm_t *vm,
     /*
      * Prevent njs_vmcode_interpreter() to unwind the current frame if
      * an exception happens.  It preserves the current frame state if
-     * njs_vm_value_to_ext_string() is called from within njs_vm_run().
+     * njs_vm_value_string() is called from within njs_vm_run().
      */
     previous = vm->top_frame->previous;
     vm->top_frame->previous = NULL;
@@ -3371,7 +3245,7 @@ njs_vm_value_string_copy(njs_vm_t *vm, n
         return NXT_ERROR;
     }
 
-    return njs_vm_value_to_ext_string(vm, retval, value, 0);
+    return njs_vm_value_to_string(vm, retval, value);
 }
 
 
@@ -3443,17 +3317,6 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm,
 }
 
 
-nxt_array_t *
-njs_vm_backtrace(njs_vm_t *vm)
-{
-    if (vm->backtrace != NULL && !nxt_array_is_empty(vm->backtrace)) {
-        return vm->backtrace;
-    }
-
-    return NULL;
-}
-
-
 void
 njs_debug(njs_index_t index, njs_value_t *value)
 {
diff -r 5a7de2ee74ba -r e03f3e12589e njs/test/njs_benchmark.c
--- a/njs/test/njs_benchmark.c	Tue Jul 02 22:10:19 2019 -0400
+++ b/njs/test/njs_benchmark.c	Tue Jul 02 22:18:56 2019 -0400
@@ -56,8 +56,8 @@ njs_unit_test_benchmark(nxt_str_t *scrip
 
         (void) njs_vm_start(nvm);
 
-        if (njs_vm_retval_to_ext_string(nvm, &s) != NXT_OK) {
-            nxt_printf("njs_vm_retval_to_ext_string() failed\n");
+        if (njs_vm_retval_string(nvm, &s) != NXT_OK) {
+            nxt_printf("njs_vm_retval_string() failed\n");
             goto done;
         }
 
diff -r 5a7de2ee74ba -r e03f3e12589e njs/test/njs_interactive_test.c
--- a/njs/test/njs_interactive_test.c	Tue Jul 02 22:10:19 2019 -0400
+++ b/njs/test/njs_interactive_test.c	Tue Jul 02 22:18:56 2019 -0400
@@ -226,7 +226,7 @@ static njs_interactive_test_t  njs_test[
                  "      repeats 2 times\n"
                  "    at main (native)\n") },
 
-    /* Exception in njs_vm_retval_to_ext_string() */
+    /* Exception in njs_vm_retval_string() */
 
     { nxt_string("var o = { toString: function() { return [1] } }" ENTER
                  "o" ENTER),
@@ -305,8 +305,8 @@ njs_interactive_test(nxt_bool_t verbose)
             }
         }
 
-        if (njs_vm_retval_to_ext_string(vm, &s) != NXT_OK) {
-            nxt_printf("njs_vm_retval_to_ext_string() failed\n");
+        if (njs_vm_retval_string(vm, &s) != NXT_OK) {
+            nxt_printf("njs_vm_retval_string() failed\n");
             goto done;
         }
 
diff -r 5a7de2ee74ba -r e03f3e12589e njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Jul 02 22:10:19 2019 -0400
+++ b/njs/test/njs_unit_test.c	Tue Jul 02 22:18:56 2019 -0400
@@ -13427,7 +13427,7 @@ njs_unit_test_method_external(njs_vm_t *
         return NJS_ERROR;
     }
 
-    ret = njs_vm_value_to_ext_string(vm, &s, njs_arg(args, nargs, 1), 0);
+    ret = njs_vm_value_to_string(vm, &s, njs_arg(args, nargs, 1));
     if (ret == NXT_OK && s.length == 3 && memcmp(s.start, "YES", 3) == 0) {
         return njs_vm_value_string_set(vm, njs_vm_retval(vm), r->uri.start,
                                        r->uri.length);
@@ -13453,9 +13453,7 @@ njs_unit_test_create_external(njs_vm_t *
         return NJS_ERROR;
     }
 
-    if (njs_vm_value_to_ext_string(vm, &uri, njs_arg(args, nargs, 1), 0)
-        != NJS_OK)
-    {
+    if (njs_vm_value_to_string(vm, &uri, njs_arg(args, nargs, 1)) != NJS_OK) {
         return NJS_ERROR;
     }
 
@@ -13799,14 +13797,14 @@ njs_unit_test(njs_unit_test_t tests[], s
 
             ret = njs_vm_start(nvm);
 
-            if (njs_vm_retval_to_ext_string(nvm, &s) != NXT_OK) {
-                nxt_printf("njs_vm_retval_to_ext_string() failed\n");
+            if (njs_vm_retval_string(nvm, &s) != NXT_OK) {
+                nxt_printf("njs_vm_retval_string() failed\n");
                 goto done;
             }
 
         } else {
-            if (njs_vm_retval_to_ext_string(vm, &s) != NXT_OK) {
-                nxt_printf("njs_vm_retval_to_ext_string() failed\n");
+            if (njs_vm_retval_string(vm, &s) != NXT_OK) {
+                nxt_printf("njs_vm_retval_string() failed\n");
                 goto done;
             }
         }
@@ -14015,8 +14013,8 @@ njs_vm_json_test(nxt_bool_t disassemble,
             goto done;
         }
 
-        if (njs_vm_retval_to_ext_string(vm, &s) != NXT_OK) {
-            nxt_printf("njs_vm_retval_to_ext_string() failed\n");
+        if (njs_vm_retval_string(vm, &s) != NXT_OK) {
+            nxt_printf("njs_vm_retval_string() failed\n");
             goto done;
         }
 
@@ -14042,8 +14040,8 @@ done:
         nxt_printf("njs_vm_json_test passed\n");
 
     } else {
-        if (njs_vm_retval_to_ext_string(vm, &s) != NXT_OK) {
-            nxt_printf("njs_vm_retval_to_ext_string() failed\n");
+        if (njs_vm_retval_string(vm, &s) != NXT_OK) {
+            nxt_printf("njs_vm_retval_string() failed\n");
 
         } else {
             nxt_printf("%V\n", &s);


More information about the nginx-devel mailing list