Modules: added js_path directive.
diff --git a/nginx/ngx_http_js_module.c b/nginx/ngx_http_js_module.c
index bea11fc..dca47b8 100644
--- a/nginx/ngx_http_js_module.c
+++ b/nginx/ngx_http_js_module.c
@@ -14,6 +14,7 @@
 
 typedef struct {
     njs_vm_t            *vm;
+    ngx_array_t         *paths;
     const njs_extern_t  *req_proto;
 } ngx_http_js_main_conf_t;
 
@@ -161,6 +162,13 @@
       0,
       NULL },
 
+    { ngx_string("js_path"),
+      NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_str_array_slot,
+      NGX_HTTP_MAIN_CONF_OFFSET,
+      offsetof(ngx_http_js_main_conf_t, paths),
+      NULL },
+
     { ngx_string("js_set"),
       NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2,
       ngx_http_js_set,
@@ -2170,9 +2178,10 @@
     u_char                *start, *end;
     ssize_t                n;
     ngx_fd_t               fd;
-    ngx_str_t             *value, file;
+    ngx_str_t             *m, *value, file;
     nxt_int_t              rc;
-    nxt_str_t              text;
+    nxt_str_t              text, path;
+    ngx_uint_t             i;
     njs_vm_opt_t           options;
     ngx_file_info_t        fi;
     ngx_pool_cleanup_t    *cln;
@@ -2259,6 +2268,34 @@
     cln->handler = ngx_http_js_cleanup_vm;
     cln->data = jmcf->vm;
 
+    path.start = ngx_cycle->prefix.data;
+    path.length = ngx_cycle->prefix.len;
+
+    rc = njs_vm_add_path(jmcf->vm, &path);
+    if (rc != NXT_OK) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to add path");
+        return NGX_CONF_ERROR;
+    }
+
+    if (jmcf->paths != NGX_CONF_UNSET_PTR) {
+        m = jmcf->paths->elts;
+
+        for (i = 0; i < jmcf->paths->nelts; i++) {
+            if (ngx_conf_full_name(cf->cycle, &m[i], 0) != NGX_OK) {
+                return NGX_CONF_ERROR;
+            }
+
+            path.start = m[i].data;
+            path.length = m[i].len;
+
+            rc = njs_vm_add_path(jmcf->vm, &path);
+            if (rc != NXT_OK) {
+                ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to add path");
+                return NGX_CONF_ERROR;
+            }
+        }
+    }
+
     jmcf->req_proto = njs_vm_external_prototype(jmcf->vm,
                                                 &ngx_http_js_externals[0]);
     if (jmcf->req_proto == NULL) {
@@ -2363,6 +2400,8 @@
      *     conf->req_proto = NULL;
      */
 
+    conf->paths = NGX_CONF_UNSET_PTR;
+
     return conf;
 }
 
diff --git a/nginx/ngx_stream_js_module.c b/nginx/ngx_stream_js_module.c
index 175d383..bdba8bf 100644
--- a/nginx/ngx_stream_js_module.c
+++ b/nginx/ngx_stream_js_module.c
@@ -15,6 +15,7 @@
 
 typedef struct {
     njs_vm_t              *vm;
+    ngx_array_t           *paths;
     const njs_extern_t    *proto;
 } ngx_stream_js_main_conf_t;
 
@@ -132,6 +133,13 @@
       0,
       NULL },
 
+    { ngx_string("js_path"),
+      NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_str_array_slot,
+      NGX_STREAM_MAIN_CONF_OFFSET,
+      offsetof(ngx_stream_js_main_conf_t, paths),
+      NULL },
+
     { ngx_string("js_set"),
       NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE2,
       ngx_stream_js_set,
@@ -1394,9 +1402,10 @@
     u_char                *start, *end;
     ssize_t                n;
     ngx_fd_t               fd;
-    ngx_str_t             *value, file;
+    ngx_str_t             *m, *value, file;
     nxt_int_t              rc;
-    nxt_str_t              text;
+    nxt_str_t              text, path;
+    ngx_uint_t             i;
     njs_vm_opt_t           options;
     ngx_file_info_t        fi;
     ngx_pool_cleanup_t    *cln;
@@ -1483,6 +1492,34 @@
     cln->handler = ngx_stream_js_cleanup_vm;
     cln->data = jmcf->vm;
 
+    path.start = ngx_cycle->prefix.data;
+    path.length = ngx_cycle->prefix.len;
+
+    rc = njs_vm_add_path(jmcf->vm, &path);
+    if (rc != NXT_OK) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to add path");
+        return NGX_CONF_ERROR;
+    }
+
+    if (jmcf->paths != NGX_CONF_UNSET_PTR) {
+        m = jmcf->paths->elts;
+
+        for (i = 0; i < jmcf->paths->nelts; i++) {
+            if (ngx_conf_full_name(cf->cycle, &m[i], 0) != NGX_OK) {
+                return NGX_CONF_ERROR;
+            }
+
+            path.start = m[i].data;
+            path.length = m[i].len;
+
+            rc = njs_vm_add_path(jmcf->vm, &path);
+            if (rc != NXT_OK) {
+                ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to add path");
+                return NGX_CONF_ERROR;
+            }
+        }
+    }
+
     jmcf->proto = njs_vm_external_prototype(jmcf->vm,
                                             &ngx_stream_js_externals[0]);
 
@@ -1552,7 +1589,7 @@
 static void *
 ngx_stream_js_create_main_conf(ngx_conf_t *cf)
 {
-    ngx_stream_js_srv_conf_t  *conf;
+    ngx_stream_js_main_conf_t  *conf;
 
     conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_js_main_conf_t));
     if (conf == NULL) {
@@ -1566,6 +1603,8 @@
      *     conf->proto = NULL;
      */
 
+    conf->paths = NGX_CONF_UNSET_PTR;
+
     return conf;
 }