[njs] Fixed Error() constructor with no arguments.
Dmitry Volyntsev
xeioex at nginx.com
Mon Aug 5 15:18:06 UTC 2019
details: https://hg.nginx.org/njs/rev/88ff9dfa847e
branches:
changeset: 1103:88ff9dfa847e
user: hongzhidao <hongzhidao at gmail.com>
date: Sun Aug 04 03:59:42 2019 -0400
description:
Fixed Error() constructor with no arguments.
diffstat:
src/njs_error.c | 10 +++-------
src/njs_value.h | 4 ++++
src/test/njs_unit_test.c | 5 +++++
3 files changed, 12 insertions(+), 7 deletions(-)
diffs (50 lines):
diff -r a07dc8b56fd3 -r 88ff9dfa847e src/njs_error.c
--- a/src/njs_error.c Mon Aug 05 17:36:09 2019 +0300
+++ b/src/njs_error.c Sun Aug 04 03:59:42 2019 -0400
@@ -133,14 +133,10 @@ njs_error_create(njs_vm_t *vm, njs_value
njs_object_t *error;
const njs_value_t *value;
- if (nargs == 1) {
- value = &njs_string_empty;
+ value = njs_arg(args, nargs, 1);
- } else {
- value = &args[1];
- }
-
- error = njs_error_alloc(vm, type, NULL, value);
+ error = njs_error_alloc(vm, type, NULL,
+ njs_is_defined(value) ? value : NULL);
if (njs_slow_path(error == NULL)) {
return NJS_ERROR;
}
diff -r a07dc8b56fd3 -r 88ff9dfa847e src/njs_value.h
--- a/src/njs_value.h Mon Aug 05 17:36:09 2019 +0300
+++ b/src/njs_value.h Sun Aug 04 03:59:42 2019 -0400
@@ -425,6 +425,10 @@ typedef struct {
((value)->type == NJS_UNDEFINED)
+#define njs_is_defined(value) \
+ ((value)->type != NJS_UNDEFINED)
+
+
#define njs_is_null_or_undefined(value) \
((value)->type <= NJS_UNDEFINED)
diff -r a07dc8b56fd3 -r 88ff9dfa847e src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Mon Aug 05 17:36:09 2019 +0300
+++ b/src/test/njs_unit_test.c Sun Aug 04 03:59:42 2019 -0400
@@ -7865,6 +7865,11 @@ static njs_unit_test_t njs_test[] =
{ njs_str("Error().__proto__.__proto__ == Object.prototype"),
njs_str("true") },
+ { njs_str("Error.prototype.message = 'm';"
+ "Error.prototype.name = 'n';"
+ "new Error()"),
+ njs_str("n: m") },
+
{ njs_str("EvalError('e')"),
njs_str("EvalError: e") },
More information about the nginx-devel
mailing list