From 7e87a1fde0d55bfdbdfea87279a14f1e8368d784 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 21 Jul 2014 19:58:04 +0400 Subject: [PATCH] Implementing CheckObjectCoercible operation and partial stubs for ToPrimitive and ToObject operations. --- src/libecmaoperations/ecma-conversion.c | 139 ++++++++++++++++++ .../ecma-conversion.h | 43 ++---- 2 files changed, 150 insertions(+), 32 deletions(-) create mode 100644 src/libecmaoperations/ecma-conversion.c rename src/{libecmaobjects => libecmaoperations}/ecma-conversion.h (67%) diff --git a/src/libecmaoperations/ecma-conversion.c b/src/libecmaoperations/ecma-conversion.c new file mode 100644 index 000000000..d9008b1f9 --- /dev/null +++ b/src/libecmaoperations/ecma-conversion.c @@ -0,0 +1,139 @@ +/* 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. + */ + +/** + * Implementation of ECMA-defined conversion routines + */ + +#include "ecma-conversion.h" +#include "ecma-exceptions.h" +#include "ecma-globals.h" + +/** \addtogroup ecma ---TODO--- + * @{ + * + * \addtogroup ecmaconversion ECMA conversion routines + * @{ + */ + +/** + * CheckObjectCoercible operation. + * + * See also: + * ECMA-262 v5, 9.10 + * + * @return completion value + * Returned value must be free with ecma_FreeCompletionValue + */ +ecma_CompletionValue_t +ecma_op_check_object_coercible( ecma_Value_t value) /**< ecma-value */ +{ + switch ( (ecma_Type_t)value.m_ValueType ) + { + case ECMA_TYPE_SIMPLE: + { + switch ( (ecma_SimpleValue_t)value.m_Value ) + { + case ECMA_SIMPLE_VALUE_UNDEFINED: + case ECMA_SIMPLE_VALUE_NULL: + { + return ecma_MakeThrowValue( ecma_NewStandardError( ECMA_ERROR_TYPE)); + } + case ECMA_SIMPLE_VALUE_FALSE: + case ECMA_SIMPLE_VALUE_TRUE: + { + break; + } + case ECMA_SIMPLE_VALUE_EMPTY: + case ECMA_SIMPLE_VALUE_ARRAY_REDIRECT: + case ECMA_SIMPLE_VALUE__COUNT: + { + JERRY_UNREACHABLE(); + } + } + + break; + } + case ECMA_TYPE_NUMBER: + case ECMA_TYPE_STRING: + case ECMA_TYPE_OBJECT: + { + break; + } + case ECMA_TYPE__COUNT: + { + JERRY_UNREACHABLE(); + } + } + + return ecma_MakeCompletionValue( ECMA_COMPLETION_TYPE_NORMAL, + ecma_MakeSimpleValue( ECMA_SIMPLE_VALUE_EMPTY), + ECMA_TARGET_ID_RESERVED); +} /* ecma_op_check_object_coercible */ + +/** + * ToPrimitive operation. + * + * See also: + * ECMA-262 v5, 9.10 + * + * @return completion value + * Returned value must be free with ecma_FreeCompletionValue + */ +ecma_CompletionValue_t +ecma_op_to_primitive( ecma_Value_t value) /**< ecma-value */ +{ + switch ( (ecma_Type_t)value.m_ValueType ) + { + case ECMA_TYPE_SIMPLE: + case ECMA_TYPE_NUMBER: + case ECMA_TYPE_STRING: + { + return ecma_MakeCompletionValue( ECMA_COMPLETION_TYPE_NORMAL, + ecma_CopyValue( value), + ECMA_TARGET_ID_RESERVED); + } + case ECMA_TYPE_OBJECT: + { + JERRY_UNIMPLEMENTED(); + } + case ECMA_TYPE__COUNT: + { + JERRY_UNREACHABLE(); + } + } + + JERRY_UNREACHABLE(); +} /* ecma_op_to_primitive */ + +/** + * ToObject operation. + * + * See also: + * ECMA-262 v5, 9.10 + * + * @return completion value + * Returned value must be free with ecma_FreeCompletionValue + */ +ecma_CompletionValue_t +ecma_op_to_object( ecma_Value_t value) /**< ecma-value */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( value); +} /* ecma_op_to_object */ + +/** + * @} + * @} + */ diff --git a/src/libecmaobjects/ecma-conversion.h b/src/libecmaoperations/ecma-conversion.h similarity index 67% rename from src/libecmaobjects/ecma-conversion.h rename to src/libecmaoperations/ecma-conversion.h index 26922564e..c52d101af 100644 --- a/src/libecmaobjects/ecma-conversion.h +++ b/src/libecmaoperations/ecma-conversion.h @@ -13,6 +13,12 @@ * limitations under the License. */ +#ifndef JERRY_ECMA_CONVERSION_H +#define JERRY_ECMA_CONVERSION_H + +#include "ecma-globals.h" +#include "ecma-helpers.h" + /** \addtogroup ecma ---TODO--- * @{ * @@ -20,40 +26,13 @@ * @{ */ -#ifndef JERRY_ECMA_CONVERSION_H -#define JERRY_ECMA_CONVERSION_H - -#include "ecma-globals.h" -#include "ecma-helpers.h" - -extern ecma_Object_t* ecma_ToObject( ecma_Value_t value); - -/* - * Stubs - */ +extern ecma_CompletionValue_t ecma_op_check_object_coercible( ecma_Value_t value); +extern ecma_CompletionValue_t ecma_op_to_primitive( ecma_Value_t value); +extern ecma_CompletionValue_t ecma_op_to_object( ecma_Value_t value); /** - * Convert value to ecma-object. - * - * See also: - * ECMA-262 5.1, 9.9. - * - * @return pointer to ecma-object descriptor + * @} + * @} */ -ecma_Object_t* -ecma_ToObject(ecma_Value_t value) /**< ecma-value */ -{ - if ( value.m_ValueType == ECMA_TYPE_OBJECT ) - { - return ecma_DecompressPointer( value.m_Value); - } - - JERRY_UNIMPLEMENTED(); -} #endif /* !JERRY_ECMA_CONVERSION_H */ - -/** - * @} - * @} - */