Added 'instanceof' binary operation to the API (#2751)

Added 'JERRY_BIN_OP_INSTANCEOF' to 'jerry_binary_operation_t' and
'jerry_binary_operation'. Added unit tests for this new operation
and updated the documentations.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
László Langó
2019-02-13 12:49:28 +01:00
committed by GitHub
parent ed0662612d
commit 2d16705050
6 changed files with 198 additions and 8 deletions
+11
View File
@@ -947,6 +947,17 @@ jerry_binary_operation (jerry_binary_operation_t op, /**< operation */
{
return jerry_return (opfunc_relation (lhs, rhs, true, true));
}
case JERRY_BIN_OP_INSTANCEOF:
{
if (!ecma_is_value_object (lhs)
|| !ecma_op_is_callable (rhs))
{
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
}
ecma_object_t *proto_obj_p = ecma_get_object_from_value (rhs);
return jerry_return (ecma_op_object_has_instance (proto_obj_p, lhs));
}
default:
{
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Unsupported binary operation")));
@@ -391,7 +391,8 @@ ecma_op_implicit_class_constructor_has_instance (ecma_object_t *func_obj_p, /**<
/**
* 15.3.5.3 implementation of [[HasInstance]] for Function objects
*
* @return ecma value
* @return true/false - if arguments are valid
* error - otherwise
* Returned value must be freed with ecma_free_value
*/
ecma_value_t
+7 -6
View File
@@ -313,12 +313,13 @@ typedef struct jerry_context_t jerry_context_t;
*/
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_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_BIN_OP_INSTANCEOF, /**< instanceof operation */
} jerry_binary_operation_t;
/**