From 11cf22f06c2fe566f2f99e1c6f66bcb1263b14b5 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Wed, 17 Sep 2014 21:12:05 +0400 Subject: [PATCH] Introducing 'ecmabuiltins' component and interface for instantiating built-in properties. --- Makefile.mk | 3 ++ .../ecma-non-instantiated-builtins.c | 44 +++++++++++++++++++ .../ecma-non-instantiated-builtins.h | 24 ++++++++++ src/libecmaobjects/ecma-helpers.c | 44 +++++++++++++++++++ src/libecmaobjects/ecma-helpers.h | 3 ++ src/libecmaoperations/ecma-objects.c | 21 +++++++-- 6 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/libecmabuiltins/ecma-non-instantiated-builtins.c create mode 100644 src/libecmabuiltins/ecma-non-instantiated-builtins.h diff --git a/Makefile.mk b/Makefile.mk index e7886e09b..e8e014c60 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -270,6 +270,7 @@ SOURCES_JERRY_C = \ $(wildcard ./src/libjsparser/*.c) \ $(wildcard ./src/libecmaobjects/*.c) \ $(wildcard ./src/libecmaoperations/*.c) \ + $(wildcard ./src/libecmabuiltins/*.c) \ $(wildcard ./src/liballocator/*.c) \ $(wildcard ./src/libcoreint/*.c) \ $(wildcard ./src/liboptimizer/*.c) ) \ @@ -283,6 +284,7 @@ SOURCES_JERRY_H = \ $(wildcard ./src/libjsparser/*.h) \ $(wildcard ./src/libecmaobjects/*.h) \ $(wildcard ./src/libecmaoperations/*.h) \ + $(wildcard ./src/libecmabuiltins/*.h) \ $(wildcard ./src/liballocator/*.h) \ $(wildcard ./src/libcoreint/*.h) \ $(wildcard ./src/liboptimizer/*.h) \ @@ -301,6 +303,7 @@ INCLUDES_JERRY = \ -I src/libjsparser \ -I src/libecmaobjects \ -I src/libecmaoperations \ + -I src/libecmabuiltins \ -I src/liballocator \ -I src/liboptimizer \ -I src/libcoreint \ diff --git a/src/libecmabuiltins/ecma-non-instantiated-builtins.c b/src/libecmabuiltins/ecma-non-instantiated-builtins.c new file mode 100644 index 000000000..614dc0aed --- /dev/null +++ b/src/libecmabuiltins/ecma-non-instantiated-builtins.c @@ -0,0 +1,44 @@ +/* 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-non-instantiated-builtins.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + */ + +/** + * If the property's name is one of built-in properties of the object + * that is not instantiated yet, instantiate the property and + * return pointer to the instantiated property. + * + * @return pointer property, if one was instantiated, + * NULL - otherwise. + */ +ecma_property_t* +ecma_object_try_to_get_non_instantiated_property (ecma_object_t *object_p, /**< object */ + ecma_string_t *string_p) /**< property's name */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (object_p, string_p); +} /* ecma_object_try_to_get_non_instantiated_property */ + +/** + * @} + * @} + */ diff --git a/src/libecmabuiltins/ecma-non-instantiated-builtins.h b/src/libecmabuiltins/ecma-non-instantiated-builtins.h new file mode 100644 index 000000000..4cba9fc21 --- /dev/null +++ b/src/libecmabuiltins/ecma-non-instantiated-builtins.h @@ -0,0 +1,24 @@ +/* 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/libecmaobjects/ecma-helpers.c b/src/libecmaobjects/ecma-helpers.c index af917559e..7f520f02b 100644 --- a/src/libecmaobjects/ecma-helpers.c +++ b/src/libecmaobjects/ecma-helpers.c @@ -68,6 +68,8 @@ ecma_create_object (ecma_object_t *prototype_object_p, /**< pointer to prototybe ECMA_OBJECT_OBJ_PROTOTYPE_OBJECT_CP_POS, ECMA_OBJECT_OBJ_PROTOTYPE_OBJECT_CP_WIDTH); + ecma_set_object_has_non_instantiated_builtins (object_p, false); + return object_p; } /* ecma_create_object */ @@ -254,6 +256,48 @@ ecma_get_object_prototype (ecma_object_t *object_p) /**< object */ return ECMA_GET_POINTER (prototype_object_cp); } /* ecma_get_object_prototype */ +/** + * Get object's has-non-instantiated-built-ins flag. + * + * @return flag's value + */ +bool +ecma_get_object_has_non_instantiated_builtins (ecma_object_t *object_p) /**< object */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (!ecma_is_lexical_environment (object_p)); + + const uint32_t offset = ECMA_OBJECT_OBJ_HAS_NON_INSTANTIATED_BUILT_IN_PROPERTIES_POS; + const uint32_t width = ECMA_OBJECT_OBJ_HAS_NON_INSTANTIATED_BUILT_IN_PROPERTIES_WIDTH; + + JERRY_ASSERT (sizeof (uintptr_t) * JERRY_BITSINBYTE >= width); + + uintptr_t flag_value = (uintptr_t) jrt_extract_bit_field (object_p->container, + offset, + width); + + return (bool) flag_value; +} /* ecma_get_object_has_non_instantiated_builtins */ + +/** + * Set object's has-non-instantiated-built-ins flag's value. + */ +void +ecma_set_object_has_non_instantiated_builtins (ecma_object_t *object_p, /**< object */ + bool is_has_non_inst_builtins) /**< value of flag */ +{ + JERRY_ASSERT (object_p != NULL); + JERRY_ASSERT (!ecma_is_lexical_environment (object_p)); + + const uint32_t offset = ECMA_OBJECT_OBJ_HAS_NON_INSTANTIATED_BUILT_IN_PROPERTIES_POS; + const uint32_t width = ECMA_OBJECT_OBJ_HAS_NON_INSTANTIATED_BUILT_IN_PROPERTIES_WIDTH; + + object_p->container = jrt_set_bit_field_value (object_p->container, + (uintptr_t) is_has_non_inst_builtins, + offset, + width); +} /* ecma_set_object_has_non_instantiated_builtins */ + /** * Get type of lexical environment. */ diff --git a/src/libecmaobjects/ecma-helpers.h b/src/libecmaobjects/ecma-helpers.h index f96ebcd16..fb6c66c30 100644 --- a/src/libecmaobjects/ecma-helpers.h +++ b/src/libecmaobjects/ecma-helpers.h @@ -173,6 +173,9 @@ extern void ecma_set_object_extensible (ecma_object_t *object_p, bool is_extensi extern ecma_object_type_t ecma_get_object_type (ecma_object_t *object_p); extern void ecma_set_object_type (ecma_object_t *object_p, ecma_object_type_t type); extern ecma_object_t* ecma_get_object_prototype (ecma_object_t *object_p); +extern bool ecma_get_object_has_non_instantiated_builtins (ecma_object_t *object_p); +extern void ecma_set_object_has_non_instantiated_builtins (ecma_object_t *object_p, + bool is_has_non_inst_builtins); extern ecma_lexical_environment_type_t ecma_get_lex_env_type (ecma_object_t *object_p); extern ecma_object_t *ecma_get_lex_env_outer_reference (ecma_object_t *object_p); extern ecma_property_t *ecma_get_property_list (ecma_object_t *object_p); diff --git a/src/libecmaoperations/ecma-objects.c b/src/libecmaoperations/ecma-objects.c index 202a5e77c..f93788d39 100644 --- a/src/libecmaoperations/ecma-objects.c +++ b/src/libecmaoperations/ecma-objects.c @@ -17,6 +17,7 @@ #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" @@ -96,6 +97,8 @@ ecma_op_object_get_own_property (ecma_object_t *obj_p, /**< the object */ const ecma_object_type_t type = ecma_get_object_type (obj_p); + ecma_property_t *prop_p = NULL; + switch (type) { case ECMA_OBJECT_TYPE_GENERAL: @@ -104,12 +107,16 @@ ecma_op_object_get_own_property (ecma_object_t *obj_p, /**< the object */ case ECMA_OBJECT_TYPE_BOUND_FUNCTION: case ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION: { - return ecma_op_general_object_get_own_property (obj_p, property_name_p); + prop_p = ecma_op_general_object_get_own_property (obj_p, property_name_p); + + break; } case ECMA_OBJECT_TYPE_ARGUMENTS: { - return ecma_op_arguments_object_get_own_property (obj_p, property_name_p); + prop_p = ecma_op_arguments_object_get_own_property (obj_p, property_name_p); + + break; } case ECMA_OBJECT_TYPE_STRING: @@ -119,7 +126,15 @@ ecma_op_object_get_own_property (ecma_object_t *obj_p, /**< the object */ } } - JERRY_UNREACHABLE(); + if (unlikely (prop_p == NULL)) + { + if (ecma_get_object_has_non_instantiated_builtins (obj_p)) + { + prop_p = ecma_object_try_to_get_non_instantiated_property (obj_p, property_name_p); + } + } + + return prop_p; } /* ecma_op_object_get_own_property */ /**