From 068a00ea8bbf57ffa7b6e5f3c9426e51e7b8a1ef Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Sat, 25 Mar 2017 13:42:40 +0300 Subject: [PATCH] The "typeof" operation changes. --- njs/njs_variable.c | 19 +++---------------- njs/njs_vm.c | 7 ++++++- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/njs/njs_variable.c b/njs/njs_variable.c index 9a5e5947..7cc48bfc 100644 --- a/njs/njs_variable.c +++ b/njs/njs_variable.c @@ -176,14 +176,12 @@ njs_variable_t * njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node, njs_name_reference_t reference) { - nxt_int_t ret; nxt_array_t *values; njs_index_t index; njs_value_t *value; njs_variable_t *var; njs_parser_scope_t *scope, *parent, *inclusive; nxt_lvlhsh_query_t lhq; - const njs_value_t *initial; lhq.key_hash = node->variable_name_hash; lhq.key = node->u.variable_name; @@ -209,8 +207,6 @@ njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node, } } - initial = &njs_value_void; - goto found; } @@ -229,23 +225,14 @@ njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node, goto not_found; } - /* Add variable referenced by typeof to the global scope. */ - var = njs_variable_alloc(vm, &lhq.key, NJS_VARIABLE_TYPEOF); if (nxt_slow_path(var == NULL)) { return NULL; } - lhq.replace = 0; - lhq.value = var; - lhq.pool = vm->mem_cache_pool; + var->index = NJS_INDEX_NONE; - ret = nxt_lvlhsh_insert(&scope->variables, &lhq); - if (nxt_slow_path(ret != NXT_OK)) { - return NULL; - } - - initial = &njs_value_invalid; + return var; found: @@ -285,7 +272,7 @@ found: *value = var->value; } else { - *value = *initial; + *value = njs_value_void; } index = scope->next_index; diff --git a/njs/njs_vm.c b/njs/njs_vm.c index c926d5b1..7b15e8f5 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -1444,6 +1444,8 @@ njs_vmcode_post_decrement(njs_vm_t *vm, njs_value_t *reference, njs_ret_t njs_vmcode_typeof(njs_vm_t *vm, njs_value_t *value, njs_value_t *invld) { + nxt_uint_t type; + /* ECMAScript 5.1: null, array and regexp are objects. */ static const njs_value_t *types[] = { @@ -1466,7 +1468,10 @@ njs_vmcode_typeof(njs_vm_t *vm, njs_value_t *value, njs_value_t *invld) &njs_string_object, }; - vm->retval = *types[value->type]; + /* A zero index means non-declared variable. */ + type = (value != NULL) ? value->type : NJS_VOID; + + vm->retval = *types[type]; return sizeof(njs_vmcode_2addr_t); } -- 2.47.3