diff --git a/src/libecmabuiltins/ecma-builtin-global-object.c b/src/libecmabuiltins/ecma-builtin-global-object.c index 657cf9a8c..1bbf32f8a 100644 --- a/src/libecmabuiltins/ecma-builtin-global-object.c +++ b/src/libecmabuiltins/ecma-builtin-global-object.c @@ -108,6 +108,235 @@ ecma_builtin_finalize_global_object (void) ecma_global_object_p = NULL; } /* ecma_builtin_finalize_global_object */ +/** + * The Global object's 'eval' routine + * + * See also: + * ECMA-262 v5, 15.1.2.1 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value. + */ +static ecma_completion_value_t +ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (x); +} /* ecma_builtin_global_object_eval */ + +/** + * The Global object's 'parseInt' routine + * + * See also: + * ECMA-262 v5, 15.1.2.2 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value. + */ +static ecma_completion_value_t +ecma_builtin_global_object_parse_int (ecma_value_t string, /**< routine's first argument */ + ecma_value_t radix) /**< routine's second argument */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (string, radix); +} /* ecma_builtin_global_object_parse_int */ + +/** + * The Global object's 'parseFloat' routine + * + * See also: + * ECMA-262 v5, 15.1.2.3 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value. + */ +static ecma_completion_value_t +ecma_builtin_global_object_parse_float (ecma_value_t string) /**< routine's first argument */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (string); +} /* ecma_builtin_global_object_parse_float */ + +/** + * The Global object's 'isNaN' routine + * + * See also: + * ECMA-262 v5, 15.1.2.4 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value. + */ +static ecma_completion_value_t +ecma_builtin_global_object_is_nan (ecma_value_t number) /**< routine's first argument */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (number); +} /* ecma_builtin_global_object_is_nan */ + +/** + * The Global object's 'isFinite' routine + * + * See also: + * ECMA-262 v5, 15.1.2.5 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value. + */ +static ecma_completion_value_t +ecma_builtin_global_object_is_finite (ecma_value_t number) /**< routine's first argument */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (number); +} /* ecma_builtin_global_object_is_finite */ + +/** + * The Global object's 'decodeURI' routine + * + * See also: + * ECMA-262 v5, 15.1.3.1 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value. + */ +static ecma_completion_value_t +ecma_builtin_global_object_decode_uri (ecma_value_t encoded_uri) /**< routine's first argument */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (encoded_uri); +} /* ecma_builtin_global_object_decode_uri */ + +/** + * The Global object's 'decodeURIComponent' routine + * + * See also: + * ECMA-262 v5, 15.1.3.2 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value. + */ +static ecma_completion_value_t +ecma_builtin_global_object_decode_uri_component (ecma_value_t encoded_uri_component) /**< routine's first argument */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (encoded_uri_component); +} /* ecma_builtin_global_object_decode_uri_component */ + +/** + * The Global object's 'encodeURI' routine + * + * See also: + * ECMA-262 v5, 15.1.3.3 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value. + */ +static ecma_completion_value_t +ecma_builtin_global_object_encode_uri (ecma_value_t uri) /**< routine's first argument */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (uri); +} /* ecma_builtin_global_object_encode_uri */ + +/** + * The Global object's 'encodeURIComponent' routine + * + * See also: + * ECMA-262 v5, 15.1.3.4 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value. + */ +static ecma_completion_value_t +ecma_builtin_global_object_encode_uri_component (ecma_value_t uri_component) /**< routine's first argument */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (uri_component); +} /* ecma_builtin_global_object_encode_uri_component */ + +/** + * Dispatcher of the Global object's built-in routines + * + * @return completion-value + * Returned value must be freed with ecma_free_completion_value. + */ +ecma_completion_value_t +ecma_builtin_global_dispatch_routine (ecma_builtin_global_property_id_t builtin_routine_id, /**< identifier of + the Global object's + initial property that + corresponds to + routine to be called */ + ecma_value_t arguments_list [], /**< list of arguments passed to routine */ + ecma_length_t arguments_number) /**< length of arguments' list */ +{ + ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); + const ecma_value_t value_undefined = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED); + + switch (builtin_routine_id) + { + case ECMA_BUILTIN_GLOBAL_PROPERTY_ID_EVAL: + { + ecma_value_t arg = (arguments_number >= 1 ? arguments_list[0] : value_undefined); + + return ecma_builtin_global_object_eval (arg); + } + + case ECMA_BUILTIN_GLOBAL_PROPERTY_ID_PARSE_INT: + { + ecma_value_t arg1 = (arguments_number >= 1 ? arguments_list[0] : value_undefined); + ecma_value_t arg2 = (arguments_number >= 2 ? arguments_list[1] : value_undefined); + + return ecma_builtin_global_object_parse_int (arg1, arg2); + } + + case ECMA_BUILTIN_GLOBAL_PROPERTY_ID_PARSE_FLOAT: + { + ecma_value_t arg = (arguments_number >= 1 ? arguments_list[0] : value_undefined); + + return ecma_builtin_global_object_parse_float (arg); + } + + case ECMA_BUILTIN_GLOBAL_PROPERTY_ID_IS_NAN: + { + ecma_value_t arg = (arguments_number >= 1 ? arguments_list[0] : value_undefined); + + return ecma_builtin_global_object_is_nan (arg); + } + + case ECMA_BUILTIN_GLOBAL_PROPERTY_ID_IS_FINITE: + { + ecma_value_t arg = (arguments_number >= 1 ? arguments_list[0] : value_undefined); + + return ecma_builtin_global_object_is_finite (arg); + } + + case ECMA_BUILTIN_GLOBAL_PROPERTY_ID_DECODE_URI: + { + ecma_value_t arg = (arguments_number >= 1 ? arguments_list[0] : value_undefined); + + return ecma_builtin_global_object_decode_uri (arg); + } + + case ECMA_BUILTIN_GLOBAL_PROPERTY_ID_DECODE_URI_COMPONENT: + { + ecma_value_t arg = (arguments_number >= 1 ? arguments_list[0] : value_undefined); + + return ecma_builtin_global_object_decode_uri_component (arg); + } + + case ECMA_BUILTIN_GLOBAL_PROPERTY_ID_ENCODE_URI: + { + ecma_value_t arg = (arguments_number >= 1 ? arguments_list[0] : value_undefined); + + return ecma_builtin_global_object_encode_uri (arg); + } + + case ECMA_BUILTIN_GLOBAL_PROPERTY_ID_ENCODE_URI_COMPONENT: + { + ecma_value_t arg = (arguments_number >= 1 ? arguments_list[0] : value_undefined); + + return ecma_builtin_global_object_encode_uri_component (arg); + } + + default: + { + JERRY_UNREACHABLE (); + } + } + + JERRY_ASSERT (!ecma_is_completion_value_empty (ret_value)); +} /* ecma_builtin_global_dispatch_routine */ + /** * @} * @} diff --git a/src/libecmabuiltins/ecma-builtin-routines-dispatcher.c b/src/libecmabuiltins/ecma-builtin-routines-dispatcher.c new file mode 100644 index 000000000..3fb604adc --- /dev/null +++ b/src/libecmabuiltins/ecma-builtin-routines-dispatcher.c @@ -0,0 +1,91 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "globals.h" +#include "ecma-builtins.h" +#include "ecma-globals.h" +#include "ecma-magic-strings.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + */ + +/** + * Dispatcher of built-in routines + * + * @return completion-value + * Returned value must be freed with ecma_free_completion_value. + */ +ecma_completion_value_t +ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, /**< built-in object' identifier */ + uint32_t builtin_routine_id, /**< identifier of the built-in object's routine + property (one of ecma_builtin_{*}_property_id_t) */ + ecma_value_t arguments_list [], /**< list of arguments passed to routine */ + ecma_length_t arguments_number) /**< length of arguments' list */ +{ + switch (builtin_object_id) + { + case ECMA_BUILTIN_ID_GLOBAL: + { + JERRY_ASSERT (builtin_routine_id < ECMA_BUILTIN_GLOBAL_PROPERTY_ID__COUNT); + return ecma_builtin_global_dispatch_routine ((ecma_builtin_global_property_id_t) builtin_routine_id, + arguments_list, arguments_number); + } + case ECMA_BUILTIN_ID_OBJECT: + case ECMA_BUILTIN_ID_OBJECT_PROTOTYPE: + case ECMA_BUILTIN_ID_FUNCTION: + case ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE: + case ECMA_BUILTIN_ID_ARRAY: + case ECMA_BUILTIN_ID_ARRAY_PROTOTYPE: + case ECMA_BUILTIN_ID_STRING: + case ECMA_BUILTIN_ID_STRING_PROTOTYPE: + case ECMA_BUILTIN_ID_BOOLEAN: + case ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE: + case ECMA_BUILTIN_ID_NUMBER: + case ECMA_BUILTIN_ID_NUMBER_PROTOTYPE: + case ECMA_BUILTIN_ID_DATE: + case ECMA_BUILTIN_ID_REGEXP: + case ECMA_BUILTIN_ID_REGEXP_PROTOTYPE: + case ECMA_BUILTIN_ID_ERROR: + case ECMA_BUILTIN_ID_ERROR_PROTOTYPE: + case ECMA_BUILTIN_ID_EVAL_ERROR: + case ECMA_BUILTIN_ID_RANGE_ERROR: + case ECMA_BUILTIN_ID_REFERENCE_ERROR: + case ECMA_BUILTIN_ID_SYNTAX_ERROR: + case ECMA_BUILTIN_ID_TYPE_ERROR: + case ECMA_BUILTIN_ID_SYNTAX_URI_ERROR: + case ECMA_BUILTIN_ID_MATH: + case ECMA_BUILTIN_ID_JSON: + { + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (builtin_routine_id, + arguments_list, + arguments_number); + } + } + + JERRY_UNREACHABLE (); +} /* ecma_builtin_dispatch_routine */ + + +/** + * @} + * @} + */ diff --git a/src/libecmabuiltins/ecma-builtins-internal.h b/src/libecmabuiltins/ecma-builtins-internal.h index 13fdf44fe..9e24d7125 100644 --- a/src/libecmabuiltins/ecma-builtins-internal.h +++ b/src/libecmabuiltins/ecma-builtins-internal.h @@ -22,10 +22,96 @@ #include "ecma-globals.h" +/** + * A built-in object's identifier + */ +typedef enum +{ + ECMA_BUILTIN_ID_GLOBAL, /**< the Global object (15.1) */ + ECMA_BUILTIN_ID_OBJECT, /**< the Object object (15.2.1) */ + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, /**< the Object object (15.2.4) */ + ECMA_BUILTIN_ID_FUNCTION, /**< the Function object (15.3.1) */ + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, /**< the Function object (15.3.4) */ + ECMA_BUILTIN_ID_ARRAY, /**< the Array object (15.4.1) */ + ECMA_BUILTIN_ID_ARRAY_PROTOTYPE, /**< the Array object (15.4.4) */ + ECMA_BUILTIN_ID_STRING, /**< the String object (15.5.1) */ + ECMA_BUILTIN_ID_STRING_PROTOTYPE, /**< the String object (15.5.4) */ + ECMA_BUILTIN_ID_BOOLEAN, /**< the Boolean object (15.6.1) */ + ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE, /**< the Boolean object (15.6.4) */ + ECMA_BUILTIN_ID_NUMBER, /**< the Number object (15.7.1) */ + ECMA_BUILTIN_ID_NUMBER_PROTOTYPE, /**< the Number object (15.7.4) */ + ECMA_BUILTIN_ID_DATE, /**< the Date object (15.9.2) */ + ECMA_BUILTIN_ID_REGEXP, /**< the RegExp object (15.10.3) */ + ECMA_BUILTIN_ID_REGEXP_PROTOTYPE, /**< the RegExp object (15.10.6) */ + ECMA_BUILTIN_ID_ERROR, /**< the Error object (15.11.1) */ + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, /**< the Error object (15.11.4) */ + ECMA_BUILTIN_ID_EVAL_ERROR, /**< the EvalError object (15.11.6.1) */ + ECMA_BUILTIN_ID_RANGE_ERROR, /**< the RangeError object (15.11.6.2) */ + ECMA_BUILTIN_ID_REFERENCE_ERROR, /**< the ReferenceError object (15.11.6.3) */ + ECMA_BUILTIN_ID_SYNTAX_ERROR, /**< the SyntaxError object (15.11.6.4) */ + ECMA_BUILTIN_ID_TYPE_ERROR, /**< the SyntaxError object (15.11.6.5) */ + ECMA_BUILTIN_ID_SYNTAX_URI_ERROR, /**< the URIError object (15.11.6.6) */ + ECMA_BUILTIN_ID_MATH, /**< the Math object (15.8) */ + ECMA_BUILTIN_ID_JSON /**< the JSON object (15.12) */ +} ecma_builtin_id_t; + +/** + * Identifier of an Global object's property + */ +typedef enum +{ + /* Non-object value properties */ + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_NAN, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_INFINITY, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_UNDEFINED, + + /* Object value properties */ + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_OBJECT, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_FUNCTION, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_ARRAY, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_STRING, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_BOOLEAN, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_NUMBER, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_DATE, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_REGEXP, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_ERROR, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_RANGE_ERROR, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_REFERENCE_ERROR, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_SYNTAX_ERROR, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_SYNTAX_URI_ERROR, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_MATH, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_JSON, + + /* Routine properties */ + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_EVAL, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_PARSE_INT, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_PARSE_FLOAT, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_IS_NAN, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_IS_FINITE, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_DECODE_URI, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_DECODE_URI_COMPONENT, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_ENCODE_URI, + ECMA_BUILTIN_GLOBAL_PROPERTY_ID_ENCODE_URI_COMPONENT, + + ECMA_BUILTIN_GLOBAL_PROPERTY_ID__COUNT +} ecma_builtin_global_property_id_t; + +/* ecma-builtin-routines-dispatcher.c */ +extern ecma_completion_value_t +ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, + uint32_t builtin_routine_id, + ecma_value_t arguments_list[], + ecma_length_t arguments_number); + /* ecma-builtin-global-object.c */ extern void ecma_builtin_init_global_object (void); extern void ecma_builtin_finalize_global_object (void); +extern ecma_completion_value_t +ecma_builtin_global_dispatch_routine (ecma_builtin_global_property_id_t builtin_routine_id, + ecma_value_t arguments_list [], + ecma_length_t arguments_number); + /* ecma-builtin-object-object.c */ extern void ecma_builtin_init_object_object (void); extern void ecma_builtin_finalize_object_object (void);