From 7df43b89deba8b6f4f82b97c8a307a7de777eeae Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Sat, 23 Mar 2019 16:39:40 +0300 Subject: [PATCH] Fixed accesing global function and objects in modules. --- njs/njs_variable.c | 2 +- njs/test/module/normal.js | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/njs/njs_variable.c b/njs/njs_variable.c index ddaa5318..b692b6f1 100644 --- a/njs/njs_variable.c +++ b/njs/njs_variable.c @@ -488,7 +488,7 @@ njs_variable_reference_resolve(njs_vm_t *vm, njs_variable_reference_t *vr, return NXT_OK; } - if (scope->module || scope->parent == NULL) { + if (scope->parent == NULL) { /* A global scope. */ vr->scope = scope; diff --git a/njs/test/module/normal.js b/njs/test/module/normal.js index 32e4964d..675b391f 100644 --- a/njs/test/module/normal.js +++ b/njs/test/module/normal.js @@ -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!"); -- 2.47.3