Renaming core -> jerry-core.
This commit is contained in:
@@ -0,0 +1,462 @@
|
||||
/* Copyright 2014-2015 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-array-object.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-number-arithmetic.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaarrayobject ECMA Array object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Reject sequence
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_reject (bool is_throw) /**< Throw flag */
|
||||
{
|
||||
if (is_throw)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
} /* ecma_reject */
|
||||
|
||||
/**
|
||||
* Array object creation operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 15.4.2.1
|
||||
* ECMA-262 v5, 15.4.2.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_create_array_object (const ecma_value_t *arguments_list_p, /**< list of arguments that
|
||||
are passed to Array constructor */
|
||||
ecma_length_t arguments_list_len, /**< length of the arguments' list */
|
||||
bool is_treat_single_arg_as_length) /**< if the value is true,
|
||||
arguments_list_len is 1
|
||||
and single argument is Number,
|
||||
then treat the single argument
|
||||
as new Array's length rather
|
||||
than as single item of the Array */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0
|
||||
|| arguments_list_p != NULL);
|
||||
|
||||
uint32_t length;
|
||||
const ecma_value_t *array_items_p;
|
||||
ecma_length_t array_items_count;
|
||||
|
||||
if (is_treat_single_arg_as_length
|
||||
&& arguments_list_len == 1
|
||||
&& ecma_is_value_number (arguments_list_p[0]))
|
||||
{
|
||||
ecma_number_t *num_p = ecma_get_number_from_value (arguments_list_p[0]);
|
||||
uint32_t num_uint32 = ecma_number_to_uint32 (*num_p);
|
||||
if (*num_p != ecma_uint32_to_number (num_uint32))
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_RANGE));
|
||||
}
|
||||
else
|
||||
{
|
||||
length = num_uint32;
|
||||
array_items_p = NULL;
|
||||
array_items_count = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
length = arguments_list_len;
|
||||
array_items_p = arguments_list_p;
|
||||
array_items_count = arguments_list_len;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
|
||||
ecma_object_t *array_prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE);
|
||||
#else /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN */
|
||||
ecma_object_t *array_prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN */
|
||||
|
||||
ecma_object_t *obj_p = ecma_create_object (array_prototype_obj_p, true, ECMA_OBJECT_TYPE_ARRAY);
|
||||
ecma_deref_object (array_prototype_obj_p);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_ARRAY_UL;
|
||||
|
||||
ecma_string_t *length_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
|
||||
ecma_number_t *length_num_p = ecma_alloc_number ();
|
||||
*length_num_p = ecma_uint32_to_number (length);
|
||||
|
||||
ecma_property_t *length_prop_p = ecma_create_named_data_property (obj_p,
|
||||
length_magic_string_p,
|
||||
true, false, false);
|
||||
ecma_set_named_data_property_value (length_prop_p, ecma_make_number_value (length_num_p));
|
||||
|
||||
ecma_deref_ecma_string (length_magic_string_p);
|
||||
|
||||
for (uint32_t index = 0;
|
||||
index < array_items_count;
|
||||
index++)
|
||||
{
|
||||
ecma_string_t* item_name_string_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
|
||||
ecma_property_descriptor_t item_prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
item_prop_desc.is_value_defined = true;
|
||||
item_prop_desc.value = array_items_p [index];
|
||||
|
||||
item_prop_desc.is_writable_defined = true;
|
||||
item_prop_desc.is_writable = true;
|
||||
|
||||
item_prop_desc.is_enumerable_defined = true;
|
||||
item_prop_desc.is_enumerable = true;
|
||||
|
||||
item_prop_desc.is_configurable_defined = true;
|
||||
item_prop_desc.is_configurable = true;
|
||||
}
|
||||
|
||||
ecma_op_object_define_own_property (obj_p,
|
||||
item_name_string_p,
|
||||
&item_prop_desc,
|
||||
false);
|
||||
|
||||
ecma_deref_ecma_string (item_name_string_p);
|
||||
}
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
|
||||
} /* ecma_op_create_array_object */
|
||||
|
||||
/**
|
||||
* [[DefineOwnProperty]] ecma array object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 15.4.5.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_array_object_define_own_property (ecma_object_t *obj_p, /**< the array object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
const ecma_property_descriptor_t* property_desc_p, /**< property descriptor */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY);
|
||||
|
||||
|
||||
// 1.
|
||||
ecma_string_t* magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
|
||||
ecma_property_t *len_prop_p = ecma_op_object_get_own_property (obj_p, magic_string_length_p);
|
||||
JERRY_ASSERT (len_prop_p != NULL && len_prop_p->type == ECMA_PROPERTY_NAMEDDATA);
|
||||
|
||||
// 2.
|
||||
ecma_value_t old_len_value = ecma_get_named_data_property_value (len_prop_p);
|
||||
|
||||
ecma_number_t *num_p = ecma_get_number_from_value (old_len_value);
|
||||
uint32_t old_len_uint32 = ecma_number_to_uint32 (*num_p);
|
||||
|
||||
// 3.
|
||||
bool is_property_name_equal_length = ecma_compare_ecma_strings (property_name_p,
|
||||
magic_string_length_p);
|
||||
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
|
||||
if (is_property_name_equal_length)
|
||||
{
|
||||
// a.
|
||||
if (!property_desc_p->is_value_defined)
|
||||
{
|
||||
// i.
|
||||
return ecma_op_general_object_define_own_property (obj_p, property_name_p, property_desc_p, is_throw);
|
||||
}
|
||||
|
||||
ecma_number_t new_len_num;
|
||||
|
||||
// c.
|
||||
ecma_completion_value_t completion = ecma_op_to_number (property_desc_p->value);
|
||||
if (ecma_is_completion_value_throw (completion))
|
||||
{
|
||||
return completion;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal (completion)
|
||||
&& ecma_is_value_number (ecma_get_completion_value_value (completion)));
|
||||
|
||||
new_len_num = *ecma_get_number_from_completion_value (completion);
|
||||
|
||||
ecma_free_completion_value (completion);
|
||||
|
||||
uint32_t new_len_uint32 = ecma_number_to_uint32 (new_len_num);
|
||||
|
||||
// d.
|
||||
if (ecma_uint32_to_number (new_len_uint32) != new_len_num)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_RANGE));
|
||||
}
|
||||
else
|
||||
{
|
||||
// b., e.
|
||||
ecma_number_t *new_len_num_p = ecma_alloc_number ();
|
||||
*new_len_num_p = new_len_num;
|
||||
|
||||
ecma_property_descriptor_t new_len_property_desc = *property_desc_p;
|
||||
new_len_property_desc.value = ecma_make_number_value (new_len_num_p);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
// f.
|
||||
if (new_len_uint32 >= old_len_uint32)
|
||||
{
|
||||
// i.
|
||||
magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
|
||||
ret_value = ecma_op_general_object_define_own_property (obj_p,
|
||||
magic_string_length_p,
|
||||
&new_len_property_desc,
|
||||
is_throw);
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
// g.
|
||||
if (!ecma_is_property_writable (len_prop_p))
|
||||
{
|
||||
ret_value = ecma_reject (is_throw);
|
||||
}
|
||||
else
|
||||
{
|
||||
// h.
|
||||
bool new_writable;
|
||||
if (!new_len_property_desc.is_writable_defined
|
||||
|| new_len_property_desc.is_writable)
|
||||
{
|
||||
new_writable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ii.
|
||||
new_writable = false;
|
||||
|
||||
// iii.
|
||||
new_len_property_desc.is_writable_defined = true;
|
||||
new_len_property_desc.is_writable = true;
|
||||
}
|
||||
|
||||
// j.
|
||||
magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
|
||||
ecma_completion_value_t succeeded = ecma_op_general_object_define_own_property (obj_p,
|
||||
magic_string_length_p,
|
||||
&new_len_property_desc,
|
||||
is_throw);
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
|
||||
/* Handling normal false and throw values */
|
||||
if (!ecma_is_completion_value_normal_true (succeeded))
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_false (succeeded)
|
||||
|| ecma_is_completion_value_throw (succeeded));
|
||||
|
||||
// k.
|
||||
ret_value = succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
// l
|
||||
JERRY_ASSERT (new_len_uint32 < old_len_uint32);
|
||||
|
||||
bool reduce_succeeded = true;
|
||||
|
||||
while (new_len_uint32 < old_len_uint32)
|
||||
{
|
||||
// i
|
||||
old_len_uint32--;
|
||||
|
||||
// ii
|
||||
ecma_string_t *old_length_string_p = ecma_new_ecma_string_from_uint32 (old_len_uint32);
|
||||
ecma_completion_value_t delete_succeeded = ecma_op_object_delete (obj_p,
|
||||
old_length_string_p,
|
||||
false);
|
||||
ecma_deref_ecma_string (old_length_string_p);
|
||||
|
||||
// iii
|
||||
if (ecma_is_completion_value_normal_false (delete_succeeded))
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_number (new_len_property_desc.value));
|
||||
|
||||
ecma_number_t *new_len_num_p = ecma_get_number_from_value (new_len_property_desc.value);
|
||||
|
||||
// 1.
|
||||
*new_len_num_p = ecma_uint32_to_number (old_len_uint32 + 1);
|
||||
|
||||
// 2.
|
||||
if (!new_writable)
|
||||
{
|
||||
new_len_property_desc.is_writable_defined = true;
|
||||
new_len_property_desc.is_writable = false;
|
||||
}
|
||||
|
||||
// 3.
|
||||
ecma_string_t *magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
|
||||
ecma_completion_value_t completion = ecma_op_general_object_define_own_property (obj_p,
|
||||
magic_string_length_p,
|
||||
&new_len_property_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)
|
||||
|| ecma_is_completion_value_normal_false (completion));
|
||||
|
||||
reduce_succeeded = false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!reduce_succeeded)
|
||||
{
|
||||
ret_value = ecma_reject (is_throw);
|
||||
}
|
||||
else
|
||||
{
|
||||
// m.
|
||||
if (!new_writable)
|
||||
{
|
||||
ecma_property_descriptor_t prop_desc_not_writable = ecma_make_empty_property_descriptor ();
|
||||
|
||||
prop_desc_not_writable.is_writable_defined = true;
|
||||
prop_desc_not_writable.is_writable = false;
|
||||
|
||||
ecma_completion_value_t completion_set_not_writable;
|
||||
magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
|
||||
completion_set_not_writable = ecma_op_general_object_define_own_property (obj_p,
|
||||
magic_string_length_p,
|
||||
&prop_desc_not_writable,
|
||||
false);
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion_set_not_writable));
|
||||
}
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ecma_dealloc_number (new_len_num_p);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4.a.
|
||||
uint32_t index;
|
||||
bool is_index;
|
||||
|
||||
if (property_name_p->container == ECMA_STRING_CONTAINER_UINT32_IN_DESC)
|
||||
{
|
||||
index = property_name_p->u.uint32_number;
|
||||
is_index = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_number_t number = ecma_string_to_number (property_name_p);
|
||||
index = ecma_number_to_uint32 (number);
|
||||
|
||||
ecma_string_t *to_uint32_to_string_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
|
||||
is_index = ecma_compare_ecma_strings (property_name_p,
|
||||
to_uint32_to_string_p);
|
||||
|
||||
ecma_deref_ecma_string (to_uint32_to_string_p);
|
||||
}
|
||||
|
||||
is_index = is_index && (index != ECMA_MAX_VALUE_OF_VALID_ARRAY_INDEX);
|
||||
|
||||
if (!is_index)
|
||||
{
|
||||
// 5.
|
||||
return ecma_op_general_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
false);
|
||||
}
|
||||
|
||||
// 4.
|
||||
|
||||
// b.
|
||||
if (index >= old_len_uint32
|
||||
&& !ecma_is_property_writable (len_prop_p))
|
||||
{
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
// c.
|
||||
ecma_completion_value_t succeeded = ecma_op_general_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
false);
|
||||
// d.
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (succeeded)
|
||||
|| ecma_is_completion_value_normal_false (succeeded));
|
||||
|
||||
if (ecma_is_completion_value_normal_false (succeeded))
|
||||
{
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
// e.
|
||||
if (index >= old_len_uint32)
|
||||
{
|
||||
// i., ii.
|
||||
ecma_number_t *num_p = ecma_alloc_number ();
|
||||
*num_p = ecma_number_add (ecma_uint32_to_number (index), ECMA_NUMBER_ONE);
|
||||
|
||||
ecma_named_data_property_assign_value (obj_p, len_prop_p, ecma_make_number_value (num_p));
|
||||
|
||||
ecma_dealloc_number (num_p);
|
||||
}
|
||||
|
||||
// f.
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
} /* ecma_op_array_object_define_own_property */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,44 @@
|
||||
/* Copyright 2014-2015 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 ECMA_ARRAY_OBJECT_H
|
||||
#define ECMA_ARRAY_OBJECT_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaarrayobject ECMA Array object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_create_array_object (const ecma_value_t *arguments_list_p,
|
||||
ecma_length_t arguments_list_len,
|
||||
bool is_treat_single_arg_as_length);
|
||||
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_array_object_define_own_property (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p,
|
||||
const ecma_property_descriptor_t* property_desc_p,
|
||||
bool is_throw);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_ARRAY_OBJECT_H */
|
||||
@@ -0,0 +1,73 @@
|
||||
/* Copyright 2014-2015 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-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabooleanobject ECMA Boolean object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Boolean object creation operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 15.6.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_create_boolean_object (const ecma_value_t& arg) /**< argument passed to the Boolean constructor */
|
||||
{
|
||||
ecma_completion_value_t conv_to_boolean_completion = ecma_op_to_boolean (arg);
|
||||
|
||||
if (!ecma_is_completion_value_normal (conv_to_boolean_completion))
|
||||
{
|
||||
return conv_to_boolean_completion;
|
||||
}
|
||||
|
||||
ecma_simple_value_t bool_value = (ecma_is_value_true (ecma_get_completion_value_value (conv_to_boolean_completion)) ?
|
||||
ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE);
|
||||
#else /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
|
||||
|
||||
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p,
|
||||
true,
|
||||
ECMA_OBJECT_TYPE_GENERAL);
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_BOOLEAN_UL;
|
||||
|
||||
ecma_property_t *prim_value_prop_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE);
|
||||
prim_value_prop_p->u.internal_property.value = bool_value;
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
|
||||
} /* ecma_op_create_boolean_object */
|
||||
@@ -0,0 +1,35 @@
|
||||
/* Copyright 2014-2015 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 ECMA_BOOLEAN_OBJECT_H
|
||||
#define ECMA_BOOLEAN_OBJECT_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabooleanobject ECMA Boolean object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_completion_value_t ecma_op_create_boolean_object (const ecma_value_t& arg);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_BOOLEAN_OBJECT_H */
|
||||
@@ -0,0 +1,460 @@
|
||||
/* Copyright 2014-2015 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-comparison.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmacomparison ECMA comparison
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* ECMA abstract equality comparison routine.
|
||||
*
|
||||
* See also: ECMA-262 v5, 11.9.3
|
||||
*
|
||||
* @return true - if values are equal,
|
||||
* false - otherwise.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_abstract_equality_compare (const ecma_value_t& x, /**< first operand */
|
||||
const ecma_value_t& y) /**< second operand */
|
||||
{
|
||||
const bool is_x_undefined = ecma_is_value_undefined (x);
|
||||
const bool is_x_null = ecma_is_value_null (x);
|
||||
const bool is_x_boolean = ecma_is_value_boolean (x);
|
||||
const bool is_x_number = ecma_is_value_number (x);
|
||||
const bool is_x_string = ecma_is_value_string (x);
|
||||
const bool is_x_object = ecma_is_value_object (x);
|
||||
|
||||
const bool is_y_undefined = ecma_is_value_undefined (y);
|
||||
const bool is_y_null = ecma_is_value_null (y);
|
||||
const bool is_y_boolean = ecma_is_value_boolean (y);
|
||||
const bool is_y_number = ecma_is_value_number (y);
|
||||
const bool is_y_string = ecma_is_value_string (y);
|
||||
const bool is_y_object = ecma_is_value_object (y);
|
||||
|
||||
const bool is_types_equal = ((is_x_undefined && is_y_undefined)
|
||||
|| (is_x_null && is_y_null)
|
||||
|| (is_x_boolean && is_y_boolean)
|
||||
|| (is_x_number && is_y_number)
|
||||
|| (is_x_string && is_y_string)
|
||||
|| (is_x_object && is_y_object));
|
||||
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
if (is_types_equal)
|
||||
{
|
||||
// 1.
|
||||
|
||||
if (is_x_undefined
|
||||
|| is_x_null)
|
||||
{
|
||||
// a., b.
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
else if (is_x_number)
|
||||
{ // c.
|
||||
ecma_number_t x_num = *ecma_get_number_from_value (x);
|
||||
ecma_number_t y_num = *ecma_get_number_from_value (y);
|
||||
|
||||
bool is_x_equal_to_y = (x_num == y_num);
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
bool is_x_equal_to_y_check;
|
||||
|
||||
if (ecma_number_is_nan (x_num)
|
||||
|| ecma_number_is_nan (y_num))
|
||||
{
|
||||
is_x_equal_to_y_check = false;
|
||||
}
|
||||
else if (x_num == y_num
|
||||
|| (ecma_number_is_zero (x_num)
|
||||
&& ecma_number_is_zero (y_num)))
|
||||
{
|
||||
is_x_equal_to_y_check = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_x_equal_to_y_check = false;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (is_x_equal_to_y == is_x_equal_to_y_check);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_x_equal_to_y ?
|
||||
ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
else if (is_x_string)
|
||||
{ // d.
|
||||
ecma_string_t* x_str_p = ecma_get_string_from_value (x);
|
||||
ecma_string_t* y_str_p = ecma_get_string_from_value (y);
|
||||
|
||||
bool is_equal = ecma_compare_ecma_strings (x_str_p, y_str_p);
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_equal ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
else if (is_x_boolean)
|
||||
{ // e.
|
||||
bool is_equal = (ecma_is_value_true (x) == ecma_is_value_true (y));
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_equal ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
else
|
||||
{ // f.
|
||||
JERRY_ASSERT(is_x_object);
|
||||
|
||||
bool is_equal = (ecma_get_object_from_value (x) == ecma_get_object_from_value (y));
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_equal ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
}
|
||||
else if ((is_x_null && is_y_undefined)
|
||||
|| (is_x_undefined && is_y_null))
|
||||
{ // 2., 3.
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
else if (is_x_number && is_y_string)
|
||||
{
|
||||
// 4.
|
||||
ECMA_TRY_CATCH (y_num_value,
|
||||
ecma_op_to_number (y),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_op_abstract_equality_compare (x, y_num_value);
|
||||
|
||||
ECMA_FINALIZE (y_num_value);
|
||||
}
|
||||
else if (is_x_string && is_y_number)
|
||||
{
|
||||
// 5.
|
||||
ECMA_TRY_CATCH (x_num_value,
|
||||
ecma_op_to_number (x),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_op_abstract_equality_compare (x_num_value, y);
|
||||
|
||||
ECMA_FINALIZE (x_num_value);
|
||||
}
|
||||
else if (is_x_boolean)
|
||||
{
|
||||
// 6.
|
||||
ECMA_TRY_CATCH (x_num_value,
|
||||
ecma_op_to_number (x),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_op_abstract_equality_compare (x_num_value, y);
|
||||
|
||||
ECMA_FINALIZE (x_num_value);
|
||||
}
|
||||
else if (is_y_boolean)
|
||||
{
|
||||
// 7.
|
||||
ECMA_TRY_CATCH (y_num_value,
|
||||
ecma_op_to_number (y),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_op_abstract_equality_compare (x, y_num_value);
|
||||
|
||||
ECMA_FINALIZE (y_num_value);
|
||||
}
|
||||
else if (is_y_object
|
||||
&& (is_x_number || is_x_string))
|
||||
{
|
||||
// 8.
|
||||
ECMA_TRY_CATCH (y_prim_value,
|
||||
ecma_op_to_primitive (y, ECMA_PREFERRED_TYPE_NO),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_op_abstract_equality_compare (x, y_prim_value);
|
||||
|
||||
ECMA_FINALIZE (y_prim_value);
|
||||
}
|
||||
else if (is_x_object
|
||||
&& (is_y_number || is_y_string))
|
||||
{
|
||||
// 9.
|
||||
ECMA_TRY_CATCH (x_prim_value,
|
||||
ecma_op_to_primitive (x, ECMA_PREFERRED_TYPE_NO),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_op_abstract_equality_compare (x_prim_value, y);
|
||||
|
||||
ECMA_FINALIZE (x_prim_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_abstract_equality_compare */
|
||||
|
||||
/**
|
||||
* ECMA strict equality comparison routine.
|
||||
*
|
||||
* See also: ECMA-262 v5, 11.9.6
|
||||
*
|
||||
* @return true - if values are strict equal,
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
ecma_op_strict_equality_compare (const ecma_value_t& x, /**< first operand */
|
||||
const ecma_value_t& y) /**< second operand */
|
||||
{
|
||||
const bool is_x_undefined = ecma_is_value_undefined (x);
|
||||
const bool is_x_null = ecma_is_value_null (x);
|
||||
const bool is_x_boolean = ecma_is_value_boolean (x);
|
||||
const bool is_x_number = ecma_is_value_number (x);
|
||||
const bool is_x_string = ecma_is_value_string (x);
|
||||
const bool is_x_object = ecma_is_value_object (x);
|
||||
|
||||
const bool is_y_undefined = ecma_is_value_undefined (y);
|
||||
const bool is_y_null = ecma_is_value_null (y);
|
||||
const bool is_y_boolean = ecma_is_value_boolean (y);
|
||||
const bool is_y_number = ecma_is_value_number (y);
|
||||
const bool is_y_string = ecma_is_value_string (y);
|
||||
const bool is_y_object = ecma_is_value_object (y);
|
||||
|
||||
const bool is_types_equal = ((is_x_undefined && is_y_undefined)
|
||||
|| (is_x_null && is_y_null)
|
||||
|| (is_x_boolean && is_y_boolean)
|
||||
|| (is_x_number && is_y_number)
|
||||
|| (is_x_string && is_y_string)
|
||||
|| (is_x_object && is_y_object));
|
||||
|
||||
// 1. If Type (x) is different from Type (y), return false.
|
||||
if (!is_types_equal)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. If Type (x) is Undefined, return true.
|
||||
if (is_x_undefined)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. If Type (x) is Null, return true.
|
||||
if (is_x_null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 4. If Type (x) is Number, then
|
||||
if (is_x_number)
|
||||
{
|
||||
// a. If x is NaN, return false.
|
||||
// b. If y is NaN, return false.
|
||||
// c. If x is the same Number value as y, return true.
|
||||
// d. If x is +0 and y is -0, return true.
|
||||
// e. If x is -0 and y is +0, return true.
|
||||
|
||||
ecma_number_t x_num = *ecma_get_number_from_value (x);
|
||||
ecma_number_t y_num = *ecma_get_number_from_value (y);
|
||||
|
||||
bool is_x_equal_to_y = (x_num == y_num);
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
bool is_x_equal_to_y_check;
|
||||
|
||||
if (ecma_number_is_nan (x_num)
|
||||
|| ecma_number_is_nan (y_num))
|
||||
{
|
||||
is_x_equal_to_y_check = false;
|
||||
}
|
||||
else if (x_num == y_num
|
||||
|| (ecma_number_is_zero (x_num)
|
||||
&& ecma_number_is_zero (y_num)))
|
||||
{
|
||||
is_x_equal_to_y_check = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_x_equal_to_y_check = false;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (is_x_equal_to_y == is_x_equal_to_y_check);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
return is_x_equal_to_y;
|
||||
}
|
||||
|
||||
// 5. If Type (x) is String, then return true if x and y are exactly the same sequence of characters
|
||||
// (same length and same characters in corresponding positions); otherwise, return false.
|
||||
if (is_x_string)
|
||||
{
|
||||
ecma_string_t* x_str_p = ecma_get_string_from_value (x);
|
||||
ecma_string_t* y_str_p = ecma_get_string_from_value (y);
|
||||
|
||||
return ecma_compare_ecma_strings (x_str_p, y_str_p);
|
||||
}
|
||||
|
||||
// 6. If Type (x) is Boolean, return true if x and y are both true or both false; otherwise, return false.
|
||||
if (is_x_boolean)
|
||||
{
|
||||
return (ecma_is_value_true (x) == ecma_is_value_true (y));
|
||||
}
|
||||
|
||||
// 7. Return true if x and y refer to the same object. Otherwise, return false.
|
||||
JERRY_ASSERT (is_x_object);
|
||||
|
||||
return (ecma_get_object_from_value (x) == ecma_get_object_from_value (y));
|
||||
} /* ecma_op_strict_equality_compare */
|
||||
|
||||
/**
|
||||
* ECMA abstract relational comparison routine.
|
||||
*
|
||||
* See also: ECMA-262 v5, 11.8.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_abstract_relational_compare (const ecma_value_t& x, /**< first operand */
|
||||
const ecma_value_t& y, /**< second operand */
|
||||
bool left_first) /**< 'LeftFirst' flag */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
const ecma_value_t& first_converted_value = left_first ? x : y;
|
||||
const ecma_value_t& second_converted_value = left_first ? y : x;
|
||||
|
||||
// 1., 2.
|
||||
ECMA_TRY_CATCH(prim_first_converted_value,
|
||||
ecma_op_to_primitive (first_converted_value, ECMA_PREFERRED_TYPE_NUMBER),
|
||||
ret_value);
|
||||
ECMA_TRY_CATCH(prim_second_converted_value,
|
||||
ecma_op_to_primitive (second_converted_value, ECMA_PREFERRED_TYPE_NUMBER),
|
||||
ret_value);
|
||||
|
||||
const ecma_value_t &px = left_first ? prim_first_converted_value : prim_second_converted_value;
|
||||
const ecma_value_t &py = left_first ? prim_second_converted_value : prim_first_converted_value;
|
||||
|
||||
const bool is_px_string = ecma_is_value_string (px);
|
||||
const bool is_py_string = ecma_is_value_string (py);
|
||||
|
||||
if (!(is_px_string && is_py_string))
|
||||
{
|
||||
// 3.
|
||||
|
||||
// a.
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (nx, px, ret_value);
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (ny, py, ret_value);
|
||||
|
||||
// b.
|
||||
if (ecma_number_is_nan (nx)
|
||||
|| ecma_number_is_nan (ny))
|
||||
{
|
||||
// c., d.
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool is_x_less_than_y = (nx < ny);
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
bool is_x_less_than_y_check;
|
||||
|
||||
if (nx == ny
|
||||
|| (ecma_number_is_zero (nx)
|
||||
&& ecma_number_is_zero (ny)))
|
||||
{
|
||||
// e., f., g.
|
||||
is_x_less_than_y_check = false;
|
||||
}
|
||||
else if (ecma_number_is_infinity (nx)
|
||||
&& !ecma_number_is_negative (nx))
|
||||
{
|
||||
// h.
|
||||
is_x_less_than_y_check = false;
|
||||
}
|
||||
else if (ecma_number_is_infinity (ny)
|
||||
&& !ecma_number_is_negative (ny))
|
||||
{
|
||||
// i.
|
||||
is_x_less_than_y_check = true;
|
||||
}
|
||||
else if (ecma_number_is_infinity (ny)
|
||||
&& ecma_number_is_negative (ny))
|
||||
{
|
||||
// j.
|
||||
is_x_less_than_y_check = false;
|
||||
}
|
||||
else if (ecma_number_is_infinity (nx)
|
||||
&& ecma_number_is_negative (nx))
|
||||
{
|
||||
// k.
|
||||
is_x_less_than_y_check = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// l.
|
||||
JERRY_ASSERT (!ecma_number_is_nan (nx)
|
||||
&& !ecma_number_is_infinity (nx));
|
||||
JERRY_ASSERT (!ecma_number_is_nan (ny)
|
||||
&& !ecma_number_is_infinity (ny));
|
||||
JERRY_ASSERT (!(ecma_number_is_zero (nx)
|
||||
&& ecma_number_is_zero (ny)));
|
||||
|
||||
if (nx < ny)
|
||||
{
|
||||
is_x_less_than_y_check = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_x_less_than_y_check = false;
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_ASSERT (is_x_less_than_y_check == is_x_less_than_y);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_x_less_than_y ?
|
||||
ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (ny);
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (nx);
|
||||
}
|
||||
else
|
||||
{ // 4.
|
||||
JERRY_ASSERT (is_px_string && is_py_string);
|
||||
|
||||
ecma_string_t *str_x_p = ecma_get_string_from_value (px);
|
||||
ecma_string_t *str_y_p = ecma_get_string_from_value (py);
|
||||
|
||||
bool is_px_less = ecma_compare_ecma_strings_relational (str_x_p, str_y_p);
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (is_px_less ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE(prim_second_converted_value);
|
||||
ECMA_FINALIZE(prim_first_converted_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_abstract_relational_compare */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,42 @@
|
||||
/* Copyright 2014-2015 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 JERRY_ECMA_COMPARISON_H
|
||||
#define JERRY_ECMA_COMPARISON_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmacomparison ECMA comparison
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_completion_value_t ecma_op_abstract_equality_compare (const ecma_value_t& x,
|
||||
const ecma_value_t& y);
|
||||
extern bool ecma_op_strict_equality_compare (const ecma_value_t& x,
|
||||
const ecma_value_t& y);
|
||||
extern ecma_completion_value_t ecma_op_abstract_relational_compare (const ecma_value_t& x,
|
||||
const ecma_value_t& y,
|
||||
bool left_first);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !JERRY_ECMA_COMPARISON_H */
|
||||
@@ -0,0 +1,822 @@
|
||||
/* Copyright 2014-2015 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of ECMA-defined conversion routines
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-boolean-object.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-number-object.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaconversion ECMA conversion routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* CheckObjectCoercible operation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.10
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_check_object_coercible (const ecma_value_t& value) /**< ecma-value */
|
||||
{
|
||||
ecma_check_value_type_is_spec_defined (value);
|
||||
|
||||
if (ecma_is_value_undefined (value)
|
||||
|| ecma_is_value_null (value))
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_empty_completion_value ();
|
||||
}
|
||||
} /* ecma_op_check_object_coercible */
|
||||
|
||||
/**
|
||||
* SameValue operation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.12
|
||||
*
|
||||
* @return true - if the value are same according to ECMA-defined SameValue algorithm,
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
ecma_op_same_value (const ecma_value_t& x, /**< ecma-value */
|
||||
const ecma_value_t& y) /**< ecma-value */
|
||||
{
|
||||
const bool is_x_undefined = ecma_is_value_undefined (x);
|
||||
const bool is_x_null = ecma_is_value_null (x);
|
||||
const bool is_x_boolean = ecma_is_value_boolean (x);
|
||||
const bool is_x_number = ecma_is_value_number (x);
|
||||
const bool is_x_string = ecma_is_value_string (x);
|
||||
const bool is_x_object = ecma_is_value_object (x);
|
||||
|
||||
const bool is_y_undefined = ecma_is_value_undefined (y);
|
||||
const bool is_y_null = ecma_is_value_null (y);
|
||||
const bool is_y_boolean = ecma_is_value_boolean (y);
|
||||
const bool is_y_number = ecma_is_value_number (y);
|
||||
const bool is_y_string = ecma_is_value_string (y);
|
||||
const bool is_y_object = ecma_is_value_object (y);
|
||||
|
||||
const bool is_types_equal = ((is_x_undefined && is_y_undefined)
|
||||
|| (is_x_null && is_y_null)
|
||||
|| (is_x_boolean && is_y_boolean)
|
||||
|| (is_x_number && is_y_number)
|
||||
|| (is_x_string && is_y_string)
|
||||
|| (is_x_object && is_y_object));
|
||||
|
||||
if (!is_types_equal)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_x_undefined
|
||||
|| is_x_null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_x_number)
|
||||
{
|
||||
ecma_number_t *x_num_p = ecma_get_number_from_value (x);
|
||||
ecma_number_t *y_num_p = ecma_get_number_from_value (y);
|
||||
|
||||
if (ecma_number_is_nan (*x_num_p)
|
||||
&& ecma_number_is_nan (*y_num_p))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (ecma_number_is_zero (*x_num_p)
|
||||
&& ecma_number_is_zero (*y_num_p)
|
||||
&& ecma_number_is_negative (*x_num_p) != ecma_number_is_negative (*y_num_p))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (*x_num_p == *y_num_p);
|
||||
}
|
||||
|
||||
if (is_x_string)
|
||||
{
|
||||
ecma_string_t* x_str_p = ecma_get_string_from_value (x);
|
||||
ecma_string_t* y_str_p = ecma_get_string_from_value (y);
|
||||
|
||||
return ecma_compare_ecma_strings (x_str_p, y_str_p);
|
||||
}
|
||||
|
||||
if (is_x_boolean)
|
||||
{
|
||||
return (ecma_is_value_true (x) == ecma_is_value_true (y));
|
||||
}
|
||||
|
||||
JERRY_ASSERT(is_x_object);
|
||||
|
||||
return (ecma_get_object_from_value (x) == ecma_get_object_from_value (y));
|
||||
} /* ecma_op_same_value */
|
||||
|
||||
/**
|
||||
* ToPrimitive operation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_to_primitive (const ecma_value_t& value, /**< ecma-value */
|
||||
ecma_preferred_type_hint_t preferred_type) /**< preferred type hint */
|
||||
{
|
||||
ecma_check_value_type_is_spec_defined (value);
|
||||
|
||||
if (ecma_is_value_object (value))
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
|
||||
return ecma_op_object_default_value (obj_p, preferred_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_normal_completion_value (ecma_copy_value (value, true));
|
||||
}
|
||||
} /* ecma_op_to_primitive */
|
||||
|
||||
/**
|
||||
* ToBoolean operation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value is simple and so need not be freed.
|
||||
* However, ecma_free_completion_value may be called for it, but it is a no-op.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_to_boolean (const ecma_value_t& value) /**< ecma-value */
|
||||
{
|
||||
ecma_check_value_type_is_spec_defined (value);
|
||||
|
||||
ecma_simple_value_t ret_value;
|
||||
|
||||
if (ecma_is_value_boolean (value))
|
||||
{
|
||||
ret_value = (ecma_is_value_true (value) ?
|
||||
ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
else if (ecma_is_value_undefined (value)
|
||||
|| ecma_is_value_null (value))
|
||||
{
|
||||
ret_value = ECMA_SIMPLE_VALUE_FALSE;
|
||||
}
|
||||
else if (ecma_is_value_number (value))
|
||||
{
|
||||
ecma_number_t *num_p = ecma_get_number_from_value (value);
|
||||
|
||||
if (ecma_number_is_nan (*num_p)
|
||||
|| ecma_number_is_zero (*num_p))
|
||||
{
|
||||
ret_value = ECMA_SIMPLE_VALUE_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ECMA_SIMPLE_VALUE_TRUE;
|
||||
}
|
||||
}
|
||||
else if (ecma_is_value_string (value))
|
||||
{
|
||||
ecma_string_t *str_p = ecma_get_string_from_value (value);
|
||||
|
||||
if (ecma_string_get_length (str_p) == 0)
|
||||
{
|
||||
ret_value = ECMA_SIMPLE_VALUE_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ECMA_SIMPLE_VALUE_TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_object (value));
|
||||
|
||||
ret_value = ECMA_SIMPLE_VALUE_TRUE;
|
||||
}
|
||||
|
||||
return ecma_make_simple_completion_value (ret_value);
|
||||
} /* ecma_op_to_boolean */
|
||||
|
||||
/**
|
||||
* ToNumber operation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_to_number (const ecma_value_t& value) /**< ecma-value */
|
||||
{
|
||||
ecma_check_value_type_is_spec_defined (value);
|
||||
|
||||
if (ecma_is_value_number (value))
|
||||
{
|
||||
return ecma_make_normal_completion_value (ecma_copy_value (value, true));
|
||||
}
|
||||
else if (ecma_is_value_string (value))
|
||||
{
|
||||
ecma_string_t *str_p = ecma_get_string_from_value (value);
|
||||
|
||||
ecma_number_t *num_p = ecma_alloc_number ();
|
||||
*num_p = ecma_string_to_number (str_p);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
|
||||
}
|
||||
else if (ecma_is_value_object (value))
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (primitive_value,
|
||||
ecma_op_to_primitive (value, ECMA_PREFERRED_TYPE_NUMBER),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_op_to_number (primitive_value);
|
||||
|
||||
ECMA_FINALIZE (primitive_value);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_number_t *num_p = ecma_alloc_number ();
|
||||
|
||||
if (ecma_is_value_undefined (value))
|
||||
{
|
||||
*num_p = ecma_number_make_nan ();
|
||||
}
|
||||
else if (ecma_is_value_null (value))
|
||||
{
|
||||
*num_p = ECMA_NUMBER_ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_boolean (value));
|
||||
|
||||
if (ecma_is_value_true (value))
|
||||
{
|
||||
*num_p = ECMA_NUMBER_ONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
*num_p = ECMA_NUMBER_ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
|
||||
}
|
||||
} /* ecma_op_to_number */
|
||||
|
||||
/**
|
||||
* ToString operation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.8
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_to_string (const ecma_value_t& value) /**< ecma-value */
|
||||
{
|
||||
ecma_check_value_type_is_spec_defined (value);
|
||||
|
||||
if (unlikely (ecma_is_value_object (value)))
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (prim_value,
|
||||
ecma_op_to_primitive (value, ECMA_PREFERRED_TYPE_STRING),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_op_to_string (prim_value);
|
||||
|
||||
ECMA_FINALIZE (prim_value);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_string_t *res_p = NULL;
|
||||
|
||||
if (ecma_is_value_string (value))
|
||||
{
|
||||
res_p = ecma_get_string_from_value (value);
|
||||
res_p = ecma_copy_or_ref_ecma_string (res_p);
|
||||
}
|
||||
else if (ecma_is_value_number (value))
|
||||
{
|
||||
ecma_number_t *num_p = ecma_get_number_from_value (value);
|
||||
res_p = ecma_new_ecma_string_from_number (*num_p);
|
||||
}
|
||||
else if (ecma_is_value_undefined (value))
|
||||
{
|
||||
res_p = ecma_get_magic_string (ECMA_MAGIC_STRING_UNDEFINED);
|
||||
}
|
||||
else if (ecma_is_value_null (value))
|
||||
{
|
||||
res_p = ecma_get_magic_string (ECMA_MAGIC_STRING_NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_boolean (value));
|
||||
|
||||
if (ecma_is_value_true (value))
|
||||
{
|
||||
res_p = ecma_get_magic_string (ECMA_MAGIC_STRING_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
res_p = ecma_get_magic_string (ECMA_MAGIC_STRING_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_string_value (res_p));
|
||||
}
|
||||
} /* ecma_op_to_string */
|
||||
|
||||
/**
|
||||
* ToObject operation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 9.9
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_to_object (const ecma_value_t& value) /**< ecma-value */
|
||||
{
|
||||
ecma_check_value_type_is_spec_defined (value);
|
||||
|
||||
if (ecma_is_value_number (value))
|
||||
{
|
||||
return ecma_op_create_number_object (value);
|
||||
}
|
||||
else if (ecma_is_value_string (value))
|
||||
{
|
||||
return ecma_op_create_string_object (&value, 1);
|
||||
}
|
||||
else if (ecma_is_value_object (value))
|
||||
{
|
||||
return ecma_make_normal_completion_value (ecma_copy_value (value, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ecma_is_value_undefined (value)
|
||||
|| ecma_is_value_null (value))
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_boolean (value));
|
||||
|
||||
return ecma_op_create_boolean_object (value);
|
||||
}
|
||||
}
|
||||
} /* ecma_op_to_object */
|
||||
|
||||
/**
|
||||
* FromPropertyDescriptor operation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.10.4
|
||||
*
|
||||
* @return constructed object
|
||||
*/
|
||||
ecma_object_t*
|
||||
ecma_op_from_property_descriptor (const ecma_property_descriptor_t* src_prop_desc_p) /**< property descriptor */
|
||||
{
|
||||
// 2.
|
||||
ecma_object_t *obj_p = ecma_op_create_object_object_noarg ();
|
||||
|
||||
ecma_completion_value_t completion;
|
||||
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
prop_desc.is_value_defined = true;
|
||||
|
||||
prop_desc.is_writable_defined = true;
|
||||
prop_desc.is_writable = true;
|
||||
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
prop_desc.is_enumerable = true;
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
prop_desc.is_configurable = true;
|
||||
}
|
||||
|
||||
// 3.
|
||||
if (prop_desc.is_value_defined
|
||||
|| prop_desc.is_writable_defined)
|
||||
{
|
||||
JERRY_ASSERT (prop_desc.is_value_defined && prop_desc.is_writable_defined);
|
||||
|
||||
// a.
|
||||
prop_desc.value = src_prop_desc_p->value;
|
||||
|
||||
ecma_string_t *value_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_VALUE);
|
||||
completion = ecma_op_object_define_own_property (obj_p,
|
||||
value_magic_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (value_magic_string_p);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
|
||||
// b.
|
||||
const bool is_writable = (src_prop_desc_p->is_writable);
|
||||
prop_desc.value = ecma_make_simple_value (is_writable ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
|
||||
ecma_string_t *writable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_WRITABLE);
|
||||
completion = ecma_op_object_define_own_property (obj_p,
|
||||
writable_magic_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (writable_magic_string_p);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4.
|
||||
JERRY_ASSERT (prop_desc.is_get_defined && prop_desc.is_set_defined);
|
||||
|
||||
// a.
|
||||
if (src_prop_desc_p->get_p == NULL)
|
||||
{
|
||||
prop_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
prop_desc.value = ecma_make_object_value (src_prop_desc_p->get_p);
|
||||
}
|
||||
|
||||
ecma_string_t *get_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_GET);
|
||||
completion = ecma_op_object_define_own_property (obj_p,
|
||||
get_magic_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (get_magic_string_p);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
|
||||
// b.
|
||||
if (src_prop_desc_p->set_p == NULL)
|
||||
{
|
||||
prop_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
prop_desc.value = ecma_make_object_value (src_prop_desc_p->set_p);
|
||||
}
|
||||
|
||||
ecma_string_t *set_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_SET);
|
||||
completion = ecma_op_object_define_own_property (obj_p,
|
||||
set_magic_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (set_magic_string_p);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
}
|
||||
|
||||
const bool is_enumerable = src_prop_desc_p->is_enumerable;
|
||||
prop_desc.value = ecma_make_simple_value (is_enumerable ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
|
||||
ecma_string_t *enumerable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ENUMERABLE);
|
||||
completion = ecma_op_object_define_own_property (obj_p,
|
||||
enumerable_magic_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (enumerable_magic_string_p);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
|
||||
const bool is_configurable = src_prop_desc_p->is_configurable;
|
||||
prop_desc.value = ecma_make_simple_value (is_configurable ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
|
||||
ecma_string_t *configurable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CONFIGURABLE);
|
||||
completion = ecma_op_object_define_own_property (obj_p,
|
||||
configurable_magic_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (configurable_magic_string_p);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
|
||||
return obj_p;
|
||||
} /* ecma_op_from_property_descriptor */
|
||||
|
||||
/**
|
||||
* ToPropertyDescriptor operation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.10.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_to_property_descriptor (const ecma_value_t& obj_value, /**< object value */
|
||||
ecma_property_descriptor_t *out_prop_desc_p) /**< out: filled property descriptor
|
||||
if return value is normal
|
||||
empty completion value */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
// 1.
|
||||
if (!ecma_is_value_object (obj_value))
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_value);
|
||||
|
||||
// 2.
|
||||
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
|
||||
|
||||
// 3.
|
||||
ecma_string_t *enumerable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ENUMERABLE);
|
||||
|
||||
if (ecma_op_object_get_property (obj_p, enumerable_magic_string_p) != NULL)
|
||||
{
|
||||
ECMA_TRY_CATCH (enumerable_prop_value,
|
||||
ecma_op_object_get (obj_p, enumerable_magic_string_p),
|
||||
ret_value);
|
||||
ECMA_TRY_CATCH (boolean_enumerable_prop_value,
|
||||
ecma_op_to_boolean (enumerable_prop_value),
|
||||
ret_value);
|
||||
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
if (ecma_is_value_true (boolean_enumerable_prop_value))
|
||||
{
|
||||
prop_desc.is_enumerable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_boolean (boolean_enumerable_prop_value));
|
||||
|
||||
prop_desc.is_enumerable = false;
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (boolean_enumerable_prop_value);
|
||||
ECMA_FINALIZE (enumerable_prop_value);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (enumerable_magic_string_p);
|
||||
|
||||
if (!ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
||||
|
||||
// 4.
|
||||
ecma_string_t *configurable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CONFIGURABLE);
|
||||
|
||||
if (ecma_op_object_get_property (obj_p, configurable_magic_string_p) != NULL)
|
||||
{
|
||||
ECMA_TRY_CATCH (configurable_prop_value,
|
||||
ecma_op_object_get (obj_p, configurable_magic_string_p),
|
||||
ret_value);
|
||||
ECMA_TRY_CATCH (boolean_configurable_prop_value,
|
||||
ecma_op_to_boolean (configurable_prop_value),
|
||||
ret_value);
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
if (ecma_is_value_true (boolean_configurable_prop_value))
|
||||
{
|
||||
prop_desc.is_configurable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_boolean (boolean_configurable_prop_value));
|
||||
|
||||
prop_desc.is_configurable = false;
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (boolean_configurable_prop_value);
|
||||
ECMA_FINALIZE (configurable_prop_value);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (configurable_magic_string_p);
|
||||
}
|
||||
|
||||
if (!ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
||||
|
||||
// 5.
|
||||
ecma_string_t *value_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_VALUE);
|
||||
|
||||
if (ecma_op_object_get_property (obj_p, value_magic_string_p) != NULL)
|
||||
{
|
||||
ECMA_TRY_CATCH (value_prop_value,
|
||||
ecma_op_object_get (obj_p, value_magic_string_p),
|
||||
ret_value);
|
||||
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.value = ecma_copy_value (value_prop_value, true);
|
||||
|
||||
ECMA_FINALIZE (value_prop_value);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (value_magic_string_p);
|
||||
}
|
||||
|
||||
if (!ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
||||
|
||||
// 6.
|
||||
ecma_string_t *writable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_WRITABLE);
|
||||
|
||||
if (ecma_op_object_get_property (obj_p, writable_magic_string_p) != NULL)
|
||||
{
|
||||
ECMA_TRY_CATCH (writable_prop_value,
|
||||
ecma_op_object_get (obj_p, writable_magic_string_p),
|
||||
ret_value);
|
||||
ECMA_TRY_CATCH (boolean_writable_prop_value,
|
||||
ecma_op_to_boolean (writable_prop_value),
|
||||
ret_value);
|
||||
|
||||
prop_desc.is_writable_defined = true;
|
||||
if (ecma_is_value_true (boolean_writable_prop_value))
|
||||
{
|
||||
prop_desc.is_writable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_boolean (boolean_writable_prop_value));
|
||||
|
||||
prop_desc.is_writable = false;
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (boolean_writable_prop_value);
|
||||
ECMA_FINALIZE (writable_prop_value);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (writable_magic_string_p);
|
||||
}
|
||||
|
||||
if (!ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
||||
|
||||
// 7.
|
||||
ecma_string_t *get_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_GET);
|
||||
|
||||
if (ecma_op_object_get_property (obj_p, get_magic_string_p) != NULL)
|
||||
{
|
||||
ECMA_TRY_CATCH (get_prop_value,
|
||||
ecma_op_object_get (obj_p, get_magic_string_p),
|
||||
ret_value);
|
||||
|
||||
if (!ecma_op_is_callable (get_prop_value)
|
||||
&& !ecma_is_value_undefined (get_prop_value))
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
prop_desc.is_get_defined = true;
|
||||
|
||||
if (ecma_is_value_undefined (get_prop_value))
|
||||
{
|
||||
prop_desc.get_p = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_object (get_prop_value));
|
||||
|
||||
ecma_object_t *get_p = ecma_get_object_from_value (get_prop_value);
|
||||
ecma_ref_object (get_p);
|
||||
|
||||
prop_desc.get_p = get_p;
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (get_prop_value);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (get_magic_string_p);
|
||||
}
|
||||
|
||||
if (!ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
||||
|
||||
// 8.
|
||||
|
||||
ecma_string_t *set_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_SET);
|
||||
|
||||
if (ecma_op_object_get_property (obj_p, set_magic_string_p) != NULL)
|
||||
{
|
||||
ECMA_TRY_CATCH (set_prop_value,
|
||||
ecma_op_object_get (obj_p, set_magic_string_p),
|
||||
ret_value);
|
||||
|
||||
if (!ecma_op_is_callable (set_prop_value)
|
||||
&& !ecma_is_value_undefined (set_prop_value))
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
prop_desc.is_set_defined = true;
|
||||
|
||||
if (ecma_is_value_undefined (set_prop_value))
|
||||
{
|
||||
prop_desc.set_p = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_object (set_prop_value));
|
||||
|
||||
ecma_object_t *set_p = ecma_get_object_from_value (set_prop_value);
|
||||
ecma_ref_object (set_p);
|
||||
|
||||
prop_desc.set_p = set_p;
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (set_prop_value);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (set_magic_string_p);
|
||||
}
|
||||
|
||||
if (!ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
||||
|
||||
// 9.
|
||||
if (prop_desc.is_get_defined
|
||||
|| prop_desc.is_set_defined)
|
||||
{
|
||||
if (prop_desc.is_value_defined
|
||||
|| prop_desc.is_writable_defined)
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ecma_is_completion_value_throw (ret_value))
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
}
|
||||
|
||||
*out_prop_desc_p = prop_desc;
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_to_property_descriptor */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,59 @@
|
||||
/* Copyright 2014-2015 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 JERRY_ECMA_CONVERSION_H
|
||||
#define JERRY_ECMA_CONVERSION_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaconversion ECMA conversion
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Second argument of 'ToPrimitive' operation that is a hint,
|
||||
* specifying the preferred type of conversion result.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_PREFERRED_TYPE_NO, /**< no preferred type is specified */
|
||||
ECMA_PREFERRED_TYPE_NUMBER, /**< Number */
|
||||
ECMA_PREFERRED_TYPE_STRING /**< String */
|
||||
} ecma_preferred_type_hint_t;
|
||||
|
||||
extern ecma_completion_value_t ecma_op_check_object_coercible (const ecma_value_t& value);
|
||||
extern bool ecma_op_same_value (const ecma_value_t& x,
|
||||
const ecma_value_t& y);
|
||||
extern ecma_completion_value_t ecma_op_to_primitive (const ecma_value_t& value,
|
||||
ecma_preferred_type_hint_t preferred_type);
|
||||
extern ecma_completion_value_t ecma_op_to_boolean (const ecma_value_t& value);
|
||||
extern ecma_completion_value_t ecma_op_to_number (const ecma_value_t& value);
|
||||
extern ecma_completion_value_t ecma_op_to_string (const ecma_value_t& value);
|
||||
extern ecma_completion_value_t ecma_op_to_object (const ecma_value_t& value);
|
||||
|
||||
extern ecma_object_t* ecma_op_from_property_descriptor (const ecma_property_descriptor_t* src_prop_desc_p);
|
||||
extern ecma_completion_value_t ecma_op_to_property_descriptor (const ecma_value_t& obj_value,
|
||||
ecma_property_descriptor_t *out_prop_desc_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !JERRY_ECMA_CONVERSION_H */
|
||||
@@ -0,0 +1,136 @@
|
||||
/* Copyright 2014-2015 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-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup exceptions Exceptions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Standard ecma-error object constructor.
|
||||
*
|
||||
* @return pointer to ecma-object representing specified error
|
||||
* with reference counter set to one.
|
||||
*/
|
||||
ecma_object_t*
|
||||
ecma_new_standard_error (ecma_standard_error_t error_type) /**< native error type */
|
||||
{
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
|
||||
ecma_builtin_id_t prototype_id = ECMA_BUILTIN_ID__COUNT;
|
||||
|
||||
switch (error_type)
|
||||
{
|
||||
case ECMA_ERROR_COMMON:
|
||||
{
|
||||
prototype_id = ECMA_BUILTIN_ID_ERROR_PROTOTYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_ERROR_EVAL:
|
||||
{
|
||||
prototype_id = ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_ERROR_RANGE:
|
||||
{
|
||||
prototype_id = ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_ERROR_REFERENCE:
|
||||
{
|
||||
prototype_id = ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_ERROR_TYPE:
|
||||
{
|
||||
prototype_id = ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_ERROR_URI:
|
||||
{
|
||||
prototype_id = ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_ERROR_SYNTAX:
|
||||
{
|
||||
prototype_id = ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (prototype_id);
|
||||
|
||||
ecma_object_t *new_error_obj_p = ecma_create_object (prototype_obj_p,
|
||||
true,
|
||||
ECMA_OBJECT_TYPE_GENERAL);
|
||||
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_create_internal_property (new_error_obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_ERROR_UL;
|
||||
|
||||
return new_error_obj_p;
|
||||
#else /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
|
||||
(void) error_type;
|
||||
|
||||
return ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR);
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
|
||||
} /* ecma_new_standard_error */
|
||||
|
||||
/**
|
||||
* Standard ecma-error object constructor.
|
||||
*
|
||||
* @return pointer to ecma-object representing specified error
|
||||
* with reference counter set to one.
|
||||
*/
|
||||
ecma_object_t*
|
||||
ecma_new_standard_error_with_message (ecma_standard_error_t error_type, /**< native error type */
|
||||
ecma_string_t* message_string_p) /**< message string */
|
||||
{
|
||||
ecma_object_t *new_error_obj_p = ecma_new_standard_error (error_type);
|
||||
|
||||
ecma_string_t *message_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_MESSAGE);
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (new_error_obj_p,
|
||||
message_magic_string_p,
|
||||
true, false, true);
|
||||
|
||||
ecma_set_named_data_property_value (prop_p,
|
||||
ecma_make_string_value (ecma_copy_or_ref_ecma_string (message_string_p)));
|
||||
ecma_deref_ecma_string (message_magic_string_p);
|
||||
|
||||
return new_error_obj_p;
|
||||
} /* ecma_new_standard_error_with_message */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,56 @@
|
||||
/* Copyright 2014-2015 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 ECMA_EXCEPTIONS_H
|
||||
#define ECMA_EXCEPTIONS_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup exceptions Exceptions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Native errors.
|
||||
*
|
||||
* See also: 15.11.1, 15.11.6
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_ERROR_COMMON, /**< Error */
|
||||
ECMA_ERROR_EVAL, /**< EvalError */
|
||||
ECMA_ERROR_RANGE, /**< RangeError */
|
||||
ECMA_ERROR_REFERENCE, /**< ReferenceError */
|
||||
ECMA_ERROR_SYNTAX, /**< SyntaxError */
|
||||
ECMA_ERROR_TYPE, /**< TypeError */
|
||||
ECMA_ERROR_URI /**< URIError */
|
||||
} ecma_standard_error_t;
|
||||
|
||||
extern ecma_object_t *ecma_new_standard_error (ecma_standard_error_t error_type);
|
||||
extern ecma_object_t* ecma_new_standard_error_with_message (ecma_standard_error_t error_type,
|
||||
ecma_string_t *message_string_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_EXCEPTIONS_H */
|
||||
@@ -0,0 +1,764 @@
|
||||
/* Copyright 2014-2015 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-exceptions.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmafunctionobject ECMA Function object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pack 'is_strict' flag and opcode index to value
|
||||
* that can be stored in an [[Code]] internal property.
|
||||
*
|
||||
* @return packed value
|
||||
*/
|
||||
static uint32_t
|
||||
ecma_pack_code_internal_property_value (bool is_strict, /**< is code strict? */
|
||||
opcode_counter_t opcode_idx) /**< index of first opcode */
|
||||
{
|
||||
uint32_t value = opcode_idx;
|
||||
const uint32_t is_strict_bit_offset = (uint32_t) (sizeof (value) * JERRY_BITSINBYTE - 1);
|
||||
|
||||
JERRY_ASSERT(((value) & (1u << is_strict_bit_offset)) == 0);
|
||||
|
||||
if (is_strict)
|
||||
{
|
||||
value |= (1u << is_strict_bit_offset);
|
||||
}
|
||||
|
||||
return value;
|
||||
} /* ecma_pack_code_internal_property_value */
|
||||
|
||||
/**
|
||||
* Unpack 'is_strict' flag and opcode index from value
|
||||
* that can be stored in an [[Code]] internal property.
|
||||
*
|
||||
* @return opcode index
|
||||
*/
|
||||
static opcode_counter_t
|
||||
ecma_unpack_code_internal_property_value (uint32_t value, /**< packed value */
|
||||
bool* out_is_strict_p) /**< out: is code strict? */
|
||||
{
|
||||
JERRY_ASSERT(out_is_strict_p != NULL);
|
||||
|
||||
const uint32_t is_strict_bit_offset = (uint32_t) (sizeof (value) * JERRY_BITSINBYTE - 1);
|
||||
|
||||
bool is_strict = ((value & (1u << is_strict_bit_offset)) != 0);
|
||||
*out_is_strict_p = is_strict;
|
||||
|
||||
opcode_counter_t opcode_idx = (opcode_counter_t) (value & ~(1u << is_strict_bit_offset));
|
||||
|
||||
return opcode_idx;
|
||||
} /* ecma_unpack_code_internal_property_value */
|
||||
|
||||
/**
|
||||
* IsCallable operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 9.11
|
||||
*
|
||||
* @return true, if value is callable object;
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
ecma_op_is_callable (const ecma_value_t& value) /**< ecma-value */
|
||||
{
|
||||
if (!ecma_is_value_object (value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
|
||||
JERRY_ASSERT(obj_p != NULL);
|
||||
JERRY_ASSERT(!ecma_is_lexical_environment (obj_p));
|
||||
|
||||
return (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION
|
||||
|| ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION
|
||||
|| ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION);
|
||||
} /* ecma_op_is_callable */
|
||||
|
||||
/**
|
||||
* Check whether the value is Object that implements [[Construct]].
|
||||
*
|
||||
* @return true, if value is constructor object;
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
ecma_is_constructor (const ecma_value_t& value) /**< ecma-value */
|
||||
{
|
||||
if (!ecma_is_value_object (value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
|
||||
JERRY_ASSERT(obj_p != NULL);
|
||||
JERRY_ASSERT(!ecma_is_lexical_environment (obj_p));
|
||||
|
||||
return (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION
|
||||
|| ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
|
||||
} /* ecma_is_constructor */
|
||||
|
||||
/**
|
||||
* Function object creation operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 13.2
|
||||
*
|
||||
* @return pointer to newly created Function object
|
||||
*/
|
||||
ecma_object_t*
|
||||
ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[], /**< formal parameters list */
|
||||
ecma_length_t formal_parameters_number, /**< formal parameters list's length */
|
||||
ecma_object_t *scope_p, /**< function's scope */
|
||||
bool is_strict, /**< 'strict' flag */
|
||||
opcode_counter_t first_opcode_idx) /**< index of first opcode of function's body */
|
||||
{
|
||||
// 1., 4., 13.
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
|
||||
|
||||
ecma_object_t *f = ecma_create_object (prototype_obj_p, true, ECMA_OBJECT_TYPE_FUNCTION);
|
||||
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
|
||||
// 2., 6., 7., 8.
|
||||
/*
|
||||
* We don't setup [[Get]], [[Call]], [[Construct]], [[HasInstance]] for each function object.
|
||||
* Instead we set the object's type to ECMA_OBJECT_TYPE_FUNCTION
|
||||
* that defines which version of the routine should be used on demand.
|
||||
*/
|
||||
|
||||
// 3.
|
||||
ecma_property_t *class_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_FUNCTION_UL;
|
||||
|
||||
// 9.
|
||||
ecma_property_t *scope_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_SCOPE);
|
||||
ECMA_SET_POINTER(scope_prop_p->u.internal_property.value, scope_p);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_object (f, scope_p);
|
||||
|
||||
// 10., 11.
|
||||
ecma_property_t *formal_parameters_prop_p = ecma_create_internal_property (f,
|
||||
ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS);
|
||||
if (formal_parameters_number != 0)
|
||||
{
|
||||
ecma_collection_header_t *formal_parameters_collection_p = ecma_new_strings_collection (formal_parameter_list_p,
|
||||
formal_parameters_number);
|
||||
ECMA_SET_POINTER (formal_parameters_prop_p->u.internal_property.value, formal_parameters_collection_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (formal_parameters_prop_p->u.internal_property.value == ECMA_NULL_POINTER);
|
||||
}
|
||||
|
||||
// 12.
|
||||
ecma_property_t *code_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CODE);
|
||||
code_prop_p->u.internal_property.value = ecma_pack_code_internal_property_value (is_strict,
|
||||
first_opcode_idx);
|
||||
|
||||
// 14.
|
||||
ecma_number_t* len_p = ecma_alloc_number ();
|
||||
*len_p = ecma_uint32_to_number (formal_parameters_number);
|
||||
|
||||
// 15.
|
||||
ecma_property_descriptor_t length_prop_desc = ecma_make_empty_property_descriptor ();
|
||||
length_prop_desc.is_value_defined = true;
|
||||
length_prop_desc.value = ecma_make_number_value (len_p);
|
||||
|
||||
ecma_string_t* magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
|
||||
ecma_completion_value_t completion = ecma_op_object_define_own_property (f,
|
||||
magic_string_length_p,
|
||||
&length_prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)
|
||||
|| ecma_is_completion_value_normal_false (completion));
|
||||
|
||||
ecma_dealloc_number (len_p);
|
||||
len_p = NULL;
|
||||
|
||||
// 16.
|
||||
ecma_object_t *proto_p = ecma_op_create_object_object_noarg ();
|
||||
|
||||
// 17.
|
||||
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.value = ecma_make_object_value (f);
|
||||
|
||||
prop_desc.is_writable_defined = true;
|
||||
prop_desc.is_writable = true;
|
||||
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
prop_desc.is_enumerable = false;
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
prop_desc.is_configurable = true;
|
||||
}
|
||||
|
||||
ecma_string_t *magic_string_constructor_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CONSTRUCTOR);
|
||||
ecma_op_object_define_own_property (proto_p,
|
||||
magic_string_constructor_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (magic_string_constructor_p);
|
||||
|
||||
// 18.
|
||||
prop_desc.value = ecma_make_object_value (proto_p);
|
||||
prop_desc.is_configurable = false;
|
||||
ecma_string_t *magic_string_prototype_p = ecma_get_magic_string (ECMA_MAGIC_STRING_PROTOTYPE);
|
||||
ecma_op_object_define_own_property (f,
|
||||
magic_string_prototype_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (magic_string_prototype_p);
|
||||
|
||||
ecma_deref_object (proto_p);
|
||||
|
||||
// 19.
|
||||
if (is_strict)
|
||||
{
|
||||
ecma_object_t *thrower_p = ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER);
|
||||
|
||||
prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
prop_desc.is_enumerable = false;
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
prop_desc.is_configurable = false;
|
||||
|
||||
prop_desc.is_get_defined = true;
|
||||
prop_desc.get_p = thrower_p;
|
||||
|
||||
prop_desc.is_set_defined = true;
|
||||
prop_desc.set_p = thrower_p;
|
||||
}
|
||||
|
||||
ecma_string_t *magic_string_caller_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CALLER);
|
||||
ecma_op_object_define_own_property (f,
|
||||
magic_string_caller_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (magic_string_caller_p);
|
||||
|
||||
ecma_string_t *magic_string_arguments_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ARGUMENTS);
|
||||
ecma_op_object_define_own_property (f,
|
||||
magic_string_arguments_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
ecma_deref_ecma_string (magic_string_arguments_p);
|
||||
|
||||
ecma_deref_object (thrower_p);
|
||||
}
|
||||
|
||||
return f;
|
||||
} /* ecma_op_create_function_object */
|
||||
|
||||
/**
|
||||
* Setup variables for arguments listed in formal parameter list.
|
||||
*
|
||||
* See also:
|
||||
* Declaration binding instantiation (ECMA-262 v5, 10.5), block 4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_function_call_setup_args_variables (ecma_object_t *func_obj_p, /**< Function object */
|
||||
ecma_object_t *env_p, /**< lexical environment */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len, /**< length of argument list */
|
||||
bool is_strict) /**< flag indicating strict mode */
|
||||
{
|
||||
ecma_property_t *formal_parameters_prop_p = ecma_get_internal_property (func_obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS);
|
||||
ecma_collection_header_t *formal_parameters_p;
|
||||
formal_parameters_p = ECMA_GET_POINTER (ecma_collection_header_t,
|
||||
formal_parameters_prop_p->u.internal_property.value);
|
||||
|
||||
if (formal_parameters_p == NULL)
|
||||
{
|
||||
return ecma_make_empty_completion_value ();
|
||||
}
|
||||
|
||||
ecma_length_t formal_parameters_count = formal_parameters_p->unit_number;
|
||||
|
||||
ecma_collection_iterator_t formal_params_iterator;
|
||||
ecma_collection_iterator_init (&formal_params_iterator, formal_parameters_p);
|
||||
|
||||
for (size_t n = 0;
|
||||
n < formal_parameters_count;
|
||||
n++)
|
||||
{
|
||||
ecma_value_t v;
|
||||
if (n >= arguments_list_len)
|
||||
{
|
||||
v = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
v = arguments_list_p[n];
|
||||
}
|
||||
|
||||
bool is_moved = ecma_collection_iterator_next (&formal_params_iterator);
|
||||
JERRY_ASSERT (is_moved);
|
||||
|
||||
ecma_value_t formal_parameter_name_value = *formal_params_iterator.current_value_p;
|
||||
ecma_string_t *formal_parameter_name_string_p = ecma_get_string_from_value (formal_parameter_name_value);
|
||||
|
||||
bool arg_already_declared = ecma_op_has_binding (env_p, formal_parameter_name_string_p);
|
||||
if (!arg_already_declared)
|
||||
{
|
||||
ecma_completion_value_t completion = ecma_op_create_mutable_binding (env_p,
|
||||
formal_parameter_name_string_p,
|
||||
false);
|
||||
if (ecma_is_completion_value_throw (completion))
|
||||
{
|
||||
return completion;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (completion));
|
||||
|
||||
completion = ecma_op_set_mutable_binding (env_p,
|
||||
formal_parameter_name_string_p,
|
||||
v,
|
||||
is_strict);
|
||||
|
||||
if (ecma_is_completion_value_throw (completion))
|
||||
{
|
||||
return completion;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (completion));
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
} /* ecma_function_call_setup_args_variables */
|
||||
|
||||
/**
|
||||
* [[Call]] implementation for Function objects,
|
||||
* created through 13.2 (ECMA_OBJECT_TYPE_FUNCTION)
|
||||
* or 15.3.4.5 (ECMA_OBJECT_TYPE_BOUND_FUNCTION),
|
||||
* and for built-in Function objects
|
||||
* from section 15 (ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION).
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object */
|
||||
const ecma_value_t& value) /**< argument 'V' */
|
||||
{
|
||||
JERRY_ASSERT(func_obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (func_obj_p));
|
||||
|
||||
if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION)
|
||||
{
|
||||
if (!ecma_is_value_object (value))
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
ecma_object_t* v_obj_p = ecma_get_object_from_value (value);
|
||||
|
||||
ecma_string_t *prototype_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_PROTOTYPE);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (prototype_obj_value,
|
||||
ecma_op_object_get (func_obj_p, prototype_magic_string_p),
|
||||
ret_value);
|
||||
|
||||
if (!ecma_is_value_object (prototype_obj_value))
|
||||
{
|
||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *prototype_obj_p = ecma_get_object_from_value (prototype_obj_value);
|
||||
JERRY_ASSERT (prototype_obj_p != NULL);
|
||||
|
||||
do
|
||||
{
|
||||
v_obj_p = ecma_get_object_prototype (v_obj_p);
|
||||
|
||||
if (v_obj_p == NULL)
|
||||
{
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
|
||||
break;
|
||||
}
|
||||
else if (v_obj_p == prototype_obj_p)
|
||||
{
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (prototype_obj_value);
|
||||
|
||||
ecma_deref_ecma_string (prototype_magic_string_p);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
else if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
|
||||
|
||||
JERRY_UNIMPLEMENTED ("Bound functions are not implemented.");
|
||||
}
|
||||
} /* ecma_op_function_has_instance */
|
||||
|
||||
/**
|
||||
* [[Call]] implementation for Function objects,
|
||||
* created through 13.2 (ECMA_OBJECT_TYPE_FUNCTION)
|
||||
* or 15.3.4.5 (ECMA_OBJECT_TYPE_BOUND_FUNCTION),
|
||||
* and for built-in Function objects
|
||||
* from section 15 (ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION).
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
|
||||
const ecma_value_t& this_arg_value, /**< 'this' argument's value */
|
||||
const ecma_value_t* arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< length of arguments list */
|
||||
{
|
||||
JERRY_ASSERT(func_obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (func_obj_p));
|
||||
JERRY_ASSERT(ecma_op_is_callable (ecma_make_object_value (func_obj_p)));
|
||||
JERRY_ASSERT(arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION)
|
||||
{
|
||||
if (unlikely (ecma_get_object_is_builtin (func_obj_p)))
|
||||
{
|
||||
return ecma_builtin_dispatch_call (func_obj_p, this_arg_value, arguments_list_p, arguments_list_len);
|
||||
}
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
/* Entering Function Code (ECMA-262 v5, 10.4.3) */
|
||||
|
||||
ecma_property_t *scope_prop_p = ecma_get_internal_property (func_obj_p, ECMA_INTERNAL_PROPERTY_SCOPE);
|
||||
ecma_property_t *code_prop_p = ecma_get_internal_property (func_obj_p, ECMA_INTERNAL_PROPERTY_CODE);
|
||||
|
||||
ecma_object_t *scope_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
|
||||
scope_prop_p->u.internal_property.value);
|
||||
uint32_t code_prop_value = code_prop_p->u.internal_property.value;
|
||||
|
||||
bool is_strict;
|
||||
// 8.
|
||||
opcode_counter_t code_first_opcode_idx = ecma_unpack_code_internal_property_value (code_prop_value, &is_strict);
|
||||
|
||||
ecma_value_t this_binding;
|
||||
// 1.
|
||||
if (is_strict)
|
||||
{
|
||||
this_binding = ecma_copy_value (this_arg_value, true);
|
||||
}
|
||||
else if (ecma_is_value_undefined (this_arg_value)
|
||||
|| ecma_is_value_null (this_arg_value))
|
||||
{
|
||||
// 2.
|
||||
this_binding = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 3., 4.
|
||||
ecma_completion_value_t completion = ecma_op_to_object (this_arg_value);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal (completion));
|
||||
|
||||
this_binding = ecma_get_completion_value_value (completion);
|
||||
}
|
||||
|
||||
// 5.
|
||||
ecma_object_t *local_env_p = ecma_create_decl_lex_env (scope_p);
|
||||
|
||||
// 9.
|
||||
ECMA_TRY_CATCH (args_var_declaration_ret,
|
||||
ecma_function_call_setup_args_variables (func_obj_p,
|
||||
local_env_p,
|
||||
arguments_list_p,
|
||||
arguments_list_len,
|
||||
is_strict),
|
||||
ret_value);
|
||||
|
||||
ecma_completion_value_t completion = run_int_from_pos (code_first_opcode_idx,
|
||||
this_binding,
|
||||
local_env_p,
|
||||
is_strict,
|
||||
false);
|
||||
if (ecma_is_completion_value_return (completion))
|
||||
{
|
||||
ret_value = ecma_make_normal_completion_value (ecma_get_completion_value_value (completion));
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = completion;
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (args_var_declaration_ret);
|
||||
|
||||
ecma_deref_object (local_env_p);
|
||||
ecma_free_value (this_binding, true);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
else if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION)
|
||||
{
|
||||
return ecma_builtin_dispatch_call (func_obj_p, this_arg_value, arguments_list_p, arguments_list_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT(ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
|
||||
|
||||
JERRY_UNIMPLEMENTED ("Bound functions are not implemented.");
|
||||
}
|
||||
} /* ecma_op_function_call */
|
||||
|
||||
/**
|
||||
* [[Construct]] implementation for Function objects,
|
||||
* created through 13.2 (ECMA_OBJECT_TYPE_FUNCTION)
|
||||
* or 15.3.4.5 (ECMA_OBJECT_TYPE_BOUND_FUNCTION).
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
|
||||
const ecma_value_t* arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< length of arguments list */
|
||||
{
|
||||
JERRY_ASSERT(func_obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (func_obj_p));
|
||||
JERRY_ASSERT(ecma_is_constructor (ecma_make_object_value (func_obj_p)));
|
||||
JERRY_ASSERT(arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION)
|
||||
{
|
||||
if (unlikely (ecma_get_object_is_builtin (func_obj_p)))
|
||||
{
|
||||
return ecma_builtin_dispatch_construct (func_obj_p, arguments_list_p, arguments_list_len);
|
||||
}
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ecma_string_t *prototype_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_PROTOTYPE);
|
||||
|
||||
// 5.
|
||||
ECMA_TRY_CATCH (func_obj_prototype_prop_value,
|
||||
ecma_op_object_get (func_obj_p,
|
||||
prototype_magic_string_p),
|
||||
ret_value);
|
||||
|
||||
// 6.
|
||||
ecma_object_t *prototype_p;
|
||||
if (ecma_is_value_object (func_obj_prototype_prop_value))
|
||||
{
|
||||
prototype_p = ecma_get_object_from_value (func_obj_prototype_prop_value);
|
||||
ecma_ref_object (prototype_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 7.
|
||||
prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
|
||||
}
|
||||
|
||||
// 1., 2., 4.
|
||||
ecma_object_t *obj_p = ecma_create_object (prototype_p, true, ECMA_OBJECT_TYPE_GENERAL);
|
||||
|
||||
// 3.
|
||||
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_FUNCTION_UL;
|
||||
|
||||
ecma_deref_object (prototype_p);
|
||||
|
||||
// 8.
|
||||
ECMA_TRY_CATCH (call_completion,
|
||||
ecma_op_function_call (func_obj_p,
|
||||
ecma_make_object_value (obj_p),
|
||||
arguments_list_p,
|
||||
arguments_list_len),
|
||||
ret_value);
|
||||
|
||||
ecma_value_t obj_value;
|
||||
|
||||
// 9.
|
||||
if (ecma_is_value_object (call_completion))
|
||||
{
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
obj_value = ecma_copy_value (call_completion, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 10.
|
||||
obj_value = ecma_make_object_value (obj_p);
|
||||
}
|
||||
|
||||
ret_value = ecma_make_normal_completion_value (obj_value);
|
||||
|
||||
ECMA_FINALIZE (call_completion);
|
||||
ECMA_FINALIZE (func_obj_prototype_prop_value);
|
||||
|
||||
ecma_deref_ecma_string (prototype_magic_string_p);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT(ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
|
||||
|
||||
JERRY_UNIMPLEMENTED ("Bound functions are not implemented.");
|
||||
}
|
||||
} /* ecma_op_function_construct */
|
||||
/**
|
||||
* Function declaration.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.5 - Declaration binding instantiation (block 5).
|
||||
*
|
||||
* @return completion value
|
||||
* returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *function_name_p, /**< function name */
|
||||
opcode_counter_t function_code_opcode_idx, /**< index of first opcode of function code */
|
||||
ecma_string_t* formal_parameter_list_p[], /**< formal parameters list */
|
||||
ecma_length_t formal_parameter_list_length, /**< length of formal parameters list */
|
||||
bool is_strict, /**< flag indicating if function is declared in strict mode code */
|
||||
bool is_configurable_bindings) /**< flag indicating whether function
|
||||
is declared in eval code */
|
||||
{
|
||||
// b.
|
||||
ecma_object_t *func_obj_p = ecma_op_create_function_object (formal_parameter_list_p,
|
||||
formal_parameter_list_length,
|
||||
lex_env_p,
|
||||
is_strict,
|
||||
function_code_opcode_idx);
|
||||
|
||||
// c.
|
||||
bool func_already_declared = ecma_op_has_binding (lex_env_p, function_name_p);
|
||||
|
||||
// d.
|
||||
ecma_completion_value_t completion = ecma_make_empty_completion_value ();
|
||||
|
||||
if (!func_already_declared)
|
||||
{
|
||||
completion = ecma_op_create_mutable_binding (lex_env_p,
|
||||
function_name_p,
|
||||
is_configurable_bindings);
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (completion));
|
||||
}
|
||||
else if (ecma_is_lexical_environment_global (lex_env_p))
|
||||
{
|
||||
// e.
|
||||
ecma_object_t *glob_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
|
||||
|
||||
ecma_property_t *existing_prop_p = ecma_op_object_get_property (glob_obj_p, function_name_p);
|
||||
|
||||
if (ecma_is_property_configurable (existing_prop_p))
|
||||
{
|
||||
ecma_property_descriptor_t property_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
property_desc.is_value_defined = true;
|
||||
property_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
property_desc.is_writable_defined = true;
|
||||
property_desc.is_writable = true;
|
||||
|
||||
property_desc.is_enumerable_defined = true;
|
||||
property_desc.is_enumerable = true;
|
||||
|
||||
property_desc.is_configurable_defined = true;
|
||||
property_desc.is_configurable = is_configurable_bindings;
|
||||
}
|
||||
|
||||
completion = ecma_op_object_define_own_property (glob_obj_p,
|
||||
function_name_p,
|
||||
&property_desc,
|
||||
true);
|
||||
}
|
||||
else if (existing_prop_p->type == ECMA_PROPERTY_NAMEDACCESSOR)
|
||||
{
|
||||
completion = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (existing_prop_p->type == ECMA_PROPERTY_NAMEDDATA);
|
||||
|
||||
if (!ecma_is_property_writable (existing_prop_p)
|
||||
|| !ecma_is_property_enumerable (existing_prop_p))
|
||||
{
|
||||
completion = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
}
|
||||
|
||||
ecma_deref_object (glob_obj_p);
|
||||
}
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
if (ecma_is_completion_value_throw (completion))
|
||||
{
|
||||
ret_value = completion;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (completion));
|
||||
|
||||
// f.
|
||||
ret_value = ecma_op_set_mutable_binding (lex_env_p,
|
||||
function_name_p,
|
||||
ecma_make_object_value (func_obj_p),
|
||||
is_strict);
|
||||
}
|
||||
|
||||
ecma_deref_object (func_obj_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_function_declaration */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,68 @@
|
||||
/* Copyright 2014-2015 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 ECMA_FUNCTION_OBJECT_H
|
||||
#define ECMA_FUNCTION_OBJECT_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "vm.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmafunctionobject ECMA Function object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern bool ecma_op_is_callable (const ecma_value_t& value);
|
||||
extern bool ecma_is_constructor (const ecma_value_t& value);
|
||||
|
||||
extern ecma_object_t*
|
||||
ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[],
|
||||
ecma_length_t formal_parameters_number,
|
||||
ecma_object_t *scope_p,
|
||||
bool is_strict,
|
||||
opcode_counter_t first_opcode_idx);
|
||||
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_function_call (ecma_object_t *func_obj_p,
|
||||
const ecma_value_t& this_arg_value,
|
||||
const ecma_value_t* arguments_list_p,
|
||||
ecma_length_t arguments_list_len);
|
||||
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_function_construct (ecma_object_t *func_obj_p,
|
||||
const ecma_value_t* arguments_list_p,
|
||||
ecma_length_t arguments_list_len);
|
||||
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_function_has_instance (ecma_object_t *func_obj_p,
|
||||
const ecma_value_t& value);
|
||||
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_function_declaration (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *function_name_p,
|
||||
opcode_counter_t function_code_opcode_idx,
|
||||
ecma_string_t* formal_parameter_list_p[],
|
||||
ecma_length_t formal_parameter_list_length,
|
||||
bool is_strict,
|
||||
bool is_configurable_bindings);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_FUNCTION_OBJECT_H */
|
||||
@@ -0,0 +1,310 @@
|
||||
/* Copyright 2014-2015 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of ECMA GetValue and PutValue
|
||||
*/
|
||||
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-operations.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaoperations ECMA-defined operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* GetValue operation part (lexical environment base or unresolvable reference).
|
||||
*
|
||||
* See also: ECMA-262 v5, 8.7.1, sections 3 and 5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_get_value_lex_env_base (ecma_object_t *ref_base_lex_env_p, /**< reference's base (lexical environment) */
|
||||
ecma_string_t *var_name_string_p, /**< variable name */
|
||||
bool is_strict) /**< flag indicating strict mode */
|
||||
{
|
||||
const bool is_unresolvable_reference = (ref_base_lex_env_p == NULL);
|
||||
|
||||
// 3.
|
||||
if (unlikely (is_unresolvable_reference))
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE));
|
||||
}
|
||||
|
||||
// 5.
|
||||
JERRY_ASSERT(ref_base_lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (ref_base_lex_env_p));
|
||||
|
||||
// 5.a
|
||||
return ecma_op_get_binding_value (ref_base_lex_env_p,
|
||||
var_name_string_p,
|
||||
is_strict);
|
||||
} /* ecma_op_get_value_lex_env_base */
|
||||
|
||||
/**
|
||||
* GetValue operation part (object base).
|
||||
*
|
||||
* See also: ECMA-262 v5, 8.7.1, section 4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_get_value_object_base (ecma_reference_t ref) /**< ECMA-reference */
|
||||
{
|
||||
const ecma_value_t base = ref.base;
|
||||
const bool is_unresolvable_reference = ecma_is_value_undefined (base);
|
||||
const bool has_primitive_base = (ecma_is_value_boolean (base)
|
||||
|| ecma_is_value_number (base)
|
||||
|| ecma_is_value_string (base));
|
||||
const bool has_object_base = (ecma_is_value_object (base)
|
||||
&& !(ecma_is_lexical_environment (ecma_get_object_from_value (base))));
|
||||
const bool is_property_reference = has_primitive_base || has_object_base;
|
||||
|
||||
JERRY_ASSERT (!is_unresolvable_reference);
|
||||
JERRY_ASSERT (is_property_reference);
|
||||
|
||||
// 4.a
|
||||
if (!has_primitive_base)
|
||||
{
|
||||
// 4.b case 1
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (base);
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
|
||||
return ecma_op_object_get (obj_p, ECMA_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
ref.referenced_name_cp));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4.b case 2
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (obj_base, ecma_op_to_object (base), ret_value);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_base);
|
||||
JERRY_ASSERT (obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
|
||||
ret_value = ecma_op_object_get (obj_p, ECMA_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
ref.referenced_name_cp));
|
||||
|
||||
ECMA_FINALIZE (obj_base);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
} /* ecma_op_get_value_object_base */
|
||||
|
||||
/**
|
||||
* PutValue operation part (lexical environment base or unresolvable reference).
|
||||
*
|
||||
* See also: ECMA-262 v5, 8.7.2, sections 3 and 5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_put_value_lex_env_base (ecma_object_t *ref_base_lex_env_p, /**< reference's base (lexical environment) */
|
||||
ecma_string_t *var_name_string_p, /**< variable name */
|
||||
bool is_strict, /**< flag indicating strict mode */
|
||||
const ecma_value_t& value) /**< ECMA-value */
|
||||
{
|
||||
const bool is_unresolvable_reference = (ref_base_lex_env_p == NULL);
|
||||
|
||||
// 3.
|
||||
if (unlikely (is_unresolvable_reference))
|
||||
{
|
||||
// 3.a.
|
||||
if (is_strict)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 3.b.
|
||||
ecma_object_t *global_object_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
|
||||
|
||||
ecma_completion_value_t completion = ecma_op_object_put (global_object_p,
|
||||
var_name_string_p,
|
||||
value,
|
||||
false);
|
||||
|
||||
ecma_deref_object (global_object_p);
|
||||
|
||||
JERRY_ASSERT(ecma_is_completion_value_normal_true (completion)
|
||||
|| ecma_is_completion_value_normal_false (completion));
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
}
|
||||
}
|
||||
|
||||
// 5.
|
||||
JERRY_ASSERT(ref_base_lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (ref_base_lex_env_p));
|
||||
|
||||
// 5.a
|
||||
return ecma_op_set_mutable_binding (ref_base_lex_env_p,
|
||||
var_name_string_p,
|
||||
value,
|
||||
is_strict);
|
||||
} /* ecma_op_put_value_lex_env_base */
|
||||
|
||||
/**
|
||||
* Reject sequence for PutValue
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_reject_put (bool is_throw) /**< Throw flag */
|
||||
{
|
||||
if (is_throw)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
}
|
||||
} /* ecma_reject_put */
|
||||
|
||||
/**
|
||||
* PutValue operation part (object base).
|
||||
*
|
||||
* See also: ECMA-262 v5, 8.7.2, section 4
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_put_value_object_base (ecma_reference_t ref, /**< ECMA-reference */
|
||||
const ecma_value_t& value) /**< ECMA-value */
|
||||
{
|
||||
const ecma_value_t base = ref.base;
|
||||
const bool is_unresolvable_reference = ecma_is_value_undefined (base);
|
||||
const bool has_primitive_base = (ecma_is_value_boolean (base)
|
||||
|| ecma_is_value_number (base)
|
||||
|| ecma_is_value_string (base));
|
||||
const bool has_object_base = (ecma_is_value_object (base)
|
||||
&& !(ecma_is_lexical_environment (ecma_get_object_from_value (base))));
|
||||
const bool is_property_reference = has_primitive_base || has_object_base;
|
||||
|
||||
JERRY_ASSERT (!is_unresolvable_reference);
|
||||
JERRY_ASSERT (is_property_reference);
|
||||
|
||||
// 4.a
|
||||
if (!has_primitive_base)
|
||||
{
|
||||
// 4.b case 1
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (base);
|
||||
JERRY_ASSERT (obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (put_ret_value,
|
||||
ecma_op_object_put (obj_p,
|
||||
ECMA_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
ref.referenced_name_cp),
|
||||
value,
|
||||
ref.is_strict),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
ECMA_FINALIZE (put_ret_value);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4.b case 2
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
// sub_1.
|
||||
ECMA_TRY_CATCH (obj_base, ecma_op_to_object (base), ret_value);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_base);
|
||||
JERRY_ASSERT (obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
|
||||
ecma_string_t *referenced_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
ref.referenced_name_cp);
|
||||
|
||||
// sub_2.
|
||||
if (!ecma_op_object_can_put (obj_p, referenced_name_p))
|
||||
{
|
||||
ret_value = ecma_reject_put (ref.is_strict);
|
||||
}
|
||||
else
|
||||
{
|
||||
// sub_3.
|
||||
ecma_property_t *own_prop_p = ecma_op_object_get_own_property (obj_p, referenced_name_p);
|
||||
|
||||
// sub_5.
|
||||
ecma_property_t *prop_p = ecma_op_object_get_property (obj_p, referenced_name_p);
|
||||
|
||||
// sub_4., sub_7
|
||||
if ((own_prop_p != NULL
|
||||
&& own_prop_p->type == ECMA_PROPERTY_NAMEDDATA)
|
||||
|| (prop_p == NULL)
|
||||
|| (prop_p->type != ECMA_PROPERTY_NAMEDACCESSOR))
|
||||
{
|
||||
ret_value = ecma_reject_put (ref.is_strict);
|
||||
}
|
||||
else
|
||||
{
|
||||
// sub_6.
|
||||
JERRY_ASSERT (prop_p != NULL && prop_p->type == ECMA_PROPERTY_NAMEDACCESSOR);
|
||||
|
||||
ecma_object_t *setter_p = ECMA_GET_NON_NULL_POINTER(ecma_object_t,
|
||||
prop_p->u.named_accessor_property.set_p);
|
||||
JERRY_ASSERT (setter_p != NULL);
|
||||
|
||||
ECMA_TRY_CATCH (call_ret,
|
||||
ecma_op_function_call (setter_p, base, &value, 1),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
ECMA_FINALIZE (call_ret);
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (obj_base);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
} /* ecma_op_put_value_object_base */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,62 @@
|
||||
/* Copyright 2014-2015 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-builtins.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-lcache.h"
|
||||
#include "ecma-operations.h"
|
||||
#include "ecma-stack.h"
|
||||
#include "mem-allocator.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmainitfinalize Initialization and finalization of ECMA components
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialize ECMA components
|
||||
*/
|
||||
void
|
||||
ecma_init (void)
|
||||
{
|
||||
ecma_strings_init ();
|
||||
ecma_init_builtins ();
|
||||
ecma_lcache_init ();
|
||||
ecma_stack_init ();
|
||||
|
||||
mem_register_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
|
||||
} /* ecma_init */
|
||||
|
||||
/**
|
||||
* Finalize ECMA components
|
||||
*/
|
||||
void
|
||||
ecma_finalize (void)
|
||||
{
|
||||
mem_unregister_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
|
||||
|
||||
ecma_stack_finalize ();
|
||||
ecma_finalize_builtins ();
|
||||
ecma_lcache_invalidate_all ();
|
||||
ecma_gc_run ((ecma_gc_gen_t) (ECMA_GC_GEN_COUNT - 1));
|
||||
} /* ecma_finalize */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,475 @@
|
||||
/* Copyright 2014-2015 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-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup lexicalenvironment Lexical environment
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* HasBinding operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.2.1
|
||||
*
|
||||
* @return true / false
|
||||
*/
|
||||
bool
|
||||
ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *name_p) /**< argument N */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
|
||||
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
||||
{
|
||||
ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p);
|
||||
|
||||
return (property_p != NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
|
||||
|
||||
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
||||
|
||||
return (ecma_op_object_get_property (binding_obj_p, name_p) != NULL);
|
||||
}
|
||||
} /* ecma_op_has_binding */
|
||||
|
||||
/**
|
||||
* CreateMutableBinding operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *name_p, /**< argument N */
|
||||
bool is_deletable) /**< argument D */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
JERRY_ASSERT(name_p != NULL);
|
||||
|
||||
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
||||
{
|
||||
ecma_create_named_data_property (lex_env_p,
|
||||
name_p,
|
||||
true, false, is_deletable);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
|
||||
|
||||
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
||||
|
||||
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
prop_desc.is_writable_defined = true;
|
||||
prop_desc.is_writable = true;
|
||||
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
prop_desc.is_enumerable = true;
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
prop_desc.is_configurable = is_deletable;
|
||||
}
|
||||
|
||||
ecma_completion_value_t completion = ecma_op_object_define_own_property (binding_obj_p,
|
||||
name_p,
|
||||
&prop_desc,
|
||||
true);
|
||||
|
||||
if (ecma_is_completion_value_throw (completion))
|
||||
{
|
||||
return completion;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)
|
||||
|| ecma_is_completion_value_normal_false (completion));
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
} /* ecma_op_create_mutable_binding */
|
||||
|
||||
/**
|
||||
* SetMutableBinding operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_set_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *name_p, /**< argument N */
|
||||
const ecma_value_t& value, /**< argument V */
|
||||
bool is_strict) /**< argument S */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
JERRY_ASSERT(name_p != NULL);
|
||||
|
||||
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
# ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
bool is_equal = false;
|
||||
|
||||
ecma_string_t *arguments_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ARGUMENTS);
|
||||
if (ecma_compare_ecma_strings (name_p, arguments_magic_string_p))
|
||||
{
|
||||
is_equal = true;
|
||||
}
|
||||
ecma_deref_ecma_string (arguments_magic_string_p);
|
||||
|
||||
JERRY_ASSERT (!is_equal);
|
||||
|
||||
if (is_equal)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR));
|
||||
}
|
||||
# endif /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
ecma_property_t *property_p = ecma_get_named_data_property (lex_env_p, name_p);
|
||||
|
||||
if (ecma_is_property_writable (property_p))
|
||||
{
|
||||
ecma_named_data_property_assign_value (lex_env_p, property_p, value);
|
||||
}
|
||||
else if (is_strict)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
|
||||
|
||||
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
||||
|
||||
ecma_completion_value_t completion = ecma_op_object_put (binding_obj_p,
|
||||
name_p,
|
||||
value,
|
||||
is_strict);
|
||||
|
||||
if (ecma_is_completion_value_throw (completion))
|
||||
{
|
||||
return completion;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)
|
||||
|| ecma_is_completion_value_normal_false (completion));
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
} /* ecma_op_set_mutable_binding */
|
||||
|
||||
/**
|
||||
* GetBindingValue operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_get_binding_value (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *name_p, /**< argument N */
|
||||
bool is_strict) /**< argument S */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
JERRY_ASSERT(name_p != NULL);
|
||||
|
||||
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
# ifdef CONFIG_ECMA_COMPACT_PROFILE
|
||||
bool is_equal = false;
|
||||
|
||||
ecma_string_t *arguments_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ARGUMENTS);
|
||||
if (ecma_compare_ecma_strings (name_p, arguments_magic_string_p))
|
||||
{
|
||||
is_equal = true;
|
||||
}
|
||||
ecma_deref_ecma_string (arguments_magic_string_p);
|
||||
|
||||
JERRY_ASSERT (!is_equal);
|
||||
|
||||
if (is_equal)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR));
|
||||
}
|
||||
# endif /* CONFIG_ECMA_COMPACT_PROFILE */
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
ecma_property_t *property_p = ecma_get_named_data_property (lex_env_p, name_p);
|
||||
|
||||
ecma_value_t prop_value = ecma_get_named_data_property_value (property_p);
|
||||
|
||||
/* is the binding mutable? */
|
||||
if (!ecma_is_property_writable (property_p)
|
||||
&& ecma_is_value_empty (prop_value))
|
||||
{
|
||||
/* unitialized immutable binding */
|
||||
if (is_strict)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_copy_value (prop_value, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
|
||||
|
||||
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
||||
|
||||
if (ecma_op_object_get_property (binding_obj_p, name_p) == NULL)
|
||||
{
|
||||
if (is_strict)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_op_object_get (binding_obj_p, name_p);
|
||||
}
|
||||
} /* ecma_op_get_binding_value */
|
||||
|
||||
/**
|
||||
* DeleteBinding operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Return value is simple and so need not be freed.
|
||||
* However, ecma_free_completion_value may be called for it, but it is a no-op.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_delete_binding (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *name_p) /**< argument N */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
JERRY_ASSERT(name_p != NULL);
|
||||
|
||||
|
||||
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
||||
{
|
||||
ecma_property_t *prop_p = ecma_find_named_property (lex_env_p, name_p);
|
||||
ecma_simple_value_t ret_val;
|
||||
|
||||
if (prop_p == NULL)
|
||||
{
|
||||
ret_val = ECMA_SIMPLE_VALUE_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT(prop_p->type == ECMA_PROPERTY_NAMEDDATA);
|
||||
|
||||
if (!ecma_is_property_configurable (prop_p))
|
||||
{
|
||||
ret_val = ECMA_SIMPLE_VALUE_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_delete_property (lex_env_p, prop_p);
|
||||
|
||||
ret_val = ECMA_SIMPLE_VALUE_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_simple_completion_value (ret_val);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
|
||||
|
||||
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
||||
|
||||
return ecma_op_object_delete (binding_obj_p, name_p, false);
|
||||
}
|
||||
} /* ecma_op_delete_binding */
|
||||
|
||||
/**
|
||||
* ImplicitThisValue operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value.
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_implicit_this_value (ecma_object_t *lex_env_p) /**< lexical environment */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
|
||||
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
|
||||
|
||||
if (ecma_get_lex_env_provide_this (lex_env_p))
|
||||
{
|
||||
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
||||
ecma_ref_object (binding_obj_p);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_object_value (binding_obj_p));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
}
|
||||
} /* ecma_op_implicit_this_value */
|
||||
|
||||
/**
|
||||
* CreateImmutableBinding operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.2.1
|
||||
*/
|
||||
void
|
||||
ecma_op_create_immutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *name_p) /**< argument N */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
|
||||
|
||||
/*
|
||||
* Warning:
|
||||
* Whether immutable bindings are deletable seems not to be defined by ECMA v5.
|
||||
*/
|
||||
ecma_property_t *prop_p = ecma_create_named_data_property (lex_env_p,
|
||||
name_p,
|
||||
false, false, false);
|
||||
|
||||
JERRY_ASSERT(ecma_is_value_undefined (ecma_get_named_data_property_value (prop_p)));
|
||||
|
||||
ecma_set_named_data_property_value (prop_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY));
|
||||
} /* ecma_op_create_immutable_binding */
|
||||
|
||||
/**
|
||||
* InitializeImmutableBinding operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.2.1
|
||||
*/
|
||||
void
|
||||
ecma_op_initialize_immutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *name_p, /**< argument N */
|
||||
const ecma_value_t& value) /**< argument V */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
|
||||
|
||||
ecma_property_t *prop_p = ecma_get_named_data_property (lex_env_p, name_p);
|
||||
|
||||
/* The binding must be unitialized immutable binding */
|
||||
JERRY_ASSERT(!ecma_is_property_writable (prop_p)
|
||||
&& ecma_is_value_empty (ecma_get_named_data_property_value (prop_p)));
|
||||
|
||||
ecma_named_data_property_assign_value (lex_env_p, prop_p, value);
|
||||
} /* ecma_op_initialize_immutable_binding */
|
||||
|
||||
/**
|
||||
* The Global Environment constructor.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.2.3
|
||||
*
|
||||
* @return pointer to created lexical environment
|
||||
*/
|
||||
ecma_object_t*
|
||||
ecma_op_create_global_environment (ecma_object_t *glob_obj_p) /**< the Global object */
|
||||
{
|
||||
#ifdef CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE
|
||||
(void) glob_obj_p;
|
||||
ecma_object_t *glob_env_p = ecma_create_decl_lex_env (NULL);
|
||||
#else /* !CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE */
|
||||
ecma_object_t *glob_env_p = ecma_create_object_lex_env (NULL, glob_obj_p, false);
|
||||
#endif /* !CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE */
|
||||
|
||||
return glob_env_p;
|
||||
} /* ecma_op_create_global_environment */
|
||||
|
||||
/**
|
||||
* Figure out whether the lexical environment is global.
|
||||
*
|
||||
* @return true - if lexical environment is object-bound and corresponding object is global object,
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
ecma_is_lexical_environment_global (ecma_object_t *lex_env_p) /**< lexical environment */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
|
||||
ecma_lexical_environment_type_t type = ecma_get_lex_env_type (lex_env_p);
|
||||
|
||||
if (type == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND)
|
||||
{
|
||||
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
|
||||
|
||||
return ecma_builtin_is (binding_obj_p, ECMA_BUILTIN_ID_GLOBAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} /* ecma_is_lexical_environment_global */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,76 @@
|
||||
/* Copyright 2014-2015 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 ECMA_LEX_ENV_H
|
||||
#define ECMA_LEX_ENV_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-reference.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup lexicalenvironment Lexical environment
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* ECMA-262 v5, 8.7.1 and 8.7.2 */
|
||||
extern ecma_completion_value_t ecma_op_get_value_lex_env_base (ecma_object_t *ref_base_lex_env_p,
|
||||
ecma_string_t *var_name_string_p,
|
||||
bool is_strict);
|
||||
extern ecma_completion_value_t ecma_op_get_value_object_base (ecma_reference_t ref);
|
||||
extern ecma_completion_value_t ecma_op_put_value_lex_env_base (ecma_object_t *ref_base_lex_env_p,
|
||||
ecma_string_t *var_name_string_p,
|
||||
bool is_strict,
|
||||
const ecma_value_t& value);
|
||||
extern ecma_completion_value_t ecma_op_put_value_object_base (ecma_reference_t ref,
|
||||
const ecma_value_t& value);
|
||||
|
||||
/* ECMA-262 v5, Table 17. Abstract methods of Environment Records */
|
||||
extern bool ecma_op_has_binding (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *name_p);
|
||||
extern ecma_completion_value_t ecma_op_create_mutable_binding (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *name_p,
|
||||
bool is_deletable);
|
||||
extern ecma_completion_value_t ecma_op_set_mutable_binding (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *name_p,
|
||||
const ecma_value_t& value,
|
||||
bool is_strict);
|
||||
extern ecma_completion_value_t ecma_op_get_binding_value (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *name_p,
|
||||
bool is_strict);
|
||||
extern ecma_completion_value_t ecma_op_delete_binding (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *name_p);
|
||||
extern ecma_completion_value_t ecma_op_implicit_this_value (ecma_object_t *lex_env_p);
|
||||
|
||||
/* ECMA-262 v5, Table 18. Additional methods of Declarative Environment Records */
|
||||
extern void ecma_op_create_immutable_binding (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *name_p);
|
||||
extern void ecma_op_initialize_immutable_binding (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *name_p,
|
||||
const ecma_value_t& value);
|
||||
|
||||
extern ecma_object_t* ecma_op_create_global_environment (ecma_object_t *glob_obj_p);
|
||||
extern bool ecma_is_lexical_environment_global (ecma_object_t *lex_env_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_LEX_ENV_H */
|
||||
@@ -0,0 +1,74 @@
|
||||
/* 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-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-number-arithmetic.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup numberarithmetic ECMA number arithmetic operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* ECMA-defined number remainder calculation.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 11.5.3
|
||||
*
|
||||
* @return number - calculated remainder.
|
||||
*/
|
||||
ecma_number_t
|
||||
ecma_op_number_remainder (ecma_number_t left_num, /**< left operand */
|
||||
ecma_number_t right_num) /**< right operand */
|
||||
{
|
||||
TODO (Check precision);
|
||||
|
||||
ecma_number_t n = left_num, d = right_num;
|
||||
|
||||
if (ecma_number_is_nan (n)
|
||||
|| ecma_number_is_nan (d)
|
||||
|| ecma_number_is_infinity (n)
|
||||
|| ecma_number_is_zero (d))
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
else if (ecma_number_is_infinity (d)
|
||||
|| (ecma_number_is_zero (n)
|
||||
&& !ecma_number_is_zero (d)))
|
||||
{
|
||||
return n;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (!ecma_number_is_nan (n)
|
||||
&& !ecma_number_is_zero (n)
|
||||
&& !ecma_number_is_infinity (n));
|
||||
JERRY_ASSERT (!ecma_number_is_nan (d)
|
||||
&& !ecma_number_is_zero (d)
|
||||
&& !ecma_number_is_infinity (d));
|
||||
|
||||
ecma_number_t q = ecma_number_trunc (ecma_number_divide (n, d));
|
||||
|
||||
return ecma_number_substract (n, ecma_number_multiply (d, q));
|
||||
} /* ecma_op_number_remainder */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,37 @@
|
||||
/* 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 ECMA_NUMBER_H
|
||||
#define ECMA_NUMBER_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup numberarithmetic ECMA number arithmetic operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_number_t ecma_op_number_remainder (ecma_number_t left_num, ecma_number_t right_num);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ECMA_NUMBER_H */
|
||||
@@ -0,0 +1,72 @@
|
||||
/* Copyright 2014-2015 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-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-objects-general.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmanumberobject ECMA Number object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Number object creation operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 15.7.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_create_number_object (const ecma_value_t& arg) /**< argument passed to the Number constructor */
|
||||
{
|
||||
ecma_completion_value_t conv_to_num_completion = ecma_op_to_number (arg);
|
||||
|
||||
if (!ecma_is_completion_value_normal (conv_to_num_completion))
|
||||
{
|
||||
return conv_to_num_completion;
|
||||
}
|
||||
|
||||
ecma_number_t *prim_value_p = ecma_get_number_from_completion_value (conv_to_num_completion);
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE);
|
||||
#else /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN */
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN */
|
||||
|
||||
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p,
|
||||
true,
|
||||
ECMA_OBJECT_TYPE_GENERAL);
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_NUMBER_UL;
|
||||
|
||||
ecma_property_t *prim_value_prop_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
|
||||
ECMA_SET_POINTER (prim_value_prop_p->u.internal_property.value, prim_value_p);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
|
||||
} /* ecma_op_create_number_object */
|
||||
@@ -0,0 +1,35 @@
|
||||
/* Copyright 2014-2015 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 ECMA_NUMBER_OBJECT_H
|
||||
#define ECMA_NUMBER_OBJECT_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmanumberobject ECMA Number object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_completion_value_t ecma_op_create_number_object (const ecma_value_t& arg);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_NUMBER_OBJECT_H */
|
||||
@@ -0,0 +1,539 @@
|
||||
/* Copyright 2014-2015 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.
|
||||
*/
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmafunctionobject ECMA Function object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-arguments.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/**
|
||||
* Arguments object creation operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 10.6
|
||||
*
|
||||
* @return pointer to newly created Arguments object
|
||||
*/
|
||||
ecma_object_t*
|
||||
ecma_create_arguments_object (ecma_object_t *func_obj_p, /**< callee function */
|
||||
ecma_object_t *lex_env_p, /**< lexical environment the Arguments
|
||||
object is created for */
|
||||
ecma_collection_iterator_t *formal_params_iter_p, /**< formal parameters
|
||||
collection iterator */
|
||||
const ecma_value_t *arguments_list_p, /**< list of arguments */
|
||||
ecma_length_t arguments_list_length, /**< length of arguments' list */
|
||||
bool is_strict) /**< flag indicating whether strict mode is enabled */
|
||||
{
|
||||
// 1.
|
||||
ecma_number_t *len_p = ecma_alloc_number ();
|
||||
*len_p = ecma_uint32_to_number (arguments_list_length);
|
||||
|
||||
// 2., 3., 6.
|
||||
ecma_object_t *prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
|
||||
|
||||
ecma_object_t *obj_p = ecma_create_object (prototype_p, true, ECMA_OBJECT_TYPE_GENERAL);
|
||||
|
||||
ecma_deref_object (prototype_p);
|
||||
|
||||
// 4.
|
||||
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_ARGUMENTS_UL;
|
||||
|
||||
// 7.
|
||||
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.value = ecma_make_number_value (len_p);
|
||||
|
||||
prop_desc.is_writable_defined = true;
|
||||
prop_desc.is_writable = true;
|
||||
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
prop_desc.is_enumerable = false;
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
prop_desc.is_configurable = true;
|
||||
}
|
||||
ecma_string_t *length_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
|
||||
ecma_completion_value_t completion = ecma_op_object_define_own_property (obj_p,
|
||||
length_magic_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
ecma_deref_ecma_string (length_magic_string_p);
|
||||
|
||||
ecma_dealloc_number (len_p);
|
||||
|
||||
// 11.a, 11.b
|
||||
for (ecma_length_t indx = 0;
|
||||
indx < arguments_list_length;
|
||||
indx++)
|
||||
{
|
||||
prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.value = arguments_list_p[indx];
|
||||
|
||||
prop_desc.is_writable_defined = true;
|
||||
prop_desc.is_writable = true;
|
||||
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
prop_desc.is_enumerable = true;
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
prop_desc.is_configurable = true;
|
||||
}
|
||||
|
||||
ecma_string_t *indx_string_p = ecma_new_ecma_string_from_number (ecma_uint32_to_number (indx));
|
||||
|
||||
completion = ecma_op_object_define_own_property (obj_p,
|
||||
indx_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
|
||||
ecma_deref_ecma_string (indx_string_p);
|
||||
}
|
||||
|
||||
const ecma_length_t formal_params_number = formal_params_iter_p->header_p->unit_number;
|
||||
if (!is_strict
|
||||
&& arguments_list_length > 0
|
||||
&& formal_params_number > 0)
|
||||
{
|
||||
// 8.
|
||||
ecma_object_t *map_p = ecma_op_create_object_object_noarg ();
|
||||
|
||||
// 11.c
|
||||
MEM_DEFINE_LOCAL_ARRAY (formal_params, formal_params_number, ecma_string_t *);
|
||||
|
||||
JERRY_ASSERT (formal_params_iter_p->current_value_p == NULL);
|
||||
uint32_t param_index;
|
||||
for (param_index = 0;
|
||||
ecma_collection_iterator_next (formal_params_iter_p);
|
||||
param_index++)
|
||||
{
|
||||
JERRY_ASSERT (formal_params_iter_p->current_value_p != NULL);
|
||||
JERRY_ASSERT (param_index < formal_params_number);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_string (*formal_params_iter_p->current_value_p));
|
||||
formal_params[param_index] = ecma_get_string_from_value (*formal_params_iter_p->current_value_p);
|
||||
}
|
||||
JERRY_ASSERT (param_index == formal_params_number);
|
||||
|
||||
for (int32_t indx = formal_params_number - 1;
|
||||
indx >= 0;
|
||||
indx--)
|
||||
{
|
||||
// i.
|
||||
ecma_string_t *name_p = formal_params[indx];
|
||||
bool is_first_occurence = true;
|
||||
|
||||
// ii.
|
||||
for (int32_t indx2 = indx + 1;
|
||||
indx2 < formal_params_number;
|
||||
indx2++)
|
||||
{
|
||||
if (ecma_compare_ecma_strings (name_p, formal_params[indx2]))
|
||||
{
|
||||
is_first_occurence = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_first_occurence)
|
||||
{
|
||||
ecma_string_t *indx_string_p = ecma_new_ecma_string_from_number (ecma_uint32_to_number ((uint32_t) indx));
|
||||
|
||||
prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.value = ecma_make_string_value (name_p);
|
||||
}
|
||||
|
||||
completion = ecma_op_object_define_own_property (map_p,
|
||||
indx_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
|
||||
ecma_deref_ecma_string (indx_string_p);
|
||||
}
|
||||
}
|
||||
|
||||
MEM_FINALIZE_LOCAL_ARRAY (formal_params);
|
||||
|
||||
// 12.
|
||||
ecma_set_object_type (obj_p, ECMA_OBJECT_TYPE_ARGUMENTS);
|
||||
|
||||
ecma_property_t *parameters_map_prop_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP);
|
||||
ECMA_SET_POINTER(parameters_map_prop_p->u.internal_property.value, map_p);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, map_p);
|
||||
|
||||
ecma_property_t *scope_prop_p = ecma_create_internal_property (map_p,
|
||||
ECMA_INTERNAL_PROPERTY_SCOPE);
|
||||
ECMA_SET_POINTER(scope_prop_p->u.internal_property.value, lex_env_p);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_object (map_p, lex_env_p);
|
||||
|
||||
ecma_deref_object (map_p);
|
||||
}
|
||||
|
||||
// 13.
|
||||
if (!is_strict)
|
||||
{
|
||||
prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.value = ecma_make_object_value (func_obj_p);
|
||||
|
||||
prop_desc.is_writable_defined = true;
|
||||
prop_desc.is_writable = true;
|
||||
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
prop_desc.is_enumerable = false;
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
prop_desc.is_configurable = true;
|
||||
}
|
||||
|
||||
ecma_string_t *callee_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CALLEE);
|
||||
|
||||
completion = ecma_op_object_define_own_property (obj_p,
|
||||
callee_magic_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
|
||||
ecma_deref_ecma_string (callee_magic_string_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *thrower_p = ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER);
|
||||
|
||||
// 14.
|
||||
prop_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
prop_desc.is_get_defined = true;
|
||||
prop_desc.get_p = thrower_p;
|
||||
|
||||
prop_desc.is_set_defined = true;
|
||||
prop_desc.set_p = thrower_p;
|
||||
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
prop_desc.is_enumerable = false;
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
prop_desc.is_configurable = false;
|
||||
}
|
||||
|
||||
ecma_string_t *callee_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CALLEE);
|
||||
ecma_string_t *caller_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CALLER);
|
||||
|
||||
completion = ecma_op_object_define_own_property (obj_p,
|
||||
callee_magic_string_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
|
||||
ecma_deref_ecma_string (callee_magic_string_p);
|
||||
ecma_deref_ecma_string (caller_magic_string_p);
|
||||
ecma_deref_object (thrower_p);
|
||||
}
|
||||
|
||||
return obj_p;
|
||||
} /* ecma_create_arguments_object */
|
||||
|
||||
/**
|
||||
* Get value of function's argument mapped to index of Arguments object.
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_arguments_get_mapped_arg_value (ecma_object_t *map_p, /**< [[ParametersMap]] object */
|
||||
ecma_property_t *arg_name_prop_p) /**< property of [[ParametersMap]]
|
||||
corresponding to index and value
|
||||
equal to mapped argument's name */
|
||||
{
|
||||
ecma_property_t *scope_prop_p = ecma_get_internal_property (map_p, ECMA_INTERNAL_PROPERTY_SCOPE);
|
||||
ecma_object_t *lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
|
||||
scope_prop_p->u.internal_property.value);
|
||||
JERRY_ASSERT(lex_env_p != NULL
|
||||
&& ecma_is_lexical_environment (lex_env_p));
|
||||
|
||||
ecma_value_t arg_name_prop_value = ecma_get_named_data_property_value (arg_name_prop_p);
|
||||
|
||||
ecma_string_t *arg_name_p = ecma_get_string_from_value (arg_name_prop_value);
|
||||
|
||||
ecma_completion_value_t completion = ecma_op_get_binding_value (lex_env_p,
|
||||
arg_name_p,
|
||||
true);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal (completion));
|
||||
|
||||
return completion;
|
||||
} /* ecma_arguments_get_mapped_arg_value */
|
||||
|
||||
/**
|
||||
* [[Get]] ecma Arguments object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 10.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_arguments_object_get (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
// 1.
|
||||
ecma_property_t *map_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP);
|
||||
ecma_object_t *map_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
|
||||
map_prop_p->u.internal_property.value);
|
||||
|
||||
// 2.
|
||||
ecma_property_t *mapped_prop_p = ecma_op_object_get_own_property (map_p, property_name_p);
|
||||
|
||||
// 3.
|
||||
if (mapped_prop_p == NULL)
|
||||
{
|
||||
/* We don't check for 'caller' (item 3.b) here, because the 'caller' property is defined
|
||||
as non-configurable and it's get/set are set to [[ThrowTypeError]] object */
|
||||
|
||||
return ecma_op_general_object_get (obj_p, property_name_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4.
|
||||
return ecma_arguments_get_mapped_arg_value (map_p, mapped_prop_p);
|
||||
}
|
||||
} /* ecma_op_arguments_object_get */
|
||||
|
||||
/**
|
||||
* [[GetOwnProperty]] ecma Arguments object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 10.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_op_arguments_object_get_own_property (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
// 1.
|
||||
ecma_property_t *desc_p = ecma_op_general_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
// 2.
|
||||
if (desc_p == NULL)
|
||||
{
|
||||
return desc_p;
|
||||
}
|
||||
|
||||
// 3.
|
||||
ecma_property_t *map_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP);
|
||||
ecma_object_t *map_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
|
||||
map_prop_p->u.internal_property.value);
|
||||
|
||||
// 4.
|
||||
ecma_property_t *mapped_prop_p = ecma_op_object_get_own_property (map_p, property_name_p);
|
||||
|
||||
// 5.
|
||||
if (mapped_prop_p != NULL)
|
||||
{
|
||||
// a.
|
||||
ecma_completion_value_t completion = ecma_arguments_get_mapped_arg_value (map_p, mapped_prop_p);
|
||||
|
||||
ecma_named_data_property_assign_value (obj_p, desc_p, ecma_get_completion_value_value (completion));
|
||||
|
||||
ecma_free_completion_value (completion);
|
||||
}
|
||||
|
||||
// 6.
|
||||
return desc_p;
|
||||
} /* ecma_op_arguments_object_get_own_property */
|
||||
|
||||
/**
|
||||
* [[DefineOwnProperty]] ecma Arguments object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 10.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_arguments_object_define_own_property (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
const ecma_property_descriptor_t* property_desc_p, /**< property
|
||||
* descriptor */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
// 1.
|
||||
ecma_property_t *map_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP);
|
||||
ecma_object_t *map_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
|
||||
map_prop_p->u.internal_property.value);
|
||||
|
||||
// 2.
|
||||
ecma_property_t *mapped_prop_p = ecma_op_object_get_own_property (map_p, property_name_p);
|
||||
|
||||
// 3.
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (defined,
|
||||
ecma_op_general_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
is_throw),
|
||||
ret_value);
|
||||
|
||||
// 5.
|
||||
if (mapped_prop_p != NULL)
|
||||
{
|
||||
// a.
|
||||
if (property_desc_p->is_get_defined
|
||||
|| property_desc_p->is_set_defined)
|
||||
{
|
||||
ecma_completion_value_t completion = ecma_op_object_delete (map_p, property_name_p, false);
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
|
||||
// 6.
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// b.
|
||||
|
||||
ecma_completion_value_t completion = ecma_make_empty_completion_value ();
|
||||
|
||||
// i.
|
||||
if (property_desc_p->is_value_defined)
|
||||
{
|
||||
completion = ecma_op_object_put (map_p,
|
||||
property_name_p,
|
||||
property_desc_p->value,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
if (unlikely (ecma_is_completion_value_throw (completion)))
|
||||
{
|
||||
ret_value = completion;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ii.
|
||||
if (property_desc_p->is_writable_defined
|
||||
&& !property_desc_p->is_writable)
|
||||
{
|
||||
completion = ecma_op_object_delete (map_p,
|
||||
property_name_p,
|
||||
false);
|
||||
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
|
||||
}
|
||||
|
||||
// 6.
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (defined);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_arguments_object_define_own_property */
|
||||
|
||||
/**
|
||||
* [[Delete]] ecma Arguments object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 10.6
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_arguments_object_delete (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
// 1.
|
||||
ecma_property_t *map_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP);
|
||||
ecma_object_t *map_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
|
||||
map_prop_p->u.internal_property.value);
|
||||
|
||||
// 2.
|
||||
ecma_property_t *mapped_prop_p = ecma_op_object_get_own_property (map_p, property_name_p);
|
||||
|
||||
// 3.
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (delete_in_args_ret,
|
||||
ecma_op_general_object_delete (obj_p,
|
||||
property_name_p,
|
||||
is_throw),
|
||||
ret_value);
|
||||
|
||||
if (ecma_is_value_true (delete_in_args_ret))
|
||||
{
|
||||
if (mapped_prop_p != NULL)
|
||||
{
|
||||
ecma_completion_value_t delete_in_map_completion = ecma_op_object_delete (map_p,
|
||||
property_name_p,
|
||||
false);
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal_true (delete_in_map_completion));
|
||||
}
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_boolean (delete_in_args_ret));
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (delete_in_args_ret);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_op_arguments_object_delete */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,43 @@
|
||||
/* Copyright 2014-2015 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 ECMA_OBJECTS_ARGUMENTS_H
|
||||
#define ECMA_OBJECTS_ARGUMENTS_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
extern ecma_object_t*
|
||||
ecma_create_arguments_object (ecma_object_t *func_obj_p,
|
||||
ecma_object_t *lex_env_p,
|
||||
ecma_collection_iterator_t *formal_params_iter_p,
|
||||
const ecma_value_t *arguments_list_p,
|
||||
ecma_length_t arguments_list_length,
|
||||
bool is_strict);
|
||||
|
||||
extern ecma_completion_value_t ecma_op_arguments_object_get (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p);
|
||||
extern ecma_property_t *ecma_op_arguments_object_get_own_property (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p);
|
||||
extern ecma_completion_value_t ecma_op_arguments_object_delete (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p,
|
||||
bool is_throw);
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_arguments_object_define_own_property (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p,
|
||||
const ecma_property_descriptor_t* property_desc_p,
|
||||
bool is_throw);
|
||||
|
||||
#endif /* !ECMA_OBJECTS_ARGUMENTS_H */
|
||||
@@ -0,0 +1,877 @@
|
||||
/* Copyright 2014-2015 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-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-function-object.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"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmageneralobjectsinternalops General ECMA objects' operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Reject sequence
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_reject (bool is_throw) /**< Throw flag */
|
||||
{
|
||||
if (is_throw)
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
} /* ecma_reject */
|
||||
|
||||
/**
|
||||
* 'Object' object creation operation with no arguments.
|
||||
*
|
||||
* See also: ECMA-262 v5, 15.2.2.1
|
||||
*
|
||||
* @return pointer to newly created 'Object' object
|
||||
*/
|
||||
ecma_object_t*
|
||||
ecma_op_create_object_object_noarg (void)
|
||||
{
|
||||
ecma_object_t *object_prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
|
||||
|
||||
// 3., 4., 6., 7.
|
||||
ecma_object_t *obj_p = ecma_create_object (object_prototype_p, true, ECMA_OBJECT_TYPE_GENERAL);
|
||||
|
||||
ecma_deref_object (object_prototype_p);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_OBJECT_UL;
|
||||
|
||||
return obj_p;
|
||||
} /* ecma_op_create_object_object_noarg */
|
||||
|
||||
/**
|
||||
* 'Object' object creation operation with one argument.
|
||||
*
|
||||
* See also: ECMA-262 v5, 15.2.2.1
|
||||
*
|
||||
* @return pointer to newly created 'Object' object
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_create_object_object_arg (const ecma_value_t& value) /**< argument of constructor */
|
||||
{
|
||||
ecma_check_value_type_is_spec_defined (value);
|
||||
|
||||
if (ecma_is_value_object (value)
|
||||
|| ecma_is_value_number (value)
|
||||
|| ecma_is_value_string (value)
|
||||
|| ecma_is_value_boolean (value))
|
||||
{
|
||||
// 1.b, 1.c, 1.d
|
||||
return ecma_op_to_object (value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2.
|
||||
JERRY_ASSERT (ecma_is_value_undefined (value)
|
||||
|| ecma_is_value_null (value));
|
||||
|
||||
ecma_object_t *obj_p = ecma_op_create_object_object_noarg ();
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
|
||||
}
|
||||
} /* ecma_op_create_object_object_arg */
|
||||
|
||||
/**
|
||||
* [[Get]] ecma general object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 8.12.3
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_general_object_get (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
// 1.
|
||||
const ecma_property_t* prop_p = ecma_op_object_get_property (obj_p, property_name_p);
|
||||
|
||||
// 2.
|
||||
if (prop_p == NULL)
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
|
||||
// 3.
|
||||
if (prop_p->type == ECMA_PROPERTY_NAMEDDATA)
|
||||
{
|
||||
return ecma_make_normal_completion_value (ecma_copy_value (ecma_get_named_data_property_value (prop_p),
|
||||
true));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4.
|
||||
ecma_object_t *getter_p = ECMA_GET_POINTER (ecma_object_t,
|
||||
prop_p->u.named_accessor_property.get_p);
|
||||
|
||||
// 5.
|
||||
if (getter_p == NULL)
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_function_call (getter_p,
|
||||
ecma_make_object_value (obj_p),
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
} /* ecma_op_general_object_get */
|
||||
|
||||
/**
|
||||
* [[GetOwnProperty]] ecma general object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 8.12.2
|
||||
*
|
||||
* @return pointer to a property - if it exists,
|
||||
* NULL (i.e. ecma-undefined) - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_op_general_object_get_own_property (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
return ecma_find_named_property (obj_p, property_name_p);
|
||||
} /* ecma_op_general_object_get_own_property */
|
||||
|
||||
/**
|
||||
* [[GetProperty]] ecma general object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 8.12.2
|
||||
*
|
||||
* @return pointer to a property - if it exists,
|
||||
* NULL (i.e. ecma-undefined) - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_op_general_object_get_property (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
// 1.
|
||||
ecma_property_t *prop_p = ecma_op_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
// 2.
|
||||
if (prop_p != NULL)
|
||||
{
|
||||
return prop_p;
|
||||
}
|
||||
|
||||
// 3.
|
||||
ecma_object_t *prototype_p = ecma_get_object_prototype (obj_p);
|
||||
|
||||
// 4., 5.
|
||||
if (prototype_p != NULL)
|
||||
{
|
||||
return ecma_op_object_get_property (prototype_p, property_name_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
} /* ecma_op_general_object_get_property */
|
||||
|
||||
/**
|
||||
* [[Put]] ecma general object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 8.12.5
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_general_object_put (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
const ecma_value_t& value, /**< ecma-value */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
// 1.
|
||||
if (!ecma_op_object_can_put (obj_p, property_name_p))
|
||||
{
|
||||
if (is_throw)
|
||||
{
|
||||
// a.
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
// b.
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
// 2.
|
||||
ecma_property_t *own_desc_p = ecma_op_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
// 3.
|
||||
if (own_desc_p != NULL
|
||||
&& own_desc_p->type == ECMA_PROPERTY_NAMEDDATA)
|
||||
{
|
||||
// a.
|
||||
ecma_property_descriptor_t value_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
value_desc.is_value_defined = true;
|
||||
value_desc.value = value;
|
||||
}
|
||||
|
||||
// b., c.
|
||||
return ecma_op_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
&value_desc,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
// 4.
|
||||
ecma_property_t *desc_p = ecma_op_object_get_property (obj_p, property_name_p);
|
||||
|
||||
// 5.
|
||||
if (desc_p != NULL
|
||||
&& desc_p->type == ECMA_PROPERTY_NAMEDACCESSOR)
|
||||
{
|
||||
// a.
|
||||
ecma_object_t *setter_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
|
||||
desc_p->u.named_accessor_property.set_p);
|
||||
JERRY_ASSERT(setter_p != NULL);
|
||||
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (call_ret,
|
||||
ecma_op_function_call (setter_p,
|
||||
ecma_make_object_value (obj_p),
|
||||
&value,
|
||||
1),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
|
||||
ECMA_FINALIZE (call_ret);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 6.
|
||||
|
||||
// a.
|
||||
ecma_property_descriptor_t new_desc = ecma_make_empty_property_descriptor ();
|
||||
{
|
||||
new_desc.is_value_defined = true;
|
||||
new_desc.value = value;
|
||||
|
||||
new_desc.is_writable_defined = true;
|
||||
new_desc.is_writable = true;
|
||||
|
||||
new_desc.is_enumerable_defined = true;
|
||||
new_desc.is_enumerable = true;
|
||||
|
||||
new_desc.is_configurable_defined = true;
|
||||
new_desc.is_configurable = true;
|
||||
}
|
||||
|
||||
// b.
|
||||
return ecma_op_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
&new_desc,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
} /* ecma_op_general_object_put */
|
||||
|
||||
/**
|
||||
* [[CanPut]] ecma general object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 8.12.4
|
||||
*
|
||||
* @return true - if [[Put]] with the given property name can be performed;
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
ecma_op_general_object_can_put (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
// 1.
|
||||
ecma_property_t *prop_p = ecma_op_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
// 2.
|
||||
if (prop_p != NULL)
|
||||
{
|
||||
// a.
|
||||
if (prop_p->type == ECMA_PROPERTY_NAMEDACCESSOR)
|
||||
{
|
||||
ecma_object_t *setter_p = ECMA_GET_POINTER (ecma_object_t,
|
||||
prop_p->u.named_accessor_property.set_p);
|
||||
|
||||
// i.
|
||||
if (setter_p == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// ii.
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// b.
|
||||
|
||||
JERRY_ASSERT(prop_p->type == ECMA_PROPERTY_NAMEDDATA);
|
||||
|
||||
return ecma_is_property_writable (prop_p);
|
||||
}
|
||||
}
|
||||
|
||||
// 3.
|
||||
ecma_object_t *proto_p = ecma_get_object_prototype (obj_p);
|
||||
|
||||
// 4.
|
||||
if (proto_p == NULL)
|
||||
{
|
||||
return ecma_get_object_extensible (obj_p);
|
||||
}
|
||||
|
||||
// 5.
|
||||
ecma_property_t *inherited_p = ecma_op_object_get_property (proto_p, property_name_p);
|
||||
|
||||
// 6.
|
||||
if (inherited_p == NULL)
|
||||
{
|
||||
return ecma_get_object_extensible (obj_p);
|
||||
}
|
||||
|
||||
// 7.
|
||||
if (inherited_p->type == ECMA_PROPERTY_NAMEDACCESSOR)
|
||||
{
|
||||
ecma_object_t *setter_p = ECMA_GET_POINTER (ecma_object_t,
|
||||
inherited_p->u.named_accessor_property.set_p);
|
||||
|
||||
// a.
|
||||
if (setter_p == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// b.
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 8.
|
||||
JERRY_ASSERT(inherited_p->type == ECMA_PROPERTY_NAMEDDATA);
|
||||
|
||||
// a.
|
||||
if (!ecma_get_object_extensible (obj_p))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// b.
|
||||
return ecma_is_property_writable (inherited_p);
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
} /* ecma_op_general_object_can_put */
|
||||
|
||||
/**
|
||||
* [[Delete]] ecma general object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 8.12.7
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_general_object_delete (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
// 1.
|
||||
ecma_property_t *desc_p = ecma_op_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
// 2.
|
||||
if (desc_p == NULL)
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
// 3.
|
||||
if (ecma_is_property_configurable (desc_p))
|
||||
{
|
||||
// a.
|
||||
ecma_delete_property (obj_p, desc_p);
|
||||
|
||||
// b.
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
else if (is_throw)
|
||||
{
|
||||
// 4.
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 5.
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
} /* ecma_op_general_object_delete */
|
||||
|
||||
/**
|
||||
* [[DefaultValue]] ecma general object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 8.12.8
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_general_object_default_value (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_preferred_type_hint_t hint) /**< hint on preferred result type */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
|
||||
if (hint == ECMA_PREFERRED_TYPE_NO)
|
||||
{
|
||||
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
ecma_magic_string_id_t obj_class = (ecma_magic_string_id_t) class_prop_p->u.internal_property.value;
|
||||
|
||||
if (obj_class == ECMA_MAGIC_STRING_DATE_UL)
|
||||
{
|
||||
hint = ECMA_PREFERRED_TYPE_STRING;
|
||||
}
|
||||
else
|
||||
{
|
||||
hint = ECMA_PREFERRED_TYPE_NUMBER;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 1; i <= 2; i++)
|
||||
{
|
||||
ecma_magic_string_id_t function_name_magic_string_id;
|
||||
|
||||
if ((i == 1 && hint == ECMA_PREFERRED_TYPE_STRING)
|
||||
|| (i == 2 && hint == ECMA_PREFERRED_TYPE_NUMBER))
|
||||
{
|
||||
function_name_magic_string_id = ECMA_MAGIC_STRING_TO_STRING_UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
function_name_magic_string_id = ECMA_MAGIC_STRING_VALUE_OF_UL;
|
||||
}
|
||||
|
||||
ecma_string_t *function_name_p = ecma_get_magic_string (function_name_magic_string_id);
|
||||
|
||||
ecma_completion_value_t function_value_get_completion = ecma_op_object_get (obj_p, function_name_p);
|
||||
|
||||
ecma_deref_ecma_string (function_name_p);
|
||||
|
||||
if (!ecma_is_completion_value_normal (function_value_get_completion))
|
||||
{
|
||||
return function_value_get_completion;
|
||||
}
|
||||
|
||||
ecma_completion_value_t call_completion = ecma_make_empty_completion_value ();
|
||||
|
||||
if (ecma_op_is_callable (ecma_get_completion_value_value (function_value_get_completion)))
|
||||
{
|
||||
ecma_object_t *func_obj_p = ecma_get_object_from_completion_value (function_value_get_completion);
|
||||
|
||||
call_completion = ecma_op_function_call (func_obj_p,
|
||||
ecma_make_object_value (obj_p),
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
ecma_free_completion_value (function_value_get_completion);
|
||||
|
||||
if (!ecma_is_completion_value_normal (call_completion))
|
||||
{
|
||||
return call_completion;
|
||||
}
|
||||
|
||||
if (!ecma_is_completion_value_empty (call_completion)
|
||||
&& !ecma_is_value_object (ecma_get_completion_value_value (call_completion)))
|
||||
{
|
||||
return call_completion;
|
||||
}
|
||||
|
||||
ecma_free_completion_value (call_completion);
|
||||
}
|
||||
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
} /* ecma_op_general_object_default_value */
|
||||
|
||||
/**
|
||||
* [[DefineOwnProperty]] ecma general object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 8.12.9
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_general_object_define_own_property (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
const ecma_property_descriptor_t* property_desc_p, /**< property
|
||||
* descriptor */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
const bool is_property_desc_generic_descriptor = (!property_desc_p->is_value_defined
|
||||
&& !property_desc_p->is_writable_defined
|
||||
&& !property_desc_p->is_get_defined
|
||||
&& !property_desc_p->is_set_defined);
|
||||
const bool is_property_desc_data_descriptor = (property_desc_p->is_value_defined
|
||||
|| property_desc_p->is_writable_defined);
|
||||
const bool is_property_desc_accessor_descriptor = (property_desc_p->is_get_defined
|
||||
|| property_desc_p->is_set_defined);
|
||||
|
||||
// 1.
|
||||
ecma_property_t *current_p = ecma_op_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
// 2.
|
||||
bool extensible = ecma_get_object_extensible (obj_p);
|
||||
|
||||
if (current_p == NULL)
|
||||
{
|
||||
// 3.
|
||||
if (!extensible)
|
||||
{
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
// 4.
|
||||
|
||||
// a.
|
||||
if (is_property_desc_generic_descriptor
|
||||
|| is_property_desc_data_descriptor)
|
||||
{
|
||||
ecma_property_t *new_prop_p = ecma_create_named_data_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p->is_writable,
|
||||
property_desc_p->is_enumerable,
|
||||
property_desc_p->is_configurable);
|
||||
|
||||
ecma_named_data_property_assign_value (obj_p, new_prop_p, property_desc_p->value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// b.
|
||||
JERRY_ASSERT(is_property_desc_accessor_descriptor);
|
||||
|
||||
ecma_create_named_accessor_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p->get_p,
|
||||
property_desc_p->set_p,
|
||||
property_desc_p->is_enumerable,
|
||||
property_desc_p->is_configurable);
|
||||
|
||||
}
|
||||
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
// 5.
|
||||
if (is_property_desc_generic_descriptor
|
||||
&& !property_desc_p->is_enumerable_defined
|
||||
&& !property_desc_p->is_configurable_defined)
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
// 6.
|
||||
const bool is_current_data_descriptor = (current_p->type == ECMA_PROPERTY_NAMEDDATA);
|
||||
const bool is_current_accessor_descriptor = (current_p->type == ECMA_PROPERTY_NAMEDACCESSOR);
|
||||
|
||||
JERRY_ASSERT(is_current_data_descriptor || is_current_accessor_descriptor);
|
||||
|
||||
bool is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = true;
|
||||
if (property_desc_p->is_value_defined)
|
||||
{
|
||||
if (!is_current_data_descriptor
|
||||
|| !ecma_op_same_value (property_desc_p->value,
|
||||
ecma_get_named_data_property_value (current_p)))
|
||||
{
|
||||
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (property_desc_p->is_writable_defined)
|
||||
{
|
||||
if (!is_current_data_descriptor
|
||||
|| property_desc_p->is_writable != ecma_is_property_writable (current_p))
|
||||
{
|
||||
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (property_desc_p->is_get_defined)
|
||||
{
|
||||
if (!is_current_accessor_descriptor
|
||||
|| property_desc_p->get_p != ECMA_GET_POINTER (ecma_object_t,
|
||||
current_p->u.named_accessor_property.get_p))
|
||||
{
|
||||
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (property_desc_p->is_set_defined)
|
||||
{
|
||||
if (!is_current_accessor_descriptor
|
||||
|| property_desc_p->set_p != ECMA_GET_POINTER (ecma_object_t,
|
||||
current_p->u.named_accessor_property.set_p))
|
||||
{
|
||||
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (property_desc_p->is_enumerable_defined)
|
||||
{
|
||||
if (property_desc_p->is_enumerable != ecma_is_property_enumerable (current_p))
|
||||
{
|
||||
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (property_desc_p->is_configurable_defined)
|
||||
{
|
||||
if (property_desc_p->is_configurable != ecma_is_property_configurable (current_p))
|
||||
{
|
||||
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_every_field_in_desc_also_occurs_in_current_desc_with_same_value)
|
||||
{
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
// 7.
|
||||
if (!ecma_is_property_configurable (current_p))
|
||||
{
|
||||
if (property_desc_p->is_configurable
|
||||
|| (property_desc_p->is_enumerable_defined
|
||||
&& property_desc_p->is_enumerable != ecma_is_property_enumerable (current_p)))
|
||||
{
|
||||
// a., b.
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
}
|
||||
|
||||
// 8.
|
||||
if (is_property_desc_generic_descriptor)
|
||||
{
|
||||
// no action required
|
||||
}
|
||||
else if (is_property_desc_data_descriptor != is_current_data_descriptor)
|
||||
{
|
||||
// 9.
|
||||
if (!ecma_is_property_configurable (current_p))
|
||||
{
|
||||
// a.
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
ecma_delete_property (obj_p, current_p);
|
||||
|
||||
if (is_current_data_descriptor)
|
||||
{
|
||||
// b.
|
||||
|
||||
current_p = ecma_create_named_accessor_property (obj_p,
|
||||
property_name_p,
|
||||
NULL,
|
||||
NULL,
|
||||
ecma_is_property_enumerable (current_p),
|
||||
ecma_is_property_configurable (current_p));
|
||||
}
|
||||
else
|
||||
{
|
||||
// c.
|
||||
|
||||
current_p = ecma_create_named_data_property (obj_p,
|
||||
property_name_p,
|
||||
false,
|
||||
ecma_is_property_enumerable (current_p),
|
||||
ecma_is_property_configurable (current_p));
|
||||
}
|
||||
}
|
||||
else if (is_property_desc_data_descriptor && is_current_data_descriptor)
|
||||
{
|
||||
// 10.
|
||||
if (!ecma_is_property_configurable (current_p))
|
||||
{
|
||||
// a.
|
||||
if (!ecma_is_property_writable (current_p))
|
||||
{
|
||||
// i.
|
||||
if (property_desc_p->is_writable)
|
||||
{
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
// ii.
|
||||
if (property_desc_p->is_value_defined
|
||||
&& !ecma_op_same_value (property_desc_p->value,
|
||||
ecma_get_named_data_property_value (current_p)))
|
||||
{
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT(is_property_desc_accessor_descriptor && is_current_accessor_descriptor);
|
||||
|
||||
// 11.
|
||||
|
||||
if (!ecma_is_property_configurable (current_p))
|
||||
{
|
||||
// a.
|
||||
|
||||
if ((property_desc_p->is_get_defined
|
||||
&& property_desc_p->get_p != ECMA_GET_POINTER (ecma_object_t,
|
||||
current_p->u.named_accessor_property.get_p))
|
||||
|| (property_desc_p->is_set_defined
|
||||
&& property_desc_p->set_p != ECMA_GET_POINTER (ecma_object_t,
|
||||
current_p->u.named_accessor_property.set_p)))
|
||||
{
|
||||
// i., ii.
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 12.
|
||||
if (property_desc_p->is_value_defined)
|
||||
{
|
||||
JERRY_ASSERT(is_current_data_descriptor);
|
||||
|
||||
ecma_named_data_property_assign_value (obj_p, current_p, property_desc_p->value);
|
||||
}
|
||||
|
||||
if (property_desc_p->is_writable_defined)
|
||||
{
|
||||
JERRY_ASSERT(is_current_data_descriptor);
|
||||
|
||||
ecma_set_property_writable_attr (current_p, property_desc_p->is_writable);
|
||||
}
|
||||
|
||||
if (property_desc_p->is_get_defined)
|
||||
{
|
||||
JERRY_ASSERT(is_current_accessor_descriptor);
|
||||
|
||||
ecma_object_t *get_p = property_desc_p->get_p;
|
||||
|
||||
ECMA_SET_POINTER(current_p->u.named_accessor_property.get_p, get_p);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, get_p);
|
||||
}
|
||||
|
||||
if (property_desc_p->is_set_defined)
|
||||
{
|
||||
JERRY_ASSERT(is_current_accessor_descriptor);
|
||||
|
||||
ecma_object_t *set_p = property_desc_p->set_p;
|
||||
|
||||
ECMA_SET_POINTER(current_p->u.named_accessor_property.set_p, set_p);
|
||||
ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, set_p);
|
||||
}
|
||||
|
||||
if (property_desc_p->is_enumerable_defined)
|
||||
{
|
||||
ecma_set_property_enumerable_attr (current_p, property_desc_p->is_enumerable);
|
||||
}
|
||||
|
||||
if (property_desc_p->is_configurable_defined)
|
||||
{
|
||||
ecma_set_property_configurable_attr (current_p, property_desc_p->is_configurable);
|
||||
}
|
||||
|
||||
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
} /* ecma_op_general_object_define_own_property */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,60 @@
|
||||
/* Copyright 2014-2015 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 ECMA_OBJECTS_GENERAL_H
|
||||
#define ECMA_OBJECTS_GENERAL_H
|
||||
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaobjectsinternalops ECMA objects' operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_object_t* ecma_op_create_object_object_noarg (void);
|
||||
extern ecma_completion_value_t ecma_op_create_object_object_arg (const ecma_value_t& value);
|
||||
|
||||
extern ecma_completion_value_t ecma_op_general_object_get (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p);
|
||||
extern ecma_property_t *ecma_op_general_object_get_own_property (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p);
|
||||
extern ecma_property_t *ecma_op_general_object_get_property (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p);
|
||||
extern ecma_completion_value_t ecma_op_general_object_put (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p,
|
||||
const ecma_value_t& value,
|
||||
bool is_throw);
|
||||
extern bool ecma_op_general_object_can_put (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p);
|
||||
extern ecma_completion_value_t ecma_op_general_object_delete (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p,
|
||||
bool is_throw);
|
||||
extern ecma_completion_value_t ecma_op_general_object_default_value (ecma_object_t *obj_p,
|
||||
ecma_preferred_type_hint_t hint);
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_general_object_define_own_property (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p,
|
||||
const ecma_property_descriptor_t* property_desc_p,
|
||||
bool is_throw);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_OBJECTS_GENERAL_H */
|
||||
@@ -0,0 +1,487 @@
|
||||
/* Copyright 2014-2015 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-array-object.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-lcache.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-objects-arguments.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-objects.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaobjectsinternalops ECMA objects' operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* [[Get]] ecma object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_object_get (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
JERRY_ASSERT (type < ECMA_OBJECT_TYPE__COUNT);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_GENERAL:
|
||||
case ECMA_OBJECT_TYPE_ARRAY:
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_STRING:
|
||||
{
|
||||
return ecma_op_general_object_get (obj_p, property_name_p);
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
{
|
||||
return ecma_op_arguments_object_get (obj_p, property_name_p);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (false);
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
}
|
||||
}
|
||||
} /* ecma_op_object_get */
|
||||
|
||||
/**
|
||||
* Long path for ecma_op_object_get_own_property
|
||||
*
|
||||
* @return pointer to a property - if it exists,
|
||||
* NULL (i.e. ecma-undefined) - otherwise.
|
||||
*/
|
||||
static __attr_noinline___ ecma_property_t*
|
||||
ecma_op_object_get_own_property_longpath (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
JERRY_ASSERT (type < ECMA_OBJECT_TYPE__COUNT);
|
||||
|
||||
const bool is_builtin = ecma_get_object_is_builtin (obj_p);
|
||||
|
||||
ecma_property_t *prop_p;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_GENERAL:
|
||||
case ECMA_OBJECT_TYPE_ARRAY:
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
|
||||
{
|
||||
prop_p = ecma_op_general_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_STRING:
|
||||
{
|
||||
prop_p = ecma_op_string_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
{
|
||||
prop_p = ecma_op_arguments_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (false);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (unlikely (prop_p == NULL))
|
||||
{
|
||||
if (is_builtin
|
||||
&& type != ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION)
|
||||
{
|
||||
prop_p = ecma_builtin_try_to_instantiate_property (obj_p, property_name_p);
|
||||
}
|
||||
}
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_op_object_get_own_property_longpath */
|
||||
|
||||
/**
|
||||
* [[GetOwnProperty]] ecma object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
*
|
||||
* @return pointer to a property - if it exists,
|
||||
* NULL (i.e. ecma-undefined) - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_op_object_get_own_property (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
ecma_property_t *prop_p = NULL;
|
||||
|
||||
if (likely (ecma_lcache_lookup (obj_p, property_name_p, &prop_p)))
|
||||
{
|
||||
return prop_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_object_get_own_property_longpath (obj_p, property_name_p);
|
||||
}
|
||||
} /* ecma_op_object_get_own_property */
|
||||
|
||||
/**
|
||||
* [[GetProperty]] ecma object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
*
|
||||
* @return pointer to a property - if it exists,
|
||||
* NULL (i.e. ecma-undefined) - otherwise.
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_op_object_get_property (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
JERRY_ASSERT (type < ECMA_OBJECT_TYPE__COUNT);
|
||||
|
||||
/*
|
||||
* typedef ecma_property_t* (*get_property_ptr_t) (ecma_object_t *, ecma_string_t *);
|
||||
* static const get_property_ptr_t get_property [ECMA_OBJECT_TYPE__COUNT] =
|
||||
* {
|
||||
* [ECMA_OBJECT_TYPE_GENERAL] = &ecma_op_general_object_get_property,
|
||||
* [ECMA_OBJECT_TYPE_ARRAY] = &ecma_op_general_object_get_property,
|
||||
* [ECMA_OBJECT_TYPE_FUNCTION] = &ecma_op_general_object_get_property,
|
||||
* [ECMA_OBJECT_TYPE_BOUND_FUNCTION] = &ecma_op_general_object_get_property,
|
||||
* [ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION] = &ecma_op_general_object_get_property,
|
||||
* [ECMA_OBJECT_TYPE_ARGUMENTS] = &ecma_op_general_object_get_property,
|
||||
* [ECMA_OBJECT_TYPE_STRING] = &ecma_op_general_object_get_property
|
||||
* };
|
||||
*
|
||||
* return get_property[type] (obj_p, property_name_p);
|
||||
*/
|
||||
|
||||
return ecma_op_general_object_get_property (obj_p, property_name_p);
|
||||
} /* ecma_op_object_get_property */
|
||||
|
||||
/**
|
||||
* [[Put]] ecma object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_object_put (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
const ecma_value_t& value, /**< ecma-value */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
JERRY_ASSERT (type < ECMA_OBJECT_TYPE__COUNT);
|
||||
|
||||
/*
|
||||
* typedef ecma_property_t* (*put_ptr_t) (ecma_object_t *, ecma_string_t *);
|
||||
* static const put_ptr_t put [ECMA_OBJECT_TYPE__COUNT] =
|
||||
* {
|
||||
* [ECMA_OBJECT_TYPE_GENERAL] = &ecma_op_general_object_put,
|
||||
* [ECMA_OBJECT_TYPE_ARRAY] = &ecma_op_general_object_put,
|
||||
* [ECMA_OBJECT_TYPE_FUNCTION] = &ecma_op_general_object_put,
|
||||
* [ECMA_OBJECT_TYPE_BOUND_FUNCTION] = &ecma_op_general_object_put,
|
||||
* [ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION] = &ecma_op_general_object_put,
|
||||
* [ECMA_OBJECT_TYPE_ARGUMENTS] = &ecma_op_general_object_put,
|
||||
* [ECMA_OBJECT_TYPE_STRING] = &ecma_op_general_object_put
|
||||
* };
|
||||
*
|
||||
* return put[type] (obj_p, property_name_p);
|
||||
*/
|
||||
|
||||
return ecma_op_general_object_put (obj_p, property_name_p, value, is_throw);
|
||||
} /* ecma_op_object_put */
|
||||
|
||||
/**
|
||||
* [[CanPut]] ecma object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
*
|
||||
* @return true - if [[Put]] with the given property name can be performed;
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
ecma_op_object_can_put (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
JERRY_ASSERT (type < ECMA_OBJECT_TYPE__COUNT);
|
||||
|
||||
/*
|
||||
* typedef ecma_property_t* (*can_put_ptr_t) (ecma_object_t *, ecma_string_t *);
|
||||
* static const can_put_ptr_t can_put [ECMA_OBJECT_TYPE__COUNT] =
|
||||
* {
|
||||
* [ECMA_OBJECT_TYPE_GENERAL] = &ecma_op_general_object_can_put,
|
||||
* [ECMA_OBJECT_TYPE_ARRAY] = &ecma_op_general_object_can_put,
|
||||
* [ECMA_OBJECT_TYPE_FUNCTION] = &ecma_op_general_object_can_put,
|
||||
* [ECMA_OBJECT_TYPE_BOUND_FUNCTION] = &ecma_op_general_object_can_put,
|
||||
* [ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION] = &ecma_op_general_object_can_put,
|
||||
* [ECMA_OBJECT_TYPE_ARGUMENTS] = &ecma_op_general_object_can_put,
|
||||
* [ECMA_OBJECT_TYPE_STRING] = &ecma_op_general_object_can_put
|
||||
* };
|
||||
*
|
||||
* return can_put[type] (obj_p, property_name_p);
|
||||
*/
|
||||
|
||||
return ecma_op_general_object_can_put (obj_p, property_name_p);
|
||||
} /* ecma_op_object_can_put */
|
||||
|
||||
/**
|
||||
* [[Delete]] ecma object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_object_delete (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
JERRY_ASSERT (type < ECMA_OBJECT_TYPE__COUNT);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_GENERAL:
|
||||
case ECMA_OBJECT_TYPE_ARRAY:
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_STRING:
|
||||
{
|
||||
return ecma_op_general_object_delete (obj_p,
|
||||
property_name_p,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
{
|
||||
return ecma_op_arguments_object_delete (obj_p,
|
||||
property_name_p,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (false);
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
}
|
||||
}
|
||||
} /* ecma_op_object_delete */
|
||||
|
||||
/**
|
||||
* [[DefaultValue]] ecma object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_object_default_value (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_preferred_type_hint_t hint) /**< hint on preferred result type */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
JERRY_ASSERT (type < ECMA_OBJECT_TYPE__COUNT);
|
||||
|
||||
/*
|
||||
* typedef ecma_property_t* (*default_value_ptr_t) (ecma_object_t *, ecma_string_t *);
|
||||
* static const default_value_ptr_t default_value [ECMA_OBJECT_TYPE__COUNT] =
|
||||
* {
|
||||
* [ECMA_OBJECT_TYPE_GENERAL] = &ecma_op_general_object_default_value,
|
||||
* [ECMA_OBJECT_TYPE_ARRAY] = &ecma_op_general_object_default_value,
|
||||
* [ECMA_OBJECT_TYPE_FUNCTION] = &ecma_op_general_object_default_value,
|
||||
* [ECMA_OBJECT_TYPE_BOUND_FUNCTION] = &ecma_op_general_object_default_value,
|
||||
* [ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION] = &ecma_op_general_object_default_value,
|
||||
* [ECMA_OBJECT_TYPE_ARGUMENTS] = &ecma_op_general_object_default_value,
|
||||
* [ECMA_OBJECT_TYPE_STRING] = &ecma_op_general_object_default_value
|
||||
* };
|
||||
*
|
||||
* return default_value[type] (obj_p, property_name_p);
|
||||
*/
|
||||
|
||||
return ecma_op_general_object_default_value (obj_p, hint);
|
||||
} /* ecma_op_object_default_value */
|
||||
|
||||
/**
|
||||
* [[DefineOwnProperty]] ecma object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_object_define_own_property (ecma_object_t *obj_p, /**< the object */
|
||||
ecma_string_t *property_name_p, /**< property name */
|
||||
const ecma_property_descriptor_t* property_desc_p, /**< property
|
||||
* descriptor */
|
||||
bool is_throw) /**< flag that controls failure handling */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT(property_name_p != NULL);
|
||||
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
JERRY_ASSERT (type < ECMA_OBJECT_TYPE__COUNT);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_GENERAL:
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_STRING:
|
||||
{
|
||||
return ecma_op_general_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_ARRAY:
|
||||
{
|
||||
return ecma_op_array_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
{
|
||||
return ecma_op_arguments_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
property_desc_p,
|
||||
is_throw);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (false);
|
||||
|
||||
return ecma_make_empty_completion_value ();
|
||||
}
|
||||
}
|
||||
} /* ecma_op_object_define_own_property */
|
||||
|
||||
/**
|
||||
* [[HasInstance]] ecma object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 9
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_object_has_instance (ecma_object_t *obj_p, /**< the object */
|
||||
const ecma_value_t& value) /**< argument 'V' */
|
||||
{
|
||||
JERRY_ASSERT(obj_p != NULL
|
||||
&& !ecma_is_lexical_environment (obj_p));
|
||||
|
||||
const ecma_object_type_t type = ecma_get_object_type (obj_p);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ECMA_OBJECT_TYPE_ARRAY:
|
||||
case ECMA_OBJECT_TYPE_GENERAL:
|
||||
case ECMA_OBJECT_TYPE_STRING:
|
||||
case ECMA_OBJECT_TYPE_ARGUMENTS:
|
||||
{
|
||||
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
|
||||
case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION:
|
||||
{
|
||||
return ecma_op_function_has_instance (obj_p, value);
|
||||
}
|
||||
|
||||
case ECMA_OBJECT_TYPE__COUNT:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
} /* ecma_op_object_has_instance */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,53 @@
|
||||
/* Copyright 2014-2015 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 ECMA_OBJECTS_H
|
||||
#define ECMA_OBJECTS_H
|
||||
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmaobjectsinternalops ECMA objects' operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_completion_value_t ecma_op_object_get (ecma_object_t *obj_p, ecma_string_t *property_name_p);
|
||||
extern ecma_property_t *ecma_op_object_get_own_property (ecma_object_t *obj_p, ecma_string_t *property_name_p);
|
||||
extern ecma_property_t *ecma_op_object_get_property (ecma_object_t *obj_p, ecma_string_t *property_name_p);
|
||||
extern ecma_completion_value_t ecma_op_object_put (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p,
|
||||
const ecma_value_t& value,
|
||||
bool is_throw);
|
||||
extern bool ecma_op_object_can_put (ecma_object_t *obj_p, ecma_string_t *property_name_p);
|
||||
extern ecma_completion_value_t ecma_op_object_delete (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p,
|
||||
bool is_throw);
|
||||
extern ecma_completion_value_t ecma_op_object_default_value (ecma_object_t *obj_p, ecma_preferred_type_hint_t hint);
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_object_define_own_property (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p,
|
||||
const ecma_property_descriptor_t* property_desc_p,
|
||||
bool is_throw);
|
||||
extern ecma_completion_value_t ecma_op_object_has_instance (ecma_object_t *obj_p,
|
||||
const ecma_value_t& value);
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_OBJECTS_H */
|
||||
@@ -0,0 +1,38 @@
|
||||
/* Copyright 2014-2015 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 JERRY_ECMA_OPERATIONS_H
|
||||
#define JERRY_ECMA_OPERATIONS_H
|
||||
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup ecmainitfinalize Initialization and finalization of ECMA components
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern void ecma_init (void);
|
||||
extern void ecma_finalize (void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* JERRY_ECMA_OPERATIONS_H */
|
||||
@@ -0,0 +1,128 @@
|
||||
/* Copyright 2014-2015 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-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-reference.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup references ECMA-Reference
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolve syntactic reference.
|
||||
*
|
||||
* @return if reference was resolved successfully,
|
||||
* pointer to lexical environment - reference's base,
|
||||
* else - NULL.
|
||||
*/
|
||||
ecma_object_t*
|
||||
ecma_op_resolve_reference_base (ecma_object_t *lex_env_p, /**< starting lexical environment */
|
||||
ecma_string_t *name_p) /**< identifier's name */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL);
|
||||
|
||||
ecma_object_t *lex_env_iter_p = lex_env_p;
|
||||
|
||||
while (lex_env_iter_p != NULL)
|
||||
{
|
||||
if (ecma_op_has_binding (lex_env_iter_p, name_p))
|
||||
{
|
||||
return lex_env_iter_p;
|
||||
}
|
||||
|
||||
lex_env_iter_p = ecma_get_lex_env_outer_reference (lex_env_iter_p);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
} /* ecma_op_resolve_reference_base */
|
||||
|
||||
/**
|
||||
* Resolve syntactic reference to ECMA-reference.
|
||||
*
|
||||
* @return ECMA-reference
|
||||
* Returned value must be freed through ecma_free_reference.
|
||||
*/
|
||||
ecma_reference_t
|
||||
ecma_op_get_identifier_reference (ecma_object_t *lex_env_p, /**< lexical environment */
|
||||
ecma_string_t *name_p, /**< identifier's name */
|
||||
bool is_strict) /**< strict reference flag */
|
||||
{
|
||||
JERRY_ASSERT(lex_env_p != NULL);
|
||||
|
||||
ecma_object_t *base_lex_env_p = ecma_op_resolve_reference_base (lex_env_p, name_p);
|
||||
|
||||
if (base_lex_env_p != NULL)
|
||||
{
|
||||
return ecma_make_reference (ecma_make_object_value (base_lex_env_p),
|
||||
name_p,
|
||||
is_strict);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_make_reference (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
name_p,
|
||||
is_strict);
|
||||
}
|
||||
} /* ecma_op_get_identifier_reference */
|
||||
|
||||
/**
|
||||
* ECMA-reference constructor.
|
||||
*
|
||||
* @return ECMA-reference
|
||||
* Returned value must be freed through ecma_free_reference.
|
||||
*/
|
||||
ecma_reference_t
|
||||
ecma_make_reference (const ecma_value_t& base, /**< base value */
|
||||
ecma_string_t *name_p, /**< referenced name */
|
||||
bool is_strict) /**< strict reference flag */
|
||||
{
|
||||
name_p = ecma_copy_or_ref_ecma_string (name_p);
|
||||
|
||||
ecma_reference_t ref;
|
||||
ref.base = ecma_copy_value (base, true);
|
||||
ref.is_strict = is_strict;
|
||||
|
||||
ECMA_SET_POINTER (ref.referenced_name_cp, name_p);
|
||||
|
||||
return ref;
|
||||
} /* ecma_make_reference */
|
||||
|
||||
/**
|
||||
* Free specified ECMA-reference.
|
||||
*
|
||||
* Warning:
|
||||
* freeing invalidates all copies of the reference.
|
||||
*/
|
||||
void
|
||||
ecma_free_reference (ecma_reference_t ref) /**< reference */
|
||||
{
|
||||
ecma_free_value (ref.base, true);
|
||||
ecma_deref_ecma_string (ECMA_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
ref.referenced_name_cp));
|
||||
} /* ecma_free_reference */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,62 @@
|
||||
/* Copyright 2014-2015 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 ECMA_REFERENCE_H
|
||||
#define ECMA_REFERENCE_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup references ECMA-Reference
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* ECMA-reference (see also: ECMA-262 v5, 8.7).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** base value */
|
||||
ecma_value_t base;
|
||||
|
||||
/** referenced name */
|
||||
unsigned int referenced_name_cp : ECMA_POINTER_FIELD_WIDTH;
|
||||
|
||||
/** strict reference flag */
|
||||
unsigned int is_strict : 1;
|
||||
} ecma_reference_t;
|
||||
|
||||
extern ecma_object_t* ecma_op_resolve_reference_base (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *name_p);
|
||||
|
||||
extern ecma_reference_t ecma_op_get_identifier_reference (ecma_object_t *lex_env_p,
|
||||
ecma_string_t *name_p,
|
||||
bool is_strict);
|
||||
extern ecma_reference_t ecma_make_reference (const ecma_value_t& base,
|
||||
ecma_string_t *name_p,
|
||||
bool is_strict);
|
||||
extern void ecma_free_reference (ecma_reference_t ref);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_REFERENCE_H */
|
||||
@@ -0,0 +1,209 @@
|
||||
/* Copyright 2014-2015 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-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-string-object.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmastringobject ECMA String object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* String object creation operation.
|
||||
*
|
||||
* See also: ECMA-262 v5, 15.5.2.1
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of arguments that
|
||||
are passed to String constructor */
|
||||
ecma_length_t arguments_list_len) /**< length of the arguments' list */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0
|
||||
|| arguments_list_p != NULL);
|
||||
|
||||
ecma_string_t* prim_prop_str_value_p;
|
||||
|
||||
ecma_number_t length_value;
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
prim_prop_str_value_p = ecma_new_ecma_string_from_magic_string_id (ECMA_MAGIC_STRING__EMPTY);
|
||||
length_value = ECMA_NUMBER_ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_completion_value_t to_str_arg_value = ecma_op_to_string (arguments_list_p [0]);
|
||||
|
||||
if (ecma_is_completion_value_throw (to_str_arg_value))
|
||||
{
|
||||
return to_str_arg_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_completion_value_normal (to_str_arg_value));
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_string (ecma_get_completion_value_value (to_str_arg_value)));
|
||||
prim_prop_str_value_p = ecma_get_string_from_completion_value (to_str_arg_value);
|
||||
|
||||
int32_t string_len = ecma_string_get_length (prim_prop_str_value_p);
|
||||
JERRY_ASSERT (string_len >= 0);
|
||||
|
||||
length_value = ecma_uint32_to_number ((uint32_t) string_len);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_STRING_PROTOTYPE);
|
||||
#else /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN */
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
|
||||
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN */
|
||||
|
||||
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p,
|
||||
true,
|
||||
ECMA_OBJECT_TYPE_STRING);
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
|
||||
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_STRING_UL;
|
||||
|
||||
ecma_property_t *prim_value_prop_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE);
|
||||
ECMA_SET_POINTER (prim_value_prop_p->u.internal_property.value, prim_prop_str_value_p);
|
||||
|
||||
// 15.5.5.1
|
||||
ecma_string_t *length_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
|
||||
ecma_property_t *length_prop_p = ecma_create_named_data_property (obj_p,
|
||||
length_magic_string_p,
|
||||
false, false, false);
|
||||
ecma_number_t *length_prop_value_p = ecma_alloc_number ();
|
||||
*length_prop_value_p = length_value;
|
||||
ecma_set_named_data_property_value (length_prop_p, ecma_make_number_value (length_prop_value_p));
|
||||
ecma_deref_ecma_string (length_magic_string_p);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
|
||||
} /* ecma_op_create_string_object */
|
||||
|
||||
/**
|
||||
* [[GetOwnProperty]] ecma String object's operation
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
|
||||
* ECMA-262 v5, 15.5.5.2
|
||||
*
|
||||
* @return completion value
|
||||
* Returned value must be freed with ecma_free_completion_value
|
||||
*/
|
||||
ecma_property_t*
|
||||
ecma_op_string_object_get_own_property (ecma_object_t *obj_p, /**< the array object */
|
||||
ecma_string_t *property_name_p) /**< property name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_STRING);
|
||||
|
||||
// 1.
|
||||
ecma_property_t *prop_p = ecma_op_general_object_get_own_property (obj_p, property_name_p);
|
||||
|
||||
// 2.
|
||||
if (prop_p != NULL)
|
||||
{
|
||||
return prop_p;
|
||||
}
|
||||
|
||||
// 3., 5.
|
||||
uint32_t uint32_index;
|
||||
ecma_string_t *new_prop_name_p;
|
||||
|
||||
if (property_name_p->container == ECMA_STRING_CONTAINER_UINT32_IN_DESC)
|
||||
{
|
||||
uint32_index = property_name_p->u.uint32_number;
|
||||
|
||||
new_prop_name_p = ecma_copy_or_ref_ecma_string (property_name_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_number_t index = ecma_string_to_number (property_name_p);
|
||||
uint32_index = ecma_number_to_uint32 (index);
|
||||
|
||||
ecma_string_t *to_str_p = ecma_new_ecma_string_from_uint32 (uint32_index);
|
||||
|
||||
bool are_equal = ecma_compare_ecma_strings (to_str_p, property_name_p);
|
||||
|
||||
if (!are_equal)
|
||||
{
|
||||
ecma_deref_ecma_string (to_str_p);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_prop_name_p = to_str_p;
|
||||
}
|
||||
}
|
||||
|
||||
// 4.
|
||||
ecma_property_t* prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE);
|
||||
ecma_string_t *prim_value_str_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
|
||||
prim_value_prop_p->u.internal_property.value);
|
||||
|
||||
// 6.
|
||||
int32_t length = ecma_string_get_length (prim_value_str_p);
|
||||
JERRY_ASSERT (length >= 0);
|
||||
|
||||
ecma_property_t *new_prop_p;
|
||||
|
||||
if (uint32_index >= (uint32_t) length)
|
||||
{
|
||||
// 7.
|
||||
new_prop_p = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 8.
|
||||
ecma_char_t c = ecma_string_get_char_at_pos (prim_value_str_p, uint32_index);
|
||||
|
||||
// 9.
|
||||
ecma_char_t new_prop_zt_str_p [2] = { c, ECMA_CHAR_NULL };
|
||||
ecma_string_t *new_prop_str_value_p = ecma_new_ecma_string (new_prop_zt_str_p);
|
||||
|
||||
new_prop_p = ecma_create_named_data_property (obj_p,
|
||||
new_prop_name_p,
|
||||
false, true, false);
|
||||
|
||||
ecma_set_named_data_property_value (new_prop_p,
|
||||
ecma_make_string_value (new_prop_str_value_p));
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (new_prop_name_p);
|
||||
|
||||
return new_prop_p;
|
||||
} /* ecma_op_string_object_get_own_property */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,41 @@
|
||||
/* Copyright 2014-2015 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 ECMA_STRING_OBJECT_H
|
||||
#define ECMA_STRING_OBJECT_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmastringobject ECMA String object related routines
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_completion_value_t
|
||||
ecma_op_create_string_object (const ecma_value_t *arguments_list_p,
|
||||
ecma_length_t arguments_list_len);
|
||||
|
||||
extern ecma_property_t*
|
||||
ecma_op_string_object_get_own_property (ecma_object_t *obj_p,
|
||||
ecma_string_t *property_name_p);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_STRING_OBJECT_H */
|
||||
@@ -0,0 +1,100 @@
|
||||
/* Copyright 2014-2015 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 ECMA_TRY_CATCH_MACRO_H
|
||||
#define ECMA_TRY_CATCH_MACRO_H
|
||||
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
/**
|
||||
* The macro defines try-block that initializes variable 'var' with 'op'
|
||||
* and checks for exceptions that might be thrown during initialization.
|
||||
*
|
||||
* If no exception was thrown, then code after the try-block is executed.
|
||||
* Otherwise, throw-completion value is just copied to return_value.
|
||||
*
|
||||
* Note:
|
||||
* Each ECMA_TRY_CATCH should have it's own corresponding ECMA_FINALIZE
|
||||
* statement with same argument as corresponding ECMA_TRY_CATCH's first argument.
|
||||
*/
|
||||
#define ECMA_TRY_CATCH(var, op, return_value) \
|
||||
ecma_completion_value_t var ## _completion = op; \
|
||||
if (unlikely (ecma_is_completion_value_throw (var ## _completion))) \
|
||||
{ \
|
||||
return_value = var ## _completion; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
JERRY_ASSERT(ecma_is_completion_value_normal (var ## _completion)); \
|
||||
\
|
||||
ecma_value_t var __attr_unused___ = ecma_get_completion_value_value (var ## _completion)
|
||||
|
||||
/**
|
||||
* The macro marks end of code block that is defined by corresponding
|
||||
* ECMA_TRY_CATCH and frees variable, initialized by the ECMA_TRY_CATCH.
|
||||
*
|
||||
* Note:
|
||||
* Each ECMA_TRY_CATCH should be followed by ECMA_FINALIZE with same argument
|
||||
* as corresponding ECMA_TRY_CATCH's first argument.
|
||||
*/
|
||||
#define ECMA_FINALIZE(var) ecma_free_completion_value (var ## _completion); \
|
||||
}
|
||||
|
||||
/**
|
||||
* The macro defines try-block that tries to perform ToNumber operation on given value
|
||||
* and checks for exceptions that might be thrown during the operation.
|
||||
*
|
||||
* If no exception was thrown, then code after the try-block is executed.
|
||||
* Otherwise, throw-completion value is just copied to return_value.
|
||||
*
|
||||
* Note:
|
||||
* Each ECMA_OP_TO_NUMBER_TRY_CATCH should have it's own corresponding ECMA_OP_TO_NUMBER_FINALIZE
|
||||
* statement with same argument as corresponding ECMA_OP_TO_NUMBER_TRY_CATCH's first argument.
|
||||
*/
|
||||
#define ECMA_OP_TO_NUMBER_TRY_CATCH(num_var, value, return_value) \
|
||||
JERRY_ASSERT (ecma_is_completion_value_empty (return_value)); \
|
||||
ecma_number_t num_var = ecma_number_make_nan (); \
|
||||
if (ecma_is_value_number (value)) \
|
||||
{ \
|
||||
num_var = *ecma_get_number_from_value (value); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ECMA_TRY_CATCH (to_number_value, \
|
||||
ecma_op_to_number (value), \
|
||||
return_value); \
|
||||
\
|
||||
num_var = *ecma_get_number_from_value (to_number_value); \
|
||||
\
|
||||
ECMA_FINALIZE (to_number_value); \
|
||||
} \
|
||||
\
|
||||
if (ecma_is_completion_value_empty (return_value)) \
|
||||
{
|
||||
|
||||
/**
|
||||
* The macro marks end of code block that is defined by corresponding ECMA_OP_TO_NUMBER_TRY_CATCH.
|
||||
*
|
||||
* Note:
|
||||
* Each ECMA_OP_TO_NUMBER_TRY_CATCH should be followed by ECMA_OP_TO_NUMBER_FINALIZE
|
||||
* with same argument as corresponding ECMA_OP_TO_NUMBER_TRY_CATCH's first argument.
|
||||
*/
|
||||
#define ECMA_OP_TO_NUMBER_FINALIZE(num_var) } \
|
||||
else \
|
||||
{ \
|
||||
JERRY_ASSERT (ecma_number_is_nan (num_var)); \
|
||||
}
|
||||
|
||||
#endif /* !ECMA_TRY_CATCH_MACRO_H */
|
||||
Reference in New Issue
Block a user