Partially implementing ECMA 'Absract equality comparison' (11.9.3).
This commit is contained in:
@@ -603,6 +603,19 @@ ecma_DuplicateEcmaString( ecma_ArrayFirstChunk_t *pFirstChunk) /**< first chunk
|
|||||||
return pFirstChunkCopy;
|
return pFirstChunkCopy;
|
||||||
} /* ecma_DuplicateEcmaString */
|
} /* ecma_DuplicateEcmaString */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare zero-terminated string to ecma-string
|
||||||
|
*
|
||||||
|
* @return true - if strings are equal;
|
||||||
|
* false - otherwise.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
ecma_CompareEcmaStringToEcmaString(const ecma_ArrayFirstChunk_t *string1_p, /* ecma-string */
|
||||||
|
const ecma_ArrayFirstChunk_t *string2_p) /* ecma-string */
|
||||||
|
{
|
||||||
|
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( string1_p, string2_p);
|
||||||
|
} /* ecma_CompareEcmaStringToEcmaString */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare zero-terminated string to ecma-string
|
* Compare zero-terminated string to ecma-string
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ extern ecma_ArrayFirstChunk_t* ecma_NewEcmaString( const ecma_Char_t *pString);
|
|||||||
extern ssize_t ecma_CopyEcmaStringCharsToBuffer( ecma_ArrayFirstChunk_t *pFirstChunk, uint8_t *pBuffer, size_t bufferSize);
|
extern ssize_t ecma_CopyEcmaStringCharsToBuffer( ecma_ArrayFirstChunk_t *pFirstChunk, uint8_t *pBuffer, size_t bufferSize);
|
||||||
extern ecma_ArrayFirstChunk_t* ecma_DuplicateEcmaString( ecma_ArrayFirstChunk_t *pFirstChunk);
|
extern ecma_ArrayFirstChunk_t* ecma_DuplicateEcmaString( ecma_ArrayFirstChunk_t *pFirstChunk);
|
||||||
extern bool ecma_CompareZtStringToEcmaString( const ecma_Char_t *pString, const ecma_ArrayFirstChunk_t *pEcmaString);
|
extern bool ecma_CompareZtStringToEcmaString( const ecma_Char_t *pString, const ecma_ArrayFirstChunk_t *pEcmaString);
|
||||||
|
extern bool ecma_CompareEcmaStringToEcmaString(const ecma_ArrayFirstChunk_t *string1_p, const ecma_ArrayFirstChunk_t *string2_p);
|
||||||
extern void ecma_FreeArray( ecma_ArrayFirstChunk_t *pFirstChunk);
|
extern void ecma_FreeArray( ecma_ArrayFirstChunk_t *pFirstChunk);
|
||||||
|
|
||||||
#endif /* !JERRY_ECMA_HELPERS_H */
|
#endif /* !JERRY_ECMA_HELPERS_H */
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/* 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-comparison.h"
|
||||||
|
#include "ecma-globals.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
|
/** \addtogroup ecma ---TODO---
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup ecmacomparison ECMA comparison
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ECMA abstract equality comparison routine.
|
||||||
|
*
|
||||||
|
* See also: ECMA-262 v5, 11.9.3
|
||||||
|
*
|
||||||
|
* @return true - if values are equal,
|
||||||
|
* false - otherwise.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
ecma_abstract_equality_compare(ecma_Value_t x, /**< first operand */
|
||||||
|
ecma_Value_t y) /**< second operand */
|
||||||
|
{
|
||||||
|
const bool is_x_undefined = ecma_IsValueUndefined( x);
|
||||||
|
const bool is_x_null = ecma_IsValueNull( x);
|
||||||
|
const bool is_x_boolean = ecma_IsValueBoolean( x);
|
||||||
|
const bool is_x_number = ( x.m_ValueType == ECMA_TYPE_NUMBER );
|
||||||
|
const bool is_x_string = ( x.m_ValueType == ECMA_TYPE_STRING );
|
||||||
|
const bool is_x_object = ( x.m_ValueType == ECMA_TYPE_OBJECT );
|
||||||
|
|
||||||
|
const bool is_y_undefined = ecma_IsValueUndefined( y);
|
||||||
|
const bool is_y_null = ecma_IsValueNull( y);
|
||||||
|
const bool is_y_boolean = ecma_IsValueBoolean( y);
|
||||||
|
const bool is_y_number = ( y.m_ValueType == ECMA_TYPE_NUMBER );
|
||||||
|
const bool is_y_string = ( y.m_ValueType == ECMA_TYPE_STRING );
|
||||||
|
const bool is_y_object = ( y.m_ValueType == ECMA_TYPE_OBJECT );
|
||||||
|
|
||||||
|
const bool is_types_equal = ( ( is_x_undefined && is_y_undefined )
|
||||||
|
|| ( is_x_null && is_y_null )
|
||||||
|
|| ( is_x_boolean && is_y_boolean )
|
||||||
|
|| ( is_x_number && is_y_number )
|
||||||
|
|| ( is_x_string && is_y_string )
|
||||||
|
|| ( is_x_object && is_y_object ) );
|
||||||
|
|
||||||
|
if ( is_types_equal )
|
||||||
|
{
|
||||||
|
// 1.
|
||||||
|
|
||||||
|
if ( is_x_undefined
|
||||||
|
|| is_x_null )
|
||||||
|
{
|
||||||
|
// a., b.
|
||||||
|
return true;
|
||||||
|
} else if ( is_x_number )
|
||||||
|
{ // c.
|
||||||
|
ecma_Number_t x_num = *(ecma_Number_t*)( ecma_GetPointer(x.m_Value) );
|
||||||
|
ecma_Number_t y_num = *(ecma_Number_t*)( ecma_GetPointer(y.m_Value) );
|
||||||
|
|
||||||
|
TODO( Implement according to ECMA );
|
||||||
|
|
||||||
|
return (x_num == y_num);
|
||||||
|
} else if ( is_x_string )
|
||||||
|
{ // d.
|
||||||
|
ecma_ArrayFirstChunk_t* x_str = (ecma_ArrayFirstChunk_t*)( ecma_GetPointer(x.m_Value) );
|
||||||
|
ecma_ArrayFirstChunk_t* y_str = (ecma_ArrayFirstChunk_t*)( ecma_GetPointer(y.m_Value) );
|
||||||
|
|
||||||
|
return ecma_CompareEcmaStringToEcmaString( x_str, y_str);
|
||||||
|
} else if ( is_x_boolean )
|
||||||
|
{ // e.
|
||||||
|
return ( x.m_Value == y.m_Value );
|
||||||
|
} else
|
||||||
|
{ // f.
|
||||||
|
JERRY_ASSERT( is_x_object );
|
||||||
|
|
||||||
|
return ( x.m_Value == y.m_Value );
|
||||||
|
}
|
||||||
|
} else if ( ( is_x_null && is_y_undefined )
|
||||||
|
|| ( is_x_undefined && is_y_null ) )
|
||||||
|
{ // 2., 3.
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
JERRY_UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
} /* ecma_abstract_equality_compare */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/* 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 JERRY_ECMA_COMPARISON_H
|
||||||
|
#define JERRY_ECMA_COMPARISON_H
|
||||||
|
|
||||||
|
#include "ecma-globals.h"
|
||||||
|
#include "ecma-helpers.h"
|
||||||
|
|
||||||
|
/** \addtogroup ecma ---TODO---
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \addtogroup ecmacomparison ECMA comparison
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern bool ecma_abstract_equality_compare( ecma_Value_t x, ecma_Value_t y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* !JERRY_ECMA_COMPARISON_H */
|
||||||
Reference in New Issue
Block a user