1/* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "ecma-alloc.h"
17#include "ecma-boolean-object.h"
18#include "ecma-builtins.h"
19#include "ecma-conversion.h"
20#include "ecma-exceptions.h"
21#include "ecma-gc.h"
22#include "ecma-globals.h"
23#include "ecma-helpers.h"
24#include "ecma-objects.h"
25#include "ecma-try-catch-macro.h"
26#include "jrt.h"
27
28#if ENABLED (JERRY_BUILTIN_BOOLEAN)
29
30#define ECMA_BUILTINS_INTERNAL
31#include "ecma-builtins-internal.h"
32
33#define BUILTIN_INC_HEADER_NAME "ecma-builtin-boolean.inc.h"
34#define BUILTIN_UNDERSCORED_ID boolean
35#include "ecma-builtin-internal-routines-template.inc.h"
36
37/** \addtogroup ecma ECMA
38 * @{
39 *
40 * \addtogroup ecmabuiltins
41 * @{
42 *
43 * \addtogroup boolean ECMA Boolean object built-in
44 * @{
45 */
46
47/**
48 * Handle calling [[Call]] of built-in Boolean object
49 *
50 * @return ecma value
51 */
52ecma_value_t
53ecma_builtin_boolean_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
54                                    ecma_length_t arguments_list_len) /**< number of arguments */
55{
56  JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
57
58  ecma_value_t arg_value;
59
60  if (arguments_list_len == 0)
61  {
62    arg_value = ECMA_VALUE_UNDEFINED;
63  }
64  else
65  {
66    arg_value = arguments_list_p[0];
67  }
68
69  return ecma_make_boolean_value (ecma_op_to_boolean (arg_value));
70} /* ecma_builtin_boolean_dispatch_call */
71
72/**
73 * Handle calling [[Construct]] of built-in Boolean object
74 *
75 * @return ecma value
76 */
77ecma_value_t
78ecma_builtin_boolean_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
79                                         ecma_length_t arguments_list_len) /**< number of arguments */
80{
81  JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
82
83  if (arguments_list_len == 0)
84  {
85    return ecma_op_create_boolean_object (ECMA_VALUE_FALSE);
86  }
87  else
88  {
89    return ecma_op_create_boolean_object (arguments_list_p[0]);
90  }
91} /* ecma_builtin_boolean_dispatch_construct */
92
93/**
94 * @}
95 * @}
96 * @}
97 */
98
99#endif /* ENABLED (JERRY_BUILTIN_BOOLEAN) */
100