mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Implementing Error and Error.prototype built-in objects.
This commit is contained in:
parent
ed08fe9983
commit
4e6f5c7716
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
190
src/libecmabuiltins/ecma-builtin-error-prototype.c
Normal file
190
src/libecmabuiltins/ecma-builtin-error-prototype.c
Normal file
@ -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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
73
src/libecmabuiltins/ecma-builtin-error-prototype.inc.h
Normal file
73
src/libecmabuiltins/ecma-builtin-error-prototype.inc.h
Normal file
@ -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
|
||||
116
src/libecmabuiltins/ecma-builtin-error.c
Normal file
116
src/libecmabuiltins/ecma-builtin-error.c
Normal file
@ -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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
65
src/libecmabuiltins/ecma-builtin-error.inc.h
Normal file
65
src/libecmabuiltins/ecma-builtin-error.inc.h
Normal file
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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: \
|
||||
{ \
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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, \
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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, "")
|
||||
|
||||
32
tests/jerry/error.js
Normal file
32
tests/jerry/error.js
Normal file
@ -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: ");
|
||||
Loading…
x
Reference in New Issue
Block a user