]> git.kaiwu.me - njs.git/commitdiff
HTTP: improved r.parent property handler.
authorDmitry Volyntsev <xeioex@nginx.com>
Mon, 25 Nov 2019 14:54:58 +0000 (17:54 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Mon, 25 Nov 2019 14:54:58 +0000 (17:54 +0300)
Previously, r.parent handler threw an exception if it was called not for
a subrequest.  This is too restrictive, as it prevents any iterations
over all r properties (for example: JSON.stringify()).

Instead, "undefined" value is returned as it is already done for
r.requestBody when request body is unavailable.

nginx/ngx_http_js_module.c

index e1ee56c088549f28eb0f96222887c26ef3956336..340887d0b8a8c3779a01c0554998f29b1cf1c8af 100644 (file)
@@ -2091,8 +2091,8 @@ ngx_http_js_ext_get_parent(njs_vm_t *vm, njs_value_t *value, void *obj,
                     : NULL;
 
     if (ctx == NULL || ctx->vm != vm) {
-        njs_vm_error(vm, "parent can only be returned for a subrequest");
-        return NJS_ERROR;
+        njs_value_undefined_set(value);
+        return NJS_OK;
     }
 
     njs_value_assign(value, njs_value_arg(&ctx->request));