[njs] Fixed accesing global function and objects in modules.

Dmitry Volyntsev xeioex at nginx.com
Sat Mar 23 15:47:32 UTC 2019


details:   https://hg.nginx.org/njs/rev/81303df0fd67
branches:  
changeset: 839:81303df0fd67
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Sat Mar 23 16:39:40 2019 +0300
description:
Fixed accesing global function and objects in modules.

diffstat:

 njs/njs_variable.c        |   2 +-
 njs/test/module/normal.js |  20 +++++++++++++-------
 2 files changed, 14 insertions(+), 8 deletions(-)

diffs (59 lines):

diff -r aaf68d999559 -r 81303df0fd67 njs/njs_variable.c
--- a/njs/njs_variable.c	Sat Mar 23 14:57:52 2019 +0300
+++ b/njs/njs_variable.c	Sat Mar 23 16:39:40 2019 +0300
@@ -488,7 +488,7 @@ njs_variable_reference_resolve(njs_vm_t 
             return NXT_OK;
         }
 
-        if (scope->module || scope->parent == NULL) {
+        if (scope->parent == NULL) {
             /* A global scope. */
             vr->scope = scope;
 
diff -r aaf68d999559 -r 81303df0fd67 njs/test/module/normal.js
--- a/njs/test/module/normal.js	Sat Mar 23 14:57:52 2019 +0300
+++ b/njs/test/module/normal.js	Sat Mar 23 16:39:40 2019 +0300
@@ -6,30 +6,36 @@ import crypto from 'crypto';
 var h = crypto.createHash('md5');
 var hash = h.update('AB').digest('hex');
 
+var fails = 0;
 if (lib1.hash() != hash) {
-    console.log("failed!");
+    fails++;
 }
 
 if (lib2.hash() != hash) {
-    console.log("failed!");
+    fails++;
 }
 
 if (lib1.get() != 0) {
-    console.log("failed!");
+    fails++;
 }
 
 if (lib1_2.get() != 0) {
-    console.log("failed!");
+    fails++;
 }
 
 lib1.inc();
 
 if (lib1.get() != 1) {
-    console.log("failed!");
+    fails++;
 }
 
 if (lib1_2.get() != 1) {
-    console.log("failed!");
+    fails++;
 }
 
-console.log("passed!");
+if (JSON.stringify({}) != "{}") {
+    fails++;
+}
+
+setImmediate(console.log,
+             fails ? "failed: " + fails : "passed!");


More information about the nginx-devel mailing list