]> git.kaiwu.me - njs.git/commitdiff
Style and small miscellaneous fixes.
authorIgor Sysoev <igor@sysoev.ru>
Sun, 1 Jan 2017 17:45:59 +0000 (20:45 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Sun, 1 Jan 2017 17:45:59 +0000 (20:45 +0300)
njs/njs_array.c
njs/njs_parser.h
njs/njs_string.c
njs/njs_string.h
njs/njs_vm.c
njs/njs_vm.h
njs/test/njs_unit_test.c

index c25f6cd11d1272df7fabe550abdbc394365cb2fd..05c6f9129b4858d21613df997decf780dc875e77 100644 (file)
@@ -1882,7 +1882,7 @@ static const njs_object_prop_t  njs_array_prototype_properties[] =
                      NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_INTEGER_ARG),
     },
 
-    /* ES6. */
+    /* ES7. */
     {
         .type = NJS_METHOD,
         .name = njs_string("includes"),
index 2f142bb2f7fa8750d357b3571e1ea50f5e2c0834..902124aba3d89ef57b58365ce2994189af04d1b6 100644 (file)
@@ -330,7 +330,6 @@ njs_token_t njs_lexer_keyword(njs_lexer_t *lexer);
 njs_extern_t *njs_parser_external(njs_vm_t *vm, njs_parser_t *parser);
 
 njs_parser_node_t *njs_parser(njs_vm_t *vm, njs_parser_t *parser);
-njs_parser_node_t *njs_nonrecursive_parser(njs_vm_t *vm, njs_parser_t *parser);
 njs_token_t njs_parser_arguments(njs_vm_t *vm, njs_parser_t *parser,
     njs_parser_node_t *parent);
 njs_token_t njs_parser_expression(njs_vm_t *vm, njs_parser_t *parser,
index 29a014c45189ed6a53a51d5a93e635d9ae27228b..95a48cce77bc759c3c0005bb1977255bdf10a05b 100644 (file)
@@ -610,7 +610,6 @@ njs_string_prototype_concat(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     length &= mask;
 
     start = njs_string_alloc(vm, &vm->retval, size, length);
-
     if (nxt_slow_path(start == NULL)) {
         return NXT_ERROR;
     }
@@ -903,8 +902,8 @@ njs_string_prototype_substr(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
     if (nargs > 1) {
         start = args[1].data.u.number;
-        if (start < length) {
 
+        if (start < length) {
             if (start < 0) {
                 start += length;
 
index f731837aea010d690253985495b9e757a5633859..e8298533dc05fccb74eb0d995274879b7f6d7cf6 100644 (file)
@@ -12,8 +12,9 @@
 /*
  * nJSVM supports two string variants:
  *
- * 1) short strings which size is lesser than 14 bytes, these strings are
- *    stored inside njs_value_t (see njs_vm.h for details);
+ * 1) short strings which size is less than or equal to 14 (NJS_STRING_SHORT)
+ *    bytes, these strings are stored inside  njs_value_t (see njs_vm.h for
+ *    details);
  *
  * 2) and long strings using additional njs_string_t structure.
  *    This structure has the start field to support external strings.
 #define NJS_STRING_MAX_LENGTH  0x7fffffff
 
 /*
- * Should be power of two to use shift and binary and operations instead of
- * division and remainder operations but no less than 16 because the maximum
- * length of short string inlined in njs_value_t is less than 16 bytes.
+ * NJS_STRING_MAP_STRIDE should be power of two to use shift and binary
+ * AND operations instead of division and remainder operations but no
+ * less than 16 because the maximum length of short string inlined in
+ * njs_value_t is less than 16 bytes.
  */
 #define NJS_STRING_MAP_STRIDE  32
 
     (((length - 1) / NJS_STRING_MAP_STRIDE) * sizeof(uint32_t))
 
 /*
- * The JavaScript standard states that strings are stored in UTF-16.
- * nJSVM allows to store any byte sequences in strings.  A size of the
- * string in bytes is stored in the size field.  If a byte sequence is
- * valid UTF-8 string then its length is stored in the UTF-8 length field.
- * Otherwise, the length field is zero.  If a string is UTF-8 string then
- * string functions work with UTF-8 characters positions and lengths.
- * Othersise they work with byte positions and lengths.  Using UTF-8
- * encoding does not allow to get quickly a character at specified position.
- * To speed up this search a map of offsets is stored after the UTF-8 string.
- * The map is aligned to uint32_t and contains byte positions of each
- * NJS_STRING_MAP_STRIDE UTF-8 character except zero position.  The map
- * can be initialized on demand.  If a string come outside JavaScript as
- * byte sequnece just to be concatenated or to be used in regular expressions
- * the offset map is not required.
+ * ECMAScript strings are stored in UTF-16.  nJSVM however, allows to store
+ * any byte sequences in strings.  A size of string in bytes is stored in the
+ * size field.  If byte sequence is valid UTF-8 string then its length is
+ * stored in the UTF-8 length field.  Otherwise, the length field is zero.
+ * If a string is UTF-8 string then string functions use UTF-8 characters
+ * positions and lengths.  Otherwise they use with byte positions and lengths.
+ * Using UTF-8 encoding does not allow to get quickly a character at specified
+ * position.  To speed up this search a map of offsets is stored after the
+ * UTF-8 string.  The map is aligned to uint32_t and contains byte positions
+ * of each NJS_STRING_MAP_STRIDE UTF-8 character except zero position.  The
+ * map can be initialized on demand.  Unitialized map is marked with zero
+ * value in the first map element.  If string comes outside JavaScript as
+ * byte string just to be concatenated or to match regular expressions the
+ * offset map is not required.
  *
  * The map is not allocated:
- * 1) if the length is zero hence it is a byte string;
- * 2) if the size and length are equal so the string contains only ASCII
- *    characters map is not required;
- * 3) if the length is less than NJS_STRING_MAP_STRIDE.
+ * 1) if string length is zero hence string is a byte string;
+ * 2) if string size and length are equal so the string contains only
+ *    ASCII characters and map is not required;
+ * 3) if string length is less than NJS_STRING_MAP_STRIDE.
  *
  * The current implementation does not support Unicode surrogate pairs.
- * If offset in map points to surrogate pair then the previous offset
- * should be used and so on until start of the string.
+ * It can be implemented later if it will be required using the following
+ * algorithm: if offset in map points to surrogate pair then the previous
+ * offset should be used and so on until start of the string.
  */
 
 struct njs_string_s {
index 72394c008341380ea1e5619c8c7b18abf63931de..d8a5236e4163d58cc05398937011035b1301fa71 100644 (file)
@@ -3357,7 +3357,7 @@ njs_value_string_copy(njs_vm_t *vm, nxt_str_t *retval, njs_value_t *value,
 
 
 void
-njs_vm_throw_exception(njs_vm_t *vm, u_char *buf, uint32_t size)
+njs_vm_throw_exception(njs_vm_t *vm, const u_char *buf, uint32_t size)
 {
     int32_t      length;
     njs_value_t  *value;
index f7bf38c4a53f4a470d278265a53ec7230f035a65..ba65a43c62645a7518c9c2975b96738cd0df3941 100644 (file)
@@ -1016,7 +1016,7 @@ njs_ret_t njs_value_to_ext_string(njs_vm_t *vm, nxt_str_t *dst,
     const njs_value_t *src);
 void njs_number_set(njs_value_t *value, double num);
 
-void njs_vm_throw_exception(njs_vm_t *vm, u_char *buf, uint32_t size);
+void njs_vm_throw_exception(njs_vm_t *vm, const u_char *buf, uint32_t size);
 
 nxt_int_t njs_builtin_objects_create(njs_vm_t *vm);
 nxt_int_t njs_builtin_objects_clone(njs_vm_t *vm);
index e4eb3b2ff15214240b510ab4c5685850cac93370..6e84d1d9bb2298e14b601d4797c3135c536de5a4 100644 (file)
@@ -626,6 +626,8 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("x = '1'; +x + 2"),
       nxt_string("3") },
 
+    /* Weird things. */
+
     { nxt_string("'3' -+-+-+ '1' + '1' / '3' * '6' + '2'"),
       nxt_string("42") },
 
@@ -641,6 +643,11 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("!--[][1]"),
       nxt_string("true") },
 
+    { nxt_string("[].concat[1,2,3]"),
+      nxt_string("undefined") },
+
+    /**/
+
     { nxt_string("'true' == true"),
       nxt_string("false") },