Fixing value copying/value leakage issues.

This commit is contained in:
Ruben Ayrapetyan
2014-07-21 17:39:39 +04:00
parent 0ff6d7ae9e
commit 1175526d52
7 changed files with 80 additions and 17 deletions
@@ -33,6 +33,9 @@
* GetValue operation.
*
* See also: ECMA-262 v5, 8.7.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_CompletionValue_t
ecma_OpGetValue( ecma_Reference_t *ref_p) /**< ECMA-reference */
@@ -106,6 +109,9 @@ ecma_OpGetValue( ecma_Reference_t *ref_p) /**< ECMA-reference */
* SetValue operation.
*
* See also: ECMA-262 v5, 8.7.1
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_CompletionValue_t
ecma_OpSetValue(ecma_Reference_t *ref_p, /**< ECMA-reference */
+27 -5
View File
@@ -32,6 +32,10 @@
* HasBinding operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Return value is simple and so need not be freed.
* However, ecma_free_completion_value may be called for it, but it is a no-op.
*/
ecma_CompletionValue_t
ecma_OpHasBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
@@ -67,6 +71,10 @@ ecma_OpHasBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
* CreateMutableBinding operation.
*
* see also: ecma-262 v5, 10.2.1
*
* @return completion value
* Return value is simple and so need not be freed.
* However, ecma_free_completion_value may be called for it, but it is a no-op.
*/
ecma_CompletionValue_t
ecma_OpCreateMutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
@@ -107,6 +115,9 @@ ecma_OpCreateMutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment *
* SetMutableBinding operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_CompletionValue_t
ecma_OpSetMutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
@@ -127,7 +138,8 @@ ecma_OpSetMutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
if ( property_p->u.m_NamedDataProperty.m_Writable == ECMA_PROPERTY_WRITABLE )
{
property_p->u.m_NamedDataProperty.m_Value = value;
ecma_FreeValue( property_p->u.m_NamedDataProperty.m_Value);
property_p->u.m_NamedDataProperty.m_Value = ecma_CopyValue( value);
} else if ( is_strict )
{
return ecma_MakeThrowValue( ecma_NewStandardError( ECMA_ERROR_TYPE));
@@ -150,6 +162,9 @@ ecma_OpSetMutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
* GetBindingValue operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_CompletionValue_t
ecma_OpGetBindingValue(ecma_Object_t *lex_env_p, /**< lexical environment */
@@ -173,7 +188,7 @@ ecma_OpGetBindingValue(ecma_Object_t *lex_env_p, /**< lexical environment */
if ( property_p->u.m_NamedDataProperty.m_Writable == ECMA_PROPERTY_WRITABLE )
{
return ecma_MakeCompletionValue( ECMA_COMPLETION_TYPE_NORMAL,
prop_value,
ecma_CopyValue( prop_value),
ECMA_TARGET_ID_RESERVED);
} else if ( prop_value.m_ValueType == ECMA_TYPE_SIMPLE
&& prop_value.m_Value == ECMA_SIMPLE_VALUE_EMPTY )
@@ -205,6 +220,10 @@ ecma_OpGetBindingValue(ecma_Object_t *lex_env_p, /**< lexical environment */
* DeleteBinding operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Return value is simple and so need not be freed.
* However, ecma_free_completion_value may be called for it, but it is a no-op.
*/
ecma_CompletionValue_t
ecma_OpDeleteBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
@@ -255,6 +274,9 @@ ecma_OpDeleteBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
* ImplicitThisValue operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_CompletionValue_t
ecma_OpImplicitThisValue( ecma_Object_t *lex_env_p) /**< lexical environment */
@@ -283,7 +305,7 @@ ecma_OpImplicitThisValue( ecma_Object_t *lex_env_p) /**< lexical environment */
*
* See also: ECMA-262 v5, 10.2.1
*/
ecma_CompletionValue_t
void
ecma_OpCreateImmutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
ecma_Char_t *name_p) /**< argument N */
{
@@ -323,7 +345,7 @@ ecma_OpCreateImmutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment
*
* See also: ECMA-262 v5, 10.2.1
*/
ecma_CompletionValue_t
void
ecma_OpInitializeImmutableBinding(ecma_Object_t *lex_env_p, /**< lexical environment */
ecma_Char_t *name_p, /**< argument N */
ecma_Value_t value) /**< argument V */
@@ -343,7 +365,7 @@ ecma_OpInitializeImmutableBinding(ecma_Object_t *lex_env_p, /**< lexical environ
&& prop_p->u.m_NamedDataProperty.m_Value.m_ValueType == ECMA_TYPE_SIMPLE
&& prop_p->u.m_NamedDataProperty.m_Value.m_Value == ECMA_SIMPLE_VALUE_EMPTY );
prop_p->u.m_NamedDataProperty.m_Value = value;
prop_p->u.m_NamedDataProperty.m_Value = ecma_CopyValue( value);
}
case ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND:
{
+2 -2
View File
@@ -37,8 +37,8 @@ extern ecma_CompletionValue_t ecma_OpDeleteBinding( ecma_Object_t *lex_env_p, ec
extern ecma_CompletionValue_t ecma_OpImplicitThisValue( ecma_Object_t *lex_env_p);
/* ECMA-262 v5, Table 18. Additional methods of Declarative Environment Records */
extern ecma_CompletionValue_t ecma_OpCreateImmutableBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p);
extern ecma_CompletionValue_t ecma_OpInitializeImmutableBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p, ecma_Value_t value);
extern void ecma_OpCreateImmutableBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p);
extern void ecma_OpInitializeImmutableBinding( ecma_Object_t *lex_env_p, ecma_Char_t *name_p, ecma_Value_t value);
/**
* @}
+5 -5
View File
@@ -36,8 +36,8 @@
* 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).
* @return ECMA-reference
* Returned value must be freed through ecma_FreeReference.
*/
ecma_Reference_t
ecma_OpGetIdentifierReference(ecma_Object_t *lex_env_p, /**< lexical environment */
@@ -78,8 +78,8 @@ ecma_OpGetIdentifierReference(ecma_Object_t *lex_env_p, /**< lexical environment
* 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).
* @return ECMA-reference
* Returned value must be freed through ecma_FreeReference.
*/
ecma_Reference_t
ecma_MakeReference(ecma_Value_t base, /**< base value */
@@ -95,7 +95,7 @@ ecma_MakeReference(ecma_Value_t base, /**< base value */
* Free specified ECMA-reference.
*
* Warning:
* after freeing all copy of the reference become invalid.
* freeing invalidates all copies of the reference.
*/
void
ecma_FreeReference( const ecma_Reference_t ref) /**< reference */