Partially implementing ECMA 'Absract relational comparison' (11.8.5).
This commit is contained in:
@@ -14,7 +14,9 @@
|
||||
*/
|
||||
|
||||
#include "ecma-comparison.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
/** \addtogroup ecma ---TODO---
|
||||
@@ -99,6 +101,74 @@ ecma_abstract_equality_compare(ecma_value_t x, /**< first operand */
|
||||
}
|
||||
} /* ecma_abstract_equality_compare */
|
||||
|
||||
/**
|
||||
* ECMA abstract relational comparison routine.
|
||||
*
|
||||
* See also: ECMA-262 v5, 11.8.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_abstract_relational_compare(ecma_value_t x, /**< first operand */
|
||||
ecma_value_t y, /**< second operand */
|
||||
bool left_first) /**< 'LeftFirst' flag */
|
||||
{
|
||||
ecma_completion_value_t ret_value, px, py;
|
||||
|
||||
ecma_value_t first_converted_value = left_first ? x : y;
|
||||
ecma_value_t second_converted_value = left_first ? y : x;
|
||||
|
||||
// 1., 2.
|
||||
ECMA_TRY_CATCH( prim_first_converted_value, ecma_op_to_primitive( first_converted_value, ECMA_PREFERRED_TYPE_NUMBER), ret_value);
|
||||
ECMA_TRY_CATCH( prim_second_converted_value, ecma_op_to_primitive( second_converted_value, ECMA_PREFERRED_TYPE_NUMBER), ret_value);
|
||||
|
||||
px = left_first ? prim_first_converted_value : prim_second_converted_value;
|
||||
py = left_first ? prim_second_converted_value : prim_first_converted_value;
|
||||
|
||||
const bool is_px_string = ( px.value.value_type == ECMA_TYPE_STRING );
|
||||
const bool is_py_string = ( py.value.value_type == ECMA_TYPE_STRING );
|
||||
|
||||
if ( !( is_px_string && is_py_string ) )
|
||||
{ // 3.
|
||||
// a.
|
||||
ECMA_TRY_CATCH( nx, ecma_op_to_number( px.value), ret_value);
|
||||
|
||||
// b.
|
||||
ECMA_TRY_CATCH( ny, ecma_op_to_number( py.value), ret_value);
|
||||
|
||||
ecma_number_t* num_x_p = (ecma_number_t*)ecma_get_pointer( nx.value.value);
|
||||
ecma_number_t* num_y_p = (ecma_number_t*)ecma_get_pointer( ny.value.value);
|
||||
|
||||
TODO( /* Implement according to ECMA */ );
|
||||
|
||||
if ( *num_x_p >= *num_y_p )
|
||||
{
|
||||
ret_value = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL,
|
||||
ecma_make_simple_value( ECMA_SIMPLE_VALUE_FALSE),
|
||||
ECMA_TARGET_ID_RESERVED);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL,
|
||||
ecma_make_simple_value( ECMA_SIMPLE_VALUE_TRUE),
|
||||
ECMA_TARGET_ID_RESERVED);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE( ny);
|
||||
ECMA_FINALIZE( nx);
|
||||
}
|
||||
else
|
||||
{ // 4.
|
||||
JERRY_UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
ECMA_FINALIZE( prim_second_converted_value);
|
||||
ECMA_FINALIZE( prim_first_converted_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_abstract_relational_compare */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
Reference in New Issue
Block a user