diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index e9cb4f608..5acb0ce03 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -13,9 +13,9 @@ * limitations under the License. */ +#include "ecma-builtins.h" #include "ecma-gc.h" #include "ecma-globals.h" -#include "ecma-global-object.h" #include "ecma-helpers.h" #include "ecma-lex-env.h" #include "ecma-operations.h" @@ -348,7 +348,10 @@ run_int (void) start_pos++; } - ecma_object_t *glob_obj_p = ecma_op_create_global_object (); + ecma_init_builtins (); + + ecma_object_t *glob_obj_p = ecma_builtin_get_global_object (); + ecma_object_t *lex_env_p = ecma_op_create_global_environment (glob_obj_p); ecma_value_t this_binding_value = ecma_make_object_value (glob_obj_p); @@ -369,7 +372,7 @@ run_int (void) { ecma_deref_object (glob_obj_p); ecma_deref_object (lex_env_p); - ecma_finalize (); + ecma_finalize_builtins (); ecma_gc_run (ECMA_GC_GEN_COUNT - 1); return ecma_is_value_true (completion.u.value); diff --git a/src/libecmaoperations/ecma-global-object.c b/src/libecmabuiltins/ecma-builtin-global-object.c similarity index 68% rename from src/libecmaoperations/ecma-global-object.c rename to src/libecmabuiltins/ecma-builtin-global-object.c index 193491b7f..657cf9a8c 100644 --- a/src/libecmaoperations/ecma-global-object.c +++ b/src/libecmabuiltins/ecma-builtin-global-object.c @@ -14,16 +14,22 @@ */ #include "globals.h" +#include "ecma-builtins.h" #include "ecma-gc.h" #include "ecma-globals.h" -#include "ecma-global-object.h" #include "ecma-helpers.h" #include "ecma-magic-strings.h" +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + /** \addtogroup ecma ECMA * @{ * - * \addtogroup ecmaglobalobject ECMA Global object related routines + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup global ECMA Global object built-in * @{ */ @@ -39,24 +45,35 @@ static ecma_object_t* ecma_global_object_p = NULL; * caller should free the reference by calling ecma_deref_object */ ecma_object_t* -ecma_get_global_object (void) +ecma_builtin_get_global_object (void) { JERRY_ASSERT(ecma_global_object_p != NULL); ecma_ref_object (ecma_global_object_p); return ecma_global_object_p; -} /* ecma_get_global_object */ +} /* ecma_builtin_get_global_object */ /** - * The Global Object construction routine. + * Check if passed object is the Global object. * - * See also: ECMA-262 v5, 15.1 - * - * @return pointer to the constructed object + * @return true - if passed pointer points to the Global object, + * false - otherwise. */ -ecma_object_t* -ecma_op_create_global_object (void) +bool +ecma_builtin_is_global_object (ecma_object_t *object_p) /**< an object */ +{ + return (object_p == ecma_global_object_p); +} /* ecma_builtin_is_global_object */ + +/** + * Initialize Global object. + * + * Warning: + * the routine should be called only from ecma_init_builtins + */ +void +ecma_builtin_init_global_object (void) { JERRY_ASSERT(ecma_global_object_p == NULL); @@ -73,26 +90,26 @@ ecma_op_create_global_object (void) TODO(/* Define NaN, Infinity, eval, parseInt, parseFloat, isNaN, isFinite properties */); - ecma_ref_object (glob_obj_p); ecma_global_object_p = glob_obj_p; - - return glob_obj_p; -} /* ecma_op_create_global_object */ +} /* ecma_builtin_init_global_object */ /** - * Remove global reference to the global object. + * Remove global reference to the Global object. * * Warning: - * the routine should be called only from ecma_finalize + * the routine should be called only from ecma_finalize_builtins */ void -ecma_finalize_global_object (void) +ecma_builtin_finalize_global_object (void) { + JERRY_ASSERT (ecma_global_object_p != NULL); + ecma_deref_object (ecma_global_object_p); ecma_global_object_p = NULL; -} /* ecma_free_global_object */ +} /* ecma_builtin_finalize_global_object */ /** + * @} * @} * @} */ diff --git a/src/libecmabuiltins/ecma-builtins-internal.h b/src/libecmabuiltins/ecma-builtins-internal.h new file mode 100644 index 000000000..13fdf44fe --- /dev/null +++ b/src/libecmabuiltins/ecma-builtins-internal.h @@ -0,0 +1,43 @@ +/* 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_BUILTINS_INTERNAL_H +#define ECMA_BUILTINS_INTERNAL_H + +#ifndef ECMA_BUILTINS_INTERNAL +# error "!ECMA_BUILTINS_INTERNAL" +#endif /* !ECMA_BUILTINS_INTERNAL */ + +#include "ecma-globals.h" + +/* ecma-builtin-global-object.c */ +extern void ecma_builtin_init_global_object (void); +extern void ecma_builtin_finalize_global_object (void); + +/* ecma-builtin-object-object.c */ +extern void ecma_builtin_init_object_object (void); +extern void ecma_builtin_finalize_object_object (void); + +extern void ecma_builtin_init_object_prototype_object (void); +extern void ecma_builtin_finalize_object_prototype_object (void); + +/* ecma-builtin-array-object.c */ +extern void ecma_builtin_init_array_object (void); +extern void ecma_builtin_finalize_array_object (void); + +extern void ecma_builtin_init_array_prototype_object (void); +extern void ecma_builtin_finalize_array_prototype_object (void); + +#endif /* !ECMA_BUILTINS_INTERNAL_H */ diff --git a/src/libecmabuiltins/ecma-non-instantiated-builtins.c b/src/libecmabuiltins/ecma-builtins.c similarity index 77% rename from src/libecmabuiltins/ecma-non-instantiated-builtins.c rename to src/libecmabuiltins/ecma-builtins.c index 614dc0aed..3099d0ae8 100644 --- a/src/libecmabuiltins/ecma-non-instantiated-builtins.c +++ b/src/libecmabuiltins/ecma-builtins.c @@ -13,8 +13,11 @@ * limitations under the License. */ +#include "ecma-builtins.h" #include "ecma-globals.h" -#include "ecma-non-instantiated-builtins.h" + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" /** \addtogroup ecma ECMA * @{ @@ -23,6 +26,24 @@ * @{ */ +/** + * Initialize ECMA built-in objects + */ +void +ecma_init_builtins (void) +{ + ecma_builtin_init_global_object (); +} /* ecma_init_builtins */ + +/** + * Finalize ECMA built-in objects + */ +void +ecma_finalize_builtins (void) +{ + ecma_builtin_finalize_global_object (); +} /* ecma_finalize_builtins */ + /** * If the property's name is one of built-in properties of the object * that is not instantiated yet, instantiate the property and diff --git a/src/libecmabuiltins/ecma-builtins.h b/src/libecmabuiltins/ecma-builtins.h new file mode 100644 index 000000000..78fabf23a --- /dev/null +++ b/src/libecmabuiltins/ecma-builtins.h @@ -0,0 +1,47 @@ +/* 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_BUILTINS_H +#define ECMA_BUILTINS_H + +#include "ecma-globals.h" + +/* ecma-builtin.c */ +extern void ecma_init_builtins (void); +extern void ecma_finalize_builtins (void); + +extern ecma_property_t* +ecma_object_try_to_get_non_instantiated_property (ecma_object_t *object_p, + ecma_string_t *string_p); + +/* ecma-builtin-global.c */ +extern ecma_object_t* ecma_builtin_get_global_object (void); +extern bool ecma_builtin_is_global_object (ecma_object_t *object_p); + +/* ecma-builtin-object.c */ +extern ecma_object_t* ecma_builtin_get_object_object (void); +extern bool ecma_builtin_is_object_object (ecma_object_t *object_p); + +extern ecma_object_t* ecma_builtin_get_object_prototype_object (void); +extern bool ecma_builtin_is_object_prototype_object (ecma_object_t *object_p); + +/* ecma-builtin-array.c */ +extern ecma_object_t* ecma_builtin_get_array_object (void); +extern bool ecma_builtin_is_array_object (ecma_object_t *object_p); + +extern ecma_object_t* ecma_builtin_get_array_prototype_object (void); +extern bool ecma_builtin_is_array_prototype_object (ecma_object_t *object_p); + +#endif /* !ECMA_BUILTINS_H */ diff --git a/src/libecmabuiltins/ecma-non-instantiated-builtins.h b/src/libecmabuiltins/ecma-non-instantiated-builtins.h deleted file mode 100644 index 4cba9fc21..000000000 --- a/src/libecmabuiltins/ecma-non-instantiated-builtins.h +++ /dev/null @@ -1,24 +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_NON_INSTANTIATED_BUILTINS_H -#define ECMA_NON_INSTANTIATED_BUILTINS_H - -#include "ecma-globals.h" - -extern ecma_property_t* ecma_object_try_to_get_non_instantiated_property (ecma_object_t *object_p, - ecma_string_t *string_p); - -#endif /* ECMA_NON_INSTANTIATED_BUILTINS_H */ diff --git a/src/libecmaoperations/ecma-finalize.c b/src/libecmaoperations/ecma-finalize.c deleted file mode 100644 index e8613e44c..000000000 --- a/src/libecmaoperations/ecma-finalize.c +++ /dev/null @@ -1,28 +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-operations.h" -#include "ecma-globals.h" -#include "ecma-global-object.h" -#include "globals.h" - -/** - * ECMA object model finalization routine - */ -void -ecma_finalize (void) -{ - ecma_finalize_global_object (); -} /* ecma_finalize */ diff --git a/src/libecmaoperations/ecma-function-object.c b/src/libecmaoperations/ecma-function-object.c index 0059ea079..b5cc89000 100644 --- a/src/libecmaoperations/ecma-function-object.c +++ b/src/libecmaoperations/ecma-function-object.c @@ -14,11 +14,11 @@ */ #include "ecma-alloc.h" +#include "ecma-builtins.h" #include "ecma-exceptions.h" #include "ecma-function-object.h" #include "ecma-gc.h" #include "ecma-globals.h" -#include "ecma-global-object.h" #include "ecma-helpers.h" #include "ecma-lex-env.h" #include "ecma-magic-strings.h" @@ -473,7 +473,7 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */ || ecma_is_value_null (this_arg_value)) { // 2. - this_binding = ecma_make_object_value (ecma_get_global_object ()); + this_binding = ecma_make_object_value (ecma_builtin_get_global_object ()); } else { @@ -667,7 +667,7 @@ ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment else if (ecma_is_lexical_environment_global (lex_env_p)) { // e. - ecma_object_t *glob_obj_p = ecma_get_global_object (); + ecma_object_t *glob_obj_p = ecma_builtin_get_global_object (); ecma_property_t *existing_prop_p = ecma_op_object_get_property (glob_obj_p, function_name_p); diff --git a/src/libecmaoperations/ecma-get-put-value.c b/src/libecmaoperations/ecma-get-put-value.c index 33f009f15..faf847f43 100644 --- a/src/libecmaoperations/ecma-get-put-value.c +++ b/src/libecmaoperations/ecma-get-put-value.c @@ -17,9 +17,9 @@ * Implementation of ECMA GetValue and PutValue */ +#include "ecma-builtins.h" #include "ecma-exceptions.h" #include "ecma-gc.h" -#include "ecma-global-object.h" #include "ecma-helpers.h" #include "ecma-lex-env.h" #include "ecma-objects.h" @@ -157,7 +157,7 @@ ecma_op_put_value (ecma_reference_t ref, /**< ECMA-reference */ else { // 3.b. - ecma_object_t *global_object_p = ecma_get_global_object (); + ecma_object_t *global_object_p = ecma_builtin_get_global_object (); ecma_completion_value_t completion = ecma_op_object_put (global_object_p, ref.referenced_name_p, diff --git a/src/libecmaoperations/ecma-global-object.h b/src/libecmaoperations/ecma-global-object.h deleted file mode 100644 index 0f87b8102..000000000 --- a/src/libecmaoperations/ecma-global-object.h +++ /dev/null @@ -1,37 +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_GLOBAL_OBJECT_H -#define ECMA_GLOBAL_OBJECT_H - -#include "ecma-globals.h" - -/** \addtogroup ecma ECMA - * @{ - * - * \addtogroup ecmaglobalobject ECMA Global object related routines - * @{ - */ - -extern ecma_object_t* ecma_get_global_object (void); -extern ecma_object_t* ecma_op_create_global_object (void); -extern void ecma_finalize_global_object (void); - -/** - * @} - * @} - */ - -#endif /* !ECMA_GLOBAL_OBJECT_H */ diff --git a/src/libecmaoperations/ecma-lex-env.c b/src/libecmaoperations/ecma-lex-env.c index 19cd26291..2004cfbde 100644 --- a/src/libecmaoperations/ecma-lex-env.c +++ b/src/libecmaoperations/ecma-lex-env.c @@ -13,10 +13,10 @@ * limitations under the License. */ +#include "ecma-builtins.h" #include "ecma-exceptions.h" #include "ecma-gc.h" #include "ecma-globals.h" -#include "ecma-global-object.h" #include "ecma-helpers.h" #include "ecma-lex-env.h" #include "ecma-objects.h" @@ -522,19 +522,16 @@ ecma_is_lexical_environment_global (ecma_object_t *lex_env_p) /**< lexical envir ecma_lexical_environment_type_t type = ecma_get_lex_env_type (lex_env_p); - bool ret_value = false; - if (type == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND) { ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); - ecma_object_t *glob_obj_p = ecma_get_global_object (); - ret_value = (binding_obj_p == glob_obj_p); - - ecma_deref_object (glob_obj_p); + return ecma_builtin_is_global_object (binding_obj_p); + } + else + { + return false; } - - return ret_value; } /* ecma_is_lexical_environment_global */ /** diff --git a/src/libecmaoperations/ecma-objects.c b/src/libecmaoperations/ecma-objects.c index f93788d39..b3b73cc12 100644 --- a/src/libecmaoperations/ecma-objects.c +++ b/src/libecmaoperations/ecma-objects.c @@ -13,11 +13,11 @@ * limitations under the License. */ +#include "ecma-builtins.h" #include "ecma-exceptions.h" #include "ecma-globals.h" #include "ecma-array-object.h" #include "ecma-function-object.h" -#include "ecma-non-instantiated-builtins.h" #include "ecma-objects-arguments.h" #include "ecma-objects-general.h" #include "ecma-objects.h" diff --git a/src/libecmaoperations/ecma-operations.h b/src/libecmaoperations/ecma-operations.h index 504fdff54..d94bb6639 100644 --- a/src/libecmaoperations/ecma-operations.h +++ b/src/libecmaoperations/ecma-operations.h @@ -31,8 +31,6 @@ 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_finalize (void); - /** * @} * @}