From 43bada0f3ba31353cf204d9e5b2daeacd1120b4f Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Sun, 27 Dec 2015 15:26:04 +0300 Subject: [PATCH] Style and small miscellaneous fixes. --- njs/njs_function.h | 2 +- njs/njs_generator.c | 2 +- njs/njs_vm.c | 20 ++++++++++---------- njs/test/njs_unit_test.c | 13 +++++++++++-- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/njs/njs_function.h b/njs/njs_function.h index f30848bd..1575bddd 100644 --- a/njs/njs_function.h +++ b/njs/njs_function.h @@ -30,7 +30,7 @@ struct njs_function_lambda_s { #define NJS_FRAME_SIZE \ nxt_align_size(sizeof(njs_frame_t), sizeof(njs_value_t)) -/* The retval and return_address fields are not used in the global frame. */ +/* The retval field are not used in the global frame. */ #define NJS_GLOBAL_FRAME_SIZE \ nxt_align_size(offsetof(njs_frame_t, retval), sizeof(njs_value_t)) diff --git a/njs/njs_generator.c b/njs/njs_generator.c index f40e493f..25992f8f 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -567,7 +567,7 @@ njs_generate_switch_statement(njs_vm_t *vm, njs_parser_t *parser, } patch = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_parser_patch_t)); + sizeof(njs_parser_patch_t)); if (nxt_slow_path(patch == NULL)) { return NXT_ERROR; } diff --git a/njs/njs_vm.c b/njs/njs_vm.c index 27b781cd..568dc9dd 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -2279,10 +2279,10 @@ njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval) vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = vm->frame->arguments; retval = njs_vmcode_operand(vm, retval); - /* - * GC: value external/internal++ depending - * on vm->retval and retval type - */ + /* + * GC: value external/internal++ depending + * on vm->retval and retval type + */ *retval = vm->retval; } else if (ret == NJS_APPLIED) { @@ -2496,7 +2496,7 @@ njs_vmcode_finally(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval) } -njs_ret_t +static njs_ret_t njs_vmcode_number_primitive(njs_vm_t *vm, njs_value_t *invld, njs_value_t *narg) { double num; @@ -2527,7 +2527,7 @@ njs_vmcode_number_primitive(njs_vm_t *vm, njs_value_t *invld, njs_value_t *narg) } -njs_ret_t +static njs_ret_t njs_vmcode_string_primitive(njs_vm_t *vm, njs_value_t *invld, njs_value_t *narg) { njs_ret_t ret; @@ -2713,10 +2713,10 @@ static const njs_vmcode_1addr_t njs_trap_number[] = { static const njs_vm_trap_t njs_vm_traps[] = { /* NJS_TRAP_PROPERTY */ { &njs_trap_strings[1], 0 }, - /* NJS_TRAP_STRINGS */ { &njs_trap_strings[0], 0 }, - /* NJS_TRAP_INCDEC */ { &njs_trap_numbers[1], 1 }, - /* NJS_TRAP_NUMBERS */ { &njs_trap_numbers[0], 0 }, - /* NJS_TRAP_NUMBER */ { &njs_trap_number[0], 0 }, + /* NJS_TRAP_STRINGS */ { &njs_trap_strings[0], 0 }, + /* NJS_TRAP_INCDEC */ { &njs_trap_numbers[1], 1 }, + /* NJS_TRAP_NUMBERS */ { &njs_trap_numbers[0], 0 }, + /* NJS_TRAP_NUMBER */ { &njs_trap_number[0], 0 }, }; diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 9371557e..3cfb91e0 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -2689,11 +2689,20 @@ static njs_unit_test_t njs_test[] = { nxt_string("a = (function(a) { return a + 1 }(2)); a"), nxt_string("3") }, + { nxt_string("a = +function(a) { return a + 1 }(2); a"), + nxt_string("3") }, + + { nxt_string("a = -function(a) { return a + 1 }(2); a"), + nxt_string("-3") }, + { nxt_string("a = !function(a) { return a + 1 }(2); a"), nxt_string("false") }, - { nxt_string("a = +function(a) { return a + 1 }(2); a"), - nxt_string("3") }, + { nxt_string("a = ~function(a) { return a + 1 }(2); a"), + nxt_string("-4") }, + + { nxt_string("a = void function(a) { return a + 1 }(2); a"), + nxt_string("undefined") }, { nxt_string("a = true && function(a) { return a + 1 }(2); a"), nxt_string("3") }, -- 2.47.3