mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Arrangement of built-in objects implementation (description of built-ins with *.inc.h headers, reducing code duplication).
This commit is contained in:
parent
6078a4c854
commit
a74c77a1d5
@ -1,299 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup array ECMA Array object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Array object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_ARRAY_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_PROTOTYPE, ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE))
|
||||
|
||||
/**
|
||||
* List of the Array object built-in routine properties in format
|
||||
* 'macro (name, C function name, arguments number of the routine, length value of the routine)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_ARRAY_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_IS_ARRAY_UL, \
|
||||
ecma_builtin_array_object_is_array, \
|
||||
1, \
|
||||
1)
|
||||
|
||||
/**
|
||||
* List of the Array object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_array_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_ARRAY_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_ARRAY_OBJECT_ROUTINES_PROPERTY_LIST (ROUTINE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the Array object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_array_property_number = (sizeof (ecma_builtin_array_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* The Array object's 'isArray' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.4.3.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_array_object_is_array (ecma_value_t arg) /**< first argument */
|
||||
{
|
||||
ecma_simple_value_t is_array = ECMA_SIMPLE_VALUE_FALSE;
|
||||
|
||||
if (arg.value_type == ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (arg.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
|
||||
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_ARRAY_UL)
|
||||
{
|
||||
is_array = ECMA_SIMPLE_VALUE_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_simple_completion_value (is_array);
|
||||
} /* ecma_builtin_array_object_is_array */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Array object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_array_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_ARRAY));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_array_property_names,
|
||||
ecma_builtin_array_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_ARRAY, id, length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_ARRAY_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_ARRAY_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_ARRAY_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_array_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Array object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_array_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< Array object's
|
||||
built-in routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_1 ROUTINE_ARG(1)
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_ARRAY_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_array_dispatch_routine */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Array object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_array_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_builtin_array_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_array_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Array object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_array_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_op_create_array_object (arguments_list_p, arguments_list_len, true);
|
||||
} /* ecma_builtin_array_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@ -1,280 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup arrayprototype ECMA Array.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Array.prototype object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_CONSTRUCTOR, ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY))
|
||||
#define ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_NUMBER_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_LENGTH, 0)
|
||||
|
||||
/**
|
||||
* List of the Array.prototype object built-in routine properties in format
|
||||
* 'macro (name, C function name, arguments number of the routine, length value of the routine)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_TO_STRING_UL, \
|
||||
ecma_builtin_array_prototype_object_to_string, \
|
||||
0, \
|
||||
0)
|
||||
TODO (/* Description of routines of Array.prototype object */)
|
||||
|
||||
/**
|
||||
* List of the Array.prototype object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_NUMBER_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (ROUTINE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the Array.prototype object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_array_prototype_property_number = (sizeof (ecma_builtin_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* The Array.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.4.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_array_prototype_object_to_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this);
|
||||
} /* ecma_builtin_array_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Array.prototype object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_array_prototype_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_ARRAY_PROTOTYPE));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_property_names,
|
||||
ecma_builtin_array_prototype_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE, \
|
||||
id, \
|
||||
length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_NUMBER_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
#define CASE_NUMBER_VALUE_PROP_LIST(name, value_num) case name: { ecma_number_t *num_p = ecma_alloc_number (); \
|
||||
*num_p = (ecma_number_t) value_num; \
|
||||
value = ecma_make_number_value (num_p); break; }
|
||||
ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_NUMBER_VALUES_PROPERTY_LIST (CASE_NUMBER_VALUE_PROP_LIST)
|
||||
#undef CASE_NUMBER_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_array_prototype_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Array.prototype object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_array_prototype_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< Array.prototype
|
||||
object's built-in
|
||||
routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
// const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
FIXME (/*
|
||||
* Remove void statements after implementation of
|
||||
* an Array.prototype object's routine that accepts
|
||||
* non-zero number of arguments.
|
||||
*/);
|
||||
(void) arguments_list;
|
||||
(void) arguments_number;
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_0
|
||||
#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_ARRAY_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_array_prototype_dispatch_routine */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
64
src/libecmabuiltins/ecma-builtin-array-prototype.c
Normal file
64
src/libecmabuiltins/ecma-builtin-array-prototype.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID array_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup arrayprototype ECMA Array.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Array.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.4.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_array_prototype_object_to_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this);
|
||||
} /* ecma_builtin_array_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
69
src/libecmabuiltins/ecma-builtin-array-prototype.inc.h
Normal file
69
src/libecmabuiltins/ecma-builtin-array-prototype.inc.h
Normal file
@ -0,0 +1,69 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Array.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.4.4.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.4.4
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_array_prototype_object_to_string, 0, 0)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
|
||||
108
src/libecmabuiltins/ecma-builtin-array.c
Normal file
108
src/libecmabuiltins/ecma-builtin-array.c
Normal file
@ -0,0 +1,108 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID array
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup array ECMA Array object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Array object's 'isArray' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.4.3.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_array_object_is_array (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< first argument */
|
||||
{
|
||||
ecma_simple_value_t is_array = ECMA_SIMPLE_VALUE_FALSE;
|
||||
|
||||
if (arg.value_type == ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (arg.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
|
||||
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_ARRAY_UL)
|
||||
{
|
||||
is_array = ECMA_SIMPLE_VALUE_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_simple_completion_value (is_array);
|
||||
} /* ecma_builtin_array_object_is_array */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Array object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_array_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_builtin_array_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_array_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Array object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_array_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_op_create_array_object (arguments_list_p, arguments_list_len, true);
|
||||
} /* ecma_builtin_array_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
59
src/libecmabuiltins/ecma-builtin-array.inc.h
Normal file
59
src/libecmabuiltins/ecma-builtin-array.inc.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Array description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_ARRAY)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.4.3.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
|
||||
@ -1,258 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-boolean-object.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup boolean ECMA Boolean object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Boolean object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_BOOLEAN_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_PROTOTYPE, ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE))
|
||||
|
||||
#define ECMA_BUILTIN_BOOLEAN_OBJECT_NUMBER_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_LENGTH, 1)
|
||||
|
||||
/**
|
||||
* List of the Boolean object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_boolean_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_boolean, length) name,
|
||||
ECMA_BUILTIN_BOOLEAN_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_BOOLEAN_OBJECT_NUMBER_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the Boolean object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_boolean_property_number = (sizeof (ecma_builtin_boolean_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Boolean object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_boolean_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_BOOLEAN));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_boolean_property_names,
|
||||
ecma_builtin_boolean_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_BOOLEAN_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_BOOLEAN_OBJECT_NUMBER_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_BOOLEAN_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
#define CASE_NUMBER_VALUE_PROP_LIST(name, value_num) case name: { ecma_number_t *num_p = ecma_alloc_number (); \
|
||||
*num_p = (ecma_number_t) value_num; \
|
||||
value = ecma_make_number_value (num_p); break; }
|
||||
ECMA_BUILTIN_BOOLEAN_OBJECT_NUMBER_VALUES_PROPERTY_LIST (CASE_NUMBER_VALUE_PROP_LIST)
|
||||
#undef CASE_NUMBER_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_boolean_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Boolean object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_boolean_dispatch_routine (ecma_magic_string_id_t builtin_routine_id __unused, /**< Boolean object's
|
||||
built-in routine's
|
||||
name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [] __unused, /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_boolean __unused) /**< length of arguments' list */
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
} /* ecma_builtin_boolean_dispatch_routine */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Boolean object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_boolean_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_value_t arg_value;
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
arg_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
arg_value = arguments_list_p [0];
|
||||
}
|
||||
|
||||
return ecma_op_to_boolean (arg_value);
|
||||
} /* ecma_builtin_boolean_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Boolean object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_boolean_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
return ecma_op_create_boolean_object (ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_create_boolean_object (arguments_list_p[0]);
|
||||
}
|
||||
} /* ecma_builtin_boolean_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@ -1,300 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup booleanprototype ECMA Boolean.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define ROUTINE_ARG_LIST_0 ecma_value_t this
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
|
||||
static ecma_completion_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number);
|
||||
#include "ecma-builtin-boolean-prototype.inc.h"
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Boolean.prototype object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_boolean_prototype_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const ecma_magic_string_id_t ecma_builtin_property_names[] =
|
||||
{
|
||||
#define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) name,
|
||||
#include "ecma-builtin-boolean-prototype.inc.h"
|
||||
};
|
||||
|
||||
int32_t index;
|
||||
index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_property_names,
|
||||
sizeof (ecma_builtin_property_names) /
|
||||
sizeof (ecma_builtin_property_names [0]),
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable;
|
||||
ecma_property_enumerable_value_t enumerable;
|
||||
ecma_property_configurable_value_t configurable;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE, \
|
||||
id, \
|
||||
length_prop_value); \
|
||||
\
|
||||
writable = ECMA_PROPERTY_WRITABLE; \
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE; \
|
||||
configurable = ECMA_PROPERTY_CONFIGURABLE; \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
#define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) case name: \
|
||||
{ \
|
||||
value = ecma_make_object_value (obj_getter); \
|
||||
writable = prop_writable; \
|
||||
enumerable = prop_enumerable; \
|
||||
configurable = prop_configurable; \
|
||||
break; \
|
||||
}
|
||||
#include "ecma-builtin-boolean-prototype.inc.h"
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_boolean_prototype_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Boolean.prototype object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_boolean_prototype_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< Boolean.prototype
|
||||
object's built-in
|
||||
routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [] __unused, /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number __unused) /**< length of
|
||||
arguments' list */
|
||||
{
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_0
|
||||
#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
#include "ecma-builtin-boolean-prototype.inc.h"
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_boolean_prototype_dispatch_routine */
|
||||
|
||||
/**
|
||||
* The Boolean.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.6.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_boolean_prototype_object_to_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (completion_value_of,
|
||||
ecma_builtin_boolean_prototype_object_value_of (this),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *ret_str_p;
|
||||
|
||||
if (ecma_is_completion_value_normal_true (completion_value_of))
|
||||
{
|
||||
ret_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_false (completion_value_of));
|
||||
|
||||
ret_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_FALSE);
|
||||
}
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
|
||||
|
||||
ECMA_FINALIZE (completion_value_of);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_boolean_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Boolean.prototype object's 'valueOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.6.4.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_boolean_prototype_object_value_of (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
if (ecma_is_value_boolean (this))
|
||||
{
|
||||
return ecma_make_normal_completion_value (this);
|
||||
}
|
||||
else if (this.value_type == ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (this.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
|
||||
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_BOOLEAN_UL)
|
||||
{
|
||||
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE);
|
||||
|
||||
JERRY_ASSERT (prim_value_prop_p->u.internal_property.value < ECMA_SIMPLE_VALUE__COUNT);
|
||||
|
||||
ecma_simple_value_t prim_simple_value = prim_value_prop_p->u.internal_property.value;
|
||||
|
||||
ecma_value_t ret_boolean_value = ecma_make_simple_value (prim_simple_value);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (ret_boolean_value));
|
||||
|
||||
return ecma_make_normal_completion_value (ret_boolean_value);
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
} /* ecma_builtin_boolean_prototype_object_value_of */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
129
src/libecmabuiltins/ecma-builtin-boolean-prototype.c
Normal file
129
src/libecmabuiltins/ecma-builtin-boolean-prototype.c
Normal file
@ -0,0 +1,129 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-boolean-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID boolean_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup booleanprototype ECMA Boolean.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Boolean.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.6.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_boolean_prototype_object_to_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (completion_value_of,
|
||||
ecma_builtin_boolean_prototype_object_value_of (this),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *ret_str_p;
|
||||
|
||||
if (ecma_is_completion_value_normal_true (completion_value_of))
|
||||
{
|
||||
ret_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_false (completion_value_of));
|
||||
|
||||
ret_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_FALSE);
|
||||
}
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
|
||||
|
||||
ECMA_FINALIZE (completion_value_of);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_boolean_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Boolean.prototype object's 'valueOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.6.4.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_boolean_prototype_object_value_of (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
if (ecma_is_value_boolean (this))
|
||||
{
|
||||
return ecma_make_normal_completion_value (this);
|
||||
}
|
||||
else if (this.value_type == ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (this.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
|
||||
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_BOOLEAN_UL)
|
||||
{
|
||||
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE);
|
||||
|
||||
JERRY_ASSERT (prim_value_prop_p->u.internal_property.value < ECMA_SIMPLE_VALUE__COUNT);
|
||||
|
||||
ecma_simple_value_t prim_simple_value = prim_value_prop_p->u.internal_property.value;
|
||||
|
||||
ecma_value_t ret_boolean_value = ecma_make_simple_value (prim_simple_value);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (ret_boolean_value));
|
||||
|
||||
return ecma_make_normal_completion_value (ret_boolean_value);
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
} /* ecma_builtin_boolean_prototype_object_value_of */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@ -17,6 +17,10 @@
|
||||
* Boolean.prototype description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
@ -25,8 +29,13 @@
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.6.4.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
@ -38,5 +47,9 @@ OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_boolean_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_boolean_prototype_object_value_of, 0, 0)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
|
||||
95
src/libecmabuiltins/ecma-builtin-boolean.c
Normal file
95
src/libecmabuiltins/ecma-builtin-boolean.c
Normal file
@ -0,0 +1,95 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-boolean-object.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-boolean.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID boolean
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup boolean ECMA Boolean object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Boolean object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_boolean_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_value_t arg_value;
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
arg_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
arg_value = arguments_list_p [0];
|
||||
}
|
||||
|
||||
return ecma_op_to_boolean (arg_value);
|
||||
} /* ecma_builtin_boolean_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Boolean object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_boolean_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
return ecma_op_create_boolean_object (ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_create_boolean_object (arguments_list_p[0]);
|
||||
}
|
||||
} /* ecma_builtin_boolean_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
64
src/libecmabuiltins/ecma-builtin-boolean.inc.h
Normal file
64
src/libecmabuiltins/ecma-builtin-boolean.inc.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Boolean description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_BOOLEAN)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.6.3.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.6.3
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@ -24,9 +24,15 @@
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-compact-profile-error.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID compact_profile_error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
@ -37,44 +43,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Number of the Boolean object's built-in properties
|
||||
*/
|
||||
const ecma_length_t ecma_builtin_compact_profile_error_property_number = 0;
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the CompactProfileError object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_compact_profile_error_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
return NULL;
|
||||
} /* ecma_builtin_compact_profile_error_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the CompactProfileError object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_compact_profile_error_dispatch_routine (ecma_magic_string_id_t builtin_routine_id __unused,
|
||||
ecma_value_t this_arg_value __unused,
|
||||
ecma_value_t arguments_list [] __unused,
|
||||
ecma_length_t arguments_compact_profile_error __unused)
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
} /* ecma_builtin_compact_profile_error_dispatch_routine */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in CompactProfileError object
|
||||
*
|
||||
@ -108,3 +76,5 @@ ecma_builtin_compact_profile_error_dispatch_construct (ecma_value_t *arguments_l
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
45
src/libecmabuiltins/ecma-builtin-compact-profile-error.inc.h
Normal file
45
src/libecmabuiltins/ecma-builtin-compact-profile-error.inc.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* CompactProfileError description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@ -1,239 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup function ECMA Function object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Function object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_FUNCTION_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_PROTOTYPE, ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE))
|
||||
#define ECMA_BUILTIN_FUNCTION_OBJECT_NUMBER_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_LENGTH, 1)
|
||||
|
||||
/**
|
||||
* List of the Function object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_function_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_FUNCTION_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_FUNCTION_OBJECT_NUMBER_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the Function object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_function_property_number = (sizeof (ecma_builtin_function_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Function object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_function_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_FUNCTION));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_function_property_names,
|
||||
ecma_builtin_function_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_FUNCTION_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_FUNCTION_OBJECT_NUMBER_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_FUNCTION_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
#define CASE_NUMBER_VALUE_PROP_LIST(name, value_num) case name: { ecma_number_t *num_p = ecma_alloc_number (); \
|
||||
*num_p = (ecma_number_t) value_num; \
|
||||
value = ecma_make_number_value (num_p); break; }
|
||||
ECMA_BUILTIN_FUNCTION_OBJECT_NUMBER_VALUES_PROPERTY_LIST (CASE_NUMBER_VALUE_PROP_LIST)
|
||||
#undef CASE_NUMBER_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_function_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Function object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_dispatch_routine (ecma_magic_string_id_t builtin_routine_id __unused, /**< Function object's
|
||||
built-in routine's
|
||||
name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [] __unused, /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number __unused) /**< length of arguments' list */
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
} /* ecma_builtin_function_dispatch_routine */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Function object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_builtin_function_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_function_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Function object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_function_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@ -1,358 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup functionprototype ECMA Function.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Function.prototype object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_FUNCTION_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_CONSTRUCTOR, ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION))
|
||||
|
||||
/**
|
||||
* List of the Function.prototype object built-in routine properties in format
|
||||
* 'macro (name, C function name, arguments number of the routine, length value of the routine)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_FUNCTION_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_TO_STRING_UL, \
|
||||
ecma_builtin_function_prototype_object_to_string, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_APPLY, \
|
||||
ecma_builtin_function_prototype_object_apply, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_CALL, \
|
||||
ecma_builtin_function_prototype_object_call, \
|
||||
NON_FIXED, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_BIND, \
|
||||
ecma_builtin_function_prototype_object_bind, \
|
||||
NON_FIXED, \
|
||||
1)
|
||||
|
||||
/**
|
||||
* List of the Function.prototype object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_FUNCTION_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_FUNCTION_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (ROUTINE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the Function.prototype object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_function_prototype_property_number = (sizeof (ecma_builtin_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_object_to_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this);
|
||||
} /* ecma_builtin_function_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'apply' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_object_apply (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg1, /**< first argument */
|
||||
ecma_value_t arg2) /**< second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg1, arg2);
|
||||
} /* ecma_builtin_function_prototype_object_apply */
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'call' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_object_call (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t *arguments_list_p, /**< list of arguments */
|
||||
ecma_length_t arguments_number) /**< number of arguments */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arguments_list_p, arguments_number);
|
||||
} /* ecma_builtin_function_prototype_object_call */
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'bind' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_object_bind (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t *arguments_list_p, /**< list of arguments */
|
||||
ecma_length_t arguments_number) /**< number of arguments */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arguments_list_p, arguments_number);
|
||||
} /* ecma_builtin_function_prototype_object_bind */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Function.prototype object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
} /* ecma_builtin_function_prototype_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Function.prototype object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
} /* ecma_builtin_function_prototype_dispatch_construct */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Function.prototype object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_function_prototype_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_property_names,
|
||||
ecma_builtin_function_prototype_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, \
|
||||
id, \
|
||||
length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_FUNCTION_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_FUNCTION_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_FUNCTION_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_function_prototype_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Function.prototype object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< Function.prototype
|
||||
object's built-in
|
||||
routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_0
|
||||
#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_FUNCTION_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_function_prototype_dispatch_routine */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
143
src/libecmabuiltins/ecma-builtin-function-prototype.c
Normal file
143
src/libecmabuiltins/ecma-builtin-function-prototype.c
Normal file
@ -0,0 +1,143 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID function_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup functionprototype ECMA Function.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_object_to_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this);
|
||||
} /* ecma_builtin_function_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'apply' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_object_apply (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg1, /**< first argument */
|
||||
ecma_value_t arg2) /**< second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg1, arg2);
|
||||
} /* ecma_builtin_function_prototype_object_apply */
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'call' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_object_call (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t *arguments_list_p, /**< list of arguments */
|
||||
ecma_length_t arguments_number) /**< number of arguments */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arguments_list_p, arguments_number);
|
||||
} /* ecma_builtin_function_prototype_object_call */
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'bind' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_object_bind (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t *arguments_list_p, /**< list of arguments */
|
||||
ecma_length_t arguments_number) /**< number of arguments */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arguments_list_p, arguments_number);
|
||||
} /* ecma_builtin_function_prototype_object_bind */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Function.prototype object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
} /* ecma_builtin_function_prototype_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Function.prototype object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_prototype_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
} /* ecma_builtin_function_prototype_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
71
src/libecmabuiltins/ecma-builtin-function-prototype.inc.h
Normal file
71
src/libecmabuiltins/ecma-builtin-function-prototype.inc.h
Normal file
@ -0,0 +1,71 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Function.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.3.4.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.3.4
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_function_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_APPLY, ecma_builtin_function_prototype_object_apply, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_CALL, ecma_builtin_function_prototype_object_call, NON_FIXED, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_BIND, ecma_builtin_function_prototype_object_bind, NON_FIXED, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
77
src/libecmabuiltins/ecma-builtin-function.c
Normal file
77
src/libecmabuiltins/ecma-builtin-function.c
Normal file
@ -0,0 +1,77 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID function
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup function ECMA Function object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Function object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_builtin_function_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_function_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Function object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_function_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_function_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
64
src/libecmabuiltins/ecma-builtin-function.inc.h
Normal file
64
src/libecmabuiltins/ecma-builtin-function.inc.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Function built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_FUNCTION)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.3.3.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.3.3.2
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@ -1,555 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup global ECMA Global object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Global object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_global_property_names[] =
|
||||
{
|
||||
ECMA_MAGIC_STRING_EVAL,
|
||||
ECMA_MAGIC_STRING_UNDEFINED,
|
||||
ECMA_MAGIC_STRING_NAN,
|
||||
ECMA_MAGIC_STRING_INFINITY_UL,
|
||||
ECMA_MAGIC_STRING_OBJECT_UL,
|
||||
ECMA_MAGIC_STRING_FUNCTION_UL,
|
||||
ECMA_MAGIC_STRING_ARRAY_UL,
|
||||
ECMA_MAGIC_STRING_STRING_UL,
|
||||
ECMA_MAGIC_STRING_BOOLEAN_UL,
|
||||
ECMA_MAGIC_STRING_NUMBER_UL,
|
||||
ECMA_MAGIC_STRING_DATE_UL,
|
||||
ECMA_MAGIC_STRING_REG_EXP_UL,
|
||||
ECMA_MAGIC_STRING_ERROR_UL,
|
||||
ECMA_MAGIC_STRING_EVAL_ERROR_UL,
|
||||
ECMA_MAGIC_STRING_RANGE_ERROR_UL,
|
||||
ECMA_MAGIC_STRING_REFERENCE_ERROR_UL,
|
||||
ECMA_MAGIC_STRING_SYNTAX_ERROR_UL,
|
||||
ECMA_MAGIC_STRING_TYPE_ERROR_UL,
|
||||
ECMA_MAGIC_STRING_URI_ERROR_UL,
|
||||
ECMA_MAGIC_STRING_MATH_UL,
|
||||
ECMA_MAGIC_STRING_JSON_U,
|
||||
ECMA_MAGIC_STRING_PARSE_INT,
|
||||
ECMA_MAGIC_STRING_PARSE_FLOAT,
|
||||
ECMA_MAGIC_STRING_IS_NAN,
|
||||
ECMA_MAGIC_STRING_IS_FINITE,
|
||||
ECMA_MAGIC_STRING_DECODE_URI,
|
||||
ECMA_MAGIC_STRING_DECODE_URI_COMPONENT,
|
||||
ECMA_MAGIC_STRING_ENCODE_URI,
|
||||
ECMA_MAGIC_STRING_ENCODE_URI_COMPONENT,
|
||||
#ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
ECMA_MAGIC_STRING_COMPACT_PROFILE_ERROR_UL
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
};
|
||||
|
||||
#define ECMA_BUILTIN_GLOBAL_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_EVAL, \
|
||||
ecma_builtin_global_object_eval, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_PARSE_FLOAT, \
|
||||
ecma_builtin_global_object_parse_float, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_IS_NAN, \
|
||||
ecma_builtin_global_object_is_nan, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_IS_FINITE, \
|
||||
ecma_builtin_global_object_is_finite, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_DECODE_URI, \
|
||||
ecma_builtin_global_object_decode_uri, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_DECODE_URI_COMPONENT, \
|
||||
ecma_builtin_global_object_decode_uri_component, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_ENCODE_URI, \
|
||||
ecma_builtin_global_object_encode_uri, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_ENCODE_URI_COMPONENT, \
|
||||
ecma_builtin_global_object_encode_uri_component, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_PARSE_INT, \
|
||||
ecma_builtin_global_object_parse_int, \
|
||||
2, \
|
||||
2)
|
||||
|
||||
/**
|
||||
* Number of the Global object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_global_property_number = (sizeof (ecma_builtin_global_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
JERRY_STATIC_ASSERT (sizeof (ecma_builtin_global_property_names) > sizeof (void*));
|
||||
|
||||
/**
|
||||
* The Global object's 'eval' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (x);
|
||||
} /* ecma_builtin_global_object_eval */
|
||||
|
||||
/**
|
||||
* The Global object's 'parseInt' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_parse_int (ecma_value_t string, /**< routine's first argument */
|
||||
ecma_value_t radix) /**< routine's second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (string, radix);
|
||||
} /* ecma_builtin_global_object_parse_int */
|
||||
|
||||
/**
|
||||
* The Global object's 'parseFloat' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_parse_float (ecma_value_t string) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (string);
|
||||
} /* ecma_builtin_global_object_parse_float */
|
||||
|
||||
/**
|
||||
* The Global object's 'isNaN' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_is_nan (ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (num_value, ecma_op_to_number (arg), ret_value);
|
||||
|
||||
ecma_number_t *num_p = ECMA_GET_POINTER (num_value.u.value.value);
|
||||
|
||||
bool is_nan = ecma_number_is_nan (*num_p);
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_nan ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
|
||||
ECMA_FINALIZE (num_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_global_object_is_nan */
|
||||
|
||||
/**
|
||||
* The Global object's 'isFinite' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_is_finite (ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (num_value, ecma_op_to_number (arg), ret_value);
|
||||
|
||||
ecma_number_t *num_p = ECMA_GET_POINTER (num_value.u.value.value);
|
||||
|
||||
bool is_finite = !(ecma_number_is_nan (*num_p)
|
||||
|| ecma_number_is_infinity (*num_p));
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_finite ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
|
||||
ECMA_FINALIZE (num_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_global_object_is_finite */
|
||||
|
||||
/**
|
||||
* The Global object's 'decodeURI' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.3.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_decode_uri (ecma_value_t encoded_uri) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (encoded_uri);
|
||||
} /* ecma_builtin_global_object_decode_uri */
|
||||
|
||||
/**
|
||||
* The Global object's 'decodeURIComponent' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.3.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_decode_uri_component (ecma_value_t encoded_uri_component) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (encoded_uri_component);
|
||||
} /* ecma_builtin_global_object_decode_uri_component */
|
||||
|
||||
/**
|
||||
* The Global object's 'encodeURI' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.3.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_encode_uri (ecma_value_t uri) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (uri);
|
||||
} /* ecma_builtin_global_object_encode_uri */
|
||||
|
||||
/**
|
||||
* The Global object's 'encodeURIComponent' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.3.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_encode_uri_component (ecma_value_t uri_component) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (uri_component);
|
||||
} /* ecma_builtin_global_object_encode_uri_component */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Global object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_global_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< Global object's
|
||||
built-in routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_1 ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_GLOBAL_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_global_dispatch_routine */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Global object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_global_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_GLOBAL));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_global_property_names,
|
||||
ecma_builtin_global_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint32_t) * JERRY_BITSINBYTE);
|
||||
|
||||
ecma_internal_property_id_t mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
uint32_t bit = (uint32_t) 1u << index;
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_GLOBAL, \
|
||||
id, \
|
||||
length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_GLOBAL_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
|
||||
case ECMA_MAGIC_STRING_UNDEFINED:
|
||||
{
|
||||
value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_NAN:
|
||||
{
|
||||
ecma_number_t *num_p = ecma_alloc_number ();
|
||||
*num_p = ecma_number_make_nan ();
|
||||
|
||||
value = ecma_make_number_value (num_p);
|
||||
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_INFINITY_UL:
|
||||
{
|
||||
ecma_number_t *num_p = ecma_alloc_number ();
|
||||
*num_p = ecma_number_make_infinity (false);
|
||||
|
||||
value = ecma_make_number_value (num_p);
|
||||
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_OBJECT_UL:
|
||||
{
|
||||
ecma_object_t *object_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT);
|
||||
|
||||
value = ecma_make_object_value (object_obj_p);
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_MATH_UL:
|
||||
{
|
||||
ecma_object_t *object_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_MATH);
|
||||
|
||||
value = ecma_make_object_value (object_obj_p);
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_STRING_UL:
|
||||
{
|
||||
ecma_object_t *string_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_STRING);
|
||||
|
||||
value = ecma_make_object_value (string_obj_p);
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_BOOLEAN_UL:
|
||||
{
|
||||
ecma_object_t *boolean_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN);
|
||||
|
||||
value = ecma_make_object_value (boolean_obj_p);
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_NUMBER_UL:
|
||||
{
|
||||
ecma_object_t *number_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER);
|
||||
|
||||
value = ecma_make_object_value (number_obj_p);
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_ARRAY_UL:
|
||||
{
|
||||
ecma_object_t *array_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY);
|
||||
|
||||
value = ecma_make_object_value (array_obj_p);
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_FUNCTION_UL:
|
||||
{
|
||||
ecma_object_t *function_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION);
|
||||
|
||||
value = ecma_make_object_value (function_obj_p);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
case ECMA_MAGIC_STRING_COMPACT_PROFILE_ERROR_UL:
|
||||
{
|
||||
ecma_object_t *compact_profile_error_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR);
|
||||
|
||||
value = ecma_make_object_value (compact_profile_error_obj_p);
|
||||
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
|
||||
case ECMA_MAGIC_STRING_DATE_UL:
|
||||
case ECMA_MAGIC_STRING_REG_EXP_UL:
|
||||
case ECMA_MAGIC_STRING_ERROR_UL:
|
||||
case ECMA_MAGIC_STRING_EVAL_ERROR_UL:
|
||||
case ECMA_MAGIC_STRING_RANGE_ERROR_UL:
|
||||
case ECMA_MAGIC_STRING_REFERENCE_ERROR_UL:
|
||||
case ECMA_MAGIC_STRING_SYNTAX_ERROR_UL:
|
||||
case ECMA_MAGIC_STRING_TYPE_ERROR_UL:
|
||||
case ECMA_MAGIC_STRING_URI_ERROR_UL:
|
||||
case ECMA_MAGIC_STRING_JSON_U:
|
||||
{
|
||||
#ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
/* The object throws CompactProfileError upon invocation */
|
||||
ecma_object_t *get_set_p = ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR);
|
||||
ecma_property_t *compact_profile_thrower_property_p = ecma_create_named_accessor_property (obj_p,
|
||||
prop_name_p,
|
||||
get_set_p,
|
||||
get_set_p,
|
||||
true,
|
||||
false);
|
||||
ecma_deref_object (get_set_p);
|
||||
|
||||
return compact_profile_thrower_property_p;
|
||||
#else /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_global_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
218
src/libecmabuiltins/ecma-builtin-global.c
Normal file
218
src/libecmabuiltins/ecma-builtin-global.c
Normal file
@ -0,0 +1,218 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-global.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID global
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup global ECMA Global object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Global object's 'eval' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_eval (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t x) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, x);
|
||||
} /* ecma_builtin_global_object_eval */
|
||||
|
||||
/**
|
||||
* The Global object's 'parseInt' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_parse_int (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t string, /**< routine's first argument */
|
||||
ecma_value_t radix) /**< routine's second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, string, radix);
|
||||
} /* ecma_builtin_global_object_parse_int */
|
||||
|
||||
/**
|
||||
* The Global object's 'parseFloat' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_parse_float (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t string) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, string);
|
||||
} /* ecma_builtin_global_object_parse_float */
|
||||
|
||||
/**
|
||||
* The Global object's 'isNaN' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_is_nan (ecma_value_t this_arg __unused, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (num_value, ecma_op_to_number (arg), ret_value);
|
||||
|
||||
ecma_number_t *num_p = ECMA_GET_POINTER (num_value.u.value.value);
|
||||
|
||||
bool is_nan = ecma_number_is_nan (*num_p);
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_nan ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
|
||||
ECMA_FINALIZE (num_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_global_object_is_nan */
|
||||
|
||||
/**
|
||||
* The Global object's 'isFinite' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.2.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_is_finite (ecma_value_t this_arg __unused, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (num_value, ecma_op_to_number (arg), ret_value);
|
||||
|
||||
ecma_number_t *num_p = ECMA_GET_POINTER (num_value.u.value.value);
|
||||
|
||||
bool is_finite = !(ecma_number_is_nan (*num_p)
|
||||
|| ecma_number_is_infinity (*num_p));
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_finite ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
|
||||
ECMA_FINALIZE (num_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_global_object_is_finite */
|
||||
|
||||
/**
|
||||
* The Global object's 'decodeURI' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.3.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_decode_uri (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t encoded_uri) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, encoded_uri);
|
||||
} /* ecma_builtin_global_object_decode_uri */
|
||||
|
||||
/**
|
||||
* The Global object's 'decodeURIComponent' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.3.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_decode_uri_component (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t encoded_uri_component) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, encoded_uri_component);
|
||||
} /* ecma_builtin_global_object_decode_uri_component */
|
||||
|
||||
/**
|
||||
* The Global object's 'encodeURI' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.3.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_encode_uri (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t uri) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, uri);
|
||||
} /* ecma_builtin_global_object_encode_uri */
|
||||
|
||||
/**
|
||||
* The Global object's 'encodeURIComponent' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.1.3.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_global_object_encode_uri_component (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t uri_component) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, uri_component);
|
||||
} /* ecma_builtin_global_object_encode_uri_component */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
221
src/libecmabuiltins/ecma-builtin-global.inc.h
Normal file
221
src/libecmabuiltins/ecma-builtin-global.inc.h
Normal file
@ -0,0 +1,221 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Global built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef SIMPLE_VALUE
|
||||
# define SIMPLE_VALUE(name, simple_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !SIMPLE_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef CP_UNIMPLEMENTED_VALUE
|
||||
# define CP_UNIMPLEMENTED_VALUE(name, value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !CP_UNIMPLEMENTED_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_GLOBAL)
|
||||
|
||||
/* Simple value properties:
|
||||
* (property name, simple value, writable, enumerable, configurable) */
|
||||
|
||||
// ECMA-262 v5, 15.1.1.3
|
||||
SIMPLE_VALUE (ECMA_MAGIC_STRING_UNDEFINED,
|
||||
ECMA_SIMPLE_VALUE_UNDEFINED,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// ECMA-262 v5, 15.1.1.1
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_NAN,
|
||||
ecma_number_make_nan (),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.1.2
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_INFINITY_UL,
|
||||
ecma_number_make_infinity (false),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// ECMA-262 v5, 15.1.4.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_OBJECT_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.2
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_FUNCTION_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.3
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_ARRAY_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.4
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_STRING_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_STRING),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.5
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_BOOLEAN_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.6
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_NUMBER_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.7
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_DATE_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_DATE),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.8
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_REG_EXP_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.9
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.10
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_EVAL_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_EVAL_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.11
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_RANGE_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_RANGE_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.12
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_REFERENCE_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REFERENCE_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.13
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_SYNTAX_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_SYNTAX_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.14
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_TYPE_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.15
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_URI_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_URI_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.5.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_MATH_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_MATH),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.5.2
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_JSON_U,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_JSON),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
#ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_COMPACT_PROFILE_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_EVAL, ecma_builtin_global_object_eval, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_PARSE_FLOAT, ecma_builtin_global_object_parse_float, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_IS_NAN, ecma_builtin_global_object_is_nan, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_IS_FINITE, ecma_builtin_global_object_is_finite, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_DECODE_URI, ecma_builtin_global_object_decode_uri, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_DECODE_URI_COMPONENT, ecma_builtin_global_object_decode_uri_component, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_ENCODE_URI, ecma_builtin_global_object_encode_uri, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_ENCODE_URI_COMPONENT, ecma_builtin_global_object_encode_uri_component, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_PARSE_INT, ecma_builtin_global_object_parse_int, 2, 2)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@ -0,0 +1,315 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BUILTIN_UNDERSCORED_ID
|
||||
# error "Please, define BUILTIN_UNDERSCORED_ID"
|
||||
#endif /* !BUILTIN_UNDERSCORED_ID */
|
||||
|
||||
#ifndef BUILTIN_INC_HEADER_NAME
|
||||
# error "Please, define BUILTIN_INC_HEADER_NAME"
|
||||
#endif /* !BUILTIN_INC_HEADER_NAME */
|
||||
|
||||
#define PASTE__(x, y) x ## y
|
||||
#define PASTE_(x, y) PASTE__ (x, y)
|
||||
#define PASTE(x, y) PASTE_ (x, y)
|
||||
|
||||
#define SORT_PROPERTY_NAMES_ROUTINE_NAME(builtin_underscored_id) \
|
||||
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _sort_property_names)
|
||||
#define TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME(builtin_underscored_id) \
|
||||
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _try_to_instantiate_property)
|
||||
#define DISPATCH_ROUTINE_ROUTINE_NAME(builtin_underscored_id) \
|
||||
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _dispatch_routine)
|
||||
|
||||
#define ROUTINE_ARG(n) , ecma_value_t arg ## n
|
||||
#define ROUTINE_ARG_LIST_0 ecma_value_t this
|
||||
#define ROUTINE_ARG_LIST_1 ROUTINE_ARG_LIST_0 ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1 ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2 ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED ROUTINE_ARG_LIST_0, ecma_value_t *arguments_list_p, ecma_length_t arguments_list_len
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
|
||||
static ecma_completion_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number);
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG
|
||||
|
||||
static ecma_magic_string_id_t ecma_builtin_property_names[] =
|
||||
{
|
||||
#define SIMPLE_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
|
||||
#define NUMBER_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
|
||||
#define CP_UNIMPLEMENTED_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
|
||||
#define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) name,
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
};
|
||||
|
||||
static const ecma_length_t ecma_builtin_property_number = (sizeof (ecma_builtin_property_names) /
|
||||
sizeof (ecma_builtin_property_names [0]));
|
||||
|
||||
/**
|
||||
* Sort builtin's property names array
|
||||
*/
|
||||
void
|
||||
SORT_PROPERTY_NAMES_ROUTINE_NAME (BUILTIN_UNDERSCORED_ID) (void)
|
||||
{
|
||||
bool swapped;
|
||||
|
||||
do
|
||||
{
|
||||
swapped = false;
|
||||
|
||||
for (ecma_length_t i = 1; i < ecma_builtin_property_number; i++)
|
||||
{
|
||||
if (ecma_builtin_property_names [i] < ecma_builtin_property_names [i - 1])
|
||||
{
|
||||
ecma_magic_string_id_t id_temp = ecma_builtin_property_names [i - 1];
|
||||
ecma_builtin_property_names [i - 1] = ecma_builtin_property_names [i];
|
||||
ecma_builtin_property_names [i] = id_temp;
|
||||
|
||||
swapped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (swapped);
|
||||
} /* SORT_PROPERTY_NAMES_ROUTINE_NAME */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the built-in object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME (BUILTIN_UNDERSCORED_ID) (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
#define OBJECT_ID(builtin_id) const ecma_builtin_id_t builtin_object_id = builtin_id;
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, builtin_object_id));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index;
|
||||
index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_property_names,
|
||||
sizeof (ecma_builtin_property_names) /
|
||||
sizeof (ecma_builtin_property_names [0]),
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable;
|
||||
ecma_property_enumerable_value_t enumerable;
|
||||
ecma_property_configurable_value_t configurable;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (builtin_object_id, \
|
||||
id, \
|
||||
length_prop_value); \
|
||||
\
|
||||
writable = ECMA_PROPERTY_WRITABLE; \
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE; \
|
||||
configurable = ECMA_PROPERTY_CONFIGURABLE; \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
#define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) case name: \
|
||||
{ \
|
||||
value = ecma_make_object_value (obj_getter); \
|
||||
writable = prop_writable; \
|
||||
enumerable = prop_enumerable; \
|
||||
configurable = prop_configurable; \
|
||||
break; \
|
||||
}
|
||||
#define SIMPLE_VALUE(name, simple_value, prop_writable, prop_enumerable, prop_configurable) case name: \
|
||||
{ \
|
||||
value = ecma_make_simple_value (simple_value); \
|
||||
\
|
||||
writable = prop_writable; \
|
||||
enumerable = prop_enumerable; \
|
||||
configurable = prop_configurable; \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
#define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable) case name: \
|
||||
{ \
|
||||
ecma_number_t *num_p = ecma_alloc_number (); \
|
||||
*num_p = number_value; \
|
||||
\
|
||||
value = ecma_make_number_value (num_p); \
|
||||
\
|
||||
writable = prop_writable; \
|
||||
enumerable = prop_enumerable; \
|
||||
configurable = prop_configurable; \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
#ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
#define CP_UNIMPLEMENTED_VALUE(name, value, prop_writable, prop_enumerable, prop_configurable) case name: \
|
||||
{ \
|
||||
/* The object throws CompactProfileError upon invocation */ \
|
||||
ecma_object_t *get_set_p = ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR); \
|
||||
ecma_property_t *compact_profile_thrower_property_p = ecma_create_named_accessor_property (obj_p, \
|
||||
prop_name_p, \
|
||||
get_set_p, \
|
||||
get_set_p, \
|
||||
true, \
|
||||
false); \
|
||||
ecma_deref_object (get_set_p); \
|
||||
\
|
||||
return compact_profile_thrower_property_p; \
|
||||
}
|
||||
#else /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
#define CP_UNIMPLEMENTED_VALUE(name) case name: \
|
||||
{ \
|
||||
JERRY_UNIMPLEMENTED ("The built-in is not implemented."); \
|
||||
}
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME */
|
||||
|
||||
/**
|
||||
* Dispatcher of the built-in's routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
DISPATCH_ROUTINE_ROUTINE_NAME (BUILTIN_UNDERSCORED_ID) (ecma_magic_string_id_t builtin_routine_id, /**< built-in's
|
||||
routine's
|
||||
name */
|
||||
ecma_value_t this_arg_value, /**< 'this' argument
|
||||
value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of
|
||||
arguments' list */
|
||||
{
|
||||
/* the arguments may be unused for some built-ins */
|
||||
(void) this_arg_value;
|
||||
(void) arguments_list;
|
||||
(void) arguments_number;
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] \
|
||||
: ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED))
|
||||
#define ROUTINE_ARG_LIST_0
|
||||
#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* DISPATCH_ROUTINE_ROUTINE_NAME */
|
||||
|
||||
#undef PASTE__
|
||||
#undef PASTE_
|
||||
#undef PASTE
|
||||
#undef SORT_PROPERTY_NAMES_ROUTINE_NAME
|
||||
#undef DISPATCH_ROUTINE_ROUTINE_NAME
|
||||
#undef TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME
|
||||
#undef BUILTIN_UNDERSCORED_ID
|
||||
#undef BUILTIN_INC_HEADER_NAME
|
||||
|
||||
@ -29,6 +29,10 @@
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-math.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID math
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
@ -39,117 +43,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Math object built-in value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_MATH_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_E_U, ECMA_NUMBER_E) \
|
||||
macro (ECMA_MAGIC_STRING_LN10_U, ECMA_NUMBER_LN10) \
|
||||
macro (ECMA_MAGIC_STRING_LN2_U, ECMA_NUMBER_LN2) \
|
||||
macro (ECMA_MAGIC_STRING_LOG2E_U, ECMA_NUMBER_LOG2E) \
|
||||
macro (ECMA_MAGIC_STRING_LOG10E_U, ECMA_NUMBER_LOG10E) \
|
||||
macro (ECMA_MAGIC_STRING_PI_U, ECMA_NUMBER_PI) \
|
||||
macro (ECMA_MAGIC_STRING_SQRT1_2_U, ECMA_NUMBER_SQRT_1_2) \
|
||||
macro (ECMA_MAGIC_STRING_SQRT2_U, ECMA_NUMBER_SQRT2)
|
||||
|
||||
/**
|
||||
* List of the Math object built-in routine properties in format
|
||||
* 'macro (name, C function name, arguments number of the routine, length value of the routine)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_MATH_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_ABS, \
|
||||
ecma_builtin_math_object_abs, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_ACOS, \
|
||||
ecma_builtin_math_object_acos, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_ASIN, \
|
||||
ecma_builtin_math_object_asin, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_ATAN, \
|
||||
ecma_builtin_math_object_atan, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_ATAN2, \
|
||||
ecma_builtin_math_object_atan2, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_CEIL, \
|
||||
ecma_builtin_math_object_ceil, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_COS, \
|
||||
ecma_builtin_math_object_cos, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_EXP, \
|
||||
ecma_builtin_math_object_exp, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_FLOOR, \
|
||||
ecma_builtin_math_object_floor, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_LOG, \
|
||||
ecma_builtin_math_object_log, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_MAX, \
|
||||
ecma_builtin_math_object_max, \
|
||||
NON_FIXED, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_MIN, \
|
||||
ecma_builtin_math_object_min, \
|
||||
NON_FIXED, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_POW, \
|
||||
ecma_builtin_math_object_pow, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_RANDOM, \
|
||||
ecma_builtin_math_object_random, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_ROUND, \
|
||||
ecma_builtin_math_object_round, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_SIN, \
|
||||
ecma_builtin_math_object_sin, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_SQRT, \
|
||||
ecma_builtin_math_object_sqrt, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_TAN, \
|
||||
ecma_builtin_math_object_tan, \
|
||||
1, \
|
||||
1)
|
||||
|
||||
/**
|
||||
* List of the Math object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_math_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_MATH_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_MATH_OBJECT_ROUTINES_PROPERTY_LIST (ROUTINE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the Math object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_math_property_number = (sizeof (ecma_builtin_math_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
JERRY_STATIC_ASSERT (sizeof (ecma_builtin_math_property_names) > sizeof (void*));
|
||||
|
||||
/**
|
||||
* The Math object's 'abs' routine
|
||||
*
|
||||
@ -160,7 +53,8 @@ JERRY_STATIC_ASSERT (sizeof (ecma_builtin_math_property_names) > sizeof (void*))
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_abs (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_abs (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
@ -198,9 +92,10 @@ ecma_builtin_math_object_abs (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_acos (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_acos (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_math_object_acos */
|
||||
|
||||
/**
|
||||
@ -213,9 +108,10 @@ ecma_builtin_math_object_acos (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_asin (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_asin (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_math_object_asin */
|
||||
|
||||
/**
|
||||
@ -228,9 +124,10 @@ ecma_builtin_math_object_asin (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_atan (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_atan (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_math_object_atan */
|
||||
|
||||
/**
|
||||
@ -243,10 +140,11 @@ ecma_builtin_math_object_atan (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_atan2 (ecma_value_t arg1, /**< first routine's argument */
|
||||
ecma_builtin_math_object_atan2 (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< first routine's argument */
|
||||
ecma_value_t arg2) /**< second routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg1, arg2);
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
|
||||
} /* ecma_builtin_math_object_atan2 */
|
||||
|
||||
/**
|
||||
@ -259,9 +157,10 @@ ecma_builtin_math_object_atan2 (ecma_value_t arg1, /**< first routine's argument
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_ceil (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_ceil (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_math_object_ceil */
|
||||
|
||||
/**
|
||||
@ -274,9 +173,10 @@ ecma_builtin_math_object_ceil (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_cos (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_cos (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_math_object_cos */
|
||||
|
||||
/**
|
||||
@ -289,7 +189,8 @@ ecma_builtin_math_object_cos (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_exp (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_exp (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
@ -342,9 +243,10 @@ ecma_builtin_math_object_exp (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_floor (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_floor (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_math_object_floor */
|
||||
|
||||
/**
|
||||
@ -357,7 +259,8 @@ ecma_builtin_math_object_floor (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_log (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_log (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
@ -407,7 +310,8 @@ ecma_builtin_math_object_log (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_max (ecma_value_t args[], /**< arguments list */
|
||||
ecma_builtin_math_object_max (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t args[], /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
@ -497,7 +401,8 @@ ecma_builtin_math_object_max (ecma_value_t args[], /**< arguments list */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_min (ecma_value_t args[], /**< arguments list */
|
||||
ecma_builtin_math_object_min (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t args[], /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
@ -587,7 +492,8 @@ ecma_builtin_math_object_min (ecma_value_t args[], /**< arguments list */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_pow (ecma_value_t arg1, /**< first routine's argument */
|
||||
ecma_builtin_math_object_pow (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< first routine's argument */
|
||||
ecma_value_t arg2) /**< second routine's argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
@ -827,7 +733,7 @@ ecma_builtin_math_object_pow (ecma_value_t arg1, /**< first routine's argument *
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_random (void)
|
||||
ecma_builtin_math_object_random (ecma_value_t this_arg __unused) /**< 'this' argument */
|
||||
{
|
||||
/* Implementation of George Marsaglia's XorShift random number generator */
|
||||
TODO (/* Check for license issues */);
|
||||
@ -868,7 +774,8 @@ ecma_builtin_math_object_random (void)
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_round (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_round (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
@ -925,9 +832,10 @@ ecma_builtin_math_object_round (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_sin (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_sin (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_math_object_sin */
|
||||
|
||||
/**
|
||||
@ -940,7 +848,8 @@ ecma_builtin_math_object_sin (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_sqrt (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_sqrt (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
@ -992,183 +901,12 @@ ecma_builtin_math_object_sqrt (ecma_value_t arg) /**< routine's argument */
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_math_object_tan (ecma_value_t arg) /**< routine's argument */
|
||||
ecma_builtin_math_object_tan (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_math_object_tan */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Math object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_math_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_MATH));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_math_property_names,
|
||||
ecma_builtin_math_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_MATH, id, length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_MATH_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_MATH_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
ecma_number_t *num_p = ecma_alloc_number ();
|
||||
value = ecma_make_number_value (num_p);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name: { *num_p = (ecma_number_t) value; break; }
|
||||
ECMA_BUILTIN_MATH_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_math_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Math object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_math_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< Object object's
|
||||
built-in routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_0
|
||||
#define ROUTINE_ARG_LIST_1 ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED arguments_list, arguments_number
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_MATH_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
#undef ROUTINE_ARG
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_math_dispatch_routine */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
128
src/libecmabuiltins/ecma-builtin-math.inc.h
Normal file
128
src/libecmabuiltins/ecma-builtin-math.inc.h
Normal file
@ -0,0 +1,128 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Math built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef SIMPLE_VALUE
|
||||
# define SIMPLE_VALUE(name, simple_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !SIMPLE_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_MATH)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// ECMA-262 v5, 15.8.1.1
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_E_U,
|
||||
ECMA_NUMBER_E,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.2
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LN10_U,
|
||||
ECMA_NUMBER_LN10,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.3
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LN2_U,
|
||||
ECMA_NUMBER_LN2,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.4
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LOG2E_U,
|
||||
ECMA_NUMBER_LOG2E,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.5
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LOG10E_U,
|
||||
ECMA_NUMBER_LOG10E,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.6
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_PI_U,
|
||||
ECMA_NUMBER_PI,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.7
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_SQRT1_2_U,
|
||||
ECMA_NUMBER_SQRT_1_2,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.8
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_SQRT2_U,
|
||||
ECMA_NUMBER_SQRT2,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_ABS, ecma_builtin_math_object_abs, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_ACOS, ecma_builtin_math_object_acos, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_ASIN, ecma_builtin_math_object_asin, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_ATAN, ecma_builtin_math_object_atan, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_ATAN2, ecma_builtin_math_object_atan2, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_CEIL, ecma_builtin_math_object_ceil, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_COS, ecma_builtin_math_object_cos, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_EXP, ecma_builtin_math_object_exp, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_FLOOR, ecma_builtin_math_object_floor, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_LOG, ecma_builtin_math_object_log, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_MAX, ecma_builtin_math_object_max, NON_FIXED, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_MIN, ecma_builtin_math_object_min, NON_FIXED, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_POW, ecma_builtin_math_object_pow, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_RANDOM, ecma_builtin_math_object_random, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_ROUND, ecma_builtin_math_object_round, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_SIN, ecma_builtin_math_object_sin, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_SQRT, ecma_builtin_math_object_sqrt, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TAN, ecma_builtin_math_object_tan, 1, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@ -1,273 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-number-object.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup number ECMA Number object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Number object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_NUMBER_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_PROTOTYPE, ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE))
|
||||
|
||||
#define ECMA_BUILTIN_NUMBER_OBJECT_NUMBER_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_LENGTH, 1) \
|
||||
macro (ECMA_MAGIC_STRING_NAN, ecma_number_make_nan ()) \
|
||||
macro (ECMA_MAGIC_STRING_MAX_VALUE_U, ECMA_NUMBER_MAX_VALUE) \
|
||||
macro (ECMA_MAGIC_STRING_MIN_VALUE_U, ECMA_NUMBER_MIN_VALUE) \
|
||||
macro (ECMA_MAGIC_STRING_POSITIVE_INFINITY_U, ecma_number_make_infinity (false)) \
|
||||
macro (ECMA_MAGIC_STRING_NEGATIVE_INFINITY_U, ecma_number_make_infinity (true))
|
||||
|
||||
/**
|
||||
* List of the Number object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_number_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_NUMBER_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_NUMBER_OBJECT_NUMBER_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the Number object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_number_property_number = (sizeof (ecma_builtin_number_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Number object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_number_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_NUMBER));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_number_property_names,
|
||||
ecma_builtin_number_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_NUMBER_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_NUMBER_OBJECT_NUMBER_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_NUMBER_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
#define CASE_NUMBER_VALUE_PROP_LIST(name, value_num) case name: { ecma_number_t *num_p = ecma_alloc_number (); \
|
||||
*num_p = (ecma_number_t) value_num; \
|
||||
value = ecma_make_number_value (num_p); break; }
|
||||
ECMA_BUILTIN_NUMBER_OBJECT_NUMBER_VALUES_PROPERTY_LIST (CASE_NUMBER_VALUE_PROP_LIST)
|
||||
#undef CASE_NUMBER_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_number_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Number object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_number_dispatch_routine (ecma_magic_string_id_t builtin_routine_id __unused, /**< Number object's
|
||||
built-in routine's
|
||||
name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [] __unused, /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number __unused) /**< length of arguments' list */
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
} /* ecma_builtin_number_dispatch_routine */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Number object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_number_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_number_t *zero_num_p = ecma_alloc_number ();
|
||||
*zero_num_p = ECMA_NUMBER_ZERO;
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (zero_num_p));
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_number (arguments_list_p [0]);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_number_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Number object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_number_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_number_t *zero_num_p = ecma_alloc_number ();
|
||||
*zero_num_p = ECMA_NUMBER_ZERO;
|
||||
|
||||
ecma_completion_value_t completion = ecma_op_create_number_object (ecma_make_number_value (zero_num_p));
|
||||
|
||||
ecma_dealloc_number (zero_num_p);
|
||||
|
||||
return completion;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_create_number_object (arguments_list_p[0]);
|
||||
}
|
||||
} /* ecma_builtin_number_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@ -1,431 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup numberprototype ECMA Number.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Number.prototype object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_NUMBER_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_CONSTRUCTOR, ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER))
|
||||
|
||||
/**
|
||||
* List of the Number.prototype object built-in routine properties in format
|
||||
* 'macro (name, C function name, arguments number of the routine, length value of the routine)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_NUMBER_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_TO_STRING_UL, \
|
||||
ecma_builtin_number_prototype_object_to_string, \
|
||||
NON_FIXED, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_VALUE_OF_UL, \
|
||||
ecma_builtin_number_prototype_object_value_of, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_TO_LOCALE_STRING_UL, \
|
||||
ecma_builtin_number_prototype_object_to_locale_string, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_TO_FIXED_UL, \
|
||||
ecma_builtin_number_prototype_object_to_fixed, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_TO_EXPONENTIAL_UL, \
|
||||
ecma_builtin_number_prototype_object_to_exponential, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_TO_PRECISION_UL, \
|
||||
ecma_builtin_number_prototype_object_to_precision, \
|
||||
1, \
|
||||
1)
|
||||
|
||||
/**
|
||||
* List of the Number.prototype object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_NUMBER_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_NUMBER_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (ROUTINE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the Number.prototype object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_number_prototype_property_number = (sizeof (ecma_builtin_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_string (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t* arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
ecma_number_t this_arg_number;
|
||||
|
||||
if (this.value_type == ECMA_TYPE_NUMBER)
|
||||
{
|
||||
ecma_number_t *this_arg_number_p = ECMA_GET_POINTER (this.value);
|
||||
|
||||
this_arg_number = *this_arg_number_p;
|
||||
}
|
||||
else if (this.value_type == ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (this.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
|
||||
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_NUMBER_UL)
|
||||
{
|
||||
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
|
||||
|
||||
ecma_number_t *prim_value_num_p = ECMA_GET_POINTER (prim_value_prop_p->u.internal_property.value);
|
||||
this_arg_number = *prim_value_num_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_string_t *ret_str_p = ecma_new_ecma_string_from_number (this_arg_number);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
|
||||
}
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arguments_list_p);
|
||||
}
|
||||
} /* ecma_builtin_number_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toLocaleString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_locale_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
return ecma_builtin_number_prototype_object_to_string (this, NULL, 0);
|
||||
} /* ecma_builtin_number_prototype_object_to_locale_string */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'valueOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_value_of (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
if (this.value_type == ECMA_TYPE_NUMBER)
|
||||
{
|
||||
return ecma_make_normal_completion_value (ecma_copy_value (this, true));
|
||||
}
|
||||
else if (this.value_type == ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (this.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
|
||||
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_NUMBER_UL)
|
||||
{
|
||||
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
|
||||
|
||||
ecma_number_t *prim_value_num_p = ECMA_GET_POINTER (prim_value_prop_p->u.internal_property.value);
|
||||
|
||||
ecma_number_t *ret_num_p = ecma_alloc_number ();
|
||||
*ret_num_p = *prim_value_num_p;
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p));
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
} /* ecma_builtin_number_prototype_object_value_of */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toFixed' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_number_prototype_object_to_fixed */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toExponential' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_exponential (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_number_prototype_object_to_exponential */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toPrecision' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.7
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_precision (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_number_prototype_object_to_precision */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Number.prototype object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_number_prototype_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_NUMBER_PROTOTYPE));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_property_names,
|
||||
ecma_builtin_number_prototype_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE, \
|
||||
id, \
|
||||
length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_NUMBER_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_NUMBER_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_NUMBER_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_number_prototype_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Number.prototype object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< Number.prototype
|
||||
object's built-in
|
||||
routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_0
|
||||
#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_NUMBER_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_number_prototype_dispatch_routine */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
208
src/libecmabuiltins/ecma-builtin-number-prototype.c
Normal file
208
src/libecmabuiltins/ecma-builtin-number-prototype.c
Normal file
@ -0,0 +1,208 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-number-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID number_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup numberprototype ECMA Number.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_string (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t* arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
ecma_number_t this_arg_number;
|
||||
|
||||
if (this.value_type == ECMA_TYPE_NUMBER)
|
||||
{
|
||||
ecma_number_t *this_arg_number_p = ECMA_GET_POINTER (this.value);
|
||||
|
||||
this_arg_number = *this_arg_number_p;
|
||||
}
|
||||
else if (this.value_type == ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (this.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
|
||||
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_NUMBER_UL)
|
||||
{
|
||||
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
|
||||
|
||||
ecma_number_t *prim_value_num_p = ECMA_GET_POINTER (prim_value_prop_p->u.internal_property.value);
|
||||
this_arg_number = *prim_value_num_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_string_t *ret_str_p = ecma_new_ecma_string_from_number (this_arg_number);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
|
||||
}
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arguments_list_p);
|
||||
}
|
||||
} /* ecma_builtin_number_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toLocaleString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_locale_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
return ecma_builtin_number_prototype_object_to_string (this, NULL, 0);
|
||||
} /* ecma_builtin_number_prototype_object_to_locale_string */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'valueOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_value_of (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
if (this.value_type == ECMA_TYPE_NUMBER)
|
||||
{
|
||||
return ecma_make_normal_completion_value (ecma_copy_value (this, true));
|
||||
}
|
||||
else if (this.value_type == ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (this.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
|
||||
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_NUMBER_UL)
|
||||
{
|
||||
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
|
||||
|
||||
ecma_number_t *prim_value_num_p = ECMA_GET_POINTER (prim_value_prop_p->u.internal_property.value);
|
||||
|
||||
ecma_number_t *ret_num_p = ecma_alloc_number ();
|
||||
*ret_num_p = *prim_value_num_p;
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p));
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
} /* ecma_builtin_number_prototype_object_value_of */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toFixed' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_number_prototype_object_to_fixed */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toExponential' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_exponential (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_number_prototype_object_to_exponential */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toPrecision' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.7
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_number_prototype_object_to_precision (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_number_prototype_object_to_precision */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
59
src/libecmabuiltins/ecma-builtin-number-prototype.inc.h
Normal file
59
src/libecmabuiltins/ecma-builtin-number-prototype.inc.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Number.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// ECMA-262 v5, 15.7.4.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_number_prototype_object_to_string, NON_FIXED, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_number_prototype_object_value_of, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_number_prototype_object_to_locale_string, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_FIXED_UL, ecma_builtin_number_prototype_object_to_fixed, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_EXPONENTIAL_UL, ecma_builtin_number_prototype_object_to_exponential, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_PRECISION_UL, ecma_builtin_number_prototype_object_to_precision, 1, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
105
src/libecmabuiltins/ecma-builtin-number.c
Normal file
105
src/libecmabuiltins/ecma-builtin-number.c
Normal file
@ -0,0 +1,105 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-number-object.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-number.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID number
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup number ECMA Number object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Number object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_number_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_number_t *zero_num_p = ecma_alloc_number ();
|
||||
*zero_num_p = ECMA_NUMBER_ZERO;
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (zero_num_p));
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_number (arguments_list_p [0]);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_number_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Number object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_number_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_number_t *zero_num_p = ecma_alloc_number ();
|
||||
*zero_num_p = ECMA_NUMBER_ZERO;
|
||||
|
||||
ecma_completion_value_t completion = ecma_op_create_number_object (ecma_make_number_value (zero_num_p));
|
||||
|
||||
ecma_dealloc_number (zero_num_p);
|
||||
|
||||
return completion;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_create_number_object (arguments_list_p[0]);
|
||||
}
|
||||
} /* ecma_builtin_number_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
95
src/libecmabuiltins/ecma-builtin-number.inc.h
Normal file
95
src/libecmabuiltins/ecma-builtin-number.inc.h
Normal file
@ -0,0 +1,95 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Number built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_NUMBER)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.7.3
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// 15.7.3.4
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_NAN,
|
||||
ecma_number_make_nan (),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// 15.7.3.2
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_MAX_VALUE_U,
|
||||
ECMA_NUMBER_MAX_VALUE,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// 15.7.3.3
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_MIN_VALUE_U,
|
||||
ECMA_NUMBER_MIN_VALUE,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// 15.7.3.5
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_POSITIVE_INFINITY_U,
|
||||
ecma_number_make_infinity (false),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
// 15.7.3.6
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_NEGATIVE_INFINITY_U,
|
||||
ecma_number_make_infinity (true),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.7.3.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@ -1,582 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup object ECMA Object object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Object object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_object_property_names[] =
|
||||
{
|
||||
ECMA_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_MAGIC_STRING_LENGTH,
|
||||
ECMA_MAGIC_STRING_GET_PROTOTYPE_OF_UL,
|
||||
ECMA_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL,
|
||||
ECMA_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL,
|
||||
ECMA_MAGIC_STRING_CREATE,
|
||||
ECMA_MAGIC_STRING_DEFINE_PROPERTY_UL,
|
||||
ECMA_MAGIC_STRING_DEFINE_PROPERTIES_UL,
|
||||
ECMA_MAGIC_STRING_SEAL,
|
||||
ECMA_MAGIC_STRING_FREEZE,
|
||||
ECMA_MAGIC_STRING_PREVENT_EXTENSIONS_UL,
|
||||
ECMA_MAGIC_STRING_IS_SEALED_UL,
|
||||
ECMA_MAGIC_STRING_IS_FROZEN_UL,
|
||||
ECMA_MAGIC_STRING_IS_EXTENSIBLE,
|
||||
ECMA_MAGIC_STRING_KEYS
|
||||
};
|
||||
|
||||
#define ECMA_BUILTIN_OBJECT_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_GET_PROTOTYPE_OF_UL, \
|
||||
ecma_builtin_object_object_get_prototype_of, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL, \
|
||||
ecma_builtin_object_object_get_own_property_names, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_SEAL, \
|
||||
ecma_builtin_object_object_seal, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_FREEZE, \
|
||||
ecma_builtin_object_object_freeze, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_PREVENT_EXTENSIONS_UL, \
|
||||
ecma_builtin_object_object_prevent_extensions, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_IS_SEALED_UL, \
|
||||
ecma_builtin_object_object_is_sealed, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_IS_FROZEN_UL, \
|
||||
ecma_builtin_object_object_is_frozen, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_IS_EXTENSIBLE, \
|
||||
ecma_builtin_object_object_is_extensible, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_KEYS, \
|
||||
ecma_builtin_object_object_keys, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, \
|
||||
ecma_builtin_object_object_get_own_property_descriptor, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_CREATE, \
|
||||
ecma_builtin_object_object_create, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_DEFINE_PROPERTIES_UL, \
|
||||
ecma_builtin_object_object_define_properties, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_DEFINE_PROPERTY_UL, \
|
||||
ecma_builtin_object_object_define_property, \
|
||||
3, \
|
||||
3) \
|
||||
|
||||
|
||||
/**
|
||||
* Number of the Object object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_object_property_number = (sizeof (ecma_builtin_object_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
JERRY_STATIC_ASSERT (sizeof (ecma_builtin_object_property_names) > sizeof (void*));
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Object object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_object_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
if (arguments_list_len == 0
|
||||
|| ecma_is_value_undefined (arguments_list_p[0])
|
||||
|| ecma_is_value_null (arguments_list_p [0]))
|
||||
{
|
||||
ret_value = ecma_builtin_object_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_object (arguments_list_p [0]);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Object object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_object_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_op_create_object_object_noarg ();
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_completion_value_t new_obj_value = ecma_op_create_object_object_arg (arguments_list_p [0]);
|
||||
|
||||
if (!ecma_is_completion_value_normal (new_obj_value))
|
||||
{
|
||||
return new_obj_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_normal_completion_value (new_obj_value.u.value);
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_object_dispatch_construct */
|
||||
|
||||
/**
|
||||
* The Object object's 'getPrototypeOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_get_prototype_of (ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
} /* ecma_builtin_object_object_get_prototype_of */
|
||||
|
||||
/**
|
||||
* The Object object's 'getOwnPropertyNames' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_get_own_property_names (ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
} /* ecma_builtin_object_object_get_own_property_names */
|
||||
|
||||
/**
|
||||
* The Object object's 'seal' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.8
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_seal (ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
} /* ecma_builtin_object_object_seal */
|
||||
|
||||
/**
|
||||
* The Object object's 'freeze' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.9
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_freeze (ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
} /* ecma_builtin_object_object_freeze */
|
||||
|
||||
/**
|
||||
* The Object object's 'preventExtensions' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.10
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_prevent_extensions (ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
} /* ecma_builtin_object_object_prevent_extensions */
|
||||
|
||||
/**
|
||||
* The Object object's 'isSealed' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.11
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_is_sealed (ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
} /* ecma_builtin_object_object_is_sealed */
|
||||
|
||||
/**
|
||||
* The Object object's 'isFrozen' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.12
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_is_frozen (ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
} /* ecma_builtin_object_object_is_frozen */
|
||||
|
||||
/**
|
||||
* The Object object's 'isExtensible' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.13
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_is_extensible (ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
} /* ecma_builtin_object_object_is_extensible */
|
||||
|
||||
/**
|
||||
* The Object object's 'keys' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.14
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_keys (ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg);
|
||||
} /* ecma_builtin_object_object_keys */
|
||||
|
||||
/**
|
||||
* The Object object's 'getOwnPropertyDescriptor' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_get_own_property_descriptor (ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg1, arg2);
|
||||
} /* ecma_builtin_object_object_get_own_property_descriptor */
|
||||
|
||||
/**
|
||||
* The Object object's 'create' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_create (ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg1, arg2);
|
||||
} /* ecma_builtin_object_object_create */
|
||||
|
||||
/**
|
||||
* The Object object's 'defineProperties' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.7
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_define_properties (ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (arg1, arg2);
|
||||
} /* ecma_builtin_object_object_define_properties */
|
||||
|
||||
/**
|
||||
* The Object object's 'defineProperty' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_define_property (ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2, /**< routine's second argument */
|
||||
ecma_value_t arg3) /**< routine's third argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
if (arg1.value_type != ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (arg1.value);
|
||||
|
||||
ECMA_TRY_CATCH (name_str_value,
|
||||
ecma_op_to_string (arg2),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *name_str_p = ECMA_GET_POINTER (name_str_value.u.value.value);
|
||||
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
ECMA_TRY_CATCH (conv_result,
|
||||
ecma_op_to_property_descriptor (arg3, &prop_desc),
|
||||
ret_value);
|
||||
|
||||
ECMA_TRY_CATCH (define_own_prop_ret,
|
||||
ecma_op_object_define_own_property (obj_p,
|
||||
name_str_p,
|
||||
prop_desc,
|
||||
true),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (ecma_copy_value (arg1, true));
|
||||
|
||||
ECMA_FINALIZE (define_own_prop_ret);
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
ECMA_FINALIZE (conv_result);
|
||||
ECMA_FINALIZE (name_str_value);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_define_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Object object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_object_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< Object object's
|
||||
built-in routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_1 ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_OBJECT_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_object_dispatch_routine */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Object object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_object_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_OBJECT));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_object_property_names,
|
||||
ecma_builtin_object_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint32_t) * JERRY_BITSINBYTE);
|
||||
|
||||
ecma_internal_property_id_t mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
uint32_t bit = (uint32_t) 1u << index;
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_OBJECT, \
|
||||
id, \
|
||||
length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_OBJECT_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
case ECMA_MAGIC_STRING_PROTOTYPE:
|
||||
{
|
||||
value = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE));
|
||||
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
break;
|
||||
}
|
||||
case ECMA_MAGIC_STRING_LENGTH:
|
||||
{
|
||||
ecma_number_t *num_p = ecma_alloc_number ();
|
||||
*num_p = ECMA_NUMBER_ONE;
|
||||
|
||||
value = ecma_make_number_value (num_p);
|
||||
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_object_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@ -1,434 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup objectprototype ECMA Object.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the Object.prototype object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_OBJECT_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_CONSTRUCTOR, ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT))
|
||||
|
||||
/**
|
||||
* List of the Object.prototype object built-in routine properties in format
|
||||
* 'macro (name, C function name, arguments number of the routine, length value of the routine)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_OBJECT_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_TO_STRING_UL, \
|
||||
ecma_builtin_object_prototype_object_to_string, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_VALUE_OF_UL, \
|
||||
ecma_builtin_object_prototype_object_value_of, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_TO_LOCALE_STRING_UL, \
|
||||
ecma_builtin_object_prototype_object_to_locale_string, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_HAS_OWN_PROPERTY_UL, \
|
||||
ecma_builtin_object_prototype_object_has_own_property, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_IS_PROTOTYPE_OF_UL, \
|
||||
ecma_builtin_object_prototype_object_is_prototype_of, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL, \
|
||||
ecma_builtin_object_prototype_object_property_is_enumerable, \
|
||||
1, \
|
||||
1)
|
||||
|
||||
/**
|
||||
* List of the Object.prototype object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_OBJECT_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_OBJECT_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (ROUTINE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the Object.prototype object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_object_prototype_property_number = (sizeof (ecma_builtin_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_to_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ecma_magic_string_id_t type_string;
|
||||
|
||||
if (ecma_is_value_undefined (this))
|
||||
{
|
||||
type_string = ECMA_MAGIC_STRING_UNDEFINED_UL;
|
||||
}
|
||||
else if (ecma_is_value_null (this))
|
||||
{
|
||||
type_string = ECMA_MAGIC_STRING_NULL_UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_completion_value_t obj_this = ecma_op_to_object (this);
|
||||
|
||||
if (!ecma_is_completion_value_normal (obj_this))
|
||||
{
|
||||
return obj_this;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (obj_this.u.value.value_type == ECMA_TYPE_OBJECT);
|
||||
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (obj_this.u.value.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
type_string = (ecma_magic_string_id_t) class_prop_p->u.internal_property.value;
|
||||
|
||||
ecma_free_completion_value (obj_this);
|
||||
}
|
||||
|
||||
/* Building string "[object #type#]" where type is 'Undefined',
|
||||
'Null' or one of possible object's classes.
|
||||
The string with null character is maximum 19 characters long. */
|
||||
const ssize_t buffer_size = 19;
|
||||
ecma_char_t str_buffer[buffer_size];
|
||||
|
||||
const ecma_char_t *left_square_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_LEFT_SQUARE_CHAR);
|
||||
const ecma_char_t *object_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_OBJECT);
|
||||
const ecma_char_t *space_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_SPACE_CHAR);
|
||||
const ecma_char_t *type_name_zt_str_p = ecma_get_magic_string_zt (type_string);
|
||||
const ecma_char_t *right_square_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_RIGHT_SQUARE_CHAR);
|
||||
|
||||
ecma_char_t *buffer_ptr = str_buffer;
|
||||
ssize_t buffer_size_left = buffer_size;
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (left_square_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (object_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (space_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (type_name_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (right_square_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
|
||||
JERRY_ASSERT (buffer_size_left >= 0);
|
||||
|
||||
ecma_string_t *ret_string_p = ecma_new_ecma_string (str_buffer);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_string_value (ret_string_p));
|
||||
} /* ecma_builtin_object_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'valueOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_value_of (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
return ecma_op_to_object (this);
|
||||
} /* ecma_builtin_object_prototype_object_value_of */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'toLocaleString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_to_locale_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this);
|
||||
} /* ecma_builtin_object_prototype_object_to_locale_string */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'hasOwnProperty' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_has_own_property (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_object_prototype_object_has_own_property */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'isPrototypeOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_is_prototype_of (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_object_prototype_object_is_prototype_of */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'propertyIsEnumerable' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.7
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_property_is_enumerable (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_object_prototype_object_property_is_enumerable */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the Object.prototype object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_object_prototype_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_OBJECT_PROTOTYPE));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_property_names,
|
||||
ecma_builtin_object_prototype_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, \
|
||||
id, \
|
||||
length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_OBJECT_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_OBJECT_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_OBJECT_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_object_prototype_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the Object.prototype object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< Object.prototype
|
||||
object's built-in
|
||||
routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_0
|
||||
#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_OBJECT_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_object_prototype_dispatch_routine */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
211
src/libecmabuiltins/ecma-builtin-object-prototype.c
Normal file
211
src/libecmabuiltins/ecma-builtin-object-prototype.c
Normal file
@ -0,0 +1,211 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID object_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup objectprototype ECMA Object.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_to_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ecma_magic_string_id_t type_string;
|
||||
|
||||
if (ecma_is_value_undefined (this))
|
||||
{
|
||||
type_string = ECMA_MAGIC_STRING_UNDEFINED_UL;
|
||||
}
|
||||
else if (ecma_is_value_null (this))
|
||||
{
|
||||
type_string = ECMA_MAGIC_STRING_NULL_UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_completion_value_t obj_this = ecma_op_to_object (this);
|
||||
|
||||
if (!ecma_is_completion_value_normal (obj_this))
|
||||
{
|
||||
return obj_this;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (obj_this.u.value.value_type == ECMA_TYPE_OBJECT);
|
||||
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (obj_this.u.value.value);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
type_string = (ecma_magic_string_id_t) class_prop_p->u.internal_property.value;
|
||||
|
||||
ecma_free_completion_value (obj_this);
|
||||
}
|
||||
|
||||
/* Building string "[object #type#]" where type is 'Undefined',
|
||||
'Null' or one of possible object's classes.
|
||||
The string with null character is maximum 19 characters long. */
|
||||
const ssize_t buffer_size = 19;
|
||||
ecma_char_t str_buffer[buffer_size];
|
||||
|
||||
const ecma_char_t *left_square_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_LEFT_SQUARE_CHAR);
|
||||
const ecma_char_t *object_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_OBJECT);
|
||||
const ecma_char_t *space_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_SPACE_CHAR);
|
||||
const ecma_char_t *type_name_zt_str_p = ecma_get_magic_string_zt (type_string);
|
||||
const ecma_char_t *right_square_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_RIGHT_SQUARE_CHAR);
|
||||
|
||||
ecma_char_t *buffer_ptr = str_buffer;
|
||||
ssize_t buffer_size_left = buffer_size;
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (left_square_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (object_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (space_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (type_name_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
buffer_ptr = ecma_copy_zt_string_to_buffer (right_square_zt_str_p,
|
||||
buffer_ptr,
|
||||
buffer_size_left);
|
||||
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
|
||||
|
||||
JERRY_ASSERT (buffer_size_left >= 0);
|
||||
|
||||
ecma_string_t *ret_string_p = ecma_new_ecma_string (str_buffer);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_string_value (ret_string_p));
|
||||
} /* ecma_builtin_object_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'valueOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_value_of (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
return ecma_op_to_object (this);
|
||||
} /* ecma_builtin_object_prototype_object_value_of */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'toLocaleString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_to_locale_string (ecma_value_t this) /**< this argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this);
|
||||
} /* ecma_builtin_object_prototype_object_to_locale_string */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'hasOwnProperty' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_has_own_property (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_object_prototype_object_has_own_property */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'isPrototypeOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_is_prototype_of (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_object_prototype_object_is_prototype_of */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'propertyIsEnumerable' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.7
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_prototype_object_property_is_enumerable (ecma_value_t this, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this, arg);
|
||||
} /* ecma_builtin_object_prototype_object_property_is_enumerable */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
59
src/libecmabuiltins/ecma-builtin-object-prototype.inc.h
Normal file
59
src/libecmabuiltins/ecma-builtin-object-prototype.inc.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Object.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.2.4.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_object_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_object_prototype_object_value_of, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_object_prototype_object_to_locale_string, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_HAS_OWN_PROPERTY_UL, ecma_builtin_object_prototype_object_has_own_property, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_IS_PROTOTYPE_OF_UL, ecma_builtin_object_prototype_object_is_prototype_of, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL, ecma_builtin_object_prototype_object_property_is_enumerable, 1, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
358
src/libecmabuiltins/ecma-builtin-object.c
Normal file
358
src/libecmabuiltins/ecma-builtin-object.c
Normal file
@ -0,0 +1,358 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID object
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup object ECMA Object object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Object object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_object_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
if (arguments_list_len == 0
|
||||
|| ecma_is_value_undefined (arguments_list_p[0])
|
||||
|| ecma_is_value_null (arguments_list_p [0]))
|
||||
{
|
||||
ret_value = ecma_builtin_object_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_object (arguments_list_p [0]);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Object object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_object_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_op_create_object_object_noarg ();
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_completion_value_t new_obj_value = ecma_op_create_object_object_arg (arguments_list_p [0]);
|
||||
|
||||
if (!ecma_is_completion_value_normal (new_obj_value))
|
||||
{
|
||||
return new_obj_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_normal_completion_value (new_obj_value.u.value);
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_object_dispatch_construct */
|
||||
|
||||
/**
|
||||
* The Object object's 'getPrototypeOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_get_prototype_of (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_object_object_get_prototype_of */
|
||||
|
||||
/**
|
||||
* The Object object's 'getOwnPropertyNames' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_get_own_property_names (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_object_object_get_own_property_names */
|
||||
|
||||
/**
|
||||
* The Object object's 'seal' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.8
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_seal (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_object_object_seal */
|
||||
|
||||
/**
|
||||
* The Object object's 'freeze' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.9
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_freeze (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_object_object_freeze */
|
||||
|
||||
/**
|
||||
* The Object object's 'preventExtensions' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.10
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_prevent_extensions (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_object_object_prevent_extensions */
|
||||
|
||||
/**
|
||||
* The Object object's 'isSealed' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.11
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_is_sealed (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_object_object_is_sealed */
|
||||
|
||||
/**
|
||||
* The Object object's 'isFrozen' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.12
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_is_frozen (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_object_object_is_frozen */
|
||||
|
||||
/**
|
||||
* The Object object's 'isExtensible' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.13
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_is_extensible (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_object_object_is_extensible */
|
||||
|
||||
/**
|
||||
* The Object object's 'keys' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.14
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_keys (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
|
||||
} /* ecma_builtin_object_object_keys */
|
||||
|
||||
/**
|
||||
* The Object object's 'getOwnPropertyDescriptor' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_get_own_property_descriptor (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
|
||||
} /* ecma_builtin_object_object_get_own_property_descriptor */
|
||||
|
||||
/**
|
||||
* The Object object's 'create' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_create (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
|
||||
} /* ecma_builtin_object_object_create */
|
||||
|
||||
/**
|
||||
* The Object object's 'defineProperties' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.7
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_define_properties (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
|
||||
} /* ecma_builtin_object_object_define_properties */
|
||||
|
||||
/**
|
||||
* The Object object's 'defineProperty' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_object_object_define_property (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2, /**< routine's second argument */
|
||||
ecma_value_t arg3) /**< routine's third argument */
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
if (arg1.value_type != ECMA_TYPE_OBJECT)
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ECMA_GET_POINTER (arg1.value);
|
||||
|
||||
ECMA_TRY_CATCH (name_str_value,
|
||||
ecma_op_to_string (arg2),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *name_str_p = ECMA_GET_POINTER (name_str_value.u.value.value);
|
||||
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
ECMA_TRY_CATCH (conv_result,
|
||||
ecma_op_to_property_descriptor (arg3, &prop_desc),
|
||||
ret_value);
|
||||
|
||||
ECMA_TRY_CATCH (define_own_prop_ret,
|
||||
ecma_op_object_define_own_property (obj_p,
|
||||
name_str_p,
|
||||
prop_desc,
|
||||
true),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (ecma_copy_value (arg1, true));
|
||||
|
||||
ECMA_FINALIZE (define_own_prop_ret);
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
ECMA_FINALIZE (conv_result);
|
||||
ECMA_FINALIZE (name_str_value);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_define_property */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
80
src/libecmabuiltins/ecma-builtin-object.inc.h
Normal file
80
src/libecmabuiltins/ecma-builtin-object.inc.h
Normal file
@ -0,0 +1,80 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Object built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_OBJECT)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.2.3
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.2.3.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ecma_builtin_object_object_get_prototype_of, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL, ecma_builtin_object_object_get_own_property_names, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_SEAL, ecma_builtin_object_object_seal, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_FREEZE, ecma_builtin_object_object_freeze, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ecma_builtin_object_object_prevent_extensions, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_IS_SEALED_UL, ecma_builtin_object_object_is_sealed, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_IS_FROZEN_UL, ecma_builtin_object_object_is_frozen, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_IS_EXTENSIBLE, ecma_builtin_object_object_is_extensible, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_KEYS, ecma_builtin_object_object_keys, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, ecma_builtin_object_object_get_own_property_descriptor, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_CREATE, ecma_builtin_object_object_create, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_DEFINE_PROPERTIES_UL, ecma_builtin_object_object_define_properties, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_DEFINE_PROPERTY_UL, ecma_builtin_object_object_define_property, 3, 3)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@ -1,346 +0,0 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup string ECMA String object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the String object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_STRING_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_PROTOTYPE, ecma_builtin_get (ECMA_BUILTIN_ID_STRING_PROTOTYPE))
|
||||
|
||||
/**
|
||||
* List of the String object built-in routine properties in format
|
||||
* 'macro (name, C function name, arguments number of the routine, length value of the routine)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_STRING_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_FROM_CHAR_CODE_UL, \
|
||||
ecma_builtin_string_object_from_char_code, \
|
||||
NON_FIXED, \
|
||||
1)
|
||||
|
||||
/**
|
||||
* List of the String object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_string_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_STRING_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_STRING_OBJECT_ROUTINES_PROPERTY_LIST (ROUTINE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the String object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_string_property_number = (sizeof (ecma_builtin_string_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* The String object's 'fromCharCode' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.5.3.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_string_object_from_char_code (ecma_value_t args[], /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
size_t zt_str_buffer_size = sizeof (ecma_char_t) * (args_number + 1u);
|
||||
|
||||
ecma_char_t *ret_zt_str_p = mem_heap_alloc_block (zt_str_buffer_size,
|
||||
MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
ret_zt_str_p [args_number] = ECMA_CHAR_NULL;
|
||||
|
||||
for (ecma_length_t arg_index = 0;
|
||||
arg_index < args_number;
|
||||
arg_index++)
|
||||
{
|
||||
ECMA_TRY_CATCH (arg_num_value,
|
||||
ecma_op_to_number (args[arg_index]),
|
||||
ret_value);
|
||||
|
||||
JERRY_ASSERT (arg_num_value.u.value.value_type == ECMA_TYPE_NUMBER);
|
||||
ecma_number_t *arg_num_p = ECMA_GET_POINTER (arg_num_value.u.value.value);
|
||||
|
||||
uint32_t uint32_char_code = ecma_number_to_uint32 (*arg_num_p);
|
||||
uint16_t uint16_char_code = (uint16_t) uint32_char_code;
|
||||
|
||||
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
|
||||
if ((uint16_char_code >> JERRY_BITSINBYTE) != 0)
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_zt_str_p [arg_index] = (ecma_char_t) uint16_char_code;
|
||||
}
|
||||
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
|
||||
ret_zt_str_p [arg_index] = (ecma_char_t) uint16_char_code;
|
||||
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
|
||||
|
||||
ECMA_FINALIZE (arg_num_value);
|
||||
|
||||
if (ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
mem_heap_free_block (ret_zt_str_p);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
||||
}
|
||||
|
||||
ecma_string_t *ret_str_p = ecma_new_ecma_string (ret_zt_str_p);
|
||||
|
||||
mem_heap_free_block (ret_zt_str_p);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
|
||||
} /* ecma_builtin_string_object_from_char_code */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the String object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_string_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_STRING));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_string_property_names,
|
||||
ecma_builtin_string_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_STRING, id, length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_STRING_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_STRING_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_STRING_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_string_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the String object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_string_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< String object's
|
||||
built-in routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED arguments_list, arguments_number
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_STRING_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_string_dispatch_routine */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in String object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_string_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_string_t *str_p = ecma_new_ecma_string_from_magic_string_id (ECMA_MAGIC_STRING__EMPTY);
|
||||
ecma_value_t str_value = ecma_make_string_value (str_p);
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (str_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_string (arguments_list_p [0]);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_string_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in String object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_string_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_op_create_string_object (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_string_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@ -28,6 +28,10 @@
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID string_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
@ -38,113 +42,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* List of the String.prototype object built-in object value properties in format 'macro (name, value)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_STRING_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_CONSTRUCTOR, ecma_builtin_get (ECMA_BUILTIN_ID_STRING))
|
||||
|
||||
/**
|
||||
* List of the String.prototype object built-in routine properties in format
|
||||
* 'macro (name, C function name, arguments number of the routine, length value of the routine)'.
|
||||
*/
|
||||
#define ECMA_BUILTIN_STRING_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST(macro) \
|
||||
macro (ECMA_MAGIC_STRING_TO_STRING_UL, \
|
||||
ecma_builtin_string_prototype_object_to_string, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_VALUE_OF_UL, \
|
||||
ecma_builtin_string_prototype_object_value_of, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_CONCAT, \
|
||||
ecma_builtin_string_prototype_object_concat, \
|
||||
NON_FIXED, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_SLICE, \
|
||||
ecma_builtin_string_prototype_object_slice, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_INDEX_OF_UL, \
|
||||
ecma_builtin_string_prototype_object_index_of, \
|
||||
2, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_LAST_INDEX_OF_UL, \
|
||||
ecma_builtin_string_prototype_object_last_index_of, \
|
||||
2, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_CHAR_AT_UL, \
|
||||
ecma_builtin_string_prototype_object_char_at, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_CHAR_CODE_AT_UL, \
|
||||
ecma_builtin_string_prototype_object_char_code_at, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_LOCALE_COMPARE_UL, \
|
||||
ecma_builtin_string_prototype_object_locale_compare, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_MATCH, \
|
||||
ecma_builtin_string_prototype_object_match, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_REPLACE, \
|
||||
ecma_builtin_string_prototype_object_replace, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_SEARCH, \
|
||||
ecma_builtin_string_prototype_object_search, \
|
||||
1, \
|
||||
1) \
|
||||
macro (ECMA_MAGIC_STRING_SPLIT, \
|
||||
ecma_builtin_string_prototype_object_split, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_SUBSTRING, \
|
||||
ecma_builtin_string_prototype_object_substring, \
|
||||
2, \
|
||||
2) \
|
||||
macro (ECMA_MAGIC_STRING_TO_LOWER_CASE_UL, \
|
||||
ecma_builtin_string_prototype_object_to_lower_case, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_TO_LOCALE_LOWER_CASE_UL, \
|
||||
ecma_builtin_string_prototype_object_to_locale_lower_case, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_TO_UPPER_CASE_UL, \
|
||||
ecma_builtin_string_prototype_object_to_upper_case, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_TO_LOCALE_UPPER_CASE_UL, \
|
||||
ecma_builtin_string_prototype_object_to_locale_upper_case, \
|
||||
0, \
|
||||
0) \
|
||||
macro (ECMA_MAGIC_STRING_TRIM, \
|
||||
ecma_builtin_string_prototype_object_trim, \
|
||||
0, \
|
||||
0)
|
||||
|
||||
/**
|
||||
* List of the String.prototype object's built-in property names
|
||||
*/
|
||||
static const ecma_magic_string_id_t ecma_builtin_property_names[] =
|
||||
{
|
||||
#define VALUE_PROP_LIST(name, value) name,
|
||||
#define ROUTINE_PROP_LIST(name, c_function_name, args_number, length) name,
|
||||
ECMA_BUILTIN_STRING_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (VALUE_PROP_LIST)
|
||||
ECMA_BUILTIN_STRING_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (ROUTINE_PROP_LIST)
|
||||
#undef VALUE_PROP_LIST
|
||||
#undef ROUTINE_PROP_LIST
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of the String.prototype object's built-in properties
|
||||
*/
|
||||
static const ecma_length_t ecma_builtin_string_prototype_property_number = (sizeof (ecma_builtin_property_names) /
|
||||
sizeof (ecma_magic_string_id_t));
|
||||
|
||||
/**
|
||||
* The String.prototype object's 'toString' routine
|
||||
*
|
||||
@ -472,178 +369,6 @@ ecma_builtin_string_prototype_object_trim (ecma_value_t this) /**< this argument
|
||||
ECMA_BUILTIN_CP_UNIMPLEMENTED (this);
|
||||
} /* ecma_builtin_string_prototype_object_trim */
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the String.prototype object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_builtin_string_prototype_try_to_instantiate_property (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *prop_name_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_STRING_PROTOTYPE));
|
||||
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
|
||||
|
||||
ecma_magic_string_id_t id;
|
||||
|
||||
if (!ecma_is_string_magic (prop_name_p, &id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_property_names,
|
||||
ecma_builtin_string_prototype_property_number,
|
||||
id);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
|
||||
|
||||
uint32_t bit;
|
||||
ecma_internal_property_id_t mask_prop_id;
|
||||
|
||||
if (index >= 32)
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
|
||||
bit = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
|
||||
bit = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
|
||||
mask_prop_p->u.internal_property.value = 0;
|
||||
}
|
||||
|
||||
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
|
||||
|
||||
if (bit_mask & bit)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bit_mask |= bit;
|
||||
|
||||
mask_prop_p->u.internal_property.value = bit_mask;
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_property_writable_value_t writable = ECMA_PROPERTY_WRITABLE;
|
||||
ecma_property_enumerable_value_t enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
ecma_property_configurable_value_t configurable = ECMA_PROPERTY_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) case name: \
|
||||
{ \
|
||||
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (ECMA_BUILTIN_ID_STRING_PROTOTYPE, \
|
||||
id, \
|
||||
length); \
|
||||
\
|
||||
value = ecma_make_object_value (func_obj_p); \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
ECMA_BUILTIN_STRING_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#define CASE_VALUE_PROP_LIST(name, value) case name:
|
||||
ECMA_BUILTIN_STRING_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_VALUE_PROP_LIST)
|
||||
#undef CASE_VALUE_PROP_LIST
|
||||
{
|
||||
writable = ECMA_PROPERTY_NOT_WRITABLE;
|
||||
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE;
|
||||
configurable = ECMA_PROPERTY_NOT_CONFIGURABLE;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
#define CASE_OBJECT_VALUE_PROP_LIST(name, value_obj) case name: { value = ecma_make_object_value (value_obj); break; }
|
||||
ECMA_BUILTIN_STRING_PROTOTYPE_OBJECT_OBJECT_VALUES_PROPERTY_LIST (CASE_OBJECT_VALUE_PROP_LIST)
|
||||
#undef CASE_OBJECT_VALUE_PROP_LIST
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
|
||||
prop_name_p,
|
||||
writable,
|
||||
enumerable,
|
||||
configurable);
|
||||
|
||||
prop_p->u.named_data_property.value = ecma_copy_value (value, false);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_value (obj_p,
|
||||
prop_p->u.named_data_property.value);
|
||||
|
||||
ecma_free_value (value, true);
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_string_prototype_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* Dispatcher of the String.prototype object's built-in routines
|
||||
*
|
||||
* @return completion-value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_string_prototype_dispatch_routine (ecma_magic_string_id_t builtin_routine_id, /**< String.prototype
|
||||
object's built-in
|
||||
routine's name */
|
||||
ecma_value_t this_arg_value __unused, /**< 'this' argument value */
|
||||
ecma_value_t arguments_list [], /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] : value_undefined)
|
||||
#define ROUTINE_ARG_LIST_0
|
||||
#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number
|
||||
#define CASE_ROUTINE_PROP_LIST(name, c_function_name, args_number, length) \
|
||||
case name: \
|
||||
{ \
|
||||
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
ECMA_BUILTIN_STRING_PROTOTYPE_OBJECT_ROUTINES_PROPERTY_LIST (CASE_ROUTINE_PROP_LIST)
|
||||
#undef CASE_ROUTINE_PROP_LIST
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_string_prototype_dispatch_routine */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
72
src/libecmabuiltins/ecma-builtin-string-prototype.inc.h
Normal file
72
src/libecmabuiltins/ecma-builtin-string-prototype.inc.h
Normal file
@ -0,0 +1,72 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* String.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_STRING_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.5.4.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_STRING),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_string_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_string_prototype_object_value_of, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_CONCAT, ecma_builtin_string_prototype_object_concat, NON_FIXED, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_SLICE, ecma_builtin_string_prototype_object_slice, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_INDEX_OF_UL, ecma_builtin_string_prototype_object_index_of, 2, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_LAST_INDEX_OF_UL, ecma_builtin_string_prototype_object_last_index_of, 2, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_CHAR_AT_UL, ecma_builtin_string_prototype_object_char_at, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_CHAR_CODE_AT_UL, ecma_builtin_string_prototype_object_char_code_at, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_LOCALE_COMPARE_UL, ecma_builtin_string_prototype_object_locale_compare, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_MATCH, ecma_builtin_string_prototype_object_match, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_REPLACE, ecma_builtin_string_prototype_object_replace, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_SEARCH, ecma_builtin_string_prototype_object_search, 1, 1)
|
||||
ROUTINE (ECMA_MAGIC_STRING_SPLIT, ecma_builtin_string_prototype_object_split, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_SUBSTRING, ecma_builtin_string_prototype_object_substring, 2, 2)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_LOWER_CASE_UL, ecma_builtin_string_prototype_object_to_lower_case, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_LOCALE_LOWER_CASE_UL, ecma_builtin_string_prototype_object_to_locale_lower_case, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_UPPER_CASE_UL, ecma_builtin_string_prototype_object_to_upper_case, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TO_LOCALE_UPPER_CASE_UL, ecma_builtin_string_prototype_object_to_locale_upper_case, 0, 0)
|
||||
ROUTINE (ECMA_MAGIC_STRING_TRIM, ecma_builtin_string_prototype_object_trim, 0, 0)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
159
src/libecmabuiltins/ecma-builtin-string.c
Normal file
159
src/libecmabuiltins/ecma-builtin-string.c
Normal file
@ -0,0 +1,159 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "globals.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID string
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup string ECMA String object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The String object's 'fromCharCode' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.5.3.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_string_object_from_char_code (ecma_value_t this_arg __unused, /**< 'this' argument */
|
||||
ecma_value_t args[], /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
size_t zt_str_buffer_size = sizeof (ecma_char_t) * (args_number + 1u);
|
||||
|
||||
ecma_char_t *ret_zt_str_p = mem_heap_alloc_block (zt_str_buffer_size,
|
||||
MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
ret_zt_str_p [args_number] = ECMA_CHAR_NULL;
|
||||
|
||||
for (ecma_length_t arg_index = 0;
|
||||
arg_index < args_number;
|
||||
arg_index++)
|
||||
{
|
||||
ECMA_TRY_CATCH (arg_num_value,
|
||||
ecma_op_to_number (args[arg_index]),
|
||||
ret_value);
|
||||
|
||||
JERRY_ASSERT (arg_num_value.u.value.value_type == ECMA_TYPE_NUMBER);
|
||||
ecma_number_t *arg_num_p = ECMA_GET_POINTER (arg_num_value.u.value.value);
|
||||
|
||||
uint32_t uint32_char_code = ecma_number_to_uint32 (*arg_num_p);
|
||||
uint16_t uint16_char_code = (uint16_t) uint32_char_code;
|
||||
|
||||
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
|
||||
if ((uint16_char_code >> JERRY_BITSINBYTE) != 0)
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_zt_str_p [arg_index] = (ecma_char_t) uint16_char_code;
|
||||
}
|
||||
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
|
||||
ret_zt_str_p [arg_index] = (ecma_char_t) uint16_char_code;
|
||||
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
|
||||
|
||||
ECMA_FINALIZE (arg_num_value);
|
||||
|
||||
if (ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
mem_heap_free_block (ret_zt_str_p);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
||||
}
|
||||
|
||||
ecma_string_t *ret_str_p = ecma_new_ecma_string (ret_zt_str_p);
|
||||
|
||||
mem_heap_free_block (ret_zt_str_p);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
|
||||
} /* ecma_builtin_string_object_from_char_code */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in String object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_string_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_string_t *str_p = ecma_new_ecma_string_from_magic_string_id (ECMA_MAGIC_STRING__EMPTY);
|
||||
ecma_value_t str_value = ecma_make_string_value (str_p);
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (str_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_string (arguments_list_p [0]);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_string_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in String object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_string_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_op_create_string_object (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_string_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
68
src/libecmabuiltins/ecma-builtin-string.inc.h
Normal file
68
src/libecmabuiltins/ecma-builtin-string.inc.h
Normal file
@ -0,0 +1,68 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* String built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_STRING)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.5.3
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.7.3.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_STRING_PROTOTYPE),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (ECMA_MAGIC_STRING_FROM_CHAR_CODE_UL, ecma_builtin_string_object_from_char_code, NON_FIXED, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@ -154,7 +154,9 @@ ecma_builtin_ ## lowercase_name ## _dispatch_routine (ecma_magic_string_id_t bui
|
||||
ecma_length_t arguments_number); \
|
||||
extern ecma_property_t* \
|
||||
ecma_builtin_ ## lowercase_name ## _try_to_instantiate_property (ecma_object_t *obj_p, \
|
||||
ecma_string_t *prop_name_p);
|
||||
ecma_string_t *prop_name_p); \
|
||||
extern void \
|
||||
ecma_builtin_ ## lowercase_name ## _sort_property_names (void);
|
||||
|
||||
ECMA_BUILTIN_LIST (DECLARE_DISPATCH_ROUTINES)
|
||||
|
||||
|
||||
@ -180,6 +180,7 @@ ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
|
||||
case ECMA_BUILTIN_ID_ ## builtin_id: \
|
||||
{ \
|
||||
JERRY_ASSERT (ecma_builtin_objects [ECMA_BUILTIN_ID_ ## builtin_id] == NULL); \
|
||||
ecma_builtin_ ## lowercase_name ## _sort_property_names (); \
|
||||
\
|
||||
ecma_object_t *prototype_obj_p; \
|
||||
if (object_prototype_builtin_id == ECMA_BUILTIN_ID__COUNT) \
|
||||
@ -211,7 +212,9 @@ ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
JERRY_ASSERT (id < ECMA_BUILTIN_ID__COUNT);
|
||||
|
||||
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
|
||||
}
|
||||
}
|
||||
} /* ecma_instantiate_builtin */
|
||||
|
||||
@ -46,7 +46,7 @@ typedef enum
|
||||
ECMA_BUILTIN_ID_REFERENCE_ERROR, /**< the ReferenceError object (15.11.6.3) */
|
||||
ECMA_BUILTIN_ID_SYNTAX_ERROR, /**< the SyntaxError object (15.11.6.4) */
|
||||
ECMA_BUILTIN_ID_TYPE_ERROR, /**< the SyntaxError object (15.11.6.5) */
|
||||
ECMA_BUILTIN_ID_SYNTAX_URI_ERROR, /**< the URIError object (15.11.6.6) */
|
||||
ECMA_BUILTIN_ID_URI_ERROR, /**< the URIError object (15.11.6.6) */
|
||||
ECMA_BUILTIN_ID_MATH, /**< the Math object (15.8) */
|
||||
ECMA_BUILTIN_ID_JSON, /**< the JSON object (15.12) */
|
||||
#ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user