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;
}
}
- initial = &njs_value_void;
-
goto found;
}
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:
*value = var->value;
} else {
- *value = *initial;
+ *value = njs_value_void;
}
index = scope->next_index;
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[] = {
&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);
}