njs_generate_global_reference(njs_vm_t *vm, njs_generator_t *generator,
    njs_parser_node_t *node, njs_bool_t exception)
{
    ssize_t                  length;
    njs_int_t                ret;
    njs_index_t              index;
    njs_value_t              property;
    njs_vmcode_prop_get_t    *prop_get;
    const njs_lexer_entry_t  *lex_entry;

    index = njs_generate_temp_index_get(vm, generator, node);
    if (njs_slow_path(index == NJS_INDEX_ERROR)) {
        return NJS_ERROR;
    }

    njs_generate_code(generator, njs_vmcode_prop_get_t, prop_get,
                 exception ? NJS_VMCODE_GLOBAL_GET: NJS_VMCODE_PROPERTY_GET,
                 3, node);

    prop_get->value = index;

    prop_get->object = njs_scope_global_this_index();
    if (njs_slow_path(prop_get->object == NJS_INDEX_ERROR)) {
        return NJS_ERROR;
    }

    lex_entry = njs_lexer_entry(node->u.reference.unique_id);
    if (njs_slow_path(lex_entry == NULL)) {
        return NJS_ERROR;
    }

    length = njs_utf8_length(lex_entry->name.start, lex_entry->name.length);
    if (njs_slow_path(length < 0)) {
        return NJS_ERROR;
    }

    ret = njs_string_new(vm, &property, lex_entry->name.start,
                         lex_entry->name.length, length);
    if (njs_slow_path(ret != NJS_OK)) {
        return NJS_ERROR;
    }

    prop_get->property = njs_scope_global_index(vm, &property,
                                                generator->runtime);
    if (njs_slow_path(prop_get->property == NJS_INDEX_ERROR)) {
        return NJS_ERROR;
    }

    node->index = index;

    if (!exception) {
        return NJS_OK;
    }

    return njs_generate_reference_error(vm, generator, node);
}
njs_generate_global_reference(njs_vm_t *vm, njs_generator_t *generator,
    njs_parser_node_t *node, njs_bool_t exception)
{
    ssize_t                  length;
    njs_int_t                ret;
    njs_index_t              index;
    njs_value_t              property;
    njs_vmcode_prop_get_t    *prop_get;
    const njs_lexer_entry_t  *lex_entry;

    index = njs_generate_temp_index_get(vm, generator, node);
    if (njs_slow_path(index == NJS_INDEX_ERROR)) {
        return NJS_ERROR;
    }

    njs_generate_code(generator, njs_vmcode_prop_get_t, prop_get,
                 exception ? NJS_VMCODE_GLOBAL_GET: NJS_VMCODE_PROPERTY_GET,
                 3, node);

    prop_get->value = index;

    prop_get->object = njs_scope_global_this_index();
    if (njs_slow_path(prop_get->object == NJS_INDEX_ERROR)) {
        return NJS_ERROR;
    }

    lex_entry = njs_lexer_entry(node->u.reference.unique_id);
    if (njs_slow_path(lex_entry == NULL)) {
        return NJS_ERROR;
    }

    length = njs_utf8_length(lex_entry->name.start, lex_entry->name.length);
    if (njs_slow_path(length < 0)) {
        return NJS_ERROR;
    }

    ret = njs_string_new(vm, &property, lex_entry->name.start,
                         lex_entry->name.length, length);
    if (njs_slow_path(ret != NJS_OK)) {
        return NJS_ERROR;
    }

    prop_get->property = njs_scope_global_index(vm, &property,
                                                generator->runtime);
    if (njs_slow_path(prop_get->property == NJS_INDEX_ERROR)) {
        return NJS_ERROR;
    }

    node->index = index;

    if (!exception) {
        return NJS_OK;
    }

    return njs_generate_reference_error(vm, generator, node);
}