mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Introducing 'ecmabuiltins' component and interface for instantiating built-in properties.
This commit is contained in:
parent
56e6d2a380
commit
11cf22f06c
@ -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 \
|
||||
|
||||
44
src/libecmabuiltins/ecma-non-instantiated-builtins.c
Normal file
44
src/libecmabuiltins/ecma-non-instantiated-builtins.c
Normal file
@ -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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
24
src/libecmabuiltins/ecma-non-instantiated-builtins.h
Normal file
24
src/libecmabuiltins/ecma-non-instantiated-builtins.h
Normal file
@ -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 */
|
||||
@ -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.
|
||||
*/
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 */
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user