mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Introducing ecma_MakeReference and ecma_FreeReference, moving ecma_OpGetIdentifierReference to libecmaoperations/ecma-reference.c.
This commit is contained in:
parent
60063683aa
commit
b72185696a
@ -18,7 +18,6 @@
|
||||
*/
|
||||
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-operations.h"
|
||||
@ -30,49 +29,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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) )
|
||||
{
|
||||
ecma_RefObject( lex_env_iter_p);
|
||||
|
||||
return (ecma_Reference_t) { .base = ecma_MakeObjectValue( lex_env_iter_p),
|
||||
.referenced_name_p = name_p,
|
||||
.is_strict = is_strict };
|
||||
}
|
||||
|
||||
lex_env_iter_p = ecma_GetPointer( lex_env_iter_p->u.m_LexicalEnvironment.m_pOuterReference);
|
||||
}
|
||||
|
||||
return (ecma_Reference_t) { .base = ecma_MakeSimpleValue( ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
.referenced_name_p = NULL,
|
||||
.is_strict = is_strict };
|
||||
} /* ecma_OpGetIdentifierReference */
|
||||
|
||||
/**
|
||||
* GetValue operation.
|
||||
*
|
||||
|
||||
108
src/libecmaoperations/ecma-reference.c
Normal file
108
src/libecmaoperations/ecma-reference.c
Normal file
@ -0,0 +1,108 @@
|
||||
/* 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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
40
src/libecmaoperations/ecma-reference.h
Normal file
40
src/libecmaoperations/ecma-reference.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef ECMA_REFERENCE_H
|
||||
#define ECMA_REFERENCE_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "globals.h"
|
||||
|
||||
/** \addtogroup ecma ---TODO---
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup references ECMA-Reference
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_Reference_t ecma_OpGetIdentifierReference(ecma_Object_t *lex_env_p, ecma_Char_t *name_p, bool is_strict);
|
||||
extern ecma_Reference_t ecma_MakeReference( ecma_Value_t base, ecma_Char_t *name_p, bool is_strict);
|
||||
extern void ecma_FreeReference( const ecma_Reference_t ref);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_REFERENCE_H */
|
||||
Loading…
x
Reference in New Issue
Block a user