Welcome! Log In Create A New Profile

Advanced

[njs] Style and small miscellaneous fixes.

January 03, 2017 10:36AM
details: http://hg.nginx.org/njs/rev/2d9ccf739861
branches:
changeset: 292:2d9ccf739861
user: Igor Sysoev <igor@sysoev.ru>
date: Sun Jan 01 20:45:59 2017 +0300
description:
Style and small miscellaneous fixes.

diffstat:

njs/njs_array.c | 2 +-
njs/njs_parser.h | 1 -
njs/njs_string.c | 3 +-
njs/njs_string.h | 53 +++++++++++++++++++++++++----------------------
njs/njs_vm.c | 2 +-
njs/njs_vm.h | 2 +-
njs/test/njs_unit_test.c | 7 ++++++
7 files changed, 39 insertions(+), 31 deletions(-)

diffs (173 lines):

diff -r 1944eaa4b2cf -r 2d9ccf739861 njs/njs_array.c
--- a/njs/njs_array.c Tue Dec 27 10:40:08 2016 +0300
+++ b/njs/njs_array.c Sun Jan 01 20:45:59 2017 +0300
@@ -1882,7 +1882,7 @@ static const njs_object_prop_t njs_arra
NJS_OBJECT_ARG, NJS_SKIP_ARG, NJS_INTEGER_ARG),
},

- /* ES6. */
+ /* ES7. */
{
.type = NJS_METHOD,
.name = njs_string("includes"),
diff -r 1944eaa4b2cf -r 2d9ccf739861 njs/njs_parser.h
--- a/njs/njs_parser.h Tue Dec 27 10:40:08 2016 +0300
+++ b/njs/njs_parser.h Sun Jan 01 20:45:59 2017 +0300
@@ -330,7 +330,6 @@ njs_token_t njs_lexer_keyword(njs_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,
diff -r 1944eaa4b2cf -r 2d9ccf739861 njs/njs_string.c
--- a/njs/njs_string.c Tue Dec 27 10:40:08 2016 +0300
+++ b/njs/njs_string.c Sun Jan 01 20:45:59 2017 +0300
@@ -610,7 +610,6 @@ njs_string_prototype_concat(njs_vm_t *vm
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

if (nargs > 1) {
start = args[1].data.u.number;
+
if (start < length) {
-
if (start < 0) {
start += length;

diff -r 1944eaa4b2cf -r 2d9ccf739861 njs/njs_string.h
--- a/njs/njs_string.h Tue Dec 27 10:40:08 2016 +0300
+++ b/njs/njs_string.h Sun Jan 01 20:45:59 2017 +0300
@@ -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.
@@ -27,9 +28,10 @@
#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

@@ -42,30 +44,31 @@
(((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 {
diff -r 1944eaa4b2cf -r 2d9ccf739861 njs/njs_vm.c
--- a/njs/njs_vm.c Tue Dec 27 10:40:08 2016 +0300
+++ b/njs/njs_vm.c Sun Jan 01 20:45:59 2017 +0300
@@ -3357,7 +3357,7 @@ njs_value_string_copy(njs_vm_t *vm, nxt_


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;
diff -r 1944eaa4b2cf -r 2d9ccf739861 njs/njs_vm.h
--- a/njs/njs_vm.h Tue Dec 27 10:40:08 2016 +0300
+++ b/njs/njs_vm.h Sun Jan 01 20:45:59 2017 +0300
@@ -1016,7 +1016,7 @@ njs_ret_t njs_value_to_ext_string(njs_vm
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);
diff -r 1944eaa4b2cf -r 2d9ccf739861 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Tue Dec 27 10:40:08 2016 +0300
+++ b/njs/test/njs_unit_test.c Sun Jan 01 20:45:59 2017 +0300
@@ -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") },

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

[njs] Style and small miscellaneous fixes.

Igor Sysoev 823 January 03, 2017 10:36AM



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

Online Users

Guests: 299
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