diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index 5acb0ce03..e803d618e 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -348,7 +348,7 @@ run_int (void) start_pos++; } - ecma_init_builtins (); + ecma_init (); ecma_object_t *glob_obj_p = ecma_builtin_get_global_object (); @@ -372,7 +372,7 @@ run_int (void) { ecma_deref_object (glob_obj_p); ecma_deref_object (lex_env_p); - ecma_finalize_builtins (); + ecma_finalize (); ecma_gc_run (ECMA_GC_GEN_COUNT - 1); return ecma_is_value_true (completion.u.value); diff --git a/src/libcoreint/opcodes-ecma-support.h b/src/libcoreint/opcodes-ecma-support.h index 48ed859f1..53429404b 100644 --- a/src/libcoreint/opcodes-ecma-support.h +++ b/src/libcoreint/opcodes-ecma-support.h @@ -24,12 +24,13 @@ #include "ecma-function-object.h" #include "ecma-gc.h" #include "ecma-helpers.h" -#include "ecma-magic-strings.h" +#include "ecma-lex-env.h" #include "ecma-number-arithmetic.h" -#include "ecma-operations.h" -#include "ecma-try-catch-macro.h" #include "ecma-objects.h" #include "ecma-objects-general.h" +#include "ecma-operations.h" +#include "ecma-reference.h" +#include "ecma-try-catch-macro.h" bool is_reg_variable (int_data_t *int_data, idx_t var_idx); ecma_completion_value_t get_variable_value (int_data_t *, idx_t, bool); diff --git a/src/libecmabuiltins/ecma-builtin-global-object.c b/src/libecmabuiltins/ecma-builtin-global-object.c index d95266cd3..831bb9f25 100644 --- a/src/libecmabuiltins/ecma-builtin-global-object.c +++ b/src/libecmabuiltins/ecma-builtin-global-object.c @@ -18,7 +18,6 @@ #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-helpers.h" -#include "ecma-magic-strings.h" #define ECMA_BUILTINS_INTERNAL #include "ecma-builtins-internal.h" diff --git a/src/libecmabuiltins/ecma-builtins.c b/src/libecmabuiltins/ecma-builtins.c index f54e3c2ea..cf115fd40 100644 --- a/src/libecmabuiltins/ecma-builtins.c +++ b/src/libecmabuiltins/ecma-builtins.c @@ -17,7 +17,6 @@ #include "ecma-builtins.h" #include "ecma-globals.h" #include "ecma-helpers.h" -#include "ecma-magic-strings.h" #include "ecma-objects.h" #include "jrt-bit-fields.h" diff --git a/src/libecmaobjects/ecma-globals.h b/src/libecmaobjects/ecma-globals.h index 872e81bf6..8a7ad3521 100644 --- a/src/libecmaobjects/ecma-globals.h +++ b/src/libecmaobjects/ecma-globals.h @@ -615,7 +615,8 @@ typedef enum stored locally in the string's descriptor */ ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< actual data is UInt32-represeneted Number stored locally in the string's descriptor */ - ECMA_STRING_CONTAINER_CONCATENATION /**< the ecma-string is concatenation of two specified ecma-strings */ + ECMA_STRING_CONTAINER_CONCATENATION, /**< the ecma-string is concatenation of two specified ecma-strings */ + ECMA_STRING_CONTAINER_MAGIC_STRING /**< the ecma-string is equal to one of ECMA magic strings */ } ecma_string_container_t; FIXME (Move to library that should define the type (libserializer /* ? */)) @@ -624,6 +625,31 @@ FIXME (Move to library that should define the type (libserializer /* ? */)) */ typedef uint32_t literal_index_t; +/** + * Identifiers of ECMA magic string constants + */ +typedef enum +{ + ECMA_MAGIC_STRING_ARGUMENTS, /**< "arguments" */ + ECMA_MAGIC_STRING_EVAL, /**< "eval" */ + ECMA_MAGIC_STRING_PROTOTYPE, /**< "prototype" */ + ECMA_MAGIC_STRING_CONSTRUCTOR, /**< "constructor" */ + ECMA_MAGIC_STRING_CALLER, /**< "caller" */ + ECMA_MAGIC_STRING_CALLEE, /**< "callee" */ + ECMA_MAGIC_STRING_UNDEFINED, /**< "undefined" */ + ECMA_MAGIC_STRING_NULL, /**< "null" */ + ECMA_MAGIC_STRING_FALSE, /**< "false" */ + ECMA_MAGIC_STRING_TRUE, /**< "true" */ + ECMA_MAGIC_STRING_NUMBER, /**< "number" */ + ECMA_MAGIC_STRING_STRING, /**< "string" */ + ECMA_MAGIC_STRING_OBJECT, /**< "object" */ + ECMA_MAGIC_STRING_FUNCTION, /**< "function" */ + ECMA_MAGIC_STRING_LENGTH, /**< "length" */ + ECMA_MAGIC_STRING_NAN, /**< "NaN" */ + ECMA_MAGIC_STRING_INFINITY, /**< "Infinity" */ + ECMA_MAGIC_STRING__COUNT /**< number of magic strings */ +} ecma_magic_string_id_t; + /** * ECMA string-value descriptor */ @@ -664,6 +690,9 @@ typedef struct unsigned int string1_cp : ECMA_POINTER_FIELD_WIDTH; unsigned int string2_cp : ECMA_POINTER_FIELD_WIDTH; } concatenation; + + /** Identifier of magic string */ + ecma_magic_string_id_t magic_string_id; } u; } ecma_string_t; diff --git a/src/libecmaobjects/ecma-helpers-conversion.c b/src/libecmaobjects/ecma-helpers-conversion.c index c20643a30..16a6cbebd 100644 --- a/src/libecmaobjects/ecma-helpers-conversion.c +++ b/src/libecmaobjects/ecma-helpers-conversion.c @@ -22,7 +22,6 @@ #include "ecma-globals.h" #include "ecma-helpers.h" -#include "ecma-magic-strings.h" #include "jerry-libc.h" /** diff --git a/src/libecmaobjects/ecma-helpers-string.c b/src/libecmaobjects/ecma-helpers-string.c index 297f68f38..33b0c456a 100644 --- a/src/libecmaobjects/ecma-helpers-string.c +++ b/src/libecmaobjects/ecma-helpers-string.c @@ -45,6 +45,36 @@ JERRY_STATIC_ASSERT ((uint32_t) ((int32_t) ECMA_STRING_MAX_CONCATENATION_LENGTH) == ECMA_STRING_MAX_CONCATENATION_LENGTH); +/** + * Lengths of magic strings + */ +static ecma_length_t ecma_magic_string_lengths [ECMA_MAGIC_STRING__COUNT]; + +/** + * Maximum length among lengths of magic strings + */ +static ecma_length_t ecma_magic_string_max_length; + +/** + * Initialize data for string helpers + */ +void +ecma_strings_init (void) +{ + /* Initializing magic strings information */ + + ecma_magic_string_max_length = 0; + + for (ecma_magic_string_id_t id = 0; + id < ECMA_MAGIC_STRING__COUNT; + id++) + { + ecma_magic_string_lengths [id] = ecma_zt_string_length (ecma_get_magic_string_zt (id)); + + ecma_magic_string_max_length = JERRY_MAX (ecma_magic_string_max_length, ecma_magic_string_lengths [id]); + } +} /* ecma_strings_init */ + /** * Allocate new ecma-string and fill it with characters from specified buffer * @@ -180,7 +210,7 @@ ecma_new_ecma_string_from_number (ecma_number_t num) /**< ecma-number */ } /* ecma_new_ecma_string_from_number */ /** - * Allocate new ecma-string and fill it with reference string literal + * Allocate new ecma-string and fill it with reference to string literal * * @return pointer to ecma-string descriptor */ @@ -320,6 +350,7 @@ ecma_deref_ecma_string (ecma_string_t *string_p) /**< ecma-string */ case ECMA_STRING_CONTAINER_CHARS_IN_DESC: case ECMA_STRING_CONTAINER_LIT_TABLE: case ECMA_STRING_CONTAINER_UINT32_IN_DESC: + case ECMA_STRING_CONTAINER_MAGIC_STRING: { /* only the string descriptor itself should be freed */ } @@ -356,6 +387,7 @@ ecma_string_to_number (const ecma_string_t *str_p) /**< ecma-string */ case ECMA_STRING_CONTAINER_LIT_TABLE: case ECMA_STRING_CONTAINER_HEAP_CHUNKS: case ECMA_STRING_CONTAINER_CONCATENATION: + case ECMA_STRING_CONTAINER_MAGIC_STRING: { ecma_char_t zt_string_buffer [ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1]; @@ -515,6 +547,19 @@ ecma_string_to_zt_string (const ecma_string_t *string_desc_p, /**< ecma-string d break; } + case ECMA_STRING_CONTAINER_MAGIC_STRING: + { + const ecma_magic_string_id_t id = string_desc_p->u.magic_string_id; + const size_t length = ecma_magic_string_lengths [id]; + + JERRY_ASSERT (length == (size_t) ecma_string_get_length (string_desc_p)); + + size_t bytes_to_copy = (length + 1) * sizeof (ecma_char_t); + + __memcpy (buffer_p, ecma_get_magic_string_zt (id), bytes_to_copy); + + bytes_copied = (ssize_t) bytes_to_copy; + } } JERRY_ASSERT (bytes_copied > 0 && bytes_copied <= required_buffer_size); @@ -791,6 +836,10 @@ ecma_compare_ecma_strings (const ecma_string_t *string1_p, /* ecma-string */ { return (string1_p->u.uint32_number == string2_p->u.uint32_number); } + case ECMA_STRING_CONTAINER_MAGIC_STRING: + { + return (string1_p->u.magic_string_id == string2_p->u.magic_string_id); + } case ECMA_STRING_CONTAINER_CONCATENATION: { /* long path */ @@ -1141,6 +1190,137 @@ ecma_zt_string_length (const ecma_char_t *string_p) /**< zero-terminated string return length; } /* ecma_zt_string_length */ +/** + * Allocate new ecma-string and fill it with reference to ECMA magic string + * + * @return pointer to ecma-string descriptor + */ +ecma_string_t* +ecma_new_ecma_string_from_magic_string_id (ecma_magic_string_id_t id) /**< identifier of magic string */ +{ + JERRY_ASSERT (id < ECMA_MAGIC_STRING__COUNT); + + ecma_string_t* string_desc_p = ecma_alloc_string (); + string_desc_p->refs = 1; + + string_desc_p->length = ecma_magic_string_lengths [id]; + string_desc_p->container = ECMA_STRING_CONTAINER_MAGIC_STRING; + + string_desc_p->u.magic_string_id = id; + + return string_desc_p; +} /* ecma_new_ecma_string_from_magic_string_id */ + +/** + * Get specified magic string as zero-terminated string + * + * @return pointer to zero-terminated magic string + */ +const ecma_char_t* +ecma_get_magic_string_zt (ecma_magic_string_id_t id) /**< magic string id */ +{ + TODO(Support UTF-16); + + switch (id) + { + case ECMA_MAGIC_STRING_ARGUMENTS: return (ecma_char_t*) "arguments"; + case ECMA_MAGIC_STRING_EVAL: return (ecma_char_t*) "eval"; + case ECMA_MAGIC_STRING_PROTOTYPE: return (ecma_char_t*) "prototype"; + case ECMA_MAGIC_STRING_CONSTRUCTOR: return (ecma_char_t*) "constructor"; + case ECMA_MAGIC_STRING_CALLER: return (ecma_char_t*) "caller"; + case ECMA_MAGIC_STRING_CALLEE: return (ecma_char_t*) "callee"; + case ECMA_MAGIC_STRING_UNDEFINED: return (ecma_char_t*) "undefined"; + case ECMA_MAGIC_STRING_NULL: return (ecma_char_t*) "null"; + case ECMA_MAGIC_STRING_FALSE: return (ecma_char_t*) "false"; + case ECMA_MAGIC_STRING_TRUE: return (ecma_char_t*) "true"; + case ECMA_MAGIC_STRING_NUMBER: return (ecma_char_t*) "number"; + case ECMA_MAGIC_STRING_STRING: return (ecma_char_t*) "string"; + case ECMA_MAGIC_STRING_OBJECT: return (ecma_char_t*) "object"; + case ECMA_MAGIC_STRING_FUNCTION: return (ecma_char_t*) "function"; + case ECMA_MAGIC_STRING_LENGTH: return (ecma_char_t*) "length"; + case ECMA_MAGIC_STRING_NAN: return (ecma_char_t*) "NaN"; + case ECMA_MAGIC_STRING_INFINITY: return (ecma_char_t*) "Infinity"; + case ECMA_MAGIC_STRING__COUNT: break; + } + + JERRY_UNREACHABLE(); +} /* ecma_get_magic_string_zt */ + +/** + * Get specified magic string + * + * @return ecma-string containing specified magic string + */ +ecma_string_t* +ecma_get_magic_string (ecma_magic_string_id_t id) /**< magic string id */ +{ + return ecma_new_ecma_string (ecma_get_magic_string_zt (id)); +} /* ecma_get_magic_string */ + +/** + * Check if passed zt-string equals to one of magic strings + * and if equal magic string was found, return it's id in 'out_id_p' argument. + * + * @return true - if magic string equal to passed string was found, + * false - otherwise. + */ +bool +ecma_is_zt_string_magic (ecma_char_t *zt_string_p, /**< zero-terminated string */ + ecma_magic_string_id_t *out_id_p) /**< out: magic string's id */ +{ + TODO (Improve performance of search); + + for (ecma_magic_string_id_t id = 0; + id < ECMA_MAGIC_STRING__COUNT; + id++) + { + if (ecma_compare_zt_strings (zt_string_p, ecma_get_magic_string_zt (id))) + { + *out_id_p = id; + + return true; + } + } + + *out_id_p = ECMA_MAGIC_STRING__COUNT; + + return false; +} /* ecma_is_zt_string_magic */ + +/** + * Check if passed string equals to one of magic strings + * and if equal magic string was found, return it's id in 'out_id_p' argument. + * + * @return true - if magic string equal to passed string was found, + * false - otherwise. + */ +bool +ecma_is_string_magic (ecma_string_t *string_p, /**< ecma-string */ + ecma_magic_string_id_t *out_id_p) /**< out: magic string's id */ +{ + if (string_p->container == ECMA_STRING_CONTAINER_MAGIC_STRING) + { + JERRY_ASSERT (string_p->u.magic_string_id < ECMA_MAGIC_STRING__COUNT); + + *out_id_p = (ecma_magic_string_id_t) string_p->u.magic_string_id; + + return true; + } + else if (ecma_string_get_length (string_p) > ecma_magic_string_max_length) + { + return false; + } + else + { + ecma_char_t zt_string_buffer [ecma_magic_string_max_length + 1]; + + ssize_t copied = ecma_string_to_zt_string (string_p, zt_string_buffer, (ssize_t) sizeof (zt_string_buffer)); + JERRY_ASSERT (copied > 0); + + return ecma_is_zt_string_magic (zt_string_buffer, out_id_p); + } +} /* ecma_is_string_magic */ + /** * @} * @} diff --git a/src/libecmaobjects/ecma-helpers.h b/src/libecmaobjects/ecma-helpers.h index fb6c66c30..560eb3d23 100644 --- a/src/libecmaobjects/ecma-helpers.h +++ b/src/libecmaobjects/ecma-helpers.h @@ -100,6 +100,7 @@ extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p); extern ecma_string_t* ecma_new_ecma_string_from_uint32 (uint32_t uint_number); extern ecma_string_t* ecma_new_ecma_string_from_number (ecma_number_t number); extern ecma_string_t* ecma_new_ecma_string_from_lit_index (literal_index_t lit_index); +extern ecma_string_t* ecma_new_ecma_string_from_magic_string_id (ecma_magic_string_id_t id); extern ecma_string_t* ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t *string2_p); extern void ecma_ref_ecma_string (ecma_string_t *string_desc_p); extern void ecma_deref_ecma_string (ecma_string_t *string_p); @@ -117,6 +118,12 @@ extern bool ecma_compare_zt_strings_relational (const ecma_char_t *string1_p, co extern ssize_t ecma_copy_zt_string_to_buffer (const ecma_char_t *string_p, ecma_char_t *buffer_p, ssize_t buffer_size); extern ecma_length_t ecma_zt_string_length (const ecma_char_t *string_p); +extern void ecma_strings_init (void); +extern const ecma_char_t* ecma_get_magic_string_zt (ecma_magic_string_id_t id); +extern ecma_string_t* ecma_get_magic_string (ecma_magic_string_id_t id); +extern bool ecma_is_string_magic (ecma_string_t *string_p, ecma_magic_string_id_t *out_id_p); +extern bool ecma_is_zt_string_magic (ecma_char_t *zt_string_p, ecma_magic_string_id_t *out_id_p); + /* ecma-helpers-number.c */ extern ecma_number_t ecma_number_make_nan (void); extern ecma_number_t ecma_number_make_infinity (bool sign); diff --git a/src/libecmaoperations/ecma-array-object.c b/src/libecmaoperations/ecma-array-object.c index 12707d10f..2b5c46a96 100644 --- a/src/libecmaoperations/ecma-array-object.c +++ b/src/libecmaoperations/ecma-array-object.c @@ -18,7 +18,6 @@ #include "ecma-exceptions.h" #include "ecma-globals.h" #include "ecma-helpers.h" -#include "ecma-magic-strings.h" #include "ecma-number-arithmetic.h" #include "ecma-objects.h" #include "ecma-objects-general.h" diff --git a/src/libecmaoperations/ecma-conversion.c b/src/libecmaoperations/ecma-conversion.c index b6c98031d..3e1de5223 100644 --- a/src/libecmaoperations/ecma-conversion.c +++ b/src/libecmaoperations/ecma-conversion.c @@ -21,7 +21,7 @@ #include "ecma-conversion.h" #include "ecma-exceptions.h" #include "ecma-globals.h" -#include "ecma-magic-strings.h" +#include "ecma-helpers.h" #include "ecma-objects.h" #include "ecma-try-catch-macro.h" #include "jerry-libc.h" diff --git a/src/libecmaoperations/ecma-function-object.c b/src/libecmaoperations/ecma-function-object.c index 78147df94..b7e7d8255 100644 --- a/src/libecmaoperations/ecma-function-object.c +++ b/src/libecmaoperations/ecma-function-object.c @@ -21,7 +21,6 @@ #include "ecma-globals.h" #include "ecma-helpers.h" #include "ecma-lex-env.h" -#include "ecma-magic-strings.h" #include "ecma-objects.h" #include "ecma-objects-general.h" #include "ecma-try-catch-macro.h" diff --git a/src/libecmaobjects/ecma-reference.h b/src/libecmaoperations/ecma-init-finalize.c similarity index 62% rename from src/libecmaobjects/ecma-reference.h rename to src/libecmaoperations/ecma-init-finalize.c index 9c7f9f3df..6e3b797f7 100644 --- a/src/libecmaobjects/ecma-reference.h +++ b/src/libecmaoperations/ecma-init-finalize.c @@ -13,22 +13,37 @@ * limitations under the License. */ -#ifndef ECMA_REFERENCE_H -#define ECMA_REFERENCE_H +#include "ecma-builtins.h" +#include "ecma-helpers.h" +#include "ecma-operations.h" /** \addtogroup ecma ECMA * @{ - */ - -/** - * \addtogroup reference ECMA-reference + * + * \addtogroup ecmainitfinalize Initialization and finalization of ECMA components * @{ */ +/** + * Initialize ECMA components + */ +void +ecma_init (void) +{ + ecma_strings_init (); + ecma_init_builtins (); +} /* ecma_init */ + +/** + * Finalize ECMA components + */ +void +ecma_finalize (void) +{ + ecma_finalize_builtins (); +} /* ecma_finalize */ /** * @} * @} */ - -#endif /* !ECMA_REFERENCE_H */ diff --git a/src/libecmaoperations/ecma-lex-env.h b/src/libecmaoperations/ecma-lex-env.h index 735e463b9..9b887e5ff 100644 --- a/src/libecmaoperations/ecma-lex-env.h +++ b/src/libecmaoperations/ecma-lex-env.h @@ -28,6 +28,11 @@ * @{ */ +/* ECMA-262 v5, 8.7.1 and 8.7.2 */ +extern ecma_completion_value_t ecma_op_get_value (ecma_reference_t ref); +extern ecma_completion_value_t ecma_op_put_value (ecma_reference_t ref, + ecma_value_t value); + /* ECMA-262 v5, Table 17. Abstract methods of Environment Records */ extern ecma_completion_value_t ecma_op_has_binding (ecma_object_t *lex_env_p, ecma_string_t *name_p); diff --git a/src/libecmaoperations/ecma-magic-strings.c b/src/libecmaoperations/ecma-magic-strings.c deleted file mode 100644 index 99fe15298..000000000 --- a/src/libecmaoperations/ecma-magic-strings.c +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ecma-globals.h" -#include "ecma-helpers.h" -#include "ecma-magic-strings.h" - -/** \addtogroup ecma ECMA - * @{ - * - * \addtogroup ecmamagicstrings Collection of magic string constants used in ECMA - * @{ - */ - -/** - * Get specified magic string as zero-terminated string - * - * @return pointer to zero-terminated magic string - */ -const ecma_char_t* -ecma_get_magic_string_zt (ecma_magic_string_id_t id) /**< magic string id */ -{ - TODO(Support UTF-16); - - switch (id) - { - case ECMA_MAGIC_STRING_ARGUMENTS: return (ecma_char_t*) "arguments"; - case ECMA_MAGIC_STRING_EVAL: return (ecma_char_t*) "eval"; - case ECMA_MAGIC_STRING_PROTOTYPE: return (ecma_char_t*) "prototype"; - case ECMA_MAGIC_STRING_CONSTRUCTOR: return (ecma_char_t*) "constructor"; - case ECMA_MAGIC_STRING_CALLER: return (ecma_char_t*) "caller"; - case ECMA_MAGIC_STRING_CALLEE: return (ecma_char_t*) "callee"; - case ECMA_MAGIC_STRING_UNDEFINED: return (ecma_char_t*) "undefined"; - case ECMA_MAGIC_STRING_NULL: return (ecma_char_t*) "null"; - case ECMA_MAGIC_STRING_FALSE: return (ecma_char_t*) "false"; - case ECMA_MAGIC_STRING_TRUE: return (ecma_char_t*) "true"; - case ECMA_MAGIC_STRING_NUMBER: return (ecma_char_t*) "number"; - case ECMA_MAGIC_STRING_STRING: return (ecma_char_t*) "string"; - case ECMA_MAGIC_STRING_OBJECT: return (ecma_char_t*) "object"; - case ECMA_MAGIC_STRING_FUNCTION: return (ecma_char_t*) "function"; - case ECMA_MAGIC_STRING_LENGTH: return (ecma_char_t*) "length"; - case ECMA_MAGIC_STRING_NAN: return (ecma_char_t*) "NaN"; - case ECMA_MAGIC_STRING_INFINITY: return (ecma_char_t*) "Infinity"; - case ECMA_MAGIC_STRING__COUNT: break; - } - - JERRY_UNREACHABLE(); -} /* ecma_get_magic_string_zt */ - -/** - * Get specified magic string - * - * @return ecma-string containing specified magic string - */ -ecma_string_t* -ecma_get_magic_string (ecma_magic_string_id_t id) /**< magic string id */ -{ - return ecma_new_ecma_string (ecma_get_magic_string_zt (id)); -} /* ecma_get_magic_string */ - -/** - * Check if passed string equals to one of magic strings - * and if equal magic string was found, return it's id in 'out_id_p' argument. - * - * @return true - if magic string equal to passed string was found, - * false - otherwise. - */ -bool -ecma_is_magic_string (ecma_char_t *zt_string_p, /**< zero-terminated string */ - ecma_magic_string_id_t *out_id_p) /**< out: magic string's id */ -{ - TODO (Improve performance of search); - - - for (ecma_magic_string_id_t id = 0; - id < ECMA_MAGIC_STRING__COUNT; - id++) - { - if (ecma_compare_zt_strings (zt_string_p, ecma_get_magic_string_zt (id))) - { - *out_id_p = id; - - return true; - } - } - - *out_id_p = ECMA_MAGIC_STRING__COUNT; - - return false; -} /* ecma_is_magic_string */ - -/** - * @} - * @} - */ diff --git a/src/libecmaoperations/ecma-magic-strings.h b/src/libecmaoperations/ecma-magic-strings.h deleted file mode 100644 index 922fa7154..000000000 --- a/src/libecmaoperations/ecma-magic-strings.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ECMA_MAGIC_STRINGS_H -#define ECMA_MAGIC_STRINGS_H - -#include "ecma-globals.h" - -/** \addtogroup ecma ECMA - * @{ - * - * \addtogroup ecmamagicstrings Collection of magic string constants used in ECMA - * @{ - */ - -/** - * Identifiers of ECMA magic string constants - */ -typedef enum -{ - ECMA_MAGIC_STRING_ARGUMENTS, /**< "arguments" */ - ECMA_MAGIC_STRING_EVAL, /**< "eval" */ - ECMA_MAGIC_STRING_PROTOTYPE, /**< "prototype" */ - ECMA_MAGIC_STRING_CONSTRUCTOR, /**< "constructor" */ - ECMA_MAGIC_STRING_CALLER, /**< "caller" */ - ECMA_MAGIC_STRING_CALLEE, /**< "callee" */ - ECMA_MAGIC_STRING_UNDEFINED, /**< "undefined" */ - ECMA_MAGIC_STRING_NULL, /**< "null" */ - ECMA_MAGIC_STRING_FALSE, /**< "false" */ - ECMA_MAGIC_STRING_TRUE, /**< "true" */ - ECMA_MAGIC_STRING_NUMBER, /**< "number" */ - ECMA_MAGIC_STRING_STRING, /**< "string" */ - ECMA_MAGIC_STRING_OBJECT, /**< "object" */ - ECMA_MAGIC_STRING_FUNCTION, /**< "function" */ - ECMA_MAGIC_STRING_LENGTH, /**< "length" */ - ECMA_MAGIC_STRING_NAN, /**< "NaN" */ - ECMA_MAGIC_STRING_INFINITY, /**< "Infinity" */ - ECMA_MAGIC_STRING__COUNT /**< number of magic strings */ -} ecma_magic_string_id_t; - -extern const ecma_char_t* ecma_get_magic_string_zt (ecma_magic_string_id_t id); -extern ecma_string_t* ecma_get_magic_string (ecma_magic_string_id_t id); -extern bool ecma_is_magic_string (ecma_char_t *zt_string_p, ecma_magic_string_id_t *out_id_p); - -/** - * @} - * @} - */ - -#endif /* ECMA_MAGIC_STRINGS_H */ diff --git a/src/libecmaoperations/ecma-objects-arguments.c b/src/libecmaoperations/ecma-objects-arguments.c index 6ebc9d121..3dec3a458 100644 --- a/src/libecmaoperations/ecma-objects-arguments.c +++ b/src/libecmaoperations/ecma-objects-arguments.c @@ -26,7 +26,6 @@ #include "ecma-globals.h" #include "ecma-helpers.h" #include "ecma-lex-env.h" -#include "ecma-magic-strings.h" #include "ecma-objects.h" #include "ecma-objects-arguments.h" #include "ecma-objects-general.h" diff --git a/src/libecmaoperations/ecma-operations.h b/src/libecmaoperations/ecma-operations.h index d94bb6639..e5dbaa29d 100644 --- a/src/libecmaoperations/ecma-operations.h +++ b/src/libecmaoperations/ecma-operations.h @@ -16,20 +16,19 @@ #ifndef JERRY_ECMA_OPERATIONS_H #define JERRY_ECMA_OPERATIONS_H -#include "ecma-globals.h" -#include "ecma-lex-env.h" -#include "ecma-reference.h" +#include "globals.h" /** \addtogroup ecma ECMA * @{ - * - * \addtogroup ecmaoperations ECMA-defined operations + */ + +/** + * \addtogroup ecmainitfinalize Initialization and finalization of ECMA components * @{ */ -extern ecma_completion_value_t ecma_op_get_value (ecma_reference_t ref); -extern ecma_completion_value_t ecma_op_put_value (ecma_reference_t ref, - ecma_value_t value); +extern void ecma_init (void); +extern void ecma_finalize (void); /** * @}