Welcome! Log In Create A New Profile

Advanced

[njs] Fixed Error() constructor with no arguments.

Dmitry Volyntsev
August 05, 2019 11:18AM
details: https://hg.nginx.org/njs/rev/88ff9dfa847e
branches:
changeset: 1103:88ff9dfa847e
user: hongzhidao <hongzhidao@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") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed Error() constructor with no arguments.

Dmitry Volyntsev 254 August 05, 2019 11:18AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 177
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready