Added new 'jerry_binary_operation' API function (#2746)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "ecma-arraybuffer-object.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-comparison.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-eval.h"
|
||||
#include "ecma-function-object.h"
|
||||
@@ -34,6 +35,7 @@
|
||||
#include "ecma-regexp-object.h"
|
||||
#include "ecma-promise-object.h"
|
||||
#include "ecma-typedarray-object.h"
|
||||
#include "opcodes.h"
|
||||
#include "jcontext.h"
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-debugger-transport.h"
|
||||
@@ -901,6 +903,57 @@ jerry_is_feature_enabled (const jerry_feature_t feature) /**< feature to check *
|
||||
);
|
||||
} /* jerry_is_feature_enabled */
|
||||
|
||||
/**
|
||||
* Perform binary operation on the given operands (==, ===, <, >, etc.).
|
||||
*
|
||||
* @return error - if argument has an error flag or operation is unsuccessful or unsupported
|
||||
* true/false - the result of the binary operation on the given operands otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_binary_operation (jerry_binary_operation_t op, /**< operation */
|
||||
const jerry_value_t lhs, /**< first operand */
|
||||
const jerry_value_t rhs) /**< second operand */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
if (ecma_is_value_error_reference (lhs) || ecma_is_value_error_reference (rhs))
|
||||
{
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (error_value_msg_p)));
|
||||
}
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case JERRY_BIN_OP_EQUAL:
|
||||
{
|
||||
return jerry_return (ecma_op_abstract_equality_compare (lhs, rhs));
|
||||
}
|
||||
case JERRY_BIN_OP_STRICT_EQUAL:
|
||||
{
|
||||
return ecma_make_boolean_value (ecma_op_strict_equality_compare (lhs, rhs));
|
||||
}
|
||||
case JERRY_BIN_OP_LESS:
|
||||
{
|
||||
return jerry_return (opfunc_relation (lhs, rhs, true, false));
|
||||
}
|
||||
case JERRY_BIN_OP_LESS_EQUAL:
|
||||
{
|
||||
return jerry_return (opfunc_relation (lhs, rhs, false, true));
|
||||
}
|
||||
case JERRY_BIN_OP_GREATER:
|
||||
{
|
||||
return jerry_return (opfunc_relation (lhs, rhs, false, false));
|
||||
}
|
||||
case JERRY_BIN_OP_GREATER_EQUAL:
|
||||
{
|
||||
return jerry_return (opfunc_relation (lhs, rhs, true, true));
|
||||
}
|
||||
default:
|
||||
{
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Unsupported binary operation")));
|
||||
}
|
||||
}
|
||||
} /* jerry_binary_operation */
|
||||
|
||||
/**
|
||||
* Create abort from an api value.
|
||||
*
|
||||
|
||||
@@ -31,8 +31,13 @@
|
||||
*
|
||||
* See also: ECMA-262 v5, 11.9.3
|
||||
*
|
||||
* Note:
|
||||
* This function might raise an exception, so the
|
||||
* returned value must be freed with ecma_free_value.
|
||||
*
|
||||
* @return true - if values are equal,
|
||||
* false - otherwise
|
||||
* error - in case of any problems
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_abstract_equality_compare (ecma_value_t x, /**< first operand */
|
||||
|
||||
@@ -308,6 +308,19 @@ typedef struct
|
||||
*/
|
||||
typedef struct jerry_context_t jerry_context_t;
|
||||
|
||||
/**
|
||||
* Enum that contains the supported binary operation types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
JERRY_BIN_OP_EQUAL = 0u, /**< equal comparison (==) */
|
||||
JERRY_BIN_OP_STRICT_EQUAL, /**< strict equal comparison (===) */
|
||||
JERRY_BIN_OP_LESS, /**< less relation (<) */
|
||||
JERRY_BIN_OP_LESS_EQUAL, /**< less or equal relation (<=) */
|
||||
JERRY_BIN_OP_GREATER, /**< greater relation (>) */
|
||||
JERRY_BIN_OP_GREATER_EQUAL /**< greater or equal relation (>=)*/
|
||||
} jerry_binary_operation_t;
|
||||
|
||||
/**
|
||||
* General engine functions.
|
||||
*/
|
||||
@@ -379,6 +392,13 @@ jerry_type_t jerry_value_get_type (const jerry_value_t value);
|
||||
*/
|
||||
bool jerry_is_feature_enabled (const jerry_feature_t feature);
|
||||
|
||||
/**
|
||||
* Binary operations
|
||||
*/
|
||||
jerry_value_t jerry_binary_operation (jerry_binary_operation_t op,
|
||||
const jerry_value_t lhs,
|
||||
const jerry_value_t rhs);
|
||||
|
||||
/**
|
||||
* Error manipulation functions.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user