[njs] Improved Object.prototype.toString for invalid values.
Dmitry Volyntsev
xeioex at nginx.com
Thu Aug 30 15:51:47 UTC 2018
details: http://hg.nginx.org/njs/rev/6931a42f5bed
branches:
changeset: 594:6931a42f5bed
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Thu Aug 30 17:21:51 2018 +0300
description:
Improved Object.prototype.toString for invalid values.
diffstat:
njs/njs_object.c | 35 +++++++++++++++++------------------
1 files changed, 17 insertions(+), 18 deletions(-)
diffs (63 lines):
diff -r da97609863ff -r 6931a42f5bed njs/njs_object.c
--- a/njs/njs_object.c Wed Aug 29 20:32:11 2018 +0300
+++ b/njs/njs_object.c Thu Aug 30 17:21:51 2018 +0300
@@ -1776,8 +1776,7 @@ njs_ret_t
njs_object_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
nxt_uint_t nargs, njs_index_t unused)
{
- int32_t index;
- const njs_value_t *value;
+ const njs_value_t *name;
static const njs_value_t *class_name[] = {
/* Primitives. */
@@ -1789,15 +1788,15 @@ njs_object_prototype_to_string(njs_vm_t
&njs_object_data_string,
&njs_object_exernal_string,
- &njs_string_empty,
- &njs_string_empty,
- &njs_string_empty,
- &njs_string_empty,
- &njs_string_empty,
- &njs_string_empty,
- &njs_string_empty,
- &njs_string_empty,
- &njs_string_empty,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
/* Objects. */
&njs_object_object_string,
@@ -1819,17 +1818,17 @@ njs_object_prototype_to_string(njs_vm_t
&njs_object_object_string,
};
- value = &args[0];
- index = value->type;
+ name = class_name[args[0].type];
- if (nxt_slow_path(class_name[index] == &njs_string_empty)) {
- njs_internal_error(vm, "Unknown value type");
- return NXT_ERROR;
+ if (nxt_fast_path(name != NULL)) {
+ vm->retval = *name;
+
+ return NXT_OK;
}
- vm->retval = *class_name[index];
+ njs_internal_error(vm, "Unknown value type");
- return NXT_OK;
+ return NXT_ERROR;
}
More information about the nginx-devel
mailing list