diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index 08d7d3e887..4276bd006e 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -18,7 +18,7 @@ set(JERRY_CORE_NAME jerry-core) project (${JERRY_CORE_NAME} C) # Optional features -set(FEATURE_PROFILE "full" CACHE STRING "Profile types: full, minimal") +set(FEATURE_PROFILE "es5.1" CACHE STRING "Profile types: es5.1, minimal, es2015-subset") set(FEATURE_ERROR_MESSAGES OFF CACHE BOOL "Enable error messages?") set(FEATURE_VALGRIND OFF CACHE BOOL "Enable Valgrind support?") set(FEATURE_VALGRIND_FREYA OFF CACHE BOOL "Enable Valgrind-Freya support?") @@ -118,9 +118,12 @@ if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") endif() # Profile modes +set(CONFIG_DISABLE_ES2015 + CONFIG_DISABLE_ARRAYBUFFER_BUILTIN) # Minimal profile if(FEATURE_PROFILE STREQUAL "minimal") set(DEFINES_JERRY ${DEFINES_JERRY} + ${CONFIG_DISABLE_ES2015} CONFIG_DISABLE_NUMBER_BUILTIN CONFIG_DISABLE_STRING_BUILTIN CONFIG_DISABLE_BOOLEAN_BUILTIN @@ -131,7 +134,10 @@ if(FEATURE_PROFILE STREQUAL "minimal") CONFIG_DISABLE_DATE_BUILTIN CONFIG_DISABLE_REGEXP_BUILTIN CONFIG_DISABLE_ANNEXB_BUILTIN) -elseif(NOT FEATURE_PROFILE STREQUAL "full") +elseif(FEATURE_PROFILE STREQUAL "es5.1") + set(DEFINES_JERRY ${DEFINES_JERRY} + ${CONFIG_DISABLE_ES2015}) +elseif(NOT FEATURE_PROFILE STREQUAL "es2015-subset") message(FATAL_ERROR "FEATURE_PROFILE='${FEATURE_PROFILE}' isn't supported") endif() diff --git a/jerry-core/ecma/base/ecma-gc.c b/jerry-core/ecma/base/ecma-gc.c index 7adb41f401..3fbfb6676c 100644 --- a/jerry-core/ecma/base/ecma-gc.c +++ b/jerry-core/ecma/base/ecma-gc.c @@ -424,14 +424,14 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */ case LIT_MAGIC_STRING_STRING_UL: case LIT_MAGIC_STRING_NUMBER_UL: { - ecma_free_value (ext_object_p->u.class_prop.value); + ecma_free_value (ext_object_p->u.class_prop.u.value); break; } case LIT_MAGIC_STRING_DATE_UL: { ecma_number_t *num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, - ext_object_p->u.class_prop.value); + ext_object_p->u.class_prop.u.value); ecma_dealloc_number (num_p); break; } @@ -439,14 +439,22 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */ case LIT_MAGIC_STRING_REGEXP_UL: { ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t, - ext_object_p->u.class_prop.value); + ext_object_p->u.class_prop.u.value); if (bytecode_p != NULL) { ecma_bytecode_deref (bytecode_p); } break; } - +#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN + case LIT_MAGIC_STRING_ARRAY_BUFFER_UL: + { + ecma_length_t arraybuffer_length = ext_object_p->u.class_prop.u.length; + size_t size = sizeof (ecma_extended_object_t) + arraybuffer_length; + ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p, size); + return; + } +#endif /* CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */ default: { JERRY_UNREACHABLE (); diff --git a/jerry-core/ecma/base/ecma-globals.h b/jerry-core/ecma/base/ecma-globals.h index bd46dbc0b1..52355afce7 100644 --- a/jerry-core/ecma/base/ecma-globals.h +++ b/jerry-core/ecma/base/ecma-globals.h @@ -626,7 +626,14 @@ typedef struct struct { uint16_t class_id; /**< class id of the object */ - ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */ + /* + * Description of extra fields. These extra fields depends on the class_id. + */ + union + { + ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */ + uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */ + } u; } class_prop; /* diff --git a/jerry-core/ecma/base/ecma-helpers.c b/jerry-core/ecma/base/ecma-helpers.c index cba5bbecab..b78ebb6fcd 100644 --- a/jerry-core/ecma/base/ecma-helpers.c +++ b/jerry-core/ecma/base/ecma-helpers.c @@ -630,7 +630,9 @@ ecma_create_named_accessor_property (ecma_object_t *object_p, /**< object */ ecma_string_t *name_p, /**< property name */ ecma_object_t *get_p, /**< getter */ ecma_object_t *set_p, /**< setter */ - uint8_t prop_attributes) /**< property attributes */ + uint8_t prop_attributes, /**< property attributes */ + ecma_property_t **out_prop_p) /**< [out] the property is also returned + * if this field is non-NULL */ { JERRY_ASSERT (object_p != NULL && name_p != NULL); JERRY_ASSERT (ecma_find_named_property (object_p, name_p) == NULL); @@ -650,7 +652,7 @@ ecma_create_named_accessor_property (ecma_object_t *object_p, /**< object */ ECMA_SET_POINTER (value.getter_setter_pair.setter_p, set_p); #endif /* JERRY_CPOINTER_32_BIT */ - return ecma_create_property (object_p, name_p, type_and_flags, value, NULL); + return ecma_create_property (object_p, name_p, type_and_flags, value, out_prop_p); } /* ecma_create_named_accessor_property */ /** diff --git a/jerry-core/ecma/base/ecma-helpers.h b/jerry-core/ecma/base/ecma-helpers.h index bdfbaac6fc..c4ef4c04e0 100644 --- a/jerry-core/ecma/base/ecma-helpers.h +++ b/jerry-core/ecma/base/ecma-helpers.h @@ -281,7 +281,8 @@ extern ecma_value_t *ecma_get_internal_property (ecma_object_t *, ecma_internal_ extern ecma_property_value_t * ecma_create_named_data_property (ecma_object_t *, ecma_string_t *, uint8_t, ecma_property_t **); extern ecma_property_value_t * -ecma_create_named_accessor_property (ecma_object_t *, ecma_string_t *, ecma_object_t *, ecma_object_t *, uint8_t); +ecma_create_named_accessor_property (ecma_object_t *, ecma_string_t *, ecma_object_t *, + ecma_object_t *, uint8_t, ecma_property_t **); extern ecma_property_t * ecma_find_named_property (ecma_object_t *, ecma_string_t *); extern ecma_property_value_t * diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h index e7aa1683e2..7c0d537101 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h @@ -83,4 +83,5 @@ ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ecma_builtin_array_prototype_object_r #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE - +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h index 8a34739764..51437016bc 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h @@ -62,4 +62,5 @@ ROUTINE (LIT_MAGIC_STRING_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1) #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE - +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c new file mode 100644 index 0000000000..55802ac484 --- /dev/null +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c @@ -0,0 +1,141 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * 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-builtin-helpers.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" +#include "ecma-objects.h" +#include "ecma-arraybuffer-object.h" +#include "ecma-try-catch-macro.h" +#include "jrt.h" +#include "jrt-libc-includes.h" + +#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer-prototype.inc.h" +#define BUILTIN_UNDERSCORED_ID arraybuffer_prototype +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup arraybuffer prototype ECMA ArrayBuffer.prototype object built-in + * @{ + */ + +/** + * The ArrayBuffer.prototype.bytelength accessor + * + * See also: + * ES2015, 24.1.4.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg) /**< this argument */ +{ + if (ecma_is_value_object (this_arg)) + { + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (ecma_object_class_is (object_p, LIT_MAGIC_STRING_ARRAY_BUFFER_UL)) + { + ecma_length_t len = ecma_arraybuffer_get_length (object_p); + + return ecma_make_uint32_value (len); + } + } + + return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a ArrayBuffer object.")); +} /* ecma_builtin_arraybuffer_prototype_bytelength_getter */ + +/** + * The ArrayBuffer.prototype object's 'slice' routine + * + * See also: + * ES2015, 24.1.4.3 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< this argument */ + ecma_value_t arg1, /**< routine's first argument */ + ecma_value_t arg2) /**< routine's second argument */ +{ + if (!ecma_is_value_object (this_arg)) + { + return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not object.")); + } + + ecma_object_t *object_p = ecma_get_object_from_value (this_arg); + + if (!ecma_object_class_is (object_p, LIT_MAGIC_STRING_ARRAY_BUFFER_UL)) + { + return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an ArrayBuffer object.")); + } + + ecma_length_t len = ecma_arraybuffer_get_length (object_p); + + ecma_length_t start = 0, end = len; + + ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); + + ECMA_OP_TO_NUMBER_TRY_CATCH (start_num, + arg1, + ret_value); + + start = ecma_builtin_helper_array_index_normalize (start_num, len); + + if (!ecma_is_value_undefined (arg2)) + { + ECMA_OP_TO_NUMBER_TRY_CATCH (end_num, + arg2, + ret_value); + + end = ecma_builtin_helper_array_index_normalize (end_num, len); + + ECMA_OP_TO_NUMBER_FINALIZE (end_num); + } + + ECMA_OP_TO_NUMBER_FINALIZE (start_num); + + JERRY_ASSERT (start <= len && end <= len); + ecma_length_t new_len = (end >= start) ? (end - start) : 0; + ecma_object_t *new_arraybuffer_p = ecma_arraybuffer_new_object (new_len); + lit_utf8_byte_t *old_buf = ecma_arraybuffer_get_buffer (object_p); + lit_utf8_byte_t *new_buf = ecma_arraybuffer_get_buffer (new_arraybuffer_p); + + memcpy (new_buf, old_buf + start, new_len); + + return ecma_make_object_value (new_arraybuffer_p); +} /* ecma_builtin_arraybuffer_prototype_object_slice */ + +/** + * @} + * @} + * @} + */ + +#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h new file mode 100644 index 0000000000..02faf2ecd4 --- /dev/null +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h @@ -0,0 +1,66 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * 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 OBJECT_ID +# define OBJECT_ID(builtin_object_id) +#endif /* !OBJECT_ID */ + +#ifndef OBJECT_VALUE +# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes) +#endif /* !OBJECT_VALUE */ + +#ifndef NUMBER_VALUE +# define NUMBER_VALUE(name, number_value, prop_attributes) +#endif /* !NUMBER_VALUE */ + +#ifndef ROUTINE +# define ROUTINE(name, c_function_name, args_number, length_prop_value) +#endif /* !ROUTINE */ + +#ifndef ACCESSOR_READ_WRITE +# define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) +#endif /* !ROUTINE */ + +#ifndef ACCESSOR_READ_ONLY +# define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) +#endif /* !ACCESSOR_READ_ONLY */ + +/* Object identifier */ +OBJECT_ID (ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE) + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR, + ECMA_BUILTIN_ID_ARRAYBUFFER, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) + +/* Readonly accessor properties */ +ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL, + ecma_builtin_arraybuffer_prototype_bytelength_getter, + ECMA_PROPERTY_FIXED) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ +ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_arraybuffer_prototype_object_slice, 2, 2) + +#undef OBJECT_ID +#undef SIMPLE_VALUE +#undef NUMBER_VALUE +#undef STRING_VALUE +#undef OBJECT_VALUE +#undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.c b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.c new file mode 100644 index 0000000000..b792fcbcc0 --- /dev/null +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.c @@ -0,0 +1,103 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * 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-arraybuffer-object.h" +#include "ecma-try-catch-macro.h" +#include "jrt.h" + +#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN + +#define ECMA_BUILTINS_INTERNAL +#include "ecma-builtins-internal.h" + +#define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer.inc.h" +#define BUILTIN_UNDERSCORED_ID arraybuffer +#include "ecma-builtin-internal-routines-template.inc.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmabuiltins + * @{ + * + * \addtogroup string ECMA ArrayBuffer object built-in + * @{ + */ + +/** + * The ArrayBuffer object's 'isView' routine + * + * See also: + * ES2015 24.1.3.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value. + */ +static ecma_value_t +ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argument */ + ecma_value_t arg) /**< argument 1 */ +{ + JERRY_UNUSED (this_arg); + JERRY_UNUSED (arg); + + /* TODO: if arg has [[ViewArrayBuffer]], return true */ + + return ecma_make_boolean_value (false); +} /* ecma_builtin_arraybuffer_object_is_view */ + +/** + * Handle calling [[Call]] of built-in ArrayBuffer object + * + * ES2015 24.1.2 ArrayBuffer is not intended to be called as + * a function and will throw an exception when called in + * that manner. + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_arraybuffer_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_raise_type_error (ECMA_ERR_MSG ("Constructor ArrayBuffer requires 'new'")); +} /* ecma_builtin_arraybuffer_dispatch_call */ + +/** + * Handle calling [[Construct]] of built-in ArrayBuffer object + * + * @return ecma value + */ +ecma_value_t +ecma_builtin_arraybuffer_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_arraybuffer_object (arguments_list_p, arguments_list_len); +} /* ecma_builtin_arraybuffer_dispatch_construct */ + +/** + * @} + * @} + * @} + */ + +#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */ diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h new file mode 100644 index 0000000000..af52746a0b --- /dev/null +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h @@ -0,0 +1,66 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * 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. + */ + +/* + * ArrayBuffer 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_attributes) +#endif /* !NUMBER_VALUE */ + +#ifndef OBJECT_VALUE +# define OBJECT_VALUE(name, obj_builtin_id, prop_attributes) +#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_ARRAYBUFFER) + +/* Number properties: + * (property name, number value, writable, enumerable, configurable) */ + +NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, + 1, + ECMA_PROPERTY_FIXED) + +/* Object properties: + * (property name, object pointer getter) */ + +OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, + ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE, + ECMA_PROPERTY_FIXED) + +/* Routine properties: + * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ + +/* ES2015 24.1.3.1 */ +ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1) + +#undef OBJECT_ID +#undef SIMPLE_VALUE +#undef NUMBER_VALUE +#undef STRING_VALUE +#undef OBJECT_VALUE +#undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.c index fd48124190..2eed584ce8 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.c @@ -106,9 +106,9 @@ ecma_builtin_boolean_prototype_object_value_of (ecma_value_t this_arg) /**< this { ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; - JERRY_ASSERT (ecma_is_value_boolean (ext_object_p->u.class_prop.value)); + JERRY_ASSERT (ecma_is_value_boolean (ext_object_p->u.class_prop.u.value)); - return ext_object_p->u.class_prop.value; + return ext_object_p->u.class_prop.u.value; } } diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h index 39a291b560..2e70abe587 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h @@ -51,3 +51,5 @@ ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_boolean_prototype_object_va #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h index 709c742aa8..7e2f83f3d7 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h @@ -58,3 +58,5 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.c index fd6fe182b2..4e08dc6b73 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.c @@ -107,7 +107,7 @@ ecma_builtin_date_prototype_to_date_string (ecma_value_t this_arg) /**< this arg ecma_object_t *object_p = ecma_get_object_from_value (obj_this); ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, - ext_object_p->u.class_prop.value); + ext_object_p->u.class_prop.u.value); if (ecma_number_is_nan (*date_num_p)) { @@ -153,7 +153,7 @@ ecma_builtin_date_prototype_to_time_string (ecma_value_t this_arg) /**< this arg ecma_object_t *object_p = ecma_get_object_from_value (obj_this); ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; ecma_number_t *prim_value_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, - ext_object_p->u.class_prop.value); + ext_object_p->u.class_prop.u.value); if (ecma_number_is_nan (*prim_value_num_p)) { @@ -252,7 +252,7 @@ ecma_builtin_date_prototype_get_time (ecma_value_t this_arg) /**< this argument ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, - ext_object_p->u.class_prop.value); + ext_object_p->u.class_prop.u.value); return ecma_make_number_value (*date_num_p); } } @@ -356,7 +356,7 @@ ecma_builtin_date_prototype_set_time (ecma_value_t this_arg, /**< this argument ecma_object_t *object_p = ecma_get_object_from_value (this_arg); ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; ecma_number_t *date_num_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, - ext_object_p->u.class_prop.value); + ext_object_p->u.class_prop.u.value); *date_num_p = value; diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h index 432213c603..4c44b3ce84 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h @@ -95,3 +95,5 @@ ROUTINE (LIT_MAGIC_STRING_TO_GMT_STRING_UL, ecma_builtin_date_prototype_to_utc_s #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-date.c b/jerry-core/ecma/builtin-objects/ecma-builtin-date.c index c55e6cd837..6e570457e9 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-date.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-date.c @@ -553,7 +553,7 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**< ecma_number_t *date_num_p = ecma_alloc_number (); *date_num_p = prim_value_num; - ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.value, date_num_p); + ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.u.value, date_num_p); ret_value = ecma_make_object_value (obj_p); } diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h index 5e78efc8fd..20e74f9972 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h @@ -56,3 +56,5 @@ ROUTINE (LIT_MAGIC_STRING_NOW, ecma_builtin_date_now, 0, 0) #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.inc.h index e498b33bc6..0d23b413c6 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-error-prototype.inc.h @@ -64,3 +64,5 @@ ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_error_prototype_object_to_s #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-error.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-error.inc.h index 4a5886db51..5caeae78ee 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-error.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-error.inc.h @@ -58,3 +58,5 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.inc.h index ea2967cf9f..82cb02a1ee 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-prototype.inc.h @@ -56,3 +56,5 @@ STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.inc.h index 6032435a91..afde0f978c 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.inc.h @@ -58,3 +58,5 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h index bdb5287a92..46bfd72445 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h @@ -65,3 +65,5 @@ ROUTINE (LIT_MAGIC_STRING_BIND, ecma_builtin_function_prototype_object_bind, NON #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-function.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-function.inc.h index 6777cde637..854ea444e9 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-function.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-function.inc.h @@ -58,3 +58,5 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h index 96467ec23a..696d06b0d9 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h @@ -168,6 +168,12 @@ OBJECT_VALUE (LIT_MAGIC_STRING_JSON_U, ECMA_PROPERTY_CONFIGURABLE_WRITABLE) #endif /* !CONFIG_DISABLE_JSON_BUILTIN */ +#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN +OBJECT_VALUE (LIT_MAGIC_STRING_ARRAY_BUFFER_UL, + ECMA_BUILTIN_ID_ARRAYBUFFER, + ECMA_PROPERTY_CONFIGURABLE_WRITABLE) +#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */ + /* Routine properties: * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */ @@ -195,3 +201,5 @@ ROUTINE (LIT_MAGIC_STRING_UNESCAPE, ecma_builtin_global_object_unescape, 1, 1) #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c index 8d1ca49125..0dd1d7ad5d 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c @@ -900,7 +900,7 @@ ecma_date_set_internal_property (ecma_value_t this_arg, /**< this argument */ ecma_object_t *object_p = ecma_get_object_from_value (this_arg); ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; - *ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, ext_object_p->u.class_prop.value) = value; + *ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, ext_object_p->u.class_prop.u.value) = value; return ecma_make_number_value (value); } /* ecma_date_set_internal_property */ @@ -1300,7 +1300,7 @@ ecma_date_get_primitive_value (ecma_value_t this_arg) /**< this argument */ ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; ecma_number_t date_num = *ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t, - ext_object_p->u.class_prop.value); + ext_object_p->u.class_prop.u.value); ret_value = ecma_make_number_value (date_num); } diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h index 9c9038a42a..f04e547513 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-internal-routines-template.inc.h @@ -42,6 +42,11 @@ 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_value_t c_function_name (ROUTINE_ARG_LIST_ ## args_number); +#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \ + static ecma_value_t c_getter_func_name (ROUTINE_ARG_LIST_0); \ + static ecma_value_t c_setter_func_name (ROUTINE_ARG_LIST_1); +#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \ + static ecma_value_t c_getter_func_name (ROUTINE_ARG_LIST_0); #include BUILTIN_INC_HEADER_NAME #undef ROUTINE_ARG_LIST_NON_FIXED #undef ROUTINE_ARG_LIST_3 @@ -55,6 +60,11 @@ enum PASTE (ECMA_ROUTINE_START_, BUILTIN_UNDERSCORED_ID) = ECMA_BUILTIN_ID__COUNT - 1, #define ROUTINE(name, c_function_name, args_number, length_prop_value) \ ECMA_ROUTINE_ ## name ## c_function_name, +#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \ + ECMA_ACCESSOR_ ## name ## c_getter_func_name, \ + ECMA_ACCESSOR_ ## name ## c_setter_func_name, +#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \ + ECMA_ACCESSOR_ ## name ## c_getter_func_name, #include BUILTIN_INC_HEADER_NAME }; @@ -98,6 +108,20 @@ const ecma_builtin_property_descriptor_t PROPERTY_DESCRIPTOR_LIST_NAME[] = prop_attributes, \ magic_string_id \ }, +#define ACCESSOR_READ_WRITE(name, c_getter_name, c_setter_name, prop_attributes) \ + { \ + name, \ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE, \ + prop_attributes, \ + ECMA_ACCESSOR_READ_WRITE (ECMA_ACCESSOR_ ## name ## c_getter_name, ECMA_ACCESSOR_ ## name ## c_setter_name) \ + }, +#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \ + { \ + name, \ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY, \ + prop_attributes, \ + ECMA_ACCESSOR_ ## name ## c_getter_func_name \ + }, #include BUILTIN_INC_HEADER_NAME { LIT_MAGIC_STRING__COUNT, @@ -142,6 +166,20 @@ DISPATCH_ROUTINE_ROUTINE_NAME (uint16_t builtin_routine_id, /**< built-in wide r { \ return c_function_name (this_arg_value ROUTINE_ARG_LIST_ ## args_number); \ } +#define ACCESSOR_READ_WRITE(name, c_getter_func_name, c_setter_func_name, prop_attributes) \ + case ECMA_ACCESSOR_ ## name ## c_getter_func_name: \ + { \ + return c_getter_func_name(this_arg_value); \ + } \ + case ECMA_ACCESSOR_ ## name ## c_setter_func_name: \ + { \ + return c_setter_func_name(this_arg_value ROUTINE_ARG_LIST_1); \ + } +#define ACCESSOR_READ_ONLY(name, c_getter_func_name, prop_attributes) \ + case ECMA_ACCESSOR_ ## name ## c_getter_func_name: \ + { \ + return c_getter_func_name(this_arg_value); \ + } #include BUILTIN_INC_HEADER_NAME #undef ROUTINE_ARG #undef ROUTINE_ARG_LIST_0 diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-json.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-json.inc.h index 1e267eecbb..e48b53f89a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-json.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-json.inc.h @@ -52,3 +52,5 @@ ROUTINE (LIT_MAGIC_STRING_STRINGIFY, ecma_builtin_json_stringify, 3, 3) #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-math.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-math.inc.h index b80d37f0a5..f4684f0aad 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-math.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-math.inc.h @@ -110,3 +110,5 @@ ROUTINE (LIT_MAGIC_STRING_TAN, ecma_builtin_math_object_tan, 1, 1) #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.c index b1869a7c7c..8ce6077684 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.c @@ -457,9 +457,9 @@ ecma_builtin_number_prototype_object_value_of (ecma_value_t this_arg) /**< this { ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; - JERRY_ASSERT (ecma_is_value_number (ext_object_p->u.class_prop.value)); + JERRY_ASSERT (ecma_is_value_number (ext_object_p->u.class_prop.u.value)); - return ecma_copy_value (ext_object_p->u.class_prop.value); + return ecma_copy_value (ext_object_p->u.class_prop.u.value); } } diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.inc.h index 19f9f3d00d..ec2a354b15 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.inc.h @@ -55,3 +55,5 @@ ROUTINE (LIT_MAGIC_STRING_TO_PRECISION_UL, ecma_builtin_number_prototype_object_ #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-number.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-number.inc.h index ee21bac94c..2b70d296f0 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-number.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-number.inc.h @@ -79,3 +79,5 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.inc.h index 49469b9bf2..129e816d5a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.inc.h @@ -55,3 +55,5 @@ ROUTINE (LIT_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL, ecma_builtin_object_prototy #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h index 259f908a46..ca5ac3f7fd 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h @@ -74,3 +74,5 @@ ROUTINE (LIT_MAGIC_STRING_DEFINE_PROPERTY_UL, ecma_builtin_object_object_define_ #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.inc.h index 4aef51986b..1b2e7e68a7 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror-prototype.inc.h @@ -56,3 +56,5 @@ STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.inc.h index cf10f835c1..b976fbc377 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-rangeerror.inc.h @@ -58,3 +58,5 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.inc.h index 3d90067210..7fa35a4766 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror-prototype.inc.h @@ -56,3 +56,5 @@ STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.inc.h index 81aa673d14..0951a6ec5a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-referenceerror.inc.h @@ -58,3 +58,5 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c index 1d193b94b9..6fde04d7f6 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c @@ -130,7 +130,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this); /* Get bytecode property. */ - ecma_value_t *bc_prop_p = &(((ecma_extended_object_t *) this_obj_p)->u.class_prop.value); + ecma_value_t *bc_prop_p = &(((ecma_extended_object_t *) this_obj_p)->u.class_prop.u.value); /* TODO: We currently have to re-compile the bytecode, because * we can't copy it without knowing its length. */ @@ -205,7 +205,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this argument ECMA_TRY_CATCH (obj_this, ecma_op_to_object (this_arg), ret_value); ecma_object_t *this_obj_p = ecma_get_object_from_value (obj_this); - ecma_value_t *bc_prop_p = &(((ecma_extended_object_t *) this_obj_p)->u.class_prop.value); + ecma_value_t *bc_prop_p = &(((ecma_extended_object_t *) this_obj_p)->u.class_prop.u.value); /* Try to compile bytecode from new source. */ const re_compiled_code_t *new_bc_p = NULL; @@ -273,7 +273,7 @@ ecma_builtin_regexp_prototype_exec (ecma_value_t this_arg, /**< this argument */ ret_value); ecma_object_t *obj_p = ecma_get_object_from_value (obj_this); - ecma_value_t *bytecode_prop_p = &(((ecma_extended_object_t *) obj_p)->u.class_prop.value); + ecma_value_t *bytecode_prop_p = &(((ecma_extended_object_t *) obj_p)->u.class_prop.u.value); void *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (void, *bytecode_prop_p); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h index 2eb98995eb..fd5efe752b 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h @@ -88,3 +88,5 @@ ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_regexp_prototype_to_string, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h index cb76d3bce8..45bd6e28a5 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp.inc.h @@ -49,3 +49,5 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c index c16996f83f..5740513023 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c @@ -78,9 +78,9 @@ ecma_builtin_string_prototype_object_to_string (ecma_value_t this_arg) /**< this { ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; - JERRY_ASSERT (ecma_is_value_string (ext_object_p->u.class_prop.value)); + JERRY_ASSERT (ecma_is_value_string (ext_object_p->u.class_prop.u.value)); - return ecma_copy_value (ext_object_p->u.class_prop.value); + return ecma_copy_value (ext_object_p->u.class_prop.u.value); } } diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.inc.h index 425a4c4f80..683f009a0a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.inc.h @@ -88,3 +88,5 @@ ROUTINE (LIT_MAGIC_STRING_SUBSTR, ecma_builtin_string_prototype_object_substr, 2 #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h index 228b7ee5fe..c50bed03be 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string.inc.h @@ -62,3 +62,5 @@ ROUTINE (LIT_MAGIC_STRING_FROM_CHAR_CODE_UL, ecma_builtin_string_object_from_cha #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.inc.h index 46305f0138..eda1b5c295 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror-prototype.inc.h @@ -56,3 +56,5 @@ STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.inc.h index 8bb0e2a5cb..7922d8b047 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-syntaxerror.inc.h @@ -58,3 +58,5 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.inc.h index 436668d337..0242a04370 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-type-error-thrower.inc.h @@ -43,3 +43,5 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.inc.h index ee17da74a9..1c7b778ea5 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror-prototype.inc.h @@ -56,3 +56,5 @@ STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.inc.h index 2561f82f83..bab2ef79f1 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-typeerror.inc.h @@ -58,3 +58,5 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.inc.h index 4fd4095c8e..da1263959d 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-urierror-prototype.inc.h @@ -56,3 +56,5 @@ STRING_VALUE (LIT_MAGIC_STRING_MESSAGE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.inc.h index 755b45c91a..b93469845b 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-urierror.inc.h @@ -58,3 +58,5 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE, #undef STRING_VALUE #undef OBJECT_VALUE #undef ROUTINE +#undef ACCESSOR_READ_WRITE +#undef ACCESSOR_READ_ONLY diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h b/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h index 6b8ccf4d6f..ac12376d45 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtins-internal.h @@ -33,6 +33,8 @@ typedef enum ECMA_BUILTIN_PROPERTY_STRING, /**< string value property */ ECMA_BUILTIN_PROPERTY_OBJECT, /**< builtin object property */ ECMA_BUILTIN_PROPERTY_ROUTINE, /**< routine property */ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE, /**< full accessor property */ + ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY, /**< read-only accessor property */ ECMA_BUILTIN_PROPERTY_END, /**< last property */ } ecma_builtin_property_type_t; diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins.c b/jerry-core/ecma/builtin-objects/ecma-builtins.c index bf8732b29f..97ff3c0b3b 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtins.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtins.c @@ -162,7 +162,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */ ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_STRING_UL; ecma_string_t *prim_prop_str_value_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY); - ext_object_p->u.class_prop.value = ecma_make_string_value (prim_prop_str_value_p); + ext_object_p->u.class_prop.u.value = ecma_make_string_value (prim_prop_str_value_p); break; } #endif /* !CONFIG_DISABLE_STRING_BUILTIN */ @@ -174,7 +174,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */ ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_NUMBER_UL; - ext_object_p->u.class_prop.value = ecma_make_integer_value (0); + ext_object_p->u.class_prop.u.value = ecma_make_integer_value (0); break; } #endif /* !CONFIG_DISABLE_NUMBER_BUILTIN */ @@ -186,7 +186,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */ ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_BOOLEAN_UL; - ext_object_p->u.class_prop.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE); + ext_object_p->u.class_prop.u.value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE); break; } #endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */ @@ -201,7 +201,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */ ecma_number_t *prim_prop_num_value_p = ecma_alloc_number (); *prim_prop_num_value_p = ecma_number_make_nan (); - ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.value, prim_prop_num_value_p); + ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.u.value, prim_prop_num_value_p); break; } #endif /* !CONFIG_DISABLE_DATE_BUILTIN */ @@ -213,7 +213,7 @@ ecma_builtin_init_object (ecma_builtin_id_t obj_builtin_id, /**< built-in ID */ ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_REGEXP_UL; - ext_object_p->u.class_prop.value = ECMA_NULL_POINTER; + ext_object_p->u.class_prop.u.value = ECMA_NULL_POINTER; break; } #endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */ @@ -331,6 +331,32 @@ ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /** return func_obj_p; } /* ecma_builtin_make_function_object_for_routine */ +/** + * Construct a Function object for specified built-in accessor getter + * + * @return pointer to constructed accessor getter Function object + */ +static ecma_object_t * +ecma_builtin_make_function_object_for_getter_accessor (ecma_builtin_id_t builtin_id, /**< id of built-in object */ + uint16_t routine_id) /**< builtin-wide id of the built-in + * object's routine property */ +{ + return ecma_builtin_make_function_object_for_routine (builtin_id, routine_id, 0); +} /* ecma_builtin_make_function_object_for_getter_accessor */ + +/** + * Construct a Function object for specified built-in accessor setter + * + * @return pointer to constructed accessor getter Function object + */ +static ecma_object_t * +ecma_builtin_make_function_object_for_setter_accessor (ecma_builtin_id_t builtin_id, /**< id of built-in object */ + uint16_t routine_id) /**< builtin-wide id of the built-in + * object's routine property */ +{ + return ecma_builtin_make_function_object_for_routine (builtin_id, routine_id, 1); +} /* ecma_builtin_make_function_object_for_setter_accessor */ + typedef const ecma_builtin_property_descriptor_t *ecma_builtin_property_list_reference_t; static const ecma_builtin_property_list_reference_t ecma_builtin_property_list_references[] = @@ -468,6 +494,9 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object * } ecma_value_t value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY); + bool is_accessor = false; + ecma_object_t *getter_p = NULL; + ecma_object_t *setter_p = NULL; switch (curr_property_p->type) { @@ -551,6 +580,22 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object * value = ecma_make_object_value (func_obj_p); break; } + case ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_WRITE: + { + is_accessor = true; + uint16_t getter_id = ECMA_ACCESSOR_READ_WRITE_GET_GETTER_ID (curr_property_p->value); + uint16_t setter_id = ECMA_ACCESSOR_READ_WRITE_GET_SETTER_ID (curr_property_p->value); + getter_p = ecma_builtin_make_function_object_for_getter_accessor (builtin_id, getter_id); + setter_p = ecma_builtin_make_function_object_for_setter_accessor (builtin_id, setter_id); + break; + } + case ECMA_BUILTIN_PROPERTY_ACCESSOR_READ_ONLY: + { + is_accessor = true; + getter_p = ecma_builtin_make_function_object_for_getter_accessor (builtin_id, + curr_property_p->value); + break; + } default: { JERRY_UNREACHABLE (); @@ -559,17 +604,38 @@ ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p, /**< object * } ecma_property_t *prop_p; - ecma_property_value_t *prop_value_p = ecma_create_named_data_property (object_p, - string_p, - curr_property_p->attributes, - &prop_p); - prop_value_p->value = value; - - /* Reference count of objects must be decreased. */ - if (ecma_is_value_object (value)) + if (is_accessor) + { + ecma_create_named_accessor_property (object_p, + string_p, + getter_p, + setter_p, + curr_property_p->attributes, + &prop_p); + + if (setter_p) + { + ecma_deref_object (setter_p); + } + if (getter_p) + { + ecma_deref_object (getter_p); + } + } + else { - ecma_free_value (value); + ecma_property_value_t *prop_value_p = ecma_create_named_data_property (object_p, + string_p, + curr_property_p->attributes, + &prop_p); + prop_value_p->value = value; + + /* Reference count of objects must be decreased. */ + if (ecma_is_value_object (value)) + { + ecma_free_value (value); + } } return prop_p; diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins.h b/jerry-core/ecma/builtin-objects/ecma-builtins.h index c8835318db..5018917b77 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtins.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtins.h @@ -49,6 +49,21 @@ typedef enum */ #define ECMA_GET_ROUTINE_ID(value) ((uint16_t) ((value) >> 4)) +/** + * Construct a fully accessor value + */ +#define ECMA_ACCESSOR_READ_WRITE(getter, setter) (((getter) << 8) | (setter)) + +/** + * Get accessor setter ID + */ +#define ECMA_ACCESSOR_READ_WRITE_GET_SETTER_ID(value) ((uint16_t) ((value) & 0xff)) + +/** + * Get accessor getter ID + */ +#define ECMA_ACCESSOR_READ_WRITE_GET_GETTER_ID(value) ((uint16_t) ((value) >> 8)) + /* ecma-builtins.c */ extern void ecma_finalize_builtins (void); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h index c1fc334cfb..234709abb4 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h @@ -298,6 +298,25 @@ BUILTIN (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER, true, type_error_thrower) +#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN + +/* The ArrayBuffer.prototype object (ES2015 24.1.4) */ +BUILTIN (ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE, + ECMA_OBJECT_TYPE_GENERAL, + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, + true, + true, + arraybuffer_prototype) + +/* The ArrayBuffer object (ES2015 24.1.2) */ +BUILTIN (ECMA_BUILTIN_ID_ARRAYBUFFER, + ECMA_OBJECT_TYPE_FUNCTION, + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, + true, + true, + arraybuffer) +#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */ + /* The Global object (15.1) */ BUILTIN (ECMA_BUILTIN_ID_GLOBAL, ECMA_OBJECT_TYPE_GENERAL, diff --git a/jerry-core/ecma/operations/ecma-arraybuffer-object.c b/jerry-core/ecma/operations/ecma-arraybuffer-object.c new file mode 100644 index 0000000000..c366082045 --- /dev/null +++ b/jerry-core/ecma/operations/ecma-arraybuffer-object.c @@ -0,0 +1,123 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * 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-arraybuffer-object.h" +#include "ecma-conversion.h" +#include "ecma-objects.h" +#include "ecma-builtins.h" +#include "ecma-exceptions.h" +#include "ecma-gc.h" +#include "ecma-globals.h" +#include "ecma-helpers.h" + +#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaarraybufferobject ECMA ArrayBuffer object related routines + * @{ + */ + +/** + * ArrayBuffer object creation operation. + * + * See also: ES2015 24.1.1.1 + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_value_t +ecma_op_create_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< list of arguments that + * are passed to String constructor */ + ecma_length_t arguments_list_len) /**< length of the arguments' list */ +{ + JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + + uint32_t length = 0; + + if (arguments_list_len > 0) + { + ecma_number_t num = ecma_get_number_from_value (ecma_op_to_number (arguments_list_p[0])); + length = ecma_number_to_uint32 (num); + if (num != ((ecma_number_t) length)) + { + return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid ArrayBuffer length.")); + } + } + + ecma_object_t *object_p = ecma_arraybuffer_new_object (length); + + return ecma_make_object_value (object_p); +} /* ecma_op_create_arraybuffer_object */ + +/** + * Helper function: create arraybuffer object based on the array length + * + * The struct of arraybuffer object: + * ecma_object_t + * extend_part + * data buffer + * + * @return ecma value + * Returned value must be freed with ecma_free_value + */ +ecma_object_t * +ecma_arraybuffer_new_object (ecma_length_t length) /**< length of the arraybuffer */ +{ + ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE); + ecma_object_t *object_p = ecma_create_object (prototype_obj_p, + sizeof (ecma_extended_object_t) + length, + ECMA_OBJECT_TYPE_CLASS); + ecma_deref_object (prototype_obj_p); + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_ARRAY_BUFFER_UL; + ext_object_p->u.class_prop.u.length = length; + return object_p; +} /* ecma_arraybuffer_new_object */ + +/** + * Helper function: return the length of the buffer inside the arraybuffer object + * + * @return ecma_length_t, the length of the arraybuffer + */ +inline ecma_length_t __attr_pure___ __attr_always_inline___ +ecma_arraybuffer_get_length (ecma_object_t *object_p) /**< pointer to the ArrayBuffer object */ +{ + JERRY_ASSERT (ecma_object_class_is (object_p, LIT_MAGIC_STRING_ARRAY_BUFFER_UL)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + return ext_object_p->u.class_prop.u.length; +} /* ecma_arraybuffer_get_length */ + +/** + * Helper function: return the pointer to the data buffer inside the arraybuffer object + * + * @return pointer to the data buffer + */ +inline lit_utf8_byte_t * __attr_pure___ __attr_always_inline___ +ecma_arraybuffer_get_buffer (ecma_object_t *object_p) /**< pointer to the ArrayBuffer object */ +{ + JERRY_ASSERT (ecma_object_class_is (object_p, LIT_MAGIC_STRING_ARRAY_BUFFER_UL)); + + ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; + return (lit_utf8_byte_t *) (ext_object_p + 1); +} /* ecma_arraybuffer_get_buffer */ + +/** + * @} + * @} + */ +#endif /* !CONFIG_DISABLE_ARRAYBUFFER_BUILTIN */ diff --git a/jerry-core/ecma/operations/ecma-arraybuffer-object.h b/jerry-core/ecma/operations/ecma-arraybuffer-object.h new file mode 100644 index 0000000000..51dedc31d5 --- /dev/null +++ b/jerry-core/ecma/operations/ecma-arraybuffer-object.h @@ -0,0 +1,46 @@ +/* Copyright JS Foundation and other contributors, http://js.foundation + * + * 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_ARRAYBUFFER_OBJECT_H +#define ECMA_ARRAYBUFFER_OBJECT_H + +#include "ecma-globals.h" + +/** \addtogroup ecma ECMA + * @{ + * + * \addtogroup ecmaarraybufferobject ECMA Arraybuffer object related routines + * @{ + */ + +extern ecma_value_t +ecma_op_create_arraybuffer_object (const ecma_value_t *, ecma_length_t); + +/** + * Helper functions for arraybuffer. + */ +extern ecma_object_t * +ecma_arraybuffer_new_object (ecma_length_t); +extern lit_utf8_byte_t * +ecma_arraybuffer_get_buffer (ecma_object_t *) __attr_pure___ __attr_always_inline___; +extern ecma_length_t +ecma_arraybuffer_get_length (ecma_object_t *) __attr_pure___ __attr_always_inline___; + +/** + * @} + * @} + */ + +#endif /* !ECMA_ARRAYBUFFER_OBJECT_H */ diff --git a/jerry-core/ecma/operations/ecma-boolean-object.c b/jerry-core/ecma/operations/ecma-boolean-object.c index 57aa5f4d9b..0a59bc9faf 100644 --- a/jerry-core/ecma/operations/ecma-boolean-object.c +++ b/jerry-core/ecma/operations/ecma-boolean-object.c @@ -57,7 +57,7 @@ ecma_op_create_boolean_object (ecma_value_t arg) /**< argument passed to the Boo ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_BOOLEAN_UL; - ext_object_p->u.class_prop.value = ecma_make_boolean_value (boolean_value); + ext_object_p->u.class_prop.u.value = ecma_make_boolean_value (boolean_value); return ecma_make_object_value (object_p); } /* ecma_op_create_boolean_object */ diff --git a/jerry-core/ecma/operations/ecma-number-object.c b/jerry-core/ecma/operations/ecma-number-object.c index 5f924142c0..00b340ced6 100644 --- a/jerry-core/ecma/operations/ecma-number-object.c +++ b/jerry-core/ecma/operations/ecma-number-object.c @@ -64,7 +64,7 @@ ecma_op_create_number_object (ecma_value_t arg) /**< argument passed to the Numb ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_NUMBER_UL; /* Pass reference (no need to free conv_to_num_completion). */ - ext_object_p->u.class_prop.value = conv_to_num_completion; + ext_object_p->u.class_prop.u.value = conv_to_num_completion; return ecma_make_object_value (object_p); } /* ecma_op_create_number_object */ diff --git a/jerry-core/ecma/operations/ecma-objects-general.c b/jerry-core/ecma/operations/ecma-objects-general.c index 5b85ba99cc..e61dea6f7e 100644 --- a/jerry-core/ecma/operations/ecma-objects-general.c +++ b/jerry-core/ecma/operations/ecma-objects-general.c @@ -384,7 +384,8 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob property_name_p, property_desc_p->get_p, property_desc_p->set_p, - prop_attributes); + prop_attributes, + NULL); } return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE); diff --git a/jerry-core/ecma/operations/ecma-objects.c b/jerry-core/ecma/operations/ecma-objects.c index be2c2cbbb3..7f01817ea7 100644 --- a/jerry-core/ecma/operations/ecma-objects.c +++ b/jerry-core/ecma/operations/ecma-objects.c @@ -92,7 +92,7 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */ { if (options & ECMA_PROPERTY_GET_VALUE) { - ecma_value_t prim_value_p = ext_object_p->u.class_prop.value; + ecma_value_t prim_value_p = ext_object_p->u.class_prop.u.value; ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); ecma_length_t length = ecma_string_get_length (prim_value_str_p); @@ -106,7 +106,7 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */ if (index != ECMA_STRING_NOT_ARRAY_INDEX) { - ecma_value_t prim_value_p = ext_object_p->u.class_prop.value; + ecma_value_t prim_value_p = ext_object_p->u.class_prop.u.value; ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); if (index < ecma_string_get_length (prim_value_str_p)) @@ -347,7 +347,7 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */ { if (ecma_string_is_length (property_name_p)) { - ecma_value_t prim_value_p = ext_object_p->u.class_prop.value; + ecma_value_t prim_value_p = ext_object_p->u.class_prop.u.value; ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); ecma_length_t length = ecma_string_get_length (prim_value_str_p); @@ -359,7 +359,7 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */ if (index != ECMA_STRING_NOT_ARRAY_INDEX) { - ecma_value_t prim_value_p = ext_object_p->u.class_prop.value; + ecma_value_t prim_value_p = ext_object_p->u.class_prop.u.value; ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); @@ -684,7 +684,7 @@ ecma_op_object_put (ecma_object_t *object_p, /**< the object */ if (index != ECMA_STRING_NOT_ARRAY_INDEX) { - ecma_value_t prim_value_p = ext_object_p->u.class_prop.value; + ecma_value_t prim_value_p = ext_object_p->u.class_prop.u.value; ecma_string_t *prim_value_str_p = ecma_get_string_from_value (prim_value_p); if (index < ecma_string_get_length (prim_value_str_p)) diff --git a/jerry-core/ecma/operations/ecma-regexp-object.c b/jerry-core/ecma/operations/ecma-regexp-object.c index 6eb99bef30..dc89f6086c 100644 --- a/jerry-core/ecma/operations/ecma-regexp-object.c +++ b/jerry-core/ecma/operations/ecma-regexp-object.c @@ -235,7 +235,7 @@ ecma_op_create_regexp_object_from_bytecode (re_compiled_code_t *bytecode_p) /**< ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_REGEXP_UL; /* Set bytecode internal property. */ - ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.value, bytecode_p); + ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.u.value, bytecode_p); ecma_bytecode_ref ((ecma_compiled_code_t *) bytecode_p); /* Initialize RegExp object properties */ @@ -294,7 +294,7 @@ ecma_op_create_regexp_object (ecma_string_t *pattern_p, /**< input pattern */ /* Set [[Class]] and bytecode internal properties. */ ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_REGEXP_UL; - ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.value, bc_p); + ECMA_SET_INTERNAL_VALUE_POINTER (ext_object_p->u.class_prop.u.value, bc_p); ret_value = ecma_make_object_value (object_p); @@ -1243,7 +1243,7 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */ ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) regexp_object_p; re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t, - ext_object_p->u.class_prop.value); + ext_object_p->u.class_prop.u.value); if (bc_p == NULL) { diff --git a/jerry-core/ecma/operations/ecma-string-object.c b/jerry-core/ecma/operations/ecma-string-object.c index b3af3d38a3..100f680c99 100644 --- a/jerry-core/ecma/operations/ecma-string-object.c +++ b/jerry-core/ecma/operations/ecma-string-object.c @@ -84,7 +84,7 @@ ecma_op_create_string_object (const ecma_value_t *arguments_list_p, /**< list of ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p; ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_STRING_UL; - ext_object_p->u.class_prop.value = ecma_make_string_value (prim_prop_str_value_p); + ext_object_p->u.class_prop.u.value = ecma_make_string_value (prim_prop_str_value_p); return ecma_make_object_value (object_p); } /* ecma_op_create_string_object */ @@ -118,7 +118,7 @@ ecma_op_string_list_lazy_property_names (ecma_object_t *obj_p, /**< a String obj ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) obj_p; JERRY_ASSERT (ext_object_p->u.class_prop.class_id == LIT_MAGIC_STRING_STRING_UL); - ecma_string_t *prim_value_str_p = ecma_get_string_from_value (ext_object_p->u.class_prop.value); + ecma_string_t *prim_value_str_p = ecma_get_string_from_value (ext_object_p->u.class_prop.u.value); ecma_length_t length = ecma_string_get_length (prim_value_str_p); diff --git a/jerry-core/lit/lit-magic-strings.inc.h b/jerry-core/lit/lit-magic-strings.inc.h index 9c13243260..94ef487ebe 100644 --- a/jerry-core/lit/lit-magic-strings.inc.h +++ b/jerry-core/lit/lit-magic-strings.inc.h @@ -132,6 +132,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FILTER, "filter") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_FREEZE, "freeze") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_DAY_UL, "getDay") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GLOBAL, "global") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_IS_VIEW_UL, "isView") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_LENGTH, "length") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NUMBER, "number") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_OBJECT, "object") @@ -199,6 +200,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SUBSTRING, "substring") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UNDEFINED, "undefined") LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (10, LIT_MAGIC_STRING_RANGE_ERROR_UL) LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RANGE_ERROR_UL, "RangeError") +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_BYTE_LENGTH_UL, "byteLength") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CHAR_CODE_AT_UL, "charCodeAt") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ENUMERABLE, "enumerable") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_MINUTES_UL, "getMinutes") @@ -209,7 +211,8 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_PARSE_FLOAT, "parseFloat") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_MINUTES_UL, "setMinutes") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_SECONDS_UL, "setSeconds") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SET_UTC_DATE_UL, "setUTCDate") -LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (11, LIT_MAGIC_STRING_SYNTAX_ERROR_UL) +LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (11, LIT_MAGIC_STRING_ARRAY_BUFFER_UL) +LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ARRAY_BUFFER_UL, "ArrayBuffer") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SYNTAX_ERROR_UL, "SyntaxError") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_CONSTRUCTOR, "constructor") LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_GET_FULL_YEAR_UL, "getFullYear") diff --git a/jerry-core/vm/opcodes.c b/jerry-core/vm/opcodes.c index 25ae18ec44..6b13fbebdb 100644 --- a/jerry-core/vm/opcodes.c +++ b/jerry-core/vm/opcodes.c @@ -175,7 +175,8 @@ opfunc_set_accessor (bool is_getter, /**< is getter accessor */ accessor_name_p, getter_func_p, setter_func_p, - ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE); + ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE, + NULL); } else if (is_getter) { diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 8b0cdcc36c..b7853b7d54 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required (VERSION 2.8.12) project (Unittest C) -if(NOT FEATURE_PROFILE STREQUAL "full") +if(NOT FEATURE_PROFILE STREQUAL "es5.1") message(FATAL_ERROR "FEATURE_PROFILE='${FEATURE_PROFILE}' isn't supported with UNITTESTS=ON") endif() diff --git a/tools/build.py b/tools/build.py index 922e53937e..1cc8233981 100755 --- a/tools/build.py +++ b/tools/build.py @@ -49,7 +49,7 @@ def devhelp(help): parser.add_argument('--builddir', metavar='DIR', action='store', default=BUILD_DIR, help='specify output directory (default: %(default)s)') parser.add_argument('--lto', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='enable link-time optimizations (%(choices)s; default: %(default)s)') parser.add_argument('--all-in-one', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='all-in-one build (%(choices)s; default: %(default)s)') - parser.add_argument('--profile', metavar='PROFILE', choices=['full', 'minimal'], default='full', type=str.lower, help='specify the profile (%(choices)s; default: %(default)s)') + parser.add_argument('--profile', metavar='PROFILE', choices=['es5.1', 'minimal', 'es2015-subset'], default='es5.1', type=str.lower, help='specify the profile (%(choices)s; default: %(default)s)') parser.add_argument('--error-messages', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable error messages (%(choices)s; default: %(default)s)') parser.add_argument('--snapshot-save', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable saving snapshot files (%(choices)s; default: %(default)s)') parser.add_argument('--snapshot-exec', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable executing snapshot files (%(choices)s; default: %(default)s)')