Moving Global object related routines to libecmabuiltins component. Introducing ecma_init_builtins and ecma_finalize_builtins routines.

This commit is contained in:
Ruben Ayrapetyan
2014-09-18 13:55:56 +04:00
parent 11cf22f06c
commit f402e42d2f
13 changed files with 165 additions and 128 deletions
+6 -3
View File
@@ -13,9 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
#include "ecma-builtins.h"
#include "ecma-gc.h" #include "ecma-gc.h"
#include "ecma-globals.h" #include "ecma-globals.h"
#include "ecma-global-object.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "ecma-lex-env.h" #include "ecma-lex-env.h"
#include "ecma-operations.h" #include "ecma-operations.h"
@@ -348,7 +348,10 @@ run_int (void)
start_pos++; 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_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); 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 (glob_obj_p);
ecma_deref_object (lex_env_p); ecma_deref_object (lex_env_p);
ecma_finalize (); ecma_finalize_builtins ();
ecma_gc_run (ECMA_GC_GEN_COUNT - 1); ecma_gc_run (ECMA_GC_GEN_COUNT - 1);
return ecma_is_value_true (completion.u.value); return ecma_is_value_true (completion.u.value);
@@ -14,16 +14,22 @@
*/ */
#include "globals.h" #include "globals.h"
#include "ecma-builtins.h"
#include "ecma-gc.h" #include "ecma-gc.h"
#include "ecma-globals.h" #include "ecma-globals.h"
#include "ecma-global-object.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "ecma-magic-strings.h" #include "ecma-magic-strings.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
/** \addtogroup ecma ECMA /** \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 * caller should free the reference by calling ecma_deref_object
*/ */
ecma_object_t* ecma_object_t*
ecma_get_global_object (void) ecma_builtin_get_global_object (void)
{ {
JERRY_ASSERT(ecma_global_object_p != NULL); JERRY_ASSERT(ecma_global_object_p != NULL);
ecma_ref_object (ecma_global_object_p); ecma_ref_object (ecma_global_object_p);
return 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 true - if passed pointer points to the Global object,
* * false - otherwise.
* @return pointer to the constructed object
*/ */
ecma_object_t* bool
ecma_op_create_global_object (void) 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); 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 */); TODO(/* Define NaN, Infinity, eval, parseInt, parseFloat, isNaN, isFinite properties */);
ecma_ref_object (glob_obj_p);
ecma_global_object_p = glob_obj_p; ecma_global_object_p = glob_obj_p;
} /* ecma_builtin_init_global_object */
return glob_obj_p;
} /* ecma_op_create_global_object */
/** /**
* Remove global reference to the global object. * Remove global reference to the Global object.
* *
* Warning: * Warning:
* the routine should be called only from ecma_finalize * the routine should be called only from ecma_finalize_builtins
*/ */
void 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_deref_object (ecma_global_object_p);
ecma_global_object_p = NULL; ecma_global_object_p = NULL;
} /* ecma_free_global_object */ } /* ecma_builtin_finalize_global_object */
/** /**
* @}
* @} * @}
* @} * @}
*/ */
@@ -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 */
@@ -13,8 +13,11 @@
* limitations under the License. * limitations under the License.
*/ */
#include "ecma-builtins.h"
#include "ecma-globals.h" #include "ecma-globals.h"
#include "ecma-non-instantiated-builtins.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
/** \addtogroup ecma ECMA /** \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 * If the property's name is one of built-in properties of the object
* that is not instantiated yet, instantiate the property and * that is not instantiated yet, instantiate the property and
+47
View File
@@ -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 */
@@ -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 */
-28
View File
@@ -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 */
+3 -3
View File
@@ -14,11 +14,11 @@
*/ */
#include "ecma-alloc.h" #include "ecma-alloc.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h" #include "ecma-exceptions.h"
#include "ecma-function-object.h" #include "ecma-function-object.h"
#include "ecma-gc.h" #include "ecma-gc.h"
#include "ecma-globals.h" #include "ecma-globals.h"
#include "ecma-global-object.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "ecma-lex-env.h" #include "ecma-lex-env.h"
#include "ecma-magic-strings.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)) || ecma_is_value_null (this_arg_value))
{ {
// 2. // 2.
this_binding = ecma_make_object_value (ecma_get_global_object ()); this_binding = ecma_make_object_value (ecma_builtin_get_global_object ());
} }
else 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)) else if (ecma_is_lexical_environment_global (lex_env_p))
{ {
// e. // 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); ecma_property_t *existing_prop_p = ecma_op_object_get_property (glob_obj_p, function_name_p);
+2 -2
View File
@@ -17,9 +17,9 @@
* Implementation of ECMA GetValue and PutValue * Implementation of ECMA GetValue and PutValue
*/ */
#include "ecma-builtins.h"
#include "ecma-exceptions.h" #include "ecma-exceptions.h"
#include "ecma-gc.h" #include "ecma-gc.h"
#include "ecma-global-object.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "ecma-lex-env.h" #include "ecma-lex-env.h"
#include "ecma-objects.h" #include "ecma-objects.h"
@@ -157,7 +157,7 @@ ecma_op_put_value (ecma_reference_t ref, /**< ECMA-reference */
else else
{ {
// 3.b. // 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, ecma_completion_value_t completion = ecma_op_object_put (global_object_p,
ref.referenced_name_p, ref.referenced_name_p,
@@ -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 */
+6 -9
View File
@@ -13,10 +13,10 @@
* limitations under the License. * limitations under the License.
*/ */
#include "ecma-builtins.h"
#include "ecma-exceptions.h" #include "ecma-exceptions.h"
#include "ecma-gc.h" #include "ecma-gc.h"
#include "ecma-globals.h" #include "ecma-globals.h"
#include "ecma-global-object.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "ecma-lex-env.h" #include "ecma-lex-env.h"
#include "ecma-objects.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); ecma_lexical_environment_type_t type = ecma_get_lex_env_type (lex_env_p);
bool ret_value = false;
if (type == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND) if (type == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND)
{ {
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p); 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); return ecma_builtin_is_global_object (binding_obj_p);
}
ecma_deref_object (glob_obj_p); else
{
return false;
} }
return ret_value;
} /* ecma_is_lexical_environment_global */ } /* ecma_is_lexical_environment_global */
/** /**
+1 -1
View File
@@ -13,11 +13,11 @@
* limitations under the License. * limitations under the License.
*/ */
#include "ecma-builtins.h"
#include "ecma-exceptions.h" #include "ecma-exceptions.h"
#include "ecma-globals.h" #include "ecma-globals.h"
#include "ecma-array-object.h" #include "ecma-array-object.h"
#include "ecma-function-object.h" #include "ecma-function-object.h"
#include "ecma-non-instantiated-builtins.h"
#include "ecma-objects-arguments.h" #include "ecma-objects-arguments.h"
#include "ecma-objects-general.h" #include "ecma-objects-general.h"
#include "ecma-objects.h" #include "ecma-objects.h"
-2
View File
@@ -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, extern ecma_completion_value_t ecma_op_put_value (ecma_reference_t ref,
ecma_value_t value); ecma_value_t value);
extern void ecma_finalize (void);
/** /**
* @} * @}
* @} * @}