Renaming core -> jerry-core.

This commit is contained in:
Ruben Ayrapetyan
2015-02-17 19:00:34 +03:00
parent b6d018d019
commit 88353e93cf
183 changed files with 14 additions and 14 deletions
+162
View File
@@ -0,0 +1,162 @@
# Copyright 2015 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.
cmake_minimum_required (VERSION 2.8.12)
project (JerryCore CXX C ASM)
# Definitions
# Get version information from git
execute_process(COMMAND git symbolic-ref -q HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE JERRY_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE JERRY_GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Get build date
execute_process(COMMAND date +%d/%m/%Y
OUTPUT_VARIABLE JERRY_BUILD_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(DEFINES_JERRY
JERRY_BUILD_DATE="${JERRY_BUILD_DATE}"
JERRY_COMMIT_HASH="${JERRY_GIT_COMMIT}"
JERRY_BRANCH_NAME="${JERRY_GIT_BRANCH}")
# Build modes
# Debug
set(DEFINES_JERRY_DEBUG JERRY_ENABLE_PRETTY_PRINTER)
# Release
set(DEFINES_JERRY_RELEASE JERRY_NDEBUG)
# Unit tests
set(DEFINES_JERRY_UNITTESTS )
# Modifiers
# Full profile
set(DEFINES_FULL_PROFILE CONFIG_ECMA_NUMBER_TYPE=CONFIG_ECMA_NUMBER_FLOAT64)
# Compact profile
set(DEFINES_COMPACT_PROFILE
CONFIG_ECMA_COMPACT_PROFILE)
# Minimal compact profile
set(DEFINES_COMPACT_PROFILE_MINIMAL
CONFIG_ECMA_COMPACT_PROFILE
CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN
CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
CONFIG_ECMA_COMPACT_PROFILE_DISABLE_MATH_BUILTIN
CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN
CONFIG_ECMA_COMPACT_PROFILE_DISABLE_JSON_BUILTIN
CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN)
# Memory statistics
set(DEFINES_JERRY_MEMORY_STATISTICS MEM_STATS)
# Valgrind
set(DEFINES_JERRY_VALGRIND JERRY_VALGRIND)
# Platform-specific
# Linux
# MCU
math(EXPR MEM_HEAP_AREA_SIZE_16K "16 * 1024")
set(DEFINES_JERRY_MCU CONFIG_MEM_HEAP_AREA_SIZE=${MEM_HEAP_AREA_SIZE_16K})
# Include directories
set(INCLUDE_CORE
${CMAKE_SOURCE_DIR}/jerry-core
${CMAKE_SOURCE_DIR}/jerry-core/mem
${CMAKE_SOURCE_DIR}/jerry-core/vm
${CMAKE_SOURCE_DIR}/jerry-core/ecma/builtin-objects
${CMAKE_SOURCE_DIR}/jerry-core/ecma/base
${CMAKE_SOURCE_DIR}/jerry-core/ecma/operations
${CMAKE_SOURCE_DIR}/jerry-core/parser/collections
${CMAKE_SOURCE_DIR}/jerry-core/parser/js
${CMAKE_SOURCE_DIR}/jerry-core/jrt)
# Third-party
# Valgrind
set(INCLUDE_THIRD_PARTY_VALGRIND ${CMAKE_SOURCE_DIR}/third-party/valgrind)
# Sources
# Jerry core
file(GLOB SOURCE_CORE_MEM mem/*.cpp)
file(GLOB SOURCE_CORE_VM vm/*.cpp)
file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.cpp)
file(GLOB SOURCE_CORE_ECMA_BASE ecma/base/*.cpp)
file(GLOB SOURCE_CORE_ECMA_OPERATIONS ecma/operations/*.cpp)
file(GLOB SOURCE_CORE_PARSER_COLLECTIONS parser/collections/*.cpp)
file(GLOB SOURCE_CORE_PARSER_JS parser/js/*.cpp)
file(GLOB SOURCE_CORE_JRT jrt/*.cpp)
set(SOURCE_CORE
jerry.cpp
${SOURCE_CORE_MEM}
${SOURCE_CORE_VM}
${SOURCE_CORE_ECMA_BUILTINS}
${SOURCE_CORE_ECMA_BASE}
${SOURCE_CORE_ECMA_OPERATIONS}
${SOURCE_CORE_PARSER_COLLECTIONS}
${SOURCE_CORE_PARSER_JS}
${SOURCE_CORE_JRT})
# Per-option configuration
# Valgrind
if("${ENABLE_VALGRIND}" STREQUAL "ON")
set(DEFINES_JERRY ${DEFINES_JERRY} ${DEFINES_JERRY_VALGRIND})
set(INCLUDE_CORE ${INCLUDE_CORE} ${INCLUDE_THIRD_PARTY_VALGRIND})
endif()
# Platform-specific configuration
set(DEFINES_JERRY ${DEFINES_JERRY} ${DEFINES_JERRY_${PLATFORM}})
# Targets declaration
function(declare_targets_for_build_mode BUILD_MODE)
set(TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}})
set(DEFINES_JERRY ${DEFINES_JERRY} ${DEFINES_JERRY_${BUILD_MODE}})
function(declare_target_with_modifiers ) # modifiers are passed in ARGN implicit argument
foreach(MODIFIER ${ARGN})
set(TARGET_NAME ${TARGET_NAME}${MODIFIER_SUFFIX_${MODIFIER}})
set(DEFINES_JERRY ${DEFINES_JERRY} ${DEFINES_${MODIFIER}})
endforeach()
add_library(${TARGET_NAME}.jerry-core STATIC ${SOURCE_CORE})
set_property(TARGET ${TARGET_NAME}.jerry-core
PROPERTY COMPILE_FLAGS "${COMPILE_FLAGS_JERRY} ${CXX_FLAGS_JERRY} ${FLAGS_COMMON_${BUILD_MODE}}")
target_compile_definitions(${TARGET_NAME}.jerry-core PRIVATE ${DEFINES_JERRY})
target_include_directories(${TARGET_NAME}.jerry-core PRIVATE ${INCLUDE_CORE})
if("${BUILD_MODE}" STREQUAL "UNITTESTS")
target_compile_definitions(${TARGET_NAME}.jerry-core INTERFACE ${DEFINES_JERRY})
target_include_directories(${TARGET_NAME}.jerry-core INTERFACE ${INCLUDE_CORE})
endif()
endfunction()
foreach(MODIFIERS_LIST ${MODIFIERS_LISTS})
separate_arguments(MODIFIERS_LIST)
declare_target_with_modifiers(${MODIFIERS_LIST})
endforeach()
endfunction()
declare_targets_for_build_mode(DEBUG)
declare_targets_for_build_mode(RELEASE)
declare_targets_for_build_mode(UNITTESTS)
+153
View File
@@ -0,0 +1,153 @@
/* Copyright 2014-2015 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 CONFIG_H
#define CONFIG_H
/**
* Limit of data (system heap, engine's data except engine's own heap)
*/
#define CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE (1024)
/**
* Limit of stack size
*/
#define CONFIG_MEM_STACK_LIMIT (4096)
/**
* Log2 of maximum number of chunks in a pool
*/
#define CONFIG_MEM_POOL_MAX_CHUNKS_NUMBER_LOG (8)
/**
* Size of pool chunk
*
* Should not be less than size of any of ECMA Object Model's data types.
*/
#define CONFIG_MEM_POOL_CHUNK_SIZE (8)
/**
* Minimum number of chunks in a pool allocated by pools' manager.
*/
#define CONFIG_MEM_LEAST_CHUNK_NUMBER_IN_POOL (32)
/**
* Size of heap chunk
*/
#define CONFIG_MEM_HEAP_CHUNK_SIZE (64)
/**
* Size of heap
*/
#ifndef CONFIG_MEM_HEAP_AREA_SIZE
# define CONFIG_MEM_HEAP_AREA_SIZE (64 * 1024)
#endif /* !CONFIG_MEM_HEAP_AREA_SIZE */
/**
* Log2 of maximum possible offset in the heap
*
* The option affects size of compressed pointer that in turn
* affects size of ECMA Object Model's data types.
*
* In any case size of any of the types should not exceed CONFIG_MEM_POOL_CHUNK_SIZE.
*
* On the other hand, value 2 ^ CONFIG_MEM_HEAP_OFFSET_LOG should not be less than CONFIG_MEM_HEAP_AREA_SIZE.
*/
#define CONFIG_MEM_HEAP_OFFSET_LOG (16)
/**
* Number of lower bits in key of literal hash table.
*/
#define CONFIG_LITERAL_HASH_TABLE_KEY_BITS (7)
/**
* Width of fields used for holding counter of references to ecma-strings and ecma-objects
*
* The option affects maximum number of simultaneously existing:
* - references to one string;
* - stack references to one object
* The number is ((2 ^ CONFIG_ECMA_REFERENCE_COUNTER_WIDTH) - 1).
*
* Also the option affects size of ECMA Object Model's data types.
* In any case size of any of the types should not exceed CONFIG_MEM_POOL_CHUNK_SIZE.
*/
#define CONFIG_ECMA_REFERENCE_COUNTER_WIDTH (10)
/**
* Maximum length of strings' concatenation
*/
#define CONFIG_ECMA_STRING_MAX_CONCATENATION_LENGTH (1048576)
/**
* Use 32-bit/64-bit float for ecma-numbers
*/
#define CONFIG_ECMA_NUMBER_FLOAT32 (1u) /* 32-bit float */
#define CONFIG_ECMA_NUMBER_FLOAT64 (2u) /* 64-bit float */
#ifndef CONFIG_ECMA_NUMBER_TYPE
# define CONFIG_ECMA_NUMBER_TYPE CONFIG_ECMA_NUMBER_FLOAT32
#else /* !CONFIG_ECMA_NUMBER_TYPE */
# if (CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT32 \
&& CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT64)
# error "ECMA-number storage is configured incorrectly"
# endif /* CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT32
&& CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT64 */
#endif /* CONFIG_ECMA_NUMBER_TYPE */
/**
* Representation for ecma-characters
*/
#define CONFIG_ECMA_CHAR_ASCII (1) /* ASCII */
#define CONFIG_ECMA_CHAR_UTF16 (2) /* UTF-16 */
#ifndef CONFIG_ECMA_CHAR_ENCODING
# define CONFIG_ECMA_CHAR_ENCODING CONFIG_ECMA_CHAR_ASCII
#else /* !CONFIG_ECMA_CHAR_ENCODING */
# if (CONFIG_ECMA_CHAR_ENCODING != CONFIG_ECMA_CHAR_ASCII \
&& CONFIG_ECMA_CHAR_ENCODING != CONFIG_ECMA_CHAR_UTF16)
# error "ECMA-char encoding is configured incorrectly"
# endif /* CONFIG_ECMA_CHAR_ENCODING != CONFIG_ECMA_CHAR_ASCII
&& CONFIG_ECMA_CHAR_ENCODING != CONFIG_ECMA_CHAR_UTF16 */
#endif /* CONFIG_ECMA_CHAR_ENCODING */
/**
* Number of ecma-values inlined into stack frame
*/
#define CONFIG_ECMA_STACK_FRAME_INLINED_VALUES_NUMBER (16)
/**
* Link Global Environment to an empty declarative lexical environment
* instead of lexical environment bound to Global Object.
*/
// #define CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE
/**
* Implementation should correspond to ECMA Compact Profile
*/
// #define CONFIG_ECMA_COMPACT_PROFILE
#ifdef CONFIG_ECMA_COMPACT_PROFILE
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_MATH_BUILTIN
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_JSON_BUILTIN
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
#endif /* !CONFIG_H */
+95
View File
@@ -0,0 +1,95 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-globals.h"
#include "ecma-gc.h"
#include "ecma-lcache.h"
#include "jrt.h"
#include "mem-poolman.h"
JERRY_STATIC_ASSERT (sizeof (ecma_value_t) <= sizeof (uint16_t));
JERRY_STATIC_ASSERT (sizeof (ecma_property_t) <= sizeof (uint64_t));
JERRY_STATIC_ASSERT (sizeof (ecma_object_t) <= sizeof (uint64_t));
JERRY_STATIC_ASSERT (ECMA_OBJECT_OBJ_TYPE_SIZE <= sizeof (uint64_t) * JERRY_BITSINBYTE);
JERRY_STATIC_ASSERT (ECMA_OBJECT_LEX_ENV_TYPE_SIZE <= sizeof (uint64_t) * JERRY_BITSINBYTE);
JERRY_STATIC_ASSERT (sizeof (ecma_collection_header_t) == sizeof (uint64_t));
JERRY_STATIC_ASSERT (sizeof (ecma_collection_chunk_t) == sizeof (uint64_t));
JERRY_STATIC_ASSERT (sizeof (ecma_string_t) == sizeof (uint64_t));
JERRY_STATIC_ASSERT (sizeof (ecma_completion_value_t) == sizeof (uint32_t));
JERRY_STATIC_ASSERT (sizeof (ecma_label_descriptor_t) == sizeof (uint64_t));
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaalloc Routines for allocation/freeing memory for ECMA data types
* @{
*/
/**
* Implementation of routines for allocation/freeing memory for ECMA data types.
*
* All allocation routines from this module have the same structure:
* 1. Try to allocate memory.
* 2. If allocation was successful, return pointer to the allocated block.
* 3. Run garbage collection.
* 4. Try to allocate memory.
* 5. If allocation was successful, return pointer to the allocated block;
* else - shutdown engine.
*/
/**
* Template of an allocation routine.
*/
#define ALLOC(ecma_type) ecma_ ## ecma_type ## _t * \
ecma_alloc_ ## ecma_type (void) \
{ \
ecma_ ## ecma_type ## _t *p ## ecma_type = (ecma_ ## ecma_type ## _t *) mem_pools_alloc (); \
\
JERRY_ASSERT (p ## ecma_type != NULL); \
\
return p ## ecma_type; \
}
/**
* Deallocation routine template
*/
#define DEALLOC(ecma_type) void \
ecma_dealloc_ ## ecma_type (ecma_ ## ecma_type ## _t *p ## ecma_type) \
{ \
mem_pools_free ((uint8_t*) p ## ecma_type); \
}
/**
* Declaration of alloc/free routine for specified ecma-type.
*/
#define DECLARE_ROUTINES_FOR(ecma_type) \
ALLOC(ecma_type) \
DEALLOC(ecma_type)
DECLARE_ROUTINES_FOR (object)
DECLARE_ROUTINES_FOR (property)
DECLARE_ROUTINES_FOR (number)
DECLARE_ROUTINES_FOR (collection_header)
DECLARE_ROUTINES_FOR (collection_chunk)
DECLARE_ROUTINES_FOR (string)
DECLARE_ROUTINES_FOR (label_descriptor)
/**
* @}
* @}
*/
+117
View File
@@ -0,0 +1,117 @@
/* Copyright 2014-2015 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.
*/
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaalloc Routines for allocation/freeing memory for ECMA data types
* @{
*/
#ifndef JERRY_ECMA_ALLOC_H
#define JERRY_ECMA_ALLOC_H
#include "ecma-globals.h"
/**
* Allocate memory for ecma-object
*
* @return pointer to allocated memory
*/
extern ecma_object_t *ecma_alloc_object (void);
/**
* Dealloc memory from an ecma-object
*/
extern void ecma_dealloc_object (ecma_object_t *object_p);
/**
* Allocate memory for ecma-property
*
* @return pointer to allocated memory
*/
extern ecma_property_t *ecma_alloc_property (void);
/**
* Dealloc memory from an ecma-property
*/
extern void ecma_dealloc_property (ecma_property_t *property_p);
/**
* Allocate memory for ecma-number
*
* @return pointer to allocated memory
*/
extern ecma_number_t *ecma_alloc_number (void);
/**
* Dealloc memory from an ecma-number
*/
extern void ecma_dealloc_number (ecma_number_t *number_p);
/**
* Allocate memory for header of a collection
*
* @return pointer to allocated memory
*/
extern ecma_collection_header_t *ecma_alloc_collection_header (void);
/**
* Dealloc memory from the collection's header
*/
extern void ecma_dealloc_collection_header (ecma_collection_header_t *collection_header_p);
/**
* Allocate memory for non-first chunk of a collection
*
* @return pointer to allocated memory
*/
extern ecma_collection_chunk_t* ecma_alloc_collection_chunk (void);
/**
* Dealloc memory from non-first chunk of a collection
*/
extern void ecma_dealloc_collection_chunk (ecma_collection_chunk_t *non_first_chunk_p);
/**
* Allocate memory for ecma-string descriptor
*
* @return pointer to allocated memory
*/
extern ecma_string_t *ecma_alloc_string (void);
/**
* Dealloc memory from ecma-string descriptor
*/
extern void ecma_dealloc_string (ecma_string_t *string_p);
/**
* Allocate memory for label descriptor
*
* @return pointer to allocated memory
*/
extern ecma_label_descriptor_t *ecma_alloc_label_descriptor (void);
/**
* Dealloc memory from label descriptor
*/
extern void ecma_dealloc_label_descriptor (ecma_label_descriptor_t *label_desc_p);
#endif /* JERRY_ECMA_ALLOC_H */
/**
* @}
* @}
*/
+730
View File
@@ -0,0 +1,730 @@
/* Copyright 2014-2015 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.
*/
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmagc Garbage collector
* @{
*/
/**
* Garbage collector implementation
*/
#include "ecma-alloc.h"
#include "ecma-globals.h"
#include "ecma-gc.h"
#include "ecma-helpers.h"
#include "ecma-lcache.h"
#include "ecma-stack.h"
#include "jrt.h"
#include "jrt-libc-includes.h"
#include "jrt-bit-fields.h"
/**
* Global lists of objects sorted by generation identifier.
*/
static ecma_object_t *ecma_gc_objects_lists[ ECMA_GC_GEN_COUNT ];
static void ecma_gc_mark (ecma_object_t *object_p, ecma_gc_gen_t maximum_gen_to_traverse);
static void ecma_gc_sweep (ecma_object_t *object_p);
/**
* Get GC reference counter of the object.
*/
static uint32_t
ecma_gc_get_object_refs (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT (object_p != NULL);
return (uint32_t) jrt_extract_bit_field (object_p->container,
ECMA_OBJECT_GC_REFS_POS,
ECMA_OBJECT_GC_REFS_WIDTH);
} /* ecma_gc_get_object_refs */
/**
* Set GC reference counter of the object.
*/
static void
ecma_gc_set_object_refs (ecma_object_t *object_p, /**< object */
uint32_t refs) /**< new reference counter */
{
JERRY_ASSERT (object_p != NULL);
object_p->container = jrt_set_bit_field_value (object_p->container,
refs,
ECMA_OBJECT_GC_REFS_POS,
ECMA_OBJECT_GC_REFS_WIDTH);
} /* ecma_gc_set_object_refs */
/**
* Get GC generation of the object.
*/
static ecma_gc_gen_t
ecma_gc_get_object_generation (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT (object_p != NULL);
ecma_gc_gen_t ret = (ecma_gc_gen_t) jrt_extract_bit_field (object_p->container,
ECMA_OBJECT_GC_GENERATION_POS,
ECMA_OBJECT_GC_GENERATION_WIDTH);
JERRY_ASSERT (ret < ECMA_GC_GEN_COUNT);
return ret;
} /* ecma_gc_get_object_generation */
/**
* Set GC generation of the object.
*/
static void
ecma_gc_set_object_generation (ecma_object_t *object_p, /**< object */
ecma_gc_gen_t generation) /**< generation */
{
JERRY_ASSERT (object_p != NULL);
JERRY_ASSERT (generation < ECMA_GC_GEN_COUNT);
object_p->container = jrt_set_bit_field_value (object_p->container,
generation,
ECMA_OBJECT_GC_GENERATION_POS,
ECMA_OBJECT_GC_GENERATION_WIDTH);
} /* ecma_gc_set_object_generation */
/**
* Get next object in list of objects with same generation.
*/
static ecma_object_t*
ecma_gc_get_object_next (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT (object_p != NULL);
JERRY_ASSERT (sizeof (uintptr_t) * JERRY_BITSINBYTE >= ECMA_OBJECT_GC_NEXT_CP_WIDTH);
uintptr_t next_cp = (uintptr_t) jrt_extract_bit_field (object_p->container,
ECMA_OBJECT_GC_NEXT_CP_POS,
ECMA_OBJECT_GC_NEXT_CP_WIDTH);
return ECMA_GET_POINTER (ecma_object_t,
next_cp);
} /* ecma_gc_get_object_next */
/**
* Set next object in list of objects with same generation.
*/
static void
ecma_gc_set_object_next (ecma_object_t *object_p, /**< object */
ecma_object_t *next_object_p) /**< next object */
{
JERRY_ASSERT (object_p != NULL);
uintptr_t next_cp;
ECMA_SET_POINTER (next_cp, next_object_p);
JERRY_ASSERT (sizeof (uintptr_t) * JERRY_BITSINBYTE >= ECMA_OBJECT_GC_NEXT_CP_WIDTH);
object_p->container = jrt_set_bit_field_value (object_p->container,
next_cp,
ECMA_OBJECT_GC_NEXT_CP_POS,
ECMA_OBJECT_GC_NEXT_CP_WIDTH);
} /* ecma_gc_set_object_next */
/**
* Get visited flag of the object.
*/
static bool
ecma_gc_is_object_visited (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT (object_p != NULL);
return jrt_extract_bit_field (object_p->container,
ECMA_OBJECT_GC_VISITED_POS,
ECMA_OBJECT_GC_VISITED_WIDTH);
} /* ecma_gc_is_object_visited */
/**
* Set visited flag of the object.
*/
static void
ecma_gc_set_object_visited (ecma_object_t *object_p, /**< object */
bool is_visited) /**< flag value */
{
JERRY_ASSERT (object_p != NULL);
object_p->container = jrt_set_bit_field_value (object_p->container,
is_visited,
ECMA_OBJECT_GC_VISITED_POS,
ECMA_OBJECT_GC_VISITED_WIDTH);
} /* ecma_gc_set_object_visited */
/**
* Get may_ref_younger_objects flag of the object.
*/
static bool
ecma_gc_is_object_may_ref_younger_objects (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT (object_p != NULL);
return jrt_extract_bit_field (object_p->container,
ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_POS,
ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_WIDTH);
} /* ecma_gc_is_object_may_ref_younger_objects */
/**
* Set may_ref_younger_objects flag of the object.
*/
static void
ecma_gc_set_object_may_ref_younger_objects (ecma_object_t *object_p, /**< object */
bool is_may_ref_younger_objects) /**< flag value */
{
JERRY_ASSERT (object_p != NULL);
object_p->container = jrt_set_bit_field_value (object_p->container,
is_may_ref_younger_objects,
ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_POS,
ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_WIDTH);
} /* ecma_gc_set_object_may_ref_younger_objects */
/**
* Initialize GC information for the object
*/
void
ecma_init_gc_info (ecma_object_t *object_p) /**< object */
{
ecma_gc_set_object_refs (object_p, 1);
ecma_gc_set_object_generation (object_p, ECMA_GC_GEN_0);
ecma_gc_set_object_next (object_p, ecma_gc_objects_lists[ ECMA_GC_GEN_0 ]);
ecma_gc_objects_lists[ ECMA_GC_GEN_0 ] = object_p;
/* Should be set to false at the beginning of garbage collection */
ecma_gc_set_object_visited (object_p, true);
ecma_gc_set_object_may_ref_younger_objects (object_p, false);
} /* ecma_init_gc_info */
/**
* Increase reference counter of an object
*/
void
ecma_ref_object (ecma_object_t *object_p) /**< object */
{
ecma_gc_set_object_refs (object_p, ecma_gc_get_object_refs (object_p) + 1);
} /* ecma_ref_object */
/**
* Decrease reference counter of an object
*/
void
ecma_deref_object (ecma_object_t *object_p) /**< object */
{
JERRY_ASSERT(ecma_gc_get_object_refs (object_p) > 0);
ecma_gc_set_object_refs (object_p, ecma_gc_get_object_refs (object_p) - 1);
} /* ecma_deref_object */
/**
* Set may_ref_younger_objects of specified object to true,
* if value is object-value and it's object's generation
* is less than generation of object specified by obj_p.
*/
void
ecma_gc_update_may_ref_younger_object_flag_by_value (ecma_object_t *obj_p, /**< object */
const ecma_value_t& value) /**< value */
{
if (!ecma_is_value_object (value))
{
return;
}
ecma_object_t *ref_obj_p = ecma_get_object_from_value (value);
JERRY_ASSERT(ref_obj_p != NULL);
ecma_gc_update_may_ref_younger_object_flag_by_object (obj_p, ref_obj_p);
} /* ecma_gc_update_may_ref_younger_object_flag_by_value */
void
ecma_gc_update_may_ref_younger_object_flag_by_object (ecma_object_t *obj_p, /**< object */
ecma_object_t *ref_obj_p) /**< referenced object
or NULL */
{
if (ref_obj_p == NULL)
{
return;
}
if (ecma_gc_get_object_generation (ref_obj_p) < ecma_gc_get_object_generation (obj_p))
{
ecma_gc_set_object_may_ref_younger_objects (obj_p, true);
}
} /* ecma_gc_update_may_ref_younger_object_flag_by_object */
/**
* Initialize garbage collector
*/
void
ecma_gc_init (void)
{
memset (ecma_gc_objects_lists, 0, sizeof (ecma_gc_objects_lists));
} /* ecma_gc_init */
/**
* Mark objects as visited starting from specified object as root
* if referenced object's generation is less or equal to maximum_gen_to_traverse.
*/
void
ecma_gc_mark (ecma_object_t *object_p, /**< start object */
ecma_gc_gen_t maximum_gen_to_traverse) /**< start recursive traverse
if referenced object generation
is less or equal to maximum_gen_to_traverse */
{
JERRY_ASSERT(object_p != NULL);
ecma_gc_set_object_visited (object_p, true);
bool does_ref_a_younger_object = false;
bool traverse_properties = true;
if (ecma_is_lexical_environment (object_p))
{
ecma_object_t *lex_env_p = ecma_get_lex_env_outer_reference (object_p);
if (lex_env_p != NULL)
{
if (ecma_gc_get_object_generation (lex_env_p) <= maximum_gen_to_traverse)
{
if (!ecma_gc_is_object_visited (lex_env_p))
{
ecma_gc_mark (lex_env_p, ECMA_GC_GEN_COUNT);
}
}
if (ecma_gc_get_object_generation (lex_env_p) < ecma_gc_get_object_generation (object_p))
{
does_ref_a_younger_object = true;
}
}
if (ecma_get_lex_env_type (object_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND)
{
ecma_object_t *binding_object_p = ecma_get_lex_env_binding_object (object_p);
if (ecma_gc_get_object_generation (binding_object_p) <= maximum_gen_to_traverse)
{
if (!ecma_gc_is_object_visited (binding_object_p))
{
ecma_gc_mark (binding_object_p, ECMA_GC_GEN_COUNT);
}
}
if (ecma_gc_get_object_generation (binding_object_p) < ecma_gc_get_object_generation (object_p))
{
does_ref_a_younger_object = true;
}
traverse_properties = false;
}
}
else
{
ecma_object_t *proto_p = ecma_get_object_prototype (object_p);
if (proto_p != NULL)
{
if (ecma_gc_get_object_generation (proto_p) <= maximum_gen_to_traverse)
{
if (!ecma_gc_is_object_visited (proto_p))
{
ecma_gc_mark (proto_p, ECMA_GC_GEN_COUNT);
}
}
if (ecma_gc_get_object_generation (proto_p) < ecma_gc_get_object_generation (object_p))
{
does_ref_a_younger_object = true;
}
}
}
if (traverse_properties)
{
for (ecma_property_t *property_p = ecma_get_property_list (object_p), *next_property_p;
property_p != NULL;
property_p = next_property_p)
{
next_property_p = ECMA_GET_POINTER (ecma_property_t,
property_p->next_property_p);
switch ((ecma_property_type_t) property_p->type)
{
case ECMA_PROPERTY_NAMEDDATA:
{
ecma_value_t value = ecma_get_named_data_property_value (property_p);
if (ecma_is_value_object (value))
{
ecma_object_t *value_obj_p = ecma_get_object_from_value (value);
if (ecma_gc_get_object_generation (value_obj_p) <= maximum_gen_to_traverse)
{
if (!ecma_gc_is_object_visited (value_obj_p))
{
ecma_gc_mark (value_obj_p, ECMA_GC_GEN_COUNT);
}
}
if (ecma_gc_get_object_generation (value_obj_p) < ecma_gc_get_object_generation (object_p))
{
does_ref_a_younger_object = true;
}
}
break;
}
case ECMA_PROPERTY_NAMEDACCESSOR:
{
ecma_object_t *getter_obj_p = ECMA_GET_POINTER (ecma_object_t,
property_p->u.named_accessor_property.get_p);
ecma_object_t *setter_obj_p = ECMA_GET_POINTER (ecma_object_t,
property_p->u.named_accessor_property.set_p);
if (getter_obj_p != NULL)
{
if (ecma_gc_get_object_generation (getter_obj_p) <= maximum_gen_to_traverse)
{
if (!ecma_gc_is_object_visited (getter_obj_p))
{
ecma_gc_mark (getter_obj_p, ECMA_GC_GEN_COUNT);
}
}
if (ecma_gc_get_object_generation (getter_obj_p) < ecma_gc_get_object_generation (object_p))
{
does_ref_a_younger_object = true;
}
}
if (setter_obj_p != NULL)
{
if (ecma_gc_get_object_generation (setter_obj_p) <= maximum_gen_to_traverse)
{
if (!ecma_gc_is_object_visited (setter_obj_p))
{
ecma_gc_mark (setter_obj_p, ECMA_GC_GEN_COUNT);
}
}
if (ecma_gc_get_object_generation (setter_obj_p) < ecma_gc_get_object_generation (object_p))
{
does_ref_a_younger_object = true;
}
}
break;
}
case ECMA_PROPERTY_INTERNAL:
{
ecma_internal_property_id_t property_id = (ecma_internal_property_id_t) property_p->u.internal_property.type;
uint32_t property_value = property_p->u.internal_property.value;
switch (property_id)
{
case ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES: /* a collection of ecma-values */
case ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES: /* a collection of ecma-values */
{
JERRY_UNIMPLEMENTED("Indexed array storage is not implemented yet.");
}
case ECMA_INTERNAL_PROPERTY_PROTOTYPE: /* the property's value is located in ecma_object_t
(see above in the routine) */
case ECMA_INTERNAL_PROPERTY_EXTENSIBLE: /* the property's value is located in ecma_object_t
(see above in the routine) */
case ECMA_INTERNAL_PROPERTY__COUNT: /* not a real internal property type,
* but number of the real internal property types */
{
JERRY_UNREACHABLE();
}
case ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS: /* a collection of strings */
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE: /* compressed pointer to a ecma_string_t */
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE: /* compressed pointer to a ecma_number_t */
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE: /* a simple boolean value */
case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */
case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ID: /* an integer */
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_ID: /* an integer */
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31: /* an integer (bit-mask) */
case ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63: /* an integer (bit-mask) */
{
break;
}
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */
{
ecma_object_t *obj_p = ECMA_GET_NON_NULL_POINTER(ecma_object_t, property_value);
if (ecma_gc_get_object_generation (obj_p) <= maximum_gen_to_traverse)
{
if (!ecma_gc_is_object_visited (obj_p))
{
ecma_gc_mark (obj_p, ECMA_GC_GEN_COUNT);
}
}
if (ecma_gc_get_object_generation (obj_p) < ecma_gc_get_object_generation (object_p))
{
does_ref_a_younger_object = true;
}
break;
}
}
break;
}
}
}
}
if (!does_ref_a_younger_object)
{
ecma_gc_set_object_may_ref_younger_objects (object_p, false);
}
} /* ecma_gc_mark */
/**
* Free specified object
*/
void
ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
{
JERRY_ASSERT(object_p != NULL
&& !ecma_gc_is_object_visited (object_p)
&& ecma_gc_get_object_refs (object_p) == 0);
if (!ecma_is_lexical_environment (object_p) ||
ecma_get_lex_env_type (object_p) != ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND)
{
for (ecma_property_t *property = ecma_get_property_list (object_p), *next_property_p;
property != NULL;
property = next_property_p)
{
next_property_p = ECMA_GET_POINTER (ecma_property_t,
property->next_property_p);
ecma_free_property (object_p, property);
}
}
ecma_dealloc_object (object_p);
} /* ecma_gc_sweep */
/**
* Run garbage collecting
*/
void
ecma_gc_run (ecma_gc_gen_t max_gen_to_collect) /**< maximum generation to run collection on */
{
JERRY_ASSERT(max_gen_to_collect < ECMA_GC_GEN_COUNT);
/* clearing visited flags for all objects of generations to be processed */
for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; gen_id <= max_gen_to_collect; gen_id = (ecma_gc_gen_t) (gen_id + 1))
{
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
obj_iter_p != NULL;
obj_iter_p = ecma_gc_get_object_next (obj_iter_p))
{
ecma_gc_set_object_visited (obj_iter_p, false);
}
}
/* if some object is referenced from stack or globals (i.e. it is root),
* start recursive marking traverse from the object */
for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; gen_id <= max_gen_to_collect; gen_id = (ecma_gc_gen_t) (gen_id + 1))
{
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
obj_iter_p != NULL;
obj_iter_p = ecma_gc_get_object_next (obj_iter_p))
{
if (ecma_gc_get_object_refs (obj_iter_p) > 0
&& !ecma_gc_is_object_visited (obj_iter_p))
{
ecma_gc_mark (obj_iter_p, ECMA_GC_GEN_COUNT);
}
}
}
/* if some object is referenced from a register variable (i.e. it is root),
* start recursive marking traverse from the object */
for (ecma_stack_frame_t *frame_iter_p = ecma_stack_get_top_frame ();
frame_iter_p != NULL;
frame_iter_p = frame_iter_p->prev_frame_p)
{
for (int32_t reg_index = 0; reg_index < frame_iter_p->regs_number; reg_index++)
{
ecma_value_t reg_value = ecma_stack_frame_get_reg_value (frame_iter_p, reg_index);
if (ecma_is_value_object (reg_value))
{
ecma_object_t *obj_p = ecma_get_object_from_value (reg_value);
if (!ecma_gc_is_object_visited (obj_p))
{
ecma_gc_mark (obj_p, ECMA_GC_GEN_COUNT);
}
}
}
}
/* if some object from generations that are not processed during current session may reference
* younger generations, start recursive marking traverse from the object, but one the first level
* consider only references to object of at most max_gen_to_collect generation */
for (ecma_gc_gen_t gen_id = (ecma_gc_gen_t) (max_gen_to_collect + 1);
gen_id < ECMA_GC_GEN_COUNT;
gen_id = (ecma_gc_gen_t) (gen_id + 1))
{
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
obj_iter_p != NULL;
obj_iter_p = ecma_gc_get_object_next (obj_iter_p))
{
if (ecma_gc_is_object_may_ref_younger_objects (obj_iter_p))
{
ecma_gc_mark (obj_iter_p, max_gen_to_collect);
}
#ifndef JERRY_NDEBUG
else if (gen_id > ECMA_GC_GEN_0)
{
ecma_gc_set_object_may_ref_younger_objects (obj_iter_p, true);
ecma_gc_mark (obj_iter_p, (ecma_gc_gen_t) (gen_id - 1));
JERRY_ASSERT (!ecma_gc_is_object_may_ref_younger_objects (obj_iter_p));
}
#endif /* !JERRY_NDEBUG */
}
}
JERRY_ASSERT (max_gen_to_collect <= ECMA_GC_GEN_COUNT);
ecma_object_t *gen_last_obj_p[ ECMA_GC_GEN_COUNT ];
#ifndef JERRY_NDEBUG
memset (gen_last_obj_p, 0, sizeof (gen_last_obj_p));
#endif /* !JERRY_NDEBUG */
for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0; gen_id <= max_gen_to_collect; gen_id = (ecma_gc_gen_t) (gen_id + 1))
{
ecma_object_t *obj_prev_p = NULL;
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ],
*obj_next_p;
obj_iter_p != NULL;
obj_iter_p = obj_next_p)
{
obj_next_p = ecma_gc_get_object_next (obj_iter_p);
if (!ecma_gc_is_object_visited (obj_iter_p))
{
ecma_gc_sweep (obj_iter_p);
if (likely (obj_prev_p != NULL))
{
ecma_gc_set_object_next (obj_prev_p, obj_next_p);
}
else
{
ecma_gc_objects_lists[ gen_id ] = obj_next_p;
}
}
else
{
obj_prev_p = obj_iter_p;
if (ecma_gc_get_object_generation (obj_iter_p) != ECMA_GC_GEN_COUNT - 1)
{
/* the object will be promoted to next generation */
ecma_gc_set_object_generation (obj_iter_p, (ecma_gc_gen_t) (ecma_gc_get_object_generation (obj_iter_p) + 1));
}
}
}
gen_last_obj_p[ gen_id ] = obj_prev_p;
}
ecma_gc_gen_t gen_to_promote = max_gen_to_collect;
if (unlikely (gen_to_promote == ECMA_GC_GEN_COUNT - 1))
{
/* not promoting last generation */
gen_to_promote = (ecma_gc_gen_t) (gen_to_promote - 1);
}
/* promoting to next generation */
if (gen_last_obj_p[ gen_to_promote ] != NULL)
{
ecma_gc_set_object_next (gen_last_obj_p [gen_to_promote], ecma_gc_objects_lists[ gen_to_promote + 1 ]);
ecma_gc_objects_lists[ gen_to_promote + 1 ] = ecma_gc_objects_lists[ gen_to_promote ];
ecma_gc_objects_lists[ gen_to_promote ] = NULL;
}
for (int32_t gen_id = (int32_t)gen_to_promote - 1;
gen_id >= 0;
gen_id--)
{
ecma_gc_objects_lists[ gen_id + 1 ] = ecma_gc_objects_lists[ gen_id ];
ecma_gc_objects_lists[ gen_id ] = NULL;
}
#ifndef JERRY_NDEBUG
for (ecma_gc_gen_t gen_id = ECMA_GC_GEN_0;
gen_id < ECMA_GC_GEN_COUNT;
gen_id = (ecma_gc_gen_t) (gen_id + 1))
{
for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ gen_id ];
obj_iter_p != NULL;
obj_iter_p = ecma_gc_get_object_next (obj_iter_p))
{
JERRY_ASSERT(ecma_gc_get_object_generation (obj_iter_p) == gen_id);
}
}
#endif /* !JERRY_NDEBUG */
} /* ecma_gc_run */
/**
* Try to free some memory (depending on severity).
*/
void
ecma_try_to_give_back_some_memory (mem_try_give_memory_back_severity_t severity) /**< severity of
* the request */
{
if (severity == MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_LOW)
{
ecma_gc_run (ECMA_GC_GEN_0);
}
else if (severity == MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_MEDIUM)
{
ecma_gc_run (ECMA_GC_GEN_1);
}
else if (severity == MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_HIGH)
{
ecma_gc_run (ECMA_GC_GEN_2);
}
else
{
JERRY_ASSERT (severity == MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_CRITICAL);
/* Freeing as much memory as we currently can */
ecma_lcache_invalidate_all ();
ecma_gc_run ((ecma_gc_gen_t) (ECMA_GC_GEN_COUNT - 1));
}
} /* ecma_try_to_give_back_some_memory */
/**
* @}
* @}
*/
+54
View File
@@ -0,0 +1,54 @@
/* Copyright 2014-2015 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.
*/
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmagc Garbage collector
* @{
*/
#ifndef ECMA_GC_H
#define ECMA_GC_H
#include "ecma-globals.h"
#include "mem-allocator.h"
/**
* GC generation identifier
*/
typedef enum
{
ECMA_GC_GEN_0, /**< generation 0 */
ECMA_GC_GEN_1, /**< generation 1 */
ECMA_GC_GEN_2, /**< generation 2 */
ECMA_GC_GEN_COUNT /**< generations' number */
} ecma_gc_gen_t;
extern void ecma_gc_init (void);
extern void ecma_init_gc_info (ecma_object_t *object_p);
extern void ecma_ref_object (ecma_object_t *object_p);
extern void ecma_deref_object (ecma_object_t *object_p);
extern void ecma_gc_update_may_ref_younger_object_flag_by_value (ecma_object_t *obj_p, const ecma_value_t& value);
extern void ecma_gc_update_may_ref_younger_object_flag_by_object (ecma_object_t *obj_p, ecma_object_t *ref_obj_p);
extern void ecma_gc_run (ecma_gc_gen_t max_gen_to_collect);
extern void ecma_try_to_give_back_some_memory (mem_try_give_memory_back_severity_t severity);
#endif /* !ECMA_GC_H */
/**
* @}
* @}
*/
+823
View File
@@ -0,0 +1,823 @@
/* Copyright 2014-2015 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.
*/
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmatypes ECMA types
* @{
*/
#ifndef JERRY_ECMA_GLOBALS_H
#define JERRY_ECMA_GLOBALS_H
#include "config.h"
#include "jrt.h"
#include "mem-allocator.h"
/** \addtogroup compressedpointer Compressed pointer
* @{
*/
/**
* Ecma-pointer field is used to calculate ecma-value's address.
*
* Ecma-pointer contains value's shifted offset from common Ecma-pointers' base.
* The offset is shifted right by MEM_ALIGNMENT_LOG.
* Least significant MEM_ALIGNMENT_LOG bits of non-shifted offset are zeroes.
*/
#define ECMA_POINTER_FIELD_WIDTH MEM_COMPRESSED_POINTER_WIDTH
/**
* The NULL value for compressed pointers
*/
#define ECMA_NULL_POINTER MEM_COMPRESSED_POINTER_NULL
/**
* @}
*/
/**
* Type of ecma-value
*/
typedef enum
{
ECMA_TYPE_SIMPLE, /**< simple value */
ECMA_TYPE_NUMBER, /**< 64-bit integer */
ECMA_TYPE_STRING, /**< pointer to description of a string */
ECMA_TYPE_OBJECT /**< pointer to description of an object */
} ecma_type_t;
/**
* Simple ecma-values
*/
typedef enum
{
/**
* 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, /**< implementation defined value for an array's elements that exist,
but are 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 */
} ecma_simple_value_t;
/**
* Type of ecma-property
*/
typedef enum
{
ECMA_PROPERTY_NAMEDDATA, /**< named data property */
ECMA_PROPERTY_NAMEDACCESSOR, /**< named accessor property */
ECMA_PROPERTY_INTERNAL /**< internal property */
} ecma_property_type_t;
/**
* Type of block evaluation (completion) result.
*
* See also: ECMA-262 v5, 8.9.
*/
typedef enum
{
ECMA_COMPLETION_TYPE_NORMAL, /**< default block completion */
ECMA_COMPLETION_TYPE_RETURN, /**< block completed with return */
ECMA_COMPLETION_TYPE_BREAK, /**< block completed with break */
ECMA_COMPLETION_TYPE_CONTINUE, /**< block completed with continue */
ECMA_COMPLETION_TYPE_THROW, /**< block completed with throw */
ECMA_COMPLETION_TYPE_EXIT, /**< implementation-defined completion type
for finishing script execution */
ECMA_COMPLETION_TYPE_META /**< implementation-defined completion type
for meta opcode */
} ecma_completion_type_t;
/**
* Description of an ecma-value
*
* Bit-field structure: type (2) | value (ECMA_POINTER_FIELD_WIDTH)
*/
typedef uint16_t ecma_value_t;
/**
* Value type (ecma_type_t)
*/
#define ECMA_VALUE_TYPE_POS (0)
#define ECMA_VALUE_TYPE_WIDTH (2)
/**
* Simple value (ecma_simple_value_t) or compressed pointer to value (depending on value_type)
*/
#define ECMA_VALUE_VALUE_POS (ECMA_VALUE_TYPE_POS + \
ECMA_VALUE_TYPE_WIDTH)
#define ECMA_VALUE_VALUE_WIDTH (ECMA_POINTER_FIELD_WIDTH)
/**
* ecma_value_t size
*/
#define ECMA_VALUE_SIZE (ECMA_VALUE_VALUE_POS + ECMA_VALUE_VALUE_WIDTH)
/**
* Description of a block completion value
*
* See also: ECMA-262 v5, 8.9.
*
* value (16)
* Bit-field structure: type (8) | padding (8) <
* label_desc_cp (16)
*/
typedef uint32_t ecma_completion_value_t;
/**
* Type (ecma_completion_type_t)
*/
#define ECMA_COMPLETION_VALUE_TYPE_POS (0)
#define ECMA_COMPLETION_VALUE_TYPE_WIDTH (8)
/**
* Padding (1 byte)
*/
#define ECMA_COMPLETION_VALUE_PADDING_WIDTH (8)
/**
* Value
*
* Used for normal, return, throw and exit completion types.
*/
#define ECMA_COMPLETION_VALUE_VALUE_POS (ECMA_COMPLETION_VALUE_TYPE_POS + \
ECMA_COMPLETION_VALUE_TYPE_WIDTH + \
ECMA_COMPLETION_VALUE_PADDING_WIDTH)
#define ECMA_COMPLETION_VALUE_VALUE_WIDTH (ECMA_VALUE_SIZE)
/**
* Label
*
* Used for break and continue completion types.
*/
#define ECMA_COMPLETION_VALUE_LABEL_DESC_CP_POS (ECMA_COMPLETION_VALUE_TYPE_POS + \
ECMA_COMPLETION_VALUE_TYPE_WIDTH + \
ECMA_COMPLETION_VALUE_PADDING_WIDTH)
#define ECMA_COMPLETION_VALUE_LABEL_DESC_CP_WIDTH (ECMA_POINTER_FIELD_WIDTH)
/**
* Label
*
* Used for break and continue completion types.
*/
typedef struct
{
/** Target's offset */
uint32_t offset;
/** Levels to label left */
uint32_t depth;
} ecma_label_descriptor_t;
/**
* Internal properties' identifiers.
*/
typedef enum
{
ECMA_INTERNAL_PROPERTY_CLASS, /**< [[Class]] */
ECMA_INTERNAL_PROPERTY_PROTOTYPE, /**< [[Prototype]] */
ECMA_INTERNAL_PROPERTY_EXTENSIBLE, /**< [[Extensible]] */
ECMA_INTERNAL_PROPERTY_SCOPE, /**< [[Scope]] */
ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP, /**< [[ParametersMap]] */
ECMA_INTERNAL_PROPERTY_CODE, /**< [[Code]] */
ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS, /**< [[FormalParameters]] */
ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE, /**< [[Primitive value]] for String objects */
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE, /**< [[Primitive value]] for Number objects */
ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE, /**< [[Primitive value]] for Boolean objects */
/** Part of an array, that is indexed by numbers */
ECMA_INTERNAL_PROPERTY_NUMBER_INDEXED_ARRAY_VALUES,
/** Part of an array, that is indexed by strings */
ECMA_INTERNAL_PROPERTY_STRING_INDEXED_ARRAY_VALUES,
/** Implementation-defined identifier of built-in object */
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID,
/** Implementation-defined identifier of built-in routine
that corresponds to a built-in function object
([[Built-in routine ID]]) */
ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_ID,
/**
* Bit-mask of non-instantiated built-in's properties (bits 0-31)
*/
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31,
/**
* Bit-mask of non-instantiated built-in's properties (bits 32-63)
*/
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63,
/**
* Number of internal properties' types
*/
ECMA_INTERNAL_PROPERTY__COUNT
} ecma_internal_property_id_t;
/**
* Property's 'Writable' attribute's values description.
*/
typedef enum
{
ECMA_PROPERTY_NOT_WRITABLE, /**< property's 'Writable' attribute is false */
ECMA_PROPERTY_WRITABLE /**< property's 'Writable' attribute is true */
} ecma_property_writable_value_t;
/**
* Property's 'Enumerable' attribute's values description.
*/
typedef enum
{
ECMA_PROPERTY_NOT_ENUMERABLE, /**< property's 'Enumerable' attribute is false */
ECMA_PROPERTY_ENUMERABLE /**< property's 'Enumerable' attribute is true */
} ecma_property_enumerable_value_t;
/**
* Property's 'Configurable' attribute's values description.
*/
typedef enum
{
ECMA_PROPERTY_NOT_CONFIGURABLE, /**< property's 'Configurable' attribute is false */
ECMA_PROPERTY_CONFIGURABLE /**< property's 'Configurable' attribute is true */
} ecma_property_configurable_value_t;
/**
* Width of internal property type field's width
*/
#define ECMA_PROPERTY_INTERNAL_PROPERTY_TYPE_WIDTH (5)
/**
* Description of ecma-property
*/
typedef struct ecma_property_t
{
/** Property's type (ecma_property_type_t) */
unsigned int type : 2;
/** Compressed pointer to next property */
unsigned int next_property_p : ECMA_POINTER_FIELD_WIDTH;
/** Property's details (depending on Type) */
union
{
/** Description of named data property */
struct __attr_packed___ ecma_named_data_property_t
{
/** Compressed pointer to property's name (pointer to String) */
unsigned int name_p : ECMA_POINTER_FIELD_WIDTH;
/** Attribute 'Writable' (ecma_property_writable_value_t) */
unsigned int writable : 1;
/** Attribute 'Enumerable' (ecma_property_enumerable_value_t) */
unsigned int enumerable : 1;
/** Attribute 'Configurable' (ecma_property_configurable_value_t) */
unsigned int configurable : 1;
/** Flag indicating whether the property is registered in LCache */
unsigned int is_lcached : 1;
/** Value */
ecma_value_t value;
} named_data_property;
/** Description of named accessor property */
struct __attr_packed___ ecma_named_accessor_property_t
{
/** Compressed pointer to property's name (pointer to String) */
unsigned int name_p : ECMA_POINTER_FIELD_WIDTH;
/** Attribute 'Enumerable' (ecma_property_enumerable_value_t) */
unsigned int enumerable : 1;
/** Attribute 'Configurable' (ecma_property_configurable_value_t) */
unsigned int configurable : 1;
/** Flag indicating whether the property is registered in LCache */
unsigned int is_lcached : 1;
/** Compressed pointer to property's getter */
unsigned int get_p : ECMA_POINTER_FIELD_WIDTH;
/** Compressed pointer to property's setter */
unsigned int set_p : ECMA_POINTER_FIELD_WIDTH;
} named_accessor_property;
/** Description of internal property */
struct __attr_packed___ ecma_internal_property_t
{
/** Internal property's type */
unsigned int type : ECMA_PROPERTY_INTERNAL_PROPERTY_TYPE_WIDTH;
/** Value (may be a compressed pointer) */
uint32_t value;
} internal_property;
} u;
} ecma_property_t;
/**
* Types of lexical environments
*/
typedef enum
{
ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE, /**< declarative lexical environment */
ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND /**< object-bound lexical environment */
} ecma_lexical_environment_type_t;
/**
* Internal object types
*
* Warning:
* definition order is significant (see also dispatch tables in libecmaobjects/ecma-objects.c)
*/
typedef enum
{
ECMA_OBJECT_TYPE_GENERAL, /**< all objects that are not String (15.5), Function (15.3),
Arguments (10.6), Array (15.4) specification-defined objects
and not host objects */
ECMA_OBJECT_TYPE_STRING, /**< String objects (15.5) */
ECMA_OBJECT_TYPE_FUNCTION, /**< Function objects (15.3), created through 13.2 routine */
ECMA_OBJECT_TYPE_BOUND_FUNCTION, /**< Function objects (15.3), created through 15.3.4.5 routine */
ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION, /** One of built-in functions described in section 15
of ECMA-262 v5 specification */
ECMA_OBJECT_TYPE_ARGUMENTS, /**< Arguments object (10.6) */
ECMA_OBJECT_TYPE_ARRAY, /**< Array object (15.4) */
// ECMA_OBJECT_TYPE_HOST, /**< Host object */
ECMA_OBJECT_TYPE__COUNT /**< number of object types */
} ecma_object_type_t;
/**
* Description of ECMA-object or lexical environment
* (depending on is_lexical_environment).
*/
typedef struct
{
/* Common part for objects and lexical environments */
/**
* Compressed pointer to property list
*/
#define ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_POS (0)
#define ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_WIDTH (ECMA_POINTER_FIELD_WIDTH)
/**
* Flag indicating whether it is a general object (false)
* or a lexical environment (true)
*/
#define ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_POS (ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_POS + \
ECMA_OBJECT_PROPERTIES_OR_BOUND_OBJECT_CP_WIDTH)
#define ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_WIDTH (1)
/**
* Reference counter of the object, i.e. number of references
* to the object from stack variables.
*/
#define ECMA_OBJECT_GC_REFS_POS (ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_POS + \
ECMA_OBJECT_IS_LEXICAL_ENVIRONMENT_WIDTH)
#define ECMA_OBJECT_GC_REFS_WIDTH (CONFIG_ECMA_REFERENCE_COUNTER_WIDTH)
/**
* Identifier of GC generation.
*/
#define ECMA_OBJECT_GC_GENERATION_POS (ECMA_OBJECT_GC_REFS_POS + \
ECMA_OBJECT_GC_REFS_WIDTH)
#define ECMA_OBJECT_GC_GENERATION_WIDTH (2)
/**
* Compressed pointer to next object in the global list of objects with same generation.
*/
#define ECMA_OBJECT_GC_NEXT_CP_POS (ECMA_OBJECT_GC_GENERATION_POS + \
ECMA_OBJECT_GC_GENERATION_WIDTH)
#define ECMA_OBJECT_GC_NEXT_CP_WIDTH (ECMA_POINTER_FIELD_WIDTH)
/**
* Marker that is set if the object was visited during graph traverse.
*/
#define ECMA_OBJECT_GC_VISITED_POS (ECMA_OBJECT_GC_NEXT_CP_POS + \
ECMA_OBJECT_GC_NEXT_CP_WIDTH)
#define ECMA_OBJECT_GC_VISITED_WIDTH (1)
/**
* Flag indicating that the object may reference objects of younger generations in its properties.
*/
#define ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_POS (ECMA_OBJECT_GC_VISITED_POS + \
ECMA_OBJECT_GC_VISITED_WIDTH)
#define ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_WIDTH (1)
/* Objects' only part */
/**
* Attribute 'Extensible'
*/
#define ECMA_OBJECT_OBJ_EXTENSIBLE_POS (ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_POS + \
ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_WIDTH)
#define ECMA_OBJECT_OBJ_EXTENSIBLE_WIDTH (1)
/**
* Implementation internal object type (ecma_object_type_t)
*/
#define ECMA_OBJECT_OBJ_TYPE_POS (ECMA_OBJECT_OBJ_EXTENSIBLE_POS + \
ECMA_OBJECT_OBJ_EXTENSIBLE_WIDTH)
#define ECMA_OBJECT_OBJ_TYPE_WIDTH (3)
/**
* Compressed pointer to prototype object (ecma_object_t)
*/
#define ECMA_OBJECT_OBJ_PROTOTYPE_OBJECT_CP_POS (ECMA_OBJECT_OBJ_TYPE_POS + \
ECMA_OBJECT_OBJ_TYPE_WIDTH)
#define ECMA_OBJECT_OBJ_PROTOTYPE_OBJECT_CP_WIDTH (ECMA_POINTER_FIELD_WIDTH)
/**
* Flag indicating whether the object is a built-in object
*/
#define ECMA_OBJECT_OBJ_IS_BUILTIN_POS (ECMA_OBJECT_OBJ_PROTOTYPE_OBJECT_CP_POS + \
ECMA_OBJECT_OBJ_PROTOTYPE_OBJECT_CP_WIDTH)
#define ECMA_OBJECT_OBJ_IS_BUILTIN_WIDTH (1)
/**
* Size of structure for objects
*/
#define ECMA_OBJECT_OBJ_TYPE_SIZE (ECMA_OBJECT_OBJ_IS_BUILTIN_POS + \
ECMA_OBJECT_OBJ_IS_BUILTIN_WIDTH)
/* Lexical environments' only part */
/**
* Type of lexical environment (ecma_lexical_environment_type_t).
*/
#define ECMA_OBJECT_LEX_ENV_TYPE_POS (ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_POS + \
ECMA_OBJECT_GC_MAY_REF_YOUNGER_OBJECTS_WIDTH)
#define ECMA_OBJECT_LEX_ENV_TYPE_WIDTH (1)
/**
* Compressed pointer to outer lexical environment
*/
#define ECMA_OBJECT_LEX_ENV_OUTER_REFERENCE_CP_POS (ECMA_OBJECT_LEX_ENV_TYPE_POS + \
ECMA_OBJECT_LEX_ENV_TYPE_WIDTH)
#define ECMA_OBJECT_LEX_ENV_OUTER_REFERENCE_CP_WIDTH (ECMA_POINTER_FIELD_WIDTH)
/**
* 'provideThis' property of object-bound lexical environments
*/
#define ECMA_OBJECT_LEX_ENV_PROVIDE_THIS_POS (ECMA_OBJECT_LEX_ENV_OUTER_REFERENCE_CP_POS + \
ECMA_OBJECT_LEX_ENV_OUTER_REFERENCE_CP_WIDTH)
#define ECMA_OBJECT_LEX_ENV_PROVIDE_THIS_WIDTH (1)
/**
* Size of structure for lexical environments
*/
#define ECMA_OBJECT_LEX_ENV_TYPE_SIZE (ECMA_OBJECT_LEX_ENV_PROVIDE_THIS_POS + \
ECMA_OBJECT_LEX_ENV_PROVIDE_THIS_WIDTH)
uint64_t container; /**< container for fields described above */
} 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]] */
bool is_writable;
/** [[Enumerable]] */
bool is_enumerable;
/** [[Configurable]] */
bool is_configurable;
} ecma_property_descriptor_t;
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
/**
* Description of an ecma-character
*/
typedef uint8_t ecma_char_t;
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
/**
* Description of an ecma-character
*/
typedef uint16_t ecma_char_t;
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
/**
* Description of an ecma-number
*/
typedef float ecma_number_t;
/**
* Maximum number of significant digits that ecma-number can store
*/
#define ECMA_NUMBER_MAX_DIGITS (9)
#elif CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64
/**
* Description of an ecma-number
*/
typedef double ecma_number_t;
/**
* Maximum number of significant digits that ecma-number can store
*/
#define ECMA_NUMBER_MAX_DIGITS (18)
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64 */
/**
* Value '0' of ecma_number_t
*/
#define ECMA_NUMBER_ZERO ((ecma_number_t) 0)
/**
* Value '1' of ecma_number_t
*/
#define ECMA_NUMBER_ONE ((ecma_number_t) 1)
/**
* Value '2' of ecma_number_t
*/
#define ECMA_NUMBER_TWO ((ecma_number_t) 2)
/**
* Value '0.5' of ecma_number_t
*/
#define ECMA_NUMBER_HALF ((ecma_number_t) 0.5f)
/**
* Minimum positive and maximum value of ecma-number
*/
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
# define ECMA_NUMBER_MIN_VALUE (FLT_MIN)
# define ECMA_NUMBER_MAX_VALUE (FLT_MAX)
#elif CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64
/**
* Number.MAX_VALUE
*
* See also: ECMA_262 v5, 15.7.3.2
*/
# define ECMA_NUMBER_MAX_VALUE ((ecma_number_t)1.7976931348623157e+308)
/**
* Number.MIN_VALUE
*
* See also: ECMA_262 v5, 15.7.3.3
*/
# define ECMA_NUMBER_MIN_VALUE ((ecma_number_t)5e-324)
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64 */
/**
* Euler number
*/
#define ECMA_NUMBER_E ((ecma_number_t)2.7182818284590452354)
/**
* Natural logarithm of 10
*/
#define ECMA_NUMBER_LN10 ((ecma_number_t)2.302585092994046)
/**
* Natural logarithm of 2
*/
#define ECMA_NUMBER_LN2 ((ecma_number_t)0.6931471805599453)
/**
* Logarithm base 2 of the Euler number
*/
#define ECMA_NUMBER_LOG2E ((ecma_number_t)1.4426950408889634)
/**
* Logarithm base 10 of the Euler number
*/
#define ECMA_NUMBER_LOG10E ((ecma_number_t)0.4342944819032518)
/**
* Pi number
*/
#define ECMA_NUMBER_PI ((ecma_number_t)3.1415926535897932)
/**
* Square root of 0.5
*/
#define ECMA_NUMBER_SQRT_1_2 ((ecma_number_t)0.7071067811865476)
/**
* Square root of 2
*/
#define ECMA_NUMBER_SQRT2 ((ecma_number_t)1.4142135623730951)
/**
* Null character (zt-string end marker)
*/
#define ECMA_CHAR_NULL ((ecma_char_t) '\0')
/**
* Maximum number of characters in string representation of ecma-number
*/
#define ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER 64
/**
* Maximum number of characters in string representation of ecma-uint32
*/
#define ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32 32
/**
* Maximum value of valid array index
*
* See also:
* ECMA-262 v5, 15.4
*/
#define ECMA_MAX_VALUE_OF_VALID_ARRAY_INDEX ((uint32_t) (-1))
/**
* Description of a collection's/string's length
*/
typedef uint16_t ecma_length_t;
/**
* Description of a collection's header.
*/
typedef struct
{
/** Compressed pointer to next chunk with collection's data */
uint16_t next_chunk_cp;
/** Number of elements in the collection */
ecma_length_t unit_number;
/** Place for the collection's data */
uint8_t data[ sizeof (uint64_t) - sizeof (uint32_t) ];
} ecma_collection_header_t;
/**
* Description of non-first chunk in a collection's chain of chunks
*/
typedef struct
{
/** Compressed pointer to next chunk */
uint16_t next_chunk_cp;
/** Characters */
uint8_t data[ sizeof (uint64_t) - sizeof (uint16_t) ];
} ecma_collection_chunk_t;
/**
* Identifier for ecma-string's actual data container
*/
typedef enum
{
ECMA_STRING_CONTAINER_LIT_TABLE, /**< actual data is in literal table */
ECMA_STRING_CONTAINER_HEAP_CHUNKS, /**< actual data is on the heap
in a ecma_collection_chunk_t chain */
ECMA_STRING_CONTAINER_HEAP_NUMBER, /**< actual data is on the heap as a ecma_number_t */
ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< actual data is UInt32-represeneted Number
stored locally in the string's descriptor */
ECMA_STRING_CONTAINER_CONCATENATION, /**< the ecma-string is concatenation of two specified ecma-strings */
ECMA_STRING_CONTAINER_MAGIC_STRING /**< the ecma-string is equal to one of ECMA magic strings */
} ecma_string_container_t;
FIXME (Move to library that should define the type (literal.h /* ? */))
/**
* Index in literal table
*/
typedef uint32_t literal_index_t;
/**
* Identifiers of ECMA magic string constants
*/
typedef enum
{
#define ECMA_MAGIC_STRING_DEF(id, ascii_zt_string) \
id,
#include "ecma-magic-strings.inc.h"
#undef ECMA_MAGIC_STRING_DEF
ECMA_MAGIC_STRING__COUNT /**< number of magic strings */
} ecma_magic_string_id_t;
/**
* ECMA string hash
*/
typedef uint8_t ecma_string_hash_t;
/**
* Number of string's last characters to use for hash calculation
*/
#define ECMA_STRING_HASH_LAST_CHARS_COUNT (2)
/**
* ECMA string-value descriptor
*/
typedef struct
{
/** Reference counter for the string */
unsigned int refs : CONFIG_ECMA_REFERENCE_COUNTER_WIDTH;
/** Flag indicating whether the string descriptor is placed
* in a stack variable (not in the heap) */
unsigned int is_stack_var : 1;
/** Where the string's data is placed (ecma_string_container_t) */
uint8_t container;
/** Hash of the string (calculated from two last characters of the string) */
ecma_string_hash_t hash;
/**
* Actual data or identifier of it's place in container (depending on 'container' field)
*/
union
{
/** Index of string in literal table */
literal_index_t lit_index;
/** Compressed pointer to an ecma_collection_header_t */
unsigned int collection_cp : ECMA_POINTER_FIELD_WIDTH;
/** Compressed pointer to an ecma_number_t */
unsigned int number_cp : ECMA_POINTER_FIELD_WIDTH;
/** UInt32-represented number placed locally in the descriptor */
uint32_t uint32_number;
/** Representation of concatenation */
struct
{
unsigned int string1_cp : ECMA_POINTER_FIELD_WIDTH;
unsigned int string2_cp : ECMA_POINTER_FIELD_WIDTH;
} concatenation;
/** Identifier of magic string */
ecma_magic_string_id_t magic_string_id;
/** For zeroing and comparison in some cases */
uint32_t common_field;
} u;
} ecma_string_t;
/**
* @}
*/
#endif /* JERRY_ECMA_GLOBALS_H */
/**
* @}
* @}
*/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,934 @@
/* 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.
*/
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
* @{
*/
#include "ecma-globals.h"
#include "ecma-helpers.h"
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
JERRY_STATIC_ASSERT (sizeof (ecma_number_t) == sizeof (uint32_t));
/**
* Width of sign field
*
* See also:
* IEEE-754 2008, 3.6, Table 3.5
*/
#define ECMA_NUMBER_SIGN_WIDTH (1)
/**
* Width of biased exponent field
*
* See also:
* IEEE-754 2008, 3.6, Table 3.5
*/
#define ECMA_NUMBER_BIASED_EXP_WIDTH (8)
/**
* Width of fraction field
*
* See also:
* IEEE-754 2008, 3.6, Table 3.5
*/
#define ECMA_NUMBER_FRACTION_WIDTH (23)
/**
* Packing sign, fraction and biased exponent to ecma-number
*
* @return ecma-number with specified sign, biased_exponent and fraction
*/
static ecma_number_t
ecma_number_pack (bool sign, /**< sign */
uint32_t biased_exp, /**< biased exponent */
uint64_t fraction) /**< fraction */
{
const uint32_t fraction_pos = 0;
const uint32_t biased_exp_pos = fraction_pos + ECMA_NUMBER_FRACTION_WIDTH;
const uint32_t sign_pos = biased_exp_pos + ECMA_NUMBER_BIASED_EXP_WIDTH;
JERRY_ASSERT ((biased_exp & ~((1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1)) == 0);
JERRY_ASSERT ((fraction & ~((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1)) == 0);
uint32_t packed_value = (((sign ? 1u : 0u) << sign_pos) |
(biased_exp << biased_exp_pos) |
(((uint32_t) fraction) << fraction_pos));
union
{
uint32_t u32_value;
ecma_number_t float_value;
} u;
u.u32_value = packed_value;
return u.float_value;
} /* ecma_number_pack */
/**
* Unpacking sign, fraction and biased exponent from ecma-number
*/
static void
ecma_number_unpack (ecma_number_t num, /**< ecma-number */
bool *sign_p, /**< optional out: sign */
uint32_t *biased_exp_p, /**< optional out: biased exponent */
uint64_t *fraction_p) /**< optional out: fraction */
{
const uint32_t fraction_pos = 0;
const uint32_t biased_exp_pos = fraction_pos + ECMA_NUMBER_FRACTION_WIDTH;
const uint32_t sign_pos = biased_exp_pos + ECMA_NUMBER_BIASED_EXP_WIDTH;
union
{
uint32_t u32_value;
ecma_number_t float_value;
} u;
u.float_value = num;
uint32_t packed_value = u.u32_value;
if (sign_p != NULL)
{
*sign_p = ((packed_value >> sign_pos) != 0);
}
if (biased_exp_p != NULL)
{
*biased_exp_p = (((packed_value) & ~(1u << sign_pos)) >> biased_exp_pos);
}
if (fraction_p != NULL)
{
*fraction_p = (packed_value & ((1u << ECMA_NUMBER_FRACTION_WIDTH) - 1));
}
} /* ecma_number_unpack */
/**
* Value used to calculate exponent from biased exponent
*
* See also:
* IEEE-754 2008, 3.6, Table 3.5
*/
const int32_t ecma_number_exponent_bias = 127;
/**
* Relative precision used in calculation with ecma-numbers
*/
const ecma_number_t ecma_number_relative_eps = 1.0e-10f;
#elif CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64
JERRY_STATIC_ASSERT (sizeof (ecma_number_t) == sizeof (uint64_t));
/**
* Width of sign field
*
* See also:
* IEEE-754 2008, 3.6, Table 3.5
*/
#define ECMA_NUMBER_SIGN_WIDTH (1)
/**
* Width of biased exponent field
*
* See also:
* IEEE-754 2008, 3.6, Table 3.5
*/
#define ECMA_NUMBER_BIASED_EXP_WIDTH (11)
/**
* Width of fraction field
*
* See also:
* IEEE-754 2008, 3.6, Table 3.5
*/
#define ECMA_NUMBER_FRACTION_WIDTH (52)
/**
* Packing sign, fraction and biased exponent to ecma-number
*
* @return ecma-number with specified sign, biased_exponent and fraction
*/
static ecma_number_t
ecma_number_pack (bool sign, /**< sign */
uint32_t biased_exp, /**< biased exponent */
uint64_t fraction) /**< fraction */
{
const uint32_t fraction_pos = 0;
const uint32_t biased_exp_pos = fraction_pos + ECMA_NUMBER_FRACTION_WIDTH;
const uint32_t sign_pos = biased_exp_pos + ECMA_NUMBER_BIASED_EXP_WIDTH;
uint64_t packed_value = (((sign ? 1ull : 0ull) << sign_pos) |
(((uint64_t) biased_exp) << biased_exp_pos) |
(fraction << fraction_pos));
JERRY_ASSERT ((biased_exp & ~((1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1)) == 0);
JERRY_ASSERT ((fraction & ~((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1)) == 0);
union
{
uint64_t u64_value;
ecma_number_t float_value;
} u;
u.u64_value = packed_value;
return u.float_value;
} /* ecma_number_pack */
/**
* Unpacking sign, fraction and biased exponent from ecma-number
*/
static void
ecma_number_unpack (ecma_number_t num, /**< ecma-number */
bool *sign_p, /**< optional out: sign */
uint32_t *biased_exp_p, /**< optional out: biased exponent */
uint64_t *fraction_p) /**< optional out: fraction */
{
const uint32_t fraction_pos = 0;
const uint32_t biased_exp_pos = fraction_pos + ECMA_NUMBER_FRACTION_WIDTH;
const uint32_t sign_pos = biased_exp_pos + ECMA_NUMBER_BIASED_EXP_WIDTH;
union
{
uint64_t u64_value;
ecma_number_t float_value;
} u;
u.float_value = num;
uint64_t packed_value = u.u64_value;
if (sign_p != NULL)
{
*sign_p = ((packed_value >> sign_pos) != 0);
}
if (biased_exp_p != NULL)
{
*biased_exp_p = (uint32_t) (((packed_value) & ~(1ull << sign_pos)) >> biased_exp_pos);
}
if (fraction_p != NULL)
{
*fraction_p = (packed_value & ((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1));
}
} /* ecma_number_unpack */
/**
* Value used to calculate exponent from biased exponent
*
* See also:
* IEEE-754 2008, 3.6, Table 3.5
*/
const int32_t ecma_number_exponent_bias = 1023;
/**
* Relative precision used in calculation with ecma-numbers
*/
const ecma_number_t ecma_number_relative_eps = 1.0e-16;
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64 */
/**
* Get fraction of number
*
* @return normalized fraction field of number
*/
static uint64_t
ecma_number_get_fraction_field (ecma_number_t num) /**< ecma-number */
{
uint64_t fraction;
ecma_number_unpack (num, NULL, NULL, &fraction);
return fraction;
} /* ecma_number_get_fraction_field */
/**
* Get exponent of number
*
* @return exponent corresponding to normalized fraction of number
*/
static uint32_t
ecma_number_get_biased_exponent_field (ecma_number_t num) /**< ecma-number */
{
uint32_t biased_exp;
ecma_number_unpack (num, NULL, &biased_exp, NULL);
return biased_exp;
} /* ecma_number_get_biased_exponent_field */
/**
* Get sign bit of number
*
* @return 0 or 1 - value of sign bit
*/
static uint32_t
ecma_number_get_sign_field (ecma_number_t num) /**< ecma-number */
{
bool sign;
ecma_number_unpack (num, &sign, NULL, NULL);
return sign;
} /* ecma_number_get_sign_field */
/**
* Check if ecma-number is NaN
*
* @return true - if biased exponent is filled with 1 bits and
fraction is filled with anything but not all zero bits,
* false - otherwise
*/
bool
ecma_number_is_nan (ecma_number_t num) /**< ecma-number */
{
bool is_nan = (num != num);
#ifndef JERRY_NDEBUG
uint32_t biased_exp = ecma_number_get_biased_exponent_field (num);
uint64_t fraction = ecma_number_get_fraction_field (num);
/* IEEE-754 2008, 3.4, a */
bool is_nan_ieee754 = ((biased_exp == (1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1)
&& (fraction != 0));
JERRY_ASSERT (is_nan == is_nan_ieee754);
#endif /* !JERRY_NDEBUG */
return is_nan;
} /* ecma_number_is_nan */
/**
* Make a NaN.
*
* @return NaN value
*/
ecma_number_t
ecma_number_make_nan (void)
{
return ecma_number_pack (false,
(1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1u,
1u);
} /* ecma_number_make_nan */
/**
* Make an Infinity.
*
* @return if !sign - +Infinity value,
* else - -Infinity value.
*/
ecma_number_t
ecma_number_make_infinity (bool sign) /**< true - for negative Infinity,
false - for positive Infinity */
{
return ecma_number_pack (sign,
(1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1u,
0u);
} /* ecma_number_make_infinity */
/**
* Check if ecma-number is negative
*
* @return true - if sign bit of ecma-number is set
* false - otherwise
*/
bool
ecma_number_is_negative (ecma_number_t num) /**< ecma-number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
/* IEEE-754 2008, 3.4 */
return (ecma_number_get_sign_field (num) != 0);
} /* ecma_number_is_negative */
/**
* Check if ecma-number is zero
*
* @return true - if fraction is zero and biased exponent is zero,
* false - otherwise
*/
bool
ecma_number_is_zero (ecma_number_t num) /**< ecma-number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
bool is_zero = (num == ECMA_NUMBER_ZERO);
#ifndef JERRY_NDEBUG
/* IEEE-754 2008, 3.4, e */
bool is_zero_ieee754 = (ecma_number_get_fraction_field (num) == 0
&& ecma_number_get_biased_exponent_field (num) == 0);
JERRY_ASSERT (is_zero == is_zero_ieee754);
#endif /* !JERRY_NDEBUG */
return is_zero;
} /* ecma_number_is_zero */
/**
* Check if number is infinity
*
* @return true - if biased exponent is filled with 1 bits and
* fraction is filled with zero bits,
* false - otherwise.
*/
bool
ecma_number_is_infinity (ecma_number_t num) /**< ecma-number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
uint32_t biased_exp = ecma_number_get_biased_exponent_field (num);
uint64_t fraction = ecma_number_get_fraction_field (num);
/* IEEE-754 2008, 3.4, b */
return ((biased_exp == (1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1)
&& (fraction == 0));
} /* ecma_number_is_infinity */
/**
* Get fraction and exponent of the number
*
* @return shift of dot in the fraction
*/
int32_t
ecma_number_get_fraction_and_exponent (ecma_number_t num, /**< ecma-number */
uint64_t *out_fraction_p, /**< out: fraction of the number */
int32_t *out_exponent_p) /**< out: exponent of the number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
uint32_t biased_exp = ecma_number_get_biased_exponent_field (num);
uint64_t fraction = ecma_number_get_fraction_field (num);
int32_t exponent;
if (unlikely (biased_exp == 0))
{
/* IEEE-754 2008, 3.4, d */
if (ecma_number_is_zero (num))
{
exponent = -ecma_number_exponent_bias;
}
else
{
exponent = 1 - ecma_number_exponent_bias;
while (!(fraction & (1ull << ECMA_NUMBER_FRACTION_WIDTH)))
{
JERRY_ASSERT (fraction != 0);
fraction <<= 1;
exponent--;
}
}
}
else if (ecma_number_is_infinity (num))
{
/* The fraction and exponent should round to infinity */
exponent = (int32_t) biased_exp - ecma_number_exponent_bias;
JERRY_ASSERT ((fraction & (1ull << ECMA_NUMBER_FRACTION_WIDTH)) == 0);
fraction |= 1ull << ECMA_NUMBER_FRACTION_WIDTH;
}
else
{
/* IEEE-754 2008, 3.4, c */
exponent = (int32_t) biased_exp - ecma_number_exponent_bias;
JERRY_ASSERT (biased_exp > 0 && biased_exp < (1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1);
JERRY_ASSERT ((fraction & (1ull << ECMA_NUMBER_FRACTION_WIDTH)) == 0);
fraction |= 1ull << ECMA_NUMBER_FRACTION_WIDTH;
}
*out_fraction_p = fraction;
*out_exponent_p = exponent;
return ECMA_NUMBER_FRACTION_WIDTH;
} /* ecma_number_get_fraction_and_exponent */
/**
* Make normalised positive Number from given fraction and exponent
*
* @return ecma-number
*/
ecma_number_t
ecma_number_make_normal_positive_from_fraction_and_exponent (uint64_t fraction, /**< fraction */
int32_t exponent) /**< exponent */
{
uint32_t biased_exp = (uint32_t) (exponent + ecma_number_exponent_bias);
JERRY_ASSERT (biased_exp > 0 && biased_exp < (1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1);
JERRY_ASSERT ((fraction & ~((1ull << (ECMA_NUMBER_FRACTION_WIDTH + 1)) - 1)) == 0);
JERRY_ASSERT ((fraction & (1ull << ECMA_NUMBER_FRACTION_WIDTH)) != 0);
return ecma_number_pack (false,
biased_exp,
fraction & ~(1ull << ECMA_NUMBER_FRACTION_WIDTH));
} /* ecma_number_make_normal_positive_from_fraction_and_exponent */
/**
* Make Number of given sign from given mantissa value and binary exponent
*
* @return ecma-number (possibly Infinity of specified sign)
*/
ecma_number_t
ecma_number_make_from_sign_mantissa_and_exponent (bool sign, /**< true - for negative sign,
false - for positive sign */
uint64_t mantissa, /**< mantissa */
int32_t exponent) /**< binary exponent */
{
/* Rounding mantissa to fit into fraction field width */
if (mantissa & ~((1ull << (ECMA_NUMBER_FRACTION_WIDTH + 1)) - 1))
{
/* Rounded mantissa looks like the following: |00...0|1|fraction_width mantissa bits| */
while ((mantissa & ~((1ull << (ECMA_NUMBER_FRACTION_WIDTH + 1)) - 1)) != 0)
{
uint64_t rightmost_bit = (mantissa & 1);
exponent++;
mantissa >>= 1;
if ((mantissa & ~((1ull << (ECMA_NUMBER_FRACTION_WIDTH + 1)) - 1)) == 0)
{
/* Rounding to nearest value */
mantissa += rightmost_bit;
/* In the first case loop is finished,
and in the second - just one shift follows and then loop finishes */
JERRY_ASSERT (((mantissa & ~((1ull << (ECMA_NUMBER_FRACTION_WIDTH + 1)) - 1)) == 0)
|| (mantissa == (1ull << (ECMA_NUMBER_FRACTION_WIDTH + 1))));
}
}
}
/* Normalizing mantissa */
while (mantissa != 0
&& ((mantissa & (1ull << ECMA_NUMBER_FRACTION_WIDTH)) == 0))
{
exponent--;
mantissa <<= 1;
}
/* Moving floating point */
exponent += ECMA_NUMBER_FRACTION_WIDTH - 1;
int32_t biased_exp_signed = exponent + ecma_number_exponent_bias;
if (biased_exp_signed < 1)
{
/* Denormalizing mantissa if biased_exponent is less than zero */
while (biased_exp_signed < 0)
{
biased_exp_signed++;
mantissa >>= 1;
}
/* Rounding to nearest value */
mantissa += 1;
mantissa >>= 1;
/* Encoding denormalized exponent */
biased_exp_signed = 0;
}
else
{
/* Clearing highest mantissa bit that should have been non-zero if mantissa is non-zero */
mantissa &= ~(1ull << ECMA_NUMBER_FRACTION_WIDTH);
}
uint32_t biased_exp = (uint32_t) biased_exp_signed;
if (biased_exp >= ((1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1))
{
return ecma_number_make_infinity (sign);
}
JERRY_ASSERT (biased_exp < (1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1);
JERRY_ASSERT ((mantissa & ~((1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1)) == 0);
return ecma_number_pack (sign,
biased_exp,
mantissa);
} /* ecma_number_make_from_sign_mantissa_and_exponent */
/**
* Get previous representable ecma-number
*
* @return maximum ecma-number that is less compared to passed argument
*/
ecma_number_t
ecma_number_get_prev (ecma_number_t num) /**< ecma-number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
JERRY_ASSERT (!ecma_number_is_zero (num));
if (ecma_number_is_negative (num))
{
return ecma_number_negate (ecma_number_get_next (num));
}
uint32_t biased_exp = ecma_number_get_biased_exponent_field (num);
uint64_t fraction = ecma_number_get_fraction_field (num);
if (fraction == 0 && biased_exp != 0)
{
fraction = (1ull << ECMA_NUMBER_FRACTION_WIDTH) - 1;
biased_exp--;
}
else
{
fraction--;
}
return ecma_number_pack (false,
biased_exp,
fraction);
} /* ecma_number_get_prev */
/**
* Get next representable ecma-number
*
* @return minimum ecma-number that is greater compared to passed argument
*/
ecma_number_t
ecma_number_get_next (ecma_number_t num) /**< ecma-number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
JERRY_ASSERT (!ecma_number_is_infinity (num));
if (ecma_number_is_negative (num))
{
return ecma_number_negate (ecma_number_get_prev (num));
}
uint32_t biased_exp = ecma_number_get_biased_exponent_field (num);
uint64_t fraction = ecma_number_get_fraction_field (num);
fraction |= (1ull << ECMA_NUMBER_FRACTION_WIDTH);
fraction++;
if ((fraction & (1ull << ECMA_NUMBER_FRACTION_WIDTH)) == 0)
{
fraction >>= 1;
biased_exp++;
}
JERRY_ASSERT (fraction & (1ull << ECMA_NUMBER_FRACTION_WIDTH));
fraction &= ~(1ull << ECMA_NUMBER_FRACTION_WIDTH);
return ecma_number_pack (false,
biased_exp,
fraction);
} /* ecma_number_get_next */
/**
* Negate ecma-number
*
* @return negated number
*/
ecma_number_t
ecma_number_negate (ecma_number_t num) /**< ecma-number */
{
ecma_number_t negated = -num;
#ifndef JERRY_NDEBUG
bool sign;
uint32_t biased_exp;
uint64_t fraction;
ecma_number_unpack (num, &sign, &biased_exp, &fraction);
sign = !sign;
ecma_number_t negated_ieee754 = ecma_number_pack (sign, biased_exp, fraction);
JERRY_ASSERT (negated == negated_ieee754
|| (ecma_number_is_nan (negated)
&& ecma_number_is_nan (negated_ieee754)));
#endif /* !JERRY_NDEBUG */
return negated;
} /* ecma_number_negate */
/**
* Truncate fractional part of the number
*
* @return integer part of the number
*/
ecma_number_t
ecma_number_trunc (ecma_number_t num) /**< ecma-number */
{
uint64_t fraction;
int32_t exponent;
const int32_t dot_shift = ecma_number_get_fraction_and_exponent (num, &fraction, &exponent);
const bool sign = ecma_number_is_negative (num);
if (exponent < 0)
{
return 0;
}
else if (exponent < dot_shift)
{
fraction &= ~((1ull << (dot_shift - exponent)) - 1);
ecma_number_t tmp = ecma_number_make_normal_positive_from_fraction_and_exponent (fraction,
exponent);
if (sign)
{
return ecma_number_negate (tmp);
}
else
{
return tmp;
}
}
else
{
return num;
}
} /* ecma_number_trunc */
/**
* ECMA-number addition.
*
* @return number - result of addition.
*/
ecma_number_t
ecma_number_add (ecma_number_t left_num, /**< left operand */
ecma_number_t right_num) /**< right operand */
{
return left_num + right_num;
} /* ecma_number_add */
/**
* ECMA-number substraction.
*
* @return number - result of substraction.
*/
ecma_number_t
ecma_number_substract (ecma_number_t left_num, /**< left operand */
ecma_number_t right_num) /**< right operand */
{
return ecma_number_add (left_num, ecma_number_negate (right_num));
} /* ecma_number_substract */
/**
* ECMA-number multiplication.
*
* @return number - result of multiplication.
*/
ecma_number_t
ecma_number_multiply (ecma_number_t left_num, /**< left operand */
ecma_number_t right_num) /**< right operand */
{
return left_num * right_num;
} /* ecma_number_multiply */
/**
* ECMA-number division.
*
* @return number - result of division.
*/
ecma_number_t
ecma_number_divide (ecma_number_t left_num, /**< left operand */
ecma_number_t right_num) /**< right operand */
{
return left_num / right_num;
} /* ecma_number_divide */
/**
* Helper for calculating absolute value
*
* Warning:
* argument should be valid number
*
* @return absolute value of the argument
*/
ecma_number_t
ecma_number_abs (ecma_number_t num) /**< valid number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
if (num < 0)
{
return ecma_number_negate (num);
}
else
{
return num;
}
} /* ecma_number_abs */
/**
* Helper for calculating square root using Newton's method.
*
* @return square root of specified number
*/
ecma_number_t
ecma_number_sqrt (ecma_number_t num) /**< valid finite
positive number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
JERRY_ASSERT (!ecma_number_is_infinity (num));
JERRY_ASSERT (!ecma_number_is_negative (num));
ecma_number_t x = ECMA_NUMBER_ONE;
ecma_number_t diff = ecma_number_make_infinity (false);
while (ecma_number_divide (diff, x) > ecma_number_relative_eps)
{
ecma_number_t x_next = ecma_number_multiply (ECMA_NUMBER_HALF,
(ecma_number_add (x,
ecma_number_divide (num, x))));
diff = ecma_number_substract (x, x_next);
if (diff < 0)
{
diff = ecma_number_negate (diff);
}
x = x_next;
}
return x;
} /* ecma_number_sqrt */
/**
* Helper for calculating natural logarithm.
*
* @return natural logarithm of specified number
*/
ecma_number_t
ecma_number_ln (ecma_number_t num) /**< valid finite
positive number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
JERRY_ASSERT (!ecma_number_is_infinity (num));
JERRY_ASSERT (!ecma_number_is_negative (num));
if (num == ECMA_NUMBER_ONE)
{
return ECMA_NUMBER_ZERO;
}
/* Taylor series of ln (1 + x) around x = 0 is x - x^2/2 + x^3/3 - x^4/4 + ... */
ecma_number_t x = num;
ecma_number_t multiplier = ECMA_NUMBER_ONE;
while (ecma_number_abs (ecma_number_substract (x,
ECMA_NUMBER_ONE)) > ECMA_NUMBER_HALF)
{
x = ecma_number_sqrt (x);
multiplier = ecma_number_multiply (multiplier, ECMA_NUMBER_TWO);
}
x = ecma_number_substract (x, ECMA_NUMBER_ONE);
ecma_number_t sum = ECMA_NUMBER_ZERO;
ecma_number_t next_power = x;
ecma_number_t next_divisor = ECMA_NUMBER_ONE;
ecma_number_t diff;
do
{
ecma_number_t next_sum = ecma_number_add (sum,
ecma_number_divide (next_power,
next_divisor));
next_divisor = ecma_number_add (next_divisor, ECMA_NUMBER_ONE);
next_power = ecma_number_multiply (next_power, x);
next_power = ecma_number_negate (next_power);
diff = ecma_number_abs (ecma_number_substract (sum, next_sum));
sum = next_sum;
}
while (ecma_number_abs (ecma_number_divide (diff,
sum)) > ecma_number_relative_eps);
sum = ecma_number_multiply (sum, multiplier);
return sum;
} /* ecma_number_ln */
/**
* Helper for calculating exponent of a number
*
* @return exponent of specified number
*/
ecma_number_t
ecma_number_exp (ecma_number_t num) /**< valid finite number */
{
JERRY_ASSERT (!ecma_number_is_nan (num));
JERRY_ASSERT (!ecma_number_is_infinity (num));
bool invert = false;
ecma_number_t pow_e;
if (ecma_number_is_negative (num))
{
invert = true;
pow_e = ecma_number_negate (num);
}
else
{
pow_e = num;
}
/* Taylor series of e^x is 1 + x/1! + x^2/2! + x^3/3! + ... + x^n/n! + ... */
ecma_number_t sum = ECMA_NUMBER_ONE;
ecma_number_t next_addendum = ecma_number_divide (pow_e, ECMA_NUMBER_ONE);
ecma_number_t next_factorial_factor = ECMA_NUMBER_ONE;
ecma_number_t diff = ecma_number_make_infinity (false);
while (ecma_number_divide (diff, sum) > ecma_number_relative_eps)
{
ecma_number_t next_sum = ecma_number_add (sum, next_addendum);
next_factorial_factor = ecma_number_add (next_factorial_factor, ECMA_NUMBER_ONE);
next_addendum = ecma_number_multiply (next_addendum, pow_e);
next_addendum = ecma_number_divide (next_addendum, next_factorial_factor);
diff = ecma_number_substract (sum, next_sum);
if (diff < 0)
{
diff = ecma_number_negate (diff);
}
sum = next_sum;
}
if (invert)
{
sum = ecma_number_divide (ECMA_NUMBER_ONE, sum);
}
return sum;
} /* ecma_number_exp */
/**
* @}
* @}
*/
File diff suppressed because it is too large Load Diff
+959
View File
@@ -0,0 +1,959 @@
/* Copyright 2015 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.
*/
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
* @{
*/
#include "ecma-alloc.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "jrt.h"
#include "jrt-bit-fields.h"
JERRY_STATIC_ASSERT (sizeof (ecma_value_t) * JERRY_BITSINBYTE == ECMA_VALUE_SIZE);
/**
* Get type field of ecma-value
*
* @return type field
*/
static ecma_type_t __attr_pure___
ecma_get_value_type_field (const ecma_value_t& value) /**< ecma-value */
{
return (ecma_type_t) jrt_extract_bit_field (value,
ECMA_VALUE_TYPE_POS,
ECMA_VALUE_TYPE_WIDTH);
} /* ecma_get_value_type_field */
/**
* Get value field of ecma-value
*
* @return value field
*/
static uintptr_t __attr_pure___
ecma_get_value_value_field (const ecma_value_t& value) /**< ecma-value */
{
return (uintptr_t) jrt_extract_bit_field (value,
ECMA_VALUE_VALUE_POS,
ECMA_VALUE_VALUE_WIDTH);
} /* ecma_get_value_value_field */
/**
* Set type field of ecma-value
*
* @return ecma-value with updated field
*/
static ecma_value_t __attr_pure___
ecma_set_value_type_field (const ecma_value_t& value, /**< ecma-value to set field in */
ecma_type_t type_field) /**< new field value */
{
return (ecma_value_t) jrt_set_bit_field_value (value,
type_field,
ECMA_VALUE_TYPE_POS,
ECMA_VALUE_TYPE_WIDTH);
} /* ecma_set_value_type_field */
/**
* Set value field of ecma-value
*
* @return ecma-value with updated field
*/
static ecma_value_t __attr_pure___
ecma_set_value_value_field (const ecma_value_t& value, /**< ecma-value to set field in */
uintptr_t value_field) /**< new field value */
{
return (ecma_value_t) jrt_set_bit_field_value (value,
value_field,
ECMA_VALUE_VALUE_POS,
ECMA_VALUE_VALUE_WIDTH);
} /* ecma_set_value_value_field */
/**
* Check if the value is empty.
*
* @return true - if the value contains implementation-defined empty simple value,
* false - otherwise.
*/
bool __attr_pure___ __attr_always_inline___
ecma_is_value_empty (const ecma_value_t& value) /**< ecma-value */
{
return (ecma_get_value_type_field (value) == ECMA_TYPE_SIMPLE
&& ecma_get_value_value_field (value) == ECMA_SIMPLE_VALUE_EMPTY);
} /* ecma_is_value_empty */
/**
* Check if the value is undefined.
*
* @return true - if the value contains ecma-undefined simple value,
* false - otherwise.
*/
bool __attr_pure___ __attr_always_inline___
ecma_is_value_undefined (const ecma_value_t& value) /**< ecma-value */
{
return (ecma_get_value_type_field (value) == ECMA_TYPE_SIMPLE
&& ecma_get_value_value_field (value) == ECMA_SIMPLE_VALUE_UNDEFINED);
} /* ecma_is_value_undefined */
/**
* Check if the value is null.
*
* @return true - if the value contains ecma-null simple value,
* false - otherwise.
*/
bool __attr_pure___ __attr_always_inline___
ecma_is_value_null (const ecma_value_t& value) /**< ecma-value */
{
return (ecma_get_value_type_field (value) == ECMA_TYPE_SIMPLE
&& ecma_get_value_value_field (value) == ECMA_SIMPLE_VALUE_NULL);
} /* ecma_is_value_null */
/**
* Check if the value is boolean.
*
* @return true - if the value contains ecma-true or ecma-false simple values,
* false - otherwise.
*/
bool __attr_pure___ __attr_always_inline___
ecma_is_value_boolean (const ecma_value_t& value) /**< ecma-value */
{
return (ecma_get_value_type_field (value) == ECMA_TYPE_SIMPLE
&& (ecma_get_value_value_field (value) == ECMA_SIMPLE_VALUE_TRUE
|| ecma_get_value_value_field (value) == ECMA_SIMPLE_VALUE_FALSE));
} /* ecma_is_value_boolean */
/**
* Check if the value is true.
*
* Warning:
* value must be boolean
*
* @return true - if the value contains ecma-true simple value,
* false - otherwise.
*/
bool __attr_pure___ __attr_always_inline___
ecma_is_value_true (const ecma_value_t& value) /**< ecma-value */
{
return (ecma_get_value_type_field (value) == ECMA_TYPE_SIMPLE
&& ecma_get_value_value_field (value) == ECMA_SIMPLE_VALUE_TRUE);
} /* ecma_is_value_true */
/**
* Check if the value is ecma-number.
*
* @return true - if the value contains ecma-number value,
* false - otherwise.
*/
bool __attr_pure___ __attr_always_inline___
ecma_is_value_number (const ecma_value_t& value) /**< ecma-value */
{
return (ecma_get_value_type_field (value) == ECMA_TYPE_NUMBER);
} /* ecma_is_value_number */
/**
* Check if the value is ecma-string.
*
* @return true - if the value contains ecma-string value,
* false - otherwise.
*/
bool __attr_pure___ __attr_always_inline___
ecma_is_value_string (const ecma_value_t& value) /**< ecma-value */
{
return (ecma_get_value_type_field (value) == ECMA_TYPE_STRING);
} /* ecma_is_value_string */
/**
* Check if the value is object.
*
* @return true - if the value contains object value,
* false - otherwise.
*/
bool __attr_pure___ __attr_always_inline___
ecma_is_value_object (const ecma_value_t& value) /**< ecma-value */
{
return (ecma_get_value_type_field (value) == ECMA_TYPE_OBJECT);
} /* ecma_is_value_object */
/**
* Debug assertion that specified value's type is one of ECMA-defined
* script-visible types, i.e.: undefined, null, boolean, number, string, object.
*/
void
ecma_check_value_type_is_spec_defined (const ecma_value_t& value) /**< ecma-value */
{
JERRY_ASSERT (ecma_is_value_undefined (value)
|| ecma_is_value_null (value)
|| ecma_is_value_boolean (value)
|| ecma_is_value_number (value)
|| ecma_is_value_string (value)
|| ecma_is_value_object (value));
} /* ecma_check_value_type_is_spec_defined */
/**
* Simple value constructor
*/
ecma_value_t __attr_const___ __attr_always_inline___
ecma_make_simple_value (ecma_simple_value_t value) /**< simple value */
{
ecma_value_t ret_value = 0;
ret_value = ecma_set_value_type_field (ret_value, ECMA_TYPE_SIMPLE);
ret_value = ecma_set_value_value_field (ret_value, value);
return ret_value;
} /* ecma_make_simple_value */
/**
* Number value constructor
*/
ecma_value_t __attr_const___
ecma_make_number_value (ecma_number_t* num_p) /**< number to reference in value */
{
JERRY_ASSERT(num_p != NULL);
uint16_t num_cp;
ECMA_SET_NON_NULL_POINTER (num_cp, num_p);
ecma_value_t ret_value = 0;
ret_value = ecma_set_value_type_field (ret_value, ECMA_TYPE_NUMBER);
ret_value = ecma_set_value_value_field (ret_value, num_cp);
return ret_value;
} /* ecma_make_number_value */
/**
* String value constructor
*/
ecma_value_t __attr_const___
ecma_make_string_value (ecma_string_t* ecma_string_p) /**< string to reference in value */
{
JERRY_ASSERT(ecma_string_p != NULL);
uint16_t string_cp;
ECMA_SET_NON_NULL_POINTER (string_cp, ecma_string_p);
ecma_value_t ret_value = 0;
ret_value = ecma_set_value_type_field (ret_value, ECMA_TYPE_STRING);
ret_value = ecma_set_value_value_field (ret_value, string_cp);
return ret_value;
} /* ecma_make_string_value */
/**
* object value constructor
*/
ecma_value_t __attr_const___
ecma_make_object_value (ecma_object_t* object_p) /**< object to reference in value */
{
JERRY_ASSERT(object_p != NULL);
uint16_t object_cp;
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
ecma_value_t ret_value = 0;
ret_value = ecma_set_value_type_field (ret_value, ECMA_TYPE_OBJECT);
ret_value = ecma_set_value_value_field (ret_value, object_cp);
return ret_value;
} /* ecma_make_object_value */
/**
* Get pointer to ecma-number from ecma-value
*
* @return the pointer
*/
ecma_number_t* __attr_pure___
ecma_get_number_from_value (const ecma_value_t& value) /**< ecma-value */
{
JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_NUMBER);
return ECMA_GET_NON_NULL_POINTER (ecma_number_t,
ecma_get_value_value_field (value));
} /* ecma_get_number_from_value */
/**
* Get pointer to ecma-string from ecma-value
*
* @return the pointer
*/
ecma_string_t* __attr_pure___
ecma_get_string_from_value (const ecma_value_t& value) /**< ecma-value */
{
JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_STRING);
return ECMA_GET_NON_NULL_POINTER (ecma_string_t,
ecma_get_value_value_field (value));
} /* ecma_get_string_from_value */
/**
* Get pointer to ecma-object from ecma-value
*
* @return the pointer
*/
ecma_object_t* __attr_pure___
ecma_get_object_from_value (const ecma_value_t& value) /**< ecma-value */
{
JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_OBJECT);
return ECMA_GET_NON_NULL_POINTER (ecma_object_t,
ecma_get_value_value_field (value));
} /* ecma_get_object_from_value */
/**
* Copy ecma-value.
*
* Note:
* Operation algorithm.
* switch (valuetype)
* case simple:
* simply return the value as it was passed;
* case number:
* copy the number
* and return new ecma-value
* pointing to copy of the number;
* case string:
* increase reference counter of the string
* and return the value as it was passed.
* case object;
* increase reference counter of the object if do_ref_if_object is true
* and return the value as it was passed.
*
* @return See note.
*/
ecma_value_t
ecma_copy_value (const ecma_value_t& value, /**< ecma-value */
bool do_ref_if_object) /**< if the value is object value,
increment reference counter of the object */
{
ecma_value_t value_copy = 0;
switch (ecma_get_value_type_field (value))
{
case ECMA_TYPE_SIMPLE:
{
value_copy = value;
break;
}
case ECMA_TYPE_NUMBER:
{
ecma_number_t *num_p = ecma_get_number_from_value (value);
ecma_number_t *number_copy_p = ecma_alloc_number ();
*number_copy_p = *num_p;
value_copy = ecma_make_number_value (number_copy_p);
break;
}
case ECMA_TYPE_STRING:
{
ecma_string_t *string_p = ecma_get_string_from_value (value);
string_p = ecma_copy_or_ref_ecma_string (string_p);
value_copy = ecma_make_string_value (string_p);
break;
}
case ECMA_TYPE_OBJECT:
{
ecma_object_t *obj_p = ecma_get_object_from_value (value);
if (do_ref_if_object)
{
ecma_ref_object (obj_p);
}
value_copy = value;
break;
}
}
return value_copy;
} /* ecma_copy_value */
/**
* Free the ecma-value
*/
void
ecma_free_value (ecma_value_t& value, /**< value description */
bool do_deref_if_object) /**< if the value is object value,
decrement reference counter of the object */
{
switch (ecma_get_value_type_field (value))
{
case ECMA_TYPE_SIMPLE:
{
/* doesn't hold additional memory */
break;
}
case ECMA_TYPE_NUMBER:
{
ecma_number_t *number_p = ecma_get_number_from_value (value);
ecma_dealloc_number (number_p);
break;
}
case ECMA_TYPE_STRING:
{
ecma_string_t *string_p = ecma_get_string_from_value (value);
ecma_deref_ecma_string (string_p);
break;
}
case ECMA_TYPE_OBJECT:
{
if (do_deref_if_object)
{
ecma_deref_object (ecma_get_object_from_value (value));
}
break;
}
}
} /* ecma_free_value */
/**
* Get type field of completion value
*
* @return type field
*/
static ecma_completion_type_t __attr_const___
ecma_get_completion_value_type_field (ecma_completion_value_t completion_value) /**< completion value */
{
return (ecma_completion_type_t) jrt_extract_bit_field (completion_value,
ECMA_COMPLETION_VALUE_TYPE_POS,
ECMA_COMPLETION_VALUE_TYPE_WIDTH);
} /* ecma_get_completion_value_type_field */
/**
* Get value field of completion value
*
* @return value field
*/
static ecma_value_t __attr_const___
ecma_get_completion_value_value_field (ecma_completion_value_t completion_value) /**< completion value */
{
return (ecma_value_t) jrt_extract_bit_field (completion_value,
ECMA_COMPLETION_VALUE_VALUE_POS,
ECMA_COMPLETION_VALUE_VALUE_WIDTH);
} /* ecma_get_completion_value_value_field */
/**
* Get pointer to label descriptor from completion value
*
* @return pointer to label descriptor
*/
static ecma_label_descriptor_t* __attr_const___
ecma_get_completion_value_label_descriptor (ecma_completion_value_t completion_value) /**< completion value */
{
return ECMA_GET_NON_NULL_POINTER (ecma_label_descriptor_t,
(uintptr_t) jrt_extract_bit_field (completion_value,
ECMA_COMPLETION_VALUE_LABEL_DESC_CP_POS,
ECMA_COMPLETION_VALUE_LABEL_DESC_CP_WIDTH));
} /* ecma_get_completion_value_label_descriptor */
/**
* Set type field of completion value
*
* @return completion value with updated field
*/
static ecma_completion_value_t __attr_const___
ecma_set_completion_value_type_field (ecma_completion_value_t completion_value, /**< completion value
* to set field in */
ecma_completion_type_t type_field) /**< new field value */
{
return (ecma_completion_value_t) jrt_set_bit_field_value (completion_value,
type_field,
ECMA_COMPLETION_VALUE_TYPE_POS,
ECMA_COMPLETION_VALUE_TYPE_WIDTH);
} /* ecma_set_completion_value_type_field */
/**
* Set value field of completion value
*
* @return completion value with updated field
*/
static ecma_completion_value_t __attr_pure___
ecma_set_completion_value_value_field (ecma_completion_value_t completion_value, /**< completion value
* to set field in */
const ecma_value_t& value_field) /**< new field value */
{
return (ecma_completion_value_t) jrt_set_bit_field_value (completion_value,
value_field,
ECMA_COMPLETION_VALUE_VALUE_POS,
ECMA_COMPLETION_VALUE_VALUE_WIDTH);
} /* ecma_set_completion_value_value_field */
/**
* Set label descriptor of completion value
*
* @return completion value with updated field
*/
static ecma_completion_value_t __attr_const___
ecma_set_completion_value_label_descriptor (ecma_completion_value_t completion_value, /**< completion value
* to set field in */
ecma_label_descriptor_t* label_desc_p) /**< pointer to the
* label descriptor */
{
uintptr_t label_desc_cp;
ECMA_SET_NON_NULL_POINTER (label_desc_cp, label_desc_p);
return (ecma_completion_value_t) jrt_set_bit_field_value (completion_value,
label_desc_cp,
ECMA_COMPLETION_VALUE_LABEL_DESC_CP_POS,
ECMA_COMPLETION_VALUE_LABEL_DESC_CP_WIDTH);
} /* ecma_set_completion_value_label_descriptor */
/**
* Normal, throw, return, exit and meta completion values constructor
*
* @return completion value
*/
ecma_completion_value_t __attr_pure___ __attr_always_inline___
ecma_make_completion_value (ecma_completion_type_t type, /**< type */
const ecma_value_t& value) /**< value */
{
const bool is_type_ok = (type == ECMA_COMPLETION_TYPE_NORMAL
|| type == ECMA_COMPLETION_TYPE_THROW
|| type == ECMA_COMPLETION_TYPE_RETURN
|| type == ECMA_COMPLETION_TYPE_EXIT
|| (type == ECMA_COMPLETION_TYPE_META
&& ecma_is_value_empty (value)));
JERRY_ASSERT (is_type_ok);
ecma_completion_value_t completion_value = 0;
completion_value = ecma_set_completion_value_type_field (completion_value,
type);
completion_value = ecma_set_completion_value_value_field (completion_value,
value);
return completion_value;
} /* ecma_make_completion_value */
/**
* Break and continue completion values constructor
*
* @return completion value
*/
ecma_completion_value_t __attr_const___
ecma_make_label_completion_value (ecma_completion_type_t type, /**< type */
uint8_t depth_level, /**< depth level (in try constructions,
with blocks, etc.) */
uint16_t offset) /**< offset to label from end of last block */
{
JERRY_ASSERT (type == ECMA_COMPLETION_TYPE_BREAK
|| type == ECMA_COMPLETION_TYPE_CONTINUE);
ecma_label_descriptor_t *label_desc_p = ecma_alloc_label_descriptor ();
label_desc_p->offset = offset;
label_desc_p->depth = depth_level;
ecma_completion_value_t completion_value = 0;
completion_value = ecma_set_completion_value_type_field (completion_value,
type);
completion_value = ecma_set_completion_value_label_descriptor (completion_value,
label_desc_p);
return completion_value;
} /* ecma_make_label_completion_value */
/**
* Simple normal completion value constructor
*
* @return completion value
*/
ecma_completion_value_t __attr_const___ __attr_always_inline___
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_make_simple_completion_value */
/**
* Normal completion value constructor
*
* @return completion value
*/
ecma_completion_value_t __attr_pure___ __attr_always_inline___
ecma_make_normal_completion_value (const ecma_value_t& value) /**< value */
{
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, value);
} /* ecma_make_normal_completion_value */
/**
* Throw completion value constructor
*
* @return completion value
*/
ecma_completion_value_t __attr_pure___ __attr_always_inline___
ecma_make_throw_completion_value (const ecma_value_t& value) /**< value */
{
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_THROW, value);
} /* ecma_make_throw_completion_value */
/**
* Throw completion value constructor.
*
* @return 'throw' completion value
*/
ecma_completion_value_t __attr_const___
ecma_make_throw_obj_completion_value (ecma_object_t *exception_p) /**< an object */
{
JERRY_ASSERT(exception_p != NULL
&& !ecma_is_lexical_environment (exception_p));
ecma_value_t exception = ecma_make_object_value (exception_p);
return ecma_make_throw_completion_value (exception);
} /* ecma_make_throw_obj_completion_value */
/**
* Empty completion value constructor.
*
* @return (normal, empty, reserved) completion value.
*/
ecma_completion_value_t __attr_const___ __attr_always_inline___
ecma_make_empty_completion_value (void)
{
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY));
} /* ecma_make_empty_completion_value */
/**
* Return completion value constructor
*
* @return completion value
*/
ecma_completion_value_t __attr_pure___ __attr_always_inline___
ecma_make_return_completion_value (const ecma_value_t& value) /**< value */
{
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_RETURN, value);
} /* ecma_make_return_completion_value */
/**
* Exit completion value constructor
*
* @return completion value
*/
ecma_completion_value_t __attr_const___ __attr_always_inline___
ecma_make_exit_completion_value (bool is_successful) /**< does completion value indicate
successfulness completion
of script execution (true) or not (false) */
{
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_EXIT,
ecma_make_simple_value (is_successful ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE));
} /* ecma_make_exit_completion_value */
/**
* Meta completion value constructor
*
* @return completion value
*/
ecma_completion_value_t __attr_const___ __attr_always_inline___
ecma_make_meta_completion_value (void)
{
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_META,
ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY));
} /* ecma_make_meta_completion_value */
/**
* Get ecma-value from specified completion value
*
* @return ecma-value
*/
ecma_value_t __attr_const___ __attr_always_inline___
ecma_get_completion_value_value (ecma_completion_value_t completion_value) /**< completion value */
{
const ecma_completion_type_t type = ecma_get_completion_value_type_field (completion_value);
const bool is_type_ok = (type == ECMA_COMPLETION_TYPE_NORMAL
|| type == ECMA_COMPLETION_TYPE_THROW
|| type == ECMA_COMPLETION_TYPE_RETURN
|| type == ECMA_COMPLETION_TYPE_EXIT);
JERRY_ASSERT (is_type_ok);
return ecma_get_completion_value_value_field (completion_value);
} /* ecma_get_completion_value_value */
/**
* Get pointer to ecma-number from completion value
*
* @return pointer
*/
ecma_number_t* __attr_const___
ecma_get_number_from_completion_value (ecma_completion_value_t completion_value) /**< completion value */
{
return ecma_get_number_from_value (ecma_get_completion_value_value (completion_value));
} /* ecma_get_number_from_completion_value */
/**
* Get pointer to ecma-string from completion value
*
* @return pointer
*/
ecma_string_t* __attr_const___
ecma_get_string_from_completion_value (ecma_completion_value_t completion_value) /**< completion value */
{
return ecma_get_string_from_value (ecma_get_completion_value_value (completion_value));
} /* ecma_get_string_from_completion_value */
/**
* Get pointer to ecma-object from completion value
*
* @return pointer
*/
ecma_object_t* __attr_const___
ecma_get_object_from_completion_value (ecma_completion_value_t completion_value) /**< completion value */
{
return ecma_get_object_from_value (ecma_get_completion_value_value (completion_value));
} /* ecma_get_object_from_completion_value */
/**
* Copy ecma-completion value.
*
* @return (source.type, ecma_copy_value (source.value), source.target).
*/
ecma_completion_value_t
ecma_copy_completion_value (ecma_completion_value_t value) /**< completion value */
{
const ecma_completion_type_t type = ecma_get_completion_value_type_field (value);
const bool is_type_ok = (type == ECMA_COMPLETION_TYPE_NORMAL
|| type == ECMA_COMPLETION_TYPE_THROW
|| type == ECMA_COMPLETION_TYPE_RETURN
|| type == ECMA_COMPLETION_TYPE_EXIT);
JERRY_ASSERT (is_type_ok);
return ecma_make_completion_value (type,
ecma_copy_value (ecma_get_completion_value_value_field (value),
true));
} /* ecma_copy_completion_value */
/**
* Free the completion value.
*/
void
ecma_free_completion_value (ecma_completion_value_t completion_value) /**< completion value */
{
switch (ecma_get_completion_value_type_field (completion_value))
{
case ECMA_COMPLETION_TYPE_NORMAL:
case ECMA_COMPLETION_TYPE_THROW:
case ECMA_COMPLETION_TYPE_RETURN:
{
ecma_value_t v = ecma_get_completion_value_value_field (completion_value);
ecma_free_value (v, true);
break;
}
case ECMA_COMPLETION_TYPE_EXIT:
{
ecma_value_t v = ecma_get_completion_value_value_field (completion_value);
JERRY_ASSERT(ecma_get_value_type_field (v) == ECMA_TYPE_SIMPLE);
break;
}
case ECMA_COMPLETION_TYPE_CONTINUE:
case ECMA_COMPLETION_TYPE_BREAK:
{
ecma_dealloc_label_descriptor (ecma_get_completion_value_label_descriptor (completion_value));
break;
}
case ECMA_COMPLETION_TYPE_META:
{
JERRY_UNREACHABLE ();
}
}
} /* ecma_free_completion_value */
/**
* Check if the completion value is normal value.
*
* @return true - if the completion type is normal,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_normal (ecma_completion_value_t value) /**< completion value */
{
return (ecma_get_completion_value_type_field (value) == ECMA_COMPLETION_TYPE_NORMAL);
} /* ecma_is_completion_value_normal */
/**
* Check if the completion value is throw value.
*
* @return true - if the completion type is throw,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_throw (ecma_completion_value_t value) /**< completion value */
{
return (ecma_get_completion_value_type_field (value) == ECMA_COMPLETION_TYPE_THROW);
} /* ecma_is_completion_value_throw */
/**
* Check if the completion value is return value.
*
* @return true - if the completion type is return,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_return (ecma_completion_value_t value) /**< completion value */
{
return (ecma_get_completion_value_type_field (value) == ECMA_COMPLETION_TYPE_RETURN);
} /* ecma_is_completion_value_return */
/**
* Check if the completion value is exit value.
*
* @return true - if the completion type is exit,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_exit (ecma_completion_value_t value) /**< completion value */
{
if (ecma_get_completion_value_type_field (value) == ECMA_COMPLETION_TYPE_EXIT)
{
JERRY_ASSERT (ecma_is_value_boolean (ecma_get_completion_value_value_field (value)));
return true;
}
else
{
return false;
}
} /* ecma_is_completion_value_exit */
/**
* Check if the completion value is meta value.
*
* @return true - if the completion type is meta,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_meta (ecma_completion_value_t value) /**< completion value */
{
if (ecma_get_completion_value_type_field (value) == ECMA_COMPLETION_TYPE_META)
{
JERRY_ASSERT (ecma_is_value_empty (ecma_get_completion_value_value_field (value)));
return true;
}
else
{
return false;
}
} /* ecma_is_completion_value_meta */
/**
* Check if the completion value is break value.
*
* @return true - if the completion type is break,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_break (ecma_completion_value_t value) /**< completion value */
{
return (ecma_get_completion_value_type_field (value) == ECMA_COMPLETION_TYPE_BREAK);
} /* ecma_is_completion_value_break */
/**
* Check if the completion value is continue value.
*
* @return true - if the completion type is continue,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_continue (ecma_completion_value_t value) /**< completion value */
{
return (ecma_get_completion_value_type_field (value) == ECMA_COMPLETION_TYPE_CONTINUE);
} /* ecma_is_completion_value_continue */
/**
* Check if the completion value is specified normal simple value.
*
* @return true - if the completion type is normal and
* value contains specified simple ecma-value,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_normal_simple_value (ecma_completion_value_t value, /**< completion value */
ecma_simple_value_t simple_value) /**< simple value to check
for equality with */
{
return (value == ecma_make_simple_completion_value (simple_value));
} /* ecma_is_completion_value_normal_simple_value */
/**
* Check if the completion value is normal true.
*
* @return true - if the completion type is normal and
* value contains ecma-true simple value,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_normal_true (ecma_completion_value_t value) /**< completion value */
{
return ecma_is_completion_value_normal_simple_value (value, ECMA_SIMPLE_VALUE_TRUE);
} /* ecma_is_completion_value_normal_true */
/**
* Check if the completion value is normal false.
*
* @return true - if the completion type is normal and
* value contains ecma-false simple value,
* false - otherwise.
*/
bool __attr_const___ __attr_always_inline___
ecma_is_completion_value_normal_false (ecma_completion_value_t value) /**< completion value */
{
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 __attr_const___ __attr_always_inline___
ecma_is_completion_value_empty (ecma_completion_value_t value) /**< completion value */
{
return (ecma_is_completion_value_normal (value)
&& ecma_is_value_empty (ecma_get_completion_value_value_field (value)));
} /* ecma_is_completion_value_empty */
/**
* @}
* @}
*/
@@ -0,0 +1,229 @@
/* Copyright 2014-2015 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.
*/
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
* @{
*/
#include "ecma-alloc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "jrt.h"
/**
* Allocate a collection of ecma-values.
*
* @return pointer to the collection's header
*/
ecma_collection_header_t*
ecma_new_values_collection (const ecma_value_t values_buffer[], /**< ecma-values */
ecma_length_t values_number, /**< number of ecma-values */
bool do_ref_if_object) /**< if the value is object value,
increase reference counter of the object */
{
JERRY_ASSERT (values_buffer != NULL);
JERRY_ASSERT (values_number > 0);
ecma_collection_header_t* header_p = ecma_alloc_collection_header ();
header_p->unit_number = values_number;
uint16_t* next_chunk_cp_p = &header_p->next_chunk_cp;
ecma_value_t* cur_value_buf_iter_p = (ecma_value_t*) header_p->data;
ecma_value_t* cur_value_buf_end_p = cur_value_buf_iter_p + sizeof (header_p->data) / sizeof (ecma_value_t);
for (ecma_length_t value_index = 0;
value_index < values_number;
value_index++)
{
if (unlikely (cur_value_buf_iter_p == cur_value_buf_end_p))
{
ecma_collection_chunk_t *chunk_p = ecma_alloc_collection_chunk ();
ECMA_SET_POINTER (*next_chunk_cp_p, chunk_p);
next_chunk_cp_p = &chunk_p->next_chunk_cp;
cur_value_buf_iter_p = (ecma_value_t*) chunk_p->data;
cur_value_buf_end_p = cur_value_buf_iter_p + sizeof (chunk_p->data) / sizeof (ecma_value_t);
}
JERRY_ASSERT (cur_value_buf_iter_p + 1 <= cur_value_buf_end_p);
*cur_value_buf_iter_p++ = ecma_copy_value (values_buffer[value_index], do_ref_if_object);
}
*next_chunk_cp_p = ECMA_NULL_POINTER;
return header_p;
} /* ecma_new_values_collection */
/**
* Free the collection of ecma-values.
*/
void
ecma_free_values_collection (ecma_collection_header_t* header_p, /**< collection's header */
bool do_deref_if_object) /**< if the value is object value,
decrement reference counter of the object */
{
JERRY_ASSERT (header_p != NULL);
ecma_value_t* cur_value_buf_iter_p = (ecma_value_t*) header_p->data;
ecma_value_t* cur_value_buf_end_p = cur_value_buf_iter_p + sizeof (header_p->data) / sizeof (ecma_value_t);
ecma_length_t string_index = 0;
while (cur_value_buf_iter_p != cur_value_buf_end_p
&& string_index < header_p->unit_number)
{
JERRY_ASSERT (cur_value_buf_iter_p < cur_value_buf_end_p);
ecma_free_value (*cur_value_buf_iter_p, do_deref_if_object);
cur_value_buf_iter_p++;
string_index++;
}
ecma_collection_chunk_t *chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
header_p->next_chunk_cp);
while (chunk_p != NULL)
{
JERRY_ASSERT (string_index < header_p->unit_number);
cur_value_buf_iter_p = (ecma_value_t*) chunk_p->data;
cur_value_buf_end_p = cur_value_buf_iter_p + sizeof (chunk_p->data) / sizeof (ecma_value_t);
while (cur_value_buf_iter_p != cur_value_buf_end_p
&& string_index < header_p->unit_number)
{
JERRY_ASSERT (cur_value_buf_iter_p < cur_value_buf_end_p);
ecma_free_value (*cur_value_buf_iter_p, do_deref_if_object);
cur_value_buf_iter_p++;
string_index++;
}
ecma_collection_chunk_t *next_chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
chunk_p->next_chunk_cp);
ecma_dealloc_collection_chunk (chunk_p);
chunk_p = next_chunk_p;
}
ecma_dealloc_collection_header (header_p);
} /* ecma_free_values_collection */
/**
* Allocate a collection of ecma-strings.
*
* @return pointer to the collection's header
*/
ecma_collection_header_t*
ecma_new_strings_collection (ecma_string_t* string_ptrs_buffer[], /**< pointers to ecma-strings */
ecma_length_t strings_number) /**< number of ecma-strings */
{
JERRY_ASSERT (string_ptrs_buffer != NULL);
JERRY_ASSERT (strings_number > 0);
ecma_collection_header_t *new_collection_p;
MEM_DEFINE_LOCAL_ARRAY (values_buffer, strings_number, ecma_value_t);
for (ecma_length_t string_index = 0;
string_index < strings_number;
string_index++)
{
values_buffer[string_index] = ecma_make_string_value (string_ptrs_buffer[string_index]);
}
new_collection_p = ecma_new_values_collection (values_buffer,
strings_number,
false);
MEM_FINALIZE_LOCAL_ARRAY (values_buffer);
return new_collection_p;
} /* ecma_new_strings_collection */
/**
* Initialize new collection iterator for the collection
*/
void
ecma_collection_iterator_init (ecma_collection_iterator_t *iterator_p, /**< context of iterator */
ecma_collection_header_t *collection_p) /**< header of collection */
{
iterator_p->header_p = collection_p;
iterator_p->next_chunk_cp = collection_p->next_chunk_cp;
iterator_p->current_index = 0;
iterator_p->current_value_p = NULL;
iterator_p->current_chunk_end_p = ((ecma_value_t*) iterator_p->header_p->data
+ sizeof (iterator_p->header_p->data) / sizeof (ecma_value_t));
} /* ecma_collection_iterator_init */
/**
* Move collection iterator to next element if there is any.
*
* @return true - if iterator moved,
* false - otherwise (current element is last element in the collection)
*/
bool
ecma_collection_iterator_next (ecma_collection_iterator_t *iterator_p) /**< context of iterator */
{
if (unlikely (iterator_p->header_p->unit_number == 0))
{
return false;
}
if (iterator_p->current_value_p == NULL)
{
JERRY_ASSERT (iterator_p->current_index == 0);
iterator_p->current_value_p = (ecma_value_t*) iterator_p->header_p->data;
return true;
}
if (iterator_p->current_index + 1 == iterator_p->header_p->unit_number)
{
return false;
}
JERRY_ASSERT (iterator_p->current_index + 1 < iterator_p->header_p->unit_number);
iterator_p->current_index++;
iterator_p->current_value_p++;
if (iterator_p->current_value_p == iterator_p->current_chunk_end_p)
{
ecma_collection_chunk_t *next_chunk_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
iterator_p->next_chunk_cp);
JERRY_ASSERT (next_chunk_p != NULL);
iterator_p->next_chunk_cp = next_chunk_p->next_chunk_cp;
iterator_p->current_value_p = (ecma_value_t*) &next_chunk_p->data;
iterator_p->current_chunk_end_p = iterator_p->current_value_p + sizeof (next_chunk_p->data) / sizeof (ecma_value_t);
}
else
{
JERRY_ASSERT (iterator_p->current_value_p < iterator_p->current_chunk_end_p);
}
return true;
} /* ecma_collection_iterator_next */
/**
* @}
* @}
*/
File diff suppressed because it is too large Load Diff
+311
View File
@@ -0,0 +1,311 @@
/* Copyright 2014-2015 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.
*/
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmahelpers Helpers for operations with ECMA data types
* @{
*/
#ifndef JERRY_ECMA_HELPERS_H
#define JERRY_ECMA_HELPERS_H
#include "ecma-globals.h"
#include "mem-allocator.h"
/**
* Get value of pointer from specified non-null compressed pointer field.
*/
#define ECMA_GET_NON_NULL_POINTER(type, field) \
((type *) mem_decompress_pointer (field))
/**
* Get value of pointer from specified compressed pointer field.
*/
#define ECMA_GET_POINTER(type, field) \
(((unlikely (field == ECMA_NULL_POINTER)) ? NULL : ECMA_GET_NON_NULL_POINTER (type, field)))
/**
* Set value of non-null compressed pointer field so that it will correspond
* to specified non_compressed_pointer.
*/
#define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) \
(field) = (mem_compress_pointer (non_compressed_pointer) & ((1u << ECMA_POINTER_FIELD_WIDTH) - 1))
/**
* Set value of compressed pointer field so that it will correspond
* to specified non_compressed_pointer.
*/
#define ECMA_SET_POINTER(field, non_compressed_pointer) \
do \
{ \
auto __temp_pointer = non_compressed_pointer; \
non_compressed_pointer = __temp_pointer; \
} while (0); \
\
(field) = (unlikely ((non_compressed_pointer) == NULL) ? ECMA_NULL_POINTER \
: (mem_compress_pointer (non_compressed_pointer) \
& ((1u << ECMA_POINTER_FIELD_WIDTH) - 1)))
/* ecma-helpers-value.c */
extern bool ecma_is_value_empty (const ecma_value_t& value);
extern bool ecma_is_value_undefined (const ecma_value_t& value);
extern bool ecma_is_value_null (const ecma_value_t& value);
extern bool ecma_is_value_boolean (const ecma_value_t& value);
extern bool ecma_is_value_true (const ecma_value_t& value);
extern bool ecma_is_value_number (const ecma_value_t& value);
extern bool ecma_is_value_string (const ecma_value_t& value);
extern bool ecma_is_value_object (const ecma_value_t& value);
extern void ecma_check_value_type_is_spec_defined (const ecma_value_t& value);
extern ecma_value_t ecma_make_simple_value (ecma_simple_value_t value);
extern ecma_value_t ecma_make_number_value (ecma_number_t* num_p);
extern ecma_value_t ecma_make_string_value (ecma_string_t* ecma_string_p);
extern ecma_value_t ecma_make_object_value (ecma_object_t* object_p);
extern ecma_number_t* __attr_pure___ ecma_get_number_from_value (const ecma_value_t& value);
extern ecma_string_t* __attr_pure___ ecma_get_string_from_value (const ecma_value_t& value);
extern ecma_object_t* __attr_pure___ ecma_get_object_from_value (const ecma_value_t& value);
extern ecma_value_t ecma_copy_value (const ecma_value_t& value, bool do_ref_if_object);
extern void ecma_free_value (ecma_value_t& value, bool do_deref_if_object);
extern ecma_completion_value_t ecma_make_completion_value (ecma_completion_type_t type,
const ecma_value_t& value);
extern ecma_completion_value_t ecma_make_label_completion_value (ecma_completion_type_t type,
uint8_t depth_level,
uint16_t offset);
extern ecma_completion_value_t ecma_make_simple_completion_value (ecma_simple_value_t simple_value);
extern ecma_completion_value_t ecma_make_normal_completion_value (const ecma_value_t& value);
extern ecma_completion_value_t ecma_make_throw_completion_value (const ecma_value_t& value);
extern ecma_completion_value_t ecma_make_throw_obj_completion_value (ecma_object_t *exception_p);
extern ecma_completion_value_t ecma_make_empty_completion_value (void);
extern ecma_completion_value_t ecma_make_return_completion_value (const ecma_value_t& value);
extern ecma_completion_value_t ecma_make_exit_completion_value (bool is_successful);
extern ecma_completion_value_t ecma_make_meta_completion_value (void);
extern ecma_value_t ecma_get_completion_value_value (ecma_completion_value_t completion_value);
extern ecma_number_t* __attr_const___
ecma_get_number_from_completion_value (ecma_completion_value_t completion_value);
extern ecma_string_t* __attr_const___
ecma_get_string_from_completion_value (ecma_completion_value_t completion_value);
extern ecma_object_t* __attr_const___
ecma_get_object_from_completion_value (ecma_completion_value_t completion_value);
extern ecma_completion_value_t ecma_copy_completion_value (ecma_completion_value_t value);
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_return (ecma_completion_value_t value);
extern bool ecma_is_completion_value_exit (ecma_completion_value_t value);
extern bool ecma_is_completion_value_meta (ecma_completion_value_t value);
extern bool ecma_is_completion_value_break (ecma_completion_value_t value);
extern bool ecma_is_completion_value_continue (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_true (ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_false (ecma_completion_value_t value);
extern bool ecma_is_completion_value_empty (ecma_completion_value_t value);
/* ecma-helpers-string.c */
extern ecma_string_t* ecma_new_ecma_string (const ecma_char_t *string_p);
extern ecma_string_t* ecma_new_ecma_string_from_uint32 (uint32_t uint_number);
extern ecma_string_t* ecma_new_ecma_string_from_number (ecma_number_t number);
extern void ecma_new_ecma_string_on_stack_from_lit_index (ecma_string_t *string_p,
literal_index_t lit_index);
extern ecma_string_t* ecma_new_ecma_string_from_lit_index (literal_index_t lit_index);
extern void ecma_new_ecma_string_on_stack_from_magic_string_id (ecma_string_t *string_p,
ecma_magic_string_id_t id);
extern ecma_string_t* ecma_new_ecma_string_from_magic_string_id (ecma_magic_string_id_t id);
extern ecma_string_t* ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t *string2_p);
extern ecma_string_t* ecma_copy_or_ref_ecma_string (ecma_string_t *string_desc_p);
extern void ecma_deref_ecma_string (ecma_string_t *string_p);
extern void ecma_check_that_ecma_string_need_not_be_freed (const ecma_string_t *string_p);
extern ecma_number_t ecma_string_to_number (const ecma_string_t *str_p);
extern ssize_t ecma_string_to_zt_string (const ecma_string_t *string_desc_p,
ecma_char_t *buffer_p,
ssize_t buffer_size);
extern bool ecma_compare_ecma_strings_equal_hashes (const ecma_string_t *string1_p,
const ecma_string_t *string2_p);
extern bool ecma_compare_ecma_strings (const ecma_string_t *string1_p,
const ecma_string_t *string2_p);
extern bool ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p,
const ecma_string_t *string2_p);
extern int32_t ecma_string_get_length (const ecma_string_t *string_p);
extern ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, uint32_t index);
extern bool ecma_compare_zt_strings (const ecma_char_t *string1_p, const ecma_char_t *string2_p);
extern bool ecma_compare_zt_strings_relational (const ecma_char_t *string1_p, const ecma_char_t *string2_p);
extern ecma_char_t*
ecma_copy_zt_string_to_buffer (const ecma_char_t *string_p,
ecma_char_t *buffer_p,
ssize_t buffer_size);
extern ecma_length_t ecma_zt_string_length (const ecma_char_t *string_p);
extern void ecma_strings_init (void);
extern const ecma_char_t* ecma_get_magic_string_zt (ecma_magic_string_id_t id);
extern ecma_string_t* ecma_get_magic_string (ecma_magic_string_id_t id);
extern bool ecma_is_string_magic (const ecma_string_t *string_p, ecma_magic_string_id_t *out_id_p);
extern bool ecma_is_zt_string_magic (const ecma_char_t *zt_string_p, ecma_magic_string_id_t *out_id_p);
extern ecma_string_hash_t ecma_string_hash (const ecma_string_t *string_p);
extern ecma_string_hash_t ecma_chars_buffer_calc_hash_last_chars (const ecma_char_t *chars, ecma_length_t length);
/* ecma-helpers-number.c */
extern const ecma_number_t ecma_number_relative_eps;
extern ecma_number_t ecma_number_make_nan (void);
extern ecma_number_t ecma_number_make_infinity (bool sign);
extern bool ecma_number_is_nan (ecma_number_t num);
extern bool ecma_number_is_negative (ecma_number_t num);
extern bool ecma_number_is_zero (ecma_number_t num);
extern bool ecma_number_is_infinity (ecma_number_t num);
extern int32_t
ecma_number_get_fraction_and_exponent (ecma_number_t num,
uint64_t *out_fraction_p,
int32_t *out_exponent_p);
extern ecma_number_t
ecma_number_make_normal_positive_from_fraction_and_exponent (uint64_t fraction,
int32_t exponent);
extern ecma_number_t
ecma_number_make_from_sign_mantissa_and_exponent (bool sign,
uint64_t mantissa,
int32_t exponent);
extern ecma_number_t ecma_number_get_prev (ecma_number_t num);
extern ecma_number_t ecma_number_get_next (ecma_number_t num);
extern ecma_number_t ecma_number_negate (ecma_number_t num);
extern ecma_number_t ecma_number_trunc (ecma_number_t num);
extern ecma_number_t ecma_number_add (ecma_number_t left_num, ecma_number_t right_num);
extern ecma_number_t ecma_number_substract (ecma_number_t left_num, ecma_number_t right_num);
extern ecma_number_t ecma_number_multiply (ecma_number_t left_num, ecma_number_t right_num);
extern ecma_number_t ecma_number_divide (ecma_number_t left_num, ecma_number_t right_num);
extern ecma_number_t ecma_number_sqrt (ecma_number_t num);
extern ecma_number_t ecma_number_abs (ecma_number_t num);
extern ecma_number_t ecma_number_ln (ecma_number_t num);
extern ecma_number_t ecma_number_exp (ecma_number_t num);
/* ecma-helpers-values-collection.c */
extern ecma_collection_header_t *ecma_new_values_collection (const ecma_value_t values_buffer[],
ecma_length_t values_number,
bool do_ref_if_object);
extern void ecma_free_values_collection (ecma_collection_header_t* header_p, bool do_deref_if_object);
extern ecma_collection_header_t *ecma_new_strings_collection (ecma_string_t* string_ptrs_buffer[],
ecma_length_t strings_number);
/**
* Context of ecma-values' collection iterator
*/
typedef struct
{
ecma_collection_header_t *header_p; /**< collection header */
uint16_t next_chunk_cp; /**< compressed pointer to next chunk */
ecma_length_t current_index; /**< index of current element */
const ecma_value_t *current_value_p; /**< pointer to current element */
const ecma_value_t *current_chunk_beg_p; /**< pointer to beginning of current chunk's data */
const ecma_value_t *current_chunk_end_p; /**< pointer to place right after the end of current chunk's data */
} ecma_collection_iterator_t;
extern void
ecma_collection_iterator_init (ecma_collection_iterator_t *iterator_p,
ecma_collection_header_t *collection_p);
extern bool
ecma_collection_iterator_next (ecma_collection_iterator_t *iterator_p);
/* ecma-helpers.c */
extern ecma_object_t* ecma_create_object (ecma_object_t *prototype_object_p,
bool is_extensible,
ecma_object_type_t type);
extern ecma_object_t* ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p);
extern ecma_object_t* ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p,
ecma_object_t *binding_obj_p,
bool provide_this);
extern bool __attr_pure___ ecma_is_lexical_environment (const ecma_object_t *object_p);
extern bool __attr_pure___ ecma_get_object_extensible (const ecma_object_t *object_p);
extern void ecma_set_object_extensible (ecma_object_t *object_p, bool is_extensible);
extern ecma_object_type_t __attr_pure___ ecma_get_object_type (const 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* __attr_pure___ ecma_get_object_prototype (const ecma_object_t *object_p);
extern bool __attr_pure___ ecma_get_object_is_builtin (const ecma_object_t *object_p);
extern void ecma_set_object_is_builtin (ecma_object_t *object_p,
bool is_builtin);
extern ecma_lexical_environment_type_t __attr_pure___ ecma_get_lex_env_type (const ecma_object_t *object_p);
extern ecma_object_t* __attr_pure___ ecma_get_lex_env_outer_reference (const ecma_object_t *object_p);
extern ecma_property_t* __attr_pure___ ecma_get_property_list (const ecma_object_t *object_p);
extern ecma_object_t* __attr_pure___ ecma_get_lex_env_binding_object (const ecma_object_t *object_p);
extern bool __attr_pure___ ecma_get_lex_env_provide_this (const ecma_object_t *object_p);
extern ecma_property_t* ecma_create_internal_property (ecma_object_t *object_p,
ecma_internal_property_id_t property_id);
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_data_property (ecma_object_t *obj_p,
ecma_string_t *name_p,
bool is_writable,
bool is_enumerable,
bool is_configurable);
extern ecma_property_t *ecma_create_named_accessor_property (ecma_object_t *obj_p,
ecma_string_t *name_p,
ecma_object_t *get_p,
ecma_object_t *set_p,
bool is_enumerable,
bool is_configurable);
extern ecma_property_t *ecma_find_named_property (ecma_object_t *obj_p,
ecma_string_t *name_p);
extern ecma_property_t *ecma_get_named_property (ecma_object_t *obj_p,
ecma_string_t *name_p);
extern ecma_property_t *ecma_get_named_data_property (ecma_object_t *obj_p,
ecma_string_t *name_p);
extern void ecma_free_property (ecma_object_t *obj_p, ecma_property_t *prop_p);
extern void ecma_delete_property (ecma_object_t *obj_p, ecma_property_t *prop_p);
extern ecma_value_t ecma_get_named_data_property_value (const ecma_property_t *prop_p);
extern void ecma_set_named_data_property_value (ecma_property_t *prop_p, const ecma_value_t& value);
extern void ecma_named_data_property_assign_value (ecma_object_t *obj_p,
ecma_property_t *prop_p,
const ecma_value_t& value);
extern bool ecma_is_property_writable (ecma_property_t* prop_p);
extern void ecma_set_property_writable_attr (ecma_property_t* prop_p, bool is_writable);
extern bool ecma_is_property_enumerable (ecma_property_t* prop_p);
extern void ecma_set_property_enumerable_attr (ecma_property_t* prop_p, bool is_enumerable);
extern bool ecma_is_property_configurable (ecma_property_t* prop_p);
extern void ecma_set_property_configurable_attr (ecma_property_t* prop_p, bool is_configurable);
extern bool ecma_is_property_lcached (ecma_property_t *prop_p);
extern void ecma_set_property_lcached (ecma_property_t *prop_p,
bool is_lcached);
extern ecma_property_descriptor_t ecma_make_empty_property_descriptor (void);
extern void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p);
/* ecma-helpers-conversion.c */
extern ecma_number_t ecma_zt_string_to_number (const ecma_char_t *str_p);
extern ssize_t ecma_uint32_to_string (uint32_t value, ecma_char_t *out_buffer_p, ssize_t buffer_size);
extern uint32_t ecma_number_to_uint32 (ecma_number_t value);
extern int32_t ecma_number_to_int32 (ecma_number_t value);
extern ecma_number_t ecma_int32_to_number (int32_t value);
extern ecma_number_t ecma_uint32_to_number (uint32_t value);
extern ecma_length_t ecma_number_to_zt_string (ecma_number_t num, ecma_char_t *buffer_p, ssize_t buffer_size);
#endif /* !JERRY_ECMA_HELPERS_H */
/**
* @}
* @}
*/
+326
View File
@@ -0,0 +1,326 @@
/* Copyright 2014-2015 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-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-lcache.h"
#include "jrt-libc-includes.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmalcache Property lookup cache
* @{
*/
/**
* Entry of LCache hash table
*/
typedef struct
{
/** Compressed pointer to object (ECMA_NULL_POINTER marks record empty) */
uint16_t object_cp;
/** Compressed pointer to property's name */
uint16_t prop_name_cp;
/** Compressed pointer to a property of the object */
uint16_t prop_cp;
/** Padding structure to 8 bytes size */
uint16_t padding;
} ecma_lcache_hash_entry_t;
JERRY_STATIC_ASSERT (sizeof (ecma_lcache_hash_entry_t) == sizeof (uint64_t));
/**
* LCache hash value length, in bits
*/
#define ECMA_LCACHE_HASH_BITS (sizeof (ecma_string_hash_t) * JERRY_BITSINBYTE)
/**
* Number of rows in LCache's hash table
*/
#define ECMA_LCACHE_HASH_ROWS_COUNT (1ull << ECMA_LCACHE_HASH_BITS)
/**
* Number of entries in a row of LCache's hash table
*/
#define ECMA_LCACHE_HASH_ROW_LENGTH (2)
/**
* LCache's hash table
*/
static ecma_lcache_hash_entry_t ecma_lcache_hash_table[ ECMA_LCACHE_HASH_ROWS_COUNT ][ ECMA_LCACHE_HASH_ROW_LENGTH ];
/**
* Initialize LCache
*/
void
ecma_lcache_init (void)
{
memset (ecma_lcache_hash_table, 0, sizeof (ecma_lcache_hash_table));
} /* ecma_lcache_init */
/**
* Invalidate specified LCache entry
*/
static void
ecma_lcache_invalidate_entry (ecma_lcache_hash_entry_t *entry_p) /**< entry to invalidate */
{
JERRY_ASSERT (entry_p != NULL);
JERRY_ASSERT (entry_p->object_cp != ECMA_NULL_POINTER);
ecma_deref_object (ECMA_GET_NON_NULL_POINTER (ecma_object_t,
entry_p->object_cp));
entry_p->object_cp = ECMA_NULL_POINTER;
ecma_deref_ecma_string (ECMA_GET_NON_NULL_POINTER (ecma_string_t,
entry_p->prop_name_cp));
if (entry_p->prop_cp != ECMA_NULL_POINTER)
{
ecma_set_property_lcached (ECMA_GET_NON_NULL_POINTER (ecma_property_t,
entry_p->prop_cp),
false);
}
} /* ecma_lcache_invalidate_entry */
/**
* Invalidate all entries in LCache
*/
void
ecma_lcache_invalidate_all (void)
{
for (uint32_t row_index = 0; row_index < ECMA_LCACHE_HASH_ROWS_COUNT; row_index++)
{
for (uint32_t entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
{
if (ecma_lcache_hash_table[ row_index ][ entry_index ].object_cp != ECMA_NULL_POINTER)
{
ecma_lcache_invalidate_entry (&ecma_lcache_hash_table[ row_index ][ entry_index ]);
}
}
}
} /* ecma_lcache_invalidate_all */
/**
* Invalidate entries of LCache's row that correspond to given (object, property) pair
*/
static void
ecma_lcache_invalidate_row_for_object_property_pair (uint32_t row_index, /**< index of the row */
unsigned int object_cp, /**< compressed pointer
* to an object */
unsigned property_cp) /**< compressed pointer
* to the object's
* property */
{
for (uint32_t entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
{
if (ecma_lcache_hash_table[ row_index ][ entry_index ].object_cp == object_cp
&& ecma_lcache_hash_table[ row_index ][ entry_index ].prop_cp == property_cp)
{
ecma_lcache_invalidate_entry (&ecma_lcache_hash_table[ row_index ][ entry_index ]);
}
}
} /* ecma_lcache_invalidate_row_for_object_property_pair */
/**
* Insert an entry into LCache
*/
void
ecma_lcache_insert (ecma_object_t *object_p, /**< object */
ecma_string_t *prop_name_p, /**< property's name */
ecma_property_t *prop_p) /**< pointer to associated property or NULL
* (NULL indicates that the object doesn't have property
* with the name specified) */
{
JERRY_ASSERT (object_p != NULL);
JERRY_ASSERT (prop_name_p != NULL);
prop_name_p = ecma_copy_or_ref_ecma_string (prop_name_p);
ecma_string_hash_t hash_key = ecma_string_hash (prop_name_p);
if (prop_p != NULL)
{
if (unlikely (ecma_is_property_lcached (prop_p)))
{
uint16_t prop_cp;
ECMA_SET_NON_NULL_POINTER (prop_cp, prop_p);
int32_t entry_index;
for (entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
{
if (ecma_lcache_hash_table[hash_key][entry_index].object_cp != ECMA_NULL_POINTER
&& ecma_lcache_hash_table[hash_key][entry_index].prop_cp == prop_cp)
{
#ifndef JERRY_NDEBUG
ecma_object_t* obj_in_entry_p;
obj_in_entry_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
ecma_lcache_hash_table[hash_key][entry_index].object_cp);
JERRY_ASSERT (obj_in_entry_p == object_p);
#endif /* !JERRY_NDEBUG */
break;
}
}
JERRY_ASSERT (entry_index != ECMA_LCACHE_HASH_ROW_LENGTH);
ecma_lcache_invalidate_entry (&ecma_lcache_hash_table[hash_key][entry_index]);
}
JERRY_ASSERT (!ecma_is_property_lcached (prop_p));
ecma_set_property_lcached (prop_p, true);
}
int32_t entry_index;
for (entry_index = 0; entry_index < ECMA_LCACHE_HASH_ROW_LENGTH; entry_index++)
{
if (ecma_lcache_hash_table[hash_key][entry_index].object_cp == ECMA_NULL_POINTER)
{
break;
}
}
if (entry_index == ECMA_LCACHE_HASH_ROW_LENGTH)
{
/* No empty entry was found, invalidating the whole row */
for (uint32_t i = 0; i < ECMA_LCACHE_HASH_ROW_LENGTH; i++)
{
ecma_lcache_invalidate_entry (&ecma_lcache_hash_table[hash_key][i]);
}
entry_index = 0;
}
ecma_ref_object (object_p);
ECMA_SET_NON_NULL_POINTER (ecma_lcache_hash_table[ hash_key ][ entry_index ].object_cp, object_p);
ECMA_SET_NON_NULL_POINTER (ecma_lcache_hash_table[ hash_key ][ entry_index ].prop_name_cp, prop_name_p);
ECMA_SET_POINTER (ecma_lcache_hash_table[ hash_key ][ entry_index ].prop_cp, prop_p);
} /* ecma_lcache_insert */
/**
* Lookup property in the LCache
*
* @return true - if (object, property name) pair is registered in LCache,
* false - probably, not registered.
*/
bool __attr_always_inline___
ecma_lcache_lookup (ecma_object_t *object_p, /**< object */
const ecma_string_t *prop_name_p, /**< property's name */
ecma_property_t **prop_p_p) /**< out: if return value is true,
* then here will be pointer to property,
* if the object contains property with specified name,
* or, otherwise - NULL;
* if return value is false,
* then the output parameter is not set */
{
ecma_string_hash_t hash_key = ecma_string_hash (prop_name_p);
unsigned int object_cp;
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
for (uint32_t i = 0; i < ECMA_LCACHE_HASH_ROW_LENGTH; i++)
{
if (ecma_lcache_hash_table[hash_key][i].object_cp == object_cp)
{
ecma_string_t *entry_prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
ecma_lcache_hash_table[hash_key][i].prop_name_cp);
if (ecma_compare_ecma_strings_equal_hashes (prop_name_p, entry_prop_name_p))
{
ecma_property_t *prop_p = ECMA_GET_POINTER (ecma_property_t, ecma_lcache_hash_table[hash_key][i].prop_cp);
JERRY_ASSERT (prop_p == NULL || ecma_is_property_lcached (prop_p));
*prop_p_p = prop_p;
return true;
}
else
{
/* may be equal but it is long to compare it here */
}
}
}
return false;
} /* ecma_lcache_lookup */
/**
* Invalidate LCache entries associated with given object and property name / property
*
* Note:
* Either property name argument or property argument should be NULL,
* and another should be non-NULL.
* In case property name argument is NULL, property's name is taken
* from property's description.
*/
void
ecma_lcache_invalidate (ecma_object_t *object_p, /**< object */
ecma_string_t *prop_name_arg_p, /**< property's name (See also: Note) */
ecma_property_t *prop_p) /**< property (See also: Note) */
{
JERRY_ASSERT (object_p != NULL);
JERRY_ASSERT (prop_p != NULL || prop_name_arg_p != NULL);
ecma_string_t *prop_name_p = NULL;
if (prop_p != NULL)
{
JERRY_ASSERT (prop_p->type == ECMA_PROPERTY_NAMEDDATA
|| prop_p->type == ECMA_PROPERTY_NAMEDACCESSOR);
bool is_cached = ecma_is_property_lcached (prop_p);
if (!is_cached)
{
return;
}
ecma_set_property_lcached (prop_p, false);
if (prop_p->type == ECMA_PROPERTY_NAMEDDATA)
{
prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
prop_p->u.named_data_property.name_p);
}
else
{
prop_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
prop_p->u.named_accessor_property.name_p);
}
}
else
{
prop_name_p = prop_name_arg_p;
}
unsigned int object_cp, prop_cp;
ECMA_SET_NON_NULL_POINTER (object_cp, object_p);
ECMA_SET_POINTER (prop_cp, prop_p);
ecma_string_hash_t hash_key = ecma_string_hash (prop_name_p);
/* Property's name has was computed.
* Given (object, property name) pair should be in the row corresponding to computed hash.
*/
ecma_lcache_invalidate_row_for_object_property_pair (hash_key, object_cp, prop_cp);
} /* ecma_lcache_invalidate */
/**
* @}
* @}
*/
+37
View File
@@ -0,0 +1,37 @@
/* Copyright 2014-2015 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_LCACHE_H
#define ECMA_LCACHE_H
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmalcache Property lookup cache
* @{
*/
extern void ecma_lcache_init (void);
extern void ecma_lcache_invalidate_all (void);
extern void ecma_lcache_insert (ecma_object_t *object_p, ecma_string_t *prop_name_p, ecma_property_t *prop_p);
extern bool ecma_lcache_lookup (ecma_object_t *object_p, const ecma_string_t *prop_name_p, ecma_property_t **prop_p_p);
extern void ecma_lcache_invalidate (ecma_object_t *object_p, ecma_string_t *prop_name_arg_p, ecma_property_t *prop_p);
/**
* @}
* @}
*/
#endif /* ECMA_LCACHE_H */
@@ -0,0 +1,210 @@
/* 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.
*/
/*
* List of ECMA magic strings
*/
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ARGUMENTS, "arguments")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EVAL, "eval")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_PROTOTYPE, "prototype")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CONSTRUCTOR, "constructor")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CALLER, "caller")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CALLEE, "callee")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_UNDEFINED, "undefined")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NULL, "null")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_FALSE, "false")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TRUE, "true")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_BOOLEAN, "boolean")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NUMBER, "number")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_STRING, "string")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_OBJECT, "object")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_FUNCTION, "function")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LENGTH, "length")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NAN, "NaN")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_INFINITY_UL, "Infinity")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_UNDEFINED_UL, "Undefined")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NULL_UL, "Null")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_OBJECT_UL, "Object")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_FUNCTION_UL, "Function")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ARRAY_UL, "Array")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ARGUMENTS_UL, "Arguments")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_STRING_UL, "String")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_BOOLEAN_UL, "Boolean")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NUMBER_UL, "Number")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_DATE_UL, "Date")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_REG_EXP_UL, "RegExp")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ERROR_UL, "Error")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EVAL_ERROR_UL, "EvalError")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_RANGE_ERROR_UL, "RangeError")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_REFERENCE_ERROR_UL, "ReferenceError")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SYNTAX_ERROR_UL, "SyntaxError")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TYPE_ERROR_UL, "TypeError")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_URI_ERROR_UL, "URIError")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MATH_UL, "Math")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_JSON_U, "JSON")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_PARSE_INT, "parseInt")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_PARSE_FLOAT, "parseFloat")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_IS_NAN, "isNaN")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_IS_FINITE, "isFinite")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_DECODE_URI, "decodeURI")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_DECODE_URI_COMPONENT, "decodeURIComponent")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ENCODE_URI, "encodeURI")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ENCODE_URI_COMPONENT, "encodeURIComponent")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_PROTOTYPE_OF_UL, "getPrototypeOf")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, "getOwnPropertyDescriptor")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL, "getOwnPropertyNames")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CREATE, "create")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_DEFINE_PROPERTY_UL, "defineProperty")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_DEFINE_PROPERTIES_UL, "defineProperties")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SEAL, "seal")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_FREEZE, "freeze")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_PREVENT_EXTENSIONS_UL, "preventExtensions")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_IS_SEALED_UL, "isSealed")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_IS_FROZEN_UL, "isFrozen")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_IS_EXTENSIBLE, "isExtensible")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_KEYS, "keys")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_WRITABLE, "writable")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ENUMERABLE, "enumerable")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CONFIGURABLE, "configurable")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_VALUE, "value")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET, "get")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET, "set")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_E_U, "E")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LN10_U, "LN10")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LN2_U, "LN2")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LOG2E_U, "LOG2E")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LOG10E_U, "LOG10E")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_PI_U, "PI")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SQRT1_2_U, "SQRT1_2")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SQRT2_U, "SQRT2")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ABS, "abs")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ACOS, "acos")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ASIN, "asin")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ATAN, "atan")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ATAN2, "atan2")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CEIL, "ceil")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_COS, "cos")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EXP, "exp")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_FLOOR, "floor")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LOG, "log")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MAX, "max")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MIN, "min")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_POW, "pow")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_RANDOM, "random")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ROUND, "round")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SIN, "sin")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SQRT, "sqrt")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TAN, "tan")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_FROM_CHAR_CODE_UL, "fromCharCode")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_IS_ARRAY_UL, "isArray")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_STRING_UL, "toString")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_VALUE_OF_UL, "valueOf")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_LOCALE_STRING_UL, "toLocaleString")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_HAS_OWN_PROPERTY_UL, "hasOwnProperty")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_IS_PROTOTYPE_OF_UL, "isPrototypeOf")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL, "propertyIsEnumerable")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CONCAT, "concat")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_POP, "pop")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_JOIN, "join")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_PUSH, "push")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_REVERSE, "reverse")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SHIFT, "shift")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SLICE, "slice")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SORT, "sort")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SPLICE, "splice")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_UNSHIFT, "unshift")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_INDEX_OF_UL, "indexOf")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LAST_INDEX_OF_UL, "lastIndexOf")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EVERY, "every")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SOME, "some")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_FOR_EACH_UL, "forEach")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MAP, "map")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_FILTER, "filter")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_REDUCE, "reduce")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_REDUCE_RIGHT_UL, "reduceRight")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CHAR_AT_UL, "charAt")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CHAR_CODE_AT_UL, "charCodeAt")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LOCALE_COMPARE_UL, "localeCompare")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MATCH, "match")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_REPLACE, "replace")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SEARCH, "search")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SPLIT, "split")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SUBSTRING, "substring")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_LOWER_CASE_UL, "toLowerCase")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_LOCALE_LOWER_CASE_UL, "toLocaleLowerCase")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_UPPER_CASE_UL, "toUpperCase")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_LOCALE_UPPER_CASE_UL, "toLocaleUpperCase")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TRIM, "trim")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_FIXED_UL, "toFixed")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_EXPONENTIAL_UL, "toExponential")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_PRECISION_UL, "toPrecision")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_DATE_STRING_UL, "toDateString")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_TIME_STRING_UL, "toTimeString")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_LOCALE_DATE_STRING_UL, "toLocaleDateString")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_LOCALE_TIME_STRING_UL, "toLocaleTimeString")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_TIME_UL, "getTime")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_FULL_YEAR_UL, "getFullYear")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_UTC_FULL_YEAR_UL, "getUTCFullYear")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_MONTH_UL, "getMonth")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_UTC_MONTH_UL, "getUTCMonth")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_DATE_UL, "getDate")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_UTC_DATE_UL, "getUTCDate")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_DAY_UL, "getDay")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_UTC_DAY_UL, "getUTCDay")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_HOURS_UL, "getHours")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_UTC_HOURS_UL, "getUTCHours")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_MINUTES_UL, "getMinutes")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_UTC_MINUTES_UL, "getUTCMinutes")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_SECONDS_UL, "getSeconds")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_UTC_SECONDS_UL, "getUTCSeconds")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_MILLISECONDS_UL, "getMilliseconds")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_UTC_MILLISECONDS_UL, "getUTCMilliseconds")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_GET_TIMEZONE_OFFSET_UL, "getTimezoneOffset")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_TIME_UL, "setTime")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_MILLISECONDS_UL, "setMilliseconds")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_UTC_MILLISECONDS_UL, "setUTCMilliseconds")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_SECONDS_UL, "setSeconds")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_UTC_SECONDS_UL, "setUTCSeconds")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_MINUTES_UL, "setMinutes")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_UTC_MINUTES_UL, "setUTCMinutes")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_HOURS_UL, "setHours")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_UTC_HOURS_UL, "setUTCHours")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_DATE_UL, "setDate")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_UTC_DATE_UL, "setUTCDate")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_MONTH_UL, "setMonth")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_UTC_MONTH_UL, "setUTCMonth")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_FULL_YEAR_UL, "setFullYear")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SET_UTC_FULL_YEAR_UL, "setUTCFullYear")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_UTC_STRING_UL, "toUTCString")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_ISO_STRING_UL, "toISOString")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TO_JSON_UL, "toJSON")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MAX_VALUE_U, "MAX_VALUE")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MIN_VALUE_U, "MIN_VALUE")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_POSITIVE_INFINITY_U, "POSITIVE_INFINITY")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NEGATIVE_INFINITY_U, "NEGATIVE_INFINITY")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_COMPACT_PROFILE_ERROR_UL, "CompactProfileError")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_APPLY, "apply")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_CALL, "call")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_BIND, "bind")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_EXEC, "exec")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_TEST, "test")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_NAME, "name")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_MESSAGE, "message")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_LEFT_SQUARE_CHAR, "[")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_RIGHT_SQUARE_CHAR, "]")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_COLON_CHAR, ":")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_SPACE_CHAR, " ")
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING__EMPTY, "")
+283
View File
@@ -0,0 +1,283 @@
/* Copyright 2015 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-helpers.h"
#include "ecma-stack.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmastack ecma-stack
* @{
*/
/**
* Size of a ecma-stack frame's dynamic chunk
*/
#define ECMA_STACK_DYNAMIC_CHUNK_SIZE (mem_heap_recommend_allocation_size (sizeof (ecma_stack_chunk_header_t) + \
sizeof (ecma_value_t)))
/**
* Number of value slots in a ecma-stack frame's dynamic chunk
*/
#define ECMA_STACK_SLOTS_IN_DYNAMIC_CHUNK ((ECMA_STACK_DYNAMIC_CHUNK_SIZE - sizeof (ecma_stack_chunk_header_t)) / \
sizeof (ecma_value_t))
/**
* The top-most ecma-stack frame
*/
ecma_stack_frame_t* ecma_stack_top_frame_p;
/**
* Initialize ecma-stack
*/
void
ecma_stack_init (void)
{
ecma_stack_top_frame_p = NULL;
} /* ecma_stack_init */
/**
* Finalize ecma-stack
*/
void
ecma_stack_finalize ()
{
JERRY_ASSERT (ecma_stack_top_frame_p == NULL);
} /* ecma_stack_finalize */
/**
* Get ecma-stack's top frame
*
* @return pointer to the top frame descriptor
*/
ecma_stack_frame_t*
ecma_stack_get_top_frame (void)
{
return ecma_stack_top_frame_p;
} /* ecma_stack_get_top_frame */
/**
* Add the frame to ecma-stack
*/
void
ecma_stack_add_frame (ecma_stack_frame_t *frame_p, /**< frame to initialize */
ecma_value_t *regs_p, /**< array of register variables' values */
int32_t regs_num) /**< number of register variables */
{
frame_p->prev_frame_p = ecma_stack_top_frame_p;
ecma_stack_top_frame_p = frame_p;
frame_p->top_chunk_p = NULL;
frame_p->dynamically_allocated_value_slots_p = frame_p->inlined_values;
frame_p->current_slot_index = 0;
frame_p->regs_p = regs_p;
frame_p->regs_number = regs_num;
for (int32_t i = 0; i < regs_num; i++)
{
regs_p [i] = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
}
} /* ecma_stack_add_frame */
/**
* Free the ecma-stack frame
*
* Note:
* the frame should be the top-most frame
*/
void
ecma_stack_free_frame (ecma_stack_frame_t *frame_p) /**< frame to initialize */
{
/* the frame should be the top-most frame */
JERRY_ASSERT (ecma_stack_top_frame_p == frame_p);
ecma_stack_top_frame_p = frame_p->prev_frame_p;
while (frame_p->top_chunk_p != NULL)
{
ecma_stack_pop (frame_p);
}
for (int32_t reg_index = 0;
reg_index < frame_p->regs_number;
reg_index++)
{
ecma_free_value (frame_p->regs_p [reg_index], false);
}
} /* ecma_stack_free_frame */
/**
* Get value of specified register variable
*
* @return ecma-value
*/
ecma_value_t
ecma_stack_frame_get_reg_value (ecma_stack_frame_t *frame_p, /**< frame */
int32_t reg_index) /**< index of register variable */
{
JERRY_ASSERT (reg_index >= 0 && reg_index < frame_p->regs_number);
return frame_p->regs_p [reg_index];
} /* ecma_stack_frame_get_reg_value */
/**
* Set value of specified register variable
*/
void
ecma_stack_frame_set_reg_value (ecma_stack_frame_t *frame_p, /**< frame */
int32_t reg_index, /**< index of register variable */
ecma_value_t value) /**< ecma-value */
{
JERRY_ASSERT (reg_index >= 0 && reg_index < frame_p->regs_number);
frame_p->regs_p [reg_index] = value;
} /* ecma_stack_frame_set_reg_value */
/**
* Calculate number of value slots in the top-most chunk of the frame
*
* @return number of value slots
*/
static size_t
ecma_stack_slots_in_top_chunk (ecma_stack_frame_t *frame_p) /**< ecma-stack frame */
{
return ((frame_p->top_chunk_p == NULL) ? ECMA_STACK_FRAME_INLINED_VALUES_NUMBER : ECMA_STACK_SLOTS_IN_DYNAMIC_CHUNK);
} /* ecma_stack_slots_in_top_chunk */
/**
* Longpath for ecma_stack_push_value (for case current chunk may be doesn't have free slots)
*/
static void __attr_noinline___
ecma_stack_push_value_longpath (ecma_stack_frame_t *frame_p) /**< ecma-stack frame */
{
JERRY_ASSERT (frame_p->current_slot_index >= JERRY_MIN (ECMA_STACK_FRAME_INLINED_VALUES_NUMBER,
ECMA_STACK_SLOTS_IN_DYNAMIC_CHUNK));
const size_t slots_in_top_chunk = ecma_stack_slots_in_top_chunk (frame_p);
if (frame_p->current_slot_index == slots_in_top_chunk)
{
ecma_stack_chunk_header_t *chunk_p;
chunk_p = (ecma_stack_chunk_header_t *) mem_heap_alloc_block (ECMA_STACK_DYNAMIC_CHUNK_SIZE,
MEM_HEAP_ALLOC_SHORT_TERM);
ECMA_SET_POINTER (chunk_p->prev_chunk_p, frame_p->top_chunk_p);
frame_p->top_chunk_p = chunk_p;
frame_p->dynamically_allocated_value_slots_p = (ecma_value_t*) (frame_p->top_chunk_p + 1);
frame_p->current_slot_index = 0;
}
} /* ecma_stack_push_value_longpath */
/**
* Push ecma-value to ecma-stack
*/
void
ecma_stack_push_value (ecma_stack_frame_t *frame_p, /**< ecma-stack frame */
ecma_value_t value) /**< ecma-value */
{
frame_p->current_slot_index++;
if (frame_p->current_slot_index >= JERRY_MIN (ECMA_STACK_FRAME_INLINED_VALUES_NUMBER,
ECMA_STACK_SLOTS_IN_DYNAMIC_CHUNK))
{
ecma_stack_push_value_longpath (frame_p);
}
JERRY_ASSERT (frame_p->current_slot_index < ecma_stack_slots_in_top_chunk (frame_p));
frame_p->dynamically_allocated_value_slots_p [frame_p->current_slot_index] = value;
} /* ecma_stack_push_value */
/**
* Get top value from ecma-stack
*/
ecma_value_t __attr_always_inline___
ecma_stack_top_value (ecma_stack_frame_t *frame_p) /**< ecma-stack frame */
{
const size_t slots_in_top_chunk = ecma_stack_slots_in_top_chunk (frame_p);
JERRY_ASSERT (frame_p->current_slot_index < slots_in_top_chunk);
return frame_p->dynamically_allocated_value_slots_p [frame_p->current_slot_index];
} /* ecma_stack_top_value */
/**
* Longpath for ecma_stack_pop (for case a dynamically allocated chunk needs to be deallocated)
*/
static void __attr_noinline___
ecma_stack_pop_longpath (ecma_stack_frame_t *frame_p) /**< ecma-stack frame */
{
JERRY_ASSERT (frame_p->current_slot_index == 0 && frame_p->top_chunk_p != NULL);
ecma_stack_chunk_header_t *chunk_to_free_p = frame_p->top_chunk_p;
frame_p->top_chunk_p = ECMA_GET_POINTER (ecma_stack_chunk_header_t,
frame_p->top_chunk_p->prev_chunk_p);
if (frame_p->top_chunk_p != NULL)
{
frame_p->dynamically_allocated_value_slots_p = (ecma_value_t*) (frame_p->top_chunk_p + 1);
frame_p->current_slot_index = (uint32_t) (ECMA_STACK_SLOTS_IN_DYNAMIC_CHUNK - 1u);
}
else
{
frame_p->dynamically_allocated_value_slots_p = frame_p->inlined_values;
frame_p->current_slot_index = (uint32_t) (ECMA_STACK_FRAME_INLINED_VALUES_NUMBER - 1u);
}
mem_heap_free_block (chunk_to_free_p);
} /* ecma_stack_pop_longpath */
/**
* Pop top value from ecma-stack and free it
*/
void
ecma_stack_pop (ecma_stack_frame_t *frame_p) /**< ecma-stack frame */
{
JERRY_ASSERT (frame_p->current_slot_index < ecma_stack_slots_in_top_chunk (frame_p));
ecma_value_t value = ecma_stack_top_value (frame_p);
if (unlikely (frame_p->current_slot_index == 0
&& frame_p->top_chunk_p != NULL))
{
ecma_stack_pop_longpath (frame_p);
}
else
{
frame_p->current_slot_index--;
}
ecma_free_value (value, true);
} /* ecma_stack_pop */
/**
* Pop multiple top values from ecma-stack and free them
*/
void
ecma_stack_pop_multiple (ecma_stack_frame_t *frame_p, /**< ecma-stack frame */
uint32_t number) /**< number of elements to pop */
{
for (uint32_t i = 0; i < number; i++)
{
ecma_stack_pop (frame_p);
}
} /* ecma_stack_pop_multiple */
/**
* @}
* @}
*/
+80
View File
@@ -0,0 +1,80 @@
/* Copyright 2015 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_STACK_H
#define ECMA_STACK_H
#include "config.h"
#include "ecma-globals.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmastack ECMA stack
* @{
*/
/**
* Number of ecma-values inlined into stack frame
*/
#define ECMA_STACK_FRAME_INLINED_VALUES_NUMBER CONFIG_ECMA_STACK_FRAME_INLINED_VALUES_NUMBER
/**
* Header of a ECMA stack frame's chunk
*/
typedef struct
{
uint16_t prev_chunk_p; /**< previous chunk of same frame */
} ecma_stack_chunk_header_t;
/**
* ECMA stack frame
*/
typedef struct ecma_stack_frame_t
{
struct ecma_stack_frame_t *prev_frame_p; /**< previous frame */
ecma_stack_chunk_header_t *top_chunk_p; /**< the top-most chunk of the frame */
ecma_value_t *dynamically_allocated_value_slots_p; /**< pointer to dynamically allocated value slots
* in the top-most chunk */
uint32_t current_slot_index; /**< index of first free slot in the top chunk */
ecma_value_t inlined_values [ECMA_STACK_FRAME_INLINED_VALUES_NUMBER]; /**< place for values inlined in stack frame
* (instead of being dynamically allocated
* on the heap) */
ecma_value_t *regs_p; /**< register variables */
int32_t regs_number; /**< number of register variables */
} ecma_stack_frame_t;
extern void ecma_stack_init (void);
extern void ecma_stack_finalize (void);
extern ecma_stack_frame_t*
ecma_stack_get_top_frame (void);
extern void
ecma_stack_add_frame (ecma_stack_frame_t *frame_p,
ecma_value_t *regs_p,
int32_t regs_num);
extern void ecma_stack_free_frame (ecma_stack_frame_t *frame_p);
extern ecma_value_t ecma_stack_frame_get_reg_value (ecma_stack_frame_t *frame_p, int32_t reg_index);
extern void ecma_stack_frame_set_reg_value (ecma_stack_frame_t *frame_p, int32_t reg_index, ecma_value_t value);
extern void ecma_stack_push_value (ecma_stack_frame_t *frame_p, ecma_value_t value);
extern ecma_value_t ecma_stack_top_value (ecma_stack_frame_t *frame_p);
extern void ecma_stack_pop (ecma_stack_frame_t *frame_p);
extern void ecma_stack_pop_multiple (ecma_stack_frame_t *frame_p, uint32_t number);
/**
* @}
* @}
*/
#endif /* !ECMA_STACK_H */
@@ -0,0 +1,68 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID array_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup arrayprototype ECMA Array.prototype object built-in
* @{
*/
/**
* The Array.prototype object's 'toString' routine
*
* See also:
* ECMA-262 v5, 15.4.4.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_array_prototype_object_to_string (const ecma_value_t& this_arg) /**< this argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
} /* ecma_builtin_array_prototype_object_to_string */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN */
@@ -0,0 +1,70 @@
/* Copyright 2014-2015 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.
*/
/*
* Array.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.4.4.1
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
/* Number properties:
* (property name, object pointer getter) */
// 15.4.4
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
0,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_array_prototype_object_to_string, 0, 0)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,112 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-array-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-array.inc.h"
#define BUILTIN_UNDERSCORED_ID array
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup array ECMA Array object built-in
* @{
*/
/**
* The Array object's 'isArray' routine
*
* See also:
* ECMA-262 v5, 15.4.3.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_array_object_is_array (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg) /**< first argument */
{
ecma_simple_value_t is_array = ECMA_SIMPLE_VALUE_FALSE;
if (ecma_is_value_object (arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (arg);
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_CLASS);
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_ARRAY_UL)
{
is_array = ECMA_SIMPLE_VALUE_TRUE;
}
}
return ecma_make_simple_completion_value (is_array);
} /* ecma_builtin_array_object_is_array */
/**
* Handle calling [[Call]] of built-in Array object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_array_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_builtin_array_dispatch_construct (arguments_list_p, arguments_list_len);
} /* ecma_builtin_array_dispatch_call */
/**
* Handle calling [[Construct]] of built-in Array object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_array_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_op_create_array_object (arguments_list_p, arguments_list_len, true);
} /* ecma_builtin_array_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN */
@@ -0,0 +1,60 @@
/* Copyright 2014-2015 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.
*/
/*
* Array description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_ARRAY)
/* Object properties:
* (property name, object pointer getter) */
// 15.4.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,133 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-boolean-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID boolean_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup booleanprototype ECMA Boolean.prototype object built-in
* @{
*/
/**
* The Boolean.prototype object's 'toString' routine
*
* See also:
* ECMA-262 v5, 15.6.4.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_boolean_prototype_object_to_string (const ecma_value_t& this_arg) /**< this argument */
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (value_of_ret,
ecma_builtin_boolean_prototype_object_value_of (this_arg),
ret_value);
ecma_string_t *ret_str_p;
if (ecma_is_value_true (value_of_ret))
{
ret_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_TRUE);
}
else
{
JERRY_ASSERT (ecma_is_value_boolean (value_of_ret));
ret_str_p = ecma_get_magic_string (ECMA_MAGIC_STRING_FALSE);
}
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
ECMA_FINALIZE (value_of_ret);
return ret_value;
} /* ecma_builtin_boolean_prototype_object_to_string */
/**
* The Boolean.prototype object's 'valueOf' routine
*
* See also:
* ECMA-262 v5, 15.6.4.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_boolean_prototype_object_value_of (const ecma_value_t& this_arg) /**< this argument */
{
if (ecma_is_value_boolean (this_arg))
{
return ecma_make_normal_completion_value (this_arg);
}
else if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_BOOLEAN_UL)
{
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE);
JERRY_ASSERT (prim_value_prop_p->u.internal_property.value < ECMA_SIMPLE_VALUE__COUNT);
ecma_simple_value_t prim_simple_value = (ecma_simple_value_t) prim_value_prop_p->u.internal_property.value;
ecma_value_t ret_boolean_value = ecma_make_simple_value (prim_simple_value);
JERRY_ASSERT (ecma_is_value_boolean (ret_boolean_value));
return ecma_make_normal_completion_value (ret_boolean_value);
}
}
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
} /* ecma_builtin_boolean_prototype_object_value_of */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
@@ -0,0 +1,56 @@
/* Copyright 2014-2015 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.
*/
/*
* Boolean.prototype description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_id)
#endif /* !OBJECT_ID */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.6.4.1
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_boolean_prototype_object_to_string, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_boolean_prototype_object_value_of, 0, 0)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,99 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-boolean-object.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-boolean.inc.h"
#define BUILTIN_UNDERSCORED_ID boolean
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup boolean ECMA Boolean object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in Boolean object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_boolean_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
ecma_value_t arg_value;
if (arguments_list_len == 0)
{
arg_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
else
{
arg_value = arguments_list_p [0];
}
return ecma_op_to_boolean (arg_value);
} /* ecma_builtin_boolean_dispatch_call */
/**
* Handle calling [[Construct]] of built-in Boolean object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_boolean_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len == 0)
{
return ecma_op_create_boolean_object (ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE));
}
else
{
return ecma_op_create_boolean_object (arguments_list_p[0]);
}
} /* ecma_builtin_boolean_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* Boolean description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_BOOLEAN)
/* Object properties:
* (property name, object pointer getter) */
// 15.6.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Number properties:
* (property name, object pointer getter) */
// 15.6.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,80 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifdef CONFIG_ECMA_COMPACT_PROFILE
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-compact-profile-error.inc.h"
#define BUILTIN_UNDERSCORED_ID compact_profile_error
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup compact_profile_error ECMA CompactProfileError object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in CompactProfileError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_compact_profile_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_make_throw_obj_completion_value (ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR));
} /* ecma_builtin_compact_profile_error_dispatch_call */
/**
* Handle calling [[Construct]] of built-in CompactProfileError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_compact_profile_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_make_throw_obj_completion_value (ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR));
} /* ecma_builtin_compact_profile_error_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
@@ -0,0 +1,46 @@
/* 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.
*/
/*
* CompactProfileError description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
0,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,206 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-error-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID error_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup errorprototype ECMA Error.prototype object built-in
* @{
*/
/**
* The Error.prototype object's 'toString' routine
*
* See also:
* ECMA-262 v5, 15.11.4.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_error_prototype_object_to_string (const ecma_value_t& this_arg) /**< this argument */
{
ecma_completion_value_t ret_value;
// 2.
if (!ecma_is_value_object (this_arg))
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_string_t *name_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_NAME);
ECMA_TRY_CATCH (name_get_ret_value,
ecma_op_object_get (obj_p, name_magic_string_p),
ret_value);
ecma_completion_value_t name_to_str_completion;
if (ecma_is_value_undefined (name_get_ret_value))
{
ecma_string_t *error_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ERROR_UL);
name_to_str_completion = ecma_make_normal_completion_value (ecma_make_string_value (error_magic_string_p));
}
else
{
name_to_str_completion = ecma_op_to_string (name_get_ret_value);
}
if (unlikely (!ecma_is_completion_value_normal (name_to_str_completion)))
{
ret_value = ecma_copy_completion_value (name_to_str_completion);
}
else
{
ecma_string_t *message_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_MESSAGE);
ECMA_TRY_CATCH (msg_get_ret_value,
ecma_op_object_get (obj_p, message_magic_string_p),
ret_value);
ecma_completion_value_t msg_to_str_completion;
if (ecma_is_value_undefined (msg_get_ret_value))
{
ecma_string_t *empty_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING__EMPTY);
msg_to_str_completion = ecma_make_normal_completion_value (ecma_make_string_value (empty_magic_string_p));
}
else
{
msg_to_str_completion = ecma_op_to_string (msg_get_ret_value);
}
if (unlikely (!ecma_is_completion_value_normal (msg_to_str_completion)))
{
ret_value = ecma_copy_completion_value (msg_to_str_completion);
}
else
{
ecma_string_t *name_string_p = ecma_get_string_from_completion_value (name_to_str_completion);
ecma_string_t *msg_string_p = ecma_get_string_from_completion_value (msg_to_str_completion);
ecma_string_t *ret_str_p;
if (ecma_string_get_length (name_string_p) == 0)
{
ret_str_p = ecma_copy_or_ref_ecma_string (msg_string_p);
}
else if (ecma_string_get_length (msg_string_p) == 0)
{
ret_str_p = ecma_copy_or_ref_ecma_string (name_string_p);
}
else
{
const ecma_char_t *colon_zt_magic_string_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_COLON_CHAR);
const ecma_char_t *space_zt_magic_string_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_SPACE_CHAR);
const int32_t len = (ecma_string_get_length (name_string_p) +
ecma_string_get_length (msg_string_p) +
ecma_zt_string_length (colon_zt_magic_string_p) +
ecma_zt_string_length (space_zt_magic_string_p));
const ssize_t buffer_size = (len + 1) * (ssize_t) sizeof (ecma_char_t);
ssize_t buffer_size_left = buffer_size;
MEM_DEFINE_LOCAL_ARRAY (ret_str_buffer, buffer_size, ecma_char_t);
ecma_char_t *ret_str_buffer_p = ret_str_buffer;
ssize_t bytes = ecma_string_to_zt_string (name_string_p, ret_str_buffer_p, buffer_size_left);
JERRY_ASSERT (bytes >= 1 && buffer_size_left - bytes >= 0);
buffer_size_left -= bytes - 1 /* null character */;
ret_str_buffer_p = (ecma_char_t*) ((uint8_t*) ret_str_buffer + (buffer_size - buffer_size_left));
ret_str_buffer_p = ecma_copy_zt_string_to_buffer (colon_zt_magic_string_p,
ret_str_buffer_p,
buffer_size_left);
buffer_size_left = buffer_size - (ret_str_buffer_p - ret_str_buffer) * (ssize_t) sizeof (ecma_char_t);
JERRY_ASSERT (buffer_size_left >= 0);
ret_str_buffer_p = ecma_copy_zt_string_to_buffer (space_zt_magic_string_p,
ret_str_buffer_p,
buffer_size_left);
buffer_size_left = buffer_size - (ret_str_buffer_p - ret_str_buffer) * (ssize_t) sizeof (ecma_char_t);
JERRY_ASSERT (buffer_size_left >= 0);
bytes = ecma_string_to_zt_string (msg_string_p, ret_str_buffer_p, buffer_size_left);
JERRY_ASSERT (bytes >= 1 && buffer_size_left - bytes >= 0);
buffer_size_left -= bytes - 1 /* null character */;
ret_str_buffer_p = (ecma_char_t*) ((uint8_t*) ret_str_buffer + (buffer_size - buffer_size_left));
JERRY_ASSERT (buffer_size_left >= (ssize_t) sizeof (ecma_char_t));
*ret_str_buffer_p = ECMA_CHAR_NULL;
ret_str_p = ecma_new_ecma_string (ret_str_buffer);
MEM_FINALIZE_LOCAL_ARRAY (ret_str_buffer);
}
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
}
ecma_free_completion_value (msg_to_str_completion);
ECMA_FINALIZE (msg_get_ret_value);
ecma_deref_ecma_string (message_magic_string_p);
}
ecma_free_completion_value (name_to_str_completion);
ECMA_FINALIZE (name_get_ret_value);
ecma_deref_ecma_string (name_magic_string_p);
}
return ret_value;
} /* ecma_builtin_error_prototype_object_to_string */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,73 @@
/* Copyright 2014-2015 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.
*/
/*
* Error.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_ERROR_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.4.1
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.4.2
STRING_VALUE (ECMA_MAGIC_STRING_NAME,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.4.3
STRING_VALUE (ECMA_MAGIC_STRING_MESSAGE,
ECMA_MAGIC_STRING__EMPTY,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_error_prototype_object_to_string, 0, 0)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,101 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-error.inc.h"
#define BUILTIN_UNDERSCORED_ID error
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup error ECMA Error object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in Error object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len != 0
&& !ecma_is_value_undefined (arguments_list_p [0]))
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (msg_str_value,
ecma_op_to_string (arguments_list_p[0]),
ret_value);
ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value);
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_COMMON,
message_string_p);
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
ECMA_FINALIZE (msg_str_value);
return ret_value;
}
else
{
ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_COMMON);
return ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
}
} /* ecma_builtin_error_dispatch_call */
/**
* Handle calling [[Construct]] of built-in Error object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
return ecma_builtin_error_dispatch_call (arguments_list_p, arguments_list_len);
} /* ecma_builtin_error_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* Error built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_ERROR)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.11.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.7.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_ERROR_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,37 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-evalerror-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID eval_error_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* EvalError.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.7.8
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_EVAL_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.9
STRING_VALUE (ECMA_MAGIC_STRING_NAME,
ECMA_MAGIC_STRING_EVAL_ERROR_UL,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.10
STRING_VALUE (ECMA_MAGIC_STRING_MESSAGE,
ECMA_MAGIC_STRING__EMPTY,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,101 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-evalerror.inc.h"
#define BUILTIN_UNDERSCORED_ID eval_error
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup evalerror ECMA EvalError object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in EvalError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_eval_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len != 0
&& !ecma_is_value_undefined (arguments_list_p [0]))
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (msg_str_value,
ecma_op_to_string (arguments_list_p[0]),
ret_value);
ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value);
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_EVAL,
message_string_p);
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
ECMA_FINALIZE (msg_str_value);
return ret_value;
}
else
{
ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_EVAL);
return ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
}
} /* ecma_builtin_eval_error_dispatch_call */
/**
* Handle calling [[Construct]] of built-in EvalError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_eval_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
return ecma_builtin_eval_error_dispatch_call (arguments_list_p, arguments_list_len);
} /* ecma_builtin_eval_error_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* EvalError built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_EVAL_ERROR)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.11.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,143 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID function_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup functionprototype ECMA Function.prototype object built-in
* @{
*/
/**
* The Function.prototype object's 'toString' routine
*
* See also:
* ECMA-262 v5, 15.3.4.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_function_prototype_object_to_string (const ecma_value_t& this_arg) /**< this argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
} /* ecma_builtin_function_prototype_object_to_string */
/**
* The Function.prototype object's 'apply' routine
*
* See also:
* ECMA-262 v5, 15.3.4.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_function_prototype_object_apply (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg1, /**< first argument */
const ecma_value_t& arg2) /**< second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_function_prototype_object_apply */
/**
* The Function.prototype object's 'call' routine
*
* See also:
* ECMA-262 v5, 15.3.4.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_function_prototype_object_call (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t* arguments_list_p, /**< list of arguments */
ecma_length_t arguments_number) /**< number of arguments */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arguments_list_p, arguments_number);
} /* ecma_builtin_function_prototype_object_call */
/**
* The Function.prototype object's 'bind' routine
*
* See also:
* ECMA-262 v5, 15.3.4.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_function_prototype_object_bind (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t* arguments_list_p, /**< list of arguments */
ecma_length_t arguments_number) /**< number of arguments */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arguments_list_p, arguments_number);
} /* ecma_builtin_function_prototype_object_bind */
/**
* Handle calling [[Call]] of built-in Function.prototype object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_function_prototype_dispatch_call (const ecma_value_t* arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
} /* ecma_builtin_function_prototype_dispatch_call */
/**
* Handle calling [[Construct]] of built-in Function.prototype object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_function_prototype_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
} /* ecma_builtin_function_prototype_dispatch_construct */
/**
* @}
* @}
* @}
*/
@@ -0,0 +1,72 @@
/* Copyright 2014-2015 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.
*/
/*
* Function.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.3.4.1
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
/* Number properties:
* (property name, object pointer getter) */
// 15.3.4
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
0,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_function_prototype_object_to_string, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_APPLY, ecma_builtin_function_prototype_object_apply, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_CALL, ecma_builtin_function_prototype_object_call, NON_FIXED, 1)
ROUTINE (ECMA_MAGIC_STRING_BIND, ecma_builtin_function_prototype_object_bind, NON_FIXED, 1)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,77 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-function-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-function.inc.h"
#define BUILTIN_UNDERSCORED_ID function
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup function ECMA Function object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in Function object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_function_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_builtin_function_dispatch_construct (arguments_list_p, arguments_list_len);
} /* ecma_builtin_function_dispatch_call */
/**
* Handle calling [[Construct]] of built-in Function object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
ECMA_BUILTIN_CP_UNIMPLEMENTED (arguments_list_p, arguments_list_len);
} /* ecma_builtin_function_dispatch_construct */
/**
* @}
* @}
* @}
*/
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* Function built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_FUNCTION)
/* Object properties:
* (property name, object pointer getter) */
// 15.3.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Number properties:
* (property name, object pointer getter) */
// 15.3.3.2
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,215 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-global.inc.h"
#define BUILTIN_UNDERSCORED_ID global
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup global ECMA Global object built-in
* @{
*/
/**
* The Global object's 'eval' routine
*
* See also:
* ECMA-262 v5, 15.1.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_global_object_eval (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& x) /**< routine's first argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, x);
} /* ecma_builtin_global_object_eval */
/**
* The Global object's 'parseInt' routine
*
* See also:
* ECMA-262 v5, 15.1.2.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_global_object_parse_int (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& string, /**< routine's first argument */
const ecma_value_t& radix) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, string, radix);
} /* ecma_builtin_global_object_parse_int */
/**
* The Global object's 'parseFloat' routine
*
* See also:
* ECMA-262 v5, 15.1.2.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_global_object_parse_float (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& string) /**< routine's first argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, string);
} /* ecma_builtin_global_object_parse_float */
/**
* The Global object's 'isNaN' routine
*
* See also:
* ECMA-262 v5, 15.1.2.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_global_object_is_nan (const ecma_value_t& this_arg __attr_unused___, /**< this argument */
const ecma_value_t& arg) /**< routine's first argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
bool is_nan = ecma_number_is_nan (arg_num);
ret_value = ecma_make_simple_completion_value (is_nan ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE);
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_global_object_is_nan */
/**
* The Global object's 'isFinite' routine
*
* See also:
* ECMA-262 v5, 15.1.2.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_global_object_is_finite (const ecma_value_t& this_arg __attr_unused___, /**< this argument */
const ecma_value_t& arg) /**< routine's first argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
bool is_finite = !(ecma_number_is_nan (arg_num)
|| ecma_number_is_infinity (arg_num));
ret_value = ecma_make_simple_completion_value (is_finite ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE);
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_global_object_is_finite */
/**
* The Global object's 'decodeURI' routine
*
* See also:
* ECMA-262 v5, 15.1.3.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_global_object_decode_uri (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& encoded_uri) /**< routine's first argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, encoded_uri);
} /* ecma_builtin_global_object_decode_uri */
/**
* The Global object's 'decodeURIComponent' routine
*
* See also:
* ECMA-262 v5, 15.1.3.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_global_object_decode_uri_component (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& encoded_uri_component) /**< routine's
* first argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, encoded_uri_component);
} /* ecma_builtin_global_object_decode_uri_component */
/**
* The Global object's 'encodeURI' routine
*
* See also:
* ECMA-262 v5, 15.1.3.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_global_object_encode_uri (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& uri) /**< routine's first argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, uri);
} /* ecma_builtin_global_object_encode_uri */
/**
* The Global object's 'encodeURIComponent' routine
*
* See also:
* ECMA-262 v5, 15.1.3.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_global_object_encode_uri_component (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& uri_component) /**< routine's first argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, uri_component);
} /* ecma_builtin_global_object_encode_uri_component */
/**
* @}
* @}
* @}
*/
@@ -0,0 +1,234 @@
/* Copyright 2014-2015 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.
*/
/*
* Global built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef SIMPLE_VALUE
# define SIMPLE_VALUE(name, simple_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !SIMPLE_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef CP_UNIMPLEMENTED_VALUE
# define CP_UNIMPLEMENTED_VALUE(name, value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !CP_UNIMPLEMENTED_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_GLOBAL)
/* Simple value properties:
* (property name, simple value, writable, enumerable, configurable) */
// ECMA-262 v5, 15.1.1.3
SIMPLE_VALUE (ECMA_MAGIC_STRING_UNDEFINED,
ECMA_SIMPLE_VALUE_UNDEFINED,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// ECMA-262 v5, 15.1.1.1
NUMBER_VALUE (ECMA_MAGIC_STRING_NAN,
ecma_number_make_nan (),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// ECMA-262 v5, 15.1.1.2
NUMBER_VALUE (ECMA_MAGIC_STRING_INFINITY_UL,
ecma_number_make_infinity (false),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// ECMA-262 v5, 15.1.4.1
OBJECT_VALUE (ECMA_MAGIC_STRING_OBJECT_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// ECMA-262 v5, 15.1.4.2
OBJECT_VALUE (ECMA_MAGIC_STRING_FUNCTION_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// ECMA-262 v5, 15.1.4.3
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
OBJECT_VALUE (ECMA_MAGIC_STRING_ARRAY_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN*/
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
// ECMA-262 v5, 15.1.4.4
OBJECT_VALUE (ECMA_MAGIC_STRING_STRING_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_STRING),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
// ECMA-262 v5, 15.1.4.5
OBJECT_VALUE (ECMA_MAGIC_STRING_BOOLEAN_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN
// ECMA-262 v5, 15.1.4.6
OBJECT_VALUE (ECMA_MAGIC_STRING_NUMBER_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN */
// ECMA-262 v5, 15.1.4.7
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_DATE_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_DATE),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// ECMA-262 v5, 15.1.4.8
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_REG_EXP_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
// ECMA-262 v5, 15.1.4.9
OBJECT_VALUE (ECMA_MAGIC_STRING_ERROR_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// ECMA-262 v5, 15.1.4.10
OBJECT_VALUE (ECMA_MAGIC_STRING_EVAL_ERROR_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_EVAL_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// ECMA-262 v5, 15.1.4.11
OBJECT_VALUE (ECMA_MAGIC_STRING_RANGE_ERROR_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_RANGE_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// ECMA-262 v5, 15.1.4.12
OBJECT_VALUE (ECMA_MAGIC_STRING_REFERENCE_ERROR_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_REFERENCE_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// ECMA-262 v5, 15.1.4.13
OBJECT_VALUE (ECMA_MAGIC_STRING_SYNTAX_ERROR_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_SYNTAX_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// ECMA-262 v5, 15.1.4.14
OBJECT_VALUE (ECMA_MAGIC_STRING_TYPE_ERROR_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// ECMA-262 v5, 15.1.4.15
OBJECT_VALUE (ECMA_MAGIC_STRING_URI_ERROR_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_URI_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_MATH_BUILTIN
// ECMA-262 v5, 15.1.5.1
OBJECT_VALUE (ECMA_MAGIC_STRING_MATH_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_MATH),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_MATH_BUILTIN */
// ECMA-262 v5, 15.1.5.2
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_JSON_U,
ecma_builtin_get (ECMA_BUILTIN_ID_JSON),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#ifdef CONFIG_ECMA_COMPACT_PROFILE
OBJECT_VALUE (ECMA_MAGIC_STRING_COMPACT_PROFILE_ERROR_UL,
ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_EVAL, ecma_builtin_global_object_eval, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_PARSE_FLOAT, ecma_builtin_global_object_parse_float, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_IS_NAN, ecma_builtin_global_object_is_nan, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_IS_FINITE, ecma_builtin_global_object_is_finite, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_DECODE_URI, ecma_builtin_global_object_decode_uri, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_DECODE_URI_COMPONENT, ecma_builtin_global_object_decode_uri_component, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_ENCODE_URI, ecma_builtin_global_object_encode_uri, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_ENCODE_URI_COMPONENT, ecma_builtin_global_object_encode_uri_component, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_PARSE_INT, ecma_builtin_global_object_parse_int, 2, 2)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,327 @@
/* Copyright 2014-2015 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 BUILTIN_UNDERSCORED_ID
# error "Please, define BUILTIN_UNDERSCORED_ID"
#endif /* !BUILTIN_UNDERSCORED_ID */
#ifndef BUILTIN_INC_HEADER_NAME
# error "Please, define BUILTIN_INC_HEADER_NAME"
#endif /* !BUILTIN_INC_HEADER_NAME */
#define PASTE__(x, y) x ## y
#define PASTE_(x, y) PASTE__ (x, y)
#define PASTE(x, y) PASTE_ (x, y)
#define SORT_PROPERTY_NAMES_ROUTINE_NAME(builtin_underscored_id) \
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _sort_property_names)
#define TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME(builtin_underscored_id) \
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _try_to_instantiate_property)
#define DISPATCH_ROUTINE_ROUTINE_NAME(builtin_underscored_id) \
PASTE (PASTE (ecma_builtin_, builtin_underscored_id), _dispatch_routine)
#define ROUTINE_ARG(n) , const ecma_value_t& arg ## n
#define ROUTINE_ARG_LIST_0 const ecma_value_t& this_arg
#define ROUTINE_ARG_LIST_1 ROUTINE_ARG_LIST_0 ROUTINE_ARG(1)
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1 ROUTINE_ARG(2)
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2 ROUTINE_ARG(3)
#define ROUTINE_ARG_LIST_NON_FIXED ROUTINE_ARG_LIST_0, \
const ecma_value_t *arguments_list_p, ecma_length_t arguments_list_len
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
static ecma_completion_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number);
#include BUILTIN_INC_HEADER_NAME
#undef ROUTINE_ARG_LIST_NON_FIXED
#undef ROUTINE_ARG_LIST_3
#undef ROUTINE_ARG_LIST_2
#undef ROUTINE_ARG_LIST_1
#undef ROUTINE_ARG_LIST_0
#undef ROUTINE_ARG
static ecma_magic_string_id_t ecma_builtin_property_names[] =
{
#define SIMPLE_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
#define NUMBER_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
#define STRING_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
#define CP_UNIMPLEMENTED_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
#define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) name,
#define ROUTINE(name, c_function_name, args_number, length_prop_value) name,
#include BUILTIN_INC_HEADER_NAME
};
/**
* Sort builtin's property names array
*/
void
SORT_PROPERTY_NAMES_ROUTINE_NAME (BUILTIN_UNDERSCORED_ID) (void)
{
bool swapped;
do
{
swapped = false;
for (ecma_length_t i = 1;
i < (sizeof (ecma_builtin_property_names) / sizeof (ecma_builtin_property_names [0]));
i++)
{
if (ecma_builtin_property_names [i] < ecma_builtin_property_names [i - 1])
{
ecma_magic_string_id_t id_temp = ecma_builtin_property_names [i - 1];
ecma_builtin_property_names [i - 1] = ecma_builtin_property_names [i];
ecma_builtin_property_names [i] = id_temp;
swapped = true;
}
}
}
while (swapped);
} /* SORT_PROPERTY_NAMES_ROUTINE_NAME */
/**
* If the property's name is one of built-in properties of the built-in 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*
TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME (BUILTIN_UNDERSCORED_ID) (ecma_object_t *obj_p, /**< object */
ecma_string_t *prop_name_p) /**< property's name */
{
#define OBJECT_ID(builtin_id) const ecma_builtin_id_t builtin_object_id = builtin_id;
#include BUILTIN_INC_HEADER_NAME
JERRY_ASSERT (ecma_builtin_is (obj_p, builtin_object_id));
JERRY_ASSERT (ecma_find_named_property (obj_p, prop_name_p) == NULL);
ecma_magic_string_id_t id;
if (!ecma_is_string_magic (prop_name_p, &id))
{
return NULL;
}
const ecma_length_t property_numbers = (ecma_length_t) (sizeof (ecma_builtin_property_names) /
sizeof (ecma_builtin_property_names [0]));
int32_t index;
index = ecma_builtin_bin_search_for_magic_string_id_in_array (ecma_builtin_property_names,
property_numbers,
id);
if (index == -1)
{
return NULL;
}
JERRY_ASSERT (index >= 0 && (uint32_t) index < sizeof (uint64_t) * JERRY_BITSINBYTE);
uint32_t bit;
ecma_internal_property_id_t mask_prop_id;
if (index >= 32)
{
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63;
bit = (uint32_t) 1u << (index - 32);
}
else
{
mask_prop_id = ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_0_31;
bit = (uint32_t) 1u << index;
}
ecma_property_t *mask_prop_p = ecma_find_internal_property (obj_p, mask_prop_id);
if (mask_prop_p == NULL)
{
mask_prop_p = ecma_create_internal_property (obj_p, mask_prop_id);
mask_prop_p->u.internal_property.value = 0;
}
uint32_t bit_mask = mask_prop_p->u.internal_property.value;
if (bit_mask & bit)
{
return NULL;
}
bit_mask |= bit;
mask_prop_p->u.internal_property.value = bit_mask;
ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
ecma_property_writable_value_t writable;
ecma_property_enumerable_value_t enumerable;
ecma_property_configurable_value_t configurable;
switch (id)
{
#define ROUTINE(name, c_function_name, args_number, length_prop_value) case name: \
{ \
ecma_object_t *func_obj_p = ecma_builtin_make_function_object_for_routine (builtin_object_id, \
id, \
length_prop_value); \
\
writable = ECMA_PROPERTY_WRITABLE; \
enumerable = ECMA_PROPERTY_NOT_ENUMERABLE; \
configurable = ECMA_PROPERTY_CONFIGURABLE; \
\
value = ecma_make_object_value (func_obj_p); \
\
break; \
}
#define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable) case name: \
{ \
value = ecma_make_object_value (obj_getter); \
writable = prop_writable; \
enumerable = prop_enumerable; \
configurable = prop_configurable; \
break; \
}
#define SIMPLE_VALUE(name, simple_value, prop_writable, prop_enumerable, prop_configurable) case name: \
{ \
value = ecma_make_simple_value (simple_value); \
\
writable = prop_writable; \
enumerable = prop_enumerable; \
configurable = prop_configurable; \
\
break; \
}
#define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable) case name: \
{ \
ecma_number_t *num_p = ecma_alloc_number (); \
*num_p = number_value; \
\
value = ecma_make_number_value (num_p); \
\
writable = prop_writable; \
enumerable = prop_enumerable; \
configurable = prop_configurable; \
\
break; \
}
#define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable) case name: \
{ \
ecma_string_t *magic_string_p = ecma_get_magic_string (magic_string_id); \
\
value = ecma_make_string_value (magic_string_p); \
\
writable = prop_writable; \
enumerable = prop_enumerable; \
configurable = prop_configurable; \
\
break; \
}
#ifdef CONFIG_ECMA_COMPACT_PROFILE
#define CP_UNIMPLEMENTED_VALUE(name, value, prop_writable, prop_enumerable, prop_configurable) case name: \
{ \
/* The object throws CompactProfileError upon invocation */ \
ecma_object_t *get_set_p = ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR); \
ecma_property_t *compact_profile_thrower_property_p = ecma_create_named_accessor_property (obj_p, \
prop_name_p, \
get_set_p, \
get_set_p, \
true, \
false); \
ecma_deref_object (get_set_p); \
\
return compact_profile_thrower_property_p; \
}
#else /* CONFIG_ECMA_COMPACT_PROFILE */
#define CP_UNIMPLEMENTED_VALUE(name, value, prop_writable, prop_enumerable, prop_configurable) case name: \
{ \
JERRY_UNIMPLEMENTED ("The built-in is not implemented."); \
}
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
#include BUILTIN_INC_HEADER_NAME
default:
{
JERRY_UNREACHABLE ();
}
}
ecma_property_t *prop_p = ecma_create_named_data_property (obj_p,
prop_name_p,
writable,
enumerable,
configurable);
ecma_named_data_property_assign_value (obj_p, prop_p, value);
ecma_free_value (value, true);
return prop_p;
} /* TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME */
/**
* Dispatcher of the built-in's routines
*
* @return completion-value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
DISPATCH_ROUTINE_ROUTINE_NAME (BUILTIN_UNDERSCORED_ID) (ecma_magic_string_id_t builtin_routine_id, /**< built-in's
routine's
name */
const ecma_value_t& this_arg_value, /**< 'this' argument
value */
const ecma_value_t arguments_list [], /**< list of arguments
passed to routine */
ecma_length_t arguments_number) /**< length of
arguments' list */
{
/* the arguments may be unused for some built-ins */
(void) this_arg_value;
(void) arguments_list;
(void) arguments_number;
switch (builtin_routine_id)
{
#define ROUTINE_ARG(n) (arguments_number >= n ? arguments_list[n - 1] \
: ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED))
#define ROUTINE_ARG_LIST_0
#define ROUTINE_ARG_LIST_1 , ROUTINE_ARG(1)
#define ROUTINE_ARG_LIST_2 ROUTINE_ARG_LIST_1, ROUTINE_ARG(2)
#define ROUTINE_ARG_LIST_3 ROUTINE_ARG_LIST_2, ROUTINE_ARG(3)
#define ROUTINE_ARG_LIST_NON_FIXED , arguments_list, arguments_number
#define ROUTINE(name, c_function_name, args_number, length_prop_value) \
case name: \
{ \
return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \
}
#include BUILTIN_INC_HEADER_NAME
#undef ROUTINE_ARG_LIST_0
#undef ROUTINE_ARG_LIST_1
#undef ROUTINE_ARG_LIST_2
#undef ROUTINE_ARG_LIST_3
#undef ROUTINE_ARG_LIST_NON_FIXED
default:
{
JERRY_UNREACHABLE ();
}
}
} /* DISPATCH_ROUTINE_ROUTINE_NAME */
#undef PASTE__
#undef PASTE_
#undef PASTE
#undef SORT_PROPERTY_NAMES_ROUTINE_NAME
#undef DISPATCH_ROUTINE_ROUTINE_NAME
#undef TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME
#undef BUILTIN_UNDERSCORED_ID
#undef BUILTIN_INC_HEADER_NAME
@@ -0,0 +1,988 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-number-arithmetic.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_MATH_BUILTIN
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-math.inc.h"
#define BUILTIN_UNDERSCORED_ID math
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup object ECMA Object object built-in
* @{
*/
/**
* The Math object's 'abs' routine
*
* See also:
* ECMA-262 v5, 15.8.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_abs (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
ecma_number_t *num_p = ecma_alloc_number ();
if (ecma_number_is_nan (arg_num))
{
*num_p = arg_num;
}
else
{
*num_p = ecma_number_abs (arg_num);
}
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_math_object_abs */
/**
* The Math object's 'acos' routine
*
* See also:
* ECMA-262 v5, 15.8.2.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_acos (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_math_object_acos */
/**
* The Math object's 'asin' routine
*
* See also:
* ECMA-262 v5, 15.8.2.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_asin (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_math_object_asin */
/**
* The Math object's 'atan' routine
*
* See also:
* ECMA-262 v5, 15.8.2.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_atan (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_math_object_atan */
/**
* The Math object's 'atan2' routine
*
* See also:
* ECMA-262 v5, 15.8.2.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_atan2 (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg1, /**< first routine's argument */
const ecma_value_t& arg2) /**< second routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_math_object_atan2 */
/**
* The Math object's 'ceil' routine
*
* See also:
* ECMA-262 v5, 15.8.2.6
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_ceil (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_math_object_ceil */
/**
* The Math object's 'cos' routine
*
* See also:
* ECMA-262 v5, 15.8.2.7
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_cos (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
ecma_number_t *num_p = ecma_alloc_number ();
if (ecma_number_is_nan (arg_num)
|| ecma_number_is_infinity (arg_num))
{
*num_p = ecma_number_make_nan ();
}
else if (ecma_number_is_zero (arg_num))
{
*num_p = ECMA_NUMBER_ONE;
}
else
{
/* Taylor series of cos (x) around x = 0 is 1 - x^2/2! + x^4/4! - x^6/6! + ... */
ecma_number_t x = ecma_op_number_remainder (arg_num, 2 * ECMA_NUMBER_PI);
ecma_number_t neg_sqr_x = ecma_number_negate (ecma_number_multiply (x, x));
ecma_number_t sum = ECMA_NUMBER_ZERO;
ecma_number_t next_addendum = ECMA_NUMBER_ONE;
ecma_number_t next_factorial_factor = ECMA_NUMBER_ZERO;
ecma_number_t diff = ecma_number_make_infinity (false);
while ((ecma_number_is_zero (sum) && !ecma_number_is_zero (diff))
|| (!ecma_number_is_zero (sum)
&& ecma_number_abs (ecma_number_divide (diff, sum)) > ecma_number_relative_eps))
{
ecma_number_t next_sum = ecma_number_add (sum, next_addendum);
next_addendum = ecma_number_multiply (next_addendum, neg_sqr_x);
next_factorial_factor = ecma_number_add (next_factorial_factor, ECMA_NUMBER_ONE);
next_addendum = ecma_number_divide (next_addendum, next_factorial_factor);
next_factorial_factor = ecma_number_add (next_factorial_factor, ECMA_NUMBER_ONE);
next_addendum = ecma_number_divide (next_addendum, next_factorial_factor);
diff = ecma_number_abs (ecma_number_substract (sum, next_sum));
sum = next_sum;
}
*num_p = sum;
}
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_math_object_cos */
/**
* The Math object's 'exp' routine
*
* See also:
* ECMA-262 v5, 15.8.2.8
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_exp (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
ecma_number_t *num_p = ecma_alloc_number ();
if (ecma_number_is_nan (arg_num))
{
*num_p = arg_num;
}
else if (ecma_number_is_zero (arg_num))
{
*num_p = ECMA_NUMBER_ONE;
}
else if (ecma_number_is_infinity (arg_num))
{
if (ecma_number_is_negative (arg_num))
{
*num_p = ECMA_NUMBER_ZERO;
}
else
{
*num_p = arg_num;
}
}
else
{
*num_p = ecma_number_exp (arg_num);
}
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_math_object_exp */
/**
* The Math object's 'floor' routine
*
* See also:
* ECMA-262 v5, 15.8.2.9
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_floor (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_math_object_floor */
/**
* The Math object's 'log' routine
*
* See also:
* ECMA-262 v5, 15.8.2.10
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_log (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
ecma_number_t *num_p = ecma_alloc_number ();
if (ecma_number_is_nan (arg_num))
{
*num_p = arg_num;
}
else if (ecma_number_is_zero (arg_num))
{
*num_p = ecma_number_make_infinity (true);
}
else if (ecma_number_is_negative (arg_num))
{
*num_p = ecma_number_make_nan ();
}
else if (ecma_number_is_infinity (arg_num))
{
*num_p = arg_num;
}
else
{
*num_p = ecma_number_ln (arg_num);
}
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_math_object_log */
/**
* The Math object's 'max' routine
*
* See also:
* ECMA-262 v5, 15.8.2.11
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_max (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t args[], /**< arguments list */
ecma_length_t args_number) /**< number of arguments */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ecma_number_t ret_num = ecma_number_make_infinity (true);
bool is_just_convert = false;
for (ecma_length_t arg_index = 0;
arg_index < args_number;
arg_index++)
{
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
if (!is_just_convert)
{
if (unlikely (ecma_number_is_nan (arg_num)))
{
ret_num = arg_num;
is_just_convert = true;
}
else if (ecma_number_is_zero (arg_num) /* both numbers are zeroes */
&& ecma_number_is_zero (ret_num))
{
if (!ecma_number_is_negative (arg_num))
{
ret_num = arg_num;
}
}
else if (ecma_number_is_infinity (arg_num))
{
if (!ecma_number_is_negative (arg_num))
{
ret_num = arg_num;
is_just_convert = true;
}
}
else if (ecma_number_is_infinity (ret_num)) /* ret_num is negative infinity */
{
JERRY_ASSERT (ecma_number_is_negative (ret_num));
ret_num = arg_num;
}
else
{
JERRY_ASSERT (!ecma_number_is_nan (arg_num)
&& !ecma_number_is_infinity (arg_num));
JERRY_ASSERT (!ecma_number_is_nan (ret_num)
&& !ecma_number_is_infinity (ret_num));
if (arg_num > ret_num)
{
ret_num = arg_num;
}
}
}
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
if (ecma_is_completion_value_throw (ret_value))
{
return ret_value;
}
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
}
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
ecma_number_t *num_p = ecma_alloc_number ();
*num_p = ret_num;
return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
} /* ecma_builtin_math_object_max */
/**
* The Math object's 'min' routine
*
* See also:
* ECMA-262 v5, 15.8.2.12
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_min (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t args[], /**< arguments list */
ecma_length_t args_number) /**< number of arguments */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ecma_number_t ret_num = ecma_number_make_infinity (false);
bool is_just_convert = false;
for (ecma_length_t arg_index = 0;
arg_index < args_number;
arg_index++)
{
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
if (!is_just_convert)
{
if (unlikely (ecma_number_is_nan (arg_num)))
{
ret_num = arg_num;
is_just_convert = true;
}
else if (ecma_number_is_zero (arg_num) /* both numbers are zeroes */
&& ecma_number_is_zero (ret_num))
{
if (ecma_number_is_negative (arg_num))
{
ret_num = arg_num;
}
}
else if (ecma_number_is_infinity (arg_num))
{
if (ecma_number_is_negative (arg_num))
{
ret_num = arg_num;
is_just_convert = true;
}
}
else if (ecma_number_is_infinity (ret_num)) /* ret_num is positive infinity */
{
JERRY_ASSERT (!ecma_number_is_negative (ret_num));
ret_num = arg_num;
}
else
{
JERRY_ASSERT (!ecma_number_is_nan (arg_num)
&& !ecma_number_is_infinity (arg_num));
JERRY_ASSERT (!ecma_number_is_nan (ret_num)
&& !ecma_number_is_infinity (ret_num));
if (arg_num < ret_num)
{
ret_num = arg_num;
}
}
}
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
if (ecma_is_completion_value_throw (ret_value))
{
return ret_value;
}
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
}
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
ecma_number_t *num_p = ecma_alloc_number ();
*num_p = ret_num;
return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
} /* ecma_builtin_math_object_min */
/**
* The Math object's 'pow' routine
*
* See also:
* ECMA-262 v5, 15.8.2.13
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_pow (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg1, /**< first routine's argument */
const ecma_value_t& arg2) /**< second routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (x, arg1, ret_value);
ECMA_OP_TO_NUMBER_TRY_CATCH (y, arg2, ret_value);
ecma_number_t *num_p = ecma_alloc_number ();
if (ecma_number_is_nan (y)
|| (ecma_number_is_nan (x)
&& !ecma_number_is_zero (y)))
{
*num_p = ecma_number_make_nan ();
}
else if (ecma_number_is_zero (y))
{
*num_p = ECMA_NUMBER_ONE;
}
else if (ecma_number_is_infinity (y))
{
const ecma_number_t x_abs = ecma_number_abs (x);
if (x_abs == ECMA_NUMBER_ONE)
{
*num_p = ecma_number_make_nan ();
}
else if ((ecma_number_is_negative (y) && x_abs < ECMA_NUMBER_ONE)
|| (!ecma_number_is_negative (y) && x_abs > ECMA_NUMBER_ONE))
{
*num_p = ecma_number_make_infinity (false);
}
else
{
JERRY_ASSERT ((ecma_number_is_negative (y) && x_abs > ECMA_NUMBER_ONE)
|| (!ecma_number_is_negative (y) && x_abs < ECMA_NUMBER_ONE));
*num_p = ECMA_NUMBER_ZERO;
}
}
else
{
const ecma_number_t diff_is_int = ecma_op_number_remainder (y, ECMA_NUMBER_ONE);
const ecma_number_t rel_diff_is_int = ecma_number_abs (ecma_number_divide (diff_is_int,
y));
const ecma_number_t y_int = ecma_number_substract (y, diff_is_int);
const ecma_number_t y_int_half = ecma_number_multiply (y_int, ECMA_NUMBER_HALF);
const ecma_number_t diff_is_odd = ecma_op_number_remainder (y_int_half, ECMA_NUMBER_ONE);
const ecma_number_t rel_diff_is_odd = ecma_number_abs (ecma_number_divide (diff_is_odd,
y_int_half));
const bool is_y_int = (rel_diff_is_int < ecma_number_relative_eps);
const bool is_y_odd = (is_y_int && rel_diff_is_odd > ecma_number_relative_eps);
if (ecma_number_is_infinity (x))
{
if (!ecma_number_is_negative (x))
{
if (y > ECMA_NUMBER_ZERO)
{
*num_p = ecma_number_make_infinity (false);
}
else
{
JERRY_ASSERT (y < ECMA_NUMBER_ZERO);
*num_p = ECMA_NUMBER_ZERO;
}
}
else
{
if (y > ECMA_NUMBER_ZERO)
{
*num_p = ecma_number_make_infinity (is_y_odd);
}
else
{
JERRY_ASSERT (y < ECMA_NUMBER_ZERO);
if (is_y_odd)
{
*num_p = ecma_number_negate (ECMA_NUMBER_ZERO);
}
else
{
*num_p = ECMA_NUMBER_ZERO;
}
}
}
}
else if (ecma_number_is_zero (x))
{
if (!ecma_number_is_negative (x))
{
if (y > ECMA_NUMBER_ZERO)
{
*num_p = ECMA_NUMBER_ZERO;
}
else
{
JERRY_ASSERT (y < ECMA_NUMBER_ZERO);
*num_p = ecma_number_make_infinity (false);
}
}
else
{
if (y > ECMA_NUMBER_ZERO)
{
if (is_y_odd)
{
*num_p = ecma_number_negate (ECMA_NUMBER_ZERO);
}
else
{
*num_p = ECMA_NUMBER_ZERO;
}
}
else
{
*num_p = ecma_number_make_infinity (is_y_odd);
}
}
}
else if (!ecma_number_is_infinity (x)
&& x < ECMA_NUMBER_ZERO
&& !ecma_number_is_infinity (y)
&& !is_y_int)
{
*num_p = ecma_number_make_nan ();
}
else
{
JERRY_ASSERT (!ecma_number_is_infinity (x)
&& !ecma_number_is_zero (x));
JERRY_ASSERT (!ecma_number_is_infinity (y)
&& !ecma_number_is_zero (y));
const bool sign = (x < ECMA_NUMBER_ZERO && is_y_odd);
const bool invert = (y < ECMA_NUMBER_ZERO);
JERRY_ASSERT (is_y_int || !sign);
ecma_number_t positive_x;
ecma_number_t positive_y;
if (x < ECMA_NUMBER_ZERO)
{
JERRY_ASSERT (x < ECMA_NUMBER_ZERO);
positive_x = ecma_number_negate (x);
}
else
{
positive_x = x;
}
if (invert)
{
positive_y = ecma_number_negate (y);
}
else
{
positive_y = y;
}
ecma_number_t ret_num;
if (is_y_int
&& ecma_uint32_to_number (ecma_number_to_uint32 (positive_y)) == positive_y)
{
TODO (/* Check for license issues */);
uint32_t power_uint32 = ecma_number_to_uint32 (positive_y);
ret_num = ECMA_NUMBER_ONE;
ecma_number_t power_accumulator = positive_x;
while (power_uint32 != 0)
{
if (power_uint32 % 2)
{
ret_num = ecma_number_multiply (ret_num, power_accumulator);
power_uint32--;
}
power_accumulator = ecma_number_multiply (power_accumulator, power_accumulator);
power_uint32 /= 2;
}
}
else
{
/* pow (x, y) = exp (y * ln (x)) */
ecma_number_t ln_x = ecma_number_ln (positive_x);
ecma_number_t y_m_ln_x = ecma_number_multiply (positive_y, ln_x);
ret_num = ecma_number_exp (y_m_ln_x);
}
if (sign)
{
ret_num = ecma_number_negate (ret_num);
}
if (invert)
{
ret_num = ecma_number_divide (ECMA_NUMBER_ONE, ret_num);
}
*num_p = ret_num;
}
}
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_OP_TO_NUMBER_FINALIZE (y);
ECMA_OP_TO_NUMBER_FINALIZE (x);
return ret_value;
} /* ecma_builtin_math_object_pow */
/**
* The Math object's 'random' routine
*
* See also:
* ECMA-262 v5, 15.8.2.14
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_random (const ecma_value_t& this_arg __attr_unused___) /**< 'this' argument */
{
/* Implementation of George Marsaglia's XorShift random number generator */
TODO (/* Check for license issues */);
static uint32_t word1 = 1455997910;
static uint32_t word2 = 1999515274;
static uint32_t word3 = 1234451287;
static uint32_t word4 = 1949149569;
uint32_t intermediate = word1 ^ (word1 << 11);
intermediate ^= intermediate >> 8;
word1 = word2;
word2 = word3;
word3 = word4;
word4 ^= word4 >> 19;
word4 ^= intermediate;
const uint32_t max_uint32 = (uint32_t) -1;
ecma_number_t rand = (ecma_number_t) word4;
rand /= (ecma_number_t) max_uint32;
rand *= (ecma_number_t) (max_uint32 - 1) / (ecma_number_t) max_uint32;
ecma_number_t *rand_p = ecma_alloc_number ();
*rand_p = rand;
return ecma_make_normal_completion_value (ecma_make_number_value (rand_p));
} /* ecma_builtin_math_object_random */
/**
* The Math object's 'round' routine
*
* See also:
* ECMA-262 v5, 15.8.2.15
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_round (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
ecma_number_t *num_p = ecma_alloc_number ();
if (ecma_number_is_nan (arg_num)
|| ecma_number_is_zero (arg_num)
|| ecma_number_is_infinity (arg_num))
{
*num_p = arg_num;
}
else if (ecma_number_is_negative (arg_num)
&& arg_num >= -0.5f)
{
*num_p = ecma_number_negate (0.0f);
}
else
{
const ecma_number_t up_half = arg_num + 0.5f;
const ecma_number_t down_half = arg_num - 0.5f;
const ecma_number_t up_rounded = up_half - ecma_op_number_remainder (up_half, 1);
const ecma_number_t down_rounded = down_half - ecma_op_number_remainder (down_half, 1);
if (up_rounded - arg_num <= arg_num - down_rounded)
{
*num_p = up_rounded;
}
else
{
*num_p = down_rounded;
}
}
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_math_object_round */
/**
* The Math object's 'sin' routine
*
* See also:
* ECMA-262 v5, 15.8.2.16
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_sin (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
ecma_number_t *num_p = ecma_alloc_number ();
if (ecma_number_is_nan (arg_num)
|| ecma_number_is_infinity (arg_num))
{
*num_p = ecma_number_make_nan ();
}
else if (ecma_number_is_zero (arg_num))
{
*num_p = arg_num;
}
else
{
/* Taylor series of sin (x) around x = 0 is x - x^3/3! + x^5/5! - x^7/7! + ... */
ecma_number_t x = ecma_op_number_remainder (arg_num, 2 * ECMA_NUMBER_PI);
ecma_number_t neg_sqr_x = ecma_number_negate (ecma_number_multiply (x, x));
ecma_number_t sum = ECMA_NUMBER_ZERO;
ecma_number_t next_addendum = ecma_number_divide (x, ECMA_NUMBER_ONE);
ecma_number_t next_factorial_factor = ECMA_NUMBER_ONE;
ecma_number_t diff = ecma_number_make_infinity (false);
while ((ecma_number_is_zero (sum) && !ecma_number_is_zero (diff))
|| (!ecma_number_is_zero (sum)
&& ecma_number_abs (ecma_number_divide (diff, sum)) > ecma_number_relative_eps))
{
ecma_number_t next_sum = ecma_number_add (sum, next_addendum);
next_addendum = ecma_number_multiply (next_addendum, neg_sqr_x);
next_factorial_factor = ecma_number_add (next_factorial_factor, ECMA_NUMBER_ONE);
next_addendum = ecma_number_divide (next_addendum, next_factorial_factor);
next_factorial_factor = ecma_number_add (next_factorial_factor, ECMA_NUMBER_ONE);
next_addendum = ecma_number_divide (next_addendum, next_factorial_factor);
diff = ecma_number_abs (ecma_number_substract (sum, next_sum));
sum = next_sum;
}
*num_p = sum;
}
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_math_object_sin */
/**
* The Math object's 'sqrt' routine
*
* See also:
* ECMA-262 v5, 15.8.2.17
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_sqrt (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, arg, ret_value);
ecma_number_t ret_num;
if (ecma_number_is_nan (arg_num)
|| (!ecma_number_is_zero (arg_num)
&& ecma_number_is_negative (arg_num)))
{
ret_num = ecma_number_make_nan ();
}
else if (ecma_number_is_zero (arg_num))
{
ret_num = arg_num;
}
else if (ecma_number_is_infinity (arg_num))
{
JERRY_ASSERT (!ecma_number_is_negative (arg_num));
ret_num = arg_num;
}
else
{
ret_num = ecma_number_sqrt (arg_num);
}
ecma_number_t *num_p = ecma_alloc_number ();
*num_p = ret_num;
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
return ret_value;
} /* ecma_builtin_math_object_sqrt */
/**
* The Math object's 'tan' routine
*
* See also:
* ECMA-262 v5, 15.8.2.18
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_math_object_tan (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_math_object_tan */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_MATH_BUILTIN */
@@ -0,0 +1,129 @@
/* 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.
*/
/*
* Math built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef SIMPLE_VALUE
# define SIMPLE_VALUE(name, simple_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !SIMPLE_VALUE */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_MATH)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// ECMA-262 v5, 15.8.1.1
NUMBER_VALUE (ECMA_MAGIC_STRING_E_U,
ECMA_NUMBER_E,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// ECMA-262 v5, 15.8.1.2
NUMBER_VALUE (ECMA_MAGIC_STRING_LN10_U,
ECMA_NUMBER_LN10,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// ECMA-262 v5, 15.8.1.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LN2_U,
ECMA_NUMBER_LN2,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// ECMA-262 v5, 15.8.1.4
NUMBER_VALUE (ECMA_MAGIC_STRING_LOG2E_U,
ECMA_NUMBER_LOG2E,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// ECMA-262 v5, 15.8.1.5
NUMBER_VALUE (ECMA_MAGIC_STRING_LOG10E_U,
ECMA_NUMBER_LOG10E,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// ECMA-262 v5, 15.8.1.6
NUMBER_VALUE (ECMA_MAGIC_STRING_PI_U,
ECMA_NUMBER_PI,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// ECMA-262 v5, 15.8.1.7
NUMBER_VALUE (ECMA_MAGIC_STRING_SQRT1_2_U,
ECMA_NUMBER_SQRT_1_2,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// ECMA-262 v5, 15.8.1.8
NUMBER_VALUE (ECMA_MAGIC_STRING_SQRT2_U,
ECMA_NUMBER_SQRT2,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_ABS, ecma_builtin_math_object_abs, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_ACOS, ecma_builtin_math_object_acos, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_ASIN, ecma_builtin_math_object_asin, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_ATAN, ecma_builtin_math_object_atan, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_ATAN2, ecma_builtin_math_object_atan2, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_CEIL, ecma_builtin_math_object_ceil, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_COS, ecma_builtin_math_object_cos, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_EXP, ecma_builtin_math_object_exp, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_FLOOR, ecma_builtin_math_object_floor, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_LOG, ecma_builtin_math_object_log, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_MAX, ecma_builtin_math_object_max, NON_FIXED, 2)
ROUTINE (ECMA_MAGIC_STRING_MIN, ecma_builtin_math_object_min, NON_FIXED, 2)
ROUTINE (ECMA_MAGIC_STRING_POW, ecma_builtin_math_object_pow, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_RANDOM, ecma_builtin_math_object_random, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_ROUND, ecma_builtin_math_object_round, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_SIN, ecma_builtin_math_object_sin, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_SQRT, ecma_builtin_math_object_sqrt, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_TAN, ecma_builtin_math_object_tan, 1, 1)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,214 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-number-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID number_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup numberprototype ECMA Number.prototype object built-in
* @{
*/
/**
* The Number.prototype object's 'toString' routine
*
* See also:
* ECMA-262 v5, 15.7.4.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_number_prototype_object_to_string (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t* arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
ecma_number_t this_arg_number;
if (ecma_is_value_number (this_arg))
{
ecma_number_t *this_arg_number_p = ecma_get_number_from_value (this_arg);
this_arg_number = *this_arg_number_p;
}
else if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_NUMBER_UL)
{
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
ecma_number_t *prim_value_num_p = ECMA_GET_NON_NULL_POINTER (ecma_number_t,
prim_value_prop_p->u.internal_property.value);
this_arg_number = *prim_value_num_p;
}
else
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
}
else
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
if (arguments_list_len == 0)
{
ecma_string_t *ret_str_p = ecma_new_ecma_string_from_number (this_arg_number);
return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
}
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (arguments_list_p);
}
} /* ecma_builtin_number_prototype_object_to_string */
/**
* The Number.prototype object's 'toLocaleString' routine
*
* See also:
* ECMA-262 v5, 15.7.4.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_number_prototype_object_to_locale_string (const ecma_value_t& this_arg) /**< this argument */
{
return ecma_builtin_number_prototype_object_to_string (this_arg, NULL, 0);
} /* ecma_builtin_number_prototype_object_to_locale_string */
/**
* The Number.prototype object's 'valueOf' routine
*
* See also:
* ECMA-262 v5, 15.7.4.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_number_prototype_object_value_of (const ecma_value_t& this_arg) /**< this argument */
{
if (ecma_is_value_number (this_arg))
{
return ecma_make_normal_completion_value (ecma_copy_value (this_arg, true));
}
else if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_NUMBER_UL)
{
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
ecma_number_t *prim_value_num_p = ECMA_GET_NON_NULL_POINTER (ecma_number_t,
prim_value_prop_p->u.internal_property.value);
ecma_number_t *ret_num_p = ecma_alloc_number ();
*ret_num_p = *prim_value_num_p;
return ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p));
}
}
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
} /* ecma_builtin_number_prototype_object_value_of */
/**
* The Number.prototype object's 'toFixed' routine
*
* See also:
* ECMA-262 v5, 15.7.4.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_number_prototype_object_to_fixed (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_number_prototype_object_to_fixed */
/**
* The Number.prototype object's 'toExponential' routine
*
* See also:
* ECMA-262 v5, 15.7.4.6
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_number_prototype_object_to_exponential (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_number_prototype_object_to_exponential */
/**
* The Number.prototype object's 'toPrecision' routine
*
* See also:
* ECMA-262 v5, 15.7.4.7
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_number_prototype_object_to_precision (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_number_prototype_object_to_precision */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN */
@@ -0,0 +1,60 @@
/* Copyright 2014-2015 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.
*/
/*
* Number.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.7.4.1
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_number_prototype_object_to_string, NON_FIXED, 1)
ROUTINE (ECMA_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_number_prototype_object_value_of, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_number_prototype_object_to_locale_string, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_TO_FIXED_UL, ecma_builtin_number_prototype_object_to_fixed, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_TO_EXPONENTIAL_UL, ecma_builtin_number_prototype_object_to_exponential, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_TO_PRECISION_UL, ecma_builtin_number_prototype_object_to_precision, 1, 1)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,109 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-number-object.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-number.inc.h"
#define BUILTIN_UNDERSCORED_ID number
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup number ECMA Number object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in Number object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_number_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
ecma_completion_value_t ret_value;
if (arguments_list_len == 0)
{
ecma_number_t *zero_num_p = ecma_alloc_number ();
*zero_num_p = ECMA_NUMBER_ZERO;
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (zero_num_p));
}
else
{
ret_value = ecma_op_to_number (arguments_list_p [0]);
}
return ret_value;
} /* ecma_builtin_number_dispatch_call */
/**
* Handle calling [[Construct]] of built-in Number object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_number_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len == 0)
{
ecma_number_t *zero_num_p = ecma_alloc_number ();
*zero_num_p = ECMA_NUMBER_ZERO;
ecma_completion_value_t completion = ecma_op_create_number_object (ecma_make_number_value (zero_num_p));
ecma_dealloc_number (zero_num_p);
return completion;
}
else
{
return ecma_op_create_number_object (arguments_list_p[0]);
}
} /* ecma_builtin_number_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN */
@@ -0,0 +1,96 @@
/* Copyright 2014-2015 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.
*/
/*
* Number built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_NUMBER)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.7.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// 15.7.3.4
NUMBER_VALUE (ECMA_MAGIC_STRING_NAN,
ecma_number_make_nan (),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// 15.7.3.2
NUMBER_VALUE (ECMA_MAGIC_STRING_MAX_VALUE_U,
ECMA_NUMBER_MAX_VALUE,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// 15.7.3.3
NUMBER_VALUE (ECMA_MAGIC_STRING_MIN_VALUE_U,
ECMA_NUMBER_MIN_VALUE,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// 15.7.3.5
NUMBER_VALUE (ECMA_MAGIC_STRING_POSITIVE_INFINITY_U,
ecma_number_make_infinity (false),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
// 15.7.3.6
NUMBER_VALUE (ECMA_MAGIC_STRING_NEGATIVE_INFINITY_U,
ecma_number_make_infinity (true),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.7.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,215 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID object_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup objectprototype ECMA Object.prototype object built-in
* @{
*/
/**
* The Object.prototype object's 'toString' routine
*
* See also:
* ECMA-262 v5, 15.2.4.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_prototype_object_to_string (const ecma_value_t& this_arg) /**< this argument */
{
ecma_magic_string_id_t type_string;
if (ecma_is_value_undefined (this_arg))
{
type_string = ECMA_MAGIC_STRING_UNDEFINED_UL;
}
else if (ecma_is_value_null (this_arg))
{
type_string = ECMA_MAGIC_STRING_NULL_UL;
}
else
{
ecma_completion_value_t obj_this = ecma_op_to_object (this_arg);
if (!ecma_is_completion_value_normal (obj_this))
{
return obj_this;
}
JERRY_ASSERT (ecma_is_value_object (ecma_get_completion_value_value (obj_this)));
ecma_object_t *obj_p = ecma_get_object_from_completion_value (obj_this);
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_CLASS);
type_string = (ecma_magic_string_id_t) class_prop_p->u.internal_property.value;
ecma_free_completion_value (obj_this);
}
ecma_string_t *ret_string_p;
/* Building string "[object #type#]" where type is 'Undefined',
'Null' or one of possible object's classes.
The string with null character is maximum 19 characters long. */
const ssize_t buffer_size = 19;
MEM_DEFINE_LOCAL_ARRAY (str_buffer, buffer_size, ecma_char_t);
const ecma_char_t *left_square_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_LEFT_SQUARE_CHAR);
const ecma_char_t *object_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_OBJECT);
const ecma_char_t *space_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_SPACE_CHAR);
const ecma_char_t *type_name_zt_str_p = ecma_get_magic_string_zt (type_string);
const ecma_char_t *right_square_zt_str_p = ecma_get_magic_string_zt (ECMA_MAGIC_STRING_RIGHT_SQUARE_CHAR);
ecma_char_t *buffer_ptr = str_buffer;
ssize_t buffer_size_left = buffer_size;
buffer_ptr = ecma_copy_zt_string_to_buffer (left_square_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
buffer_ptr = ecma_copy_zt_string_to_buffer (object_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
buffer_ptr = ecma_copy_zt_string_to_buffer (space_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
buffer_ptr = ecma_copy_zt_string_to_buffer (type_name_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
buffer_ptr = ecma_copy_zt_string_to_buffer (right_square_zt_str_p,
buffer_ptr,
buffer_size_left);
buffer_size_left = buffer_size - (buffer_ptr - str_buffer) * (ssize_t) sizeof (ecma_char_t);
JERRY_ASSERT (buffer_size_left >= 0);
ret_string_p = ecma_new_ecma_string (str_buffer);
MEM_FINALIZE_LOCAL_ARRAY (str_buffer);
return ecma_make_normal_completion_value (ecma_make_string_value (ret_string_p));
} /* ecma_builtin_object_prototype_object_to_string */
/**
* The Object.prototype object's 'valueOf' routine
*
* See also:
* ECMA-262 v5, 15.2.4.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_prototype_object_value_of (const ecma_value_t& this_arg) /**< this argument */
{
return ecma_op_to_object (this_arg);
} /* ecma_builtin_object_prototype_object_value_of */
/**
* The Object.prototype object's 'toLocaleString' routine
*
* See also:
* ECMA-262 v5, 15.2.4.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_prototype_object_to_locale_string (const ecma_value_t& this_arg) /**< this argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
} /* ecma_builtin_object_prototype_object_to_locale_string */
/**
* The Object.prototype object's 'hasOwnProperty' routine
*
* See also:
* ECMA-262 v5, 15.2.4.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_prototype_object_has_own_property (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< first argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_prototype_object_has_own_property */
/**
* The Object.prototype object's 'isPrototypeOf' routine
*
* See also:
* ECMA-262 v5, 15.2.4.6
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_prototype_object_is_prototype_of (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's first argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_prototype_object_is_prototype_of */
/**
* The Object.prototype object's 'propertyIsEnumerable' routine
*
* See also:
* ECMA-262 v5, 15.2.4.7
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_prototype_object_property_is_enumerable (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's first argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_prototype_object_property_is_enumerable */
/**
* @}
* @}
* @}
*/
@@ -0,0 +1,60 @@
/* Copyright 2014-2015 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.
*/
/*
* Object.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.2.4.1
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_object_prototype_object_to_string, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_object_prototype_object_value_of, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_TO_LOCALE_STRING_UL, ecma_builtin_object_prototype_object_to_locale_string, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_HAS_OWN_PROPERTY_UL, ecma_builtin_object_prototype_object_has_own_property, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_IS_PROTOTYPE_OF_UL, ecma_builtin_object_prototype_object_is_prototype_of, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL, ecma_builtin_object_prototype_object_property_is_enumerable, 1, 1)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,358 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-object.inc.h"
#define BUILTIN_UNDERSCORED_ID object
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup object ECMA Object object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in Object object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_object_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
ecma_completion_value_t ret_value;
if (arguments_list_len == 0
|| ecma_is_value_undefined (arguments_list_p[0])
|| ecma_is_value_null (arguments_list_p [0]))
{
ret_value = ecma_builtin_object_dispatch_construct (arguments_list_p, arguments_list_len);
}
else
{
ret_value = ecma_op_to_object (arguments_list_p [0]);
}
return ret_value;
} /* ecma_builtin_object_dispatch_call */
/**
* Handle calling [[Construct]] of built-in Object object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_object_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len == 0)
{
ecma_object_t *obj_p = ecma_op_create_object_object_noarg ();
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
}
else
{
ecma_completion_value_t new_obj_value = ecma_op_create_object_object_arg (arguments_list_p [0]);
if (!ecma_is_completion_value_normal (new_obj_value))
{
return new_obj_value;
}
else
{
return ecma_make_normal_completion_value (ecma_get_completion_value_value (new_obj_value));
}
}
} /* ecma_builtin_object_dispatch_construct */
/**
* The Object object's 'getPrototypeOf' routine
*
* See also:
* ECMA-262 v5, 15.2.3.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_get_prototype_of (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_object_get_prototype_of */
/**
* The Object object's 'getOwnPropertyNames' routine
*
* See also:
* ECMA-262 v5, 15.2.3.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_get_own_property_names (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_object_get_own_property_names */
/**
* The Object object's 'seal' routine
*
* See also:
* ECMA-262 v5, 15.2.3.8
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_seal (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_object_seal */
/**
* The Object object's 'freeze' routine
*
* See also:
* ECMA-262 v5, 15.2.3.9
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_freeze (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_object_freeze */
/**
* The Object object's 'preventExtensions' routine
*
* See also:
* ECMA-262 v5, 15.2.3.10
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_prevent_extensions (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_object_prevent_extensions */
/**
* The Object object's 'isSealed' routine
*
* See also:
* ECMA-262 v5, 15.2.3.11
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_is_sealed (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_object_is_sealed */
/**
* The Object object's 'isFrozen' routine
*
* See also:
* ECMA-262 v5, 15.2.3.12
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_is_frozen (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_object_is_frozen */
/**
* The Object object's 'isExtensible' routine
*
* See also:
* ECMA-262 v5, 15.2.3.13
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_is_extensible (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_object_is_extensible */
/**
* The Object object's 'keys' routine
*
* See also:
* ECMA-262 v5, 15.2.3.14
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_keys (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_object_object_keys */
/**
* The Object object's 'getOwnPropertyDescriptor' routine
*
* See also:
* ECMA-262 v5, 15.2.3.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_get_own_property_descriptor (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_object_object_get_own_property_descriptor */
/**
* The Object object's 'create' routine
*
* See also:
* ECMA-262 v5, 15.2.3.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_create (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_object_object_create */
/**
* The Object object's 'defineProperties' routine
*
* See also:
* ECMA-262 v5, 15.2.3.7
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_define_properties (const ecma_value_t& this_arg, /**< 'this' argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_object_object_define_properties */
/**
* The Object object's 'defineProperty' routine
*
* See also:
* ECMA-262 v5, 15.2.3.6
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_object_object_define_property (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2, /**< routine's second argument */
const ecma_value_t& arg3) /**< routine's third argument */
{
ecma_completion_value_t ret_value;
if (!ecma_is_value_object (arg1))
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
ecma_object_t *obj_p = ecma_get_object_from_value (arg1);
ECMA_TRY_CATCH (name_str_value,
ecma_op_to_string (arg2),
ret_value);
ecma_string_t *name_str_p = ecma_get_string_from_value (name_str_value);
ecma_property_descriptor_t prop_desc;
ECMA_TRY_CATCH (conv_result,
ecma_op_to_property_descriptor (arg3, &prop_desc),
ret_value);
ECMA_TRY_CATCH (define_own_prop_ret,
ecma_op_object_define_own_property (obj_p,
name_str_p,
&prop_desc,
true),
ret_value);
ret_value = ecma_make_normal_completion_value (ecma_copy_value (arg1, true));
ECMA_FINALIZE (define_own_prop_ret);
ecma_free_property_descriptor (&prop_desc);
ECMA_FINALIZE (conv_result);
ECMA_FINALIZE (name_str_value);
}
return ret_value;
} /* ecma_builtin_object_object_define_property */
/**
* @}
* @}
* @}
*/
@@ -0,0 +1,81 @@
/* Copyright 2014-2015 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.
*/
/*
* Object built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_OBJECT)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.2.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.2.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_GET_PROTOTYPE_OF_UL, ecma_builtin_object_object_get_prototype_of, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_GET_OWN_PROPERTY_NAMES_UL, ecma_builtin_object_object_get_own_property_names, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_SEAL, ecma_builtin_object_object_seal, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_FREEZE, ecma_builtin_object_object_freeze, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_PREVENT_EXTENSIONS_UL, ecma_builtin_object_object_prevent_extensions, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_IS_SEALED_UL, ecma_builtin_object_object_is_sealed, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_IS_FROZEN_UL, ecma_builtin_object_object_is_frozen, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_IS_EXTENSIBLE, ecma_builtin_object_object_is_extensible, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_KEYS, ecma_builtin_object_object_keys, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_GET_OWN_PROPERTY_DESCRIPTOR_UL, ecma_builtin_object_object_get_own_property_descriptor, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_CREATE, ecma_builtin_object_object_create, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_DEFINE_PROPERTIES_UL, ecma_builtin_object_object_define_properties, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_DEFINE_PROPERTY_UL, ecma_builtin_object_object_define_property, 3, 3)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,37 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-rangeerror-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID range_error_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* RangeError.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.7.8
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_RANGE_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.9
STRING_VALUE (ECMA_MAGIC_STRING_NAME,
ECMA_MAGIC_STRING_RANGE_ERROR_UL,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.10
STRING_VALUE (ECMA_MAGIC_STRING_MESSAGE,
ECMA_MAGIC_STRING__EMPTY,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,101 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-rangeerror.inc.h"
#define BUILTIN_UNDERSCORED_ID range_error
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup rangeerror ECMA RangeError object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in RangeError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_range_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len != 0
&& !ecma_is_value_undefined (arguments_list_p [0]))
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (msg_str_value,
ecma_op_to_string (arguments_list_p[0]),
ret_value);
ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value);
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_RANGE,
message_string_p);
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
ECMA_FINALIZE (msg_str_value);
return ret_value;
}
else
{
ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_RANGE);
return ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
}
} /* ecma_builtin_range_error_dispatch_call */
/**
* Handle calling [[Construct]] of built-in RangeError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_range_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
return ecma_builtin_range_error_dispatch_call (arguments_list_p, arguments_list_len);
} /* ecma_builtin_range_error_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* RangeError built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_RANGE_ERROR)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.11.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,37 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-referenceerror-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID reference_error_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* ReferenceError.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.7.8
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_REFERENCE_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.9
STRING_VALUE (ECMA_MAGIC_STRING_NAME,
ECMA_MAGIC_STRING_REFERENCE_ERROR_UL,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.10
STRING_VALUE (ECMA_MAGIC_STRING_MESSAGE,
ECMA_MAGIC_STRING__EMPTY,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,101 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-referenceerror.inc.h"
#define BUILTIN_UNDERSCORED_ID reference_error
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup referenceerror ECMA ReferenceError object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in ReferenceError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_reference_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len != 0
&& !ecma_is_value_undefined (arguments_list_p [0]))
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (msg_str_value,
ecma_op_to_string (arguments_list_p[0]),
ret_value);
ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value);
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_REFERENCE,
message_string_p);
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
ECMA_FINALIZE (msg_str_value);
return ret_value;
}
else
{
ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_REFERENCE);
return ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
}
} /* ecma_builtin_reference_error_dispatch_call */
/**
* Handle calling [[Construct]] of built-in ReferenceError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_reference_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
return ecma_builtin_reference_error_dispatch_call (arguments_list_p, arguments_list_len);
} /* ecma_builtin_reference_error_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* ReferenceError built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_REFERENCE_ERROR)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.11.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,381 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID string_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup stringprototype ECMA String.prototype object built-in
* @{
*/
/**
* The String.prototype object's 'toString' routine
*
* See also:
* ECMA-262 v5, 15.5.4.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_to_string (const ecma_value_t& this_arg) /**< this argument */
{
if (ecma_is_value_string (this_arg))
{
return ecma_make_normal_completion_value (ecma_copy_value (this_arg, true));
}
else if (ecma_is_value_object (this_arg))
{
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
ecma_property_t *class_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
if (class_prop_p->u.internal_property.value == ECMA_MAGIC_STRING_STRING_UL)
{
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE);
ecma_string_t *prim_value_str_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
prim_value_prop_p->u.internal_property.value);
prim_value_str_p = ecma_copy_or_ref_ecma_string (prim_value_str_p);
return ecma_make_normal_completion_value (ecma_make_string_value (prim_value_str_p));
}
}
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
} /* ecma_builtin_string_prototype_object_to_string */
/**
* The String.prototype object's 'valueOf' routine
*
* See also:
* ECMA-262 v5, 15.5.4.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_value_of (const ecma_value_t& this_arg) /**< this argument */
{
return ecma_builtin_string_prototype_object_to_string (this_arg);
} /* ecma_builtin_string_prototype_object_value_of */
/**
* The String.prototype object's 'charAt' routine
*
* See also:
* ECMA-262 v5, 15.5.4.4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_char_at (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_string_prototype_object_char_at */
/**
* The String.prototype object's 'charCodeAt' routine
*
* See also:
* ECMA-262 v5, 15.5.4.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_char_code_at (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_string_prototype_object_char_code_at */
/**
* The String.prototype object's 'concat' routine
*
* See also:
* ECMA-262 v5, 15.5.4.6
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_concat (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t* argument_list_p, /**< arguments list */
ecma_length_t arguments_number) /**< number of arguments */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, argument_list_p, arguments_number);
} /* ecma_builtin_string_prototype_object_concat */
/**
* The String.prototype object's 'indexOf' routine
*
* See also:
* ECMA-262 v5, 15.5.4.7
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_index_of (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_string_prototype_object_index_of */
/**
* The String.prototype object's 'lastIndexOf' routine
*
* See also:
* ECMA-262 v5, 15.5.4.8
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_last_index_of (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_string_prototype_object_last_index_of */
/**
* The String.prototype object's 'localeCompare' routine
*
* See also:
* ECMA-262 v5, 15.5.4.9
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_locale_compare (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_string_prototype_object_locale_compare */
/**
* The String.prototype object's 'match' routine
*
* See also:
* ECMA-262 v5, 15.5.4.10
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_match (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_string_prototype_object_match */
/**
* The String.prototype object's 'replace' routine
*
* See also:
* ECMA-262 v5, 15.5.4.11
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_replace (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_string_prototype_object_replace */
/**
* The String.prototype object's 'search' routine
*
* See also:
* ECMA-262 v5, 15.5.4.12
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_search (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg) /**< routine's argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
} /* ecma_builtin_string_prototype_object_search */
/**
* The String.prototype object's 'slice' routine
*
* See also:
* ECMA-262 v5, 15.5.4.13
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_slice (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_string_prototype_object_slice */
/**
* The String.prototype object's 'split' routine
*
* See also:
* ECMA-262 v5, 15.5.4.14
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_split (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_string_prototype_object_split */
/**
* The String.prototype object's 'substring' routine
*
* See also:
* ECMA-262 v5, 15.5.4.15
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_substring (const ecma_value_t& this_arg, /**< this argument */
const ecma_value_t& arg1, /**< routine's first argument */
const ecma_value_t& arg2) /**< routine's second argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg1, arg2);
} /* ecma_builtin_string_prototype_object_substring */
/**
* The String.prototype object's 'toLowerCase' routine
*
* See also:
* ECMA-262 v5, 15.5.4.16
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_to_lower_case (const ecma_value_t& this_arg) /**< this argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
} /* ecma_builtin_string_prototype_object_to_lower_case */
/**
* The String.prototype object's 'toLocaleLowerCase' routine
*
* See also:
* ECMA-262 v5, 15.5.4.17
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_to_locale_lower_case (const ecma_value_t& this_arg) /**< this argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
} /* ecma_builtin_string_prototype_object_to_locale_lower_case */
/**
* The String.prototype object's 'toUpperCase' routine
*
* See also:
* ECMA-262 v5, 15.5.4.18
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_to_upper_case (const ecma_value_t& this_arg) /**< this argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
} /* ecma_builtin_string_prototype_object_to_upper_case */
/**
* The String.prototype object's 'toLocaleUpperCase' routine
*
* See also:
* ECMA-262 v5, 15.5.4.19
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_to_locale_upper_case (const ecma_value_t& this_arg) /**< this argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
} /* ecma_builtin_string_prototype_object_to_locale_upper_case */
/**
* The String.prototype object's 'trim' routine
*
* See also:
* ECMA-262 v5, 15.5.4.20
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_prototype_object_trim (const ecma_value_t& this_arg) /**< this argument */
{
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
} /* ecma_builtin_string_prototype_object_trim */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN */
@@ -0,0 +1,73 @@
/* Copyright 2014-2015 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.
*/
/*
* String.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_STRING_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.5.4.1
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_STRING),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_string_prototype_object_to_string, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_string_prototype_object_value_of, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_CONCAT, ecma_builtin_string_prototype_object_concat, NON_FIXED, 1)
ROUTINE (ECMA_MAGIC_STRING_SLICE, ecma_builtin_string_prototype_object_slice, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_INDEX_OF_UL, ecma_builtin_string_prototype_object_index_of, 2, 1)
ROUTINE (ECMA_MAGIC_STRING_LAST_INDEX_OF_UL, ecma_builtin_string_prototype_object_last_index_of, 2, 1)
ROUTINE (ECMA_MAGIC_STRING_CHAR_AT_UL, ecma_builtin_string_prototype_object_char_at, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_CHAR_CODE_AT_UL, ecma_builtin_string_prototype_object_char_code_at, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_LOCALE_COMPARE_UL, ecma_builtin_string_prototype_object_locale_compare, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_MATCH, ecma_builtin_string_prototype_object_match, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_REPLACE, ecma_builtin_string_prototype_object_replace, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_SEARCH, ecma_builtin_string_prototype_object_search, 1, 1)
ROUTINE (ECMA_MAGIC_STRING_SPLIT, ecma_builtin_string_prototype_object_split, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_SUBSTRING, ecma_builtin_string_prototype_object_substring, 2, 2)
ROUTINE (ECMA_MAGIC_STRING_TO_LOWER_CASE_UL, ecma_builtin_string_prototype_object_to_lower_case, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_TO_LOCALE_LOWER_CASE_UL, ecma_builtin_string_prototype_object_to_locale_lower_case, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_TO_UPPER_CASE_UL, ecma_builtin_string_prototype_object_to_upper_case, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_TO_LOCALE_UPPER_CASE_UL, ecma_builtin_string_prototype_object_to_locale_upper_case, 0, 0)
ROUTINE (ECMA_MAGIC_STRING_TRIM, ecma_builtin_string_prototype_object_trim, 0, 0)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,158 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-string.inc.h"
#define BUILTIN_UNDERSCORED_ID string
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup string ECMA String object built-in
* @{
*/
/**
* The String object's 'fromCharCode' routine
*
* See also:
* ECMA-262 v5, 15.5.3.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_string_object_from_char_code (const ecma_value_t& this_arg __attr_unused___, /**< 'this' argument */
const ecma_value_t args[], /**< arguments list */
ecma_length_t args_number) /**< number of arguments */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
size_t zt_str_buffer_size = sizeof (ecma_char_t) * (args_number + 1u);
ecma_char_t *ret_zt_str_p = (ecma_char_t*) mem_heap_alloc_block (zt_str_buffer_size,
MEM_HEAP_ALLOC_SHORT_TERM);
ret_zt_str_p [args_number] = ECMA_CHAR_NULL;
for (ecma_length_t arg_index = 0;
arg_index < args_number;
arg_index++)
{
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
uint32_t uint32_char_code = ecma_number_to_uint32 (arg_num);
uint16_t uint16_char_code = (uint16_t) uint32_char_code;
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII
if ((uint16_char_code >> JERRY_BITSINBYTE) != 0)
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
ret_zt_str_p [arg_index] = (ecma_char_t) uint16_char_code;
}
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16
ret_zt_str_p [arg_index] = (ecma_char_t) uint16_char_code;
#endif /* CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 */
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
if (ecma_is_completion_value_throw (ret_value))
{
mem_heap_free_block (ret_zt_str_p);
return ret_value;
}
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
}
ecma_string_t *ret_str_p = ecma_new_ecma_string (ret_zt_str_p);
mem_heap_free_block (ret_zt_str_p);
return ecma_make_normal_completion_value (ecma_make_string_value (ret_str_p));
} /* ecma_builtin_string_object_from_char_code */
/**
* Handle calling [[Call]] of built-in String object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_string_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
ecma_completion_value_t ret_value;
if (arguments_list_len == 0)
{
ecma_string_t *str_p = ecma_new_ecma_string_from_magic_string_id (ECMA_MAGIC_STRING__EMPTY);
ecma_value_t str_value = ecma_make_string_value (str_p);
ret_value = ecma_make_normal_completion_value (str_value);
}
else
{
ret_value = ecma_op_to_string (arguments_list_p [0]);
}
return ret_value;
} /* ecma_builtin_string_dispatch_call */
/**
* Handle calling [[Construct]] of built-in String object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_string_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
return ecma_op_create_string_object (arguments_list_p, arguments_list_len);
} /* ecma_builtin_string_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN */
@@ -0,0 +1,69 @@
/* Copyright 2014-2015 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.
*/
/*
* String built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
#ifndef ROUTINE
# define ROUTINE(name, c_function_name, args_number, length_prop_value)
#endif /* !ROUTINE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_STRING)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.5.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.7.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_STRING_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Routine properties:
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
ROUTINE (ECMA_MAGIC_STRING_FROM_CHAR_CODE_UL, ecma_builtin_string_object_from_char_code, NON_FIXED, 1)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,37 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-syntaxerror-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID syntax_error_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* SyntaxError.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.7.8
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_SYNTAX_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.9
STRING_VALUE (ECMA_MAGIC_STRING_NAME,
ECMA_MAGIC_STRING_SYNTAX_ERROR_UL,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.10
STRING_VALUE (ECMA_MAGIC_STRING_MESSAGE,
ECMA_MAGIC_STRING__EMPTY,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,101 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-syntaxerror.inc.h"
#define BUILTIN_UNDERSCORED_ID syntax_error
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup syntaxerror ECMA SyntaxError object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in SyntaxError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_syntax_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len != 0
&& !ecma_is_value_undefined (arguments_list_p [0]))
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (msg_str_value,
ecma_op_to_string (arguments_list_p[0]),
ret_value);
ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value);
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_SYNTAX,
message_string_p);
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
ECMA_FINALIZE (msg_str_value);
return ret_value;
}
else
{
ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_SYNTAX);
return ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
}
} /* ecma_builtin_syntax_error_dispatch_call */
/**
* Handle calling [[Construct]] of built-in SyntaxError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_syntax_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
return ecma_builtin_syntax_error_dispatch_call (arguments_list_p, arguments_list_len);
} /* ecma_builtin_syntax_error_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* SyntaxError built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_SYNTAX_ERROR)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.11.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,84 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-type-error-thrower.inc.h"
#define BUILTIN_UNDERSCORED_ID type_error_thrower
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup type_error_thrower ECMA [[ThrowTypeError]] object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in [[ThrowTypeError]] object
*
* See also:
* ECMA-262 v5, 13.2.3
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_type_error_thrower_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
/* The object should throw TypeError */
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
} /* ecma_builtin_type_error_thrower_dispatch_call */
/**
* Handle calling [[Construct]] of built-in [[ThrowTypeError]] object
*
* See also:
* ECMA-262 v5, 13.2.3
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_type_error_thrower_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
/* The object is not a constructor */
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
} /* ecma_builtin_type_error_thrower_dispatch_construct */
/**
* @}
* @}
* @}
*/
@@ -0,0 +1,48 @@
/* 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.
*/
/*
* [[ThrowTypeError]] description
*
* See also: ECMA-262 v5, 13.2.3
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
0,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,37 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typeerror-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID type_error_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* TypeError.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.7.8
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.9
STRING_VALUE (ECMA_MAGIC_STRING_NAME,
ECMA_MAGIC_STRING_TYPE_ERROR_UL,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.10
STRING_VALUE (ECMA_MAGIC_STRING_MESSAGE,
ECMA_MAGIC_STRING__EMPTY,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,101 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-typeerror.inc.h"
#define BUILTIN_UNDERSCORED_ID type_error
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup typeerror ECMA TypeError object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in TypeError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_type_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len != 0
&& !ecma_is_value_undefined (arguments_list_p [0]))
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (msg_str_value,
ecma_op_to_string (arguments_list_p[0]),
ret_value);
ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value);
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_TYPE,
message_string_p);
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
ECMA_FINALIZE (msg_str_value);
return ret_value;
}
else
{
ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_TYPE);
return ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
}
} /* ecma_builtin_type_error_dispatch_call */
/**
* Handle calling [[Construct]] of built-in TypeError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_type_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
return ecma_builtin_type_error_dispatch_call (arguments_list_p, arguments_list_len);
} /* ecma_builtin_type_error_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* TypeError built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_TYPE_ERROR)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.11.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,37 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-urierror-prototype.inc.h"
#define BUILTIN_UNDERSCORED_ID uri_error_prototype
#include "ecma-builtin-internal-routines-template.inc.h"
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* UriError.prototype built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.7.8
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
ecma_builtin_get (ECMA_BUILTIN_ID_URI_ERROR),
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.9
STRING_VALUE (ECMA_MAGIC_STRING_NAME,
ECMA_MAGIC_STRING_URI_ERROR_UL,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
// 15.11.7.10
STRING_VALUE (ECMA_MAGIC_STRING_MESSAGE,
ECMA_MAGIC_STRING__EMPTY,
ECMA_PROPERTY_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,101 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-urierror.inc.h"
#define BUILTIN_UNDERSCORED_ID uri_error
#include "ecma-builtin-internal-routines-template.inc.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*
* \addtogroup urierror ECMA UriError object built-in
* @{
*/
/**
* Handle calling [[Call]] of built-in UriError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_uri_error_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (arguments_list_len != 0
&& !ecma_is_value_undefined (arguments_list_p [0]))
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (msg_str_value,
ecma_op_to_string (arguments_list_p[0]),
ret_value);
ecma_string_t *message_string_p = ecma_get_string_from_value (msg_str_value);
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_URI,
message_string_p);
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
ECMA_FINALIZE (msg_str_value);
return ret_value;
}
else
{
ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_URI);
return ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
}
} /* ecma_builtin_uri_error_dispatch_call */
/**
* Handle calling [[Construct]] of built-in UriError object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_uri_error_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< number of arguments */
{
return ecma_builtin_uri_error_dispatch_call (arguments_list_p, arguments_list_len);
} /* ecma_builtin_uri_error_dispatch_construct */
/**
* @}
* @}
* @}
*/
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
@@ -0,0 +1,65 @@
/* Copyright 2014-2015 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.
*/
/*
* UriError built-in description
*/
#ifndef OBJECT_ID
# define OBJECT_ID(builtin_object_id)
#endif /* !OBJECT_ID */
#ifndef NUMBER_VALUE
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
#endif /* !NUMBER_VALUE */
#ifndef STRING_VALUE
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
#endif /* !STRING_VALUE */
#ifndef OBJECT_VALUE
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
#endif /* !OBJECT_VALUE */
/* Object identifier */
OBJECT_ID (ECMA_BUILTIN_ID_URI_ERROR)
/* Number properties:
* (property name, number value, writable, enumerable, configurable) */
// 15.11.3
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
1,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
/* Object properties:
* (property name, object pointer getter) */
// 15.11.3.1
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
ecma_builtin_get (ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE),
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE)
#undef OBJECT_ID
#undef SIMPLE_VALUE
#undef NUMBER_VALUE
#undef STRING_VALUE
#undef OBJECT_VALUE
#undef CP_UNIMPLEMENTED_VALUE
#undef ROUTINE
@@ -0,0 +1,98 @@
/* Copyright 2014-2015 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-builtins.h"
#include "ecma-globals.h"
/**
* Position of built-in object's id field in [[Built-in routine ID]] internal property
*/
#define ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_POS (0)
/**
* Width of built-in object's id field in [[Built-in routine ID]] internal property
*/
#define ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_WIDTH (16)
/**
* Position of built-in routine's id field in [[Built-in routine ID]] internal property
*/
#define ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_POS \
(ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_POS + \
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_WIDTH)
/**
* Width of built-in routine's id field in [[Built-in routine ID]] internal property
*/
#define ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_WIDTH (16)
/* ecma-builtins.c */
extern ecma_object_t*
ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id,
ecma_magic_string_id_t routine_id,
ecma_number_t length_prop_num_value);
extern int32_t
ecma_builtin_bin_search_for_magic_string_id_in_array (const ecma_magic_string_id_t ids[],
ecma_length_t array_length,
ecma_magic_string_id_t key);
#define BUILTIN(builtin_id, \
object_type, \
object_class, \
object_prototype_builtin_id, \
is_extensible, \
lowercase_name) \
extern ecma_completion_value_t \
ecma_builtin_ ## lowercase_name ## _dispatch_call (const ecma_value_t *arguments_list_p, \
ecma_length_t arguments_list_len); \
extern ecma_completion_value_t \
ecma_builtin_ ## lowercase_name ## _dispatch_construct (const ecma_value_t *arguments_list_p, \
ecma_length_t arguments_list_len); \
extern ecma_completion_value_t \
ecma_builtin_ ## lowercase_name ## _dispatch_routine (ecma_magic_string_id_t builtin_routine_id, \
const ecma_value_t& this_arg_value, \
const ecma_value_t arguments_list [], \
ecma_length_t arguments_number); \
extern ecma_property_t* \
ecma_builtin_ ## lowercase_name ## _try_to_instantiate_property (ecma_object_t *obj_p, \
ecma_string_t *prop_name_p); \
extern void \
ecma_builtin_ ## lowercase_name ## _sort_property_names (void);
#include "ecma-builtins.inc.h"
#ifndef CONFIG_ECMA_COMPACT_PROFILE
# define ECMA_BUILTIN_CP_UNIMPLEMENTED(...) \
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("Built-in is not implemented.", __VA_ARGS__)
#else /* !CONFIG_ECMA_COMPACT_PROFILE */
# define ECMA_BUILTIN_CP_UNIMPLEMENTED(...) \
{ \
if (false) \
{ \
jerry_ref_unused_variables (0, __VA_ARGS__); \
} \
ecma_object_t *cp_error_p = ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR); \
return ecma_make_throw_obj_completion_value (cp_error_p); \
}
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
#endif /* !ECMA_BUILTINS_INTERNAL_H */
@@ -0,0 +1,610 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "jrt-bit-fields.h"
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabuiltins
* @{
*/
static ecma_completion_value_t
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id,
ecma_magic_string_id_t builtin_routine_id,
const ecma_value_t& this_arg_value,
const ecma_value_t arguments_list [],
ecma_length_t arguments_number);
static void ecma_instantiate_builtin (ecma_builtin_id_t id);
/**
* Pointer to instances of built-in objects
*/
static ecma_object_t* ecma_builtin_objects [ECMA_BUILTIN_ID__COUNT];
/**
* Check if passed object is the instance of specified built-in.
*/
bool
ecma_builtin_is (ecma_object_t *obj_p, /**< pointer to an object */
ecma_builtin_id_t builtin_id) /**< id of built-in to check on */
{
JERRY_ASSERT (obj_p != NULL && !ecma_is_lexical_environment (obj_p));
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
if (unlikely (ecma_builtin_objects [builtin_id] == NULL))
{
ecma_instantiate_builtin (builtin_id);
}
return (obj_p == ecma_builtin_objects [builtin_id]);
} /* ecma_builtin_is */
/**
* Get reference to specified built-in object
*
* @return pointer to the object's instance
*/
ecma_object_t*
ecma_builtin_get (ecma_builtin_id_t builtin_id) /**< id of built-in to check on */
{
JERRY_ASSERT (builtin_id < ECMA_BUILTIN_ID__COUNT);
if (unlikely (ecma_builtin_objects [builtin_id] == NULL))
{
ecma_instantiate_builtin (builtin_id);
}
ecma_ref_object (ecma_builtin_objects [builtin_id]);
return ecma_builtin_objects [builtin_id];
} /* ecma_builtin_get */
/**
* Initialize specified built-in object.
*
* Warning:
* the routine should be called only from ecma_init_builtins
*
* @return pointer to the object
*/
static ecma_object_t*
ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */
ecma_object_t* prototype_obj_p, /**< prototype object */
ecma_object_type_t obj_type, /**< object's type */
ecma_magic_string_id_t obj_class, /**< object's class */
bool is_extensible) /**< value of object's [[Extensible]] property */
{
ecma_object_t *object_obj_p = ecma_create_object (prototype_obj_p, is_extensible, obj_type);
ecma_property_t *class_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_CLASS);
class_prop_p->u.internal_property.value = obj_class;
ecma_property_t *built_in_id_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
built_in_id_prop_p->u.internal_property.value = obj_builtin_id;
ecma_set_object_is_builtin (object_obj_p, true);
/** Initializing [[PrimitiveValue]] properties of built-in prototype objects */
switch (obj_builtin_id)
{
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
case ECMA_BUILTIN_ID_STRING_PROTOTYPE:
{
ecma_string_t *prim_prop_str_value_p = ecma_get_magic_string (ECMA_MAGIC_STRING__EMPTY);
ecma_property_t *prim_value_prop_p;
prim_value_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE);
ECMA_SET_POINTER (prim_value_prop_p->u.internal_property.value, prim_prop_str_value_p);
break;
}
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN
case ECMA_BUILTIN_ID_NUMBER_PROTOTYPE:
{
ecma_number_t *prim_prop_num_value_p = ecma_alloc_number ();
*prim_prop_num_value_p = ECMA_NUMBER_ZERO;
ecma_property_t *prim_value_prop_p;
prim_value_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
ECMA_SET_POINTER (prim_value_prop_p->u.internal_property.value, prim_prop_num_value_p);
break;
}
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
case ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE:
{
ecma_property_t *prim_value_prop_p;
prim_value_prop_p = ecma_create_internal_property (object_obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE);
prim_value_prop_p->u.internal_property.value = ECMA_SIMPLE_VALUE_FALSE;
break;
}
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
default:
{
break;
}
}
return object_obj_p;
} /* ecma_builtin_init_object */
/**
* Initialize ECMA built-ins components
*/
void
ecma_init_builtins (void)
{
for (ecma_builtin_id_t id = (ecma_builtin_id_t) 0;
id < ECMA_BUILTIN_ID__COUNT;
id = (ecma_builtin_id_t) (id + 1))
{
ecma_builtin_objects [id] = NULL;
}
} /* ecma_init_builtins */
/**
* Instantiate specified ECMA built-in object
*/
static void
ecma_instantiate_builtin (ecma_builtin_id_t id) /**< built-in id */
{
switch (id)
{
#define BUILTIN(builtin_id, \
object_type, \
object_class, \
object_prototype_builtin_id, \
is_extensible, \
lowercase_name) \
case builtin_id: \
{ \
JERRY_ASSERT (ecma_builtin_objects [builtin_id] == NULL); \
ecma_builtin_ ## lowercase_name ## _sort_property_names (); \
\
ecma_object_t *prototype_obj_p; \
if (object_prototype_builtin_id == ECMA_BUILTIN_ID__COUNT) \
{ \
prototype_obj_p = NULL; \
} \
else \
{ \
if (ecma_builtin_objects [object_prototype_builtin_id] == NULL) \
{ \
ecma_instantiate_builtin (object_prototype_builtin_id); \
} \
prototype_obj_p = ecma_builtin_objects [object_prototype_builtin_id]; \
JERRY_ASSERT (prototype_obj_p != NULL); \
} \
\
ecma_object_t *builtin_obj_p = ecma_builtin_init_object (builtin_id, \
prototype_obj_p, \
object_type, \
object_class, \
is_extensible); \
ecma_builtin_objects [builtin_id] = builtin_obj_p; \
\
break; \
}
#include "ecma-builtins.inc.h"
default:
{
JERRY_ASSERT (id < ECMA_BUILTIN_ID__COUNT);
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
}
}
} /* ecma_instantiate_builtin */
/**
* Finalize ECMA built-in objects
*/
void
ecma_finalize_builtins (void)
{
for (ecma_builtin_id_t id = (ecma_builtin_id_t) 0;
id < ECMA_BUILTIN_ID__COUNT;
id = (ecma_builtin_id_t) (id + 1))
{
if (ecma_builtin_objects [id] != NULL)
{
ecma_deref_object (ecma_builtin_objects [id]);
ecma_builtin_objects [id] = NULL;
}
}
} /* 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
* return pointer to the instantiated property.
*
* @return pointer property, if one was instantiated,
* NULL - otherwise.
*/
ecma_property_t*
ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object */
ecma_string_t *string_p) /**< property's name */
{
JERRY_ASSERT (ecma_get_object_is_builtin (object_p));
ecma_property_t *built_in_id_prop_p = ecma_get_internal_property (object_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_id_prop_p->u.internal_property.value;
JERRY_ASSERT (ecma_builtin_is (object_p, builtin_id));
switch (builtin_id)
{
#define BUILTIN(builtin_id, \
object_type, \
object_class, \
object_prototype_builtin_id, \
is_extensible, \
lowercase_name) \
case builtin_id: \
{ \
return ecma_builtin_ ## lowercase_name ## _try_to_instantiate_property (object_p, \
string_p); \
}
#include "ecma-builtins.inc.h"
case ECMA_BUILTIN_ID__COUNT:
{
JERRY_UNREACHABLE ();
}
default:
{
#ifdef CONFIG_ECMA_COMPACT_PROFILE
JERRY_UNREACHABLE ();
#else /* CONFIG_ECMA_COMPACT_PROFILE */
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
#endif /* !CONFIG_ECMA_COMPACT_PROFILE */
}
}
JERRY_UNREACHABLE ();
} /* ecma_builtin_try_to_instantiate_property */
/**
* Construct a Function object for specified built-in routine
*
* See also: ECMA-262 v5, 15
*
* @return pointer to constructed Function object
*/
ecma_object_t*
ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**< identifier of built-in object
that initially contains property
with the routine */
ecma_magic_string_id_t routine_id, /**< name of the built-in
object's routine property */
ecma_number_t length_prop_num_value) /**< ecma-number - value
of 'length' property
of function object to create */
{
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
ecma_object_t *func_obj_p = ecma_create_object (prototype_obj_p, true, ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION);
ecma_deref_object (prototype_obj_p);
ecma_set_object_is_builtin (func_obj_p, true);
uint64_t packed_value = jrt_set_bit_field_value (0,
builtin_id,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_POS,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_WIDTH);
packed_value = jrt_set_bit_field_value (packed_value,
routine_id,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_POS,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_WIDTH);
ecma_property_t *routine_id_prop_p = ecma_create_internal_property (func_obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_ID);
JERRY_ASSERT ((uint32_t) packed_value == packed_value);
routine_id_prop_p->u.internal_property.value = (uint32_t) packed_value;
ecma_string_t* magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
ecma_property_t *len_prop_p = ecma_create_named_data_property (func_obj_p,
magic_string_length_p,
false, false, false);
ecma_deref_ecma_string (magic_string_length_p);
ecma_number_t* len_p = ecma_alloc_number ();
*len_p = length_prop_num_value;
ecma_set_named_data_property_value (len_prop_p, ecma_make_number_value (len_p));
return func_obj_p;
} /* ecma_builtin_make_function_object_for_routine */
/**
* Handle calling [[Call]] of built-in object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
const ecma_value_t& this_arg_value, /**< 'this' argument value */
const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< length of the arguments list */
{
JERRY_ASSERT (ecma_get_object_is_builtin (obj_p));
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION)
{
ecma_property_t *id_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_ID);
uint64_t packed_built_in_and_routine_id = id_prop_p->u.internal_property.value;
uint64_t built_in_id_field = jrt_extract_bit_field (packed_built_in_and_routine_id,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_POS,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_OBJECT_ID_WIDTH);
JERRY_ASSERT (built_in_id_field < ECMA_BUILTIN_ID__COUNT);
uint64_t routine_id_field = jrt_extract_bit_field (packed_built_in_and_routine_id,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_POS,
ECMA_BUILTIN_ROUTINE_ID_BUILT_IN_ROUTINE_ID_WIDTH);
JERRY_ASSERT (routine_id_field < ECMA_MAGIC_STRING__COUNT);
ecma_builtin_id_t built_in_id = (ecma_builtin_id_t) built_in_id_field;
ecma_magic_string_id_t routine_id = (ecma_magic_string_id_t) routine_id_field;
return ecma_builtin_dispatch_routine (built_in_id,
routine_id,
this_arg_value,
arguments_list_p,
arguments_list_len);
}
else
{
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
ecma_property_t *built_in_id_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_id_prop_p->u.internal_property.value;
JERRY_ASSERT (ecma_builtin_is (obj_p, builtin_id));
switch (builtin_id)
{
#define BUILTIN(builtin_id, \
object_type, \
object_class, \
object_prototype_builtin_id, \
is_extensible, \
lowercase_name) \
case builtin_id: \
{ \
if (object_type == ECMA_OBJECT_TYPE_FUNCTION) \
{ \
return ecma_builtin_ ## lowercase_name ## _dispatch_call (arguments_list_p, \
arguments_list_len); \
} \
else \
{ \
JERRY_UNREACHABLE (); \
} \
}
#include "ecma-builtins.inc.h"
case ECMA_BUILTIN_ID__COUNT:
{
JERRY_UNREACHABLE ();
}
default:
{
#ifdef CONFIG_ECMA_COMPACT_PROFILE
JERRY_UNREACHABLE ();
#else /* CONFIG_ECMA_COMPACT_PROFILE */
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
#endif /* !CONFIG_ECMA_COMPACT_PROFILE */
}
}
}
JERRY_UNREACHABLE ();
} /* ecma_builtin_dispatch_call */
/**
* Handle calling [[Construct]] of built-in object
*
* @return completion-value
*/
ecma_completion_value_t
ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< length of the arguments list */
{
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
JERRY_ASSERT (ecma_get_object_is_builtin (obj_p));
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
ecma_property_t *built_in_id_prop_p = ecma_get_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
ecma_builtin_id_t builtin_id = (ecma_builtin_id_t) built_in_id_prop_p->u.internal_property.value;
JERRY_ASSERT (ecma_builtin_is (obj_p, builtin_id));
switch (builtin_id)
{
#define BUILTIN(builtin_id, \
object_type, \
object_class, \
object_prototype_builtin_id, \
is_extensible, \
lowercase_name) \
case builtin_id: \
{ \
if (object_type == ECMA_OBJECT_TYPE_FUNCTION) \
{ \
return ecma_builtin_ ## lowercase_name ## _dispatch_construct (arguments_list_p, \
arguments_list_len); \
} \
else \
{ \
JERRY_UNREACHABLE (); \
} \
}
#include "ecma-builtins.inc.h"
case ECMA_BUILTIN_ID__COUNT:
{
JERRY_UNREACHABLE ();
}
default:
{
#ifdef CONFIG_ECMA_COMPACT_PROFILE
JERRY_UNREACHABLE ();
#else /* CONFIG_ECMA_COMPACT_PROFILE */
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
#endif /* !CONFIG_ECMA_COMPACT_PROFILE */
}
}
JERRY_UNREACHABLE ();
} /* ecma_builtin_dispatch_construct */
/**
* Dispatcher of built-in routines
*
* @return completion-value
* Returned value must be freed with ecma_free_completion_value.
*/
static ecma_completion_value_t
ecma_builtin_dispatch_routine (ecma_builtin_id_t builtin_object_id, /**< built-in object' identifier */
ecma_magic_string_id_t builtin_routine_id, /**< name of the built-in object's
routine property */
const ecma_value_t& this_arg_value, /**< 'this' argument value */
const ecma_value_t arguments_list [], /**< list of arguments passed to routine */
ecma_length_t arguments_number) /**< length of arguments' list */
{
switch (builtin_object_id)
{
#define BUILTIN(builtin_id, \
object_type, \
object_class, \
object_prototype_builtin_id, \
is_extensible, \
lowercase_name) \
case builtin_id: \
{ \
return ecma_builtin_ ## lowercase_name ## _dispatch_routine (builtin_routine_id, \
this_arg_value, \
arguments_list, \
arguments_number); \
}
#include "ecma-builtins.inc.h"
case ECMA_BUILTIN_ID__COUNT:
{
JERRY_UNREACHABLE ();
}
default:
{
#ifdef CONFIG_ECMA_COMPACT_PROFILE
JERRY_UNREACHABLE ();
#else /* CONFIG_ECMA_COMPACT_PROFILE */
JERRY_UNIMPLEMENTED ("The built-in is not implemented.");
#endif /* !CONFIG_ECMA_COMPACT_PROFILE */
}
}
JERRY_UNREACHABLE ();
} /* ecma_builtin_dispatch_routine */
/**
* Binary search for magic string identifier in array.
*
* Warning:
* array should be sorted in ascending order
*
* @return index of identifier, if it is contained in array,
* -1 - otherwise.
*/
int32_t
ecma_builtin_bin_search_for_magic_string_id_in_array (const ecma_magic_string_id_t ids[], /**< array to search in */
ecma_length_t array_length, /**< number of elements
in the array */
ecma_magic_string_id_t key) /**< value to search for */
{
#ifndef JERRY_NDEBUG
/* For binary search the values should be sorted */
for (ecma_length_t id_index = 1;
id_index < array_length;
id_index++)
{
JERRY_ASSERT (ids [id_index - 1] < ids [id_index]);
}
#endif /* !JERRY_NDEBUG */
int32_t min = 0;
int32_t max = array_length - 1;
while (min <= max)
{
int32_t mid = (min + max) / 2;
if (ids[mid] == key)
{
return mid;
}
else if (ids[mid] > key)
{
max = mid - 1;
}
else
{
JERRY_ASSERT (ids[mid] < key);
min = mid + 1;
}
}
return -1;
} /* ecma_builtin_bin_search_for_magic_string_id_in_array */
/**
* @}
* @}
*/
@@ -0,0 +1,58 @@
/* Copyright 2014-2015 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"
/**
* A built-in object's identifier
*/
typedef enum
{
#define BUILTIN(builtin_id, \
object_type, \
object_class, \
object_prototype_builtin_id, \
is_extensible, \
lowercase_name) \
builtin_id,
#include "ecma-builtins.inc.h"
ECMA_BUILTIN_ID__COUNT /**< number of built-in objects */
} ecma_builtin_id_t;
/* ecma-builtins.c */
extern void ecma_init_builtins (void);
extern void ecma_finalize_builtins (void);
extern ecma_completion_value_t
ecma_builtin_dispatch_call (ecma_object_t *obj_p,
const ecma_value_t& this_arg,
const ecma_value_t *arguments_list_p,
ecma_length_t arguments_list_len);
extern ecma_completion_value_t
ecma_builtin_dispatch_construct (ecma_object_t *obj_p,
const ecma_value_t *arguments_list_p,
ecma_length_t arguments_list_len);
extern ecma_property_t*
ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p,
ecma_string_t *string_p);
extern bool
ecma_builtin_is (ecma_object_t *obj_p,
ecma_builtin_id_t builtin_id);
extern ecma_object_t*
ecma_builtin_get (ecma_builtin_id_t builtin_id);
#endif /* !ECMA_BUILTINS_H */
@@ -0,0 +1,273 @@
/* 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.
*/
/* Description of built-in objects
in format (ECMA_BUILTIN_ID_id, object_type, class_magic_string_id, prototype_id, is_extensible, underscored_id) */
/* The Object.prototype object (15.2.4) */
BUILTIN (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_OBJECT_UL,
ECMA_BUILTIN_ID__COUNT /* no prototype */,
true,
object_prototype)
/* The Object object (15.2.1) */
BUILTIN (ECMA_BUILTIN_ID_OBJECT,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_OBJECT_UL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
object)
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
/* The Array.prototype object (15.4.4) */
BUILTIN (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_ARRAY,
ECMA_MAGIC_STRING_ARRAY_UL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
array_prototype)
/* The Array object (15.4.1) */
BUILTIN (ECMA_BUILTIN_ID_ARRAY,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_ARRAY_UL,
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
true,
array)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN*/
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN
/* The String.prototype object (15.5.4) */
BUILTIN (ECMA_BUILTIN_ID_STRING_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_STRING_UL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
string_prototype)
/* The String object (15.5.1) */
BUILTIN (ECMA_BUILTIN_ID_STRING,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_STRING_UL,
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
true,
string)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_STRING_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
/* The Boolean.prototype object (15.6.4) */
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_BOOLEAN_UL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
boolean_prototype)
/* The Boolean object (15.6.1) */
BUILTIN (ECMA_BUILTIN_ID_BOOLEAN,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_BOOLEAN_UL,
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
true,
boolean)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN
/* The Number.prototype object (15.7.4) */
BUILTIN (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_NUMBER_UL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
number_prototype)
/* The Number object (15.7.1) */
BUILTIN (ECMA_BUILTIN_ID_NUMBER,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_NUMBER_UL,
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
true,
number)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_NUMBER_BUILTIN */
/* The Function.prototype object (15.3.4) */
BUILTIN (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_FUNCTION_UL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
function_prototype)
/* The Function object (15.3.1) */
BUILTIN (ECMA_BUILTIN_ID_FUNCTION,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_FUNCTION_UL,
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
true,
function)
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_MATH_BUILTIN
/* The Math object (15.8) */
BUILTIN (ECMA_BUILTIN_ID_MATH,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_MATH_UL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
math)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_MATH_BUILTIN */
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
/* The Error.prototype object (15.11.4) */
BUILTIN (ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
true,
error_prototype)
/* The Error object (15.11.1) */
BUILTIN (ECMA_BUILTIN_ID_ERROR,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
true,
error)
/* The EvalError.prototype object (15.11.6.1) */
BUILTIN (ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
true,
eval_error_prototype)
/* The EvalError object (15.11.6.1) */
BUILTIN (ECMA_BUILTIN_ID_EVAL_ERROR,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE,
true,
eval_error)
/* The RangeError.prototype object (15.11.6.2) */
BUILTIN (ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
true,
range_error_prototype)
/* The RangeError object (15.11.6.2) */
BUILTIN (ECMA_BUILTIN_ID_RANGE_ERROR,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE,
true,
range_error)
/* The ReferenceError.prototype object (15.11.6.3) */
BUILTIN (ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
true,
reference_error_prototype)
/* The ReferenceError object (15.11.6.3) */
BUILTIN (ECMA_BUILTIN_ID_REFERENCE_ERROR,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE,
true,
reference_error)
/* The SyntaxError.prototype object (15.11.6.4) */
BUILTIN (ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
true,
syntax_error_prototype)
/* The SyntaxError object (15.11.6.4) */
BUILTIN (ECMA_BUILTIN_ID_SYNTAX_ERROR,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE,
true,
syntax_error)
/* The TypeError.prototype object (15.11.6.5) */
BUILTIN (ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
true,
type_error_prototype)
/* The TypeError object (15.11.6.5) */
BUILTIN (ECMA_BUILTIN_ID_TYPE_ERROR,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE,
true,
type_error)
/* The URIError.prototype object (15.11.6.6) */
BUILTIN (ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_ERROR_PROTOTYPE,
true,
uri_error_prototype)
/* The URIError object (15.11.6.6) */
BUILTIN (ECMA_BUILTIN_ID_URI_ERROR,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_ERROR_UL,
ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE,
true,
uri_error)
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
/**< The [[ThrowTypeError]] object (13.2.3) */
BUILTIN (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_FUNCTION_UL,
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
false,
type_error_thrower)
#ifdef CONFIG_ECMA_COMPACT_PROFILE
/* The CompactProfileError object defined in the Compact Profile */
BUILTIN (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR,
ECMA_OBJECT_TYPE_FUNCTION,
ECMA_MAGIC_STRING_COMPACT_PROFILE_ERROR_UL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
false,
compact_profile_error)
#endif /* CONFIG_ECMA_COMPACT_PROFILE */
/* The Global object (15.1) */
BUILTIN (ECMA_BUILTIN_ID_GLOBAL,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_MAGIC_STRING_OBJECT_UL,
ECMA_BUILTIN_ID__COUNT /* no prototype */,
true,
global)
#undef BUILTIN
@@ -0,0 +1,462 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-array-object.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-number-arithmetic.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaarrayobject ECMA Array object related routines
* @{
*/
/**
* Reject sequence
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
static ecma_completion_value_t
ecma_reject (bool is_throw) /**< Throw flag */
{
if (is_throw)
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
}
} /* ecma_reject */
/**
* Array object creation operation.
*
* See also: ECMA-262 v5, 15.4.2.1
* ECMA-262 v5, 15.4.2.2
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_create_array_object (const ecma_value_t *arguments_list_p, /**< list of arguments that
are passed to Array constructor */
ecma_length_t arguments_list_len, /**< length of the arguments' list */
bool is_treat_single_arg_as_length) /**< if the value is true,
arguments_list_len is 1
and single argument is Number,
then treat the single argument
as new Array's length rather
than as single item of the Array */
{
JERRY_ASSERT (arguments_list_len == 0
|| arguments_list_p != NULL);
uint32_t length;
const ecma_value_t *array_items_p;
ecma_length_t array_items_count;
if (is_treat_single_arg_as_length
&& arguments_list_len == 1
&& ecma_is_value_number (arguments_list_p[0]))
{
ecma_number_t *num_p = ecma_get_number_from_value (arguments_list_p[0]);
uint32_t num_uint32 = ecma_number_to_uint32 (*num_p);
if (*num_p != ecma_uint32_to_number (num_uint32))
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_RANGE));
}
else
{
length = num_uint32;
array_items_p = NULL;
array_items_count = 0;
}
}
else
{
length = arguments_list_len;
array_items_p = arguments_list_p;
array_items_count = arguments_list_len;
}
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN
ecma_object_t *array_prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAY_PROTOTYPE);
#else /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN */
ecma_object_t *array_prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ARRAY_BUILTIN */
ecma_object_t *obj_p = ecma_create_object (array_prototype_obj_p, true, ECMA_OBJECT_TYPE_ARRAY);
ecma_deref_object (array_prototype_obj_p);
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_ARRAY_UL;
ecma_string_t *length_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
ecma_number_t *length_num_p = ecma_alloc_number ();
*length_num_p = ecma_uint32_to_number (length);
ecma_property_t *length_prop_p = ecma_create_named_data_property (obj_p,
length_magic_string_p,
true, false, false);
ecma_set_named_data_property_value (length_prop_p, ecma_make_number_value (length_num_p));
ecma_deref_ecma_string (length_magic_string_p);
for (uint32_t index = 0;
index < array_items_count;
index++)
{
ecma_string_t* item_name_string_p = ecma_new_ecma_string_from_uint32 (index);
ecma_property_descriptor_t item_prop_desc = ecma_make_empty_property_descriptor ();
{
item_prop_desc.is_value_defined = true;
item_prop_desc.value = array_items_p [index];
item_prop_desc.is_writable_defined = true;
item_prop_desc.is_writable = true;
item_prop_desc.is_enumerable_defined = true;
item_prop_desc.is_enumerable = true;
item_prop_desc.is_configurable_defined = true;
item_prop_desc.is_configurable = true;
}
ecma_op_object_define_own_property (obj_p,
item_name_string_p,
&item_prop_desc,
false);
ecma_deref_ecma_string (item_name_string_p);
}
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
} /* ecma_op_create_array_object */
/**
* [[DefineOwnProperty]] ecma array object's operation
*
* See also:
* ECMA-262 v5, 8.6.2; ECMA-262 v5, Table 8
* ECMA-262 v5, 15.4.5.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_array_object_define_own_property (ecma_object_t *obj_p, /**< the array object */
ecma_string_t *property_name_p, /**< property name */
const ecma_property_descriptor_t* property_desc_p, /**< property descriptor */
bool is_throw) /**< flag that controls failure handling */
{
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY);
// 1.
ecma_string_t* magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
ecma_property_t *len_prop_p = ecma_op_object_get_own_property (obj_p, magic_string_length_p);
JERRY_ASSERT (len_prop_p != NULL && len_prop_p->type == ECMA_PROPERTY_NAMEDDATA);
// 2.
ecma_value_t old_len_value = ecma_get_named_data_property_value (len_prop_p);
ecma_number_t *num_p = ecma_get_number_from_value (old_len_value);
uint32_t old_len_uint32 = ecma_number_to_uint32 (*num_p);
// 3.
bool is_property_name_equal_length = ecma_compare_ecma_strings (property_name_p,
magic_string_length_p);
ecma_deref_ecma_string (magic_string_length_p);
if (is_property_name_equal_length)
{
// a.
if (!property_desc_p->is_value_defined)
{
// i.
return ecma_op_general_object_define_own_property (obj_p, property_name_p, property_desc_p, is_throw);
}
ecma_number_t new_len_num;
// c.
ecma_completion_value_t completion = ecma_op_to_number (property_desc_p->value);
if (ecma_is_completion_value_throw (completion))
{
return completion;
}
JERRY_ASSERT (ecma_is_completion_value_normal (completion)
&& ecma_is_value_number (ecma_get_completion_value_value (completion)));
new_len_num = *ecma_get_number_from_completion_value (completion);
ecma_free_completion_value (completion);
uint32_t new_len_uint32 = ecma_number_to_uint32 (new_len_num);
// d.
if (ecma_uint32_to_number (new_len_uint32) != new_len_num)
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_RANGE));
}
else
{
// b., e.
ecma_number_t *new_len_num_p = ecma_alloc_number ();
*new_len_num_p = new_len_num;
ecma_property_descriptor_t new_len_property_desc = *property_desc_p;
new_len_property_desc.value = ecma_make_number_value (new_len_num_p);
ecma_completion_value_t ret_value;
// f.
if (new_len_uint32 >= old_len_uint32)
{
// i.
magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
ret_value = ecma_op_general_object_define_own_property (obj_p,
magic_string_length_p,
&new_len_property_desc,
is_throw);
ecma_deref_ecma_string (magic_string_length_p);
}
else
{
// g.
if (!ecma_is_property_writable (len_prop_p))
{
ret_value = ecma_reject (is_throw);
}
else
{
// h.
bool new_writable;
if (!new_len_property_desc.is_writable_defined
|| new_len_property_desc.is_writable)
{
new_writable = true;
}
else
{
// ii.
new_writable = false;
// iii.
new_len_property_desc.is_writable_defined = true;
new_len_property_desc.is_writable = true;
}
// j.
magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
ecma_completion_value_t succeeded = ecma_op_general_object_define_own_property (obj_p,
magic_string_length_p,
&new_len_property_desc,
is_throw);
ecma_deref_ecma_string (magic_string_length_p);
/* Handling normal false and throw values */
if (!ecma_is_completion_value_normal_true (succeeded))
{
JERRY_ASSERT (ecma_is_completion_value_normal_false (succeeded)
|| ecma_is_completion_value_throw (succeeded));
// k.
ret_value = succeeded;
}
else
{
// l
JERRY_ASSERT (new_len_uint32 < old_len_uint32);
bool reduce_succeeded = true;
while (new_len_uint32 < old_len_uint32)
{
// i
old_len_uint32--;
// ii
ecma_string_t *old_length_string_p = ecma_new_ecma_string_from_uint32 (old_len_uint32);
ecma_completion_value_t delete_succeeded = ecma_op_object_delete (obj_p,
old_length_string_p,
false);
ecma_deref_ecma_string (old_length_string_p);
// iii
if (ecma_is_completion_value_normal_false (delete_succeeded))
{
JERRY_ASSERT (ecma_is_value_number (new_len_property_desc.value));
ecma_number_t *new_len_num_p = ecma_get_number_from_value (new_len_property_desc.value);
// 1.
*new_len_num_p = ecma_uint32_to_number (old_len_uint32 + 1);
// 2.
if (!new_writable)
{
new_len_property_desc.is_writable_defined = true;
new_len_property_desc.is_writable = false;
}
// 3.
ecma_string_t *magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
ecma_completion_value_t completion = ecma_op_general_object_define_own_property (obj_p,
magic_string_length_p,
&new_len_property_desc,
false);
ecma_deref_ecma_string (magic_string_length_p);
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)
|| ecma_is_completion_value_normal_false (completion));
reduce_succeeded = false;
break;
}
}
if (!reduce_succeeded)
{
ret_value = ecma_reject (is_throw);
}
else
{
// m.
if (!new_writable)
{
ecma_property_descriptor_t prop_desc_not_writable = ecma_make_empty_property_descriptor ();
prop_desc_not_writable.is_writable_defined = true;
prop_desc_not_writable.is_writable = false;
ecma_completion_value_t completion_set_not_writable;
magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
completion_set_not_writable = ecma_op_general_object_define_own_property (obj_p,
magic_string_length_p,
&prop_desc_not_writable,
false);
ecma_deref_ecma_string (magic_string_length_p);
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion_set_not_writable));
}
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
}
}
}
}
ecma_dealloc_number (new_len_num_p);
return ret_value;
}
JERRY_UNREACHABLE();
}
else
{
// 4.a.
uint32_t index;
bool is_index;
if (property_name_p->container == ECMA_STRING_CONTAINER_UINT32_IN_DESC)
{
index = property_name_p->u.uint32_number;
is_index = true;
}
else
{
ecma_number_t number = ecma_string_to_number (property_name_p);
index = ecma_number_to_uint32 (number);
ecma_string_t *to_uint32_to_string_p = ecma_new_ecma_string_from_uint32 (index);
is_index = ecma_compare_ecma_strings (property_name_p,
to_uint32_to_string_p);
ecma_deref_ecma_string (to_uint32_to_string_p);
}
is_index = is_index && (index != ECMA_MAX_VALUE_OF_VALID_ARRAY_INDEX);
if (!is_index)
{
// 5.
return ecma_op_general_object_define_own_property (obj_p,
property_name_p,
property_desc_p,
false);
}
// 4.
// b.
if (index >= old_len_uint32
&& !ecma_is_property_writable (len_prop_p))
{
return ecma_reject (is_throw);
}
// c.
ecma_completion_value_t succeeded = ecma_op_general_object_define_own_property (obj_p,
property_name_p,
property_desc_p,
false);
// d.
JERRY_ASSERT (ecma_is_completion_value_normal_true (succeeded)
|| ecma_is_completion_value_normal_false (succeeded));
if (ecma_is_completion_value_normal_false (succeeded))
{
return ecma_reject (is_throw);
}
// e.
if (index >= old_len_uint32)
{
// i., ii.
ecma_number_t *num_p = ecma_alloc_number ();
*num_p = ecma_number_add (ecma_uint32_to_number (index), ECMA_NUMBER_ONE);
ecma_named_data_property_assign_value (obj_p, len_prop_p, ecma_make_number_value (num_p));
ecma_dealloc_number (num_p);
}
// f.
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
}
JERRY_UNREACHABLE();
} /* ecma_op_array_object_define_own_property */
/**
* @}
* @}
*/
@@ -0,0 +1,44 @@
/* Copyright 2014-2015 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_ARRAY_OBJECT_H
#define ECMA_ARRAY_OBJECT_H
#include "ecma-globals.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaarrayobject ECMA Array object related routines
* @{
*/
extern ecma_completion_value_t
ecma_op_create_array_object (const ecma_value_t *arguments_list_p,
ecma_length_t arguments_list_len,
bool is_treat_single_arg_as_length);
extern ecma_completion_value_t
ecma_op_array_object_define_own_property (ecma_object_t *obj_p,
ecma_string_t *property_name_p,
const ecma_property_descriptor_t* property_desc_p,
bool is_throw);
/**
* @}
* @}
*/
#endif /* !ECMA_ARRAY_OBJECT_H */
@@ -0,0 +1,73 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-boolean-object.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabooleanobject ECMA Boolean object related routines
* @{
*/
/**
* Boolean object creation operation.
*
* See also: ECMA-262 v5, 15.6.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_create_boolean_object (const ecma_value_t& arg) /**< argument passed to the Boolean constructor */
{
ecma_completion_value_t conv_to_boolean_completion = ecma_op_to_boolean (arg);
if (!ecma_is_completion_value_normal (conv_to_boolean_completion))
{
return conv_to_boolean_completion;
}
ecma_simple_value_t bool_value = (ecma_is_value_true (ecma_get_completion_value_value (conv_to_boolean_completion)) ?
ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE);
#else /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_BOOLEAN_BUILTIN */
ecma_object_t *obj_p = ecma_create_object (prototype_obj_p,
true,
ECMA_OBJECT_TYPE_GENERAL);
ecma_deref_object (prototype_obj_p);
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_BOOLEAN_UL;
ecma_property_t *prim_value_prop_p = ecma_create_internal_property (obj_p,
ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE);
prim_value_prop_p->u.internal_property.value = bool_value;
return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
} /* ecma_op_create_boolean_object */
@@ -0,0 +1,35 @@
/* Copyright 2014-2015 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_BOOLEAN_OBJECT_H
#define ECMA_BOOLEAN_OBJECT_H
#include "ecma-globals.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmabooleanobject ECMA Boolean object related routines
* @{
*/
extern ecma_completion_value_t ecma_op_create_boolean_object (const ecma_value_t& arg);
/**
* @}
* @}
*/
#endif /* !ECMA_BOOLEAN_OBJECT_H */
@@ -0,0 +1,460 @@
/* Copyright 2014-2015 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-comparison.h"
#include "ecma-conversion.h"
#include "ecma-globals.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmacomparison ECMA comparison
* @{
*/
/**
* ECMA abstract equality comparison routine.
*
* See also: ECMA-262 v5, 11.9.3
*
* @return true - if values are equal,
* false - otherwise.
*/
ecma_completion_value_t
ecma_op_abstract_equality_compare (const ecma_value_t& x, /**< first operand */
const ecma_value_t& y) /**< second operand */
{
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 = ecma_is_value_number (x);
const bool is_x_string = ecma_is_value_string (x);
const bool is_x_object = ecma_is_value_object (x);
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 = ecma_is_value_number (y);
const bool is_y_string = ecma_is_value_string (y);
const bool is_y_object = ecma_is_value_object (y);
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));
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
if (is_types_equal)
{
// 1.
if (is_x_undefined
|| is_x_null)
{
// a., b.
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
}
else if (is_x_number)
{ // c.
ecma_number_t x_num = *ecma_get_number_from_value (x);
ecma_number_t y_num = *ecma_get_number_from_value (y);
bool is_x_equal_to_y = (x_num == y_num);
#ifndef JERRY_NDEBUG
bool is_x_equal_to_y_check;
if (ecma_number_is_nan (x_num)
|| ecma_number_is_nan (y_num))
{
is_x_equal_to_y_check = false;
}
else if (x_num == y_num
|| (ecma_number_is_zero (x_num)
&& ecma_number_is_zero (y_num)))
{
is_x_equal_to_y_check = true;
}
else
{
is_x_equal_to_y_check = false;
}
JERRY_ASSERT (is_x_equal_to_y == is_x_equal_to_y_check);
#endif /* !JERRY_NDEBUG */
ret_value = ecma_make_simple_completion_value (is_x_equal_to_y ?
ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
}
else if (is_x_string)
{ // d.
ecma_string_t* x_str_p = ecma_get_string_from_value (x);
ecma_string_t* y_str_p = ecma_get_string_from_value (y);
bool is_equal = ecma_compare_ecma_strings (x_str_p, y_str_p);
ret_value = ecma_make_simple_completion_value (is_equal ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
}
else if (is_x_boolean)
{ // e.
bool is_equal = (ecma_is_value_true (x) == ecma_is_value_true (y));
ret_value = ecma_make_simple_completion_value (is_equal ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
}
else
{ // f.
JERRY_ASSERT(is_x_object);
bool is_equal = (ecma_get_object_from_value (x) == ecma_get_object_from_value (y));
ret_value = ecma_make_simple_completion_value (is_equal ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
}
}
else if ((is_x_null && is_y_undefined)
|| (is_x_undefined && is_y_null))
{ // 2., 3.
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
}
else if (is_x_number && is_y_string)
{
// 4.
ECMA_TRY_CATCH (y_num_value,
ecma_op_to_number (y),
ret_value);
ret_value = ecma_op_abstract_equality_compare (x, y_num_value);
ECMA_FINALIZE (y_num_value);
}
else if (is_x_string && is_y_number)
{
// 5.
ECMA_TRY_CATCH (x_num_value,
ecma_op_to_number (x),
ret_value);
ret_value = ecma_op_abstract_equality_compare (x_num_value, y);
ECMA_FINALIZE (x_num_value);
}
else if (is_x_boolean)
{
// 6.
ECMA_TRY_CATCH (x_num_value,
ecma_op_to_number (x),
ret_value);
ret_value = ecma_op_abstract_equality_compare (x_num_value, y);
ECMA_FINALIZE (x_num_value);
}
else if (is_y_boolean)
{
// 7.
ECMA_TRY_CATCH (y_num_value,
ecma_op_to_number (y),
ret_value);
ret_value = ecma_op_abstract_equality_compare (x, y_num_value);
ECMA_FINALIZE (y_num_value);
}
else if (is_y_object
&& (is_x_number || is_x_string))
{
// 8.
ECMA_TRY_CATCH (y_prim_value,
ecma_op_to_primitive (y, ECMA_PREFERRED_TYPE_NO),
ret_value);
ret_value = ecma_op_abstract_equality_compare (x, y_prim_value);
ECMA_FINALIZE (y_prim_value);
}
else if (is_x_object
&& (is_y_number || is_y_string))
{
// 9.
ECMA_TRY_CATCH (x_prim_value,
ecma_op_to_primitive (x, ECMA_PREFERRED_TYPE_NO),
ret_value);
ret_value = ecma_op_abstract_equality_compare (x_prim_value, y);
ECMA_FINALIZE (x_prim_value);
}
else
{
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
}
return ret_value;
} /* ecma_op_abstract_equality_compare */
/**
* ECMA strict equality comparison routine.
*
* See also: ECMA-262 v5, 11.9.6
*
* @return true - if values are strict equal,
* false - otherwise.
*/
bool
ecma_op_strict_equality_compare (const ecma_value_t& x, /**< first operand */
const ecma_value_t& y) /**< second operand */
{
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 = ecma_is_value_number (x);
const bool is_x_string = ecma_is_value_string (x);
const bool is_x_object = ecma_is_value_object (x);
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 = ecma_is_value_number (y);
const bool is_y_string = ecma_is_value_string (y);
const bool is_y_object = ecma_is_value_object (y);
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));
// 1. If Type (x) is different from Type (y), return false.
if (!is_types_equal)
{
return false;
}
// 2. If Type (x) is Undefined, return true.
if (is_x_undefined)
{
return true;
}
// 3. If Type (x) is Null, return true.
if (is_x_null)
{
return true;
}
// 4. If Type (x) is Number, then
if (is_x_number)
{
// a. If x is NaN, return false.
// b. If y is NaN, return false.
// c. If x is the same Number value as y, return true.
// d. If x is +0 and y is -0, return true.
// e. If x is -0 and y is +0, return true.
ecma_number_t x_num = *ecma_get_number_from_value (x);
ecma_number_t y_num = *ecma_get_number_from_value (y);
bool is_x_equal_to_y = (x_num == y_num);
#ifndef JERRY_NDEBUG
bool is_x_equal_to_y_check;
if (ecma_number_is_nan (x_num)
|| ecma_number_is_nan (y_num))
{
is_x_equal_to_y_check = false;
}
else if (x_num == y_num
|| (ecma_number_is_zero (x_num)
&& ecma_number_is_zero (y_num)))
{
is_x_equal_to_y_check = true;
}
else
{
is_x_equal_to_y_check = false;
}
JERRY_ASSERT (is_x_equal_to_y == is_x_equal_to_y_check);
#endif /* !JERRY_NDEBUG */
return is_x_equal_to_y;
}
// 5. If Type (x) is String, then return true if x and y are exactly the same sequence of characters
// (same length and same characters in corresponding positions); otherwise, return false.
if (is_x_string)
{
ecma_string_t* x_str_p = ecma_get_string_from_value (x);
ecma_string_t* y_str_p = ecma_get_string_from_value (y);
return ecma_compare_ecma_strings (x_str_p, y_str_p);
}
// 6. If Type (x) is Boolean, return true if x and y are both true or both false; otherwise, return false.
if (is_x_boolean)
{
return (ecma_is_value_true (x) == ecma_is_value_true (y));
}
// 7. Return true if x and y refer to the same object. Otherwise, return false.
JERRY_ASSERT (is_x_object);
return (ecma_get_object_from_value (x) == ecma_get_object_from_value (y));
} /* ecma_op_strict_equality_compare */
/**
* ECMA abstract relational comparison routine.
*
* See also: ECMA-262 v5, 11.8.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_abstract_relational_compare (const ecma_value_t& x, /**< first operand */
const ecma_value_t& y, /**< second operand */
bool left_first) /**< 'LeftFirst' flag */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
const ecma_value_t& first_converted_value = left_first ? x : y;
const ecma_value_t& second_converted_value = left_first ? y : x;
// 1., 2.
ECMA_TRY_CATCH(prim_first_converted_value,
ecma_op_to_primitive (first_converted_value, ECMA_PREFERRED_TYPE_NUMBER),
ret_value);
ECMA_TRY_CATCH(prim_second_converted_value,
ecma_op_to_primitive (second_converted_value, ECMA_PREFERRED_TYPE_NUMBER),
ret_value);
const ecma_value_t &px = left_first ? prim_first_converted_value : prim_second_converted_value;
const ecma_value_t &py = left_first ? prim_second_converted_value : prim_first_converted_value;
const bool is_px_string = ecma_is_value_string (px);
const bool is_py_string = ecma_is_value_string (py);
if (!(is_px_string && is_py_string))
{
// 3.
// a.
ECMA_OP_TO_NUMBER_TRY_CATCH (nx, px, ret_value);
ECMA_OP_TO_NUMBER_TRY_CATCH (ny, py, ret_value);
// b.
if (ecma_number_is_nan (nx)
|| ecma_number_is_nan (ny))
{
// c., d.
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
else
{
bool is_x_less_than_y = (nx < ny);
#ifndef JERRY_NDEBUG
bool is_x_less_than_y_check;
if (nx == ny
|| (ecma_number_is_zero (nx)
&& ecma_number_is_zero (ny)))
{
// e., f., g.
is_x_less_than_y_check = false;
}
else if (ecma_number_is_infinity (nx)
&& !ecma_number_is_negative (nx))
{
// h.
is_x_less_than_y_check = false;
}
else if (ecma_number_is_infinity (ny)
&& !ecma_number_is_negative (ny))
{
// i.
is_x_less_than_y_check = true;
}
else if (ecma_number_is_infinity (ny)
&& ecma_number_is_negative (ny))
{
// j.
is_x_less_than_y_check = false;
}
else if (ecma_number_is_infinity (nx)
&& ecma_number_is_negative (nx))
{
// k.
is_x_less_than_y_check = true;
}
else
{
// l.
JERRY_ASSERT (!ecma_number_is_nan (nx)
&& !ecma_number_is_infinity (nx));
JERRY_ASSERT (!ecma_number_is_nan (ny)
&& !ecma_number_is_infinity (ny));
JERRY_ASSERT (!(ecma_number_is_zero (nx)
&& ecma_number_is_zero (ny)));
if (nx < ny)
{
is_x_less_than_y_check = true;
}
else
{
is_x_less_than_y_check = false;
}
}
JERRY_ASSERT (is_x_less_than_y_check == is_x_less_than_y);
#endif /* !JERRY_NDEBUG */
ret_value = ecma_make_simple_completion_value (is_x_less_than_y ?
ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
}
ECMA_OP_TO_NUMBER_FINALIZE (ny);
ECMA_OP_TO_NUMBER_FINALIZE (nx);
}
else
{ // 4.
JERRY_ASSERT (is_px_string && is_py_string);
ecma_string_t *str_x_p = ecma_get_string_from_value (px);
ecma_string_t *str_y_p = ecma_get_string_from_value (py);
bool is_px_less = ecma_compare_ecma_strings_relational (str_x_p, str_y_p);
ret_value = ecma_make_simple_completion_value (is_px_less ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE);
}
ECMA_FINALIZE(prim_second_converted_value);
ECMA_FINALIZE(prim_first_converted_value);
return ret_value;
} /* ecma_op_abstract_relational_compare */
/**
* @}
* @}
*/
@@ -0,0 +1,42 @@
/* Copyright 2014-2015 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 JERRY_ECMA_COMPARISON_H
#define JERRY_ECMA_COMPARISON_H
#include "ecma-globals.h"
#include "ecma-helpers.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmacomparison ECMA comparison
* @{
*/
extern ecma_completion_value_t ecma_op_abstract_equality_compare (const ecma_value_t& x,
const ecma_value_t& y);
extern bool ecma_op_strict_equality_compare (const ecma_value_t& x,
const ecma_value_t& y);
extern ecma_completion_value_t ecma_op_abstract_relational_compare (const ecma_value_t& x,
const ecma_value_t& y,
bool left_first);
/**
* @}
* @}
*/
#endif /* !JERRY_ECMA_COMPARISON_H */
@@ -0,0 +1,822 @@
/* Copyright 2014-2015 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.
*/
/**
* Implementation of ECMA-defined conversion routines
*/
#include "ecma-alloc.h"
#include "ecma-boolean-object.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-function-object.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-number-object.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "ecma-string-object.h"
#include "ecma-try-catch-macro.h"
#include "jrt-libc-includes.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaconversion ECMA conversion routines
* @{
*/
/**
* CheckObjectCoercible operation.
*
* See also:
* ECMA-262 v5, 9.10
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_check_object_coercible (const ecma_value_t& value) /**< ecma-value */
{
ecma_check_value_type_is_spec_defined (value);
if (ecma_is_value_undefined (value)
|| ecma_is_value_null (value))
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
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 (const ecma_value_t& x, /**< ecma-value */
const 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 = ecma_is_value_number (x);
const bool is_x_string = ecma_is_value_string (x);
const bool is_x_object = ecma_is_value_object (x);
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 = ecma_is_value_number (y);
const bool is_y_string = ecma_is_value_string (y);
const bool is_y_object = ecma_is_value_object (y);
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)
{
ecma_number_t *x_num_p = ecma_get_number_from_value (x);
ecma_number_t *y_num_p = ecma_get_number_from_value (y);
if (ecma_number_is_nan (*x_num_p)
&& ecma_number_is_nan (*y_num_p))
{
return true;
}
else if (ecma_number_is_zero (*x_num_p)
&& ecma_number_is_zero (*y_num_p)
&& ecma_number_is_negative (*x_num_p) != ecma_number_is_negative (*y_num_p))
{
return false;
}
return (*x_num_p == *y_num_p);
}
if (is_x_string)
{
ecma_string_t* x_str_p = ecma_get_string_from_value (x);
ecma_string_t* y_str_p = ecma_get_string_from_value (y);
return ecma_compare_ecma_strings (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_object_from_value (x) == ecma_get_object_from_value (y));
} /* ecma_op_same_value */
/**
* ToPrimitive operation.
*
* See also:
* ECMA-262 v5, 9.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_to_primitive (const ecma_value_t& value, /**< ecma-value */
ecma_preferred_type_hint_t preferred_type) /**< preferred type hint */
{
ecma_check_value_type_is_spec_defined (value);
if (ecma_is_value_object (value))
{
ecma_object_t *obj_p = ecma_get_object_from_value (value);
return ecma_op_object_default_value (obj_p, preferred_type);
}
else
{
return ecma_make_normal_completion_value (ecma_copy_value (value, true));
}
} /* ecma_op_to_primitive */
/**
* ToBoolean operation.
*
* See also:
* ECMA-262 v5, 9.2
*
* @return completion value
* Returned value is simple and so need not be freed.
* However, ecma_free_completion_value may be called for it, but it is a no-op.
*/
ecma_completion_value_t
ecma_op_to_boolean (const ecma_value_t& value) /**< ecma-value */
{
ecma_check_value_type_is_spec_defined (value);
ecma_simple_value_t ret_value;
if (ecma_is_value_boolean (value))
{
ret_value = (ecma_is_value_true (value) ?
ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
}
else if (ecma_is_value_undefined (value)
|| ecma_is_value_null (value))
{
ret_value = ECMA_SIMPLE_VALUE_FALSE;
}
else if (ecma_is_value_number (value))
{
ecma_number_t *num_p = ecma_get_number_from_value (value);
if (ecma_number_is_nan (*num_p)
|| ecma_number_is_zero (*num_p))
{
ret_value = ECMA_SIMPLE_VALUE_FALSE;
}
else
{
ret_value = ECMA_SIMPLE_VALUE_TRUE;
}
}
else if (ecma_is_value_string (value))
{
ecma_string_t *str_p = ecma_get_string_from_value (value);
if (ecma_string_get_length (str_p) == 0)
{
ret_value = ECMA_SIMPLE_VALUE_FALSE;
}
else
{
ret_value = ECMA_SIMPLE_VALUE_TRUE;
}
}
else
{
JERRY_ASSERT (ecma_is_value_object (value));
ret_value = ECMA_SIMPLE_VALUE_TRUE;
}
return ecma_make_simple_completion_value (ret_value);
} /* ecma_op_to_boolean */
/**
* ToNumber operation.
*
* See also:
* ECMA-262 v5, 9.3
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_to_number (const ecma_value_t& value) /**< ecma-value */
{
ecma_check_value_type_is_spec_defined (value);
if (ecma_is_value_number (value))
{
return ecma_make_normal_completion_value (ecma_copy_value (value, true));
}
else if (ecma_is_value_string (value))
{
ecma_string_t *str_p = ecma_get_string_from_value (value);
ecma_number_t *num_p = ecma_alloc_number ();
*num_p = ecma_string_to_number (str_p);
return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
}
else if (ecma_is_value_object (value))
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (primitive_value,
ecma_op_to_primitive (value, ECMA_PREFERRED_TYPE_NUMBER),
ret_value);
ret_value = ecma_op_to_number (primitive_value);
ECMA_FINALIZE (primitive_value);
return ret_value;
}
else
{
ecma_number_t *num_p = ecma_alloc_number ();
if (ecma_is_value_undefined (value))
{
*num_p = ecma_number_make_nan ();
}
else if (ecma_is_value_null (value))
{
*num_p = ECMA_NUMBER_ZERO;
}
else
{
JERRY_ASSERT (ecma_is_value_boolean (value));
if (ecma_is_value_true (value))
{
*num_p = ECMA_NUMBER_ONE;
}
else
{
*num_p = ECMA_NUMBER_ZERO;
}
}
return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
}
} /* ecma_op_to_number */
/**
* ToString operation.
*
* See also:
* ECMA-262 v5, 9.8
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_to_string (const ecma_value_t& value) /**< ecma-value */
{
ecma_check_value_type_is_spec_defined (value);
if (unlikely (ecma_is_value_object (value)))
{
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (prim_value,
ecma_op_to_primitive (value, ECMA_PREFERRED_TYPE_STRING),
ret_value);
ret_value = ecma_op_to_string (prim_value);
ECMA_FINALIZE (prim_value);
return ret_value;
}
else
{
ecma_string_t *res_p = NULL;
if (ecma_is_value_string (value))
{
res_p = ecma_get_string_from_value (value);
res_p = ecma_copy_or_ref_ecma_string (res_p);
}
else if (ecma_is_value_number (value))
{
ecma_number_t *num_p = ecma_get_number_from_value (value);
res_p = ecma_new_ecma_string_from_number (*num_p);
}
else if (ecma_is_value_undefined (value))
{
res_p = ecma_get_magic_string (ECMA_MAGIC_STRING_UNDEFINED);
}
else if (ecma_is_value_null (value))
{
res_p = ecma_get_magic_string (ECMA_MAGIC_STRING_NULL);
}
else
{
JERRY_ASSERT (ecma_is_value_boolean (value));
if (ecma_is_value_true (value))
{
res_p = ecma_get_magic_string (ECMA_MAGIC_STRING_TRUE);
}
else
{
res_p = ecma_get_magic_string (ECMA_MAGIC_STRING_FALSE);
}
}
return ecma_make_normal_completion_value (ecma_make_string_value (res_p));
}
} /* ecma_op_to_string */
/**
* ToObject operation.
*
* See also:
* ECMA-262 v5, 9.9
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_to_object (const ecma_value_t& value) /**< ecma-value */
{
ecma_check_value_type_is_spec_defined (value);
if (ecma_is_value_number (value))
{
return ecma_op_create_number_object (value);
}
else if (ecma_is_value_string (value))
{
return ecma_op_create_string_object (&value, 1);
}
else if (ecma_is_value_object (value))
{
return ecma_make_normal_completion_value (ecma_copy_value (value, true));
}
else
{
if (ecma_is_value_undefined (value)
|| ecma_is_value_null (value))
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
JERRY_ASSERT (ecma_is_value_boolean (value));
return ecma_op_create_boolean_object (value);
}
}
} /* ecma_op_to_object */
/**
* FromPropertyDescriptor operation.
*
* See also:
* ECMA-262 v5, 8.10.4
*
* @return constructed object
*/
ecma_object_t*
ecma_op_from_property_descriptor (const ecma_property_descriptor_t* src_prop_desc_p) /**< property descriptor */
{
// 2.
ecma_object_t *obj_p = ecma_op_create_object_object_noarg ();
ecma_completion_value_t completion;
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
{
prop_desc.is_value_defined = true;
prop_desc.is_writable_defined = true;
prop_desc.is_writable = true;
prop_desc.is_enumerable_defined = true;
prop_desc.is_enumerable = true;
prop_desc.is_configurable_defined = true;
prop_desc.is_configurable = true;
}
// 3.
if (prop_desc.is_value_defined
|| prop_desc.is_writable_defined)
{
JERRY_ASSERT (prop_desc.is_value_defined && prop_desc.is_writable_defined);
// a.
prop_desc.value = src_prop_desc_p->value;
ecma_string_t *value_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_VALUE);
completion = ecma_op_object_define_own_property (obj_p,
value_magic_string_p,
&prop_desc,
false);
ecma_deref_ecma_string (value_magic_string_p);
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
// b.
const bool is_writable = (src_prop_desc_p->is_writable);
prop_desc.value = ecma_make_simple_value (is_writable ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE);
ecma_string_t *writable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_WRITABLE);
completion = ecma_op_object_define_own_property (obj_p,
writable_magic_string_p,
&prop_desc,
false);
ecma_deref_ecma_string (writable_magic_string_p);
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
}
else
{
// 4.
JERRY_ASSERT (prop_desc.is_get_defined && prop_desc.is_set_defined);
// a.
if (src_prop_desc_p->get_p == NULL)
{
prop_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
else
{
prop_desc.value = ecma_make_object_value (src_prop_desc_p->get_p);
}
ecma_string_t *get_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_GET);
completion = ecma_op_object_define_own_property (obj_p,
get_magic_string_p,
&prop_desc,
false);
ecma_deref_ecma_string (get_magic_string_p);
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
// b.
if (src_prop_desc_p->set_p == NULL)
{
prop_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
else
{
prop_desc.value = ecma_make_object_value (src_prop_desc_p->set_p);
}
ecma_string_t *set_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_SET);
completion = ecma_op_object_define_own_property (obj_p,
set_magic_string_p,
&prop_desc,
false);
ecma_deref_ecma_string (set_magic_string_p);
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
}
const bool is_enumerable = src_prop_desc_p->is_enumerable;
prop_desc.value = ecma_make_simple_value (is_enumerable ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE);
ecma_string_t *enumerable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ENUMERABLE);
completion = ecma_op_object_define_own_property (obj_p,
enumerable_magic_string_p,
&prop_desc,
false);
ecma_deref_ecma_string (enumerable_magic_string_p);
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
const bool is_configurable = src_prop_desc_p->is_configurable;
prop_desc.value = ecma_make_simple_value (is_configurable ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE);
ecma_string_t *configurable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CONFIGURABLE);
completion = ecma_op_object_define_own_property (obj_p,
configurable_magic_string_p,
&prop_desc,
false);
ecma_deref_ecma_string (configurable_magic_string_p);
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion));
return obj_p;
} /* ecma_op_from_property_descriptor */
/**
* ToPropertyDescriptor operation.
*
* See also:
* ECMA-262 v5, 8.10.5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_to_property_descriptor (const ecma_value_t& obj_value, /**< object value */
ecma_property_descriptor_t *out_prop_desc_p) /**< out: filled property descriptor
if return value is normal
empty completion value */
{
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
// 1.
if (!ecma_is_value_object (obj_value))
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
ecma_object_t *obj_p = ecma_get_object_from_value (obj_value);
// 2.
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
// 3.
ecma_string_t *enumerable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ENUMERABLE);
if (ecma_op_object_get_property (obj_p, enumerable_magic_string_p) != NULL)
{
ECMA_TRY_CATCH (enumerable_prop_value,
ecma_op_object_get (obj_p, enumerable_magic_string_p),
ret_value);
ECMA_TRY_CATCH (boolean_enumerable_prop_value,
ecma_op_to_boolean (enumerable_prop_value),
ret_value);
prop_desc.is_enumerable_defined = true;
if (ecma_is_value_true (boolean_enumerable_prop_value))
{
prop_desc.is_enumerable = true;
}
else
{
JERRY_ASSERT (ecma_is_value_boolean (boolean_enumerable_prop_value));
prop_desc.is_enumerable = false;
}
ECMA_FINALIZE (boolean_enumerable_prop_value);
ECMA_FINALIZE (enumerable_prop_value);
}
ecma_deref_ecma_string (enumerable_magic_string_p);
if (!ecma_is_completion_value_throw (ret_value))
{
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
// 4.
ecma_string_t *configurable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CONFIGURABLE);
if (ecma_op_object_get_property (obj_p, configurable_magic_string_p) != NULL)
{
ECMA_TRY_CATCH (configurable_prop_value,
ecma_op_object_get (obj_p, configurable_magic_string_p),
ret_value);
ECMA_TRY_CATCH (boolean_configurable_prop_value,
ecma_op_to_boolean (configurable_prop_value),
ret_value);
prop_desc.is_configurable_defined = true;
if (ecma_is_value_true (boolean_configurable_prop_value))
{
prop_desc.is_configurable = true;
}
else
{
JERRY_ASSERT (ecma_is_value_boolean (boolean_configurable_prop_value));
prop_desc.is_configurable = false;
}
ECMA_FINALIZE (boolean_configurable_prop_value);
ECMA_FINALIZE (configurable_prop_value);
}
ecma_deref_ecma_string (configurable_magic_string_p);
}
if (!ecma_is_completion_value_throw (ret_value))
{
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
// 5.
ecma_string_t *value_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_VALUE);
if (ecma_op_object_get_property (obj_p, value_magic_string_p) != NULL)
{
ECMA_TRY_CATCH (value_prop_value,
ecma_op_object_get (obj_p, value_magic_string_p),
ret_value);
prop_desc.is_value_defined = true;
prop_desc.value = ecma_copy_value (value_prop_value, true);
ECMA_FINALIZE (value_prop_value);
}
ecma_deref_ecma_string (value_magic_string_p);
}
if (!ecma_is_completion_value_throw (ret_value))
{
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
// 6.
ecma_string_t *writable_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_WRITABLE);
if (ecma_op_object_get_property (obj_p, writable_magic_string_p) != NULL)
{
ECMA_TRY_CATCH (writable_prop_value,
ecma_op_object_get (obj_p, writable_magic_string_p),
ret_value);
ECMA_TRY_CATCH (boolean_writable_prop_value,
ecma_op_to_boolean (writable_prop_value),
ret_value);
prop_desc.is_writable_defined = true;
if (ecma_is_value_true (boolean_writable_prop_value))
{
prop_desc.is_writable = true;
}
else
{
JERRY_ASSERT (ecma_is_value_boolean (boolean_writable_prop_value));
prop_desc.is_writable = false;
}
ECMA_FINALIZE (boolean_writable_prop_value);
ECMA_FINALIZE (writable_prop_value);
}
ecma_deref_ecma_string (writable_magic_string_p);
}
if (!ecma_is_completion_value_throw (ret_value))
{
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
// 7.
ecma_string_t *get_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_GET);
if (ecma_op_object_get_property (obj_p, get_magic_string_p) != NULL)
{
ECMA_TRY_CATCH (get_prop_value,
ecma_op_object_get (obj_p, get_magic_string_p),
ret_value);
if (!ecma_op_is_callable (get_prop_value)
&& !ecma_is_value_undefined (get_prop_value))
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
prop_desc.is_get_defined = true;
if (ecma_is_value_undefined (get_prop_value))
{
prop_desc.get_p = NULL;
}
else
{
JERRY_ASSERT (ecma_is_value_object (get_prop_value));
ecma_object_t *get_p = ecma_get_object_from_value (get_prop_value);
ecma_ref_object (get_p);
prop_desc.get_p = get_p;
}
}
ECMA_FINALIZE (get_prop_value);
}
ecma_deref_ecma_string (get_magic_string_p);
}
if (!ecma_is_completion_value_throw (ret_value))
{
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
// 8.
ecma_string_t *set_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_SET);
if (ecma_op_object_get_property (obj_p, set_magic_string_p) != NULL)
{
ECMA_TRY_CATCH (set_prop_value,
ecma_op_object_get (obj_p, set_magic_string_p),
ret_value);
if (!ecma_op_is_callable (set_prop_value)
&& !ecma_is_value_undefined (set_prop_value))
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
prop_desc.is_set_defined = true;
if (ecma_is_value_undefined (set_prop_value))
{
prop_desc.set_p = NULL;
}
else
{
JERRY_ASSERT (ecma_is_value_object (set_prop_value));
ecma_object_t *set_p = ecma_get_object_from_value (set_prop_value);
ecma_ref_object (set_p);
prop_desc.set_p = set_p;
}
}
ECMA_FINALIZE (set_prop_value);
}
ecma_deref_ecma_string (set_magic_string_p);
}
if (!ecma_is_completion_value_throw (ret_value))
{
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
// 9.
if (prop_desc.is_get_defined
|| prop_desc.is_set_defined)
{
if (prop_desc.is_value_defined
|| prop_desc.is_writable_defined)
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
}
}
if (!ecma_is_completion_value_throw (ret_value))
{
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
}
else
{
ecma_free_property_descriptor (&prop_desc);
}
*out_prop_desc_p = prop_desc;
}
return ret_value;
} /* ecma_op_to_property_descriptor */
/**
* @}
* @}
*/
@@ -0,0 +1,59 @@
/* Copyright 2014-2015 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 JERRY_ECMA_CONVERSION_H
#define JERRY_ECMA_CONVERSION_H
#include "ecma-globals.h"
#include "ecma-helpers.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaconversion ECMA conversion
* @{
*/
/**
* Second argument of 'ToPrimitive' operation that is a hint,
* specifying the preferred type of conversion result.
*/
typedef enum
{
ECMA_PREFERRED_TYPE_NO, /**< no preferred type is specified */
ECMA_PREFERRED_TYPE_NUMBER, /**< Number */
ECMA_PREFERRED_TYPE_STRING /**< String */
} ecma_preferred_type_hint_t;
extern ecma_completion_value_t ecma_op_check_object_coercible (const ecma_value_t& value);
extern bool ecma_op_same_value (const ecma_value_t& x,
const ecma_value_t& y);
extern ecma_completion_value_t ecma_op_to_primitive (const ecma_value_t& value,
ecma_preferred_type_hint_t preferred_type);
extern ecma_completion_value_t ecma_op_to_boolean (const ecma_value_t& value);
extern ecma_completion_value_t ecma_op_to_number (const ecma_value_t& value);
extern ecma_completion_value_t ecma_op_to_string (const ecma_value_t& value);
extern ecma_completion_value_t ecma_op_to_object (const ecma_value_t& value);
extern ecma_object_t* ecma_op_from_property_descriptor (const ecma_property_descriptor_t* src_prop_desc_p);
extern ecma_completion_value_t ecma_op_to_property_descriptor (const ecma_value_t& obj_value,
ecma_property_descriptor_t *out_prop_desc_p);
/**
* @}
* @}
*/
#endif /* !JERRY_ECMA_CONVERSION_H */
@@ -0,0 +1,136 @@
/* Copyright 2014-2015 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-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "jrt.h"
/** \addtogroup ecma ECMA
* @{
*/
/**
* \addtogroup exceptions Exceptions
* @{
*/
/**
* Standard ecma-error object constructor.
*
* @return pointer to ecma-object representing specified error
* with reference counter set to one.
*/
ecma_object_t*
ecma_new_standard_error (ecma_standard_error_t error_type) /**< native error type */
{
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS
ecma_builtin_id_t prototype_id = ECMA_BUILTIN_ID__COUNT;
switch (error_type)
{
case ECMA_ERROR_COMMON:
{
prototype_id = ECMA_BUILTIN_ID_ERROR_PROTOTYPE;
break;
}
case ECMA_ERROR_EVAL:
{
prototype_id = ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE;
break;
}
case ECMA_ERROR_RANGE:
{
prototype_id = ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE;
break;
}
case ECMA_ERROR_REFERENCE:
{
prototype_id = ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE;
break;
}
case ECMA_ERROR_TYPE:
{
prototype_id = ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE;
break;
}
case ECMA_ERROR_URI:
{
prototype_id = ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE;
break;
}
case ECMA_ERROR_SYNTAX:
{
prototype_id = ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE;
break;
}
}
ecma_object_t *prototype_obj_p = ecma_builtin_get (prototype_id);
ecma_object_t *new_error_obj_p = ecma_create_object (prototype_obj_p,
true,
ECMA_OBJECT_TYPE_GENERAL);
ecma_deref_object (prototype_obj_p);
ecma_property_t *class_prop_p = ecma_create_internal_property (new_error_obj_p,
ECMA_INTERNAL_PROPERTY_CLASS);
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_ERROR_UL;
return new_error_obj_p;
#else /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
(void) error_type;
return ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR);
#endif /* CONFIG_ECMA_COMPACT_PROFILE_DISABLE_ERROR_BUILTINS */
} /* ecma_new_standard_error */
/**
* Standard ecma-error object constructor.
*
* @return pointer to ecma-object representing specified error
* with reference counter set to one.
*/
ecma_object_t*
ecma_new_standard_error_with_message (ecma_standard_error_t error_type, /**< native error type */
ecma_string_t* message_string_p) /**< message string */
{
ecma_object_t *new_error_obj_p = ecma_new_standard_error (error_type);
ecma_string_t *message_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_MESSAGE);
ecma_property_t *prop_p = ecma_create_named_data_property (new_error_obj_p,
message_magic_string_p,
true, false, true);
ecma_set_named_data_property_value (prop_p,
ecma_make_string_value (ecma_copy_or_ref_ecma_string (message_string_p)));
ecma_deref_ecma_string (message_magic_string_p);
return new_error_obj_p;
} /* ecma_new_standard_error_with_message */
/**
* @}
* @}
*/
@@ -0,0 +1,56 @@
/* Copyright 2014-2015 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_EXCEPTIONS_H
#define ECMA_EXCEPTIONS_H
#include "ecma-globals.h"
#include "jrt.h"
/** \addtogroup ecma ECMA
* @{
*/
/**
* \addtogroup exceptions Exceptions
* @{
*/
/**
* Native errors.
*
* See also: 15.11.1, 15.11.6
*/
typedef enum
{
ECMA_ERROR_COMMON, /**< Error */
ECMA_ERROR_EVAL, /**< EvalError */
ECMA_ERROR_RANGE, /**< RangeError */
ECMA_ERROR_REFERENCE, /**< ReferenceError */
ECMA_ERROR_SYNTAX, /**< SyntaxError */
ECMA_ERROR_TYPE, /**< TypeError */
ECMA_ERROR_URI /**< URIError */
} ecma_standard_error_t;
extern ecma_object_t *ecma_new_standard_error (ecma_standard_error_t error_type);
extern ecma_object_t* ecma_new_standard_error_with_message (ecma_standard_error_t error_type,
ecma_string_t *message_string_p);
/**
* @}
* @}
*/
#endif /* !ECMA_EXCEPTIONS_H */
@@ -0,0 +1,764 @@
/* Copyright 2014-2015 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-alloc.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-function-object.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-lex-env.h"
#include "ecma-objects.h"
#include "ecma-objects-general.h"
#include "ecma-try-catch-macro.h"
#include "jrt.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmafunctionobject ECMA Function object related routines
* @{
*/
/**
* Pack 'is_strict' flag and opcode index to value
* that can be stored in an [[Code]] internal property.
*
* @return packed value
*/
static uint32_t
ecma_pack_code_internal_property_value (bool is_strict, /**< is code strict? */
opcode_counter_t opcode_idx) /**< index of first opcode */
{
uint32_t value = opcode_idx;
const uint32_t is_strict_bit_offset = (uint32_t) (sizeof (value) * JERRY_BITSINBYTE - 1);
JERRY_ASSERT(((value) & (1u << is_strict_bit_offset)) == 0);
if (is_strict)
{
value |= (1u << is_strict_bit_offset);
}
return value;
} /* ecma_pack_code_internal_property_value */
/**
* Unpack 'is_strict' flag and opcode index from value
* that can be stored in an [[Code]] internal property.
*
* @return opcode index
*/
static opcode_counter_t
ecma_unpack_code_internal_property_value (uint32_t value, /**< packed value */
bool* out_is_strict_p) /**< out: is code strict? */
{
JERRY_ASSERT(out_is_strict_p != NULL);
const uint32_t is_strict_bit_offset = (uint32_t) (sizeof (value) * JERRY_BITSINBYTE - 1);
bool is_strict = ((value & (1u << is_strict_bit_offset)) != 0);
*out_is_strict_p = is_strict;
opcode_counter_t opcode_idx = (opcode_counter_t) (value & ~(1u << is_strict_bit_offset));
return opcode_idx;
} /* ecma_unpack_code_internal_property_value */
/**
* IsCallable operation.
*
* See also: ECMA-262 v5, 9.11
*
* @return true, if value is callable object;
* false - otherwise.
*/
bool
ecma_op_is_callable (const ecma_value_t& value) /**< ecma-value */
{
if (!ecma_is_value_object (value))
{
return false;
}
ecma_object_t *obj_p = ecma_get_object_from_value (value);
JERRY_ASSERT(obj_p != NULL);
JERRY_ASSERT(!ecma_is_lexical_environment (obj_p));
return (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION
|| ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION
|| ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION);
} /* ecma_op_is_callable */
/**
* Check whether the value is Object that implements [[Construct]].
*
* @return true, if value is constructor object;
* false - otherwise.
*/
bool
ecma_is_constructor (const ecma_value_t& value) /**< ecma-value */
{
if (!ecma_is_value_object (value))
{
return false;
}
ecma_object_t *obj_p = ecma_get_object_from_value (value);
JERRY_ASSERT(obj_p != NULL);
JERRY_ASSERT(!ecma_is_lexical_environment (obj_p));
return (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION
|| ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
} /* ecma_is_constructor */
/**
* Function object creation operation.
*
* See also: ECMA-262 v5, 13.2
*
* @return pointer to newly created Function object
*/
ecma_object_t*
ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[], /**< formal parameters list */
ecma_length_t formal_parameters_number, /**< formal parameters list's length */
ecma_object_t *scope_p, /**< function's scope */
bool is_strict, /**< 'strict' flag */
opcode_counter_t first_opcode_idx) /**< index of first opcode of function's body */
{
// 1., 4., 13.
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
ecma_object_t *f = ecma_create_object (prototype_obj_p, true, ECMA_OBJECT_TYPE_FUNCTION);
ecma_deref_object (prototype_obj_p);
// 2., 6., 7., 8.
/*
* We don't setup [[Get]], [[Call]], [[Construct]], [[HasInstance]] for each function object.
* Instead we set the object's type to ECMA_OBJECT_TYPE_FUNCTION
* that defines which version of the routine should be used on demand.
*/
// 3.
ecma_property_t *class_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CLASS);
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_FUNCTION_UL;
// 9.
ecma_property_t *scope_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_SCOPE);
ECMA_SET_POINTER(scope_prop_p->u.internal_property.value, scope_p);
ecma_gc_update_may_ref_younger_object_flag_by_object (f, scope_p);
// 10., 11.
ecma_property_t *formal_parameters_prop_p = ecma_create_internal_property (f,
ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS);
if (formal_parameters_number != 0)
{
ecma_collection_header_t *formal_parameters_collection_p = ecma_new_strings_collection (formal_parameter_list_p,
formal_parameters_number);
ECMA_SET_POINTER (formal_parameters_prop_p->u.internal_property.value, formal_parameters_collection_p);
}
else
{
JERRY_ASSERT (formal_parameters_prop_p->u.internal_property.value == ECMA_NULL_POINTER);
}
// 12.
ecma_property_t *code_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CODE);
code_prop_p->u.internal_property.value = ecma_pack_code_internal_property_value (is_strict,
first_opcode_idx);
// 14.
ecma_number_t* len_p = ecma_alloc_number ();
*len_p = ecma_uint32_to_number (formal_parameters_number);
// 15.
ecma_property_descriptor_t length_prop_desc = ecma_make_empty_property_descriptor ();
length_prop_desc.is_value_defined = true;
length_prop_desc.value = ecma_make_number_value (len_p);
ecma_string_t* magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
ecma_completion_value_t completion = ecma_op_object_define_own_property (f,
magic_string_length_p,
&length_prop_desc,
false);
ecma_deref_ecma_string (magic_string_length_p);
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)
|| ecma_is_completion_value_normal_false (completion));
ecma_dealloc_number (len_p);
len_p = NULL;
// 16.
ecma_object_t *proto_p = ecma_op_create_object_object_noarg ();
// 17.
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
{
prop_desc.is_value_defined = true;
prop_desc.value = ecma_make_object_value (f);
prop_desc.is_writable_defined = true;
prop_desc.is_writable = true;
prop_desc.is_enumerable_defined = true;
prop_desc.is_enumerable = false;
prop_desc.is_configurable_defined = true;
prop_desc.is_configurable = true;
}
ecma_string_t *magic_string_constructor_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CONSTRUCTOR);
ecma_op_object_define_own_property (proto_p,
magic_string_constructor_p,
&prop_desc,
false);
ecma_deref_ecma_string (magic_string_constructor_p);
// 18.
prop_desc.value = ecma_make_object_value (proto_p);
prop_desc.is_configurable = false;
ecma_string_t *magic_string_prototype_p = ecma_get_magic_string (ECMA_MAGIC_STRING_PROTOTYPE);
ecma_op_object_define_own_property (f,
magic_string_prototype_p,
&prop_desc,
false);
ecma_deref_ecma_string (magic_string_prototype_p);
ecma_deref_object (proto_p);
// 19.
if (is_strict)
{
ecma_object_t *thrower_p = ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER);
prop_desc = ecma_make_empty_property_descriptor ();
{
prop_desc.is_enumerable_defined = true;
prop_desc.is_enumerable = false;
prop_desc.is_configurable_defined = true;
prop_desc.is_configurable = false;
prop_desc.is_get_defined = true;
prop_desc.get_p = thrower_p;
prop_desc.is_set_defined = true;
prop_desc.set_p = thrower_p;
}
ecma_string_t *magic_string_caller_p = ecma_get_magic_string (ECMA_MAGIC_STRING_CALLER);
ecma_op_object_define_own_property (f,
magic_string_caller_p,
&prop_desc,
false);
ecma_deref_ecma_string (magic_string_caller_p);
ecma_string_t *magic_string_arguments_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ARGUMENTS);
ecma_op_object_define_own_property (f,
magic_string_arguments_p,
&prop_desc,
false);
ecma_deref_ecma_string (magic_string_arguments_p);
ecma_deref_object (thrower_p);
}
return f;
} /* ecma_op_create_function_object */
/**
* Setup variables for arguments listed in formal parameter list.
*
* See also:
* Declaration binding instantiation (ECMA-262 v5, 10.5), block 4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
static ecma_completion_value_t
ecma_function_call_setup_args_variables (ecma_object_t *func_obj_p, /**< Function object */
ecma_object_t *env_p, /**< lexical environment */
const ecma_value_t *arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len, /**< length of argument list */
bool is_strict) /**< flag indicating strict mode */
{
ecma_property_t *formal_parameters_prop_p = ecma_get_internal_property (func_obj_p,
ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS);
ecma_collection_header_t *formal_parameters_p;
formal_parameters_p = ECMA_GET_POINTER (ecma_collection_header_t,
formal_parameters_prop_p->u.internal_property.value);
if (formal_parameters_p == NULL)
{
return ecma_make_empty_completion_value ();
}
ecma_length_t formal_parameters_count = formal_parameters_p->unit_number;
ecma_collection_iterator_t formal_params_iterator;
ecma_collection_iterator_init (&formal_params_iterator, formal_parameters_p);
for (size_t n = 0;
n < formal_parameters_count;
n++)
{
ecma_value_t v;
if (n >= arguments_list_len)
{
v = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
else
{
v = arguments_list_p[n];
}
bool is_moved = ecma_collection_iterator_next (&formal_params_iterator);
JERRY_ASSERT (is_moved);
ecma_value_t formal_parameter_name_value = *formal_params_iterator.current_value_p;
ecma_string_t *formal_parameter_name_string_p = ecma_get_string_from_value (formal_parameter_name_value);
bool arg_already_declared = ecma_op_has_binding (env_p, formal_parameter_name_string_p);
if (!arg_already_declared)
{
ecma_completion_value_t completion = ecma_op_create_mutable_binding (env_p,
formal_parameter_name_string_p,
false);
if (ecma_is_completion_value_throw (completion))
{
return completion;
}
JERRY_ASSERT (ecma_is_completion_value_empty (completion));
completion = ecma_op_set_mutable_binding (env_p,
formal_parameter_name_string_p,
v,
is_strict);
if (ecma_is_completion_value_throw (completion))
{
return completion;
}
JERRY_ASSERT (ecma_is_completion_value_empty (completion));
}
}
return ecma_make_empty_completion_value ();
} /* ecma_function_call_setup_args_variables */
/**
* [[Call]] implementation for Function objects,
* created through 13.2 (ECMA_OBJECT_TYPE_FUNCTION)
* or 15.3.4.5 (ECMA_OBJECT_TYPE_BOUND_FUNCTION),
* and for built-in Function objects
* from section 15 (ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION).
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object */
const ecma_value_t& value) /**< argument 'V' */
{
JERRY_ASSERT(func_obj_p != NULL
&& !ecma_is_lexical_environment (func_obj_p));
if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION)
{
if (!ecma_is_value_object (value))
{
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
}
ecma_object_t* v_obj_p = ecma_get_object_from_value (value);
ecma_string_t *prototype_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_PROTOTYPE);
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (prototype_obj_value,
ecma_op_object_get (func_obj_p, prototype_magic_string_p),
ret_value);
if (!ecma_is_value_object (prototype_obj_value))
{
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
ecma_object_t *prototype_obj_p = ecma_get_object_from_value (prototype_obj_value);
JERRY_ASSERT (prototype_obj_p != NULL);
do
{
v_obj_p = ecma_get_object_prototype (v_obj_p);
if (v_obj_p == NULL)
{
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_FALSE);
break;
}
else if (v_obj_p == prototype_obj_p)
{
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
break;
}
} while (true);
}
ECMA_FINALIZE (prototype_obj_value);
ecma_deref_ecma_string (prototype_magic_string_p);
return ret_value;
}
else if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION)
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
JERRY_UNIMPLEMENTED ("Bound functions are not implemented.");
}
} /* ecma_op_function_has_instance */
/**
* [[Call]] implementation for Function objects,
* created through 13.2 (ECMA_OBJECT_TYPE_FUNCTION)
* or 15.3.4.5 (ECMA_OBJECT_TYPE_BOUND_FUNCTION),
* and for built-in Function objects
* from section 15 (ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION).
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
const ecma_value_t& this_arg_value, /**< 'this' argument's value */
const ecma_value_t* arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< length of arguments list */
{
JERRY_ASSERT(func_obj_p != NULL
&& !ecma_is_lexical_environment (func_obj_p));
JERRY_ASSERT(ecma_op_is_callable (ecma_make_object_value (func_obj_p)));
JERRY_ASSERT(arguments_list_len == 0 || arguments_list_p != NULL);
if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION)
{
if (unlikely (ecma_get_object_is_builtin (func_obj_p)))
{
return ecma_builtin_dispatch_call (func_obj_p, this_arg_value, arguments_list_p, arguments_list_len);
}
ecma_completion_value_t ret_value;
/* Entering Function Code (ECMA-262 v5, 10.4.3) */
ecma_property_t *scope_prop_p = ecma_get_internal_property (func_obj_p, ECMA_INTERNAL_PROPERTY_SCOPE);
ecma_property_t *code_prop_p = ecma_get_internal_property (func_obj_p, ECMA_INTERNAL_PROPERTY_CODE);
ecma_object_t *scope_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t,
scope_prop_p->u.internal_property.value);
uint32_t code_prop_value = code_prop_p->u.internal_property.value;
bool is_strict;
// 8.
opcode_counter_t code_first_opcode_idx = ecma_unpack_code_internal_property_value (code_prop_value, &is_strict);
ecma_value_t this_binding;
// 1.
if (is_strict)
{
this_binding = ecma_copy_value (this_arg_value, true);
}
else if (ecma_is_value_undefined (this_arg_value)
|| ecma_is_value_null (this_arg_value))
{
// 2.
this_binding = ecma_make_object_value (ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL));
}
else
{
// 3., 4.
ecma_completion_value_t completion = ecma_op_to_object (this_arg_value);
JERRY_ASSERT (ecma_is_completion_value_normal (completion));
this_binding = ecma_get_completion_value_value (completion);
}
// 5.
ecma_object_t *local_env_p = ecma_create_decl_lex_env (scope_p);
// 9.
ECMA_TRY_CATCH (args_var_declaration_ret,
ecma_function_call_setup_args_variables (func_obj_p,
local_env_p,
arguments_list_p,
arguments_list_len,
is_strict),
ret_value);
ecma_completion_value_t completion = run_int_from_pos (code_first_opcode_idx,
this_binding,
local_env_p,
is_strict,
false);
if (ecma_is_completion_value_return (completion))
{
ret_value = ecma_make_normal_completion_value (ecma_get_completion_value_value (completion));
}
else
{
ret_value = completion;
}
ECMA_FINALIZE (args_var_declaration_ret);
ecma_deref_object (local_env_p);
ecma_free_value (this_binding, true);
return ret_value;
}
else if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION)
{
return ecma_builtin_dispatch_call (func_obj_p, this_arg_value, arguments_list_p, arguments_list_len);
}
else
{
JERRY_ASSERT(ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
JERRY_UNIMPLEMENTED ("Bound functions are not implemented.");
}
} /* ecma_op_function_call */
/**
* [[Construct]] implementation for Function objects,
* created through 13.2 (ECMA_OBJECT_TYPE_FUNCTION)
* or 15.3.4.5 (ECMA_OBJECT_TYPE_BOUND_FUNCTION).
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
const ecma_value_t* arguments_list_p, /**< arguments list */
ecma_length_t arguments_list_len) /**< length of arguments list */
{
JERRY_ASSERT(func_obj_p != NULL
&& !ecma_is_lexical_environment (func_obj_p));
JERRY_ASSERT(ecma_is_constructor (ecma_make_object_value (func_obj_p)));
JERRY_ASSERT(arguments_list_len == 0 || arguments_list_p != NULL);
if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION)
{
if (unlikely (ecma_get_object_is_builtin (func_obj_p)))
{
return ecma_builtin_dispatch_construct (func_obj_p, arguments_list_p, arguments_list_len);
}
ecma_completion_value_t ret_value;
ecma_string_t *prototype_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_PROTOTYPE);
// 5.
ECMA_TRY_CATCH (func_obj_prototype_prop_value,
ecma_op_object_get (func_obj_p,
prototype_magic_string_p),
ret_value);
// 6.
ecma_object_t *prototype_p;
if (ecma_is_value_object (func_obj_prototype_prop_value))
{
prototype_p = ecma_get_object_from_value (func_obj_prototype_prop_value);
ecma_ref_object (prototype_p);
}
else
{
// 7.
prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
}
// 1., 2., 4.
ecma_object_t *obj_p = ecma_create_object (prototype_p, true, ECMA_OBJECT_TYPE_GENERAL);
// 3.
ecma_property_t *class_prop_p = ecma_create_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_CLASS);
class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_FUNCTION_UL;
ecma_deref_object (prototype_p);
// 8.
ECMA_TRY_CATCH (call_completion,
ecma_op_function_call (func_obj_p,
ecma_make_object_value (obj_p),
arguments_list_p,
arguments_list_len),
ret_value);
ecma_value_t obj_value;
// 9.
if (ecma_is_value_object (call_completion))
{
ecma_deref_object (obj_p);
obj_value = ecma_copy_value (call_completion, true);
}
else
{
// 10.
obj_value = ecma_make_object_value (obj_p);
}
ret_value = ecma_make_normal_completion_value (obj_value);
ECMA_FINALIZE (call_completion);
ECMA_FINALIZE (func_obj_prototype_prop_value);
ecma_deref_ecma_string (prototype_magic_string_p);
return ret_value;
}
else
{
JERRY_ASSERT(ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
JERRY_UNIMPLEMENTED ("Bound functions are not implemented.");
}
} /* ecma_op_function_construct */
/**
* Function declaration.
*
* See also: ECMA-262 v5, 10.5 - Declaration binding instantiation (block 5).
*
* @return completion value
* returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *function_name_p, /**< function name */
opcode_counter_t function_code_opcode_idx, /**< index of first opcode of function code */
ecma_string_t* formal_parameter_list_p[], /**< formal parameters list */
ecma_length_t formal_parameter_list_length, /**< length of formal parameters list */
bool is_strict, /**< flag indicating if function is declared in strict mode code */
bool is_configurable_bindings) /**< flag indicating whether function
is declared in eval code */
{
// b.
ecma_object_t *func_obj_p = ecma_op_create_function_object (formal_parameter_list_p,
formal_parameter_list_length,
lex_env_p,
is_strict,
function_code_opcode_idx);
// c.
bool func_already_declared = ecma_op_has_binding (lex_env_p, function_name_p);
// d.
ecma_completion_value_t completion = ecma_make_empty_completion_value ();
if (!func_already_declared)
{
completion = ecma_op_create_mutable_binding (lex_env_p,
function_name_p,
is_configurable_bindings);
JERRY_ASSERT (ecma_is_completion_value_empty (completion));
}
else if (ecma_is_lexical_environment_global (lex_env_p))
{
// e.
ecma_object_t *glob_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
ecma_property_t *existing_prop_p = ecma_op_object_get_property (glob_obj_p, function_name_p);
if (ecma_is_property_configurable (existing_prop_p))
{
ecma_property_descriptor_t property_desc = ecma_make_empty_property_descriptor ();
{
property_desc.is_value_defined = true;
property_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
property_desc.is_writable_defined = true;
property_desc.is_writable = true;
property_desc.is_enumerable_defined = true;
property_desc.is_enumerable = true;
property_desc.is_configurable_defined = true;
property_desc.is_configurable = is_configurable_bindings;
}
completion = ecma_op_object_define_own_property (glob_obj_p,
function_name_p,
&property_desc,
true);
}
else if (existing_prop_p->type == ECMA_PROPERTY_NAMEDACCESSOR)
{
completion = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
JERRY_ASSERT (existing_prop_p->type == ECMA_PROPERTY_NAMEDDATA);
if (!ecma_is_property_writable (existing_prop_p)
|| !ecma_is_property_enumerable (existing_prop_p))
{
completion = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
}
ecma_deref_object (glob_obj_p);
}
ecma_completion_value_t ret_value;
if (ecma_is_completion_value_throw (completion))
{
ret_value = completion;
}
else
{
JERRY_ASSERT (ecma_is_completion_value_empty (completion));
// f.
ret_value = ecma_op_set_mutable_binding (lex_env_p,
function_name_p,
ecma_make_object_value (func_obj_p),
is_strict);
}
ecma_deref_object (func_obj_p);
return ret_value;
} /* ecma_op_function_declaration */
/**
* @}
* @}
*/
@@ -0,0 +1,68 @@
/* Copyright 2014-2015 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_FUNCTION_OBJECT_H
#define ECMA_FUNCTION_OBJECT_H
#include "ecma-globals.h"
#include "vm.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmafunctionobject ECMA Function object related routines
* @{
*/
extern bool ecma_op_is_callable (const ecma_value_t& value);
extern bool ecma_is_constructor (const ecma_value_t& value);
extern ecma_object_t*
ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[],
ecma_length_t formal_parameters_number,
ecma_object_t *scope_p,
bool is_strict,
opcode_counter_t first_opcode_idx);
extern ecma_completion_value_t
ecma_op_function_call (ecma_object_t *func_obj_p,
const ecma_value_t& this_arg_value,
const ecma_value_t* arguments_list_p,
ecma_length_t arguments_list_len);
extern ecma_completion_value_t
ecma_op_function_construct (ecma_object_t *func_obj_p,
const ecma_value_t* arguments_list_p,
ecma_length_t arguments_list_len);
extern ecma_completion_value_t
ecma_op_function_has_instance (ecma_object_t *func_obj_p,
const ecma_value_t& value);
extern ecma_completion_value_t
ecma_op_function_declaration (ecma_object_t *lex_env_p,
ecma_string_t *function_name_p,
opcode_counter_t function_code_opcode_idx,
ecma_string_t* formal_parameter_list_p[],
ecma_length_t formal_parameter_list_length,
bool is_strict,
bool is_configurable_bindings);
/**
* @}
* @}
*/
#endif /* !ECMA_FUNCTION_OBJECT_H */
@@ -0,0 +1,310 @@
/* Copyright 2014-2015 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.
*/
/**
* Implementation of ECMA GetValue and PutValue
*/
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-helpers.h"
#include "ecma-lex-env.h"
#include "ecma-objects.h"
#include "ecma-function-object.h"
#include "ecma-objects-general.h"
#include "ecma-operations.h"
#include "ecma-try-catch-macro.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmaoperations ECMA-defined operations
* @{
*/
/**
* GetValue operation part (lexical environment base or unresolvable reference).
*
* See also: ECMA-262 v5, 8.7.1, sections 3 and 5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_get_value_lex_env_base (ecma_object_t *ref_base_lex_env_p, /**< reference's base (lexical environment) */
ecma_string_t *var_name_string_p, /**< variable name */
bool is_strict) /**< flag indicating strict mode */
{
const bool is_unresolvable_reference = (ref_base_lex_env_p == NULL);
// 3.
if (unlikely (is_unresolvable_reference))
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE));
}
// 5.
JERRY_ASSERT(ref_base_lex_env_p != NULL
&& ecma_is_lexical_environment (ref_base_lex_env_p));
// 5.a
return ecma_op_get_binding_value (ref_base_lex_env_p,
var_name_string_p,
is_strict);
} /* ecma_op_get_value_lex_env_base */
/**
* GetValue operation part (object base).
*
* See also: ECMA-262 v5, 8.7.1, section 4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_get_value_object_base (ecma_reference_t ref) /**< ECMA-reference */
{
const ecma_value_t base = ref.base;
const bool is_unresolvable_reference = ecma_is_value_undefined (base);
const bool has_primitive_base = (ecma_is_value_boolean (base)
|| ecma_is_value_number (base)
|| ecma_is_value_string (base));
const bool has_object_base = (ecma_is_value_object (base)
&& !(ecma_is_lexical_environment (ecma_get_object_from_value (base))));
const bool is_property_reference = has_primitive_base || has_object_base;
JERRY_ASSERT (!is_unresolvable_reference);
JERRY_ASSERT (is_property_reference);
// 4.a
if (!has_primitive_base)
{
// 4.b case 1
ecma_object_t *obj_p = ecma_get_object_from_value (base);
JERRY_ASSERT(obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
return ecma_op_object_get (obj_p, ECMA_GET_NON_NULL_POINTER (ecma_string_t,
ref.referenced_name_cp));
}
else
{
// 4.b case 2
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (obj_base, ecma_op_to_object (base), ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_base);
JERRY_ASSERT (obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
ret_value = ecma_op_object_get (obj_p, ECMA_GET_NON_NULL_POINTER (ecma_string_t,
ref.referenced_name_cp));
ECMA_FINALIZE (obj_base);
return ret_value;
}
} /* ecma_op_get_value_object_base */
/**
* PutValue operation part (lexical environment base or unresolvable reference).
*
* See also: ECMA-262 v5, 8.7.2, sections 3 and 5
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_put_value_lex_env_base (ecma_object_t *ref_base_lex_env_p, /**< reference's base (lexical environment) */
ecma_string_t *var_name_string_p, /**< variable name */
bool is_strict, /**< flag indicating strict mode */
const ecma_value_t& value) /**< ECMA-value */
{
const bool is_unresolvable_reference = (ref_base_lex_env_p == NULL);
// 3.
if (unlikely (is_unresolvable_reference))
{
// 3.a.
if (is_strict)
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE));
}
else
{
// 3.b.
ecma_object_t *global_object_p = ecma_builtin_get (ECMA_BUILTIN_ID_GLOBAL);
ecma_completion_value_t completion = ecma_op_object_put (global_object_p,
var_name_string_p,
value,
false);
ecma_deref_object (global_object_p);
JERRY_ASSERT(ecma_is_completion_value_normal_true (completion)
|| ecma_is_completion_value_normal_false (completion));
return ecma_make_empty_completion_value ();
}
}
// 5.
JERRY_ASSERT(ref_base_lex_env_p != NULL
&& ecma_is_lexical_environment (ref_base_lex_env_p));
// 5.a
return ecma_op_set_mutable_binding (ref_base_lex_env_p,
var_name_string_p,
value,
is_strict);
} /* ecma_op_put_value_lex_env_base */
/**
* Reject sequence for PutValue
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
static ecma_completion_value_t
ecma_reject_put (bool is_throw) /**< Throw flag */
{
if (is_throw)
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
else
{
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_EMPTY);
}
} /* ecma_reject_put */
/**
* PutValue operation part (object base).
*
* See also: ECMA-262 v5, 8.7.2, section 4
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_put_value_object_base (ecma_reference_t ref, /**< ECMA-reference */
const ecma_value_t& value) /**< ECMA-value */
{
const ecma_value_t base = ref.base;
const bool is_unresolvable_reference = ecma_is_value_undefined (base);
const bool has_primitive_base = (ecma_is_value_boolean (base)
|| ecma_is_value_number (base)
|| ecma_is_value_string (base));
const bool has_object_base = (ecma_is_value_object (base)
&& !(ecma_is_lexical_environment (ecma_get_object_from_value (base))));
const bool is_property_reference = has_primitive_base || has_object_base;
JERRY_ASSERT (!is_unresolvable_reference);
JERRY_ASSERT (is_property_reference);
// 4.a
if (!has_primitive_base)
{
// 4.b case 1
ecma_object_t *obj_p = ecma_get_object_from_value (base);
JERRY_ASSERT (obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (put_ret_value,
ecma_op_object_put (obj_p,
ECMA_GET_NON_NULL_POINTER (ecma_string_t,
ref.referenced_name_cp),
value,
ref.is_strict),
ret_value);
ret_value = ecma_make_empty_completion_value ();
ECMA_FINALIZE (put_ret_value);
return ret_value;
}
else
{
// 4.b case 2
ecma_completion_value_t ret_value;
// sub_1.
ECMA_TRY_CATCH (obj_base, ecma_op_to_object (base), ret_value);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_base);
JERRY_ASSERT (obj_p != NULL
&& !ecma_is_lexical_environment (obj_p));
ecma_string_t *referenced_name_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
ref.referenced_name_cp);
// sub_2.
if (!ecma_op_object_can_put (obj_p, referenced_name_p))
{
ret_value = ecma_reject_put (ref.is_strict);
}
else
{
// sub_3.
ecma_property_t *own_prop_p = ecma_op_object_get_own_property (obj_p, referenced_name_p);
// sub_5.
ecma_property_t *prop_p = ecma_op_object_get_property (obj_p, referenced_name_p);
// sub_4., sub_7
if ((own_prop_p != NULL
&& own_prop_p->type == ECMA_PROPERTY_NAMEDDATA)
|| (prop_p == NULL)
|| (prop_p->type != ECMA_PROPERTY_NAMEDACCESSOR))
{
ret_value = ecma_reject_put (ref.is_strict);
}
else
{
// sub_6.
JERRY_ASSERT (prop_p != NULL && prop_p->type == ECMA_PROPERTY_NAMEDACCESSOR);
ecma_object_t *setter_p = ECMA_GET_NON_NULL_POINTER(ecma_object_t,
prop_p->u.named_accessor_property.set_p);
JERRY_ASSERT (setter_p != NULL);
ECMA_TRY_CATCH (call_ret,
ecma_op_function_call (setter_p, base, &value, 1),
ret_value);
ret_value = ecma_make_empty_completion_value ();
ECMA_FINALIZE (call_ret);
}
}
ECMA_FINALIZE (obj_base);
return ret_value;
}
} /* ecma_op_put_value_object_base */
/**
* @}
* @}
*/
@@ -0,0 +1,62 @@
/* Copyright 2014-2015 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-builtins.h"
#include "ecma-helpers.h"
#include "ecma-gc.h"
#include "ecma-lcache.h"
#include "ecma-operations.h"
#include "ecma-stack.h"
#include "mem-allocator.h"
/** \addtogroup ecma ECMA
* @{
*
* \addtogroup ecmainitfinalize Initialization and finalization of ECMA components
* @{
*/
/**
* Initialize ECMA components
*/
void
ecma_init (void)
{
ecma_strings_init ();
ecma_init_builtins ();
ecma_lcache_init ();
ecma_stack_init ();
mem_register_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
} /* ecma_init */
/**
* Finalize ECMA components
*/
void
ecma_finalize (void)
{
mem_unregister_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
ecma_stack_finalize ();
ecma_finalize_builtins ();
ecma_lcache_invalidate_all ();
ecma_gc_run ((ecma_gc_gen_t) (ECMA_GC_GEN_COUNT - 1));
} /* ecma_finalize */
/**
* @}
* @}
*/
+475
View File
@@ -0,0 +1,475 @@
/* Copyright 2014-2015 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-builtins.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-lex-env.h"
#include "ecma-objects.h"
#include "jrt.h"
/** \addtogroup ecma ECMA
* @{
*/
/**
* \addtogroup lexicalenvironment Lexical environment
* @{
*/
/**
* HasBinding operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return true / false
*/
bool
ecma_op_has_binding (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *name_p) /**< argument N */
{
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
{
ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p);
return (property_p != NULL);
}
else
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
return (ecma_op_object_get_property (binding_obj_p, name_p) != NULL);
}
} /* ecma_op_has_binding */
/**
* CreateMutableBinding operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
ecma_op_create_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *name_p, /**< argument N */
bool is_deletable) /**< argument D */
{
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
JERRY_ASSERT(name_p != NULL);
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
{
ecma_create_named_data_property (lex_env_p,
name_p,
true, false, is_deletable);
}
else
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
ecma_property_descriptor_t prop_desc = ecma_make_empty_property_descriptor ();
{
prop_desc.is_value_defined = true;
prop_desc.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
prop_desc.is_writable_defined = true;
prop_desc.is_writable = true;
prop_desc.is_enumerable_defined = true;
prop_desc.is_enumerable = true;
prop_desc.is_configurable_defined = true;
prop_desc.is_configurable = is_deletable;
}
ecma_completion_value_t completion = ecma_op_object_define_own_property (binding_obj_p,
name_p,
&prop_desc,
true);
if (ecma_is_completion_value_throw (completion))
{
return completion;
}
else
{
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)
|| ecma_is_completion_value_normal_false (completion));
}
}
return ecma_make_empty_completion_value ();
} /* ecma_op_create_mutable_binding */
/**
* SetMutableBinding operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_set_mutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *name_p, /**< argument N */
const ecma_value_t& value, /**< argument V */
bool is_strict) /**< argument S */
{
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
JERRY_ASSERT(name_p != NULL);
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
{
#ifndef JERRY_NDEBUG
# ifdef CONFIG_ECMA_COMPACT_PROFILE
bool is_equal = false;
ecma_string_t *arguments_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ARGUMENTS);
if (ecma_compare_ecma_strings (name_p, arguments_magic_string_p))
{
is_equal = true;
}
ecma_deref_ecma_string (arguments_magic_string_p);
JERRY_ASSERT (!is_equal);
if (is_equal)
{
return ecma_make_throw_obj_completion_value (ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR));
}
# endif /* CONFIG_ECMA_COMPACT_PROFILE */
#endif /* !JERRY_NDEBUG */
ecma_property_t *property_p = ecma_get_named_data_property (lex_env_p, name_p);
if (ecma_is_property_writable (property_p))
{
ecma_named_data_property_assign_value (lex_env_p, property_p, value);
}
else if (is_strict)
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
}
}
else
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
ecma_completion_value_t completion = ecma_op_object_put (binding_obj_p,
name_p,
value,
is_strict);
if (ecma_is_completion_value_throw (completion))
{
return completion;
}
else
{
JERRY_ASSERT (ecma_is_completion_value_normal_true (completion)
|| ecma_is_completion_value_normal_false (completion));
}
}
return ecma_make_empty_completion_value ();
} /* ecma_op_set_mutable_binding */
/**
* GetBindingValue operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_get_binding_value (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *name_p, /**< argument N */
bool is_strict) /**< argument S */
{
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
JERRY_ASSERT(name_p != NULL);
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
{
#ifndef JERRY_NDEBUG
# ifdef CONFIG_ECMA_COMPACT_PROFILE
bool is_equal = false;
ecma_string_t *arguments_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_ARGUMENTS);
if (ecma_compare_ecma_strings (name_p, arguments_magic_string_p))
{
is_equal = true;
}
ecma_deref_ecma_string (arguments_magic_string_p);
JERRY_ASSERT (!is_equal);
if (is_equal)
{
return ecma_make_throw_obj_completion_value (ecma_builtin_get (ECMA_BUILTIN_ID_COMPACT_PROFILE_ERROR));
}
# endif /* CONFIG_ECMA_COMPACT_PROFILE */
#endif /* !JERRY_NDEBUG */
ecma_property_t *property_p = ecma_get_named_data_property (lex_env_p, name_p);
ecma_value_t prop_value = ecma_get_named_data_property_value (property_p);
/* is the binding mutable? */
if (!ecma_is_property_writable (property_p)
&& ecma_is_value_empty (prop_value))
{
/* unitialized immutable binding */
if (is_strict)
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE));
}
else
{
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
}
return ecma_make_normal_completion_value (ecma_copy_value (prop_value, true));
}
else
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
if (ecma_op_object_get_property (binding_obj_p, name_p) == NULL)
{
if (is_strict)
{
return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_REFERENCE));
}
else
{
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
}
return ecma_op_object_get (binding_obj_p, name_p);
}
} /* ecma_op_get_binding_value */
/**
* DeleteBinding operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Return value is simple and so need not be freed.
* However, ecma_free_completion_value may be called for it, but it is a no-op.
*/
ecma_completion_value_t
ecma_op_delete_binding (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *name_p) /**< argument N */
{
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
JERRY_ASSERT(name_p != NULL);
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
{
ecma_property_t *prop_p = ecma_find_named_property (lex_env_p, name_p);
ecma_simple_value_t ret_val;
if (prop_p == NULL)
{
ret_val = ECMA_SIMPLE_VALUE_TRUE;
}
else
{
JERRY_ASSERT(prop_p->type == ECMA_PROPERTY_NAMEDDATA);
if (!ecma_is_property_configurable (prop_p))
{
ret_val = ECMA_SIMPLE_VALUE_FALSE;
}
else
{
ecma_delete_property (lex_env_p, prop_p);
ret_val = ECMA_SIMPLE_VALUE_TRUE;
}
}
return ecma_make_simple_completion_value (ret_val);
}
else
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
return ecma_op_object_delete (binding_obj_p, name_p, false);
}
} /* ecma_op_delete_binding */
/**
* ImplicitThisValue operation.
*
* See also: ECMA-262 v5, 10.2.1
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value.
*/
ecma_completion_value_t
ecma_op_implicit_this_value (ecma_object_t *lex_env_p) /**< lexical environment */
{
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
if (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE)
{
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
else
{
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND);
if (ecma_get_lex_env_provide_this (lex_env_p))
{
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
ecma_ref_object (binding_obj_p);
return ecma_make_normal_completion_value (ecma_make_object_value (binding_obj_p));
}
else
{
return ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
}
} /* ecma_op_implicit_this_value */
/**
* CreateImmutableBinding operation.
*
* See also: ECMA-262 v5, 10.2.1
*/
void
ecma_op_create_immutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *name_p) /**< argument N */
{
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
/*
* Warning:
* Whether immutable bindings are deletable seems not to be defined by ECMA v5.
*/
ecma_property_t *prop_p = ecma_create_named_data_property (lex_env_p,
name_p,
false, false, false);
JERRY_ASSERT(ecma_is_value_undefined (ecma_get_named_data_property_value (prop_p)));
ecma_set_named_data_property_value (prop_p,
ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY));
} /* ecma_op_create_immutable_binding */
/**
* InitializeImmutableBinding operation.
*
* See also: ECMA-262 v5, 10.2.1
*/
void
ecma_op_initialize_immutable_binding (ecma_object_t *lex_env_p, /**< lexical environment */
ecma_string_t *name_p, /**< argument N */
const ecma_value_t& value) /**< argument V */
{
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
ecma_property_t *prop_p = ecma_get_named_data_property (lex_env_p, name_p);
/* The binding must be unitialized immutable binding */
JERRY_ASSERT(!ecma_is_property_writable (prop_p)
&& ecma_is_value_empty (ecma_get_named_data_property_value (prop_p)));
ecma_named_data_property_assign_value (lex_env_p, prop_p, value);
} /* ecma_op_initialize_immutable_binding */
/**
* The Global Environment constructor.
*
* See also: ECMA-262 v5, 10.2.3
*
* @return pointer to created lexical environment
*/
ecma_object_t*
ecma_op_create_global_environment (ecma_object_t *glob_obj_p) /**< the Global object */
{
#ifdef CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE
(void) glob_obj_p;
ecma_object_t *glob_env_p = ecma_create_decl_lex_env (NULL);
#else /* !CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE */
ecma_object_t *glob_env_p = ecma_create_object_lex_env (NULL, glob_obj_p, false);
#endif /* !CONFIG_ECMA_GLOBAL_ENVIRONMENT_DECLARATIVE */
return glob_env_p;
} /* ecma_op_create_global_environment */
/**
* Figure out whether the lexical environment is global.
*
* @return true - if lexical environment is object-bound and corresponding object is global object,
* false - otherwise.
*/
bool
ecma_is_lexical_environment_global (ecma_object_t *lex_env_p) /**< lexical environment */
{
JERRY_ASSERT(lex_env_p != NULL
&& ecma_is_lexical_environment (lex_env_p));
ecma_lexical_environment_type_t type = ecma_get_lex_env_type (lex_env_p);
if (type == ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND)
{
ecma_object_t *binding_obj_p = ecma_get_lex_env_binding_object (lex_env_p);
return ecma_builtin_is (binding_obj_p, ECMA_BUILTIN_ID_GLOBAL);
}
else
{
return false;
}
} /* ecma_is_lexical_environment_global */
/**
* @}
* @}
*/
+76
View File
@@ -0,0 +1,76 @@
/* Copyright 2014-2015 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_LEX_ENV_H
#define ECMA_LEX_ENV_H
#include "ecma-globals.h"
#include "ecma-reference.h"
#include "jrt.h"
/** \addtogroup ecma ECMA
* @{
*/
/**
* \addtogroup lexicalenvironment Lexical environment
* @{
*/
/* ECMA-262 v5, 8.7.1 and 8.7.2 */
extern ecma_completion_value_t ecma_op_get_value_lex_env_base (ecma_object_t *ref_base_lex_env_p,
ecma_string_t *var_name_string_p,
bool is_strict);
extern ecma_completion_value_t ecma_op_get_value_object_base (ecma_reference_t ref);
extern ecma_completion_value_t ecma_op_put_value_lex_env_base (ecma_object_t *ref_base_lex_env_p,
ecma_string_t *var_name_string_p,
bool is_strict,
const ecma_value_t& value);
extern ecma_completion_value_t ecma_op_put_value_object_base (ecma_reference_t ref,
const ecma_value_t& value);
/* ECMA-262 v5, Table 17. Abstract methods of Environment Records */
extern bool ecma_op_has_binding (ecma_object_t *lex_env_p,
ecma_string_t *name_p);
extern ecma_completion_value_t ecma_op_create_mutable_binding (ecma_object_t *lex_env_p,
ecma_string_t *name_p,
bool is_deletable);
extern ecma_completion_value_t ecma_op_set_mutable_binding (ecma_object_t *lex_env_p,
ecma_string_t *name_p,
const ecma_value_t& value,
bool is_strict);
extern ecma_completion_value_t ecma_op_get_binding_value (ecma_object_t *lex_env_p,
ecma_string_t *name_p,
bool is_strict);
extern ecma_completion_value_t ecma_op_delete_binding (ecma_object_t *lex_env_p,
ecma_string_t *name_p);
extern ecma_completion_value_t ecma_op_implicit_this_value (ecma_object_t *lex_env_p);
/* ECMA-262 v5, Table 18. Additional methods of Declarative Environment Records */
extern void ecma_op_create_immutable_binding (ecma_object_t *lex_env_p,
ecma_string_t *name_p);
extern void ecma_op_initialize_immutable_binding (ecma_object_t *lex_env_p,
ecma_string_t *name_p,
const ecma_value_t& value);
extern ecma_object_t* ecma_op_create_global_environment (ecma_object_t *glob_obj_p);
extern bool ecma_is_lexical_environment_global (ecma_object_t *lex_env_p);
/**
* @}
* @}
*/
#endif /* !ECMA_LEX_ENV_H */

Some files were not shown because too many files have changed in this diff Show More