From 4e6f5c77163bd6fb91f20327cfdf34c2e15ae0c3 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Wed, 29 Oct 2014 18:49:31 +0300 Subject: [PATCH] Implementing Error and Error.prototype built-in objects. --- .../ecma-builtin-array-prototype.inc.h | 1 + src/libecmabuiltins/ecma-builtin-array.inc.h | 1 + .../ecma-builtin-boolean-prototype.inc.h | 1 + .../ecma-builtin-boolean.inc.h | 1 + .../ecma-builtin-compact-profile-error.inc.h | 1 + .../ecma-builtin-error-prototype.c | 190 ++++++++++++++++++ .../ecma-builtin-error-prototype.inc.h | 73 +++++++ src/libecmabuiltins/ecma-builtin-error.c | 116 +++++++++++ src/libecmabuiltins/ecma-builtin-error.inc.h | 65 ++++++ .../ecma-builtin-function-prototype.inc.h | 1 + .../ecma-builtin-function.inc.h | 1 + src/libecmabuiltins/ecma-builtin-global.inc.h | 11 +- ...a-builtin-internal-routines-template.inc.h | 13 ++ src/libecmabuiltins/ecma-builtin-math.inc.h | 1 + .../ecma-builtin-number-prototype.inc.h | 3 +- src/libecmabuiltins/ecma-builtin-number.inc.h | 1 + .../ecma-builtin-object-prototype.inc.h | 1 + src/libecmabuiltins/ecma-builtin-object.inc.h | 1 + .../ecma-builtin-string-prototype.inc.h | 1 + src/libecmabuiltins/ecma-builtin-string.inc.h | 1 + src/libecmabuiltins/ecma-builtins-internal.h | 18 +- src/libecmabuiltins/ecma-builtins.h | 24 ++- src/libecmaobjects/ecma-magic-strings.inc.h | 1 + tests/jerry/error.js | 32 +++ 24 files changed, 540 insertions(+), 19 deletions(-) create mode 100644 src/libecmabuiltins/ecma-builtin-error-prototype.c create mode 100644 src/libecmabuiltins/ecma-builtin-error-prototype.inc.h create mode 100644 src/libecmabuiltins/ecma-builtin-error.c create mode 100644 src/libecmabuiltins/ecma-builtin-error.inc.h create mode 100644 tests/jerry/error.js diff --git a/src/libecmabuiltins/ecma-builtin-array-prototype.inc.h b/src/libecmabuiltins/ecma-builtin-array-prototype.inc.h index bd224f57c..a5d219863 100644 --- a/src/libecmabuiltins/ecma-builtin-array-prototype.inc.h +++ b/src/libecmabuiltins/ecma-builtin-array-prototype.inc.h @@ -63,6 +63,7 @@ ROUTINE (ECMA_MAGIC_STRING_TO_STRING_UL, ecma_builtin_array_prototype_object_to_ #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-array.inc.h b/src/libecmabuiltins/ecma-builtin-array.inc.h index 141002a35..c5f28a2c4 100644 --- a/src/libecmabuiltins/ecma-builtin-array.inc.h +++ b/src/libecmabuiltins/ecma-builtin-array.inc.h @@ -53,6 +53,7 @@ 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 diff --git a/src/libecmabuiltins/ecma-builtin-boolean-prototype.inc.h b/src/libecmabuiltins/ecma-builtin-boolean-prototype.inc.h index 8a3ba3086..c7aa7f0b9 100644 --- a/src/libecmabuiltins/ecma-builtin-boolean-prototype.inc.h +++ b/src/libecmabuiltins/ecma-builtin-boolean-prototype.inc.h @@ -50,6 +50,7 @@ ROUTINE (ECMA_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_boolean_prototype_object_v #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-boolean.inc.h b/src/libecmabuiltins/ecma-builtin-boolean.inc.h index ae7a39c66..46905a088 100644 --- a/src/libecmabuiltins/ecma-builtin-boolean.inc.h +++ b/src/libecmabuiltins/ecma-builtin-boolean.inc.h @@ -59,6 +59,7 @@ NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH, #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-compact-profile-error.inc.h b/src/libecmabuiltins/ecma-builtin-compact-profile-error.inc.h index 23d3a8027..24b4ac99b 100644 --- a/src/libecmabuiltins/ecma-builtin-compact-profile-error.inc.h +++ b/src/libecmabuiltins/ecma-builtin-compact-profile-error.inc.h @@ -40,6 +40,7 @@ NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH, #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-error-prototype.c b/src/libecmabuiltins/ecma-builtin-error-prototype.c new file mode 100644 index 000000000..627286309 --- /dev/null +++ b/src/libecmabuiltins/ecma-builtin-error-prototype.c @@ -0,0 +1,190 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-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 "globals.h" + +#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 (ecma_value_t this) /**< this argument */ +{ + ecma_completion_value_t ret_value; + + // 2. + if (this.value_type != ECMA_TYPE_OBJECT) + { + ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); + } + else + { + ecma_object_t *obj_p = ECMA_GET_POINTER (this.value); + ecma_string_t *name_magic_string_p = ecma_get_magic_string (ECMA_MAGIC_STRING_NAME); + + ECMA_TRY_CATCH (name_get_completion, + ecma_op_object_get (obj_p, name_magic_string_p), + ret_value); + + ecma_completion_value_t name_to_str_completion; + + if (ecma_is_completion_value_normal_simple_value (name_get_completion, ECMA_SIMPLE_VALUE_UNDEFINED)) + { + 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_completion.u.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_completion, + ecma_op_object_get (obj_p, message_magic_string_p), + ret_value); + + ecma_completion_value_t msg_to_str_completion; + + if (ecma_is_completion_value_normal_simple_value (msg_get_completion, ECMA_SIMPLE_VALUE_UNDEFINED)) + { + 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_completion.u.value); + } + + if (unlikely (!ecma_is_completion_value_normal (msg_to_str_completion))) + { + ret_value = ecma_copy_completion_value (msg_to_str_completion); + } + else + { + JERRY_ASSERT (name_to_str_completion.u.value.value_type == ECMA_TYPE_STRING); + JERRY_ASSERT (msg_to_str_completion.u.value.value_type == ECMA_TYPE_STRING); + + ecma_string_t *name_string_p = ECMA_GET_POINTER (name_to_str_completion.u.value.value); + ecma_string_t *msg_string_p = ECMA_GET_POINTER (msg_to_str_completion.u.value.value); + + 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 bytes, buffer_size_left = buffer_size; + + ecma_char_t ret_str_buffer [buffer_size]; + ecma_char_t *ret_str_buffer_p = ret_str_buffer; + + 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; + + ecma_string_t *ret_str_p = ecma_new_ecma_string (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_completion); + + ecma_deref_ecma_string (message_magic_string_p); + } + + ecma_free_completion_value (name_to_str_completion); + + ECMA_FINALIZE (name_get_completion); + + ecma_deref_ecma_string (name_magic_string_p); + } + + return ret_value; +} /* ecma_builtin_error_prototype_object_to_string */ + +/** + * @} + * @} + * @} + */ diff --git a/src/libecmabuiltins/ecma-builtin-error-prototype.inc.h b/src/libecmabuiltins/ecma-builtin-error-prototype.inc.h new file mode 100644 index 000000000..3ea467cd9 --- /dev/null +++ b/src/libecmabuiltins/ecma-builtin-error-prototype.inc.h @@ -0,0 +1,73 @@ +/* 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. + */ + +/* + * 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 diff --git a/src/libecmabuiltins/ecma-builtin-error.c b/src/libecmabuiltins/ecma-builtin-error.c new file mode 100644 index 000000000..88e6de577 --- /dev/null +++ b/src/libecmabuiltins/ecma-builtin-error.c @@ -0,0 +1,116 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecma-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 "globals.h" + +#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 (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 msg_to_str_completion = ecma_make_empty_completion_value ();; + + if (arguments_list_len != 0 + && !ecma_is_value_undefined (arguments_list_p [0])) + { + msg_to_str_completion = ecma_op_to_string (arguments_list_p[0]); + + if (!ecma_is_completion_value_normal (msg_to_str_completion)) + { + return msg_to_str_completion; + } + } + + ecma_object_t *error_prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_ERROR_PROTOTYPE); + + ecma_object_t *new_error_object_p = ecma_create_object (error_prototype_obj_p, + true, + ECMA_OBJECT_TYPE_GENERAL); + + ecma_deref_object (error_prototype_obj_p); + + ecma_property_t *class_prop_p = ecma_create_internal_property (new_error_object_p, + ECMA_INTERNAL_PROPERTY_CLASS); + class_prop_p->u.internal_property.value = ECMA_MAGIC_STRING_ERROR_UL; + + if (!ecma_is_completion_value_empty (msg_to_str_completion)) + { + 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_object_p, + message_magic_string_p, + ECMA_PROPERTY_WRITABLE, + ECMA_PROPERTY_NOT_ENUMERABLE, + ECMA_PROPERTY_CONFIGURABLE); + prop_p->u.named_data_property.value = ecma_copy_value (msg_to_str_completion.u.value, true); + ecma_gc_update_may_ref_younger_object_flag_by_value (new_error_object_p, prop_p->u.named_data_property.value); + + ecma_deref_ecma_string (message_magic_string_p); + + ecma_free_completion_value (msg_to_str_completion); + } + + 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 (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 */ + +/** + * @} + * @} + * @} + */ diff --git a/src/libecmabuiltins/ecma-builtin-error.inc.h b/src/libecmabuiltins/ecma-builtin-error.inc.h new file mode 100644 index 000000000..317ba86b7 --- /dev/null +++ b/src/libecmabuiltins/ecma-builtin-error.inc.h @@ -0,0 +1,65 @@ +/* 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. + */ + +/* + * 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 diff --git a/src/libecmabuiltins/ecma-builtin-function-prototype.inc.h b/src/libecmabuiltins/ecma-builtin-function-prototype.inc.h index a3a34ceef..d13f89117 100644 --- a/src/libecmabuiltins/ecma-builtin-function-prototype.inc.h +++ b/src/libecmabuiltins/ecma-builtin-function-prototype.inc.h @@ -66,6 +66,7 @@ ROUTINE (ECMA_MAGIC_STRING_BIND, ecma_builtin_function_prototype_object_bind, NO #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-function.inc.h b/src/libecmabuiltins/ecma-builtin-function.inc.h index c95c89376..81cd38b4f 100644 --- a/src/libecmabuiltins/ecma-builtin-function.inc.h +++ b/src/libecmabuiltins/ecma-builtin-function.inc.h @@ -59,6 +59,7 @@ NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH, #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-global.inc.h b/src/libecmabuiltins/ecma-builtin-global.inc.h index 43acc0160..22238a2ed 100644 --- a/src/libecmabuiltins/ecma-builtin-global.inc.h +++ b/src/libecmabuiltins/ecma-builtin-global.inc.h @@ -131,11 +131,11 @@ CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_REG_EXP_UL, ECMA_PROPERTY_CONFIGURABLE) // ECMA-262 v5, 15.1.4.9 -CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_ERROR_UL, - ecma_builtin_get (ECMA_BUILTIN_ID_ERROR), - ECMA_PROPERTY_WRITABLE, - ECMA_PROPERTY_NOT_ENUMERABLE, - ECMA_PROPERTY_CONFIGURABLE) +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 CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_EVAL_ERROR_UL, @@ -216,6 +216,7 @@ 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 diff --git a/src/libecmabuiltins/ecma-builtin-internal-routines-template.inc.h b/src/libecmabuiltins/ecma-builtin-internal-routines-template.inc.h index ecd4cd2a8..29d44b046 100644 --- a/src/libecmabuiltins/ecma-builtin-internal-routines-template.inc.h +++ b/src/libecmabuiltins/ecma-builtin-internal-routines-template.inc.h @@ -52,6 +52,7 @@ 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, @@ -210,6 +211,18 @@ TRY_TO_INSTANTIATE_PROPERTY_ROUTINE_NAME (BUILTIN_UNDERSCORED_ID) (ecma_object_t \ 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: \ { \ diff --git a/src/libecmabuiltins/ecma-builtin-math.inc.h b/src/libecmabuiltins/ecma-builtin-math.inc.h index dfc95f5d7..1a9b6d3c7 100644 --- a/src/libecmabuiltins/ecma-builtin-math.inc.h +++ b/src/libecmabuiltins/ecma-builtin-math.inc.h @@ -123,6 +123,7 @@ 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 diff --git a/src/libecmabuiltins/ecma-builtin-number-prototype.inc.h b/src/libecmabuiltins/ecma-builtin-number-prototype.inc.h index 07432fc50..471f04747 100644 --- a/src/libecmabuiltins/ecma-builtin-number-prototype.inc.h +++ b/src/libecmabuiltins/ecma-builtin-number-prototype.inc.h @@ -35,7 +35,7 @@ OBJECT_ID (ECMA_BUILTIN_ID_NUMBER_PROTOTYPE) /* Object properties: * (property name, object pointer getter) */ -// ECMA-262 v5, 15.7.4.1 +// 15.7.4.1 OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR, ecma_builtin_get (ECMA_BUILTIN_ID_NUMBER), ECMA_PROPERTY_WRITABLE, @@ -54,6 +54,7 @@ ROUTINE (ECMA_MAGIC_STRING_TO_PRECISION_UL, ecma_builtin_number_prototype_object #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-number.inc.h b/src/libecmabuiltins/ecma-builtin-number.inc.h index f157a183e..ad8f09be8 100644 --- a/src/libecmabuiltins/ecma-builtin-number.inc.h +++ b/src/libecmabuiltins/ecma-builtin-number.inc.h @@ -90,6 +90,7 @@ OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE, #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-object-prototype.inc.h b/src/libecmabuiltins/ecma-builtin-object-prototype.inc.h index e319dd82e..8064782d5 100644 --- a/src/libecmabuiltins/ecma-builtin-object-prototype.inc.h +++ b/src/libecmabuiltins/ecma-builtin-object-prototype.inc.h @@ -54,6 +54,7 @@ ROUTINE (ECMA_MAGIC_STRING_PROPERTY_IS_ENUMERABLE_UL, ecma_builtin_object_protot #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-object.inc.h b/src/libecmabuiltins/ecma-builtin-object.inc.h index 364263af1..0124af453 100644 --- a/src/libecmabuiltins/ecma-builtin-object.inc.h +++ b/src/libecmabuiltins/ecma-builtin-object.inc.h @@ -75,6 +75,7 @@ ROUTINE (ECMA_MAGIC_STRING_DEFINE_PROPERTY_UL, ecma_builtin_object_object_define #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtin-string-prototype.inc.h b/src/libecmabuiltins/ecma-builtin-string-prototype.inc.h index 62be89349..d1f9d6153 100644 --- a/src/libecmabuiltins/ecma-builtin-string-prototype.inc.h +++ b/src/libecmabuiltins/ecma-builtin-string-prototype.inc.h @@ -67,6 +67,7 @@ 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 diff --git a/src/libecmabuiltins/ecma-builtin-string.inc.h b/src/libecmabuiltins/ecma-builtin-string.inc.h index 78d58e826..c92c12867 100644 --- a/src/libecmabuiltins/ecma-builtin-string.inc.h +++ b/src/libecmabuiltins/ecma-builtin-string.inc.h @@ -63,6 +63,7 @@ ROUTINE (ECMA_MAGIC_STRING_FROM_CHAR_CODE_UL, ecma_builtin_string_object_from_ch #undef OBJECT_ID #undef SIMPLE_VALUE #undef NUMBER_VALUE +#undef STRING_VALUE #undef OBJECT_VALUE #undef CP_UNIMPLEMENTED_VALUE #undef ROUTINE diff --git a/src/libecmabuiltins/ecma-builtins-internal.h b/src/libecmabuiltins/ecma-builtins-internal.h index 60f402c47..ed861a144 100644 --- a/src/libecmabuiltins/ecma-builtins-internal.h +++ b/src/libecmabuiltins/ecma-builtins-internal.h @@ -102,22 +102,22 @@ ecma_builtin_bin_search_for_magic_string_id_in_array (const ecma_magic_string_id math) \ macro (ARRAY, \ TYPE_FUNCTION, \ - FUNCTION_UL, \ + ARRAY_UL, \ ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, \ array) \ macro (STRING, \ TYPE_FUNCTION, \ - FUNCTION_UL, \ + STRING_UL, \ ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, \ string) \ macro (BOOLEAN, \ TYPE_FUNCTION, \ - FUNCTION_UL, \ + BOOLEAN_UL, \ ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, \ boolean) \ macro (NUMBER, \ TYPE_FUNCTION, \ - FUNCTION_UL, \ + NUMBER_UL, \ ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, \ number) \ macro (FUNCTION, \ @@ -125,6 +125,16 @@ ecma_builtin_bin_search_for_magic_string_id_in_array (const ecma_magic_string_id FUNCTION_UL, \ ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, \ function) \ + macro (ERROR_PROTOTYPE, \ + TYPE_GENERAL, \ + ERROR_UL, \ + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, \ + error_prototype) \ + macro (ERROR, \ + TYPE_FUNCTION, \ + ERROR_UL, \ + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, \ + error) \ macro (COMPACT_PROFILE_ERROR, \ TYPE_FUNCTION, \ COMPACT_PROFILE_ERROR_UL, \ diff --git a/src/libecmabuiltins/ecma-builtins.h b/src/libecmabuiltins/ecma-builtins.h index b84501d36..47e65afc2 100644 --- a/src/libecmabuiltins/ecma-builtins.h +++ b/src/libecmabuiltins/ecma-builtins.h @@ -25,28 +25,34 @@ typedef enum { ECMA_BUILTIN_ID_GLOBAL, /**< the Global object (15.1) */ ECMA_BUILTIN_ID_OBJECT, /**< the Object object (15.2.1) */ - ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, /**< the Object object (15.2.4) */ + ECMA_BUILTIN_ID_OBJECT_PROTOTYPE, /**< the Object.prototype object (15.2.4) */ ECMA_BUILTIN_ID_FUNCTION, /**< the Function object (15.3.1) */ - ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, /**< the Function object (15.3.4) */ + ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE, /**< the Function.prototype object (15.3.4) */ ECMA_BUILTIN_ID_ARRAY, /**< the Array object (15.4.1) */ - ECMA_BUILTIN_ID_ARRAY_PROTOTYPE, /**< the Array object (15.4.4) */ + ECMA_BUILTIN_ID_ARRAY_PROTOTYPE, /**< the Array.prototype object (15.4.4) */ ECMA_BUILTIN_ID_STRING, /**< the String object (15.5.1) */ - ECMA_BUILTIN_ID_STRING_PROTOTYPE, /**< the String object (15.5.4) */ + ECMA_BUILTIN_ID_STRING_PROTOTYPE, /**< the String.prototype object (15.5.4) */ ECMA_BUILTIN_ID_BOOLEAN, /**< the Boolean object (15.6.1) */ - ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE, /**< the Boolean object (15.6.4) */ + ECMA_BUILTIN_ID_BOOLEAN_PROTOTYPE, /**< the Boolean.prototype object (15.6.4) */ ECMA_BUILTIN_ID_NUMBER, /**< the Number object (15.7.1) */ - ECMA_BUILTIN_ID_NUMBER_PROTOTYPE, /**< the Number object (15.7.4) */ + ECMA_BUILTIN_ID_NUMBER_PROTOTYPE, /**< the Number.prototype object (15.7.4) */ ECMA_BUILTIN_ID_DATE, /**< the Date object (15.9.2) */ ECMA_BUILTIN_ID_REGEXP, /**< the RegExp object (15.10.3) */ - ECMA_BUILTIN_ID_REGEXP_PROTOTYPE, /**< the RegExp object (15.10.6) */ + ECMA_BUILTIN_ID_REGEXP_PROTOTYPE, /**< the RegExp.prototype object (15.10.6) */ ECMA_BUILTIN_ID_ERROR, /**< the Error object (15.11.1) */ - ECMA_BUILTIN_ID_ERROR_PROTOTYPE, /**< the Error object (15.11.4) */ + ECMA_BUILTIN_ID_ERROR_PROTOTYPE, /**< the Error.prototype object (15.11.4) */ ECMA_BUILTIN_ID_EVAL_ERROR, /**< the EvalError object (15.11.6.1) */ + ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE, /**< the EvalError.prototype object (15.11.6.1) */ ECMA_BUILTIN_ID_RANGE_ERROR, /**< the RangeError object (15.11.6.2) */ + ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE, /**< the RangeError.prototype object (15.11.6.2) */ ECMA_BUILTIN_ID_REFERENCE_ERROR, /**< the ReferenceError object (15.11.6.3) */ + ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE, /**< the ReferenceError.prototype object (15.11.6.3) */ ECMA_BUILTIN_ID_SYNTAX_ERROR, /**< the SyntaxError object (15.11.6.4) */ - ECMA_BUILTIN_ID_TYPE_ERROR, /**< the SyntaxError object (15.11.6.5) */ + ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE, /**< the SyntaxError.prototype object (15.11.6.4) */ + ECMA_BUILTIN_ID_TYPE_ERROR, /**< the TypeError object (15.11.6.5) */ + ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE, /**< the TypeError.prototype object (15.11.6.5) */ ECMA_BUILTIN_ID_URI_ERROR, /**< the URIError object (15.11.6.6) */ + ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE, /**< the URIError.prototype object (15.11.6.6) */ ECMA_BUILTIN_ID_MATH, /**< the Math object (15.8) */ ECMA_BUILTIN_ID_JSON, /**< the JSON object (15.12) */ #ifdef CONFIG_ECMA_COMPACT_PROFILE diff --git a/src/libecmaobjects/ecma-magic-strings.inc.h b/src/libecmaobjects/ecma-magic-strings.inc.h index ac8379849..6706b8639 100644 --- a/src/libecmaobjects/ecma-magic-strings.inc.h +++ b/src/libecmaobjects/ecma-magic-strings.inc.h @@ -205,5 +205,6 @@ 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, "") diff --git a/tests/jerry/error.js b/tests/jerry/error.js new file mode 100644 index 000000000..bf03d4ee8 --- /dev/null +++ b/tests/jerry/error.js @@ -0,0 +1,32 @@ +// Copyright 2014 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var e; + +e = new Error (); +assert (e.name === "Error"); +assert (e.message === ""); +assert (e.toString() === "Error: "); + +e = new Error("some message"); +assert (e.name === "Error"); +assert (e.message === "some message"); +assert (e.toString() === "Error: some message"); + + +assert (Error.prototype.toString !== Object.prototype.toString); +assert (Error.prototype.constructor === Error); +assert (Error.prototype.name === "Error"); +assert (Error.prototype.message === ""); +assert (Error.prototype.toString() === "Error: ");