Merge branch 'master' into geppetto

This commit is contained in:
Ilmir Usmanov 2014-07-29 17:49:23 +04:00
commit 7d20bb3361
16 changed files with 1048 additions and 131 deletions

View File

@ -53,7 +53,12 @@ export FLASH_TARGETS = $(foreach __TARGET,$(foreach __MODE,$(TARGET_MODES),$(for
export OUT_DIR = ./out
export UNITTESTS_SRC_DIR = ./tests/unit
export SHELL=/bin/bash
export dwarf4
export echo
export todo
export fixme
all: clean $(JERRY_TARGETS) $(TESTS_TARGET) $(CHECK_TARGETS)

View File

@ -53,6 +53,26 @@ else
OPTION_DWARF4 := disable
endif
# Print TODO, FIXME
ifeq ($(todo),1)
OPTION_TODO := enable
else
OPTION_TODO := disable
endif
ifeq ($(fixme),1)
OPTION_FIXME := enable
else
OPTION_FIXME := disable
endif
# Compilation command line echoing
ifeq ($(echo),1)
OPTION_ECHO := enable
else
OPTION_ECHO := disable
endif
# JERRY_NDEBUG, debug symbols
ifeq ($(TARGET_MODE),release)
OPTION_NDEBUG = enable
@ -200,6 +220,14 @@ else
DEFINES_JERRY += -D__TARGET_MCU
endif
ifeq ($(OPTION_TODO),enable)
DEFINES_JERRY += -DJERRY_PRINT_TODO
endif
ifeq ($(OPTION_FIXME),enable)
DEFINES_JERRY += -DJERRY_PRINT_FIXME
endif
#
# Third-party sources, headers, includes, cflags, ldflags
#
@ -241,6 +269,7 @@ $(JERRY_TARGETS):
for jerry_src in $(SOURCES_JERRY) $(MAIN_MODULE_SRC); do \
cmd="$(CC) -c $(DEFINES_JERRY) $(CFLAGS_COMMON) $(CFLAGS_JERRY) $(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) $$jerry_src \
-o $(TARGET_DIR)/obj/$$(basename $$jerry_src).$$source_index.o"; \
if [ "$(OPTION_ECHO)" = "enable" ]; then echo $$cmd; echo; fi; \
$$cmd; \
if [ $$? -ne 0 ]; then echo Failed "'$$cmd'"; exit 1; fi; \
source_index=$$(($$source_index+1)); \
@ -248,11 +277,13 @@ $(JERRY_TARGETS):
for thirdparty_src in $(SOURCES_THIRDPARTY); do \
cmd="$(CC) -c $(CFLAGS_COMMON) $(CFLAGS_THIRDPARTY) $(INCLUDES_THIRDPARTY) $$thirdparty_src \
-o $(TARGET_DIR)/obj/$$(basename $$thirdparty_src).$$source_index.o"; \
if [ "$(OPTION_ECHO)" = "enable" ]; then echo $$cmd; echo; fi; \
$$cmd; \
if [ $$? -ne 0 ]; then echo Failed "'$$cmd'"; exit 1; fi; \
source_index=$$(($$source_index+1)); \
done; \
cmd="$(CC) $(CFLAGS_COMMON) $(TARGET_DIR)/obj/* $(LDFLAGS) -o $(TARGET_DIR)/$(ENGINE_NAME)"; \
if [ "$(OPTION_ECHO)" = "enable" ]; then echo $$cmd; echo; fi; \
$$cmd; \
if [ $$? -ne 0 ]; then echo Failed "'$$cmd'"; exit 1; fi;
@if [ "$(OPTION_STRIP)" = "enable" ]; then $(STRIP) $(TARGET_DIR)/$(ENGINE_NAME) || exit $$?; fi;
@ -268,8 +299,7 @@ $(TESTS_TARGET):
do \
cmd="$(CC) -c $(DEFINES_JERRY) $(CFLAGS_COMMON) $(CFLAGS_JERRY) \
$(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) $$jerry_src -o $(TARGET_DIR)/obj/$$(basename $$jerry_src).$$source_index.o"; \
echo $$cmd; \
echo; \
if [ "$(option_echo)" = "enable" ]; then echo $$cmd; echo; fi; \
$$cmd; \
if [ $$? -ne 0 ]; then echo Failed "'$$cmd'"; exit 1; fi; \
source_index=$$(($$source_index+1)); \
@ -278,8 +308,7 @@ $(TESTS_TARGET):
do \
cmd="$(CC) $(DEFINES_JERRY) $(CFLAGS_COMMON) $(CFLAGS_JERRY) \
$(INCLUDES_JERRY) $(INCLUDES_THIRDPARTY) $(TARGET_DIR)/obj/*.o $(UNITTESTS_SRC_DIR)/$$unit_test.c -o $(TARGET_DIR)/$$unit_test"; \
echo $$cmd; \
echo; \
if [ "$(OPTION_ECHO)" = "enable" ]; then echo $$cmd; echo; fi; \
$$cmd; \
if [ $$? -ne 0 ]; then echo Failed "'$$cmd'"; exit 1; fi; \
done

View File

@ -0,0 +1,125 @@
// 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.
var tmp, a, b = 1, c = 2, d, e = 3, g = 4;
var count = 1000;
tmp = b * c;
a = tmp + g;
d = tmp * e + a;
var waitTime = 600000;
var numOfIterations = 10;
while (1)
{
for (var j = 0; j < numOfIterations; j += 1)
{
LEDOn(12);
LEDOn(13);
LEDOn(14);
LEDOn(15);
wait(waitTime * 2);
LEDOff(12);
LEDOff(13);
LEDOff(14);
LEDOff(15);
wait(waitTime * 2);
}
for (var j = 0; j < numOfIterations; j += 1)
{
LEDOn(12);
wait(waitTime);
LEDOff(12);
wait(waitTime);
LEDOn(13);
wait(waitTime);
LEDOff(13);
wait(waitTime);
LEDOn(14);
wait(waitTime);
LEDOff(14);
wait(waitTime);
LEDOn(15);
wait(waitTime);
LEDOff(15);
wait(waitTime);
}
for (var j = 0; j < numOfIterations; j += 1)
{
LEDOn(12);
wait(waitTime);
LEDOff(12);
LEDOn(13);
wait(waitTime);
LEDOff(13);
LEDOn(14);
wait(waitTime);
LEDOff(14);
LEDOn(15);
wait(waitTime);
LEDOff(15);
}
for (var j = 0; j < numOfIterations; j += 1)
{
LEDOn(12);
wait(waitTime / 2);
LEDOff(12);
LEDOn(13);
wait(waitTime / 2);
LEDOff(13);
LEDOn(14);
wait(waitTime / 2);
LEDOff(14);
LEDOn(15);
wait(waitTime / 2);
LEDOff(15);
}
for (var j = 0; j < numOfIterations; j += 1)
{
LEDOn(12);
wait(waitTime / 3);
LEDOff(12);
LEDOn(13);
wait(waitTime / 3);
LEDOff(13);
LEDOn(14);
wait(waitTime / 3);
LEDOff(14);
LEDOn(15);
wait(waitTime / 3);
LEDOff(15);
}
for (var j = 0; j < numOfIterations; j += 1)
{
LEDOn(12);
wait(waitTime / 6);
LEDOff(12);
LEDOn(13);
wait(waitTime / 6);
LEDOff(13);
LEDOn(14);
wait(waitTime / 6);
LEDOff(14);
LEDOn(15);
wait(waitTime / 6);
LEDOff(15);
}
}

View File

@ -16,25 +16,115 @@
#include "globals.h"
static const char* generated_source = ""
"var tmp, a, b = 1, c = 2, d, e = 3, g = 4;\n"
"var count = 10000*10000;\n"
"for (var i = 0; i < count; i += 1)\n"
"{\n"
" tmp = b * c;\n"
" a = tmp + g;\n"
" d = tmp * e;\n"
"\n"
" if (i % 1000 == 0) \n"
" { \n"
" LEDOn (12);\n"
" LEDOn (13);\n"
" LEDOn (14);\n"
" LEDOn (15);\n"
" wait (300000);\n"
" LEDOff (12);\n"
" LEDOff (13);\n"
" LEDOff (14);\n"
" LEDOff (15);\n"
" }\n"
"}\n"
;
"var tmp, a, b = 1, c = 2, d, e = 3, g = 4;\n"
"\n"
"var count = 1000;\n"
"\n"
"tmp = b * c;\n"
"a = tmp + g;\n"
"d = tmp * e + a;\n"
"\n"
"var waitTime = 600000;\n"
"var numOfIterations = 10;\n"
"\n"
"while (1)\n"
"{\n"
"for (var j = 0; j < numOfIterations; j += 1)\n"
"{\n"
"LEDOn(12);\n"
"LEDOn(13);\n"
"LEDOn(14);\n"
"LEDOn(15);\n"
"wait(waitTime * 2);\n"
"LEDOff(12);\n"
"LEDOff(13);\n"
"LEDOff(14);\n"
"LEDOff(15);\n"
"wait(waitTime * 2);\n"
"}\n"
"\n"
"for (var j = 0; j < numOfIterations; j += 1)\n"
"{\n"
"LEDOn(12);\n"
"wait(waitTime);\n"
"LEDOff(12);\n"
"wait(waitTime);\n"
"LEDOn(13);\n"
"wait(waitTime);\n"
"LEDOff(13);\n"
"wait(waitTime);\n"
"LEDOn(14);\n"
"wait(waitTime);\n"
"LEDOff(14);\n"
"wait(waitTime);\n"
"LEDOn(15);\n"
"wait(waitTime);\n"
"LEDOff(15);\n"
"wait(waitTime);\n"
"}\n"
"\n"
"for (var j = 0; j < numOfIterations; j += 1)\n"
"{\n"
"LEDOn(12);\n"
"wait(waitTime);\n"
"LEDOff(12);\n"
"LEDOn(13);\n"
"wait(waitTime);\n"
"LEDOff(13);\n"
"LEDOn(14);\n"
"wait(waitTime);\n"
"LEDOff(14);\n"
"LEDOn(15);\n"
"wait(waitTime);\n"
"LEDOff(15);\n"
"}\n"
"\n"
"for (var j = 0; j < numOfIterations; j += 1)\n"
"{\n"
"LEDOn(12);\n"
"wait(waitTime / 2);\n"
"LEDOff(12);\n"
"LEDOn(13);\n"
"wait(waitTime / 2);\n"
"LEDOff(13);\n"
"LEDOn(14);\n"
"wait(waitTime / 2);\n"
"LEDOff(14);\n"
"LEDOn(15);\n"
"wait(waitTime / 2);\n"
"LEDOff(15);\n"
"}\n"
"\n"
"for (var j = 0; j < numOfIterations; j += 1)\n"
"{\n"
"LEDOn(12);\n"
"wait(waitTime / 3);\n"
"LEDOff(12);\n"
"LEDOn(13);\n"
"wait(waitTime / 3);\n"
"LEDOff(13);\n"
"LEDOn(14);\n"
"wait(waitTime / 3);\n"
"LEDOff(14);\n"
"LEDOn(15);\n"
"wait(waitTime / 3);\n"
"LEDOff(15);\n"
"}\n"
"\n"
"for (var j = 0; j < numOfIterations; j += 1)\n"
"{\n"
"LEDOn(12);\n"
"wait(waitTime / 6);\n"
"LEDOff(12);\n"
"LEDOn(13);\n"
"wait(waitTime / 6);\n"
"LEDOff(13);\n"
"LEDOn(14);\n"
"wait(waitTime / 6);\n"
"LEDOff(14);\n"
"LEDOn(15);\n"
"wait(waitTime / 6);\n"
"LEDOff(15);\n"
"}\n"
"}\n"
;

View File

@ -70,8 +70,18 @@ typedef enum
#define JERRY_STATIC_ASSERT( x ) typedef char JERRY_STATIC_ASSERT_GLUE( static_assertion_failed_, __LINE__) [ ( x ) ? 1 : -1 ] __unused
#define CALL_PRAGMA(x) _Pragma (#x)
#define TODO(x) CALL_PRAGMA(message ("TODO - " #x))
#define FIXME(x) CALL_PRAGMA(message ("FIXME - " #x))
#ifdef JERRY_PRINT_TODO
# define TODO(x) CALL_PRAGMA(message ("TODO - " #x))
#else /* !JERRY_PRINT_TODO */
# define TODO(X)
#endif /* !JERRY_PRINT_TODO */
#ifdef JERRY_PRINT_FIXME
# define FIXME(x) CALL_PRAGMA(message ("FIXME - " #x))
#else /* !JERRY_PRINT_FIXME */
# define FIXME(X)
#endif /* !JERRY_PRINT_FIXME */
/**
* Variable that must not be referenced.

View File

@ -127,8 +127,7 @@ run_int_from_pos (int start_pos,
completion = __opfuncs[curr->op_idx](*curr, &int_data);
JERRY_ASSERT( !ecma_is_completion_value_normal( completion)
|| ecma_is_completion_value_normal_simple_value(completion,
ECMA_SIMPLE_VALUE_EMPTY) );
|| ecma_is_empty_completion_value( completion) );
} while ( completion.type == ECMA_COMPLETION_TYPE_NORMAL );
if ( completion.type == ECMA_COMPLETION_TYPE_BREAK )

View File

@ -912,8 +912,7 @@ opfunc_pre_incr(OPCODE opdata, /**< operation data */
ecma_completion_value_t reg_assignment_res = set_variable_value (int_data,
dst_var_idx,
new_num_value);
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value (reg_assignment_res,
ECMA_SIMPLE_VALUE_EMPTY) );
JERRY_ASSERT( ecma_is_empty_completion_value( reg_assignment_res) );
ecma_dealloc_number( new_num_p);
@ -963,8 +962,7 @@ opfunc_pre_decr(OPCODE opdata, /**< operation data */
ecma_completion_value_t reg_assignment_res = set_variable_value (int_data,
dst_var_idx,
new_num_value);
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value (reg_assignment_res,
ECMA_SIMPLE_VALUE_EMPTY) );
JERRY_ASSERT( ecma_is_empty_completion_value (reg_assignment_res) );
ecma_dealloc_number( new_num_p);
@ -1014,8 +1012,7 @@ opfunc_post_incr(OPCODE opdata, /**< operation data */
ecma_completion_value_t reg_assignment_res = set_variable_value (int_data,
dst_var_idx,
old_value.value);
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value (reg_assignment_res,
ECMA_SIMPLE_VALUE_EMPTY) );
JERRY_ASSERT( ecma_is_empty_completion_value( reg_assignment_res) );
ECMA_FINALIZE(old_num_value);
ECMA_FINALIZE(old_value);
@ -1063,8 +1060,7 @@ opfunc_post_decr(OPCODE opdata, /**< operation data */
ecma_completion_value_t reg_assignment_res = set_variable_value (int_data,
dst_var_idx,
old_value.value);
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value (reg_assignment_res,
ECMA_SIMPLE_VALUE_EMPTY) );
JERRY_ASSERT( ecma_is_empty_completion_value (reg_assignment_res) );
ECMA_FINALIZE(old_num_value);
ECMA_FINALIZE(old_value);

View File

@ -63,12 +63,18 @@ typedef enum {
* Simple ecma-values
*/
typedef enum {
ECMA_SIMPLE_VALUE_EMPTY, /**< empty value (see also: ECMA-262 v5, 8.9 Completion specification type) */
/**
* Empty value is implementation defined value, used for:
* - representing empty value in completion values (see also: ECMA-262 v5, 8.9 Completion specification type);
* - values of uninitialized immutable bindings;
* - values of empty register variables.
*/
ECMA_SIMPLE_VALUE_EMPTY,
ECMA_SIMPLE_VALUE_UNDEFINED, /**< undefined value */
ECMA_SIMPLE_VALUE_NULL, /**< null value */
ECMA_SIMPLE_VALUE_FALSE, /**< boolean false */
ECMA_SIMPLE_VALUE_TRUE, /**< boolean true */
ECMA_SIMPLE_VALUE_ARRAY_REDIRECT, /**< special value for an array's elements that exists,
ECMA_SIMPLE_VALUE_ARRAY_REDIRECT, /**< implementation defined value for an array's elements that exists,
but is stored directly in the array's property list
(used for array elements with non-default attribute values) */
ECMA_SIMPLE_VALUE__COUNT /** count of simple ecma-values */
@ -183,7 +189,7 @@ typedef enum
} ecma_property_configurable_value_t;
/**
* Description of ecma-property.
* Description of ecma-property
*/
typedef struct ecma_property_t {
/** Property's type (ecma_property_type_t) */
@ -343,6 +349,54 @@ typedef struct ecma_object_t {
ecma_gc_info_t GCInfo;
} __packed ecma_object_t;
/**
* Description of ECMA property descriptor
*
* See also: ECMA-262 v5, 8.10.
*
* Note:
* If a component of descriptor is undefined then corresponding
* field should contain it's default value.
*/
typedef struct
{
/** Is [[Value]] defined? */
unsigned int is_value_defined : 1;
/** Is [[Get]] defined? */
unsigned int is_get_defined : 1;
/** Is [[Set]] defined? */
unsigned int is_set_defined : 1;
/** Is [[Writable]] defined? */
unsigned int is_writable_defined : 1;
/** Is [[Enumerable]] defined? */
unsigned int is_enumerable_defined : 1;
/** Is [[Configurable]] defined? */
unsigned int is_configurable_defined : 1;
/** [[Value]] */
ecma_value_t value;
/** [[Get]] */
ecma_object_t* get_p;
/** [[Set]] */
ecma_object_t* set_p;
/** [[Writable]] */
ecma_property_writable_value_t writable;
/** [[Enumerable]] */
ecma_property_enumerable_value_t enumerable;
/** [[Configurable]] */
ecma_property_configurable_value_t configurable;
} ecma_property_descriptor_t;
/**
* Description of an ecma-character
*/

View File

@ -282,6 +282,24 @@ ecma_make_completion_value(ecma_completion_type_t type, /**< type */
return (ecma_completion_value_t) { .type = type, .value = value, .target = target };
} /* ecma_make_completion_value */
/**
* Simple normal completion value constructor
*
* @return completion value
*/
ecma_completion_value_t
ecma_make_simple_completion_value( ecma_simple_value_t simple_value) /**< simple ecma-value */
{
JERRY_ASSERT( simple_value == ECMA_SIMPLE_VALUE_UNDEFINED
|| simple_value == ECMA_SIMPLE_VALUE_NULL
|| simple_value == ECMA_SIMPLE_VALUE_FALSE
|| simple_value == ECMA_SIMPLE_VALUE_TRUE );
return ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value( simple_value),
ECMA_TARGET_ID_RESERVED);
} /* ecma_make_simple_completion_value */
/**
* Throw completion value constructor.
*
@ -308,8 +326,8 @@ ecma_completion_value_t
ecma_make_empty_completion_value( void)
{
return ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value( ECMA_SIMPLE_VALUE_EMPTY),
ECMA_TARGET_ID_RESERVED);
ecma_make_simple_value( ECMA_SIMPLE_VALUE_EMPTY),
ECMA_TARGET_ID_RESERVED);
} /* ecma_make_empty_completion_value */
/**
@ -321,8 +339,8 @@ ecma_completion_value_t
ecma_copy_completion_value( ecma_completion_value_t value) /**< completion value */
{
return ecma_make_completion_value( value.type,
ecma_copy_value( value.value),
value.target);
ecma_copy_value( value.value),
value.target);
} /* ecma_copy_completion_value */
/**
@ -412,6 +430,20 @@ ecma_is_completion_value_normal_false( ecma_completion_value_t value) /**< compl
return ecma_is_completion_value_normal_simple_value( value, ECMA_SIMPLE_VALUE_FALSE);
} /* ecma_is_completion_value_normal_false */
/**
* Check if the completion value is normal empty value.
*
* @return true - if the completion type is normal and
* value contains empty simple value,
* false - otherwise.
*/
bool
ecma_is_empty_completion_value( ecma_completion_value_t value) /**< completion value */
{
return ( ecma_is_completion_value_normal( value)
&& ecma_is_value_empty( value.value) );
} /* ecma_is_empty_completion_value */
/**
* @}
* @}

View File

@ -208,11 +208,11 @@ ecma_get_internal_property(ecma_object_t *object_p, /**< object descriptor */
* @return pointer to newly created property
*/
ecma_property_t*
ecma_create_named_property(ecma_object_t *obj_p, /**< object */
ecma_char_t *name_p, /**< property name */
ecma_property_writable_value_t writable, /**< 'writable' attribute */
ecma_property_enumerable_value_t enumerable, /**< 'enumerable' attribute */
ecma_property_configurable_value_t configurable) /**< 'configurable' attribute */
ecma_create_named_data_property(ecma_object_t *obj_p, /**< object */
ecma_char_t *name_p, /**< property name */
ecma_property_writable_value_t writable, /**< 'writable' attribute */
ecma_property_enumerable_value_t enumerable, /**< 'enumerable' attribute */
ecma_property_configurable_value_t configurable) /**< 'configurable' attribute */
{
JERRY_ASSERT( obj_p != NULL && name_p != NULL );
@ -232,7 +232,40 @@ ecma_create_named_property(ecma_object_t *obj_p, /**< object */
ecma_set_pointer( obj_p->properties_p, prop);
return prop;
} /* ecma_create_named_property */
} /* ecma_create_named_data_property */
/**
* Create named accessor property with given name, attributes, getter and setter.
*
* @return pointer to newly created property
*/
ecma_property_t*
ecma_create_named_accessor_property(ecma_object_t *obj_p, /**< object */
ecma_char_t *name_p, /**< property name */
ecma_object_t *get_p, /**< getter */
ecma_object_t *set_p, /**< setter */
ecma_property_enumerable_value_t enumerable, /**< 'enumerable' attribute */
ecma_property_configurable_value_t configurable) /**< 'configurable' attribute */
{
JERRY_ASSERT( obj_p != NULL && name_p != NULL );
ecma_property_t *prop_p = ecma_alloc_property();
prop_p->type = ECMA_PROPERTY_NAMEDACCESSOR;
ecma_set_pointer( prop_p->u.named_accessor_property.name_p, ecma_new_ecma_string( name_p));
ecma_set_pointer( prop_p->u.named_accessor_property.get_p, get_p);
ecma_set_pointer( prop_p->u.named_accessor_property.set_p, set_p);
prop_p->u.named_accessor_property.enumerable = enumerable;
prop_p->u.named_accessor_property.configurable = configurable;
ecma_set_pointer( prop_p->next_property_p, ecma_get_pointer( obj_p->properties_p));
ecma_set_pointer( obj_p->properties_p, prop_p);
return prop_p;
} /* ecma_create_named_accessor_property */
/**
* Find named data property or named access property in specified object.

View File

@ -56,6 +56,7 @@ extern ecma_value_t ecma_copy_value( const ecma_value_t value);
extern void ecma_free_value( const ecma_value_t value);
extern ecma_completion_value_t ecma_make_completion_value( ecma_completion_type_t type, ecma_value_t value, uint8_t target);
extern ecma_completion_value_t ecma_make_simple_completion_value( ecma_simple_value_t simple_value);
extern ecma_completion_value_t ecma_make_throw_value( ecma_object_t *exception_p);
extern ecma_completion_value_t ecma_make_empty_completion_value( void);
extern ecma_completion_value_t ecma_copy_completion_value( ecma_completion_value_t value);
@ -64,8 +65,9 @@ extern void ecma_free_completion_value( ecma_completion_value_t completion_value
extern bool ecma_is_completion_value_normal( ecma_completion_value_t value);
extern bool ecma_is_completion_value_throw( ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_simple_value( ecma_completion_value_t value, ecma_simple_value_t simple_value);
extern bool ecma_is_completion_value_normal_false( ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_true( ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_false( ecma_completion_value_t value);
extern bool ecma_is_empty_completion_value( ecma_completion_value_t value);
extern ecma_object_t* ecma_create_object( ecma_object_t *prototype_object_p, bool is_extensible);
extern ecma_object_t* ecma_create_lexical_environment( ecma_object_t *outer_lexical_environment_p, ecma_lexical_environment_type_t type);
@ -75,7 +77,8 @@ extern ecma_property_t* ecma_create_internal_property(ecma_object_t *object_p, e
extern ecma_property_t* ecma_find_internal_property(ecma_object_t *object_p, ecma_internal_property_id_t property_id);
extern ecma_property_t* ecma_get_internal_property(ecma_object_t *object_p, ecma_internal_property_id_t property_id);
extern ecma_property_t *ecma_create_named_property(ecma_object_t *obj_p, ecma_char_t *name_p, ecma_property_writable_value_t writable, ecma_property_enumerable_value_t enumerable, ecma_property_configurable_value_t configurable);
extern ecma_property_t *ecma_create_named_data_property(ecma_object_t *obj_p, ecma_char_t *name_p, ecma_property_writable_value_t writable, ecma_property_enumerable_value_t enumerable, ecma_property_configurable_value_t configurable);
extern ecma_property_t *ecma_create_named_accessor_property(ecma_object_t *obj_p, ecma_char_t *name_p, ecma_object_t *get_p, ecma_object_t *set_p, ecma_property_enumerable_value_t enumerable, ecma_property_configurable_value_t configurable);
extern ecma_property_t *ecma_find_named_property(ecma_object_t *obj_p, ecma_char_t *name_p);
extern ecma_property_t *ecma_get_named_property(ecma_object_t *obj_p, ecma_char_t *name_p);
extern ecma_property_t *ecma_get_named_data_property(ecma_object_t *obj_p, ecma_char_t *name_p);

View File

@ -44,25 +44,18 @@ ecma_op_check_object_coercible( ecma_value_t value) /**< ecma-value */
{
case ECMA_TYPE_SIMPLE:
{
switch ( (ecma_simple_value_t)value.value )
{
case ECMA_SIMPLE_VALUE_UNDEFINED:
case ECMA_SIMPLE_VALUE_NULL:
{
return ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_TYPE));
}
case ECMA_SIMPLE_VALUE_FALSE:
case ECMA_SIMPLE_VALUE_TRUE:
{
break;
}
case ECMA_SIMPLE_VALUE_EMPTY:
case ECMA_SIMPLE_VALUE_ARRAY_REDIRECT:
case ECMA_SIMPLE_VALUE__COUNT:
{
JERRY_UNREACHABLE();
}
}
if ( ecma_is_value_undefined( value) )
{
return ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_TYPE));
}
else if ( ecma_is_value_boolean( value) )
{
break;
}
else
{
JERRY_UNREACHABLE();
}
break;
}
@ -81,6 +74,79 @@ ecma_op_check_object_coercible( ecma_value_t value) /**< ecma-value */
return ecma_make_empty_completion_value();
} /* ecma_op_check_object_coercible */
/**
* SameValue operation.
*
* See also:
* ECMA-262 v5, 9.12
*
* @return true - if the value are same according to ECMA-defined SameValue algorithm,
* false - otherwise.
*/
bool
ecma_op_same_value( ecma_value_t x, /**< ecma-value */
ecma_value_t y) /**< ecma-value */
{
const bool is_x_undefined = ecma_is_value_undefined( x);
const bool is_x_null = ecma_is_value_null( x);
const bool is_x_boolean = ecma_is_value_boolean( x);
const bool is_x_number = ( x.value_type == ECMA_TYPE_NUMBER );
const bool is_x_string = ( x.value_type == ECMA_TYPE_STRING );
const bool is_x_object = ( x.value_type == ECMA_TYPE_OBJECT );
const bool is_y_undefined = ecma_is_value_undefined( y);
const bool is_y_null = ecma_is_value_null( y);
const bool is_y_boolean = ecma_is_value_boolean( y);
const bool is_y_number = ( y.value_type == ECMA_TYPE_NUMBER );
const bool is_y_string = ( y.value_type == ECMA_TYPE_STRING );
const bool is_y_object = ( y.value_type == ECMA_TYPE_OBJECT );
const bool is_types_equal = ( ( is_x_undefined && is_y_undefined )
|| ( is_x_null && is_y_null )
|| ( is_x_boolean && is_y_boolean )
|| ( is_x_number && is_y_number )
|| ( is_x_string && is_y_string )
|| ( is_x_object && is_y_object ) );
if ( !is_types_equal )
{
return false;
}
if ( is_x_undefined
|| is_x_null )
{
return true;
}
if ( is_x_number )
{
TODO( Implement according to ECMA );
ecma_number_t *x_num_p = (ecma_number_t*)ecma_get_pointer( x.value);
ecma_number_t *y_num_p = (ecma_number_t*)ecma_get_pointer( y.value);
return ( *x_num_p == *y_num_p );
}
if ( is_x_string )
{
ecma_array_first_chunk_t* x_str_p = (ecma_array_first_chunk_t*)( ecma_get_pointer(x.value) );
ecma_array_first_chunk_t* y_str_p = (ecma_array_first_chunk_t*)( ecma_get_pointer(y.value) );
return ecma_compare_ecma_string_to_ecma_string( x_str_p, y_str_p);
}
if ( is_x_boolean )
{
return ( ecma_is_value_true( x) == ecma_is_value_true( y) );
}
JERRY_ASSERT( is_x_object );
return ( ecma_get_pointer( x.value) == ecma_get_pointer( y.value) );
} /* ecma_op_same_value */
/**
* ToPrimitive operation.
*
@ -130,8 +196,6 @@ ecma_op_to_primitive( ecma_value_t value, /**< ecma-value */
ecma_completion_value_t
ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
{
ecma_simple_value_t res = ECMA_SIMPLE_VALUE_EMPTY;
switch ( (ecma_type_t)value.value_type )
{
case ECMA_TYPE_NUMBER:
@ -139,8 +203,9 @@ ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
ecma_number_t *num_p = ecma_get_pointer( value.value);
TODO( Implement according to ECMA );
res = ( *num_p == 0 ) ? ECMA_SIMPLE_VALUE_FALSE:
ECMA_SIMPLE_VALUE_TRUE;
return ecma_make_simple_completion_value( ( *num_p == 0 ) ? ECMA_SIMPLE_VALUE_FALSE
: ECMA_SIMPLE_VALUE_TRUE );
break;
}
@ -148,11 +213,11 @@ ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
{
if ( ecma_is_value_boolean (value ) )
{
res = value.value;
return ecma_make_simple_completion_value( value.value);
} else if ( ecma_is_value_undefined (value)
|| ecma_is_value_null( value) )
{
res = ECMA_SIMPLE_VALUE_FALSE;
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_FALSE);
} else
{
JERRY_UNREACHABLE();
@ -164,14 +229,14 @@ ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
{
ecma_array_first_chunk_t *str_p = ecma_get_pointer( value.value);
res = ( str_p->header.unit_number == 0 ) ? ECMA_SIMPLE_VALUE_FALSE:
ECMA_SIMPLE_VALUE_TRUE;
return ecma_make_simple_completion_value( ( str_p->header.unit_number == 0 ) ? ECMA_SIMPLE_VALUE_FALSE
: ECMA_SIMPLE_VALUE_TRUE );
break;
}
case ECMA_TYPE_OBJECT:
{
res = ECMA_SIMPLE_VALUE_TRUE;
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_TRUE);
break;
}
@ -181,12 +246,7 @@ ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
}
}
JERRY_ASSERT( res == ECMA_SIMPLE_VALUE_FALSE
|| res == ECMA_SIMPLE_VALUE_TRUE );
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value( res),
ECMA_TARGET_ID_RESERVED);
JERRY_UNREACHABLE();
} /* ecma_op_to_boolean */
/**

View File

@ -41,6 +41,7 @@ typedef enum
} ecma_preferred_type_hint_t;
extern ecma_completion_value_t ecma_op_check_object_coercible( ecma_value_t value);
extern bool ecma_op_same_value( ecma_value_t x, ecma_value_t y);
extern ecma_completion_value_t ecma_op_to_primitive( ecma_value_t value, ecma_preferred_type_hint_t preferred_type);
extern ecma_completion_value_t ecma_op_to_boolean( ecma_value_t value);
extern ecma_completion_value_t ecma_op_to_number( ecma_value_t value);

View File

@ -90,12 +90,12 @@ ecma_op_create_mutable_binding(ecma_object_t *lex_env_p, /**< lexical environmen
{
JERRY_ASSERT( ecma_is_completion_value_normal_false( ecma_op_has_binding( lex_env_p, name_p)) );
ecma_create_named_property( lex_env_p,
name_p,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
is_deletable ? ECMA_PROPERTY_CONFIGURABLE
: ECMA_PROPERTY_NOT_CONFIGURABLE);
ecma_create_named_data_property( lex_env_p,
name_p,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
is_deletable ? ECMA_PROPERTY_CONFIGURABLE
: ECMA_PROPERTY_NOT_CONFIGURABLE);
break;
@ -186,8 +186,7 @@ ecma_op_get_binding_value(ecma_object_t *lex_env_p, /**< lexical environment */
return ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL,
ecma_copy_value( prop_value),
ECMA_TARGET_ID_RESERVED);
} else if ( prop_value.value_type == ECMA_TYPE_SIMPLE
&& prop_value.value == ECMA_SIMPLE_VALUE_EMPTY )
} else if ( ecma_is_value_empty( prop_value) )
{
/* unitialized immutable binding */
if ( is_strict )
@ -317,14 +316,15 @@ ecma_op_create_immutable_binding(ecma_object_t *lex_env_p, /**< lexical environm
* Warning:
* Whether immutable bindings are deletable seems not to be defined by ECMA v5.
*/
ecma_property_t *prop_p = ecma_create_named_property( lex_env_p,
name_p,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE);
ecma_property_t *prop_p = ecma_create_named_data_property( lex_env_p,
name_p,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE);
JERRY_ASSERT( prop_p->u.named_data_property.value.value_type == ECMA_TYPE_SIMPLE );
JERRY_ASSERT( ecma_is_value_undefined( prop_p->u.named_data_property.value ) );
prop_p->u.named_data_property.value.value_type = ECMA_TYPE_SIMPLE;
prop_p->u.named_data_property.value.value = ECMA_SIMPLE_VALUE_EMPTY;
}
case ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND:
@ -358,8 +358,7 @@ ecma_op_initialize_immutable_binding(ecma_object_t *lex_env_p, /**< lexical envi
/* The binding must be unitialized immutable binding */
JERRY_ASSERT( prop_p->u.named_data_property.writable == ECMA_PROPERTY_NOT_WRITABLE
&& prop_p->u.named_data_property.value.value_type == ECMA_TYPE_SIMPLE
&& prop_p->u.named_data_property.value.value == ECMA_SIMPLE_VALUE_EMPTY );
&& ecma_is_value_empty( prop_p->u.named_data_property.value) );
prop_p->u.named_data_property.value = ecma_copy_value( value);
}

View File

@ -13,7 +13,9 @@
* limitations under the License.
*/
#include "ecma-exceptions.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects-properties.h"
/** \addtogroup ecma ---TODO---
@ -34,9 +36,53 @@
*/
ecma_completion_value_t
ecma_op_object_get( ecma_object_t *obj_p, /**< the object */
ecma_array_first_chunk_t *property_name_p) /**< property name */
ecma_char_t *property_name_p) /**< property name */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, property_name_p);
JERRY_ASSERT( obj_p != NULL && !obj_p->is_lexical_environment );
JERRY_ASSERT( property_name_p != NULL );
/*
* ECMA-262 v5, 8.12.3
*
* Common implementation of operation for objects other than Host, Function or Arguments objects.
*/
// 1.
const ecma_property_t* prop_p = ecma_op_object_get_property( obj_p, property_name_p);
// 2.
if ( prop_p == NULL )
{
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_UNDEFINED);
}
// 3.
if ( prop_p->type == ECMA_PROPERTY_NAMEDDATA )
{
return ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL,
ecma_copy_value( prop_p->u.named_data_property.value),
ECMA_TARGET_ID_RESERVED);
}
else
{
// 4.
ecma_object_t *getter = ecma_get_pointer( prop_p->u.named_accessor_property.get_p);
// 5.
if ( getter == NULL )
{
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_UNDEFINED);
}
else
{
/*
* Return result of O.[[Call]];
*/
JERRY_UNIMPLEMENTED();
}
}
JERRY_UNREACHABLE();
} /* ecma_op_object_get */
/**
@ -46,13 +92,22 @@ ecma_op_object_get( ecma_object_t *obj_p, /**< the object */
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
*
* @return pointer to a property - if it exists,
* NULL - otherwise.
* NULL (i.e. ecma-undefined) - otherwise.
*/
ecma_property_t*
ecma_op_object_get_own_property( ecma_object_t *obj_p, /**< the object */
ecma_array_first_chunk_t *property_name_p) /**< property name */
ecma_char_t *property_name_p) /**< property name */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, property_name_p);
JERRY_ASSERT( obj_p != NULL && !obj_p->is_lexical_environment );
JERRY_ASSERT( property_name_p != NULL );
/*
* ECMA-262 v5, 8.12.2
*
* Common implementation of operation for objects other than Host, Function or Arguments objects.
*/
return ecma_find_named_property( obj_p, property_name_p);
} /* ecma_op_object_get_own_property */
/**
@ -62,13 +117,42 @@ ecma_op_object_get_own_property( ecma_object_t *obj_p, /**< the object */
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
*
* @return pointer to a property - if it exists,
* NULL - otherwise.
* NULL (i.e. ecma-undefined) - otherwise.
*/
ecma_property_t*
ecma_op_object_get_property( ecma_object_t *obj_p, /**< the object */
ecma_array_first_chunk_t *property_name_p) /**< property name */
ecma_char_t *property_name_p) /**< property name */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, property_name_p);
JERRY_ASSERT( obj_p != NULL && !obj_p->is_lexical_environment );
JERRY_ASSERT( property_name_p != NULL );
/*
* ECMA-262 v5, 8.12.2
*
* Common implementation of operation for objects other than Host, Function or Arguments objects.
*/
// 1.
ecma_property_t *prop_p = ecma_op_object_get_own_property( obj_p, property_name_p);
// 2.
if ( prop_p != NULL )
{
return prop_p;
}
// 3.
ecma_object_t *prototype_p = ecma_get_pointer( obj_p->u.object.prototype_object_p);
// 4., 5.
if ( prototype_p != NULL )
{
return ecma_op_object_get_property( prototype_p, property_name_p);
}
else
{
return NULL;
}
} /* ecma_op_object_get_property */
/**
@ -82,11 +166,112 @@ ecma_op_object_get_property( ecma_object_t *obj_p, /**< the object */
*/
ecma_completion_value_t
ecma_op_object_put( ecma_object_t *obj_p, /**< the object */
ecma_array_first_chunk_t *property_name_p, /**< property name */
ecma_char_t *property_name_p, /**< property name */
ecma_value_t value, /**< ecma-value */
bool is_throw) /**< flag that controls failure handling */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, property_name_p, value, is_throw);
JERRY_ASSERT( obj_p != NULL && !obj_p->is_lexical_environment );
JERRY_ASSERT( property_name_p != NULL );
// 1.
if ( !ecma_op_object_can_put( obj_p, property_name_p) )
{
if ( is_throw )
{
// a.
return ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_TYPE));
}
else
{
// b.
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_FALSE);
}
}
// 2.
ecma_property_t *own_desc_p = ecma_op_object_get_own_property( obj_p, property_name_p);
// 3.
if ( own_desc_p->type == ECMA_PROPERTY_NAMEDDATA )
{
// a.
ecma_property_descriptor_t value_desc = (ecma_property_descriptor_t) {
.is_value_defined = true,
.value = value,
.is_get_defined = false,
.get_p = NULL,
.is_set_defined = false,
.set_p = NULL,
.is_writable_defined = false,
.writable = ECMA_PROPERTY_NOT_WRITABLE,
.is_enumerable_defined = false,
.enumerable = ECMA_PROPERTY_NOT_ENUMERABLE,
.is_configurable_defined = false,
.configurable = ECMA_PROPERTY_NOT_CONFIGURABLE,
};
// b., c.
return ecma_op_object_define_own_property( obj_p,
property_name_p,
value_desc,
is_throw);
}
// 4.
ecma_property_t *desc_p = ecma_op_object_get_property( obj_p, property_name_p);
// 5.
if ( desc_p->type == ECMA_PROPERTY_NAMEDACCESSOR )
{
// a.
ecma_object_t *setter_p = ecma_get_pointer( desc_p->u.named_accessor_property.set_p);
JERRY_ASSERT( setter_p != NULL );
// b.
/*
* setter_p->[[Call]]( obj_p, value);
*/
JERRY_UNIMPLEMENTED();
}
else
{
// 6.
// a.
ecma_property_descriptor_t new_desc = (ecma_property_descriptor_t) {
.is_value_defined = true,
.value = value,
.is_get_defined = false,
.get_p = NULL,
.is_set_defined = false,
.set_p = NULL,
.is_writable_defined = true,
.writable = ECMA_PROPERTY_WRITABLE,
.is_enumerable_defined = true,
.enumerable = ECMA_PROPERTY_ENUMERABLE,
.is_configurable_defined = true,
.configurable = ECMA_PROPERTY_CONFIGURABLE
};
// b.
return ecma_op_object_define_own_property( obj_p,
property_name_p,
new_desc,
is_throw);
}
JERRY_UNREACHABLE();
} /* ecma_op_object_put */
/**
@ -100,9 +285,97 @@ ecma_op_object_put( ecma_object_t *obj_p, /**< the object */
*/
bool
ecma_op_object_can_put( ecma_object_t *obj_p, /**< the object */
ecma_array_first_chunk_t *property_name_p) /**< property name */
ecma_char_t *property_name_p) /**< property name */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, property_name_p);
JERRY_ASSERT( obj_p != NULL && !obj_p->is_lexical_environment );
JERRY_ASSERT( property_name_p != NULL );
/*
* ECMA-262 v5, 8.12.2
*
* Common implementation of operation for objects other than Host, Function or Arguments objects.
*/
// 1.
ecma_property_t *prop_p = ecma_op_object_get_own_property( obj_p, property_name_p);
// 2.
if ( prop_p != NULL )
{
// a.
if ( prop_p->type == ECMA_PROPERTY_NAMEDACCESSOR )
{
ecma_object_t *setter_p = ecma_get_pointer( prop_p->u.named_accessor_property.set_p);
// i.
if ( setter_p == NULL )
{
return false;
}
// ii.
return true;
}
else
{
// b.
JERRY_ASSERT( prop_p->type == ECMA_PROPERTY_NAMEDDATA );
return ( prop_p->u.named_data_property.writable == ECMA_PROPERTY_WRITABLE );
}
}
// 3.
ecma_object_t *proto_p = ecma_get_pointer( obj_p->u.object.prototype_object_p);
// 4.
if ( proto_p == NULL )
{
return obj_p->u.object.extensible;
}
// 5.
ecma_property_t *inherited_p = ecma_op_object_get_property( proto_p, property_name_p);
// 6.
if ( inherited_p == NULL )
{
return obj_p->u.object.extensible;
}
// 7.
if ( inherited_p->type == ECMA_PROPERTY_NAMEDACCESSOR )
{
ecma_object_t *setter_p = ecma_get_pointer( inherited_p->u.named_accessor_property.set_p);
// a.
if ( setter_p == NULL )
{
return false;
}
// b.
return true;
}
else
{
// 8.
JERRY_ASSERT( inherited_p->type == ECMA_PROPERTY_NAMEDDATA );
// a.
if ( !obj_p->u.object.extensible )
{
return false;
}
else
{
// b.
return ( inherited_p->u.named_data_property.writable == ECMA_PROPERTY_WRITABLE );
}
}
JERRY_UNREACHABLE();
} /* ecma_op_object_can_put */
/**
@ -116,9 +389,20 @@ ecma_op_object_can_put( ecma_object_t *obj_p, /**< the object */
*/
bool
ecma_op_object_has_property( ecma_object_t *obj_p, /**< the object */
ecma_array_first_chunk_t *property_name_p) /**< property name */
ecma_char_t *property_name_p) /**< property name */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, property_name_p);
JERRY_ASSERT( obj_p != NULL && !obj_p->is_lexical_environment );
JERRY_ASSERT( property_name_p != NULL );
/*
* ECMA-262 v5, 8.12.2
*
* Common implementation of operation for objects other than Host, Function or Arguments objects.
*/
ecma_property_t *desc_p = ecma_op_object_get_property( obj_p, property_name_p);
return ( desc_p != NULL );
} /* ecma_op_object_has_property */
/**
@ -132,10 +416,60 @@ ecma_op_object_has_property( ecma_object_t *obj_p, /**< the object */
*/
ecma_completion_value_t
ecma_op_object_delete( ecma_object_t *obj_p, /**< the object */
ecma_array_first_chunk_t *property_name_p, /**< property name */
ecma_char_t *property_name_p, /**< property name */
bool is_throw) /**< flag that controls failure handling */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, property_name_p, is_throw);
JERRY_ASSERT( obj_p != NULL && !obj_p->is_lexical_environment );
JERRY_ASSERT( property_name_p != NULL );
/*
* ECMA-262 v5, 8.12.2
*
* Common implementation of operation for objects other than Host, Function or Arguments objects.
*/
// 1.
ecma_property_t *desc_p = ecma_op_object_get_own_property( obj_p, property_name_p);
// 2.
if ( desc_p == NULL )
{
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_TRUE);
}
// 3.
bool is_configurable;
if ( desc_p->type == ECMA_PROPERTY_NAMEDACCESSOR )
{
is_configurable = desc_p->u.named_accessor_property.configurable;
}
else
{
JERRY_ASSERT( desc_p->type == ECMA_PROPERTY_NAMEDDATA );
is_configurable = desc_p->u.named_data_property.configurable;
}
if ( is_configurable )
{
// a.
ecma_delete_property( obj_p, desc_p);
// b.
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_TRUE);
}
else if ( is_throw )
{
// 4.
return ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_TYPE));
}
else
{
// 5.
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_FALSE);
}
JERRY_UNREACHABLE();
} /* ecma_op_object_delete */
/**
@ -151,6 +485,8 @@ ecma_completion_value_t
ecma_op_object_default_value( ecma_object_t *obj_p, /**< the object */
ecma_preferred_type_hint_t hint) /**< hint on preferred result type */
{
JERRY_ASSERT( obj_p != NULL && !obj_p->is_lexical_environment );
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, hint);
} /* ecma_op_object_default_value */
@ -165,11 +501,156 @@ ecma_op_object_default_value( ecma_object_t *obj_p, /**< the object */
*/
ecma_completion_value_t
ecma_op_object_define_own_property( ecma_object_t *obj_p, /**< the object */
ecma_array_first_chunk_t *property_name_p, /**< property name */
ecma_property_t property_desc, /**< property descriptor */
ecma_char_t *property_name_p, /**< property name */
ecma_property_descriptor_t property_desc, /**< property descriptor */
bool is_throw) /**< flag that controls failure handling */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, property_name_p, property_desc, is_throw);
JERRY_ASSERT( obj_p != NULL && !obj_p->is_lexical_environment );
JERRY_ASSERT( property_name_p != NULL );
const bool is_property_desc_generic_descriptor = ( !property_desc.is_value_defined
&& !property_desc.is_writable_defined
&& !property_desc.is_get_defined
&& !property_desc.is_set_defined );
const bool is_property_desc_data_descriptor = ( property_desc.is_value_defined
|| property_desc.is_writable_defined );
const bool is_property_desc_accessor_descriptor = ( property_desc.is_get_defined
|| property_desc.is_set_defined );
// 1.
ecma_property_t *current_p = ecma_op_object_get_own_property( obj_p, property_name_p);
// 2.
bool extensible = obj_p->u.object.extensible;
if ( current_p == NULL )
{
// 3.
if ( !extensible )
{
// Reject
if ( is_throw )
{
return ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_TYPE));
}
else
{
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_FALSE);
}
}
else
{
// 4.
// a.
if ( is_property_desc_generic_descriptor
|| is_property_desc_data_descriptor )
{
ecma_create_named_data_property( obj_p,
property_name_p,
property_desc.writable,
property_desc.enumerable,
property_desc.configurable);
}
else
{
// b.
JERRY_ASSERT( is_property_desc_accessor_descriptor );
ecma_create_named_accessor_property( obj_p,
property_name_p,
property_desc.get_p,
property_desc.set_p,
property_desc.enumerable,
property_desc.configurable);
}
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_TRUE);
}
}
// 5.
if ( is_property_desc_generic_descriptor
&& !property_desc.is_enumerable_defined
&& !property_desc.is_configurable_defined )
{
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_TRUE);
}
// 6.
const bool is_current_data_descriptor = ( current_p->type == ECMA_PROPERTY_NAMEDDATA );
const bool is_current_accessor_descriptor = ( current_p->type == ECMA_PROPERTY_NAMEDACCESSOR );
JERRY_ASSERT( is_current_data_descriptor || is_current_accessor_descriptor );
bool is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = true;
if ( property_desc.is_value_defined )
{
if ( !is_current_data_descriptor
|| !ecma_op_same_value( property_desc.value,
current_p->u.named_data_property.value) )
{
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
}
}
if ( property_desc.is_writable_defined )
{
if ( !is_current_data_descriptor
|| property_desc.writable != current_p->u.named_data_property.writable )
{
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
}
}
if ( property_desc.is_get_defined )
{
if ( !is_current_accessor_descriptor
|| property_desc.get_p != ecma_get_pointer( current_p->u.named_accessor_property.get_p) )
{
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
}
}
if ( property_desc.is_set_defined )
{
if ( !is_current_accessor_descriptor
|| property_desc.set_p != ecma_get_pointer( current_p->u.named_accessor_property.set_p) )
{
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
}
}
if ( property_desc.is_enumerable_defined )
{
if ( ( is_current_data_descriptor
&& property_desc.enumerable != current_p->u.named_data_property.enumerable )
|| ( is_current_accessor_descriptor
&& property_desc.configurable != current_p->u.named_accessor_property.enumerable ) )
{
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
}
}
if ( property_desc.is_configurable_defined )
{
if ( ( is_current_data_descriptor
&& property_desc.configurable != current_p->u.named_data_property.configurable )
|| ( is_current_accessor_descriptor
&& property_desc.configurable != current_p->u.named_accessor_property.configurable ) )
{
is_every_field_in_desc_also_occurs_in_current_desc_with_same_value = false;
}
}
if ( is_every_field_in_desc_also_occurs_in_current_desc_with_same_value )
{
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_TRUE);
}
// 7., ...
JERRY_UNIMPLEMENTED();
} /* ecma_op_object_define_own_property */
/**

View File

@ -26,22 +26,22 @@
* @{
*/
extern ecma_completion_value_t ecma_op_object_get( ecma_object_t *obj_p, ecma_array_first_chunk_t *property_name_p);
extern ecma_property_t *ecma_op_object_get_own_property( ecma_object_t *obj_p, ecma_array_first_chunk_t *property_name_p);
extern ecma_property_t *ecma_op_object_get_property( ecma_object_t *obj_p, ecma_array_first_chunk_t *property_name_p);
extern ecma_completion_value_t ecma_op_object_get( ecma_object_t *obj_p, ecma_char_t *property_name_p);
extern ecma_property_t *ecma_op_object_get_own_property( ecma_object_t *obj_p, ecma_char_t *property_name_p);
extern ecma_property_t *ecma_op_object_get_property( ecma_object_t *obj_p, ecma_char_t *property_name_p);
extern ecma_completion_value_t ecma_op_object_put( ecma_object_t *obj_p,
ecma_array_first_chunk_t *property_name_p,
ecma_char_t *property_name_p,
ecma_value_t value,
bool is_throw);
extern bool ecma_op_object_can_put( ecma_object_t *obj_p, ecma_array_first_chunk_t *property_name_p);
extern bool ecma_op_object_has_property( ecma_object_t *obj_p, ecma_array_first_chunk_t *property_name_p);
extern bool ecma_op_object_can_put( ecma_object_t *obj_p, ecma_char_t *property_name_p);
extern bool ecma_op_object_has_property( ecma_object_t *obj_p, ecma_char_t *property_name_p);
extern ecma_completion_value_t ecma_op_object_delete( ecma_object_t *obj_p,
ecma_array_first_chunk_t *property_name_p,
ecma_char_t *property_name_p,
bool is_throw);
extern ecma_completion_value_t ecma_op_object_default_value( ecma_object_t *obj_p, ecma_preferred_type_hint_t hint);
extern ecma_completion_value_t ecma_op_object_define_own_property( ecma_object_t *obj_p,
ecma_array_first_chunk_t *property_name_p,
ecma_property_t property_desc,
ecma_char_t *property_name_p,
ecma_property_descriptor_t property_desc,
bool is_throw);
/**