]> git.kaiwu.me - njs.git/commitdiff
Fixed "accumulative" mode of VM.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 26 Nov 2019 12:01:02 +0000 (15:01 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 26 Nov 2019 12:01:02 +0000 (15:01 +0300)
The issue was introduced in 452ce96df2e3.

This closes #258 issue on Github.

src/njs_vm.c
src/test/njs_interactive_test.c

index 354a49da440e459788c23ae2bffd2b8c7e79ed1a..19ec0e9719fefead54c773dcee729079584421db 100644 (file)
@@ -195,7 +195,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
 
     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;
index 931b799735a92cbdb1499648bda3de96b18c8c74..fb384a02535567fedf28acf54aa9318fe5e56a94 100644 (file)
@@ -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