<commit_before>/* Copyright 2014 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-lex-env.h"
#include "ecma-reference.h"
#include "globals.h"

/** \addtogroup ecma ---TODO---
 * @{
 */

/**
 * \addtogroup references ECMA-Reference
 * @{
 */

/**
 * Resolve syntactic reference to ECMA-reference.
 *
 * Warning: string pointed by name_p
 *          must not be freed or reused
 *          until the reference is freed.
 *
 * @return ECMA-reference (if base value is an object, upon return
 *         it's reference counter is increased by one).
 */
ecma_Reference_t
ecma_OpGetIdentifierReference(ecma_Object_t *lex_env_p, /**< lexical environment */
                              ecma_Char_t *name_p, /**< identifier's name */
                              bool is_strict) /**< strict reference flag */
{
  JERRY_ASSERT( lex_env_p != NULL );

  ecma_Object_t *lex_env_iter_p = lex_env_p;

  while ( lex_env_iter_p != NULL )
  {
    ecma_CompletionValue_t completion_value;
    completion_value = ecma_OpHasBinding( lex_env_iter_p, name_p);

    JERRY_ASSERT( completion_value.type == ECMA_COMPLETION_TYPE_NORMAL );

    if ( ecma_IsValueTrue( completion_value.value) )
    {
      return ecma_MakeReference( ecma_MakeObjectValue( lex_env_iter_p),
                                 name_p,
                                 is_strict);
    }

    lex_env_iter_p = ecma_GetPointer( lex_env_iter_p->u.m_LexicalEnvironment.m_pOuterReference);
  }

  return ecma_MakeReference( ecma_MakeSimpleValue( ECMA_SIMPLE_VALUE_UNDEFINED),
                             name_p,
                             is_strict);
} /* ecma_OpGetIdentifierReference */

/**
 * ECMA-reference constructor.
 *
 * Warning: string pointed by name_p
 *          must not be freed or reused
 *          until the reference is freed.
 *
 * @return ECMA-reference (if base_p it not NULL, then upon return
 *         corresponding object's reference counter is increased by one).
 */
ecma_Reference_t
ecma_MakeReference(ecma_Value_t base, /**< base value */
                   ecma_Char_t *name_p, /**< referenced name */
                   bool is_strict) /**< strict reference flag */
{
  return (ecma_Reference_t) { .base = ecma_CopyValue( base),
                              .referenced_name_p = name_p,
                              .is_strict = is_strict };
} /* ecma_MakeReference */

/**
 * Free specified ECMA-reference.
 *
 * Warning:
 *         after freeing all copy of the reference become invalid.
 */
void
ecma_FreeReference( const ecma_Reference_t ref) /**< reference */
{
  ecma_FreeValue( ref.base);
} /* ecma_FreeReference */

/**
 * @}
 * @}
 */
<commit_msg>Fixing assertion in ecma_OpGetIdentifierReference.<commit_after>/* Copyright 2014 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-lex-env.h"
#include "ecma-reference.h"
#include "globals.h"

/** \addtogroup ecma ---TODO---
 * @{
 */

/**
 * \addtogroup references ECMA-Reference
 * @{
 */

/**
 * Resolve syntactic reference to ECMA-reference.
 *
 * Warning: string pointed by name_p
 *          must not be freed or reused
 *          until the reference is freed.
 *
 * @return ECMA-reference (if base value is an object, upon return
 *         it's reference counter is increased by one).
 */
ecma_Reference_t
ecma_OpGetIdentifierReference(ecma_Object_t *lex_env_p, /**< lexical environment */
                              ecma_Char_t *name_p, /**< identifier's name */
                              bool is_strict) /**< strict reference flag */
{
  JERRY_ASSERT( lex_env_p != NULL );

  ecma_Object_t *lex_env_iter_p = lex_env_p;

  while ( lex_env_iter_p != NULL )
  {
    ecma_CompletionValue_t completion_value;
    completion_value = ecma_OpHasBinding( lex_env_iter_p, name_p);

    JERRY_ASSERT( ecma_IsCompletionValueNormalBoolean( completion_value) );

    if ( ecma_IsValueTrue( completion_value.value) )
    {
      return ecma_MakeReference( ecma_MakeObjectValue( lex_env_iter_p),
                                 name_p,
                                 is_strict);
    }

    lex_env_iter_p = ecma_GetPointer( lex_env_iter_p->u.m_LexicalEnvironment.m_pOuterReference);
  }

  return ecma_MakeReference( ecma_MakeSimpleValue( ECMA_SIMPLE_VALUE_UNDEFINED),
                             name_p,
                             is_strict);
} /* ecma_OpGetIdentifierReference */

/**
 * ECMA-reference constructor.
 *
 * Warning: string pointed by name_p
 *          must not be freed or reused
 *          until the reference is freed.
 *
 * @return ECMA-reference (if base_p it not NULL, then upon return
 *         corresponding object's reference counter is increased by one).
 */
ecma_Reference_t
ecma_MakeReference(ecma_Value_t base, /**< base value */
                   ecma_Char_t *name_p, /**< referenced name */
                   bool is_strict) /**< strict reference flag */
{
  return (ecma_Reference_t) { .base = ecma_CopyValue( base),
                              .referenced_name_p = name_p,
                              .is_strict = is_strict };
} /* ecma_MakeReference */

/**
 * Free specified ECMA-reference.
 *
 * Warning:
 *         after freeing all copy of the reference become invalid.
 */
void
ecma_FreeReference( const ecma_Reference_t ref) /**< reference */
{
  ecma_FreeValue( ref.base);
} /* ecma_FreeReference */

/**
 * @}
 * @}
 */

{'fraction_non_alphanumeric': 0.09758321933424532, 'fraction_numerical': 0.0024319805441556466, 'mean_word_length': 2.574144486692015, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1067949', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1951, 'n_words': 551}