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-exceptions.h" 20 #include "ecma-gc.h" 21 #include "ecma-globals.h" 22 #include "ecma-helpers.h" 23 #include "ecma-objects.h" 24 #include "ecma-objects-general.h" 25 26 /** \addtogroup ecma ECMA 27 * @{ 28 * 29 * \addtogroup ecmabooleanobject ECMA Boolean object related routines 30 * @{ 31 */ 32 33 /** 34 * Boolean object creation operation. 35 * 36 * See also: ECMA-262 v5, 15.6.2.1 37 * 38 * @return ecma value 39 * Returned value must be freed with ecma_free_value 40 */ 41 ecma_value_t ecma_op_create_boolean_object(ecma_value_t arg)42ecma_op_create_boolean_object (ecma_value_t arg) /**< argument passed to the Boolean constructor */ 43 { 44 bool boolean_value = ecma_op_to_boolean (arg); 45 46 #if ENABLED (JERRY_BUILTIN_BOOLEAN) 47 ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE); 48 #else /* ENABLED (JERRY_BUILTIN_BOOLEAN) */ 49 ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE); 50 #endif /* !(ENABLED (JERRY_BUILTIN_BOOLEAN) */ 51 52 ecma_object_t *object_p = ecma_create_object (prototype_obj_p, 53 sizeof (ecma_extended_object_t), 54 ECMA_OBJECT_TYPE_CLASS); 55 56 ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; 57 ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_BOOLEAN_UL; 58 ext_object_p->u.class_prop.u.value = ecma_make_boolean_value (boolean_value); 59 60 return ecma_make_object_value (object_p); 61 } /* ecma_op_create_boolean_object */ 62 63 /** 64 * @} 65 * @} 66 */ 67