[njs] Fixed "accumulative" mode of VM.

Dmitry Volyntsev xeioex at nginx.com
Tue Nov 26 12:42:34 UTC 2019


details:   https://hg.nginx.org/njs/rev/8a41cab86cc2
branches:  
changeset: 1258:8a41cab86cc2
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Nov 26 15:01:02 2019 +0300
description:
Fixed "accumulative" mode of VM.

The issue was introduced in 452ce96df2e3.

This closes #258 issue on Github.

diffstat:

 src/njs_vm.c                    |   2 +-
 src/test/njs_interactive_test.c |  10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)

diffs (32 lines):

diff -r 851550b92d9d -r 8a41cab86cc2 src/njs_vm.c
--- a/src/njs_vm.c	Mon Nov 25 17:54:58 2019 +0300
+++ b/src/njs_vm.c	Tue Nov 26 15:01:02 2019 +0300
@@ -195,7 +195,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
 
     vm->variables_hash = scope->variables;
 
-    if (vm->options.init) {
+    if (vm->options.init && !vm->options.accumulative) {
         ret = njs_vm_init(vm);
         if (njs_slow_path(ret != NJS_OK)) {
             return ret;
diff -r 851550b92d9d -r 8a41cab86cc2 src/test/njs_interactive_test.c
--- a/src/test/njs_interactive_test.c	Mon Nov 25 17:54:58 2019 +0300
+++ b/src/test/njs_interactive_test.c	Tue Nov 26 15:01:02 2019 +0300
@@ -75,6 +75,16 @@ static njs_interactive_test_t  njs_test[
     { njs_str("/abc/i.test('ABC')" ENTER),
       njs_str("true") },
 
+    /* Accumulative mode. */
+
+    { njs_str("var a = 1" ENTER
+              "a" ENTER),
+      njs_str("1") },
+
+    { njs_str("Number.prototype.test = 'test'" ENTER
+              "Number.prototype.test" ENTER),
+      njs_str("test") },
+
     /* Error handling */
 
     { njs_str("var a = ;" ENTER


More information about the nginx-devel mailing list