From: hongzhidao Date: Sun, 4 Aug 2019 07:59:42 +0000 (-0400) Subject: Fixed Error() constructor with no arguments. X-Git-Tag: 0.3.4~24 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=53b54ff04ae0c570aa180ee2bd3196c1a880e1c2;p=njs.git Fixed Error() constructor with no arguments. --- diff --git a/src/njs_error.c b/src/njs_error.c index 97f8c0c7..1729f3a1 100644 --- a/src/njs_error.c +++ b/src/njs_error.c @@ -133,14 +133,10 @@ njs_error_create(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, 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 --git a/src/njs_value.h b/src/njs_value.h index b59ef9e0..fac48342 100644 --- a/src/njs_value.h +++ b/src/njs_value.h @@ -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 --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 61c6ad15..a87ab398 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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") },