From: Dmitry Volyntsev Date: Sat, 23 Mar 2019 13:39:40 +0000 (+0300) Subject: Fixed accesing global function and objects in modules. X-Git-Tag: 0.3.0~7 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=7df43b89deba8b6f4f82b97c8a307a7de777eeae;p=njs.git Fixed accesing global function and objects in modules. --- 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!");