mirror of
https://github.com/google/pebble.git
synced 2025-07-04 22:00:38 -04:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
2801
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c
vendored
Normal file
2801
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
86
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h
vendored
Normal file
86
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Array.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.4.4.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_ARRAY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.4.4
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FLAG_WRITABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_array_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_array_prototype_object_to_locale_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_CONCAT, ecma_builtin_array_prototype_object_concat, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_JOIN, ecma_builtin_array_prototype_join, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_POP, ecma_builtin_array_prototype_object_pop, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_PUSH, ecma_builtin_array_prototype_object_push, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_REVERSE, ecma_builtin_array_prototype_object_reverse, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_SHIFT, ecma_builtin_array_prototype_object_shift, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_array_prototype_object_slice, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_SORT, ecma_builtin_array_prototype_object_sort, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SPLICE, ecma_builtin_array_prototype_object_splice, NON_FIXED, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_UNSHIFT, ecma_builtin_array_prototype_object_unshift, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_INDEX_OF_UL, ecma_builtin_array_prototype_object_index_of, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, ecma_builtin_array_prototype_object_last_index_of, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_EVERY, ecma_builtin_array_prototype_object_every, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SOME, ecma_builtin_array_prototype_object_some, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ecma_builtin_array_prototype_object_for_each, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_MAP, ecma_builtin_array_prototype_object_map, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_FILTER, ecma_builtin_array_prototype_object_filter, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_REDUCE, ecma_builtin_array_prototype_object_reduce, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ecma_builtin_array_prototype_object_reduce_right, NON_FIXED, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
||||
|
110
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.c
vendored
Normal file
110
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.c
vendored
Normal file
|
@ -0,0 +1,110 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ARRAY_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID array
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup array ECMA Array object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Array object's 'isArray' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.4.3.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_array_object_is_array (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< first argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_simple_value_t is_array = ECMA_SIMPLE_VALUE_FALSE;
|
||||
|
||||
if (ecma_is_value_object (arg))
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
|
||||
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_ARRAY_UL)
|
||||
{
|
||||
is_array = ECMA_SIMPLE_VALUE_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_make_simple_value (is_array);
|
||||
} /* ecma_builtin_array_object_is_array */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Array object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_builtin_array_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_array_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Array object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_op_create_array_object (arguments_list_p, arguments_list_len, true);
|
||||
} /* ecma_builtin_array_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ARRAY_BUILTIN */
|
65
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h
vendored
Normal file
65
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Array description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_ARRAY)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.4.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_ARRAY_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.4.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
||||
|
125
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.c
vendored
Normal file
125
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.c
vendored
Normal file
|
@ -0,0 +1,125 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-boolean-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID boolean_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup booleanprototype ECMA Boolean.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Boolean.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.6.4.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_boolean_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_TRY_CATCH (value_of_ret,
|
||||
ecma_builtin_boolean_prototype_object_value_of (this_arg),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *ret_str_p;
|
||||
|
||||
if (ecma_is_value_true (value_of_ret))
|
||||
{
|
||||
ret_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_boolean (value_of_ret));
|
||||
|
||||
ret_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_FALSE);
|
||||
}
|
||||
|
||||
ret_value = ecma_make_string_value (ret_str_p);
|
||||
|
||||
ECMA_FINALIZE (value_of_ret);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_boolean_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Boolean.prototype object's 'valueOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.6.4.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_boolean_prototype_object_value_of (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
if (ecma_is_value_boolean (this_arg))
|
||||
{
|
||||
return this_arg;
|
||||
}
|
||||
else if (ecma_is_value_object (this_arg))
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_BOOLEAN_UL)
|
||||
{
|
||||
ecma_value_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (*prim_value_prop_p));
|
||||
|
||||
return *prim_value_prop_p;
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
} /* ecma_builtin_boolean_prototype_object_value_of */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
|
53
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h
vendored
Normal file
53
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Boolean.prototype description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.6.4.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_BOOLEAN,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_boolean_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_boolean_prototype_object_value_of, 0, 0)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
100
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.c
vendored
Normal file
100
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.c
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-boolean-object.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-boolean.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID boolean
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup boolean ECMA Boolean object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Boolean object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_boolean_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_value_t arg_value;
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
arg_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
else
|
||||
{
|
||||
arg_value = arguments_list_p[0];
|
||||
}
|
||||
|
||||
return ecma_make_simple_value (ecma_op_to_boolean (arg_value) ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
} /* ecma_builtin_boolean_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Boolean object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_boolean_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
return ecma_op_create_boolean_object (ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_create_boolean_object (arguments_list_p[0]);
|
||||
}
|
||||
} /* ecma_builtin_boolean_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
|
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h
vendored
Normal file
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Boolean description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_BOOLEAN)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.6.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.6.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
1327
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.c
vendored
Normal file
1327
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
97
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h
vendored
Normal file
97
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,97 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Date.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_DATE_PROTOTYPE)
|
||||
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_DATE,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_date_prototype_to_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_DATE_STRING_UL, ecma_builtin_date_prototype_to_date_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_TIME_STRING_UL, ecma_builtin_date_prototype_to_time_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_date_prototype_to_locale_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_DATE_STRING_UL, ecma_builtin_date_prototype_to_locale_date_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_TIME_STRING_UL, ecma_builtin_date_prototype_to_locale_time_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_date_prototype_value_of, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_TIME_UL, ecma_builtin_date_prototype_get_time, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_FULL_YEAR_UL, ecma_builtin_date_prototype_get_full_year, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_UTC_FULL_YEAR_UL, ecma_builtin_date_prototype_get_utc_full_year, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_MONTH_UL, ecma_builtin_date_prototype_get_month, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_UTC_MONTH_UL, ecma_builtin_date_prototype_get_utc_month, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_DATE_UL, ecma_builtin_date_prototype_get_date, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_UTC_DATE_UL, ecma_builtin_date_prototype_get_utc_date, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_DAY_UL, ecma_builtin_date_prototype_get_day, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_UTC_DAY_UL, ecma_builtin_date_prototype_get_utc_day, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_HOURS_UL, ecma_builtin_date_prototype_get_hours, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_UTC_HOURS_UL, ecma_builtin_date_prototype_get_utc_hours, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_MINUTES_UL, ecma_builtin_date_prototype_get_minutes, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_UTC_MINUTES_UL, ecma_builtin_date_prototype_get_utc_minutes, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_SECONDS_UL, ecma_builtin_date_prototype_get_seconds, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_UTC_SECONDS_UL, ecma_builtin_date_prototype_get_utc_seconds, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_MILLISECONDS_UL, ecma_builtin_date_prototype_get_milliseconds, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_UTC_MILLISECONDS_UL, ecma_builtin_date_prototype_get_utc_milliseconds, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_TIMEZONE_OFFSET_UL, ecma_builtin_date_prototype_get_timezone_offset, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_TIME_UL, ecma_builtin_date_prototype_set_time, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_MILLISECONDS_UL, ecma_builtin_date_prototype_set_milliseconds, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_UTC_MILLISECONDS_UL, ecma_builtin_date_prototype_set_utc_milliseconds, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_SECONDS_UL, ecma_builtin_date_prototype_set_seconds, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_UTC_SECONDS_UL, ecma_builtin_date_prototype_set_utc_seconds, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_MINUTES_UL, ecma_builtin_date_prototype_set_minutes, NON_FIXED, 3)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_UTC_MINUTES_UL, ecma_builtin_date_prototype_set_utc_minutes, NON_FIXED, 3)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_HOURS_UL, ecma_builtin_date_prototype_set_hours, NON_FIXED, 4)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_UTC_HOURS_UL, ecma_builtin_date_prototype_set_utc_hours, NON_FIXED, 4)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_DATE_UL, ecma_builtin_date_prototype_set_date, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_UTC_DATE_UL, ecma_builtin_date_prototype_set_utc_date, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_MONTH_UL, ecma_builtin_date_prototype_set_month, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_UTC_MONTH_UL, ecma_builtin_date_prototype_set_utc_month, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_FULL_YEAR_UL, ecma_builtin_date_prototype_set_full_year, NON_FIXED, 3)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_UTC_FULL_YEAR_UL, ecma_builtin_date_prototype_set_utc_full_year, NON_FIXED, 3)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_UTC_STRING_UL, ecma_builtin_date_prototype_to_utc_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_ISO_STRING_UL, ecma_builtin_date_prototype_to_iso_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_JSON_UL, ecma_builtin_date_prototype_to_json, 1, 1)
|
||||
|
||||
#ifndef CONFIG_DISABLE_ANNEXB_BUILTIN
|
||||
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_YEAR_UL, ecma_builtin_date_prototype_get_year, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_SET_YEAR_UL, ecma_builtin_date_prototype_set_year, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_GMT_STRING_UL, ecma_builtin_date_prototype_to_utc_string, 0, 0)
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
577
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.c
vendored
Normal file
577
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.c
vendored
Normal file
|
@ -0,0 +1,577 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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-builtin-helpers.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "lit-char-helpers.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_DATE_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-date.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID date
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup date ECMA Date object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper function to try to parse a part of a date string
|
||||
*
|
||||
* @return NaN if cannot read from string, ToNumber() otherwise
|
||||
*/
|
||||
static ecma_number_t
|
||||
ecma_date_parse_date_chars (const lit_utf8_byte_t **str_p, /**< pointer to the cesu8 string */
|
||||
const lit_utf8_byte_t *str_end_p, /**< pointer to the end of the string */
|
||||
uint32_t num_of_chars) /**< number of characters to read and convert */
|
||||
{
|
||||
JERRY_ASSERT (num_of_chars > 0);
|
||||
const lit_utf8_byte_t *str_start_p = *str_p;
|
||||
|
||||
while (num_of_chars--)
|
||||
{
|
||||
if (*str_p >= str_end_p || !lit_char_is_decimal_digit (lit_utf8_read_next (str_p)))
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_utf8_string_to_number (str_start_p, (lit_utf8_size_t) (*str_p - str_start_p));
|
||||
} /* ecma_date_parse_date_chars */
|
||||
|
||||
/**
|
||||
* Calculate MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli)) for Date constructor and UTC
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.9.3.1
|
||||
* ECMA-262 v5, 15.9.4.3
|
||||
*
|
||||
* @return result of MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli))
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_date_construct_helper (const ecma_value_t *args, /**< arguments passed to the Date constructor */
|
||||
ecma_length_t args_len) /**< number of arguments */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_number_t prim_value = ecma_number_make_nan ();
|
||||
|
||||
ECMA_TRY_CATCH (year_value, ecma_op_to_number (args[0]), ret_value);
|
||||
ECMA_TRY_CATCH (month_value, ecma_op_to_number (args[1]), ret_value);
|
||||
|
||||
ecma_number_t year = ecma_get_number_from_value (year_value);
|
||||
ecma_number_t month = ecma_get_number_from_value (month_value);
|
||||
ecma_number_t date = ECMA_NUMBER_ONE;
|
||||
ecma_number_t hours = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t minutes = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t seconds = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t milliseconds = ECMA_NUMBER_ZERO;
|
||||
|
||||
/* 3. */
|
||||
if (args_len >= 3 && ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (date_value, ecma_op_to_number (args[2]), ret_value);
|
||||
date = ecma_get_number_from_value (date_value);
|
||||
ECMA_FINALIZE (date_value);
|
||||
}
|
||||
|
||||
/* 4. */
|
||||
if (args_len >= 4 && ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (hours_value, ecma_op_to_number (args[3]), ret_value);
|
||||
hours = ecma_get_number_from_value (hours_value);
|
||||
ECMA_FINALIZE (hours_value);
|
||||
}
|
||||
|
||||
/* 5. */
|
||||
if (args_len >= 5 && ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (minutes_value, ecma_op_to_number (args[4]), ret_value);
|
||||
minutes = ecma_get_number_from_value (minutes_value);
|
||||
ECMA_FINALIZE (minutes_value);
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
if (args_len >= 6 && ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (seconds_value, ecma_op_to_number (args[5]), ret_value);
|
||||
seconds = ecma_get_number_from_value (seconds_value);
|
||||
ECMA_FINALIZE (seconds_value);
|
||||
}
|
||||
|
||||
/* 7. */
|
||||
if (args_len >= 7 && ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (milliseconds_value, ecma_op_to_number (args[6]), ret_value);
|
||||
milliseconds = ecma_get_number_from_value (milliseconds_value);
|
||||
ECMA_FINALIZE (milliseconds_value);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
if (!ecma_number_is_nan (year))
|
||||
{
|
||||
/* 8. */
|
||||
ecma_number_t y = ecma_number_trunc (year);
|
||||
|
||||
if (y >= 0 && y <= 99)
|
||||
{
|
||||
year = 1900 + y;
|
||||
}
|
||||
}
|
||||
|
||||
prim_value = ecma_date_make_date (ecma_date_make_day (year,
|
||||
month,
|
||||
date),
|
||||
ecma_date_make_time (hours,
|
||||
minutes,
|
||||
seconds,
|
||||
milliseconds));
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (month_value);
|
||||
ECMA_FINALIZE (year_value);
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_make_number_value (prim_value);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_date_construct_helper */
|
||||
|
||||
/**
|
||||
* The Date object's 'parse' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.9.4.2
|
||||
* ECMA-262 v5, 15.9.1.15
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< string */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_number_t date_num = ecma_number_make_nan ();
|
||||
|
||||
/* Date Time String fromat (ECMA-262 v5, 15.9.1.15) */
|
||||
ECMA_TRY_CATCH (date_str_value,
|
||||
ecma_op_to_string (arg),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *date_str_p = ecma_get_string_from_value (date_str_value);
|
||||
|
||||
ECMA_STRING_TO_UTF8_STRING (date_str_p, date_start_p, date_start_size);
|
||||
|
||||
const lit_utf8_byte_t *date_str_curr_p = date_start_p;
|
||||
const lit_utf8_byte_t *date_str_end_p = date_start_p + date_start_size;
|
||||
|
||||
/* 1. read year */
|
||||
ecma_number_t year = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 4);
|
||||
|
||||
if (!ecma_number_is_nan (year)
|
||||
&& year >= 0)
|
||||
{
|
||||
ecma_number_t month = ECMA_NUMBER_ONE;
|
||||
ecma_number_t day = ECMA_NUMBER_ONE;
|
||||
ecma_number_t time = ECMA_NUMBER_ZERO;
|
||||
|
||||
/* 2. read month if any */
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == '-')
|
||||
{
|
||||
/* eat up '-' */
|
||||
date_str_curr_p++;
|
||||
month = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (month > 12 || month < 1)
|
||||
{
|
||||
month = ecma_number_make_nan ();
|
||||
}
|
||||
}
|
||||
|
||||
/* 3. read day if any */
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == '-')
|
||||
{
|
||||
/* eat up '-' */
|
||||
date_str_curr_p++;
|
||||
day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (day < 1 || day > 31)
|
||||
{
|
||||
day = ecma_number_make_nan ();
|
||||
}
|
||||
}
|
||||
|
||||
/* 4. read time if any */
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == 'T')
|
||||
{
|
||||
/* eat up 'T' */
|
||||
date_str_curr_p++;
|
||||
|
||||
ecma_number_t hours = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t minutes = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t seconds = ECMA_NUMBER_ZERO;
|
||||
ecma_number_t milliseconds = ECMA_NUMBER_ZERO;
|
||||
|
||||
ecma_length_t remaining_length = lit_utf8_string_length (date_str_curr_p,
|
||||
(lit_utf8_size_t) (date_str_end_p - date_str_curr_p));
|
||||
|
||||
if (remaining_length >= 5)
|
||||
{
|
||||
/* 4.1 read hours and minutes */
|
||||
hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (hours < 0 || hours > 24)
|
||||
{
|
||||
hours = ecma_number_make_nan ();
|
||||
}
|
||||
else if (hours == 24)
|
||||
{
|
||||
hours = ECMA_NUMBER_ZERO;
|
||||
}
|
||||
|
||||
/* eat up ':' */
|
||||
date_str_curr_p++;
|
||||
|
||||
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (minutes < 0 || minutes > 59)
|
||||
{
|
||||
minutes = ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
/* 4.2 read seconds if any */
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == ':')
|
||||
{
|
||||
/* eat up ':' */
|
||||
date_str_curr_p++;
|
||||
seconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (seconds < 0 || seconds > 59)
|
||||
{
|
||||
seconds = ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
/* 4.3 read milliseconds if any */
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == '.')
|
||||
{
|
||||
/* eat up '.' */
|
||||
date_str_curr_p++;
|
||||
milliseconds = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 3);
|
||||
|
||||
if (milliseconds < 0)
|
||||
{
|
||||
milliseconds = ecma_number_make_nan ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
time = ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
/* 4.4 read timezone if any */
|
||||
if (date_str_curr_p < date_str_end_p
|
||||
&& *date_str_curr_p == 'Z'
|
||||
&& !ecma_number_is_nan (time))
|
||||
{
|
||||
date_str_curr_p++;
|
||||
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
|
||||
}
|
||||
else if (date_str_curr_p < date_str_end_p
|
||||
&& (*date_str_curr_p == '+' || *date_str_curr_p == '-'))
|
||||
{
|
||||
ecma_length_t remaining_length;
|
||||
remaining_length = lit_utf8_string_length (date_str_curr_p,
|
||||
(lit_utf8_size_t) (date_str_end_p - date_str_curr_p)) - 1;
|
||||
|
||||
if (remaining_length == 5)
|
||||
{
|
||||
bool is_negative = false;
|
||||
|
||||
if (*date_str_curr_p == '-')
|
||||
{
|
||||
is_negative = true;
|
||||
}
|
||||
|
||||
/* eat up '+/-' */
|
||||
date_str_curr_p++;
|
||||
|
||||
/* read hours and minutes */
|
||||
hours = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (hours < 0 || hours > 24)
|
||||
{
|
||||
hours = ecma_number_make_nan ();
|
||||
}
|
||||
else if (hours == 24)
|
||||
{
|
||||
hours = ECMA_NUMBER_ZERO;
|
||||
}
|
||||
|
||||
/* eat up ':' */
|
||||
date_str_curr_p++;
|
||||
|
||||
minutes = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2);
|
||||
|
||||
if (minutes < 0 || minutes > 59)
|
||||
{
|
||||
minutes = ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
time += ecma_date_make_time (hours, minutes, ECMA_NUMBER_ZERO, ECMA_NUMBER_ZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
time -= ecma_date_make_time (hours, minutes, ECMA_NUMBER_ZERO, ECMA_NUMBER_ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (date_str_curr_p >= date_str_end_p)
|
||||
{
|
||||
ecma_number_t date = ecma_date_make_day (year, month - 1, day);
|
||||
date_num = ecma_date_make_date (date, time);
|
||||
}
|
||||
}
|
||||
|
||||
ret_value = ecma_make_number_value (date_num);
|
||||
|
||||
ECMA_FINALIZE_UTF8_STRING (date_start_p, date_start_size);
|
||||
ECMA_FINALIZE (date_str_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_date_parse */
|
||||
|
||||
/**
|
||||
* The Date object's 'UTC' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.9.4.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_date_utc (ecma_value_t this_arg, /**< this argument */
|
||||
const ecma_value_t args[], /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (args_number < 2)
|
||||
{
|
||||
/* Note:
|
||||
* When the UTC function is called with fewer than two arguments,
|
||||
* the behaviour is implementation-dependent, so just return NaN.
|
||||
*/
|
||||
return ecma_make_number_value (ecma_number_make_nan ());
|
||||
}
|
||||
|
||||
ECMA_TRY_CATCH (time_value, ecma_date_construct_helper (args, args_number), ret_value);
|
||||
|
||||
ecma_number_t time = ecma_get_number_from_value (time_value);
|
||||
ret_value = ecma_make_number_value (ecma_date_time_clip (time));
|
||||
|
||||
ECMA_FINALIZE (time_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_date_utc */
|
||||
|
||||
/**
|
||||
* The Date object's 'now' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.9.4.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_date_now (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
return ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (jerry_port_get_current_time ()));
|
||||
} /* ecma_builtin_date_now */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Date object
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.9.2.1
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_date_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_UNUSED (arguments_list_p);
|
||||
JERRY_UNUSED (arguments_list_len);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_TRY_CATCH (now_val,
|
||||
ecma_builtin_date_now (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED)),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_date_value_to_string (ecma_get_number_from_value (now_val));
|
||||
|
||||
ECMA_FINALIZE (now_val);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_date_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Date object
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.9.3.1
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_number_t prim_value_num = ECMA_NUMBER_ZERO;
|
||||
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_DATE_PROTOTYPE);
|
||||
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p,
|
||||
false,
|
||||
true,
|
||||
ECMA_OBJECT_TYPE_GENERAL);
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ECMA_TRY_CATCH (parse_res_value,
|
||||
ecma_builtin_date_now (ecma_make_object_value (obj_p)),
|
||||
ret_value);
|
||||
|
||||
prim_value_num = ecma_get_number_from_value (parse_res_value);
|
||||
|
||||
ECMA_FINALIZE (parse_res_value)
|
||||
}
|
||||
else if (arguments_list_len == 1)
|
||||
{
|
||||
ECMA_TRY_CATCH (prim_comp_value,
|
||||
ecma_op_to_primitive (arguments_list_p[0], ECMA_PREFERRED_TYPE_NUMBER),
|
||||
ret_value);
|
||||
|
||||
if (ecma_is_value_string (prim_comp_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (parse_res_value,
|
||||
ecma_builtin_date_parse (ecma_make_object_value (obj_p), prim_comp_value),
|
||||
ret_value);
|
||||
|
||||
prim_value_num = ecma_get_number_from_value (parse_res_value);
|
||||
|
||||
ECMA_FINALIZE (parse_res_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_TRY_CATCH (prim_value, ecma_op_to_number (arguments_list_p[0]), ret_value);
|
||||
|
||||
prim_value_num = ecma_date_time_clip (ecma_get_number_from_value (prim_value));
|
||||
|
||||
ECMA_FINALIZE (prim_value);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (prim_comp_value);
|
||||
}
|
||||
else if (arguments_list_len >= 2)
|
||||
{
|
||||
ECMA_TRY_CATCH (time_value,
|
||||
ecma_date_construct_helper (arguments_list_p, arguments_list_len),
|
||||
ret_value);
|
||||
|
||||
ecma_number_t time = ecma_get_number_from_value (time_value);
|
||||
prim_value_num = ecma_date_time_clip (ecma_date_utc (time));
|
||||
|
||||
ECMA_FINALIZE (time_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
prim_value_num = ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
if (!ecma_number_is_nan (prim_value_num) && ecma_number_is_infinity (prim_value_num))
|
||||
{
|
||||
prim_value_num = ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
ecma_value_t *class_prop_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_CLASS);
|
||||
*class_prop_p = LIT_MAGIC_STRING_DATE_UL;
|
||||
|
||||
ecma_value_t *date_prop_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
|
||||
|
||||
ecma_number_t *date_num_p = ecma_alloc_number ();
|
||||
*date_num_p = prim_value_num;
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (*date_prop_p, date_num_p);
|
||||
|
||||
ret_value = ecma_make_object_value (obj_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ECMA_IS_VALUE_ERROR (ret_value));
|
||||
ecma_deref_object (obj_p);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_date_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_DATE_BUILTIN */
|
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h
vendored
Normal file
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Date built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_DATE)
|
||||
|
||||
// ECMA-262 v5, 15.9.4.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_DATE_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
7,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE, ecma_builtin_date_parse, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_UTC_U, ecma_builtin_date_utc, NON_FIXED, 7)
|
||||
ROUTINE (LIT_MAGIC_STRING_NOW, ecma_builtin_date_now, 0, 0)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
195
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.c
vendored
Normal file
195
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.c
vendored
Normal file
|
@ -0,0 +1,195 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
#include "lit-magic-strings.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-error-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID error_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup errorprototype ECMA Error.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Error.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.11.4.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_error_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
// 2.
|
||||
if (!ecma_is_value_object (this_arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_string_t *name_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_NAME);
|
||||
|
||||
ECMA_TRY_CATCH (name_get_ret_value,
|
||||
ecma_op_object_get (obj_p, name_magic_string_p),
|
||||
ret_value);
|
||||
|
||||
ecma_value_t name_to_str_completion;
|
||||
|
||||
if (ecma_is_value_undefined (name_get_ret_value))
|
||||
{
|
||||
ecma_string_t *error_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_ERROR_UL);
|
||||
|
||||
name_to_str_completion = ecma_make_string_value (error_magic_string_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
name_to_str_completion = ecma_op_to_string (name_get_ret_value);
|
||||
}
|
||||
|
||||
if (unlikely (ECMA_IS_VALUE_ERROR (name_to_str_completion)))
|
||||
{
|
||||
ret_value = ecma_copy_value (name_to_str_completion);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_string_t *message_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE);
|
||||
|
||||
ECMA_TRY_CATCH (msg_get_ret_value,
|
||||
ecma_op_object_get (obj_p, message_magic_string_p),
|
||||
ret_value);
|
||||
|
||||
ecma_value_t msg_to_str_completion;
|
||||
|
||||
if (ecma_is_value_undefined (msg_get_ret_value))
|
||||
{
|
||||
ecma_string_t *empty_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
|
||||
msg_to_str_completion = ecma_make_string_value (empty_magic_string_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg_to_str_completion = ecma_op_to_string (msg_get_ret_value);
|
||||
}
|
||||
|
||||
if (unlikely (ECMA_IS_VALUE_ERROR (msg_to_str_completion)))
|
||||
{
|
||||
ret_value = ecma_copy_value (msg_to_str_completion);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_string_t *name_string_p = ecma_get_string_from_value (name_to_str_completion);
|
||||
ecma_string_t *msg_string_p = ecma_get_string_from_value (msg_to_str_completion);
|
||||
|
||||
ecma_string_t *ret_str_p;
|
||||
|
||||
if (ecma_string_is_empty (name_string_p))
|
||||
{
|
||||
ret_str_p = msg_string_p;
|
||||
ecma_ref_ecma_string (ret_str_p);
|
||||
}
|
||||
else if (ecma_string_is_empty (msg_string_p))
|
||||
{
|
||||
ret_str_p = name_string_p;
|
||||
ecma_ref_ecma_string (ret_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
const lit_utf8_size_t name_size = ecma_string_get_size (name_string_p);
|
||||
const lit_utf8_size_t msg_size = ecma_string_get_size (msg_string_p);
|
||||
const lit_utf8_size_t colon_size = lit_get_magic_string_size (LIT_MAGIC_STRING_COLON_CHAR);
|
||||
const lit_utf8_size_t space_size = lit_get_magic_string_size (LIT_MAGIC_STRING_SPACE_CHAR);
|
||||
const lit_utf8_size_t size = name_size + msg_size + colon_size + space_size;
|
||||
|
||||
JMEM_DEFINE_LOCAL_ARRAY (ret_str_buffer, size, lit_utf8_byte_t);
|
||||
lit_utf8_byte_t *ret_str_buffer_p = ret_str_buffer;
|
||||
|
||||
lit_utf8_size_t bytes = ecma_string_copy_to_utf8_buffer (name_string_p, ret_str_buffer_p, name_size);
|
||||
JERRY_ASSERT (bytes == name_size);
|
||||
ret_str_buffer_p = ret_str_buffer_p + bytes;
|
||||
JERRY_ASSERT (ret_str_buffer_p <= ret_str_buffer + size);
|
||||
|
||||
ret_str_buffer_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_COLON_CHAR,
|
||||
ret_str_buffer_p,
|
||||
colon_size);
|
||||
JERRY_ASSERT (ret_str_buffer_p <= ret_str_buffer + size);
|
||||
|
||||
ret_str_buffer_p = lit_copy_magic_string_to_buffer (LIT_MAGIC_STRING_SPACE_CHAR,
|
||||
ret_str_buffer_p,
|
||||
space_size);
|
||||
JERRY_ASSERT (ret_str_buffer_p <= ret_str_buffer + size);
|
||||
|
||||
bytes = ecma_string_copy_to_utf8_buffer (msg_string_p, ret_str_buffer_p, msg_size);
|
||||
JERRY_ASSERT (bytes == msg_size);
|
||||
ret_str_buffer_p = ret_str_buffer_p + bytes;
|
||||
JERRY_ASSERT (ret_str_buffer_p == ret_str_buffer + size);
|
||||
|
||||
ret_str_p = ecma_new_ecma_string_from_utf8 (ret_str_buffer,
|
||||
size);
|
||||
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (ret_str_buffer);
|
||||
}
|
||||
|
||||
ret_value = ecma_make_string_value (ret_str_p);
|
||||
}
|
||||
|
||||
ecma_free_value (msg_to_str_completion);
|
||||
|
||||
ECMA_FINALIZE (msg_get_ret_value);
|
||||
|
||||
ecma_deref_ecma_string (message_magic_string_p);
|
||||
}
|
||||
|
||||
ecma_free_value (name_to_str_completion);
|
||||
|
||||
ECMA_FINALIZE (name_get_ret_value);
|
||||
|
||||
ecma_deref_ecma_string (name_magic_string_p);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_error_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
66
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.inc.h
vendored
Normal file
66
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Error.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_ERROR_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.4.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.4.2
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_ERROR_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.4.3
|
||||
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
|
||||
LIT_MAGIC_STRING__EMPTY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_error_prototype_object_to_string, 0, 0)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
73
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.c
vendored
Normal file
73
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.c
vendored
Normal file
|
@ -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-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-error.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup error ECMA Error object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Error object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_COMMON, arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_error_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Error object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_error_dispatch_call (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_error_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.inc.h
vendored
Normal file
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-error.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Error built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_ERROR)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.11.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.7.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.c
vendored
Normal file
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.c
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-evalerror-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID eval_error_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.inc.h
vendored
Normal file
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* EvalError.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.7.8
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_EVAL_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.9
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_EVAL_ERROR_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.10
|
||||
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
|
||||
LIT_MAGIC_STRING__EMPTY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.c
vendored
Normal file
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.c
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-evalerror.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID eval_error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup evalerror ECMA EvalError object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in EvalError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_eval_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_EVAL, arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_eval_error_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in EvalError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_eval_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_eval_error_dispatch_call (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_eval_error_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.inc.h
vendored
Normal file
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* EvalError built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_EVAL_ERROR)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.11.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
400
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c
vendored
Normal file
400
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.c
vendored
Normal file
|
@ -0,0 +1,400 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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-builtin-helpers.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID function_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup functionprototype ECMA Function.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_function_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (!ecma_op_is_callable (this_arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_string_t *function_to_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__FUNCTION_TO_STRING);
|
||||
ret_value = ecma_make_string_value (function_to_string_p);
|
||||
}
|
||||
return ret_value;
|
||||
} /* ecma_builtin_function_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'apply' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_function_prototype_object_apply (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg1, /**< first argument */
|
||||
ecma_value_t arg2) /**< second argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 1. */
|
||||
if (!ecma_op_is_callable (this_arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *func_obj_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
/* 2. */
|
||||
if (ecma_is_value_null (arg2) || ecma_is_value_undefined (arg2))
|
||||
{
|
||||
ret_value = ecma_op_function_call (func_obj_p, arg1, NULL, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 3. */
|
||||
if (!ecma_is_value_object (arg2))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg2);
|
||||
ecma_string_t *length_magic_string_p = ecma_new_ecma_length_string ();
|
||||
|
||||
/* 4. */
|
||||
ECMA_TRY_CATCH (length_value,
|
||||
ecma_op_object_get (obj_p, length_magic_string_p),
|
||||
ret_value);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (length_number,
|
||||
length_value,
|
||||
ret_value);
|
||||
|
||||
/* 5. */
|
||||
const uint32_t length = ecma_number_to_uint32 (length_number);
|
||||
|
||||
/* 6. */
|
||||
JMEM_DEFINE_LOCAL_ARRAY (arguments_list_p, length, ecma_value_t);
|
||||
uint32_t last_index = 0;
|
||||
|
||||
/* 7. */
|
||||
for (uint32_t index = 0;
|
||||
index < length && ecma_is_value_empty (ret_value);
|
||||
index++)
|
||||
{
|
||||
ecma_string_t *curr_idx_str_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
|
||||
ECMA_TRY_CATCH (get_value,
|
||||
ecma_op_object_get (obj_p, curr_idx_str_p),
|
||||
ret_value);
|
||||
|
||||
arguments_list_p[index] = ecma_copy_value (get_value);
|
||||
last_index = index + 1;
|
||||
|
||||
ECMA_FINALIZE (get_value);
|
||||
ecma_deref_ecma_string (curr_idx_str_p);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
JERRY_ASSERT (last_index == length);
|
||||
ret_value = ecma_op_function_call (func_obj_p,
|
||||
arg1,
|
||||
arguments_list_p,
|
||||
length);
|
||||
}
|
||||
|
||||
for (uint32_t index = 0; index < last_index; index++)
|
||||
{
|
||||
ecma_free_value (arguments_list_p[index]);
|
||||
}
|
||||
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (arguments_list_p);
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (length_number);
|
||||
ECMA_FINALIZE (length_value);
|
||||
ecma_deref_ecma_string (length_magic_string_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_function_prototype_object_apply */
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'call' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_function_prototype_object_call (ecma_value_t this_arg, /**< this argument */
|
||||
const ecma_value_t *arguments_list_p, /**< list of arguments */
|
||||
ecma_length_t arguments_number) /**< number of arguments */
|
||||
{
|
||||
if (!ecma_op_is_callable (this_arg))
|
||||
{
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *func_obj_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
if (arguments_number == 0)
|
||||
{
|
||||
/* Even a 'this' argument is missing. */
|
||||
return ecma_op_function_call (func_obj_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_function_call (func_obj_p,
|
||||
arguments_list_p[0],
|
||||
arguments_list_p + 1,
|
||||
(ecma_length_t) (arguments_number - 1u));
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_function_prototype_object_call */
|
||||
|
||||
/**
|
||||
* The Function.prototype object's 'bind' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.4.5
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_function_prototype_object_bind (ecma_value_t this_arg, /**< this argument */
|
||||
const ecma_value_t *arguments_list_p, /**< list of arguments */
|
||||
ecma_length_t arguments_number) /**< number of arguments */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 2. */
|
||||
if (!ecma_op_is_callable (this_arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 4. 11. 18. */
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
|
||||
ecma_object_t *function_p = ecma_create_object (prototype_obj_p,
|
||||
false,
|
||||
true,
|
||||
ECMA_OBJECT_TYPE_BOUND_FUNCTION);
|
||||
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
|
||||
/* 7. */
|
||||
ecma_value_t *target_function_prop_p;
|
||||
target_function_prop_p = ecma_create_internal_property (function_p,
|
||||
ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_TARGET_FUNCTION);
|
||||
|
||||
ecma_object_t *this_arg_obj_p = ecma_get_object_from_value (this_arg);
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (*target_function_prop_p, this_arg_obj_p);
|
||||
|
||||
/* 8. */
|
||||
ecma_value_t *bound_this_prop_p;
|
||||
bound_this_prop_p = ecma_create_internal_property (function_p, ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_THIS);
|
||||
const ecma_length_t arg_count = arguments_number;
|
||||
|
||||
if (arg_count > 0)
|
||||
{
|
||||
*bound_this_prop_p = ecma_copy_value_if_not_object (arguments_list_p[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
*bound_this_prop_p = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
|
||||
if (arg_count > 1)
|
||||
{
|
||||
ecma_collection_header_t *bound_args_collection_p;
|
||||
bound_args_collection_p = ecma_new_values_collection (&arguments_list_p[1], arg_count - 1, false);
|
||||
|
||||
ecma_value_t *bound_args_prop_p;
|
||||
bound_args_prop_p = ecma_create_internal_property (function_p, ECMA_INTERNAL_PROPERTY_BOUND_FUNCTION_BOUND_ARGS);
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (*bound_args_prop_p, bound_args_collection_p);
|
||||
}
|
||||
|
||||
/*
|
||||
* [[Class]] property is not stored explicitly for objects of ECMA_OBJECT_TYPE_FUNCTION type.
|
||||
*
|
||||
* See also: ecma_object_get_class_name
|
||||
*/
|
||||
|
||||
/* 16. */
|
||||
ecma_number_t length = ECMA_NUMBER_ZERO;
|
||||
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
|
||||
|
||||
/* 15. */
|
||||
if (ecma_object_get_class_name (this_arg_obj_p) == LIT_MAGIC_STRING_FUNCTION_UL)
|
||||
{
|
||||
ecma_value_t get_len_value = ecma_op_object_get (this_arg_obj_p, magic_string_length_p);
|
||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (get_len_value));
|
||||
JERRY_ASSERT (ecma_is_value_number (get_len_value));
|
||||
|
||||
const ecma_length_t bound_arg_count = arg_count > 1 ? arg_count - 1 : 0;
|
||||
|
||||
/* 15.a */
|
||||
length = ecma_get_number_from_value (get_len_value) - ((ecma_number_t) bound_arg_count);
|
||||
ecma_free_value (get_len_value);
|
||||
|
||||
/* 15.b */
|
||||
if (ecma_number_is_negative (length))
|
||||
{
|
||||
length = ECMA_NUMBER_ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
/* 17. */
|
||||
ecma_value_t completion = ecma_builtin_helper_def_prop (function_p,
|
||||
magic_string_length_p,
|
||||
ecma_make_number_value (length),
|
||||
false, /* Writable */
|
||||
false, /* Enumerable */
|
||||
false, /* Configurable */
|
||||
false); /* Failure handling */
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (completion));
|
||||
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
|
||||
/* 19-21. */
|
||||
ecma_object_t *thrower_p = ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER);
|
||||
|
||||
ecma_property_descriptor_t 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 (LIT_MAGIC_STRING_CALLER);
|
||||
completion = ecma_op_object_define_own_property (function_p,
|
||||
magic_string_caller_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (completion));
|
||||
|
||||
ecma_deref_ecma_string (magic_string_caller_p);
|
||||
|
||||
ecma_string_t *magic_string_arguments_p = ecma_get_magic_string (LIT_MAGIC_STRING_ARGUMENTS);
|
||||
completion = ecma_op_object_define_own_property (function_p,
|
||||
magic_string_arguments_p,
|
||||
&prop_desc,
|
||||
false);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (completion));
|
||||
|
||||
ecma_deref_ecma_string (magic_string_arguments_p);
|
||||
ecma_deref_object (thrower_p);
|
||||
|
||||
/* 22. */
|
||||
ret_value = ecma_make_object_value (function_p);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_function_prototype_object_bind */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Function.prototype object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_function_prototype_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
} /* ecma_builtin_function_prototype_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Function.prototype object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_function_prototype_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
} /* ecma_builtin_function_prototype_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
67
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h
vendored
Normal file
67
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Function.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.3.4.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_FUNCTION,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.3.4
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_function_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_APPLY, ecma_builtin_function_prototype_object_apply, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_CALL, ecma_builtin_function_prototype_object_call, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_BIND, ecma_builtin_function_prototype_object_bind, NON_FIXED, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
213
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.c
vendored
Normal file
213
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.c
vendored
Normal file
|
@ -0,0 +1,213 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-eval.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-lex-env.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "lit-magic-strings.h"
|
||||
#include "js-parser.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID function
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup function ECMA Function object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Function object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_function_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_builtin_function_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_function_dispatch_call */
|
||||
|
||||
/**
|
||||
* Helper method to count and convert the arguments for the Function constructor call.
|
||||
*
|
||||
* Performs the operation described in ECMA 262 v5.1 15.3.2.1 steps 5.a-d
|
||||
*
|
||||
*
|
||||
* @return ecma value - concatenated arguments as a string.
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_function_helper_get_function_expression (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ecma_string_t *left_parenthesis_str_p, *right_parenthesis_str_p;
|
||||
ecma_string_t *left_brace_str_p, *right_brace_str_p;
|
||||
ecma_string_t *comma_str_p;
|
||||
ecma_string_t *function_kw_str_p, *empty_str_p;
|
||||
ecma_string_t *expr_str_p, *concated_str_p;
|
||||
|
||||
left_parenthesis_str_p = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING_LEFT_PARENTHESIS_CHAR);
|
||||
right_parenthesis_str_p = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING_RIGHT_PARENTHESIS_CHAR);
|
||||
|
||||
left_brace_str_p = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING_LEFT_BRACE_CHAR);
|
||||
right_brace_str_p = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING_RIGHT_BRACE_CHAR);
|
||||
|
||||
comma_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_COMMA_CHAR);
|
||||
|
||||
function_kw_str_p = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING_FUNCTION);
|
||||
empty_str_p = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING__EMPTY);
|
||||
|
||||
/* First, we only process the function arguments skipping the function body */
|
||||
ecma_length_t number_of_function_args = (arguments_list_len == 0 ? 0 : arguments_list_len - 1);
|
||||
|
||||
expr_str_p = ecma_concat_ecma_strings (left_parenthesis_str_p, function_kw_str_p);
|
||||
|
||||
concated_str_p = ecma_concat_ecma_strings (expr_str_p, left_parenthesis_str_p);
|
||||
ecma_deref_ecma_string (expr_str_p);
|
||||
expr_str_p = concated_str_p;
|
||||
|
||||
for (ecma_length_t idx = 0;
|
||||
idx < number_of_function_args && ecma_is_value_empty (ret_value);
|
||||
idx++)
|
||||
{
|
||||
ECMA_TRY_CATCH (str_arg_value,
|
||||
ecma_op_to_string (arguments_list_p[idx]),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *str_p = ecma_get_string_from_value (str_arg_value);
|
||||
|
||||
concated_str_p = ecma_concat_ecma_strings (expr_str_p, str_p);
|
||||
ecma_deref_ecma_string (expr_str_p);
|
||||
expr_str_p = concated_str_p;
|
||||
|
||||
if (idx < number_of_function_args - 1)
|
||||
{
|
||||
concated_str_p = ecma_concat_ecma_strings (expr_str_p, comma_str_p);
|
||||
ecma_deref_ecma_string (expr_str_p);
|
||||
expr_str_p = concated_str_p;
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (str_arg_value);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
concated_str_p = ecma_concat_ecma_strings (expr_str_p, right_parenthesis_str_p);
|
||||
ecma_deref_ecma_string (expr_str_p);
|
||||
expr_str_p = concated_str_p;
|
||||
|
||||
concated_str_p = ecma_concat_ecma_strings (expr_str_p, left_brace_str_p);
|
||||
ecma_deref_ecma_string (expr_str_p);
|
||||
expr_str_p = concated_str_p;
|
||||
|
||||
if (arguments_list_len != 0)
|
||||
{
|
||||
ECMA_TRY_CATCH (str_arg_value,
|
||||
ecma_op_to_string (arguments_list_p[arguments_list_len - 1]),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *body_str_p = ecma_get_string_from_value (str_arg_value);
|
||||
|
||||
concated_str_p = ecma_concat_ecma_strings (expr_str_p, body_str_p);
|
||||
ecma_deref_ecma_string (expr_str_p);
|
||||
expr_str_p = concated_str_p;
|
||||
|
||||
ECMA_FINALIZE (str_arg_value);
|
||||
}
|
||||
|
||||
concated_str_p = ecma_concat_ecma_strings (expr_str_p, right_brace_str_p);
|
||||
ecma_deref_ecma_string (expr_str_p);
|
||||
expr_str_p = concated_str_p;
|
||||
|
||||
concated_str_p = ecma_concat_ecma_strings (expr_str_p, right_parenthesis_str_p);
|
||||
ecma_deref_ecma_string (expr_str_p);
|
||||
expr_str_p = concated_str_p;
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (left_parenthesis_str_p);
|
||||
ecma_deref_ecma_string (right_parenthesis_str_p);
|
||||
ecma_deref_ecma_string (left_brace_str_p);
|
||||
ecma_deref_ecma_string (right_brace_str_p);
|
||||
ecma_deref_ecma_string (comma_str_p);
|
||||
ecma_deref_ecma_string (function_kw_str_p);
|
||||
ecma_deref_ecma_string (empty_str_p);
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_make_string_value (expr_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_deref_ecma_string (expr_str_p);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_function_helper_get_function_expression */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Function object
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.3.
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_TRY_CATCH (arguments_value,
|
||||
ecma_builtin_function_helper_get_function_expression (arguments_list_p,
|
||||
arguments_list_len),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *function_expression_p = ecma_get_string_from_value (arguments_value);
|
||||
|
||||
ret_value = ecma_op_eval (function_expression_p, false, false);
|
||||
|
||||
ECMA_FINALIZE (arguments_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_function_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.inc.h
vendored
Normal file
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-function.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Function built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_FUNCTION)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.3.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.3.3.2
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
1443
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.c
vendored
Normal file
1443
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
199
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h
vendored
Normal file
199
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h
vendored
Normal file
|
@ -0,0 +1,199 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Global built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef SIMPLE_VALUE
|
||||
# define SIMPLE_VALUE(name, simple_value, prop_attributes)
|
||||
#endif /* !SIMPLE_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_GLOBAL)
|
||||
|
||||
/* Simple value properties:
|
||||
* (property name, simple value, writable, enumerable, configurable) */
|
||||
|
||||
// ECMA-262 v5, 15.1.1.3
|
||||
SIMPLE_VALUE (LIT_MAGIC_STRING_UNDEFINED,
|
||||
ECMA_SIMPLE_VALUE_UNDEFINED,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// ECMA-262 v5, 15.1.1.1
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_NAN,
|
||||
ECMA_BUILTIN_NUMBER_NAN,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.1.1.2
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_INFINITY_UL,
|
||||
ECMA_BUILTIN_NUMBER_POSITIVE_INFINITY,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// ECMA-262 v5, 15.1.4.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_OBJECT_UL,
|
||||
ECMA_BUILTIN_ID_OBJECT,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.2
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_FUNCTION_UL,
|
||||
ECMA_BUILTIN_ID_FUNCTION,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.3
|
||||
#ifndef CONFIG_DISABLE_ARRAY_BUILTIN
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_ARRAY_UL,
|
||||
ECMA_BUILTIN_ID_ARRAY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_ARRAY_BUILTIN*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_STRING_BUILTIN
|
||||
// ECMA-262 v5, 15.1.4.4
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_STRING_UL,
|
||||
ECMA_BUILTIN_ID_STRING,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_STRING_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
|
||||
// ECMA-262 v5, 15.1.4.5
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_BOOLEAN_UL,
|
||||
ECMA_BUILTIN_ID_BOOLEAN,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_NUMBER_BUILTIN
|
||||
// ECMA-262 v5, 15.1.4.6
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_NUMBER_UL,
|
||||
ECMA_BUILTIN_ID_NUMBER,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_NUMBER_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_DATE_BUILTIN
|
||||
// ECMA-262 v5, 15.1.4.7
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_DATE_UL,
|
||||
ECMA_BUILTIN_ID_DATE,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_DATE_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
|
||||
// ECMA-262 v5, 15.1.4.8
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_REGEXP_UL,
|
||||
ECMA_BUILTIN_ID_REGEXP,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
|
||||
|
||||
// ECMA-262 v5, 15.1.4.9
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_ERROR_UL,
|
||||
ECMA_BUILTIN_ID_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
// ECMA-262 v5, 15.1.4.10
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_EVAL_ERROR_UL,
|
||||
ECMA_BUILTIN_ID_EVAL_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.11
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_RANGE_ERROR_UL,
|
||||
ECMA_BUILTIN_ID_RANGE_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.12
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_REFERENCE_ERROR_UL,
|
||||
ECMA_BUILTIN_ID_REFERENCE_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.13
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_SYNTAX_ERROR_UL,
|
||||
ECMA_BUILTIN_ID_SYNTAX_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.14
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_TYPE_ERROR_UL,
|
||||
ECMA_BUILTIN_ID_TYPE_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.15
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_URI_ERROR_UL,
|
||||
ECMA_BUILTIN_ID_URI_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
||||
|
||||
#ifndef CONFIG_DISABLE_MATH_BUILTIN
|
||||
// ECMA-262 v5, 15.1.5.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_MATH_UL,
|
||||
ECMA_BUILTIN_ID_MATH,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_MATH_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_JSON_BUILTIN
|
||||
// ECMA-262 v5, 15.1.5.2
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_JSON_U,
|
||||
ECMA_BUILTIN_ID_JSON,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
#endif /* !CONFIG_DISABLE_JSON_BUILTIN */
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
|
||||
// Implementation-defined 'print' routine
|
||||
#ifndef CONFIG_DISABLE_PRINT_BUILTIN
|
||||
ROUTINE (LIT_MAGIC_STRING_PRINT, ecma_builtin_global_object_print, NON_FIXED, 1)
|
||||
#endif
|
||||
|
||||
ROUTINE (LIT_MAGIC_STRING_EVAL, ecma_builtin_global_object_eval, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE_FLOAT, ecma_builtin_global_object_parse_float, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_NAN, ecma_builtin_global_object_is_nan, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_FINITE, ecma_builtin_global_object_is_finite, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_DECODE_URI, ecma_builtin_global_object_decode_uri, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_DECODE_URI_COMPONENT, ecma_builtin_global_object_decode_uri_component, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ENCODE_URI, ecma_builtin_global_object_encode_uri, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ENCODE_URI_COMPONENT, ecma_builtin_global_object_encode_uri_component, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE_INT, ecma_builtin_global_object_parse_int, 2, 2)
|
||||
|
||||
#ifndef CONFIG_DISABLE_ANNEXB_BUILTIN
|
||||
ROUTINE (LIT_MAGIC_STRING_ESCAPE, ecma_builtin_global_object_escape, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_UNESCAPE, ecma_builtin_global_object_unescape, 1, 1)
|
||||
#endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
1322
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c
vendored
Normal file
1322
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
78
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-error.c
vendored
Normal file
78
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-error.c
vendored
Normal file
|
@ -0,0 +1,78 @@
|
|||
/* Copyright 2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltinhelpers ECMA builtin helper operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of a built-in error object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t error_type, /**< native error type */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len != 0
|
||||
&& !ecma_is_value_undefined (arguments_list_p[0]))
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_TRY_CATCH (msg_str_value,
|
||||
ecma_op_to_string (arguments_list_p[0]),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value);
|
||||
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (error_type,
|
||||
message_string_p);
|
||||
ret_value = ecma_make_object_value (new_error_object_p);
|
||||
|
||||
ECMA_FINALIZE (msg_str_value);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *new_error_object_p = ecma_new_standard_error (error_type);
|
||||
|
||||
return ecma_make_object_value (new_error_object_p);
|
||||
}
|
||||
} /* ecma_builtin_helper_error_dispatch_call */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
310
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-json.c
vendored
Normal file
310
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-json.c
vendored
Normal file
|
@ -0,0 +1,310 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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-helpers.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "lit-char-helpers.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltinhelpers ECMA builtin helper operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check the object value existance in the collection.
|
||||
*
|
||||
* Used by:
|
||||
* - ecma_builtin_json_object step 1
|
||||
* - ecma_builtin_json_array step 1
|
||||
*
|
||||
* @return true, if the object is already in the collection.
|
||||
*/
|
||||
bool
|
||||
ecma_has_object_value_in_collection (ecma_collection_header_t *collection_p, /**< collection */
|
||||
ecma_value_t object_value) /**< object value */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_object (object_value));
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (object_value);
|
||||
|
||||
ecma_collection_iterator_t iterator;
|
||||
ecma_collection_iterator_init (&iterator, collection_p);
|
||||
|
||||
while (ecma_collection_iterator_next (&iterator))
|
||||
{
|
||||
ecma_value_t value = *iterator.current_value_p;
|
||||
ecma_object_t *current_p = ecma_get_object_from_value (value);
|
||||
|
||||
if (current_p == obj_p)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* ecma_has_object_value_in_collection */
|
||||
|
||||
/**
|
||||
* Check the string value existance in the collection.
|
||||
*
|
||||
* Used by:
|
||||
* - ecma_builtin_json_stringify step 4.b.ii.5
|
||||
*
|
||||
* @return true, if the string is already in the collection.
|
||||
*/
|
||||
bool
|
||||
ecma_has_string_value_in_collection (ecma_collection_header_t *collection_p, /**< collection */
|
||||
ecma_value_t string_value) /**< string value */
|
||||
{
|
||||
JERRY_ASSERT (ecma_is_value_string (string_value));
|
||||
|
||||
ecma_string_t *string_p = ecma_get_string_from_value (string_value);
|
||||
|
||||
ecma_collection_iterator_t iterator;
|
||||
ecma_collection_iterator_init (&iterator, collection_p);
|
||||
|
||||
while (ecma_collection_iterator_next (&iterator))
|
||||
{
|
||||
ecma_value_t value = *iterator.current_value_p;
|
||||
ecma_string_t *current_p = ecma_get_string_from_value (value);
|
||||
|
||||
if (ecma_compare_ecma_strings (current_p, string_p))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* ecma_has_string_value_in_collection*/
|
||||
|
||||
/**
|
||||
* Common function to concatenate key-value pairs into an ecma-string.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.12.3
|
||||
*
|
||||
* Used by:
|
||||
* - ecma_builtin_helper_json_create_formatted_json step 10.b.ii
|
||||
* - ecma_builtin_helper_json_create_non_formatted_json step 10.a.i
|
||||
*
|
||||
* @return pointer to ecma-string
|
||||
* Returned value must be freed with ecma_deref_ecma_string.
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_builtin_helper_json_create_separated_properties (ecma_collection_header_t *partial_p, /**< key-value pairs*/
|
||||
ecma_string_t *separator_p) /**< separator*/
|
||||
{
|
||||
ecma_string_t *properties_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
ecma_string_t *tmp_str_p;
|
||||
|
||||
ecma_collection_iterator_t iterator;
|
||||
ecma_collection_iterator_init (&iterator, partial_p);
|
||||
|
||||
uint32_t index = 0;
|
||||
|
||||
while (ecma_collection_iterator_next (&iterator))
|
||||
{
|
||||
ecma_value_t name_value = *iterator.current_value_p;
|
||||
ecma_string_t *current_p = ecma_get_string_from_value (name_value);
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
index++;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (properties_str_p, current_p);
|
||||
ecma_deref_ecma_string (properties_str_p);
|
||||
properties_str_p = tmp_str_p;
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (properties_str_p, separator_p);
|
||||
ecma_deref_ecma_string (properties_str_p);
|
||||
properties_str_p = tmp_str_p;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (properties_str_p, current_p);
|
||||
ecma_deref_ecma_string (properties_str_p);
|
||||
properties_str_p = tmp_str_p;
|
||||
}
|
||||
|
||||
return properties_str_p;
|
||||
} /* ecma_builtin_helper_json_create_separated_properties */
|
||||
|
||||
/**
|
||||
* Common function to create a formatted JSON string.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.12.3
|
||||
*
|
||||
* Used by:
|
||||
* - ecma_builtin_json_object step 10.b
|
||||
* - ecma_builtin_json_array step 10.b
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_json_create_formatted_json (ecma_string_t *left_bracket_p, /**< left bracket*/
|
||||
ecma_string_t *right_bracket_p, /**< right bracket*/
|
||||
ecma_string_t *stepback_p, /**< stepback*/
|
||||
ecma_collection_header_t *partial_p, /**< key-value pairs*/
|
||||
ecma_json_stringify_context_t *context_p) /**< context*/
|
||||
{
|
||||
/* 10.b */
|
||||
ecma_string_t *comma_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_COMMA_CHAR);
|
||||
ecma_string_t *line_feed_p = ecma_get_magic_string (LIT_MAGIC_STRING_NEW_LINE_CHAR);
|
||||
ecma_string_t *properties_str_p;
|
||||
ecma_string_t *separator_p;
|
||||
|
||||
/* 10.b.i */
|
||||
ecma_string_t *tmp_str_p = ecma_concat_ecma_strings (comma_str_p, line_feed_p);
|
||||
ecma_deref_ecma_string (comma_str_p);
|
||||
separator_p = tmp_str_p;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (separator_p, context_p->indent_str_p);
|
||||
ecma_deref_ecma_string (separator_p);
|
||||
separator_p = tmp_str_p;
|
||||
|
||||
/* 10.b.ii */
|
||||
properties_str_p = ecma_builtin_helper_json_create_separated_properties (partial_p, separator_p);
|
||||
ecma_deref_ecma_string (separator_p);
|
||||
|
||||
/* 10.b.iii */
|
||||
ecma_string_t *final_str_p;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (left_bracket_p, line_feed_p);
|
||||
final_str_p = tmp_str_p;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (final_str_p, context_p->indent_str_p);
|
||||
ecma_deref_ecma_string (final_str_p);
|
||||
final_str_p = tmp_str_p;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (final_str_p, properties_str_p);
|
||||
ecma_deref_ecma_string (final_str_p);
|
||||
ecma_deref_ecma_string (properties_str_p);
|
||||
final_str_p = tmp_str_p;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (final_str_p, line_feed_p);
|
||||
ecma_deref_ecma_string (line_feed_p);
|
||||
ecma_deref_ecma_string (final_str_p);
|
||||
final_str_p = tmp_str_p;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (final_str_p, stepback_p);
|
||||
ecma_deref_ecma_string (final_str_p);
|
||||
final_str_p = tmp_str_p;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (final_str_p, right_bracket_p);
|
||||
ecma_deref_ecma_string (final_str_p);
|
||||
final_str_p = tmp_str_p;
|
||||
|
||||
return ecma_make_string_value (final_str_p);
|
||||
} /* ecma_builtin_helper_json_create_formatted_json */
|
||||
|
||||
/**
|
||||
* Common function to create a non-formatted JSON string.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.12.3
|
||||
*
|
||||
* Used by:
|
||||
* - ecma_builtin_json_object step 10.a
|
||||
* - ecma_builtin_json_array step 10.a
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_json_create_non_formatted_json (ecma_string_t *left_bracket_p, /**< left bracket*/
|
||||
ecma_string_t *right_bracket_p, /**< right bracket*/
|
||||
ecma_collection_header_t *partial_p) /**< key-value pairs*/
|
||||
{
|
||||
/* 10.a */
|
||||
ecma_string_t *comma_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_COMMA_CHAR);
|
||||
ecma_string_t *properties_str_p;
|
||||
ecma_string_t *tmp_str_p;
|
||||
|
||||
/* 10.a.i */
|
||||
properties_str_p = ecma_builtin_helper_json_create_separated_properties (partial_p, comma_str_p);
|
||||
ecma_deref_ecma_string (comma_str_p);
|
||||
|
||||
/* 10.a.ii */
|
||||
tmp_str_p = ecma_concat_ecma_strings (left_bracket_p, properties_str_p);
|
||||
ecma_deref_ecma_string (properties_str_p);
|
||||
properties_str_p = tmp_str_p;
|
||||
|
||||
tmp_str_p = ecma_concat_ecma_strings (properties_str_p, right_bracket_p);
|
||||
ecma_deref_ecma_string (properties_str_p);
|
||||
properties_str_p = tmp_str_p;
|
||||
|
||||
return ecma_make_string_value (properties_str_p);
|
||||
} /* ecma_builtin_helper_json_create_non_formatted_json */
|
||||
|
||||
/**
|
||||
* Convert decimal value to 4 digit hexadecimal string value.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.12.3
|
||||
*
|
||||
* Used by:
|
||||
* - ecma_builtin_json_quote step 2.c.iii
|
||||
*
|
||||
* @return pointer to ecma-string
|
||||
* Returned value must be freed with ecma_deref_ecma_string.
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_builtin_helper_json_create_hex_digit_ecma_string (uint8_t value) /**< value in decimal*/
|
||||
{
|
||||
/* 2.c.iii */
|
||||
ecma_string_t *hex_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
|
||||
JMEM_DEFINE_LOCAL_ARRAY (hex_buff, 4, lit_utf8_byte_t);
|
||||
|
||||
for (uint32_t i = 0; i < 4; i++)
|
||||
{
|
||||
uint8_t remainder = value % 16;
|
||||
lit_utf8_byte_t ch = ' ';
|
||||
|
||||
if (remainder < 10)
|
||||
{
|
||||
ch = (lit_utf8_byte_t) (LIT_CHAR_0 + remainder);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t a = (uint8_t) (remainder - 10);
|
||||
ch = (lit_utf8_byte_t) (LIT_CHAR_LOWERCASE_A + a);
|
||||
}
|
||||
|
||||
hex_buff[3 - i] = ch;
|
||||
|
||||
value = value / 16;
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (hex_str_p);
|
||||
hex_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) hex_buff, 4);
|
||||
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (hex_buff);
|
||||
|
||||
JERRY_ASSERT (ecma_string_get_length (hex_str_p));
|
||||
|
||||
return hex_str_p;
|
||||
} /* ecma_builtin_helper_json_create_hex_digit_ecma_string */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
700
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c
vendored
Normal file
700
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c
vendored
Normal file
|
@ -0,0 +1,700 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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-builtin-helpers.h"
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-array-object.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-function-object.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "lit-magic-strings.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltinhelpers ECMA builtin helper operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Common implementation of the Object.prototype.toString routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.2
|
||||
*
|
||||
* Used by:
|
||||
* - The Object.prototype.toString routine.
|
||||
* - The Array.prototype.toString routine as fallback.
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_object_to_string (const ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
lit_magic_string_id_t type_string;
|
||||
|
||||
if (ecma_is_value_undefined (this_arg))
|
||||
{
|
||||
type_string = LIT_MAGIC_STRING_UNDEFINED_UL;
|
||||
}
|
||||
else if (ecma_is_value_null (this_arg))
|
||||
{
|
||||
type_string = LIT_MAGIC_STRING_NULL_UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_value_t obj_this = ecma_op_to_object (this_arg);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (obj_this))
|
||||
{
|
||||
return obj_this;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_object (obj_this));
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
|
||||
|
||||
type_string = ecma_object_get_class_name (obj_p);
|
||||
|
||||
ecma_free_value (obj_this);
|
||||
}
|
||||
|
||||
ecma_string_t *ret_string_p;
|
||||
|
||||
/* Building string "[object #type#]" where type is 'Undefined',
|
||||
'Null' or one of possible object's classes.
|
||||
The string with null character is maximum 19 characters long. */
|
||||
const lit_utf8_size_t buffer_size = 19;
|
||||
JMEM_DEFINE_LOCAL_ARRAY (str_buffer, buffer_size, lit_utf8_byte_t);
|
||||
|
||||
lit_utf8_byte_t *buffer_ptr = str_buffer;
|
||||
|
||||
const lit_magic_string_id_t magic_string_ids[] =
|
||||
{
|
||||
LIT_MAGIC_STRING_LEFT_SQUARE_CHAR,
|
||||
LIT_MAGIC_STRING_OBJECT,
|
||||
LIT_MAGIC_STRING_SPACE_CHAR,
|
||||
type_string,
|
||||
LIT_MAGIC_STRING_RIGHT_SQUARE_CHAR
|
||||
};
|
||||
|
||||
for (uint32_t i = 0; i < sizeof (magic_string_ids) / sizeof (lit_magic_string_id_t); ++i)
|
||||
{
|
||||
buffer_ptr = lit_copy_magic_string_to_buffer (magic_string_ids[i], buffer_ptr,
|
||||
(lit_utf8_size_t) ((str_buffer + buffer_size) - buffer_ptr));
|
||||
JERRY_ASSERT (buffer_ptr <= str_buffer + buffer_size);
|
||||
}
|
||||
|
||||
ret_string_p = ecma_new_ecma_string_from_utf8 (str_buffer, (lit_utf8_size_t) (buffer_ptr - str_buffer));
|
||||
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (str_buffer);
|
||||
|
||||
return ecma_make_string_value (ret_string_p);
|
||||
} /* ecma_builtin_helper_object_to_string */
|
||||
|
||||
/**
|
||||
* The Array.prototype's 'toLocaleString' single element operation routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.4.4.3 steps 6-8 and 10.b-d
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /**< this object */
|
||||
uint32_t index) /**< array index */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
|
||||
ECMA_TRY_CATCH (index_value,
|
||||
ecma_op_object_get (obj_p, index_string_p),
|
||||
ret_value);
|
||||
|
||||
if (ecma_is_value_undefined (index_value) || ecma_is_value_null (index_value))
|
||||
{
|
||||
ecma_string_t *return_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
ret_value = ecma_make_string_value (return_string_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_TRY_CATCH (index_obj_value,
|
||||
ecma_op_to_object (index_value),
|
||||
ret_value);
|
||||
|
||||
ecma_object_t *index_obj_p = ecma_get_object_from_value (index_obj_value);
|
||||
ecma_string_t *locale_string_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL);
|
||||
|
||||
ECMA_TRY_CATCH (to_locale_value,
|
||||
ecma_op_object_get (index_obj_p, locale_string_magic_string_p),
|
||||
ret_value);
|
||||
|
||||
if (ecma_op_is_callable (to_locale_value))
|
||||
{
|
||||
ecma_object_t *locale_func_obj_p = ecma_get_object_from_value (to_locale_value);
|
||||
ECMA_TRY_CATCH (call_value,
|
||||
ecma_op_function_call (locale_func_obj_p,
|
||||
ecma_make_object_value (index_obj_p),
|
||||
NULL,
|
||||
0),
|
||||
ret_value);
|
||||
ret_value = ecma_op_to_string (call_value);
|
||||
ECMA_FINALIZE (call_value);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (to_locale_value);
|
||||
|
||||
ecma_deref_ecma_string (locale_string_magic_string_p);
|
||||
|
||||
ECMA_FINALIZE (index_obj_value);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (index_value);
|
||||
|
||||
ecma_deref_ecma_string (index_string_p);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_helper_get_to_locale_string_at_index */
|
||||
|
||||
|
||||
/**
|
||||
* The Object.keys and Object.getOwnPropertyNames routine's common part.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.4 steps 2-5
|
||||
* ECMA-262 v5, 15.2.3.14 steps 3-6
|
||||
*
|
||||
* @return ecma value - Array of property names.
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_object_get_properties (ecma_object_t *obj_p, /**< object */
|
||||
bool only_enumerable_properties) /**< list enumerable properties? */
|
||||
{
|
||||
JERRY_ASSERT (obj_p != NULL);
|
||||
|
||||
ecma_value_t new_array = ecma_op_create_array_object (NULL, 0, false);
|
||||
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (new_array));
|
||||
ecma_object_t *new_array_p = ecma_get_object_from_value (new_array);
|
||||
|
||||
uint32_t index = 0;
|
||||
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p,
|
||||
false,
|
||||
only_enumerable_properties,
|
||||
false);
|
||||
|
||||
ecma_collection_iterator_t iter;
|
||||
ecma_collection_iterator_init (&iter, props_p);
|
||||
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
{
|
||||
ecma_string_t *index_string_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
|
||||
ecma_value_t completion = ecma_builtin_helper_def_prop (new_array_p,
|
||||
index_string_p,
|
||||
*iter.current_value_p,
|
||||
true, /* Writable */
|
||||
true, /* Enumerable */
|
||||
true, /* Configurable */
|
||||
false); /* Failure handling */
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (completion));
|
||||
|
||||
ecma_deref_ecma_string (index_string_p);
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, true);
|
||||
|
||||
return new_array;
|
||||
} /* ecma_builtin_helper_object_get_properties */
|
||||
|
||||
/**
|
||||
* Helper function to normalizing an array index
|
||||
*
|
||||
* This function clamps the given index to the [0, length] range.
|
||||
* If the index is negative, it is used as the offset from the end of the array,
|
||||
* to compute normalized index.
|
||||
* If the index is greater than the length of the array, the normalized index will be the length of the array.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.4.4.10 steps 5-6, 7 (part 2) and 8
|
||||
* ECMA-262 v5, 15.4.4.12 steps 5-6
|
||||
* ECMA-262 v5, 15.4.4.14 steps 5
|
||||
* ECMA-262 v5, 15.5.4.13 steps 4, 5 (part 2) and 6-7
|
||||
*
|
||||
* Used by:
|
||||
* - The Array.prototype.slice routine.
|
||||
* - The Array.prototype.splice routine.
|
||||
* - The Array.prototype.indexOf routine.
|
||||
* - The String.prototype.slice routine.
|
||||
*
|
||||
* @return uint32_t - the normalized value of the index
|
||||
*/
|
||||
uint32_t
|
||||
ecma_builtin_helper_array_index_normalize (ecma_number_t index, /**< index */
|
||||
uint32_t length) /**< array's length */
|
||||
{
|
||||
uint32_t norm_index;
|
||||
|
||||
if (!ecma_number_is_nan (index))
|
||||
{
|
||||
|
||||
if (ecma_number_is_zero (index))
|
||||
{
|
||||
norm_index = 0;
|
||||
}
|
||||
else if (ecma_number_is_infinity (index))
|
||||
{
|
||||
norm_index = ecma_number_is_negative (index) ? 0 : length;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ecma_number_is_negative (index))
|
||||
{
|
||||
ecma_number_t index_neg = ecma_number_negate (index);
|
||||
|
||||
if (index_neg > length)
|
||||
{
|
||||
norm_index = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
norm_index = length - ecma_number_to_uint32 (index_neg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index > length)
|
||||
{
|
||||
norm_index = length;
|
||||
}
|
||||
else
|
||||
{
|
||||
norm_index = ecma_number_to_uint32 (index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
norm_index = 0;
|
||||
}
|
||||
|
||||
return norm_index;
|
||||
} /* ecma_builtin_helper_array_index_normalize */
|
||||
|
||||
/**
|
||||
* Helper function for concatenating an ecma_value_t to an Array.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.4.4.4 steps 5.b - 5.c
|
||||
*
|
||||
* Used by:
|
||||
* - The Array.prototype.concat routine.
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_array_concat_value (ecma_object_t *obj_p, /**< array */
|
||||
uint32_t *length_p, /**< [in,out] array's length */
|
||||
ecma_value_t value) /**< value to concat */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 5.b */
|
||||
if (ecma_is_value_object (value)
|
||||
&& (ecma_object_get_class_name (ecma_get_object_from_value (value)) == LIT_MAGIC_STRING_ARRAY_UL))
|
||||
{
|
||||
ecma_string_t *magic_string_length_p = ecma_new_ecma_length_string ();
|
||||
/* 5.b.ii */
|
||||
ECMA_TRY_CATCH (arg_len_value,
|
||||
ecma_op_object_get (ecma_get_object_from_value (value),
|
||||
magic_string_length_p),
|
||||
ret_value);
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_len_number, arg_len_value, ret_value);
|
||||
|
||||
uint32_t arg_len = ecma_number_to_uint32 (arg_len_number);
|
||||
|
||||
/* 5.b.iii */
|
||||
for (uint32_t array_index = 0;
|
||||
array_index < arg_len && ecma_is_value_empty (ret_value);
|
||||
array_index++)
|
||||
{
|
||||
ecma_string_t *array_index_string_p = ecma_new_ecma_string_from_uint32 (array_index);
|
||||
|
||||
/* 5.b.iii.2 */
|
||||
ECMA_TRY_CATCH (get_value,
|
||||
ecma_op_object_find (ecma_get_object_from_value (value),
|
||||
array_index_string_p),
|
||||
ret_value);
|
||||
|
||||
if (ecma_is_value_found (get_value))
|
||||
{
|
||||
/* 5.b.iii.3.a */
|
||||
ecma_string_t *new_array_index_string_p = ecma_new_ecma_string_from_uint32 (*length_p + array_index);
|
||||
|
||||
/* 5.b.iii.3.b */
|
||||
/* This will always be a simple value since 'is_throw' is false, so no need to free. */
|
||||
ecma_value_t put_comp = ecma_builtin_helper_def_prop (obj_p,
|
||||
new_array_index_string_p,
|
||||
get_value,
|
||||
true, /* Writable */
|
||||
true, /* Enumerable */
|
||||
true, /* Configurable */
|
||||
false); /* Failure handling */
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (put_comp));
|
||||
ecma_deref_ecma_string (new_array_index_string_p);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (get_value);
|
||||
|
||||
ecma_deref_ecma_string (array_index_string_p);
|
||||
}
|
||||
|
||||
*length_p += arg_len;
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_len_number);
|
||||
ECMA_FINALIZE (arg_len_value);
|
||||
ecma_deref_ecma_string (magic_string_length_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_string_t *new_array_index_string_p = ecma_new_ecma_string_from_uint32 ((*length_p)++);
|
||||
|
||||
/* 5.c.i */
|
||||
/* This will always be a simple value since 'is_throw' is false, so no need to free. */
|
||||
ecma_value_t put_comp = ecma_builtin_helper_def_prop (obj_p,
|
||||
new_array_index_string_p,
|
||||
value,
|
||||
true, /* Writable */
|
||||
true, /* Enumerable */
|
||||
true, /* Configurable */
|
||||
false); /* Failure handling */
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_true (put_comp));
|
||||
|
||||
ecma_deref_ecma_string (new_array_index_string_p);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_helper_array_concat_value */
|
||||
|
||||
/**
|
||||
* Helper function to normalizing a string index
|
||||
*
|
||||
* This function clamps the given index to the [0, length] range.
|
||||
* If the index is negative, 0 value is used.
|
||||
* If the index is greater than the length of the string, the normalized index will be the length of the string.
|
||||
* NaN is mapped to zero or length depending on the nan_to_zero parameter.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.5.4.15
|
||||
*
|
||||
* Used by:
|
||||
* - The String.prototype.substring routine.
|
||||
* - The ecma_builtin_helper_string_prototype_object_index_of helper routine.
|
||||
*
|
||||
* @return uint32_t - the normalized value of the index
|
||||
*/
|
||||
uint32_t
|
||||
ecma_builtin_helper_string_index_normalize (ecma_number_t index, /**< index */
|
||||
uint32_t length, /**< string's length */
|
||||
bool nan_to_zero) /**< whether NaN is mapped to zero (t) or length (f) */
|
||||
{
|
||||
uint32_t norm_index = 0;
|
||||
|
||||
if (ecma_number_is_nan (index))
|
||||
{
|
||||
if (!nan_to_zero)
|
||||
{
|
||||
norm_index = length;
|
||||
}
|
||||
}
|
||||
else if (!ecma_number_is_negative (index))
|
||||
{
|
||||
if (ecma_number_is_infinity (index))
|
||||
{
|
||||
norm_index = length;
|
||||
}
|
||||
else
|
||||
{
|
||||
norm_index = ecma_number_to_uint32 (index);
|
||||
|
||||
if (norm_index > length)
|
||||
{
|
||||
norm_index = length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return norm_index;
|
||||
} /* ecma_builtin_helper_string_index_normalize */
|
||||
|
||||
/**
|
||||
* Helper function for string indexOf and lastIndexOf functions
|
||||
*
|
||||
* This function implements string indexOf and lastIndexOf with required checks and conversions.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.5.4.7
|
||||
* ECMA-262 v5, 15.5.4.8
|
||||
*
|
||||
* Used by:
|
||||
* - The String.prototype.indexOf routine.
|
||||
* - The String.prototype.lastIndexOf routine.
|
||||
*
|
||||
* @return uint32_t - (last) index of search string
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2, /**< routine's second argument */
|
||||
bool first_index) /**< routine's third argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 1 */
|
||||
ECMA_TRY_CATCH (check_coercible_val,
|
||||
ecma_op_check_object_coercible (this_arg),
|
||||
ret_value);
|
||||
|
||||
/* 2 */
|
||||
ECMA_TRY_CATCH (to_str_val,
|
||||
ecma_op_to_string (this_arg),
|
||||
ret_value);
|
||||
|
||||
/* 3 */
|
||||
ECMA_TRY_CATCH (search_str_val,
|
||||
ecma_op_to_string (arg1),
|
||||
ret_value);
|
||||
|
||||
/* 4 */
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (pos_num,
|
||||
arg2,
|
||||
ret_value);
|
||||
|
||||
/* 5 (indexOf) -- 6 (lastIndexOf) */
|
||||
ecma_string_t *original_str_p = ecma_get_string_from_value (to_str_val);
|
||||
const ecma_length_t original_len = ecma_string_get_length (original_str_p);
|
||||
|
||||
/* 4b, 6 (indexOf) - 4b, 5, 7 (lastIndexOf) */
|
||||
ecma_length_t start = ecma_builtin_helper_string_index_normalize (pos_num, original_len, first_index);
|
||||
|
||||
/* 7 (indexOf) -- 8 (lastIndexOf) */
|
||||
ecma_string_t *search_str_p = ecma_get_string_from_value (search_str_val);
|
||||
|
||||
ecma_number_t ret_num = ECMA_NUMBER_MINUS_ONE;
|
||||
|
||||
/* 8 (indexOf) -- 9 (lastIndexOf) */
|
||||
ecma_length_t index_of = 0;
|
||||
if (ecma_builtin_helper_string_find_index (original_str_p, search_str_p, first_index, start, &index_of))
|
||||
{
|
||||
ret_num = ((ecma_number_t) index_of);
|
||||
}
|
||||
|
||||
ret_value = ecma_make_number_value (ret_num);
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (pos_num);
|
||||
ECMA_FINALIZE (search_str_val);
|
||||
ECMA_FINALIZE (to_str_val);
|
||||
ECMA_FINALIZE (check_coercible_val);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_helper_string_prototype_object_index_of */
|
||||
|
||||
/**
|
||||
* Helper function for finding index of a search string
|
||||
*
|
||||
* This function clamps the given index to the [0, length] range.
|
||||
* If the index is negative, 0 value is used.
|
||||
* If the index is greater than the length of the string, the normalized index will be the length of the string.
|
||||
* NaN is mapped to zero or length depending on the nan_to_zero parameter.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.5.4.7,8,11
|
||||
*
|
||||
* Used by:
|
||||
* - The ecma_builtin_helper_string_prototype_object_index_of helper routine.
|
||||
* - The ecma_builtin_string_prototype_object_replace_match helper routine.
|
||||
*
|
||||
* @return uint32_t - the normalized value of the index
|
||||
*/
|
||||
bool
|
||||
ecma_builtin_helper_string_find_index (ecma_string_t *original_str_p, /**< index */
|
||||
ecma_string_t *search_str_p, /**< string's length */
|
||||
bool first_index, /**< whether search for first (t) or last (f) index */
|
||||
ecma_length_t start_pos, /**< start position */
|
||||
ecma_length_t *ret_index_p) /**< position found in original string */
|
||||
{
|
||||
bool match_found = false;
|
||||
const ecma_length_t original_len = ecma_string_get_length (original_str_p);
|
||||
const ecma_length_t search_len = ecma_string_get_length (search_str_p);
|
||||
|
||||
if (search_len <= original_len)
|
||||
{
|
||||
if (!search_len)
|
||||
{
|
||||
match_found = true;
|
||||
*ret_index_p = first_index ? 0 : original_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* create utf8 string from original string and advance to position */
|
||||
ECMA_STRING_TO_UTF8_STRING (original_str_p, original_str_utf8_p, original_str_size);
|
||||
|
||||
ecma_length_t index = start_pos;
|
||||
|
||||
const lit_utf8_byte_t *original_str_curr_p = original_str_utf8_p;
|
||||
for (ecma_length_t idx = 0; idx < index; idx++)
|
||||
{
|
||||
lit_utf8_incr (&original_str_curr_p);
|
||||
}
|
||||
|
||||
/* create utf8 string from search string */
|
||||
ECMA_STRING_TO_UTF8_STRING (search_str_p, search_str_utf8_p, search_str_size);
|
||||
|
||||
const lit_utf8_byte_t *search_str_curr_p = search_str_utf8_p;
|
||||
|
||||
/* iterate original string and try to match at each position */
|
||||
bool searching = true;
|
||||
ecma_char_t first_char = lit_utf8_read_next (&search_str_curr_p);
|
||||
while (searching)
|
||||
{
|
||||
/* match as long as possible */
|
||||
ecma_length_t match_len = 0;
|
||||
const lit_utf8_byte_t *stored_original_str_curr_p = original_str_curr_p;
|
||||
|
||||
if (match_len < search_len &&
|
||||
index + match_len < original_len &&
|
||||
lit_utf8_read_next (&original_str_curr_p) == first_char)
|
||||
{
|
||||
const lit_utf8_byte_t *nested_search_str_curr_p = search_str_curr_p;
|
||||
match_len++;
|
||||
|
||||
while (match_len < search_len &&
|
||||
index + match_len < original_len &&
|
||||
lit_utf8_read_next (&original_str_curr_p) == lit_utf8_read_next (&nested_search_str_curr_p))
|
||||
{
|
||||
match_len++;
|
||||
}
|
||||
}
|
||||
|
||||
/* check for match */
|
||||
if (match_len == search_len)
|
||||
{
|
||||
match_found = true;
|
||||
*ret_index_p = index;
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* inc/dec index and update iterators and search condition */
|
||||
original_str_curr_p = stored_original_str_curr_p;
|
||||
|
||||
if (first_index)
|
||||
{
|
||||
if ((searching = (index <= original_len - search_len)))
|
||||
{
|
||||
lit_utf8_incr (&original_str_curr_p);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((searching = (index > 0)))
|
||||
{
|
||||
lit_utf8_decr (&original_str_curr_p);
|
||||
index--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_FINALIZE_UTF8_STRING (search_str_utf8_p, search_str_size);
|
||||
ECMA_FINALIZE_UTF8_STRING (original_str_utf8_p, original_str_size);
|
||||
}
|
||||
}
|
||||
|
||||
return match_found;
|
||||
} /* ecma_builtin_helper_string_find_index */
|
||||
|
||||
/**
|
||||
* Helper function for using [[DefineOwnProperty]].
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 8.12.9
|
||||
* ECMA-262 v5, 15.4.5.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_helper_def_prop (ecma_object_t *obj_p, /**< object */
|
||||
ecma_string_t *index_p, /**< index string */
|
||||
ecma_value_t value, /**< value */
|
||||
bool writable, /**< writable */
|
||||
bool enumerable, /**< enumerable */
|
||||
bool configurable, /**< configurable */
|
||||
bool is_throw) /**< is_throw */
|
||||
{
|
||||
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
|
||||
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.value = value;
|
||||
|
||||
prop_desc.is_writable_defined = true;
|
||||
prop_desc.is_writable = writable;
|
||||
|
||||
prop_desc.is_enumerable_defined = true;
|
||||
prop_desc.is_enumerable = enumerable;
|
||||
|
||||
prop_desc.is_configurable_defined = true;
|
||||
prop_desc.is_configurable = configurable;
|
||||
|
||||
return ecma_op_object_define_own_property (obj_p,
|
||||
index_p,
|
||||
&prop_desc,
|
||||
is_throw);
|
||||
} /* ecma_builtin_helper_def_prop */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
179
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h
vendored
Normal file
179
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h
vendored
Normal file
|
@ -0,0 +1,179 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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_BUILTIN_HELPERS_H
|
||||
#define ECMA_BUILTIN_HELPERS_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-exceptions.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltinhelpers ECMA builtin helper operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern ecma_value_t
|
||||
ecma_builtin_helper_object_to_string (const ecma_value_t);
|
||||
extern ecma_value_t
|
||||
ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *, uint32_t);
|
||||
extern ecma_value_t
|
||||
ecma_builtin_helper_object_get_properties (ecma_object_t *, bool);
|
||||
extern ecma_value_t
|
||||
ecma_builtin_helper_array_concat_value (ecma_object_t *, uint32_t *, ecma_value_t);
|
||||
extern uint32_t
|
||||
ecma_builtin_helper_array_index_normalize (ecma_number_t, uint32_t);
|
||||
extern uint32_t
|
||||
ecma_builtin_helper_string_index_normalize (ecma_number_t, uint32_t, bool);
|
||||
extern ecma_value_t
|
||||
ecma_builtin_helper_string_prototype_object_index_of (ecma_value_t, ecma_value_t,
|
||||
ecma_value_t, bool);
|
||||
extern bool
|
||||
ecma_builtin_helper_string_find_index (ecma_string_t *, ecma_string_t *, bool, ecma_length_t, ecma_length_t *);
|
||||
extern ecma_value_t
|
||||
ecma_builtin_helper_def_prop (ecma_object_t *, ecma_string_t *, ecma_value_t,
|
||||
bool, bool, bool, bool);
|
||||
|
||||
#ifndef CONFIG_DISABLE_DATE_BUILTIN
|
||||
|
||||
/**
|
||||
* Time range defines for helper functions.
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.9.1.1, 15.9.1.10
|
||||
*/
|
||||
|
||||
/** Hours in a day. */
|
||||
#define ECMA_DATE_HOURS_PER_DAY ((ecma_number_t) 24)
|
||||
|
||||
/** Minutes in an hour. */
|
||||
#define ECMA_DATE_MINUTES_PER_HOUR ((ecma_number_t) 60)
|
||||
|
||||
/** Seconds in a minute. */
|
||||
#define ECMA_DATE_SECONDS_PER_MINUTE ((ecma_number_t) 60)
|
||||
|
||||
/** Milliseconds in a second. */
|
||||
#define ECMA_DATE_MS_PER_SECOND ((ecma_number_t) 1000)
|
||||
|
||||
/** ECMA_DATE_MS_PER_MINUTE == 60000 */
|
||||
#define ECMA_DATE_MS_PER_MINUTE (ECMA_DATE_MS_PER_SECOND * ECMA_DATE_SECONDS_PER_MINUTE)
|
||||
|
||||
/** ECMA_DATE_MS_PER_HOUR == 3600000 */
|
||||
#define ECMA_DATE_MS_PER_HOUR (ECMA_DATE_MS_PER_MINUTE * ECMA_DATE_MINUTES_PER_HOUR)
|
||||
|
||||
/** ECMA_DATE_MS_PER_DAY == 86400000 */
|
||||
#define ECMA_DATE_MS_PER_DAY (ECMA_DATE_MS_PER_HOUR * ECMA_DATE_HOURS_PER_DAY)
|
||||
|
||||
/**
|
||||
* This gives a range of 8,640,000,000,000,000 milliseconds
|
||||
* to either side of 01 January, 1970 UTC.
|
||||
*/
|
||||
#define ECMA_DATE_MAX_VALUE 8.64e15
|
||||
|
||||
/**
|
||||
* Timezone type.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_DATE_UTC, /**< date vaule is in UTC */
|
||||
ECMA_DATE_LOCAL /**< date vaule is in local time */
|
||||
} ecma_date_timezone_t;
|
||||
|
||||
/* ecma-builtin-helpers-date.c */
|
||||
extern ecma_number_t ecma_date_day (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_time_within_day (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_days_in_year (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_day_from_year (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_time_from_year (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_year_from_time (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_in_leap_year (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_day_within_year (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_month_from_time (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_date_from_time (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_week_day (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_local_tza ();
|
||||
extern ecma_number_t ecma_date_daylight_saving_ta (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_local_time (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_utc (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_hour_from_time (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_min_from_time (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_sec_from_time (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_ms_from_time (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_make_time (ecma_number_t, ecma_number_t, ecma_number_t, ecma_number_t);
|
||||
extern ecma_number_t ecma_date_make_day (ecma_number_t, ecma_number_t, ecma_number_t);
|
||||
extern ecma_number_t ecma_date_make_date (ecma_number_t, ecma_number_t);
|
||||
extern ecma_number_t ecma_date_time_clip (ecma_number_t);
|
||||
extern ecma_number_t ecma_date_timezone_offset (ecma_number_t);
|
||||
extern ecma_value_t ecma_date_set_internal_property (ecma_value_t, ecma_number_t,
|
||||
ecma_number_t, ecma_date_timezone_t);
|
||||
|
||||
extern ecma_value_t ecma_date_value_to_string (ecma_number_t);
|
||||
extern ecma_value_t ecma_date_value_to_utc_string (ecma_number_t);
|
||||
extern ecma_value_t ecma_date_value_to_iso_string (ecma_number_t);
|
||||
extern ecma_value_t ecma_date_value_to_date_string (ecma_number_t);
|
||||
extern ecma_value_t ecma_date_value_to_time_string (ecma_number_t);
|
||||
extern ecma_value_t ecma_date_get_primitive_value (ecma_value_t);
|
||||
|
||||
#endif /* !CONFIG_DISABLE_DATE_BUILTIN */
|
||||
|
||||
/* ecma-builtin-helper-json.c */
|
||||
|
||||
/**
|
||||
* Context for JSON.stringify()
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** Collection for property keys. */
|
||||
ecma_collection_header_t *property_list_p;
|
||||
|
||||
/** Collection for traversing objects. */
|
||||
ecma_collection_header_t *occurence_stack_p;
|
||||
|
||||
/** The actual indentation text. */
|
||||
ecma_string_t *indent_str_p;
|
||||
|
||||
/** The indentation text. */
|
||||
ecma_string_t *gap_str_p;
|
||||
|
||||
/** The replacer function. */
|
||||
ecma_object_t *replacer_function_p;
|
||||
} ecma_json_stringify_context_t;
|
||||
|
||||
extern bool ecma_has_object_value_in_collection (ecma_collection_header_t *, ecma_value_t);
|
||||
extern bool ecma_has_string_value_in_collection (ecma_collection_header_t *, ecma_value_t);
|
||||
|
||||
extern ecma_string_t *
|
||||
ecma_builtin_helper_json_create_hex_digit_ecma_string (uint8_t);
|
||||
extern ecma_string_t *
|
||||
ecma_builtin_helper_json_create_separated_properties (ecma_collection_header_t *, ecma_string_t *);
|
||||
extern ecma_value_t
|
||||
ecma_builtin_helper_json_create_formatted_json (ecma_string_t *, ecma_string_t *, ecma_string_t *,
|
||||
ecma_collection_header_t *, ecma_json_stringify_context_t *);
|
||||
extern ecma_value_t
|
||||
ecma_builtin_helper_json_create_non_formatted_json (ecma_string_t *, ecma_string_t *, ecma_collection_header_t *);
|
||||
|
||||
/* ecma-builtin-helper-error.c */
|
||||
|
||||
extern ecma_value_t
|
||||
ecma_builtin_helper_error_dispatch_call (ecma_standard_error_t, const ecma_value_t *, ecma_length_t);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !ECMA_BUILTIN_HELPERS_H */
|
|
@ -0,0 +1,167 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BUILTIN_UNDERSCORED_ID
|
||||
# error "Please, define BUILTIN_UNDERSCORED_ID"
|
||||
#endif /* !BUILTIN_UNDERSCORED_ID */
|
||||
|
||||
#ifndef BUILTIN_INC_HEADER_NAME
|
||||
# error "Please, define BUILTIN_INC_HEADER_NAME"
|
||||
#endif /* !BUILTIN_INC_HEADER_NAME */
|
||||
|
||||
#include "ecma-objects.h"
|
||||
|
||||
#define PASTE__(x, y) x ## y
|
||||
#define PASTE_(x, y) PASTE__ (x, y)
|
||||
#define PASTE(x, y) PASTE_ (x, y)
|
||||
|
||||
#define PROPERTY_DESCRIPTOR_LIST_NAME \
|
||||
PASTE (PASTE (ecma_builtin_, BUILTIN_UNDERSCORED_ID), _property_descriptor_list)
|
||||
#define DISPATCH_ROUTINE_ROUTINE_NAME \
|
||||
PASTE (PASTE (ecma_builtin_, BUILTIN_UNDERSCORED_ID), _dispatch_routine)
|
||||
|
||||
#define ROUTINE_ARG(n) , ecma_value_t arg ## n
|
||||
#define ROUTINE_ARG_LIST_0 ecma_value_t this_arg
|
||||
#define ROUTINE_ARG_LIST_1 ROUTINE_ARG_LIST_0 ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1 ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2 ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED ROUTINE_ARG_LIST_0, \
|
||||
const ecma_value_t *arguments_list_p, ecma_length_t arguments_list_len
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
|
||||
static ecma_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number);
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG
|
||||
|
||||
enum
|
||||
{
|
||||
PASTE (ECMA_ROUTINE_START_, BUILTIN_UNDERSCORED_ID) = ECMA_BUILTIN_ID__COUNT - 1,
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
|
||||
ECMA_ROUTINE_ ## name ## c_function_name,
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
};
|
||||
|
||||
/**
|
||||
* Built-in property list of the built-in object.
|
||||
*/
|
||||
const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] =
|
||||
{
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
|
||||
{ \
|
||||
name, \
|
||||
ECMA_BUILTIN_PROPERTY_ROUTINE, \
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE, \
|
||||
ECMA_ROUTINE_VALUE (ECMA_ROUTINE_ ## name ## c_function_name, length_prop_value) \
|
||||
},
|
||||
#define OBJECT_VALUE(name, obj_builtin_id, prop_attributes) \
|
||||
{ \
|
||||
name, \
|
||||
ECMA_BUILTIN_PROPERTY_OBJECT, \
|
||||
prop_attributes, \
|
||||
obj_builtin_id \
|
||||
},
|
||||
#define SIMPLE_VALUE(name, simple_value, prop_attributes) \
|
||||
{ \
|
||||
name, \
|
||||
ECMA_BUILTIN_PROPERTY_SIMPLE, \
|
||||
prop_attributes, \
|
||||
simple_value \
|
||||
},
|
||||
#define NUMBER_VALUE(name, number_value, prop_attributes) \
|
||||
{ \
|
||||
name, \
|
||||
ECMA_BUILTIN_PROPERTY_NUMBER, \
|
||||
prop_attributes, \
|
||||
number_value \
|
||||
},
|
||||
#define STRING_VALUE(name, magic_string_id, prop_attributes) \
|
||||
{ \
|
||||
name, \
|
||||
ECMA_BUILTIN_PROPERTY_STRING, \
|
||||
prop_attributes, \
|
||||
magic_string_id \
|
||||
},
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
{
|
||||
LIT_MAGIC_STRING__COUNT,
|
||||
ECMA_BUILTIN_PROPERTY_END,
|
||||
0,
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispatcher of the built-in's routines
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
DISPATCH_ROUTINE_ROUTINE_NAME (uint16_t builtin_routine_id, /**< built-in wide routine
|
||||
identifier */
|
||||
ecma_value_t this_arg_value, /**< 'this' argument
|
||||
value */
|
||||
const ecma_value_t arguments_list[], /**< list of arguments
|
||||
passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of
|
||||
arguments' list */
|
||||
{
|
||||
/* the arguments may be unused for some built-ins */
|
||||
JERRY_UNUSED (this_arg_value);
|
||||
JERRY_UNUSED (arguments_list);
|
||||
JERRY_UNUSED (arguments_number);
|
||||
|
||||
switch (builtin_routine_id)
|
||||
{
|
||||
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] \
|
||||
: ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED))
|
||||
#define ROUTINE_ARG_LIST_0
|
||||
#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG(1)
|
||||
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
|
||||
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
|
||||
#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number
|
||||
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
|
||||
case ECMA_ROUTINE_ ## name ## c_function_name: \
|
||||
{ \
|
||||
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
|
||||
}
|
||||
#include BUILTIN_INC_HEADER_NAME
|
||||
#undef ROUTINE_ARG
|
||||
#undef ROUTINE_ARG_LIST_0
|
||||
#undef ROUTINE_ARG_LIST_1
|
||||
#undef ROUTINE_ARG_LIST_2
|
||||
#undef ROUTINE_ARG_LIST_3
|
||||
#undef ROUTINE_ARG_LIST_NON_FIXED
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* DISPATCH_ROUTINE_ROUTINE_NAME */
|
||||
|
||||
#undef PASTE__
|
||||
#undef PASTE_
|
||||
#undef PASTE
|
||||
#undef PROPERTY_DESCRIPTOR_LIST_NAME
|
||||
#undef DISPATCH_ROUTINE_ROUTINE_NAME
|
||||
#undef BUILTIN_UNDERSCORED_ID
|
||||
#undef BUILTIN_INC_HEADER_NAME
|
||||
#undef ECMA_BUILTIN_PROPERTY_NAME_INDEX
|
1746
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-json.c
vendored
Normal file
1746
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-json.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
54
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-json.inc.h
vendored
Normal file
54
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-json.inc.h
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* JSON built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef SIMPLE_VALUE
|
||||
# define SIMPLE_VALUE(name, simple_value, prop_attributes)
|
||||
#endif /* !SIMPLE_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_JSON)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_PARSE, ecma_builtin_json_parse, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_STRINGIFY, ecma_builtin_json_stringify, 3, 3)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
667
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.c
vendored
Normal file
667
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.c
vendored
Normal file
|
@ -0,0 +1,667 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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 <math.h>
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-number-arithmetic.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_MATH_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-math.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID math
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup object ECMA Object object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Math object's 'abs' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.1
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_abs (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (fabs (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_abs */
|
||||
|
||||
/**
|
||||
* The Math object's 'acos' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_acos (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (acos (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_acos */
|
||||
|
||||
/**
|
||||
* The Math object's 'asin' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_asin (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (asin (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_asin */
|
||||
|
||||
/**
|
||||
* The Math object's 'atan' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_atan (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (atan (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_atan */
|
||||
|
||||
/**
|
||||
* The Math object's 'atan2' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.5
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_atan2 (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< first routine's argument */
|
||||
ecma_value_t arg2) /**< second routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (x, arg1, ret_value);
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (y, arg2, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (atan2 (x, y)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (y);
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (x);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_atan2 */
|
||||
|
||||
/**
|
||||
* The Math object's 'ceil' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.6
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_ceil (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (ceil (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_ceil */
|
||||
|
||||
/**
|
||||
* The Math object's 'cos' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.7
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_cos (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (cos (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_cos */
|
||||
|
||||
/**
|
||||
* The Math object's 'exp' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.8
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_exp (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (exp (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_exp */
|
||||
|
||||
/**
|
||||
* The Math object's 'floor' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.9
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_floor (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (floor (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_floor */
|
||||
|
||||
/**
|
||||
* The Math object's 'log' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.10
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_log (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (log (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_log */
|
||||
|
||||
/**
|
||||
* The Math object's 'max' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.11
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_max (ecma_value_t this_arg, /**< 'this' argument */
|
||||
const ecma_value_t args[], /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ecma_number_t ret_num = ecma_number_make_infinity (true);
|
||||
|
||||
bool is_NaN = false;
|
||||
|
||||
for (ecma_length_t arg_index = 0;
|
||||
arg_index < args_number && ecma_is_value_empty (ret_value);
|
||||
arg_index++)
|
||||
{
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
|
||||
|
||||
if (!is_NaN)
|
||||
{
|
||||
if (unlikely (ecma_number_is_nan (arg_num)))
|
||||
{
|
||||
ret_num = arg_num;
|
||||
is_NaN = true;
|
||||
}
|
||||
else if (ecma_number_is_zero (arg_num) /* both numbers are zeroes */
|
||||
&& ecma_number_is_zero (ret_num))
|
||||
{
|
||||
if (!ecma_number_is_negative (arg_num))
|
||||
{
|
||||
ret_num = arg_num;
|
||||
}
|
||||
}
|
||||
else if (ecma_number_is_infinity (arg_num))
|
||||
{
|
||||
if (!ecma_number_is_negative (arg_num))
|
||||
{
|
||||
ret_num = arg_num;
|
||||
}
|
||||
}
|
||||
else if (ecma_number_is_infinity (ret_num))
|
||||
{
|
||||
if (ecma_number_is_negative (ret_num))
|
||||
{
|
||||
ret_num = arg_num;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (!ecma_number_is_nan (arg_num)
|
||||
&& !ecma_number_is_infinity (arg_num));
|
||||
JERRY_ASSERT (!ecma_number_is_nan (ret_num)
|
||||
&& !ecma_number_is_infinity (ret_num));
|
||||
|
||||
if (arg_num > ret_num)
|
||||
{
|
||||
ret_num = arg_num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_make_number_value (ret_num);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_max */
|
||||
|
||||
/**
|
||||
* The Math object's 'min' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.12
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_min (ecma_value_t this_arg, /**< 'this' argument */
|
||||
const ecma_value_t args[], /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ecma_number_t ret_num = ecma_number_make_infinity (false);
|
||||
|
||||
bool is_NaN = false;
|
||||
|
||||
for (ecma_length_t arg_index = 0;
|
||||
arg_index < args_number && ecma_is_value_empty (ret_value);
|
||||
arg_index++)
|
||||
{
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
|
||||
|
||||
if (!is_NaN)
|
||||
{
|
||||
if (unlikely (ecma_number_is_nan (arg_num)))
|
||||
{
|
||||
ret_num = arg_num;
|
||||
is_NaN = true;
|
||||
}
|
||||
else if (ecma_number_is_zero (arg_num) /* both numbers are zeroes */
|
||||
&& ecma_number_is_zero (ret_num))
|
||||
{
|
||||
if (ecma_number_is_negative (arg_num))
|
||||
{
|
||||
ret_num = arg_num;
|
||||
}
|
||||
}
|
||||
else if (ecma_number_is_infinity (arg_num))
|
||||
{
|
||||
if (ecma_number_is_negative (arg_num))
|
||||
{
|
||||
ret_num = arg_num;
|
||||
}
|
||||
}
|
||||
else if (ecma_number_is_infinity (ret_num))
|
||||
{
|
||||
if (!ecma_number_is_negative (ret_num))
|
||||
{
|
||||
ret_num = arg_num;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (!ecma_number_is_nan (arg_num)
|
||||
&& !ecma_number_is_infinity (arg_num));
|
||||
JERRY_ASSERT (!ecma_number_is_nan (ret_num)
|
||||
&& !ecma_number_is_infinity (ret_num));
|
||||
|
||||
if (arg_num < ret_num)
|
||||
{
|
||||
ret_num = arg_num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_make_number_value (ret_num);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_min */
|
||||
|
||||
/**
|
||||
* The Math object's 'pow' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.13
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_pow (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< first routine's argument */
|
||||
ecma_value_t arg2) /**< second routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (x, arg1, ret_value);
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (y, arg2, ret_value);
|
||||
|
||||
if (ecma_number_is_nan (y) ||
|
||||
(ecma_number_is_infinity (y) && (x == 1.0 || x == -1.0)))
|
||||
{
|
||||
/* Handle differences between ES5.1 and ISO C standards for pow. */
|
||||
ret_value = ecma_make_number_value (ecma_number_make_nan ());
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (pow (x, y)));
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (y);
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (x);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_pow */
|
||||
|
||||
/**
|
||||
* The Math object's 'random' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.14
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_random (ecma_value_t this_arg) /**< 'this' argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
uint32_t rnd = 1;
|
||||
uint32_t reps_count;
|
||||
#if RAND_MAX < 0x100
|
||||
reps_count = 4;
|
||||
#elif RAND_MAX < 0x10000
|
||||
reps_count = 2;
|
||||
#else /* RAND_MAX >= 0x10000 */
|
||||
reps_count = 1;
|
||||
#endif /* RAND_MAX < 0x100 */
|
||||
|
||||
for (uint32_t i = 0; i < reps_count; i++)
|
||||
{
|
||||
uint32_t next_rand = (uint32_t) rand ();
|
||||
rnd *= next_rand;
|
||||
}
|
||||
|
||||
const uint32_t max_uint32 = (uint32_t) -1;
|
||||
ecma_number_t rand = (ecma_number_t) rnd;
|
||||
rand /= (ecma_number_t) max_uint32;
|
||||
rand *= (ecma_number_t) (max_uint32 - 1) / (ecma_number_t) max_uint32;
|
||||
|
||||
return ecma_make_number_value (rand);
|
||||
} /* ecma_builtin_math_object_random */
|
||||
|
||||
/**
|
||||
* The Math object's 'round' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.15
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_round (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ecma_number_t num = ECMA_NUMBER_ZERO;
|
||||
|
||||
if (ecma_number_is_nan (arg_num)
|
||||
|| ecma_number_is_zero (arg_num)
|
||||
|| ecma_number_is_infinity (arg_num))
|
||||
{
|
||||
num = arg_num;
|
||||
}
|
||||
else if (ecma_number_is_negative (arg_num)
|
||||
&& arg_num >= -ECMA_NUMBER_HALF)
|
||||
{
|
||||
num = ecma_number_negate (ECMA_NUMBER_ZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
const ecma_number_t up_half = arg_num + ECMA_NUMBER_HALF;
|
||||
const ecma_number_t down_half = arg_num - ECMA_NUMBER_HALF;
|
||||
const ecma_number_t up_rounded = up_half - ecma_op_number_remainder (up_half, ECMA_NUMBER_ONE);
|
||||
const ecma_number_t down_rounded = down_half - ecma_op_number_remainder (down_half, ECMA_NUMBER_ONE);
|
||||
|
||||
if (up_rounded - arg_num <= arg_num - down_rounded)
|
||||
{
|
||||
num = up_rounded;
|
||||
}
|
||||
else
|
||||
{
|
||||
num = down_rounded;
|
||||
}
|
||||
}
|
||||
|
||||
ret_value = ecma_make_number_value (num);
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_round */
|
||||
|
||||
/**
|
||||
* The Math object's 'sin' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.16
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_sin (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (sin (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_sin */
|
||||
|
||||
/**
|
||||
* The Math object's 'sqrt' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.17
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_sqrt (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (sqrt (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_sqrt */
|
||||
|
||||
/**
|
||||
* The Math object's 'tan' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.8.2.18
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_math_object_tan (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
ret_value = ecma_make_number_value (DOUBLE_TO_ECMA_NUMBER_T (tan (arg_num)));
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_math_object_tan */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_MATH_BUILTIN */
|
112
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.inc.h
vendored
Normal file
112
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-math.inc.h
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Math built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef SIMPLE_VALUE
|
||||
# define SIMPLE_VALUE(name, simple_value, prop_attributes)
|
||||
#endif /* !SIMPLE_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_MATH)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// ECMA-262 v5, 15.8.1.1
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_E_U,
|
||||
ECMA_BUILTIN_NUMBER_E,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.2
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LN10_U,
|
||||
ECMA_BUILTIN_NUMBER_LN10,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LN2_U,
|
||||
ECMA_BUILTIN_NUMBER_LN2,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.4
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LOG2E_U,
|
||||
ECMA_BUILTIN_NUMBER_LOG2E,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.5
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LOG10E_U,
|
||||
ECMA_BUILTIN_NUMBER_LOG10E,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.6
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_PI_U,
|
||||
ECMA_BUILTIN_NUMBER_PI,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.7
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_SQRT1_2_U,
|
||||
ECMA_BUILTIN_NUMBER_SQRT_1_2,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.8.1.8
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_SQRT2_U,
|
||||
ECMA_BUILTIN_NUMBER_SQRT2,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_ABS, ecma_builtin_math_object_abs, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ACOS, ecma_builtin_math_object_acos, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ASIN, ecma_builtin_math_object_asin, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ATAN, ecma_builtin_math_object_atan, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_ATAN2, ecma_builtin_math_object_atan2, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_CEIL, ecma_builtin_math_object_ceil, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_COS, ecma_builtin_math_object_cos, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_EXP, ecma_builtin_math_object_exp, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_FLOOR, ecma_builtin_math_object_floor, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_LOG, ecma_builtin_math_object_log, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_MAX, ecma_builtin_math_object_max, NON_FIXED, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_MIN, ecma_builtin_math_object_min, NON_FIXED, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_POW, ecma_builtin_math_object_pow, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_RANDOM, ecma_builtin_math_object_random, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_ROUND, ecma_builtin_math_object_round, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SIN, ecma_builtin_math_object_sin, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SQRT, ecma_builtin_math_object_sqrt, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_TAN, ecma_builtin_math_object_tan, 1, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
933
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.c
vendored
Normal file
933
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.c
vendored
Normal file
|
@ -0,0 +1,933 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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 <math.h>
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_NUMBER_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-number-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID number_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup numberprototype ECMA Number.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper for stringifying numbers
|
||||
*
|
||||
* @return the length of the generated string representation
|
||||
*/
|
||||
static lit_utf8_size_t
|
||||
ecma_builtin_number_prototype_helper_to_string (lit_utf8_byte_t *digits_p, /**< number as string in decimal form */
|
||||
lit_utf8_size_t num_digits, /**< length of the string representation */
|
||||
int32_t exponent, /**< decimal exponent */
|
||||
lit_utf8_byte_t *to_digits_p, /**< [out] buffer to write */
|
||||
lit_utf8_size_t to_num_digits) /**< requested number of digits */
|
||||
{
|
||||
lit_utf8_byte_t *p = to_digits_p;
|
||||
|
||||
if (exponent <= 0)
|
||||
{
|
||||
/* Add zero to the integer part. */
|
||||
*p++ = '0';
|
||||
to_num_digits--;
|
||||
|
||||
if (to_num_digits > 0)
|
||||
{
|
||||
*p++ = '.';
|
||||
|
||||
/* Add leading zeros to the fraction part. */
|
||||
for (int i = 0; i < -exponent && to_num_digits > 0; i++)
|
||||
{
|
||||
*p++ = '0';
|
||||
to_num_digits--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add significant digits of the integer part. */
|
||||
lit_utf8_size_t to_copy = JERRY_MIN (num_digits, to_num_digits);
|
||||
to_copy = JERRY_MIN (to_copy, (lit_utf8_size_t) exponent);
|
||||
memmove (p, digits_p, (size_t) to_copy);
|
||||
p += to_copy;
|
||||
to_num_digits -= to_copy;
|
||||
digits_p += to_copy;
|
||||
num_digits -= to_copy;
|
||||
exponent -= (int32_t) to_copy;
|
||||
|
||||
/* Add zeros before decimal point. */
|
||||
while (exponent > 0 && to_num_digits > 0)
|
||||
{
|
||||
JERRY_ASSERT (num_digits == 0);
|
||||
*p++ = '0';
|
||||
to_num_digits--;
|
||||
exponent--;
|
||||
}
|
||||
|
||||
if (to_num_digits > 0)
|
||||
{
|
||||
*p++ = '.';
|
||||
}
|
||||
}
|
||||
|
||||
if (to_num_digits > 0)
|
||||
{
|
||||
/* Add significant digits of the fraction part. */
|
||||
lit_utf8_size_t to_copy = JERRY_MIN (num_digits, to_num_digits);
|
||||
memmove (p, digits_p, (size_t) to_copy);
|
||||
p += to_copy;
|
||||
to_num_digits -= to_copy;
|
||||
|
||||
/* Add trailing zeros. */
|
||||
while (to_num_digits > 0)
|
||||
{
|
||||
*p++ = '0';
|
||||
to_num_digits--;
|
||||
}
|
||||
}
|
||||
|
||||
return (lit_utf8_size_t) (p - to_digits_p);
|
||||
} /* ecma_builtin_number_prototype_helper_to_string */
|
||||
|
||||
/**
|
||||
* Helper for rounding numbers
|
||||
*
|
||||
* @return rounded number
|
||||
*/
|
||||
static inline lit_utf8_size_t __attr_always_inline___
|
||||
ecma_builtin_number_prototype_helper_round (lit_utf8_byte_t *digits_p, /**< [in,out] number as a string in decimal
|
||||
* form */
|
||||
lit_utf8_size_t num_digits, /**< length of the string representation */
|
||||
int32_t round_num, /**< number of digits to keep */
|
||||
int32_t *exponent_p) /**< [in, out] decimal exponent */
|
||||
{
|
||||
if (round_num < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((lit_utf8_size_t) round_num >= num_digits)
|
||||
{
|
||||
return num_digits;
|
||||
}
|
||||
|
||||
if (digits_p[round_num] >= '5')
|
||||
{
|
||||
digits_p[round_num] = '0';
|
||||
|
||||
int i = 1;
|
||||
|
||||
/* Handle curry number. */
|
||||
for (; i < (int) num_digits; i++)
|
||||
{
|
||||
if (++digits_p[round_num - i] <= '9')
|
||||
{
|
||||
break;
|
||||
}
|
||||
digits_p[round_num - i] = '0';
|
||||
}
|
||||
|
||||
/* Prepend highest digit */
|
||||
if (i >= (int) num_digits)
|
||||
{
|
||||
memmove (digits_p + 1, digits_p, num_digits);
|
||||
digits_p[0] = '1';
|
||||
*exponent_p += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return (lit_utf8_size_t) round_num;
|
||||
} /* ecma_builtin_number_prototype_helper_round */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_number_prototype_object_to_string (ecma_value_t this_arg, /**< this argument */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_TRY_CATCH (this_value, ecma_builtin_number_prototype_object_value_of (this_arg), ret_value);
|
||||
ecma_number_t this_arg_number = ecma_get_number_from_value (this_value);
|
||||
|
||||
if (arguments_list_len == 0
|
||||
|| ecma_number_is_nan (this_arg_number)
|
||||
|| ecma_number_is_infinity (this_arg_number)
|
||||
|| ecma_number_is_zero (this_arg_number)
|
||||
|| (arguments_list_len > 0 && ecma_is_value_undefined (arguments_list_p[0])))
|
||||
{
|
||||
ecma_string_t *ret_str_p = ecma_new_ecma_string_from_number (this_arg_number);
|
||||
|
||||
ret_value = ecma_make_string_value (ret_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
static const lit_utf8_byte_t digit_chars[36] =
|
||||
{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
||||
'u', 'v', 'w', 'x', 'y', 'z'
|
||||
};
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arguments_list_p[0], ret_value);
|
||||
|
||||
uint32_t radix = ecma_number_to_uint32 (arg_num);
|
||||
|
||||
if (radix < 2 || radix > 36)
|
||||
{
|
||||
ret_value = ecma_raise_range_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else if (radix == 10)
|
||||
{
|
||||
ecma_string_t *ret_str_p = ecma_new_ecma_string_from_number (this_arg_number);
|
||||
|
||||
ret_value = ecma_make_string_value (ret_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool is_negative = false;
|
||||
if (ecma_number_is_negative (this_arg_number))
|
||||
{
|
||||
this_arg_number = -this_arg_number;
|
||||
is_negative = true;
|
||||
}
|
||||
|
||||
lit_utf8_byte_t digits[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
int32_t exponent;
|
||||
lit_utf8_size_t num_digits = ecma_number_to_decimal (this_arg_number, digits, &exponent);
|
||||
|
||||
exponent = exponent - (int32_t) num_digits;
|
||||
|
||||
/* Calculate the scale of the number in the specified radix. */
|
||||
int scale = (int) -floor ((log (10) / log (radix)) * exponent);
|
||||
|
||||
bool is_scale_negative = false;
|
||||
if (scale < 0)
|
||||
{
|
||||
is_scale_negative = true;
|
||||
scale = -scale;
|
||||
}
|
||||
|
||||
int buff_size;
|
||||
if (is_scale_negative)
|
||||
{
|
||||
buff_size = (int) floor (log (this_arg_number) / log (radix)) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
buff_size = scale + ECMA_NUMBER_FRACTION_WIDTH + 2;
|
||||
}
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
buff_size++;
|
||||
}
|
||||
|
||||
/* Normalize the number, so that it is as close to 0 exponent as possible. */
|
||||
if (is_scale_negative)
|
||||
{
|
||||
for (int i = 0; i < scale; i++)
|
||||
{
|
||||
this_arg_number /= (ecma_number_t) radix;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < scale; i++)
|
||||
{
|
||||
this_arg_number *= (ecma_number_t) radix;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t whole = (uint64_t) this_arg_number;
|
||||
ecma_number_t fraction = this_arg_number - (ecma_number_t) whole;
|
||||
|
||||
bool should_round = false;
|
||||
if (!ecma_number_is_zero (fraction) && is_scale_negative)
|
||||
{
|
||||
/* Add one extra digit for rounding. */
|
||||
buff_size++;
|
||||
should_round = true;
|
||||
}
|
||||
|
||||
JMEM_DEFINE_LOCAL_ARRAY (buff, buff_size, lit_utf8_byte_t);
|
||||
int buff_index = 0;
|
||||
|
||||
/* Calculate digits for whole part. */
|
||||
while (whole > 0)
|
||||
{
|
||||
buff[buff_index++] = (lit_utf8_byte_t) (whole % radix);
|
||||
whole /= radix;
|
||||
}
|
||||
|
||||
/* Calculate where we have to put the radix point. */
|
||||
int point = is_scale_negative ? buff_index + scale : buff_index - scale;
|
||||
|
||||
/* Reverse the digits, since they are backwards. */
|
||||
for (int i = 0; i < buff_index / 2; i++)
|
||||
{
|
||||
lit_utf8_byte_t swap = buff[i];
|
||||
buff[i] = buff[buff_index - i - 1];
|
||||
buff[buff_index - i - 1] = swap;
|
||||
}
|
||||
|
||||
int required_digits = buff_size;
|
||||
if (is_negative)
|
||||
{
|
||||
required_digits--;
|
||||
}
|
||||
|
||||
if (!is_scale_negative)
|
||||
{
|
||||
/* Leave space for leading zeros / radix point. */
|
||||
required_digits -= scale + 1;
|
||||
}
|
||||
|
||||
/* Calculate digits for fractional part. */
|
||||
while (buff_index < required_digits && (fraction != 0 || is_scale_negative))
|
||||
{
|
||||
fraction *= (ecma_number_t) radix;
|
||||
lit_utf8_byte_t digit = (lit_utf8_byte_t) floor (fraction);
|
||||
|
||||
buff[buff_index++] = digit;
|
||||
fraction -= (ecma_number_t) floor (fraction);
|
||||
}
|
||||
|
||||
if (should_round)
|
||||
{
|
||||
/* Round off last digit. */
|
||||
if (buff[buff_index - 1] > radix / 2)
|
||||
{
|
||||
buff[buff_index - 2]++;
|
||||
}
|
||||
|
||||
buff_index--;
|
||||
|
||||
/* Propagate carry. */
|
||||
for (int i = buff_index - 1; i > 0 && buff[i] >= radix; i--)
|
||||
{
|
||||
buff[i] = (lit_utf8_byte_t) (buff[i] - radix);
|
||||
buff[i - 1]++;
|
||||
}
|
||||
|
||||
/* Carry propagated over the whole number, need to add a leading digit. */
|
||||
if (buff[0] >= radix)
|
||||
{
|
||||
memmove (buff + 1, buff, (size_t) buff_index);
|
||||
buff_index++;
|
||||
buff[0] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove trailing zeros from fraction. */
|
||||
while (buff_index - 1 > point && buff[buff_index - 1] == 0)
|
||||
{
|
||||
buff_index--;
|
||||
}
|
||||
|
||||
/* Add leading zeros in case place of radix point is negative. */
|
||||
if (point <= 0)
|
||||
{
|
||||
memmove (buff - point + 1, buff, (size_t) buff_index);
|
||||
buff_index += -point + 1;
|
||||
|
||||
for (int i = 0; i < -point + 1; i++)
|
||||
{
|
||||
buff[i] = 0;
|
||||
}
|
||||
|
||||
point = 1;
|
||||
}
|
||||
|
||||
/* Convert digits to characters. */
|
||||
for (int i = 0; i < buff_index; i++)
|
||||
{
|
||||
buff[i] = digit_chars[buff[i]];
|
||||
}
|
||||
|
||||
/* Place radix point to the required position. */
|
||||
if (point < buff_index)
|
||||
{
|
||||
memmove (buff + point + 1, buff + point, (size_t) buff_index);
|
||||
buff[point] = '.';
|
||||
buff_index++;
|
||||
}
|
||||
|
||||
/* Add negative sign if necessary. */
|
||||
if (is_negative)
|
||||
{
|
||||
memmove (buff + 1, buff, (size_t) buff_index);
|
||||
buff_index++;
|
||||
buff[0] = '-';
|
||||
}
|
||||
|
||||
JERRY_ASSERT (buff_index <= buff_size);
|
||||
ecma_string_t *str_p = ecma_new_ecma_string_from_utf8 (buff, (lit_utf8_size_t) buff_index);
|
||||
ret_value = ecma_make_string_value (str_p);
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (buff);
|
||||
}
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
}
|
||||
ECMA_FINALIZE (this_value);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_number_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toLocaleString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_number_prototype_object_to_locale_string (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
return ecma_builtin_number_prototype_object_to_string (this_arg, NULL, 0);
|
||||
} /* ecma_builtin_number_prototype_object_to_locale_string */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'valueOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_number_prototype_object_value_of (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
if (ecma_is_value_number (this_arg))
|
||||
{
|
||||
return ecma_copy_value (this_arg);
|
||||
}
|
||||
else if (ecma_is_value_object (this_arg))
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_NUMBER_UL)
|
||||
{
|
||||
ecma_value_t *prim_value_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_number (*prim_value_p));
|
||||
|
||||
return ecma_copy_value (*prim_value_p);
|
||||
}
|
||||
}
|
||||
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
} /* ecma_builtin_number_prototype_object_value_of */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toFixed' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.5
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_TRY_CATCH (this_value, ecma_builtin_number_prototype_object_value_of (this_arg), ret_value);
|
||||
ecma_number_t this_num = ecma_get_number_from_value (this_value);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
/* 2. */
|
||||
if (arg_num <= -1 || arg_num >= 21)
|
||||
{
|
||||
ret_value = ecma_raise_range_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 4. */
|
||||
if (ecma_number_is_nan (this_num))
|
||||
{
|
||||
ecma_string_t *nan_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_NAN);
|
||||
ret_value = ecma_make_string_value (nan_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 6. */
|
||||
bool is_negative = false;
|
||||
if (ecma_number_is_negative (this_num))
|
||||
{
|
||||
is_negative = true;
|
||||
this_num *= -1;
|
||||
}
|
||||
|
||||
/* We handle infinities separately. */
|
||||
if (ecma_number_is_infinity (this_num))
|
||||
{
|
||||
ecma_string_t *infinity_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
ecma_string_t *neg_str_p = ecma_new_ecma_string_from_utf8 ((const lit_utf8_byte_t *) "-", 1);
|
||||
ecma_string_t *neg_inf_str_p = ecma_concat_ecma_strings (neg_str_p, infinity_str_p);
|
||||
ecma_deref_ecma_string (infinity_str_p);
|
||||
ecma_deref_ecma_string (neg_str_p);
|
||||
ret_value = ecma_make_string_value (neg_inf_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_string_value (infinity_str_p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get the parameters of the number if non-zero. */
|
||||
lit_utf8_byte_t digits[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
lit_utf8_size_t num_digits;
|
||||
int32_t exponent;
|
||||
|
||||
if (!ecma_number_is_zero (this_num))
|
||||
{
|
||||
num_digits = ecma_number_to_decimal (this_num, digits, &exponent);
|
||||
}
|
||||
else
|
||||
{
|
||||
digits[0] = '0';
|
||||
num_digits = 1;
|
||||
exponent = 1;
|
||||
}
|
||||
|
||||
/* 7. */
|
||||
if (exponent > 21)
|
||||
{
|
||||
ret_value = ecma_builtin_number_prototype_object_to_string (this_arg, NULL, 0);
|
||||
}
|
||||
/* 8. */
|
||||
else
|
||||
{
|
||||
/* 1. */
|
||||
int32_t frac_digits = ecma_number_to_int32 (arg_num);
|
||||
|
||||
num_digits = ecma_builtin_number_prototype_helper_round (digits,
|
||||
num_digits,
|
||||
exponent + frac_digits,
|
||||
&exponent);
|
||||
|
||||
/* Buffer that is used to construct the string. */
|
||||
int buffer_size = (exponent > 0) ? exponent + frac_digits + 2 : frac_digits + 3;
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
buffer_size++;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (buffer_size > 0);
|
||||
JMEM_DEFINE_LOCAL_ARRAY (buff, buffer_size, lit_utf8_byte_t);
|
||||
|
||||
lit_utf8_byte_t *p = buff;
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
*p++ = '-';
|
||||
}
|
||||
|
||||
lit_utf8_size_t to_num_digits = ((exponent > 0) ? (lit_utf8_size_t) (exponent + frac_digits)
|
||||
: (lit_utf8_size_t) (frac_digits + 1));
|
||||
p += ecma_builtin_number_prototype_helper_to_string (digits,
|
||||
num_digits,
|
||||
exponent,
|
||||
p,
|
||||
to_num_digits);
|
||||
|
||||
JERRY_ASSERT (p - buff < buffer_size);
|
||||
/* String terminator. */
|
||||
*p = 0;
|
||||
ecma_string_t *str = ecma_new_ecma_string_from_utf8 (buff, (lit_utf8_size_t) (p - buff));
|
||||
|
||||
ret_value = ecma_make_string_value (str);
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (buff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
ECMA_FINALIZE (this_value);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_number_prototype_object_to_fixed */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toExponential' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.6
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_number_prototype_object_to_exponential (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 1. */
|
||||
ECMA_TRY_CATCH (this_value, ecma_builtin_number_prototype_object_value_of (this_arg), ret_value);
|
||||
ecma_number_t this_num = ecma_get_number_from_value (this_value);
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
/* 7. */
|
||||
if (arg_num <= -1.0 || arg_num >= 21.0)
|
||||
{
|
||||
ret_value = ecma_raise_range_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 3. */
|
||||
if (ecma_number_is_nan (this_num))
|
||||
{
|
||||
ecma_string_t *nan_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_NAN);
|
||||
ret_value = ecma_make_string_value (nan_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 5. */
|
||||
bool is_negative = false;
|
||||
if (ecma_number_is_negative (this_num) && !ecma_number_is_zero (this_num))
|
||||
{
|
||||
is_negative = true;
|
||||
this_num *= -1;
|
||||
}
|
||||
|
||||
/* 6. */
|
||||
if (ecma_number_is_infinity (this_num))
|
||||
{
|
||||
ecma_string_t *infinity_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
ecma_string_t *neg_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_MINUS_CHAR);
|
||||
ecma_string_t *neg_inf_str_p = ecma_concat_ecma_strings (neg_str_p, infinity_str_p);
|
||||
ecma_deref_ecma_string (infinity_str_p);
|
||||
ecma_deref_ecma_string (neg_str_p);
|
||||
ret_value = ecma_make_string_value (neg_inf_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_string_value (infinity_str_p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get the parameters of the number if non zero. */
|
||||
lit_utf8_byte_t digits[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
lit_utf8_size_t num_digits;
|
||||
int32_t exponent;
|
||||
|
||||
if (!ecma_number_is_zero (this_num))
|
||||
{
|
||||
num_digits = ecma_number_to_decimal (this_num, digits, &exponent);
|
||||
}
|
||||
else
|
||||
{
|
||||
digits[0] = '0';
|
||||
num_digits = 1;
|
||||
exponent = 1;
|
||||
}
|
||||
|
||||
int32_t frac_digits;
|
||||
if (ecma_is_value_undefined (arg))
|
||||
{
|
||||
frac_digits = (int32_t) num_digits - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
frac_digits = ecma_number_to_int32 (arg_num);
|
||||
}
|
||||
|
||||
num_digits = ecma_builtin_number_prototype_helper_round (digits, num_digits, frac_digits + 1, &exponent);
|
||||
|
||||
/* frac_digits + 2 characters for number, 5 characters for exponent, 1 for \0. */
|
||||
int buffer_size = frac_digits + 2 + 5 + 1;
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
/* +1 character for sign. */
|
||||
buffer_size++;
|
||||
}
|
||||
|
||||
JMEM_DEFINE_LOCAL_ARRAY (buff, buffer_size, lit_utf8_byte_t);
|
||||
|
||||
lit_utf8_byte_t *actual_char_p = buff;
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
*actual_char_p++ = '-';
|
||||
}
|
||||
|
||||
actual_char_p += ecma_builtin_number_prototype_helper_to_string (digits,
|
||||
num_digits,
|
||||
1,
|
||||
actual_char_p,
|
||||
(lit_utf8_size_t) (frac_digits + 1));
|
||||
|
||||
*actual_char_p++ = 'e';
|
||||
|
||||
exponent--;
|
||||
if (exponent < 0)
|
||||
{
|
||||
exponent *= -1;
|
||||
*actual_char_p++ = '-';
|
||||
}
|
||||
else
|
||||
{
|
||||
*actual_char_p++ = '+';
|
||||
}
|
||||
|
||||
/* Add exponent digits. */
|
||||
actual_char_p += ecma_uint32_to_utf8_string ((uint32_t) exponent, actual_char_p, 3);
|
||||
|
||||
JERRY_ASSERT (actual_char_p - buff < buffer_size);
|
||||
*actual_char_p = '\0';
|
||||
ecma_string_t *str = ecma_new_ecma_string_from_utf8 (buff, (lit_utf8_size_t) (actual_char_p - buff));
|
||||
ret_value = ecma_make_string_value (str);
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (buff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
ECMA_FINALIZE (this_value);
|
||||
return ret_value;
|
||||
} /* ecma_builtin_number_prototype_object_to_exponential */
|
||||
|
||||
/**
|
||||
* The Number.prototype object's 'toPrecision' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.7.4.7
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_number_prototype_object_to_precision (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 1. */
|
||||
ECMA_TRY_CATCH (this_value, ecma_builtin_number_prototype_object_value_of (this_arg), ret_value);
|
||||
ecma_number_t this_num = ecma_get_number_from_value (this_value);
|
||||
|
||||
/* 2. */
|
||||
if (ecma_is_value_undefined (arg))
|
||||
{
|
||||
ret_value = ecma_builtin_number_prototype_object_to_string (this_arg, NULL, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 3. */
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
|
||||
|
||||
/* 4. */
|
||||
if (ecma_number_is_nan (this_num))
|
||||
{
|
||||
ecma_string_t *nan_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_NAN);
|
||||
ret_value = ecma_make_string_value (nan_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 6. */
|
||||
bool is_negative = false;
|
||||
if (ecma_number_is_negative (this_num) && !ecma_number_is_zero (this_num))
|
||||
{
|
||||
is_negative = true;
|
||||
this_num *= -1;
|
||||
}
|
||||
|
||||
/* 7. */
|
||||
if (ecma_number_is_infinity (this_num))
|
||||
{
|
||||
ecma_string_t *infinity_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INFINITY_UL);
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
ecma_string_t *neg_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_MINUS_CHAR);
|
||||
ecma_string_t *neg_inf_str_p = ecma_concat_ecma_strings (neg_str_p, infinity_str_p);
|
||||
ecma_deref_ecma_string (infinity_str_p);
|
||||
ecma_deref_ecma_string (neg_str_p);
|
||||
ret_value = ecma_make_string_value (neg_inf_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_string_value (infinity_str_p);
|
||||
}
|
||||
}
|
||||
/* 8. */
|
||||
else if (arg_num < 1.0 || arg_num >= 22.0)
|
||||
{
|
||||
ret_value = ecma_raise_range_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get the parameters of the number if non-zero. */
|
||||
lit_utf8_byte_t digits[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
lit_utf8_size_t num_digits;
|
||||
int32_t exponent;
|
||||
|
||||
if (!ecma_number_is_zero (this_num))
|
||||
{
|
||||
num_digits = ecma_number_to_decimal (this_num, digits, &exponent);
|
||||
}
|
||||
else
|
||||
{
|
||||
digits[0] = '0';
|
||||
num_digits = 1;
|
||||
exponent = 1;
|
||||
}
|
||||
|
||||
int32_t precision = ecma_number_to_int32 (arg_num);
|
||||
|
||||
num_digits = ecma_builtin_number_prototype_helper_round (digits, num_digits, precision, &exponent);
|
||||
|
||||
int buffer_size;
|
||||
if (exponent < -5 || exponent > precision)
|
||||
{
|
||||
/* Exponential notation, precision + 1 digits for number, 5 for exponent, 1 for \0 */
|
||||
buffer_size = precision + 1 + 5 + 1;
|
||||
}
|
||||
else if (exponent <= 0)
|
||||
{
|
||||
/* Fixed notation, -exponent + 2 digits for leading zeros, precision digits, 1 for \0 */
|
||||
buffer_size = -exponent + 2 + precision + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Fixed notation, precision + 1 digits for number, 1 for \0 */
|
||||
buffer_size = precision + 1 + 1;
|
||||
}
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
buffer_size++;
|
||||
}
|
||||
|
||||
JMEM_DEFINE_LOCAL_ARRAY (buff, buffer_size, lit_utf8_byte_t);
|
||||
lit_utf8_byte_t *actual_char_p = buff;
|
||||
|
||||
if (is_negative)
|
||||
{
|
||||
*actual_char_p++ = '-';
|
||||
}
|
||||
|
||||
/* 10.c, Exponential notation.*/
|
||||
if (exponent < -5 || exponent > precision)
|
||||
{
|
||||
actual_char_p += ecma_builtin_number_prototype_helper_to_string (digits,
|
||||
num_digits,
|
||||
1,
|
||||
actual_char_p,
|
||||
(lit_utf8_size_t) precision);
|
||||
|
||||
*actual_char_p++ = 'e';
|
||||
|
||||
exponent--;
|
||||
if (exponent < 0)
|
||||
{
|
||||
exponent *= -1;
|
||||
*actual_char_p++ = '-';
|
||||
}
|
||||
else
|
||||
{
|
||||
*actual_char_p++ = '+';
|
||||
}
|
||||
|
||||
/* Add exponent digits. */
|
||||
actual_char_p += ecma_uint32_to_utf8_string ((uint32_t) exponent, actual_char_p, 3);
|
||||
}
|
||||
/* Fixed notation. */
|
||||
else
|
||||
{
|
||||
lit_utf8_size_t to_num_digits = ((exponent <= 0) ? (lit_utf8_size_t) (1 - exponent + precision)
|
||||
: (lit_utf8_size_t) precision);
|
||||
actual_char_p += ecma_builtin_number_prototype_helper_to_string (digits,
|
||||
num_digits,
|
||||
exponent,
|
||||
actual_char_p,
|
||||
to_num_digits);
|
||||
|
||||
}
|
||||
|
||||
JERRY_ASSERT (actual_char_p - buff < buffer_size);
|
||||
*actual_char_p = '\0';
|
||||
ecma_string_t *str_p = ecma_new_ecma_string_from_utf8 (buff, (lit_utf8_size_t) (actual_char_p - buff));
|
||||
|
||||
ret_value = ecma_make_string_value (str_p);
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (buff);
|
||||
}
|
||||
}
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
}
|
||||
ECMA_FINALIZE (this_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_number_prototype_object_to_precision */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_NUMBER_BUILTIN */
|
57
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.inc.h
vendored
Normal file
57
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Number.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.7.4.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_NUMBER,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_number_prototype_object_to_string, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_number_prototype_object_value_of, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_number_prototype_object_to_locale_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_FIXED_UL, ecma_builtin_number_prototype_object_to_fixed, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_EXPONENTIAL_UL, ecma_builtin_number_prototype_object_to_exponential, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_PRECISION_UL, ecma_builtin_number_prototype_object_to_precision, 1, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
100
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.c
vendored
Normal file
100
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.c
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-number-object.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_NUMBER_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-number.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID number
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup number ECMA Number object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Number object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_number_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ret_value = ecma_make_integer_value (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_number (arguments_list_p[0]);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_number_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Number object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_number_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_value_t completion = ecma_op_create_number_object (ecma_make_integer_value (0));
|
||||
return completion;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_create_number_object (arguments_list_p[0]);
|
||||
}
|
||||
} /* ecma_builtin_number_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_NUMBER_BUILTIN */
|
81
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.inc.h
vendored
Normal file
81
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-number.inc.h
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Number built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_NUMBER)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.7.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// 15.7.3.4
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_NAN,
|
||||
ECMA_BUILTIN_NUMBER_NAN,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// 15.7.3.2
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_MAX_VALUE_U,
|
||||
ECMA_BUILTIN_NUMBER_MAX,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// 15.7.3.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_MIN_VALUE_U,
|
||||
ECMA_BUILTIN_NUMBER_MIN,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// 15.7.3.5
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_POSITIVE_INFINITY_U,
|
||||
ECMA_BUILTIN_NUMBER_POSITIVE_INFINITY,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// 15.7.3.6
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_NEGATIVE_INFINITY_U,
|
||||
ECMA_BUILTIN_NUMBER_NEGATIVE_INFINITY,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.7.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
273
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.c
vendored
Normal file
273
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.c
vendored
Normal file
|
@ -0,0 +1,273 @@
|
|||
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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-builtin-helpers.h"
|
||||
#include "ecma-builtins.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-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID object_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup objectprototype ECMA Object.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_prototype_object_to_string (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
return ecma_builtin_helper_object_to_string (this_arg);
|
||||
} /* ecma_builtin_object_prototype_object_to_string */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'valueOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_prototype_object_value_of (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
return ecma_op_to_object (this_arg);
|
||||
} /* ecma_builtin_object_prototype_object_value_of */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'toLocaleString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_prototype_object_to_locale_string (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
ecma_value_t return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
/* 1. */
|
||||
ECMA_TRY_CATCH (obj_val,
|
||||
ecma_op_to_object (this_arg),
|
||||
return_value);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_val);
|
||||
ecma_string_t *to_string_magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_TO_STRING_UL);
|
||||
|
||||
/* 2. */
|
||||
ECMA_TRY_CATCH (to_string_val,
|
||||
ecma_op_object_get (obj_p, to_string_magic_string_p),
|
||||
return_value);
|
||||
|
||||
/* 3. */
|
||||
if (!ecma_op_is_callable (to_string_val))
|
||||
{
|
||||
return_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 4. */
|
||||
ecma_object_t *to_string_func_obj_p = ecma_get_object_from_value (to_string_val);
|
||||
return_value = ecma_op_function_call (to_string_func_obj_p, this_arg, NULL, 0);
|
||||
}
|
||||
ECMA_FINALIZE (to_string_val);
|
||||
|
||||
ecma_deref_ecma_string (to_string_magic_string_p);
|
||||
|
||||
ECMA_FINALIZE (obj_val);
|
||||
|
||||
return return_value;
|
||||
} /* ecma_builtin_object_prototype_object_to_locale_string */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'hasOwnProperty' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.5
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_prototype_object_has_own_property (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< first argument */
|
||||
{
|
||||
ecma_value_t return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 1. */
|
||||
ECMA_TRY_CATCH (to_string_val,
|
||||
ecma_op_to_string (arg),
|
||||
return_value);
|
||||
|
||||
/* 2. */
|
||||
ECMA_TRY_CATCH (obj_val,
|
||||
ecma_op_to_object (this_arg),
|
||||
return_value);
|
||||
|
||||
ecma_string_t *property_name_string_p = ecma_get_string_from_value (to_string_val);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_val);
|
||||
|
||||
/* 3. */
|
||||
if (ecma_op_object_has_own_property (obj_p, property_name_string_p))
|
||||
{
|
||||
return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (obj_val);
|
||||
|
||||
ECMA_FINALIZE (to_string_val);
|
||||
|
||||
return return_value;
|
||||
} /* ecma_builtin_object_prototype_object_has_own_property */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'isPrototypeOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.6
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_prototype_object_is_prototype_of (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
/* 1. Is the argument an object? */
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
ecma_value_t return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 2. ToObject(this) */
|
||||
ECMA_TRY_CATCH (obj_value,
|
||||
ecma_op_to_object (this_arg),
|
||||
return_value);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_value);
|
||||
|
||||
/* 3. Compare prototype to object */
|
||||
ECMA_TRY_CATCH (v_obj_value,
|
||||
ecma_op_to_object (arg),
|
||||
return_value);
|
||||
|
||||
ecma_object_t *v_obj_p = ecma_get_object_from_value (v_obj_value);
|
||||
|
||||
bool is_prototype_of = ecma_op_object_is_prototype_of (obj_p, v_obj_p);
|
||||
return_value = ecma_make_simple_value (is_prototype_of ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
ECMA_FINALIZE (v_obj_value);
|
||||
|
||||
ECMA_FINALIZE (obj_value);
|
||||
|
||||
return return_value;
|
||||
} /* ecma_builtin_object_prototype_object_is_prototype_of */
|
||||
|
||||
/**
|
||||
* The Object.prototype object's 'propertyIsEnumerable' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.4.7
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_prototype_object_property_is_enumerable (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's first argument */
|
||||
{
|
||||
ecma_value_t return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 1. */
|
||||
ECMA_TRY_CATCH (to_string_val,
|
||||
ecma_op_to_string (arg),
|
||||
return_value);
|
||||
|
||||
/* 2. */
|
||||
ECMA_TRY_CATCH (obj_val,
|
||||
ecma_op_to_object (this_arg),
|
||||
return_value);
|
||||
|
||||
ecma_string_t *property_name_string_p = ecma_get_string_from_value (to_string_val);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_val);
|
||||
|
||||
/* 3. */
|
||||
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
|
||||
property_name_string_p,
|
||||
NULL,
|
||||
ECMA_PROPERTY_GET_NO_OPTIONS);
|
||||
|
||||
/* 4. */
|
||||
if (property != ECMA_PROPERTY_TYPE_NOT_FOUND)
|
||||
{
|
||||
bool is_enumerable = ecma_is_property_enumerable (property);
|
||||
|
||||
return_value = ecma_make_boolean_value (is_enumerable);
|
||||
}
|
||||
else
|
||||
{
|
||||
return_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (obj_val);
|
||||
|
||||
ECMA_FINALIZE (to_string_val);
|
||||
|
||||
return return_value;
|
||||
} /* ecma_builtin_object_prototype_object_property_is_enumerable */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
57
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.inc.h
vendored
Normal file
57
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Object.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.2.4.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_OBJECT,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_object_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_object_prototype_object_value_of, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_object_prototype_object_to_locale_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_HAS_OWN_PROPERTY_UL, ecma_builtin_object_prototype_object_has_own_property, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_PROTOTYPE_OF_UL, ecma_builtin_object_prototype_object_is_prototype_of, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL, ecma_builtin_object_prototype_object_property_is_enumerable, 1, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
848
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.c
vendored
Normal file
848
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.c
vendored
Normal file
|
@ -0,0 +1,848 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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-builtin-helpers.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-objects-general.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID object
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup object ECMA Object object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in Object object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_object_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (arguments_list_len == 0
|
||||
|| ecma_is_value_undefined (arguments_list_p[0])
|
||||
|| ecma_is_value_null (arguments_list_p[0]))
|
||||
{
|
||||
ret_value = ecma_builtin_object_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_object (arguments_list_p[0]);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in Object object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_object_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_op_create_object_object_noarg ();
|
||||
|
||||
return ecma_make_object_value (obj_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_create_object_object_arg (arguments_list_p[0]);
|
||||
}
|
||||
} /* ecma_builtin_object_dispatch_construct */
|
||||
|
||||
/**
|
||||
* The Object object's 'getPrototypeOf' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_get_prototype_of (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
/* 1. */
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 2. */
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
ecma_object_t *prototype_p = ecma_get_object_prototype (obj_p);
|
||||
|
||||
if (prototype_p)
|
||||
{
|
||||
ret_value = ecma_make_object_value (prototype_p);
|
||||
ecma_ref_object (prototype_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_get_prototype_of */
|
||||
|
||||
/**
|
||||
* The Object object's 'getOwnPropertyNames' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_get_own_property_names (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
/* 1. */
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
/* 2-5. */
|
||||
ret_value = ecma_builtin_helper_object_get_properties (obj_p, false);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_get_own_property_names */
|
||||
|
||||
/**
|
||||
* The Object object's 'seal' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.8
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_seal (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
// 1.
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2.
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, false, false, false);
|
||||
|
||||
ecma_collection_iterator_t iter;
|
||||
ecma_collection_iterator_init (&iter, props_p);
|
||||
|
||||
while (ecma_collection_iterator_next (&iter)
|
||||
&& ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
|
||||
// 2.a
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
if (!ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2.b
|
||||
prop_desc.is_configurable = false;
|
||||
|
||||
// 2.c
|
||||
ECMA_TRY_CATCH (define_own_prop_ret,
|
||||
ecma_op_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
&prop_desc,
|
||||
true),
|
||||
ret_value);
|
||||
ECMA_FINALIZE (define_own_prop_ret);
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, true);
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
// 3.
|
||||
ecma_set_object_extensible (obj_p, false);
|
||||
|
||||
// 4.
|
||||
ret_value = ecma_copy_value (arg);
|
||||
}
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_seal */
|
||||
|
||||
/**
|
||||
* The Object object's 'freeze' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.9
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_freeze (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
// 1.
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2.
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, false, false, false);
|
||||
|
||||
|
||||
ecma_collection_iterator_t iter;
|
||||
ecma_collection_iterator_init (&iter, props_p);
|
||||
|
||||
while (ecma_collection_iterator_next (&iter)
|
||||
&& ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
|
||||
// 2.a
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
if (!ecma_op_object_get_own_property_descriptor (obj_p, property_name_p, &prop_desc))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2.b
|
||||
if (prop_desc.is_writable_defined && prop_desc.is_writable)
|
||||
{
|
||||
prop_desc.is_writable = false;
|
||||
}
|
||||
|
||||
// 2.c
|
||||
prop_desc.is_configurable = false;
|
||||
|
||||
// 2.d
|
||||
ECMA_TRY_CATCH (define_own_prop_ret,
|
||||
ecma_op_object_define_own_property (obj_p,
|
||||
property_name_p,
|
||||
&prop_desc,
|
||||
true),
|
||||
ret_value);
|
||||
ECMA_FINALIZE (define_own_prop_ret);
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, true);
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
// 3.
|
||||
ecma_set_object_extensible (obj_p, false);
|
||||
|
||||
// 4.
|
||||
ret_value = ecma_copy_value (arg);
|
||||
}
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_freeze */
|
||||
|
||||
/**
|
||||
* The Object object's 'preventExtensions' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.10
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_prevent_extensions (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
ecma_set_object_extensible (obj_p, false);
|
||||
|
||||
ret_value = ecma_copy_value (arg);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_prevent_extensions */
|
||||
|
||||
/**
|
||||
* The Object object's 'isSealed' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.11
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_is_sealed (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
// 1.
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
|
||||
bool is_sealed;
|
||||
|
||||
// 3.
|
||||
if (ecma_get_object_extensible (obj_p))
|
||||
{
|
||||
is_sealed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the value can be updated in the loop below */
|
||||
is_sealed = true;
|
||||
|
||||
// 2.
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, false, false, false);
|
||||
|
||||
ecma_collection_iterator_t iter;
|
||||
ecma_collection_iterator_init (&iter, props_p);
|
||||
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
|
||||
// 2.a
|
||||
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
|
||||
property_name_p,
|
||||
NULL,
|
||||
ECMA_PROPERTY_GET_NO_OPTIONS);
|
||||
|
||||
// 2.b
|
||||
if (ecma_is_property_configurable (property))
|
||||
{
|
||||
is_sealed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, true);
|
||||
}
|
||||
|
||||
// 4.
|
||||
ret_value = ecma_make_simple_value (is_sealed ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_is_sealed */
|
||||
|
||||
/**
|
||||
* The Object object's 'isFrozen' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.12
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_is_frozen (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
// 1.
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
|
||||
bool is_frozen;
|
||||
|
||||
// 3.
|
||||
if (ecma_get_object_extensible (obj_p))
|
||||
{
|
||||
is_frozen = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_frozen = true;
|
||||
|
||||
// 2.
|
||||
ecma_collection_header_t *props_p = ecma_op_object_get_property_names (obj_p, false, false, false);
|
||||
|
||||
ecma_collection_iterator_t iter;
|
||||
ecma_collection_iterator_init (&iter, props_p);
|
||||
|
||||
while (ecma_collection_iterator_next (&iter))
|
||||
{
|
||||
ecma_string_t *property_name_p = ecma_get_string_from_value (*iter.current_value_p);
|
||||
|
||||
// 2.a
|
||||
ecma_property_t property = ecma_op_object_get_own_property (obj_p,
|
||||
property_name_p,
|
||||
NULL,
|
||||
ECMA_PROPERTY_GET_NO_OPTIONS);
|
||||
|
||||
// 2.b
|
||||
if (ECMA_PROPERTY_GET_TYPE (property) != ECMA_PROPERTY_TYPE_NAMEDACCESSOR
|
||||
&& ecma_is_property_writable (property))
|
||||
{
|
||||
is_frozen = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// 2.c
|
||||
if (ecma_is_property_configurable (property))
|
||||
{
|
||||
is_frozen = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ecma_free_values_collection (props_p, true);
|
||||
}
|
||||
|
||||
// 4.
|
||||
ret_value = ecma_make_simple_value (is_frozen ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_is_frozen */
|
||||
|
||||
/**
|
||||
* The Object object's 'isExtensible' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.13
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_is_extensible (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
|
||||
bool extensible = ecma_get_object_extensible (obj_p);
|
||||
|
||||
ret_value = ecma_make_simple_value (extensible ? ECMA_SIMPLE_VALUE_TRUE
|
||||
: ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_is_extensible */
|
||||
|
||||
/**
|
||||
* The Object object's 'keys' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.14
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_keys (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (!ecma_is_value_object (arg))
|
||||
{
|
||||
/* 1. */
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
|
||||
/* 3-6. */
|
||||
ret_value = ecma_builtin_helper_object_get_properties (obj_p, true);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_keys */
|
||||
|
||||
/**
|
||||
* The Object object's 'getOwnPropertyDescriptor' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.3
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_get_own_property_descriptor (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
// 1.
|
||||
if (!ecma_is_value_object (arg1))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg1);
|
||||
|
||||
// 2.
|
||||
ECMA_TRY_CATCH (name_str_value,
|
||||
ecma_op_to_string (arg2),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *name_str_p = ecma_get_string_from_value (name_str_value);
|
||||
|
||||
// 3.
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
if (ecma_op_object_get_own_property_descriptor (obj_p, name_str_p, &prop_desc))
|
||||
{
|
||||
// 4.
|
||||
ecma_object_t *desc_obj_p = ecma_op_from_property_descriptor (&prop_desc);
|
||||
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
|
||||
ret_value = ecma_make_object_value (desc_obj_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (name_str_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_get_own_property_descriptor */
|
||||
|
||||
/**
|
||||
* The Object object's 'create' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.5
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_create (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
// 1.
|
||||
if (!ecma_is_value_object (arg1) && !ecma_is_value_null (arg1))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = NULL;
|
||||
|
||||
if (!ecma_is_value_null (arg1))
|
||||
{
|
||||
obj_p = ecma_get_object_from_value (arg1);
|
||||
}
|
||||
// 2-3.
|
||||
ecma_object_t *result_obj_p = ecma_op_create_object_object_noarg_and_set_prototype (obj_p);
|
||||
|
||||
// 4.
|
||||
if (!ecma_is_value_undefined (arg2))
|
||||
{
|
||||
ECMA_TRY_CATCH (obj,
|
||||
ecma_builtin_object_object_define_properties (this_arg,
|
||||
ecma_make_object_value (result_obj_p),
|
||||
arg2),
|
||||
ret_value);
|
||||
ECMA_FINALIZE (obj);
|
||||
}
|
||||
|
||||
// 5.
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_copy_value (ecma_make_object_value (result_obj_p));
|
||||
}
|
||||
|
||||
ecma_deref_object (result_obj_p);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_create */
|
||||
|
||||
/**
|
||||
* The Object object's 'defineProperties' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.7
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_define_properties (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2) /**< routine's second argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
// 1.
|
||||
if (!ecma_is_value_object (arg1))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg1);
|
||||
|
||||
// 2.
|
||||
ECMA_TRY_CATCH (props,
|
||||
ecma_op_to_object (arg2),
|
||||
ret_value);
|
||||
|
||||
ecma_object_t *props_p = ecma_get_object_from_value (props);
|
||||
// 3.
|
||||
ecma_collection_header_t *prop_names_p = ecma_op_object_get_property_names (props_p, false, true, false);
|
||||
uint32_t property_number = prop_names_p->unit_number;
|
||||
|
||||
ecma_collection_iterator_t iter;
|
||||
ecma_collection_iterator_init (&iter, prop_names_p);
|
||||
|
||||
// 4.
|
||||
JMEM_DEFINE_LOCAL_ARRAY (property_descriptors, property_number, ecma_property_descriptor_t);
|
||||
|
||||
uint32_t property_descriptor_number = 0;
|
||||
|
||||
while (ecma_collection_iterator_next (&iter)
|
||||
&& ecma_is_value_empty (ret_value))
|
||||
{
|
||||
// 5.a
|
||||
ECMA_TRY_CATCH (desc_obj,
|
||||
ecma_op_object_get (props_p, ecma_get_string_from_value (*iter.current_value_p)),
|
||||
ret_value);
|
||||
|
||||
// 5.b
|
||||
ECMA_TRY_CATCH (conv_result,
|
||||
ecma_op_to_property_descriptor (desc_obj,
|
||||
&property_descriptors[property_descriptor_number]),
|
||||
ret_value);
|
||||
|
||||
property_descriptor_number++;
|
||||
|
||||
ECMA_FINALIZE (conv_result);
|
||||
ECMA_FINALIZE (desc_obj);
|
||||
}
|
||||
|
||||
// 6.
|
||||
ecma_collection_iterator_init (&iter, prop_names_p);
|
||||
for (uint32_t index = 0;
|
||||
index < property_number && ecma_is_value_empty (ret_value);
|
||||
index++)
|
||||
{
|
||||
bool is_next = ecma_collection_iterator_next (&iter);
|
||||
JERRY_ASSERT (is_next);
|
||||
|
||||
ECMA_TRY_CATCH (define_own_prop_ret,
|
||||
ecma_op_object_define_own_property (obj_p,
|
||||
ecma_get_string_from_value (*iter.current_value_p),
|
||||
&property_descriptors[index],
|
||||
true),
|
||||
ret_value);
|
||||
|
||||
ECMA_FINALIZE (define_own_prop_ret);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
for (uint32_t index = 0;
|
||||
index < property_descriptor_number;
|
||||
index++)
|
||||
{
|
||||
ecma_free_property_descriptor (&property_descriptors[index]);
|
||||
}
|
||||
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (property_descriptors);
|
||||
|
||||
ecma_free_values_collection (prop_names_p, true);
|
||||
|
||||
// 7.
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_copy_value (arg1);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (props);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_define_properties */
|
||||
|
||||
/**
|
||||
* The Object object's 'defineProperty' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.2.3.6
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_object_object_define_property (ecma_value_t this_arg, /**< 'this' argument */
|
||||
ecma_value_t arg1, /**< routine's first argument */
|
||||
ecma_value_t arg2, /**< routine's second argument */
|
||||
ecma_value_t arg3) /**< routine's third argument */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (!ecma_is_value_object (arg1))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (arg1);
|
||||
|
||||
ECMA_TRY_CATCH (name_str_value,
|
||||
ecma_op_to_string (arg2),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *name_str_p = ecma_get_string_from_value (name_str_value);
|
||||
|
||||
ecma_property_descriptor_t prop_desc;
|
||||
|
||||
ECMA_TRY_CATCH (conv_result,
|
||||
ecma_op_to_property_descriptor (arg3, &prop_desc),
|
||||
ret_value);
|
||||
|
||||
ECMA_TRY_CATCH (define_own_prop_ret,
|
||||
ecma_op_object_define_own_property (obj_p,
|
||||
name_str_p,
|
||||
&prop_desc,
|
||||
true),
|
||||
ret_value);
|
||||
|
||||
ret_value = ecma_copy_value (arg1);
|
||||
|
||||
ECMA_FINALIZE (define_own_prop_ret);
|
||||
ecma_free_property_descriptor (&prop_desc);
|
||||
ECMA_FINALIZE (conv_result);
|
||||
ECMA_FINALIZE (name_str_value);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_object_object_define_property */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
76
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h
vendored
Normal file
76
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Object built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_OBJECT)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.2.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.2.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ecma_builtin_object_object_get_prototype_of, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL, ecma_builtin_object_object_get_own_property_names, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SEAL, ecma_builtin_object_object_seal, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_FREEZE, ecma_builtin_object_object_freeze, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ecma_builtin_object_object_prevent_extensions, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_SEALED_UL, ecma_builtin_object_object_is_sealed, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_FROZEN_UL, ecma_builtin_object_object_is_frozen, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_IS_EXTENSIBLE, ecma_builtin_object_object_is_extensible, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_KEYS, ecma_builtin_object_object_keys, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, ecma_builtin_object_object_get_own_property_descriptor, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_CREATE, ecma_builtin_object_object_create, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTIES_UL, ecma_builtin_object_object_define_properties, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTY_UL, ecma_builtin_object_object_define_property, 3, 3)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.c
vendored
Normal file
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.c
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-rangeerror-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID range_error_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.inc.h
vendored
Normal file
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* RangeError.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.7.8
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_RANGE_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.9
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_RANGE_ERROR_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.10
|
||||
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
|
||||
LIT_MAGIC_STRING__EMPTY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.c
vendored
Normal file
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.c
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-rangeerror.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID range_error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup rangeerror ECMA RangeError object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in RangeError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_range_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_RANGE, arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_range_error_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in RangeError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_range_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_range_error_dispatch_call (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_range_error_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.inc.h
vendored
Normal file
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* RangeError built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_RANGE_ERROR)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.11.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.c
vendored
Normal file
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.c
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-referenceerror-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID reference_error_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
|
@ -0,0 +1,58 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ReferenceError.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.7.8
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_REFERENCE_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.9
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_REFERENCE_ERROR_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.10
|
||||
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
|
||||
LIT_MAGIC_STRING__EMPTY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.c
vendored
Normal file
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.c
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-referenceerror.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID reference_error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup referenceerror ECMA ReferenceError object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in ReferenceError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_reference_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_REFERENCE, arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_reference_error_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in ReferenceError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_reference_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_reference_error_dispatch_call (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_reference_error_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.inc.h
vendored
Normal file
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ReferenceError built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_REFERENCE_ERROR)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.11.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
451
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c
vendored
Normal file
451
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c
vendored
Normal file
|
@ -0,0 +1,451 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
|
||||
#include "ecma-regexp-object.h"
|
||||
#include "re-compiler.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-regexp-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID regexp_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup regexpprototype ECMA RegExp.prototype object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_ANNEXB_BUILTIN
|
||||
|
||||
/**
|
||||
* The RegExp.prototype object's 'compile' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, B.2.5.1
|
||||
*
|
||||
* @return undefined - if compiled successfully
|
||||
* error ecma value - otherwise
|
||||
*
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t pattern_arg, /**< pattern or RegExp object */
|
||||
ecma_value_t flags_arg) /**< flags */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (!ecma_is_value_object (this_arg)
|
||||
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_REGEXP_UL)
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type"));
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t flags = 0;
|
||||
|
||||
if (ecma_is_value_object (pattern_arg)
|
||||
&& ecma_object_get_class_name (ecma_get_object_from_value (pattern_arg)) == LIT_MAGIC_STRING_REGEXP_UL)
|
||||
{
|
||||
if (!ecma_is_value_undefined (flags_arg))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument of RegExp compile."));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Compile from existing RegExp pbject. */
|
||||
ecma_object_t *target_p = ecma_get_object_from_value (pattern_arg);
|
||||
|
||||
/* Get source. */
|
||||
ecma_string_t *magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_SOURCE);
|
||||
ecma_value_t source_value = ecma_op_object_get_own_data_prop (target_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
ecma_string_t *pattern_string_p = ecma_get_string_from_value (source_value);
|
||||
|
||||
/* Get flags. */
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_GLOBAL);
|
||||
ecma_value_t global_value = ecma_op_object_get_own_data_prop (target_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (global_value));
|
||||
|
||||
if (ecma_is_value_true (global_value))
|
||||
{
|
||||
flags |= RE_FLAG_GLOBAL;
|
||||
}
|
||||
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_IGNORECASE_UL);
|
||||
ecma_value_t ignore_case_value = ecma_op_object_get_own_data_prop (target_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (ignore_case_value));
|
||||
|
||||
if (ecma_is_value_true (ignore_case_value))
|
||||
{
|
||||
flags |= RE_FLAG_IGNORE_CASE;
|
||||
}
|
||||
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_MULTILINE);
|
||||
ecma_value_t multiline_value = ecma_op_object_get_own_data_prop (target_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (multiline_value));
|
||||
|
||||
if (ecma_is_value_true (multiline_value))
|
||||
{
|
||||
flags |= RE_FLAG_MULTILINE;
|
||||
}
|
||||
|
||||
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value);
|
||||
ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this);
|
||||
|
||||
/* Get bytecode property. */
|
||||
ecma_value_t *bc_prop_p = ecma_get_internal_property (this_obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
|
||||
|
||||
/* TODO: We currently have to re-compile the bytecode, because
|
||||
* we can't copy it without knowing its length. */
|
||||
const re_compiled_code_t *new_bc_p = NULL;
|
||||
ecma_value_t bc_comp = re_compile_bytecode (&new_bc_p, pattern_string_p, flags);
|
||||
/* Should always succeed, since we're compiling from a source that has been compiled previously. */
|
||||
JERRY_ASSERT (ecma_is_value_empty (bc_comp));
|
||||
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
|
||||
re_compiled_code_t *old_bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, *bc_prop_p);
|
||||
|
||||
if (old_bc_p != NULL)
|
||||
{
|
||||
/* Free the old bytecode */
|
||||
ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p);
|
||||
}
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (*bc_prop_p, new_bc_p);
|
||||
|
||||
re_initialize_props (this_obj_p, pattern_string_p, flags);
|
||||
|
||||
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
ECMA_FINALIZE (obj_this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_string_t *pattern_string_p = NULL;
|
||||
|
||||
/* Get source string. */
|
||||
if (!ecma_is_value_undefined (pattern_arg))
|
||||
{
|
||||
ECMA_TRY_CATCH (regexp_str_value,
|
||||
ecma_op_to_string (pattern_arg),
|
||||
ret_value);
|
||||
|
||||
if (ecma_string_is_empty (ecma_get_string_from_value (regexp_str_value)))
|
||||
{
|
||||
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_string_p = ecma_get_string_from_value (regexp_str_value);
|
||||
ecma_ref_ecma_string (pattern_string_p);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (regexp_str_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
}
|
||||
|
||||
/* Parse flags. */
|
||||
if (ecma_is_value_empty (ret_value) && !ecma_is_value_undefined (flags_arg))
|
||||
{
|
||||
ECMA_TRY_CATCH (flags_str_value,
|
||||
ecma_op_to_string (flags_arg),
|
||||
ret_value);
|
||||
|
||||
ECMA_TRY_CATCH (flags_dummy,
|
||||
re_parse_regexp_flags (ecma_get_string_from_value (flags_str_value), &flags),
|
||||
ret_value);
|
||||
ECMA_FINALIZE (flags_dummy);
|
||||
ECMA_FINALIZE (flags_str_value);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value);
|
||||
ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this);
|
||||
|
||||
ecma_value_t *bc_prop_p = ecma_get_internal_property (this_obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
|
||||
|
||||
/* Try to compile bytecode from new source. */
|
||||
const re_compiled_code_t *new_bc_p = NULL;
|
||||
ECMA_TRY_CATCH (bc_dummy,
|
||||
re_compile_bytecode (&new_bc_p, pattern_string_p, flags),
|
||||
ret_value);
|
||||
|
||||
re_compiled_code_t *old_bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, *bc_prop_p);
|
||||
|
||||
if (old_bc_p != NULL)
|
||||
{
|
||||
/* Free the old bytecode */
|
||||
ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p);
|
||||
}
|
||||
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (*bc_prop_p, new_bc_p);
|
||||
re_initialize_props (this_obj_p, pattern_string_p, flags);
|
||||
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
ECMA_FINALIZE (bc_dummy);
|
||||
|
||||
ECMA_FINALIZE (obj_this);
|
||||
}
|
||||
|
||||
if (pattern_string_p != NULL)
|
||||
{
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_prototype_compile */
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */
|
||||
|
||||
/**
|
||||
* The RegExp.prototype object's 'exec' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.10.6.2
|
||||
*
|
||||
* @return array object containing the results - if the matched
|
||||
* null - otherwise
|
||||
*
|
||||
* May raise error, so returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (!ecma_is_value_object (this_arg)
|
||||
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_REGEXP_UL)
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value);
|
||||
|
||||
ECMA_TRY_CATCH (input_str_value,
|
||||
ecma_op_to_string (arg),
|
||||
ret_value);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
|
||||
ecma_value_t *bytecode_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
|
||||
|
||||
void *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (void, *bytecode_prop_p);
|
||||
|
||||
if (bytecode_p == NULL)
|
||||
{
|
||||
/* Missing bytecode means empty RegExp: '/(?:)/', so always return empty string. */
|
||||
ecma_string_t *capture_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
|
||||
ecma_value_t arguments_list[1];
|
||||
arguments_list[0] = ecma_make_string_value (capture_str_p);
|
||||
|
||||
ret_value = ecma_op_create_array_object (arguments_list, 1, false);
|
||||
|
||||
ecma_deref_ecma_string (capture_str_p);
|
||||
|
||||
re_set_result_array_properties (ecma_get_object_from_value (ret_value),
|
||||
ecma_get_string_from_value (input_str_value),
|
||||
1,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_regexp_exec_helper (obj_this, input_str_value, false);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (input_str_value);
|
||||
ECMA_FINALIZE (obj_this);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_prototype_exec */
|
||||
|
||||
/**
|
||||
* The RegExp.prototype object's 'test' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.10.6.3
|
||||
*
|
||||
* @return true - if match is not null
|
||||
* false - otherwise
|
||||
*
|
||||
* May raise error, so returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_regexp_prototype_test (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg) /**< routine's argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ECMA_TRY_CATCH (match_value,
|
||||
ecma_builtin_regexp_prototype_exec (this_arg, arg),
|
||||
ret_value);
|
||||
|
||||
if (ecma_is_value_null (match_value))
|
||||
{
|
||||
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (match_value);
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_prototype_test */
|
||||
|
||||
/**
|
||||
* The RegExp.prototype object's 'toString' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.10.6.4
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_regexp_prototype_to_string (ecma_value_t this_arg) /**< this argument */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (!ecma_is_value_object (this_arg)
|
||||
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_REGEXP_UL)
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Incomplete RegExp type"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_TRY_CATCH (obj_this,
|
||||
ecma_op_to_object (this_arg),
|
||||
ret_value);
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
|
||||
|
||||
/* Get RegExp source from the source property */
|
||||
ecma_string_t *magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_SOURCE);
|
||||
ecma_value_t source_value = ecma_op_object_get_own_data_prop (obj_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
ecma_string_t *src_sep_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_SLASH_CHAR);
|
||||
ecma_string_t *source_str_p = ecma_get_string_from_value (source_value);
|
||||
ecma_string_t *output_str_p = ecma_concat_ecma_strings (src_sep_str_p, source_str_p);
|
||||
ecma_deref_ecma_string (source_str_p);
|
||||
|
||||
ecma_string_t *concat_p = ecma_concat_ecma_strings (output_str_p, src_sep_str_p);
|
||||
ecma_deref_ecma_string (src_sep_str_p);
|
||||
ecma_deref_ecma_string (output_str_p);
|
||||
output_str_p = concat_p;
|
||||
|
||||
/* Check the global flag */
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_GLOBAL);
|
||||
ecma_value_t global_value = ecma_op_object_get_own_data_prop (obj_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (global_value));
|
||||
|
||||
if (ecma_is_value_true (global_value))
|
||||
{
|
||||
ecma_string_t *g_flag_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_G_CHAR);
|
||||
concat_p = ecma_concat_ecma_strings (output_str_p, g_flag_str_p);
|
||||
ecma_deref_ecma_string (output_str_p);
|
||||
ecma_deref_ecma_string (g_flag_str_p);
|
||||
output_str_p = concat_p;
|
||||
}
|
||||
|
||||
/* Check the ignoreCase flag */
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_IGNORECASE_UL);
|
||||
ecma_value_t ignore_case_value = ecma_op_object_get_own_data_prop (obj_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (ignore_case_value));
|
||||
|
||||
if (ecma_is_value_true (ignore_case_value))
|
||||
{
|
||||
ecma_string_t *ic_flag_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_I_CHAR);
|
||||
concat_p = ecma_concat_ecma_strings (output_str_p, ic_flag_str_p);
|
||||
ecma_deref_ecma_string (output_str_p);
|
||||
ecma_deref_ecma_string (ic_flag_str_p);
|
||||
output_str_p = concat_p;
|
||||
}
|
||||
|
||||
/* Check the multiline flag */
|
||||
magic_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_MULTILINE);
|
||||
ecma_value_t multiline_value = ecma_op_object_get_own_data_prop (obj_p, magic_string_p);
|
||||
ecma_deref_ecma_string (magic_string_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_boolean (multiline_value));
|
||||
|
||||
if (ecma_is_value_true (multiline_value))
|
||||
{
|
||||
ecma_string_t *m_flag_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_M_CHAR);
|
||||
concat_p = ecma_concat_ecma_strings (output_str_p, m_flag_str_p);
|
||||
ecma_deref_ecma_string (output_str_p);
|
||||
ecma_deref_ecma_string (m_flag_str_p);
|
||||
output_str_p = concat_p;
|
||||
}
|
||||
|
||||
ret_value = ecma_make_string_value (output_str_p);
|
||||
|
||||
ECMA_FINALIZE (obj_this);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_prototype_to_string */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
|
90
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h
vendored
Normal file
90
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* RegExp.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef SIMPLE_VALUE
|
||||
# define SIMPLE_VALUE(name, simple_value, prop_attributes)
|
||||
#endif /* !SIMPLE_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE)
|
||||
|
||||
// ECMA-262 v5, 15.10.6.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_REGEXP,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// ECMA-262 v5, 15.10.7.1
|
||||
STRING_VALUE (LIT_MAGIC_STRING_SOURCE,
|
||||
LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.10.7.2
|
||||
SIMPLE_VALUE (LIT_MAGIC_STRING_GLOBAL,
|
||||
ECMA_SIMPLE_VALUE_FALSE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.10.7.3
|
||||
SIMPLE_VALUE (LIT_MAGIC_STRING_IGNORECASE_UL,
|
||||
ECMA_SIMPLE_VALUE_FALSE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.10.7.4
|
||||
SIMPLE_VALUE (LIT_MAGIC_STRING_MULTILINE,
|
||||
ECMA_SIMPLE_VALUE_FALSE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.10.7.5
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LASTINDEX_UL,
|
||||
0,
|
||||
ECMA_PROPERTY_FLAG_WRITABLE)
|
||||
|
||||
#ifndef CONFIG_DISABLE_ANNEXB_BUILTIN
|
||||
ROUTINE (LIT_MAGIC_STRING_COMPILE, ecma_builtin_regexp_prototype_compile, 2, 1)
|
||||
#endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */
|
||||
ROUTINE (LIT_MAGIC_STRING_EXEC, ecma_builtin_regexp_prototype_exec, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_TEST, ecma_builtin_regexp_prototype_test, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_regexp_prototype_to_string, 0, 0)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
160
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.c
vendored
Normal file
160
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.c
vendored
Normal file
|
@ -0,0 +1,160 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-regexp-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-regexp.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID regexp
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup regexp ECMA RegExp object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in RegExp object
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_regexp_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_regexp_dispatch_construct (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_regexp_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in RegExp object
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_value_t pattern_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
ecma_value_t flags_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
if (arguments_list_len > 0)
|
||||
{
|
||||
/* pattern string or RegExp object */
|
||||
pattern_value = arguments_list_p[0];
|
||||
|
||||
if (arguments_list_len > 1)
|
||||
{
|
||||
flags_value = arguments_list_p[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (ecma_is_value_object (pattern_value)
|
||||
&& ecma_object_get_class_name (ecma_get_object_from_value (pattern_value)) == LIT_MAGIC_STRING_REGEXP_UL)
|
||||
{
|
||||
if (ecma_is_value_undefined (flags_value))
|
||||
{
|
||||
ret_value = ecma_copy_value (pattern_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument of RegExp call."));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_string_t *pattern_string_p = NULL;
|
||||
ecma_string_t *flags_string_p = NULL;
|
||||
|
||||
if (!ecma_is_value_undefined (pattern_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (regexp_str_value,
|
||||
ecma_op_to_string (pattern_value),
|
||||
ret_value);
|
||||
|
||||
if (ecma_string_is_empty (ecma_get_string_from_value (regexp_str_value)))
|
||||
{
|
||||
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_string_p = ecma_get_string_from_value (regexp_str_value);
|
||||
ecma_ref_ecma_string (pattern_string_p);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (regexp_str_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value) && !ecma_is_value_undefined (flags_value))
|
||||
{
|
||||
ECMA_TRY_CATCH (flags_str_value,
|
||||
ecma_op_to_string (flags_value),
|
||||
ret_value);
|
||||
|
||||
flags_string_p = ecma_get_string_from_value (flags_str_value);
|
||||
ecma_ref_ecma_string (flags_string_p);
|
||||
|
||||
ECMA_FINALIZE (flags_str_value);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_op_create_regexp_object (pattern_string_p, flags_string_p);
|
||||
}
|
||||
|
||||
if (pattern_string_p != NULL)
|
||||
{
|
||||
ecma_deref_ecma_string (pattern_string_p);
|
||||
}
|
||||
|
||||
if (flags_string_p != NULL)
|
||||
{
|
||||
ecma_deref_ecma_string (flags_string_p);
|
||||
}
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_regexp_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
|
51
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h
vendored
Normal file
51
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015 University of Szeged.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* RegExp built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_REGEXP)
|
||||
|
||||
// ECMA-262 v5, 15.10.5
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
2,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
// ECMA-262 v5, 15.10.5.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_REGEXP_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
2316
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c
vendored
Normal file
2316
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
90
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.inc.h
vendored
Normal file
90
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* String.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_STRING_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.5.4.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_STRING,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value) */
|
||||
|
||||
// 15.5.4 (String.prototype is itself a String object whose value is an empty String), 15.5.5.1
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_string_prototype_object_to_string, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_string_prototype_object_value_of, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_CONCAT, ecma_builtin_string_prototype_object_concat, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_string_prototype_object_slice, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_INDEX_OF_UL, ecma_builtin_string_prototype_object_index_of, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, ecma_builtin_string_prototype_object_last_index_of, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_CHAR_AT_UL, ecma_builtin_string_prototype_object_char_at, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_CHAR_CODE_AT_UL, ecma_builtin_string_prototype_object_char_code_at, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_LOCALE_COMPARE_UL, ecma_builtin_string_prototype_object_locale_compare, 1, 1)
|
||||
|
||||
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
|
||||
ROUTINE (LIT_MAGIC_STRING_MATCH, ecma_builtin_string_prototype_object_match, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_REPLACE, ecma_builtin_string_prototype_object_replace, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_SEARCH, ecma_builtin_string_prototype_object_search, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SPLIT, ecma_builtin_string_prototype_object_split, 2, 2)
|
||||
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
|
||||
|
||||
ROUTINE (LIT_MAGIC_STRING_SUBSTRING, ecma_builtin_string_prototype_object_substring, 2, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_LOWER_CASE_UL, ecma_builtin_string_prototype_object_to_lower_case, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_LOWER_CASE_UL, ecma_builtin_string_prototype_object_to_locale_lower_case, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_UPPER_CASE_UL, ecma_builtin_string_prototype_object_to_upper_case, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_UPPER_CASE_UL, ecma_builtin_string_prototype_object_to_locale_upper_case, 0, 0)
|
||||
ROUTINE (LIT_MAGIC_STRING_TRIM, ecma_builtin_string_prototype_object_trim, 0, 0)
|
||||
|
||||
#ifndef CONFIG_DISABLE_ANNEXB_BUILTIN
|
||||
ROUTINE (LIT_MAGIC_STRING_SUBSTR, ecma_builtin_string_prototype_object_substr, 2, 2)
|
||||
#endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
159
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.c
vendored
Normal file
159
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.c
vendored
Normal file
|
@ -0,0 +1,159 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_STRING_BUILTIN
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID string
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup string ECMA String object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The String object's 'fromCharCode' routine
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 15.5.3.2
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_string_object_from_char_code (ecma_value_t this_arg, /**< 'this' argument */
|
||||
const ecma_value_t args[], /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_string_t *ret_string_p = NULL;
|
||||
|
||||
if (args_number == 0)
|
||||
{
|
||||
ret_string_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
}
|
||||
else
|
||||
{
|
||||
lit_utf8_size_t utf8_buf_size = args_number * LIT_CESU8_MAX_BYTES_IN_CODE_UNIT;
|
||||
|
||||
JMEM_DEFINE_LOCAL_ARRAY (utf8_buf_p,
|
||||
utf8_buf_size,
|
||||
lit_utf8_byte_t);
|
||||
|
||||
lit_utf8_size_t utf8_buf_used = 0;
|
||||
|
||||
for (ecma_length_t arg_index = 0;
|
||||
arg_index < args_number && ecma_is_value_empty (ret_value);
|
||||
arg_index++)
|
||||
{
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
|
||||
|
||||
uint32_t uint32_char_code = ecma_number_to_uint32 (arg_num);
|
||||
ecma_char_t code_unit = (uint16_t) uint32_char_code;
|
||||
|
||||
JERRY_ASSERT (utf8_buf_used <= utf8_buf_size - LIT_UTF8_MAX_BYTES_IN_CODE_UNIT);
|
||||
utf8_buf_used += lit_code_unit_to_utf8 (code_unit, utf8_buf_p + utf8_buf_used);
|
||||
JERRY_ASSERT (utf8_buf_used <= utf8_buf_size);
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_string_p = ecma_new_ecma_string_from_utf8 (utf8_buf_p, utf8_buf_used);
|
||||
}
|
||||
|
||||
JMEM_FINALIZE_LOCAL_ARRAY (utf8_buf_p);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_make_string_value (ret_string_p);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_string_object_from_char_code */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in String object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_string_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
if (arguments_list_len == 0)
|
||||
{
|
||||
ecma_string_t *str_p = ecma_new_ecma_string_from_magic_string_id (LIT_MAGIC_STRING__EMPTY);
|
||||
ecma_value_t str_value = ecma_make_string_value (str_p);
|
||||
|
||||
ret_value = str_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_value = ecma_op_to_string (arguments_list_p[0]);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_string_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in String object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_string_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
return ecma_op_create_string_object (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_string_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_STRING_BUILTIN */
|
64
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h
vendored
Normal file
64
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* String built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
#ifndef ROUTINE
|
||||
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
|
||||
#endif /* !ROUTINE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_STRING)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.5.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.7.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_STRING_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Routine properties:
|
||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||
ROUTINE (LIT_MAGIC_STRING_FROM_CHAR_CODE_UL, ecma_builtin_string_object_from_char_code, NON_FIXED, 1)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.c
vendored
Normal file
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.c
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-syntaxerror-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID syntax_error_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.inc.h
vendored
Normal file
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SyntaxError.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.7.8
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_SYNTAX_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.9
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_SYNTAX_ERROR_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.10
|
||||
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
|
||||
LIT_MAGIC_STRING__EMPTY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.c
vendored
Normal file
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.c
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-syntaxerror.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID syntax_error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup syntaxerror ECMA SyntaxError object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in SyntaxError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_syntax_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_SYNTAX, arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_syntax_error_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in SyntaxError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_syntax_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_syntax_error_dispatch_call (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_syntax_error_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.inc.h
vendored
Normal file
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SyntaxError built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_SYNTAX_ERROR)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.11.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
84
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.c
vendored
Normal file
84
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.c
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-type-error-thrower.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID type_error_thrower
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup type_error_thrower ECMA [[ThrowTypeError]] object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in [[ThrowTypeError]] object
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 13.2.3
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_type_error_thrower_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
/* The object should throw TypeError */
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
} /* ecma_builtin_type_error_thrower_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in [[ThrowTypeError]] object
|
||||
*
|
||||
* See also:
|
||||
* ECMA-262 v5, 13.2.3
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_type_error_thrower_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
/* The object is not a constructor */
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG (""));
|
||||
} /* ecma_builtin_type_error_thrower_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
45
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.inc.h
vendored
Normal file
45
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.inc.h
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* [[ThrowTypeError]] description
|
||||
*
|
||||
* See also: ECMA-262 v5, 13.2.3
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
0,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.c
vendored
Normal file
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.c
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typeerror-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID type_error_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.inc.h
vendored
Normal file
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* TypeError.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.7.8
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_TYPE_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.9
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_TYPE_ERROR_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.10
|
||||
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
|
||||
LIT_MAGIC_STRING__EMPTY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.c
vendored
Normal file
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.c
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typeerror.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID type_error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup typeerror ECMA TypeError object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in TypeError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_type_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_TYPE, arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_type_error_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in TypeError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_type_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_type_error_dispatch_call (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_type_error_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.inc.h
vendored
Normal file
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* TypeError built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_TYPE_ERROR)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.11.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.c
vendored
Normal file
37
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.c
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-string-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-urierror-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID uri_error_prototype
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.inc.h
vendored
Normal file
58
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.inc.h
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* UriError.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.7.8
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
|
||||
ECMA_BUILTIN_ID_URI_ERROR,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.9
|
||||
STRING_VALUE (LIT_MAGIC_STRING_NAME,
|
||||
LIT_MAGIC_STRING_URI_ERROR_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
// 15.11.7.10
|
||||
STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
|
||||
LIT_MAGIC_STRING__EMPTY,
|
||||
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.c
vendored
Normal file
77
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.c
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
/* 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-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-urierror.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID uri_error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup urierror ECMA UriError object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in UriError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_uri_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_helper_error_dispatch_call (ECMA_ERROR_URI, arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_uri_error_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in UriError object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_uri_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_uri_error_dispatch_call (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_uri_error_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.inc.h
vendored
Normal file
60
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.inc.h
vendored
Normal file
|
@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* UriError built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_attributes)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_attributes)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_URI_ERROR)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.11.3
|
||||
NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.3.1
|
||||
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
|
||||
ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE,
|
||||
ECMA_PROPERTY_FIXED)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef ROUTINE
|
91
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h
vendored
Normal file
91
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* Copyright 2014-2016 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_BUILTINS_INTERNAL_H
|
||||
#define ECMA_BUILTINS_INTERNAL_H
|
||||
|
||||
#ifndef ECMA_BUILTINS_INTERNAL
|
||||
# error "!ECMA_BUILTINS_INTERNAL"
|
||||
#endif /* !ECMA_BUILTINS_INTERNAL */
|
||||
|
||||
#include "ecma-builtins.h"
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/**
|
||||
* Type of built-in properties.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_BUILTIN_PROPERTY_SIMPLE, /**< simple value property */
|
||||
ECMA_BUILTIN_PROPERTY_NUMBER, /**< number value property */
|
||||
ECMA_BUILTIN_PROPERTY_STRING, /**< string value property */
|
||||
ECMA_BUILTIN_PROPERTY_OBJECT, /**< builtin object property */
|
||||
ECMA_BUILTIN_PROPERTY_ROUTINE, /**< routine property */
|
||||
ECMA_BUILTIN_PROPERTY_END, /**< last property */
|
||||
} ecma_builtin_property_type_t;
|
||||
|
||||
/**
|
||||
* Type of symbolic built-in number types (starting from 256).
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ECMA_BUILTIN_NUMBER_MAX = 256, /**< value of ECMA_NUMBER_MAX_VALUE */
|
||||
ECMA_BUILTIN_NUMBER_MIN, /**< value of ECMA_NUMBER_MIN_VALUE */
|
||||
ECMA_BUILTIN_NUMBER_E, /**< value of ECMA_NUMBER_E */
|
||||
ECMA_BUILTIN_NUMBER_PI, /**< value of ECMA_NUMBER_PI */
|
||||
ECMA_BUILTIN_NUMBER_LN10, /**< value of ECMA_NUMBER_LN10 */
|
||||
ECMA_BUILTIN_NUMBER_LN2, /**< value of ECMA_NUMBER_LN2 */
|
||||
ECMA_BUILTIN_NUMBER_LOG2E, /**< value of ECMA_NUMBER_LOG2E */
|
||||
ECMA_BUILTIN_NUMBER_LOG10E, /**< value of ECMA_NUMBER_LOG10E */
|
||||
ECMA_BUILTIN_NUMBER_SQRT2, /**< value of ECMA_NUMBER_SQRT2 */
|
||||
ECMA_BUILTIN_NUMBER_SQRT_1_2, /**< value of ECMA_NUMBER_SQRT_1_2 */
|
||||
ECMA_BUILTIN_NUMBER_NAN, /**< result of ecma_number_make_nan () */
|
||||
ECMA_BUILTIN_NUMBER_POSITIVE_INFINITY, /**< result of ecma_number_make_infinity (false) */
|
||||
ECMA_BUILTIN_NUMBER_NEGATIVE_INFINITY, /**< result of ecma_number_make_infinity (true) */
|
||||
} ecma_builtin_number_type_t;
|
||||
|
||||
/**
|
||||
* Description of built-in properties.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t magic_string_id; /**< name of the property */
|
||||
uint8_t type; /**< type of the property */
|
||||
uint8_t attributes; /**< attributes of the property */
|
||||
uint16_t value; /**< value of the property */
|
||||
} ecma_builtin_property_descriptor_t;
|
||||
|
||||
#define BUILTIN(builtin_id, \
|
||||
object_type, \
|
||||
object_prototype_builtin_id, \
|
||||
is_extensible, \
|
||||
is_static, \
|
||||
lowercase_name) \
|
||||
extern const ecma_builtin_property_descriptor_t \
|
||||
ecma_builtin_ ## lowercase_name ## _property_descriptor_list[]; \
|
||||
extern ecma_value_t \
|
||||
ecma_builtin_ ## lowercase_name ## _dispatch_call (const ecma_value_t *, \
|
||||
ecma_length_t); \
|
||||
extern ecma_value_t \
|
||||
ecma_builtin_ ## lowercase_name ## _dispatch_construct (const ecma_value_t *, \
|
||||
ecma_length_t); \
|
||||
extern ecma_value_t \
|
||||
ecma_builtin_ ## lowercase_name ## _dispatch_routine (uint16_t builtin_routine_id, \
|
||||
ecma_value_t this_arg_value, \
|
||||
const ecma_value_t [], \
|
||||
ecma_length_t);
|
||||
#include "ecma-builtins.inc.h"
|
||||
|
||||
#endif /* !ECMA_BUILTINS_INTERNAL_H */
|
811
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.c
vendored
Normal file
811
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.c
vendored
Normal file
|
@ -0,0 +1,811 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged
|
||||
*
|
||||
* 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-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-objects.h"
|
||||
#include "jcontext.h"
|
||||
#include "jrt-bit-fields.h"
|
||||
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*/
|
||||
|
||||
static void ecma_instantiate_builtin (ecma_builtin_id_t id);
|
||||
|
||||
/**
|
||||
* Check if passed object is the instance of specified built-in.
|
||||
*/
|
||||
bool
|
||||
ecma_builtin_is (ecma_object_t *obj_p, /**< pointer to an object */
|
||||
ecma_builtin_id_t builtin_id) /**< id of built-in to check on */
|
||||
{
|
||||
JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p));
|
||||
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
|
||||
|
||||
if (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] == NULL)
|
||||
{
|
||||
/* If a built-in object is not instantiated,
|
||||
* the specified object cannot be the built-in object */
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (obj_p == JERRY_CONTEXT (ecma_builtin_objects)[builtin_id]);
|
||||
}
|
||||
} /* ecma_builtin_is */
|
||||
|
||||
/**
|
||||
* Get reference to specified built-in object
|
||||
*
|
||||
* @return pointer to the object's instance
|
||||
*/
|
||||
ecma_object_t *
|
||||
ecma_builtin_get (ecma_builtin_id_t builtin_id) /**< id of built-in to check on */
|
||||
{
|
||||
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
|
||||
|
||||
if (unlikely (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] == NULL))
|
||||
{
|
||||
ecma_instantiate_builtin (builtin_id);
|
||||
}
|
||||
|
||||
ecma_ref_object (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id]);
|
||||
|
||||
return JERRY_CONTEXT (ecma_builtin_objects)[builtin_id];
|
||||
} /* ecma_builtin_get */
|
||||
|
||||
/**
|
||||
* Checks whether the given function is a built-in routine
|
||||
*
|
||||
* @return true if the function object is a built-in routine
|
||||
* false otherwise
|
||||
*/
|
||||
inline bool __attr_always_inline___
|
||||
ecma_builtin_function_is_routine (ecma_object_t *func_obj_p) /**< function object */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (func_obj_p));
|
||||
|
||||
ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p;
|
||||
return (ext_func_obj_p->u.built_in.routine_id >= ECMA_BUILTIN_ID__COUNT);
|
||||
} /* ecma_builtin_function_is_routine */
|
||||
|
||||
/**
|
||||
* Initialize specified built-in object.
|
||||
*
|
||||
* @return pointer to the object
|
||||
*/
|
||||
static ecma_object_t *
|
||||
ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
|
||||
ecma_object_t *prototype_obj_p, /**< prototype object */
|
||||
ecma_object_type_t obj_type, /**< object's type */
|
||||
bool is_extensible) /**< value of object's [[Extensible]] property */
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p, true, is_extensible, obj_type);
|
||||
|
||||
/*
|
||||
* [[Class]] property of built-in object is not stored explicitly.
|
||||
*
|
||||
* See also: ecma_object_get_class_name
|
||||
*/
|
||||
|
||||
ecma_set_object_is_builtin (obj_p);
|
||||
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
ext_obj_p->u.built_in.id = obj_builtin_id;
|
||||
ext_obj_p->u.built_in.routine_id = obj_builtin_id;
|
||||
ext_obj_p->u.built_in.instantiated_bitset = 0;
|
||||
|
||||
/** Initializing [[PrimitiveValue]] properties of built-in prototype objects */
|
||||
switch (obj_builtin_id)
|
||||
{
|
||||
#ifndef CONFIG_DISABLE_ARRAY_BUILTIN
|
||||
case ECMA_BUILTIN_ID_ARRAY_PROTOTYPE:
|
||||
{
|
||||
ecma_string_t *length_str_p = ecma_new_ecma_length_string ();
|
||||
|
||||
ecma_property_value_t *length_prop_value_p;
|
||||
length_prop_value_p = ecma_create_named_data_property (obj_p,
|
||||
length_str_p,
|
||||
ECMA_PROPERTY_FLAG_WRITABLE,
|
||||
NULL);
|
||||
|
||||
length_prop_value_p->value = ecma_make_integer_value (0);
|
||||
|
||||
ecma_deref_ecma_string (length_str_p);
|
||||
break;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_ARRAY_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_STRING_BUILTIN
|
||||
case ECMA_BUILTIN_ID_STRING_PROTOTYPE:
|
||||
{
|
||||
ecma_string_t *prim_prop_str_value_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
|
||||
ecma_value_t *prim_value_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
|
||||
*prim_value_p = ecma_make_string_value (prim_prop_str_value_p);
|
||||
break;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_STRING_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_NUMBER_BUILTIN
|
||||
case ECMA_BUILTIN_ID_NUMBER_PROTOTYPE:
|
||||
{
|
||||
ecma_value_t *prim_value_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
|
||||
*prim_value_p = ecma_make_integer_value (0);
|
||||
break;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_NUMBER_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
|
||||
case ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE:
|
||||
{
|
||||
ecma_value_t *prim_value_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_ECMA_VALUE);
|
||||
*prim_value_p = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE);
|
||||
break;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_DATE_BUILTIN
|
||||
case ECMA_BUILTIN_ID_DATE_PROTOTYPE:
|
||||
{
|
||||
ecma_number_t *prim_prop_num_value_p = ecma_alloc_number ();
|
||||
*prim_prop_num_value_p = ecma_number_make_nan ();
|
||||
|
||||
ecma_value_t *prim_value_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_DATE_FLOAT);
|
||||
ECMA_SET_INTERNAL_VALUE_POINTER (*prim_value_p, prim_prop_num_value_p);
|
||||
break;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_DATE_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
|
||||
case ECMA_BUILTIN_ID_REGEXP_PROTOTYPE:
|
||||
{
|
||||
ecma_value_t *bytecode_prop_p = ecma_create_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE);
|
||||
*bytecode_prop_p = ECMA_NULL_POINTER;
|
||||
break;
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return obj_p;
|
||||
} /* ecma_builtin_init_object */
|
||||
|
||||
/**
|
||||
* Instantiate specified ECMA built-in object
|
||||
*/
|
||||
static void
|
||||
ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
#define BUILTIN(builtin_id, \
|
||||
object_type, \
|
||||
object_prototype_builtin_id, \
|
||||
is_extensible, \
|
||||
is_static, \
|
||||
lowercase_name) \
|
||||
case builtin_id: \
|
||||
{ \
|
||||
JERRY_ASSERT (JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] == NULL); \
|
||||
\
|
||||
ecma_object_t *prototype_obj_p; \
|
||||
if (object_prototype_builtin_id == ECMA_BUILTIN_ID__COUNT) \
|
||||
{ \
|
||||
prototype_obj_p = NULL; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
if (JERRY_CONTEXT (ecma_builtin_objects)[object_prototype_builtin_id] == NULL) \
|
||||
{ \
|
||||
ecma_instantiate_builtin (object_prototype_builtin_id); \
|
||||
} \
|
||||
prototype_obj_p = JERRY_CONTEXT (ecma_builtin_objects)[object_prototype_builtin_id]; \
|
||||
JERRY_ASSERT (prototype_obj_p != NULL); \
|
||||
} \
|
||||
\
|
||||
ecma_object_t *builtin_obj_p = ecma_builtin_init_object (builtin_id, \
|
||||
prototype_obj_p, \
|
||||
object_type, \
|
||||
is_extensible); \
|
||||
JERRY_CONTEXT (ecma_builtin_objects)[builtin_id] = builtin_obj_p; \
|
||||
\
|
||||
break; \
|
||||
}
|
||||
#include "ecma-builtins.inc.h"
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (id < ECMA_BUILTIN_ID__COUNT);
|
||||
|
||||
JERRY_UNREACHABLE (); /* The built-in is not implemented. */
|
||||
}
|
||||
}
|
||||
} /* ecma_instantiate_builtin */
|
||||
|
||||
/**
|
||||
* Finalize ECMA built-in objects
|
||||
*/
|
||||
void
|
||||
ecma_finalize_builtins (void)
|
||||
{
|
||||
for (ecma_builtin_id_t id = (ecma_builtin_id_t) 0;
|
||||
id < ECMA_BUILTIN_ID__COUNT;
|
||||
id = (ecma_builtin_id_t) (id + 1))
|
||||
{
|
||||
if (JERRY_CONTEXT (ecma_builtin_objects)[id] != NULL)
|
||||
{
|
||||
ecma_deref_object (JERRY_CONTEXT (ecma_builtin_objects)[id]);
|
||||
JERRY_CONTEXT (ecma_builtin_objects)[id] = NULL;
|
||||
}
|
||||
}
|
||||
} /* ecma_finalize_builtins */
|
||||
|
||||
/**
|
||||
* Construct a Function object for specified built-in routine
|
||||
*
|
||||
* See also: ECMA-262 v5, 15
|
||||
*
|
||||
* @return pointer to constructed Function object
|
||||
*/
|
||||
static ecma_object_t *
|
||||
ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**< identifier of built-in object */
|
||||
uint16_t routine_id, /**< builtin-wide identifier of the built-in
|
||||
* object's routine property */
|
||||
uint8_t length_prop_value) /**< value of 'length' property */
|
||||
{
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
|
||||
|
||||
ecma_object_t *func_obj_p = ecma_create_object (prototype_obj_p, true, true, ECMA_OBJECT_TYPE_FUNCTION);
|
||||
|
||||
ecma_deref_object (prototype_obj_p);
|
||||
|
||||
ecma_set_object_is_builtin (func_obj_p);
|
||||
|
||||
JERRY_ASSERT (routine_id >= ECMA_BUILTIN_ID__COUNT);
|
||||
|
||||
ecma_extended_object_t *ext_func_obj_p = (ecma_extended_object_t *) func_obj_p;
|
||||
ext_func_obj_p->u.built_in.id = builtin_id;
|
||||
ext_func_obj_p->u.built_in.length = length_prop_value;
|
||||
ext_func_obj_p->u.built_in.routine_id = routine_id;
|
||||
ext_func_obj_p->u.built_in.instantiated_bitset = 0;
|
||||
|
||||
return func_obj_p;
|
||||
} /* ecma_builtin_make_function_object_for_routine */
|
||||
|
||||
typedef const ecma_builtin_property_descriptor_t *ecma_builtin_property_list_reference_t;
|
||||
|
||||
static const ecma_builtin_property_list_reference_t ecma_builtin_property_list_references[] =
|
||||
{
|
||||
#define BUILTIN(builtin_id, \
|
||||
object_type, \
|
||||
object_prototype_builtin_id, \
|
||||
is_extensible, \
|
||||
is_static, \
|
||||
lowercase_name) \
|
||||
ecma_builtin_ ## lowercase_name ## _property_descriptor_list,
|
||||
#include "ecma-builtins.inc.h"
|
||||
};
|
||||
|
||||
/**
|
||||
* If the property's name is one of built-in properties of the object
|
||||
* that is not instantiated yet, instantiate the property and
|
||||
* return pointer to the instantiated property.
|
||||
*
|
||||
* @return pointer property, if one was instantiated,
|
||||
* NULL - otherwise.
|
||||
*/
|
||||
ecma_property_t *
|
||||
ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object */
|
||||
ecma_string_t *string_p) /**< property's name */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
|
||||
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
|
||||
&& ecma_builtin_function_is_routine (object_p))
|
||||
{
|
||||
if (ecma_string_is_length (string_p))
|
||||
{
|
||||
/*
|
||||
* Lazy instantiation of 'length' property
|
||||
*
|
||||
* Note:
|
||||
* We don't need to mark that the property was already lazy instantiated,
|
||||
* as it is non-configurable and so can't be deleted
|
||||
*/
|
||||
|
||||
ecma_property_t *len_prop_p;
|
||||
ecma_property_value_t *len_prop_value_p = ecma_create_named_data_property (object_p,
|
||||
string_p,
|
||||
ECMA_PROPERTY_FIXED,
|
||||
&len_prop_p);
|
||||
|
||||
len_prop_value_p->value = ecma_make_integer_value (ext_obj_p->u.built_in.length);
|
||||
|
||||
return len_prop_p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lit_magic_string_id_t magic_string_id;
|
||||
|
||||
if (!ecma_is_string_magic (string_p, &magic_string_id))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) ext_obj_p->u.built_in.id;
|
||||
|
||||
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
|
||||
JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id));
|
||||
|
||||
const ecma_builtin_property_descriptor_t *property_list_p = ecma_builtin_property_list_references[builtin_id];
|
||||
|
||||
const ecma_builtin_property_descriptor_t *curr_property_p = property_list_p;
|
||||
|
||||
while (curr_property_p->magic_string_id != magic_string_id)
|
||||
{
|
||||
if (curr_property_p->magic_string_id == LIT_MAGIC_STRING__COUNT)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
curr_property_p++;
|
||||
}
|
||||
|
||||
uint32_t index = (uint32_t) (curr_property_p - property_list_p);
|
||||
|
||||
JERRY_ASSERT (index < 64);
|
||||
|
||||
if (likely (index < 32))
|
||||
{
|
||||
uint32_t bit_for_index = (uint32_t) 1u << index;
|
||||
|
||||
if (ext_obj_p->u.built_in.instantiated_bitset & bit_for_index)
|
||||
{
|
||||
/* This property was instantiated before. */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ext_obj_p->u.built_in.instantiated_bitset |= bit_for_index;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t bit_for_index = (uint32_t) 1u << (index - 32);
|
||||
ecma_value_t *mask_prop_p = ecma_find_internal_property (object_p,
|
||||
ECMA_INTERNAL_PROPERTY_INSTANTIATED_MASK_32_63);
|
||||
|
||||
uint32_t instantiated_bitset;
|
||||
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
mask_prop_p = ecma_create_internal_property (object_p, ECMA_INTERNAL_PROPERTY_INSTANTIATED_MASK_32_63);
|
||||
instantiated_bitset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
instantiated_bitset = *mask_prop_p;
|
||||
|
||||
if (instantiated_bitset & bit_for_index)
|
||||
{
|
||||
/* This property was instantiated before. */
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
*mask_prop_p = (instantiated_bitset | bit_for_index);
|
||||
}
|
||||
|
||||
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
switch (curr_property_p->type)
|
||||
{
|
||||
case ECMA_BUILTIN_PROPERTY_SIMPLE:
|
||||
{
|
||||
value = ecma_make_simple_value (curr_property_p->value);
|
||||
break;
|
||||
}
|
||||
case ECMA_BUILTIN_PROPERTY_NUMBER:
|
||||
{
|
||||
ecma_number_t num = 0.0;
|
||||
|
||||
if (curr_property_p->value < ECMA_BUILTIN_NUMBER_MAX)
|
||||
{
|
||||
num = curr_property_p->value;
|
||||
}
|
||||
else if (curr_property_p->value < ECMA_BUILTIN_NUMBER_NAN)
|
||||
{
|
||||
static const ecma_number_t builtin_number_list[] =
|
||||
{
|
||||
ECMA_NUMBER_MAX_VALUE,
|
||||
ECMA_NUMBER_MIN_VALUE,
|
||||
ECMA_NUMBER_E,
|
||||
ECMA_NUMBER_PI,
|
||||
ECMA_NUMBER_LN10,
|
||||
ECMA_NUMBER_LN2,
|
||||
ECMA_NUMBER_LOG2E,
|
||||
ECMA_NUMBER_LOG10E,
|
||||
ECMA_NUMBER_SQRT2,
|
||||
ECMA_NUMBER_SQRT_1_2
|
||||
};
|
||||
|
||||
num = builtin_number_list[curr_property_p->value - ECMA_BUILTIN_NUMBER_MAX];
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (curr_property_p->value)
|
||||
{
|
||||
case ECMA_BUILTIN_NUMBER_NAN:
|
||||
{
|
||||
num = ecma_number_make_nan ();
|
||||
break;
|
||||
}
|
||||
case ECMA_BUILTIN_NUMBER_POSITIVE_INFINITY:
|
||||
{
|
||||
num = ecma_number_make_infinity (false);
|
||||
break;
|
||||
}
|
||||
case ECMA_BUILTIN_NUMBER_NEGATIVE_INFINITY:
|
||||
{
|
||||
num = ecma_number_make_infinity (true);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value = ecma_make_number_value (num);
|
||||
break;
|
||||
}
|
||||
case ECMA_BUILTIN_PROPERTY_STRING:
|
||||
{
|
||||
value = ecma_make_string_value (ecma_get_magic_string (curr_property_p->value));
|
||||
break;
|
||||
}
|
||||
case ECMA_BUILTIN_PROPERTY_OBJECT:
|
||||
{
|
||||
value = ecma_make_object_value (ecma_builtin_get (curr_property_p->value));
|
||||
break;
|
||||
}
|
||||
case ECMA_BUILTIN_PROPERTY_ROUTINE:
|
||||
{
|
||||
ecma_object_t *func_obj_p;
|
||||
func_obj_p = ecma_builtin_make_function_object_for_routine (builtin_id,
|
||||
ECMA_GET_ROUTINE_ID (curr_property_p->value),
|
||||
ECMA_GET_ROUTINE_LENGTH (curr_property_p->value));
|
||||
value = ecma_make_object_value (func_obj_p);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ecma_property_t *prop_p;
|
||||
ecma_property_value_t *prop_value_p = ecma_create_named_data_property (object_p,
|
||||
string_p,
|
||||
curr_property_p->attributes,
|
||||
&prop_p);
|
||||
|
||||
prop_value_p->value = value;
|
||||
|
||||
/* Reference count of objects must be decreased. */
|
||||
if (ecma_is_value_object (value))
|
||||
{
|
||||
ecma_free_value (value);
|
||||
}
|
||||
|
||||
return prop_p;
|
||||
} /* ecma_builtin_try_to_instantiate_property */
|
||||
|
||||
/**
|
||||
* List names of a built-in object's lazy instantiated properties
|
||||
*
|
||||
* See also:
|
||||
* ecma_builtin_try_to_instantiate_property
|
||||
*/
|
||||
void
|
||||
ecma_builtin_list_lazy_property_names (ecma_object_t *object_p, /**< a built-in object */
|
||||
bool separate_enumerable, /**< true - list enumerable properties into
|
||||
* main collection, and non-enumerable
|
||||
* to collection of 'skipped non-enumerable'
|
||||
* properties,
|
||||
* false - list all properties into main collection.
|
||||
*/
|
||||
ecma_collection_header_t *main_collection_p, /**< 'main' collection */
|
||||
ecma_collection_header_t *non_enum_collection_p) /**< skipped 'non-enumerable'
|
||||
* collection */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
|
||||
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) object_p;
|
||||
|
||||
if (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
|
||||
&& ecma_builtin_function_is_routine (object_p))
|
||||
{
|
||||
ecma_collection_header_t *for_enumerable_p = main_collection_p;
|
||||
JERRY_UNUSED (for_enumerable_p);
|
||||
|
||||
ecma_collection_header_t *for_non_enumerable_p = separate_enumerable ? non_enum_collection_p : main_collection_p;
|
||||
|
||||
/* 'length' property is non-enumerable (ECMA-262 v5, 15) */
|
||||
ecma_string_t *name_p = ecma_new_ecma_length_string ();
|
||||
ecma_append_to_values_collection (for_non_enumerable_p, ecma_make_string_value (name_p), true);
|
||||
ecma_deref_ecma_string (name_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) ext_obj_p->u.built_in.id;
|
||||
|
||||
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
|
||||
JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id));
|
||||
|
||||
const ecma_builtin_property_descriptor_t *curr_property_p = ecma_builtin_property_list_references[builtin_id];
|
||||
|
||||
ecma_length_t index = 0;
|
||||
uint32_t instantiated_bitset = ext_obj_p->u.built_in.instantiated_bitset;
|
||||
|
||||
ecma_collection_header_t *for_non_enumerable_p = (separate_enumerable ? non_enum_collection_p
|
||||
: main_collection_p);
|
||||
|
||||
while (curr_property_p->magic_string_id != LIT_MAGIC_STRING__COUNT)
|
||||
{
|
||||
JERRY_ASSERT (index < 64);
|
||||
|
||||
if (index == 32)
|
||||
{
|
||||
ecma_value_t *mask_prop_p = ecma_find_internal_property (object_p,
|
||||
ECMA_INTERNAL_PROPERTY_INSTANTIATED_MASK_32_63);
|
||||
|
||||
if (mask_prop_p == NULL)
|
||||
{
|
||||
instantiated_bitset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
instantiated_bitset = *mask_prop_p;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t bit_for_index;
|
||||
if (index >= 32)
|
||||
{
|
||||
bit_for_index = (uint32_t) 1u << (index - 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
bit_for_index = (uint32_t) 1u << index;
|
||||
}
|
||||
|
||||
bool was_instantiated = false;
|
||||
|
||||
if (instantiated_bitset & bit_for_index)
|
||||
{
|
||||
was_instantiated = true;
|
||||
}
|
||||
|
||||
ecma_string_t *name_p = ecma_get_magic_string (curr_property_p->magic_string_id);
|
||||
|
||||
if (!was_instantiated || ecma_op_object_has_own_property (object_p, name_p))
|
||||
{
|
||||
ecma_append_to_values_collection (for_non_enumerable_p,
|
||||
ecma_make_string_value (name_p),
|
||||
true);
|
||||
}
|
||||
|
||||
ecma_deref_ecma_string (name_p);
|
||||
|
||||
curr_property_p++;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_list_lazy_property_names */
|
||||
|
||||
/**
|
||||
* Dispatcher of built-in routines
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value.
|
||||
*/
|
||||
static ecma_value_t
|
||||
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, /**< built-in object' identifier */
|
||||
uint16_t builtin_routine_id, /**< builtin-wide identifier
|
||||
* of the built-in object's
|
||||
* routine property */
|
||||
ecma_value_t this_arg_value, /**< 'this' argument value */
|
||||
const ecma_value_t arguments_list[], /**< list of arguments passed to routine */
|
||||
ecma_length_t arguments_number) /**< length of arguments' list */
|
||||
{
|
||||
switch (builtin_object_id)
|
||||
{
|
||||
#define BUILTIN(builtin_id, \
|
||||
object_type, \
|
||||
object_prototype_builtin_id, \
|
||||
is_extensible, \
|
||||
is_static, \
|
||||
lowercase_name) \
|
||||
case builtin_id: \
|
||||
{ \
|
||||
return ecma_builtin_ ## lowercase_name ## _dispatch_routine (builtin_routine_id, \
|
||||
this_arg_value, \
|
||||
arguments_list, \
|
||||
arguments_number); \
|
||||
}
|
||||
#include "ecma-builtins.inc.h"
|
||||
|
||||
case ECMA_BUILTIN_ID__COUNT:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE (); /* The built-in is not implemented. */
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
} /* ecma_builtin_dispatch_routine */
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
|
||||
ecma_value_t this_arg_value, /**< 'this' argument value */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< arguments list length */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (obj_p));
|
||||
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
if (ecma_builtin_function_is_routine (obj_p))
|
||||
{
|
||||
ret_value = ecma_builtin_dispatch_routine (ext_obj_p->u.built_in.id,
|
||||
ext_obj_p->u.built_in.routine_id,
|
||||
this_arg_value,
|
||||
arguments_list_p,
|
||||
arguments_list_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
|
||||
switch ((ecma_builtin_id_t) ext_obj_p->u.built_in.id)
|
||||
{
|
||||
#define BUILTIN(builtin_id, \
|
||||
object_type, \
|
||||
object_prototype_builtin_id, \
|
||||
is_extensible, \
|
||||
is_static, \
|
||||
lowercase_name) \
|
||||
case builtin_id: \
|
||||
{ \
|
||||
if (object_type == ECMA_OBJECT_TYPE_FUNCTION) \
|
||||
{ \
|
||||
ret_value = ecma_builtin_ ## lowercase_name ## _dispatch_call (arguments_list_p, \
|
||||
arguments_list_len); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
#include "ecma-builtins.inc.h"
|
||||
|
||||
case ECMA_BUILTIN_ID__COUNT:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE (); /* The built-in is not implemented. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_ASSERT (!ecma_is_value_empty (ret_value));
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in object
|
||||
*
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< arguments list length */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (obj_p));
|
||||
|
||||
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
|
||||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
|
||||
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
|
||||
switch (ext_obj_p->u.built_in.id)
|
||||
{
|
||||
#define BUILTIN(builtin_id, \
|
||||
object_type, \
|
||||
object_prototype_builtin_id, \
|
||||
is_extensible, \
|
||||
is_static, \
|
||||
lowercase_name) \
|
||||
case builtin_id: \
|
||||
{ \
|
||||
if (object_type == ECMA_OBJECT_TYPE_FUNCTION) \
|
||||
{ \
|
||||
ret_value = ecma_builtin_ ## lowercase_name ## _dispatch_construct (arguments_list_p, \
|
||||
arguments_list_len); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
#include "ecma-builtins.inc.h"
|
||||
|
||||
case ECMA_BUILTIN_ID__COUNT:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE (); /* The built-in is not implemented. */
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_ASSERT (!ecma_is_value_empty (ret_value));
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
75
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.h
vendored
Normal file
75
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.h
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
/* 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_BUILTINS_H
|
||||
#define ECMA_BUILTINS_H
|
||||
|
||||
#include "ecma-globals.h"
|
||||
|
||||
/**
|
||||
* A built-in object's identifier
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
#define BUILTIN(builtin_id, \
|
||||
object_type, \
|
||||
object_prototype_builtin_id, \
|
||||
is_extensible, \
|
||||
is_static, \
|
||||
lowercase_name) \
|
||||
builtin_id,
|
||||
#include "ecma-builtins.inc.h"
|
||||
ECMA_BUILTIN_ID__COUNT /**< number of built-in objects */
|
||||
} ecma_builtin_id_t;
|
||||
|
||||
/**
|
||||
* Construct a routine value
|
||||
*/
|
||||
#define ECMA_ROUTINE_VALUE(id, length) (((id) << 4) | length)
|
||||
|
||||
/**
|
||||
* Get routine length
|
||||
*/
|
||||
#define ECMA_GET_ROUTINE_LENGTH(value) ((uint8_t) ((value) & 0xf))
|
||||
|
||||
/**
|
||||
* Get routine ID
|
||||
*/
|
||||
#define ECMA_GET_ROUTINE_ID(value) ((uint16_t) ((value) >> 4))
|
||||
|
||||
/* ecma-builtins.c */
|
||||
extern void ecma_finalize_builtins (void);
|
||||
|
||||
extern ecma_value_t
|
||||
ecma_builtin_dispatch_call (ecma_object_t *, ecma_value_t,
|
||||
const ecma_value_t *, ecma_length_t);
|
||||
extern ecma_value_t
|
||||
ecma_builtin_dispatch_construct (ecma_object_t *,
|
||||
const ecma_value_t *, ecma_length_t);
|
||||
extern ecma_property_t *
|
||||
ecma_builtin_try_to_instantiate_property (ecma_object_t *, ecma_string_t *);
|
||||
extern void
|
||||
ecma_builtin_list_lazy_property_names (ecma_object_t *,
|
||||
bool,
|
||||
ecma_collection_header_t *,
|
||||
ecma_collection_header_t *);
|
||||
extern bool
|
||||
ecma_builtin_is (ecma_object_t *, ecma_builtin_id_t);
|
||||
extern ecma_object_t *
|
||||
ecma_builtin_get (ecma_builtin_id_t);
|
||||
extern bool
|
||||
ecma_builtin_function_is_routine (ecma_object_t *);
|
||||
|
||||
#endif /* !ECMA_BUILTINS_H */
|
309
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h
vendored
Normal file
309
third_party/jerryscript/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h
vendored
Normal file
|
@ -0,0 +1,309 @@
|
|||
/* Copyright 2014-2016 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.
|
||||
*/
|
||||
|
||||
/* Description of built-in objects
|
||||
in format (ECMA_BUILTIN_ID_id, object_type, prototype_id, is_extensible, is_static, underscored_id) */
|
||||
|
||||
/* The Object.prototype object (15.2.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID__COUNT /* no prototype */,
|
||||
true,
|
||||
true,
|
||||
object_prototype)
|
||||
|
||||
/* The Object object (15.2.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_OBJECT,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
object)
|
||||
|
||||
#ifndef CONFIG_DISABLE_ARRAY_BUILTIN
|
||||
/* The Array.prototype object (15.4.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_ARRAY,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
array_prototype)
|
||||
|
||||
/* The Array object (15.4.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
array)
|
||||
#endif /* !CONFIG_DISABLE_ARRAY_BUILTIN*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_STRING_BUILTIN
|
||||
/* The String.prototype object (15.5.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_STRING_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
string_prototype)
|
||||
|
||||
/* The String object (15.5.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_STRING,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
string)
|
||||
#endif /* !CONFIG_DISABLE_STRING_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
|
||||
/* The Boolean.prototype object (15.6.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
boolean_prototype)
|
||||
|
||||
/* The Boolean object (15.6.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
boolean)
|
||||
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_NUMBER_BUILTIN
|
||||
/* The Number.prototype object (15.7.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
number_prototype)
|
||||
|
||||
/* The Number object (15.7.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_NUMBER,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
number)
|
||||
#endif /* !CONFIG_DISABLE_NUMBER_BUILTIN */
|
||||
|
||||
/* The Function.prototype object (15.3.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
function_prototype)
|
||||
|
||||
/* The Function object (15.3.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_FUNCTION,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
function)
|
||||
|
||||
#ifndef CONFIG_DISABLE_MATH_BUILTIN
|
||||
/* The Math object (15.8) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_MATH,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
math)
|
||||
#endif /* !CONFIG_DISABLE_MATH_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_JSON_BUILTIN
|
||||
/* The JSON object (15.12) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_JSON,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
json)
|
||||
#endif /* !CONFIG_DISABLE_JSON_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_DATE_BUILTIN
|
||||
/* The Date.prototype object (15.9.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_DATE_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
date_prototype)
|
||||
|
||||
/* The Date object (15.9.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_DATE,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
date)
|
||||
#endif /* !CONFIG_DISABLE_DATE_BUILTIN */
|
||||
|
||||
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
|
||||
/* The RegExp.prototype object (15.10.6) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
regexp_prototype)
|
||||
|
||||
/* The RegExp object (15.10) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_REGEXP,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
regexp)
|
||||
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
|
||||
|
||||
/* The Error object (15.11.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
error)
|
||||
|
||||
/* The Error.prototype object (15.11.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
error_prototype)
|
||||
|
||||
#ifndef CONFIG_DISABLE_ERROR_BUILTINS
|
||||
/* The EvalError.prototype object (15.11.6.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
eval_error_prototype)
|
||||
|
||||
/* The EvalError object (15.11.6.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_EVAL_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
eval_error)
|
||||
|
||||
/* The RangeError.prototype object (15.11.6.2) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
range_error_prototype)
|
||||
|
||||
/* The RangeError object (15.11.6.2) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_RANGE_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
range_error)
|
||||
|
||||
/* The ReferenceError.prototype object (15.11.6.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
reference_error_prototype)
|
||||
|
||||
/* The ReferenceError object (15.11.6.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_REFERENCE_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
reference_error)
|
||||
|
||||
/* The SyntaxError.prototype object (15.11.6.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
syntax_error_prototype)
|
||||
|
||||
/* The SyntaxError object (15.11.6.4) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_SYNTAX_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
syntax_error)
|
||||
|
||||
/* The TypeError.prototype object (15.11.6.5) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
type_error_prototype)
|
||||
|
||||
/* The TypeError object (15.11.6.5) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_TYPE_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
type_error)
|
||||
|
||||
/* The URIError.prototype object (15.11.6.6) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
uri_error_prototype)
|
||||
|
||||
/* The URIError object (15.11.6.6) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_URI_ERROR,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
true,
|
||||
uri_error)
|
||||
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
|
||||
|
||||
/**< The [[ThrowTypeError]] object (13.2.3) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
false,
|
||||
true,
|
||||
type_error_thrower)
|
||||
|
||||
/* The Global object (15.1) */
|
||||
BUILTIN (ECMA_BUILTIN_ID_GLOBAL,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, /* Implementation-dependent */
|
||||
true,
|
||||
true,
|
||||
global)
|
||||
|
||||
#undef BUILTIN
|
Loading…
Add table
Add a link
Reference in a new issue