• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-builtins.h"
18 #include "ecma-exceptions.h"
19 #include "ecma-gc.h"
20 #include "ecma-globals.h"
21 #include "ecma-helpers.h"
22 #include "ecma-number-object.h"
23 #include "ecma-objects.h"
24 #include "ecma-objects-general.h"
25 
26 /** \addtogroup ecma ECMA
27  * @{
28  *
29  * \addtogroup ecmanumberobject ECMA Number object related routines
30  * @{
31  */
32 
33 /**
34  * Number object creation operation.
35  *
36  * See also: ECMA-262 v5, 15.7.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_number_object(ecma_value_t arg)42 ecma_op_create_number_object (ecma_value_t arg) /**< argument passed to the Number constructor */
43 {
44   ecma_value_t conv_to_num_completion = ecma_op_to_number (arg);
45 
46   if (ECMA_IS_VALUE_ERROR (conv_to_num_completion))
47   {
48     return conv_to_num_completion;
49   }
50 
51 #if ENABLED (JERRY_BUILTIN_NUMBER)
52   ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE);
53 #else /* ENABLED (JERRY_BUILTIN_NUMBER) */
54   ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
55 #endif /* ENABLED (JERRY_BUILTIN_NUMBER) */
56 
57   ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
58                                                 sizeof (ecma_extended_object_t),
59                                                 ECMA_OBJECT_TYPE_CLASS);
60 
61   ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
62   ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_NUMBER_UL;
63 
64   /* Pass reference (no need to free conv_to_num_completion). */
65   ext_object_p->u.class_prop.u.value = conv_to_num_completion;
66 
67   return ecma_make_object_value (object_p);
68 } /* ecma_op_create_number_object */
69 
70 /**
71  * @}
72  * @}
73  */
74