[njs] Fixed typeof for object_value type.

Dmitry Volyntsev xeioex at nginx.com
Thu Nov 22 17:07:03 UTC 2018


details:   https://hg.nginx.org/njs/rev/ec82852f909a
branches:  
changeset: 668:ec82852f909a
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Nov 22 19:32:48 2018 +0300
description:
Fixed typeof for object_value type.

diffstat:

 njs/njs_object.c         |  2 +-
 njs/njs_vm.c             |  3 ++-
 njs/njs_vm.h             |  1 +
 njs/test/njs_unit_test.c |  8 +++++++-
 4 files changed, 11 insertions(+), 3 deletions(-)

diffs (68 lines):

diff -r 82cbeec8fd19 -r ec82852f909a njs/njs_object.c
--- a/njs/njs_object.c	Thu Nov 22 18:55:32 2018 +0300
+++ b/njs/njs_object.c	Thu Nov 22 19:32:48 2018 +0300
@@ -2098,7 +2098,7 @@ njs_object_prototype_to_string(njs_vm_t 
 {
     const njs_value_t  *name;
 
-    static const njs_value_t  *class_name[] = {
+    static const njs_value_t  *class_name[NJS_TYPE_MAX] = {
         /* Primitives. */
         &njs_object_null_string,
         &njs_object_undefined_string,
diff -r 82cbeec8fd19 -r ec82852f909a njs/njs_vm.c
--- a/njs/njs_vm.c	Thu Nov 22 18:55:32 2018 +0300
+++ b/njs/njs_vm.c	Thu Nov 22 19:32:48 2018 +0300
@@ -1024,7 +1024,7 @@ njs_vmcode_typeof(njs_vm_t *vm, njs_valu
 
     /* ECMAScript 5.1: null, array and regexp are objects. */
 
-    static const njs_value_t  *types[] = {
+    static const njs_value_t  *types[NJS_TYPE_MAX] = {
         &njs_string_object,
         &njs_string_void,
         &njs_string_boolean,
@@ -1058,6 +1058,7 @@ njs_vmcode_typeof(njs_vm_t *vm, njs_valu
         &njs_string_object,
         &njs_string_object,
         &njs_string_object,
+        &njs_string_object,
     };
 
     /* A zero index means non-declared variable. */
diff -r 82cbeec8fd19 -r ec82852f909a njs/njs_vm.h
--- a/njs/njs_vm.h	Thu Nov 22 18:55:32 2018 +0300
+++ b/njs/njs_vm.h	Thu Nov 22 19:32:48 2018 +0300
@@ -134,6 +134,7 @@ typedef enum {
     NJS_OBJECT_TYPE_ERROR     = 0x1e,
     NJS_OBJECT_URI_ERROR      = 0x1f,
     NJS_OBJECT_VALUE          = 0x20,
+#define NJS_TYPE_MAX         (NJS_OBJECT_VALUE + 1)
 } njs_value_type_t;
 
 
diff -r 82cbeec8fd19 -r ec82852f909a njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Thu Nov 22 18:55:32 2018 +0300
+++ b/njs/test/njs_unit_test.c	Thu Nov 22 19:32:48 2018 +0300
@@ -10302,7 +10302,10 @@ static njs_unit_test_t  njs_test[] =
                  "h.update('A').digest('hex'); h.update('B')"),
       nxt_string("Error: Digest already called") },
 
-    /* require('crypto').createHash() */
+    { nxt_string("typeof require('crypto').createHash('md5')"),
+      nxt_string("object") },
+
+    /* require('crypto').createHmac() */
 
     { nxt_string("require('crypto').createHmac('sha1', '')"),
       nxt_string("[object Hmac]") },
@@ -10411,6 +10414,9 @@ static njs_unit_test_t  njs_test[] =
                  "h.update('A').digest('hex'); h.update('B')"),
       nxt_string("Error: Digest already called") },
 
+    { nxt_string("typeof require('crypto').createHmac('md5', 'a')"),
+      nxt_string("object") },
+
     /* setTimeout(). */
 
     { nxt_string("setTimeout()"),


More information about the nginx-devel mailing list