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
@@ -0,0 +1,115 @@
/* 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-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-magic-strings.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup global ECMA Global object built-in
* @{
*/
/**
* Global object
*/
static ecma_object_t* ecma_global_object_p = NULL;
/**
* Get Global object
*
* @return pointer to the Global object
* caller should free the reference by calling ecma_deref_object
*/
ecma_object_t*
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_builtin_get_global_object */
/**
* Check if passed object is the Global object.
*
* @return true - if passed pointer points to the Global object,
* false - otherwise.
*/
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);
ecma_object_t *glob_obj_p = ecma_create_object (NULL, true, ECMA_OBJECT_TYPE_GENERAL);
ecma_string_t* undefined_identifier_p = ecma_get_magic_string (ECMA_MAGIC_STRING_UNDEFINED);
ecma_property_t *undefined_prop_p = ecma_create_named_data_property (glob_obj_p,
undefined_identifier_p,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE);
ecma_deref_ecma_string (undefined_identifier_p);
JERRY_ASSERT(ecma_is_value_undefined (undefined_prop_p->u.named_data_property.value));
TODO(/* Define NaN, Infinity, eval, parseInt, parseFloat, isNaN, isFinite properties */);
ecma_global_object_p = glob_obj_p;
} /* ecma_builtin_init_global_object */
/**
* Remove global reference to the Global object.
*
* Warning:
* the routine should be called only from ecma_finalize_builtins
*/
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_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.
*/
#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
+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 */