diff --git a/src/libecmaoperations/ecma-global-object.c b/src/libecmaoperations/ecma-global-object.c new file mode 100644 index 000000000..e421c7f07 --- /dev/null +++ b/src/libecmaoperations/ecma-global-object.c @@ -0,0 +1,56 @@ +/* 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-globals.h" +#include "ecma-global-object.h" +#include "ecma-helpers.h" +#include "ecma-magic-strings.h" + +/** \addtogroup ecma ---TODO--- + * @{ + * + * \addtogroup ecmaglobalobject ECMA Global object related routines + * @{ + */ + +/** + * The Global Object construction routine. + * + * See also: ECMA-262 v5, 15.1 + * + * @return pointer to the constructed object + */ +ecma_object_t* +ecma_op_create_global_object( void) +{ + ecma_object_t *glob_obj_p = ecma_create_object( NULL, true, ECMA_OBJECT_TYPE_GENERAL); + + ecma_property_t *undefined_prop_p = ecma_create_named_data_property( glob_obj_p, + ecma_get_magic_string( ECMA_MAGIC_STRING_UNDEFINED), + ECMA_PROPERTY_NOT_WRITABLE, + ECMA_PROPERTY_NOT_ENUMERABLE, + ECMA_PROPERTY_NOT_CONFIGURABLE); + JERRY_ASSERT( ecma_is_value_undefined( undefined_prop_p->u.named_data_property.value) ); + + TODO( /* Define NaN, Infinity, eval, parseInt, parseFloat, isNaN, isFinite properties */ ); + + return glob_obj_p; +} /* ecma_op_create_global_object */ + +/** + * @} + * @} + */ diff --git a/src/libecmaoperations/ecma-global-object.h b/src/libecmaoperations/ecma-global-object.h new file mode 100644 index 000000000..60782170a --- /dev/null +++ b/src/libecmaoperations/ecma-global-object.h @@ -0,0 +1,35 @@ +/* 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 ---TODO--- + * @{ + * + * \addtogroup ecmaglobalobject ECMA Global object related routines + * @{ + */ + +extern ecma_object_t* ecma_op_create_global_object( void); + +/** + * @} + * @} + */ + +#endif /* !ECMA_GLOBAL_OBJECT_H */ diff --git a/src/libecmaoperations/ecma-magic-strings.c b/src/libecmaoperations/ecma-magic-strings.c index 56cd59b61..8672eb66a 100644 --- a/src/libecmaoperations/ecma-magic-strings.c +++ b/src/libecmaoperations/ecma-magic-strings.c @@ -44,6 +44,8 @@ ecma_get_magic_string( ecma_magic_string_id_t id) /**< magic string id */ return (ecma_char_t*) "constructor"; case ECMA_MAGIC_STRING_CALLER: return (ecma_char_t*) "caller"; + case ECMA_MAGIC_STRING_UNDEFINED: + return (ecma_char_t*) "undefined"; } JERRY_UNREACHABLE(); diff --git a/src/libecmaoperations/ecma-magic-strings.h b/src/libecmaoperations/ecma-magic-strings.h index 4428f8583..ebd69a1d3 100644 --- a/src/libecmaoperations/ecma-magic-strings.h +++ b/src/libecmaoperations/ecma-magic-strings.h @@ -34,7 +34,8 @@ typedef enum ECMA_MAGIC_STRING_EVAL, /**< "eval" */ ECMA_MAGIC_STRING_PROTOTYPE, /**< "prototype" */ ECMA_MAGIC_STRING_CONSTRUCTOR, /**< "constructor" */ - ECMA_MAGIC_STRING_CALLER /**< "caller" */ + ECMA_MAGIC_STRING_CALLER, /**< "caller" */ + ECMA_MAGIC_STRING_UNDEFINED /**< undefined */ } ecma_magic_string_id_t; extern const ecma_char_t* ecma_get_magic_string( ecma_magic_string_id_t id);