Implementing ReferenceError and ReferenceError.prototype built-ins.
This commit is contained in:
@@ -152,11 +152,11 @@ CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_RANGE_ERROR_UL,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.12
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_REFERENCE_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REFERENCE_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_REFERENCE_ERROR_UL,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REFERENCE_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// ECMA-262 v5, 15.1.4.13
|
||||
CP_UNIMPLEMENTED_VALUE (ECMA_MAGIC_STRING_SYNTAX_ERROR_UL,
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/* 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-referenceerror-prototype.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID reference_error_prototype
|
||||
#include "ecma-builtin-internal-routines-template.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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ReferenceError.prototype built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.11.7.8
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_CONSTRUCTOR,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REFERENCE_ERROR),
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// 15.11.7.9
|
||||
STRING_VALUE (ECMA_MAGIC_STRING_NAME,
|
||||
ECMA_MAGIC_STRING_REFERENCE_ERROR_UL,
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
// 15.11.7.10
|
||||
STRING_VALUE (ECMA_MAGIC_STRING_MESSAGE,
|
||||
ECMA_MAGIC_STRING__EMPTY,
|
||||
ECMA_PROPERTY_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_CONFIGURABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@@ -0,0 +1,97 @@
|
||||
/* 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-referenceerror.inc.h"
|
||||
#define BUILTIN_UNDERSCORED_ID reference_error
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
* \addtogroup ecmabuiltins
|
||||
* @{
|
||||
*
|
||||
* \addtogroup referenceerror ECMA ReferenceError object built-in
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling [[Call]] of built-in ReferenceError object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_reference_error_dispatch_call (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
if (arguments_list_len != 0
|
||||
&& !ecma_is_value_undefined (arguments_list_p [0]))
|
||||
{
|
||||
ecma_completion_value_t ret_value;
|
||||
|
||||
ECMA_TRY_CATCH (msg_to_str_completion,
|
||||
ecma_op_to_string (arguments_list_p[0]),
|
||||
ret_value);
|
||||
|
||||
ecma_string_t *message_string_p = ECMA_GET_POINTER (msg_to_str_completion.u.value.value);
|
||||
ecma_object_t *new_error_object_p = ecma_new_standard_error_with_message (ECMA_ERROR_REFERENCE,
|
||||
message_string_p);
|
||||
ret_value = ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
|
||||
|
||||
ECMA_FINALIZE (msg_to_str_completion);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_object_t *new_error_object_p = ecma_new_standard_error (ECMA_ERROR_REFERENCE);
|
||||
|
||||
return ecma_make_normal_completion_value (ecma_make_object_value (new_error_object_p));
|
||||
}
|
||||
} /* ecma_builtin_reference_error_dispatch_call */
|
||||
|
||||
/**
|
||||
* Handle calling [[Construct]] of built-in ReferenceError object
|
||||
*
|
||||
* @return completion-value
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_reference_error_dispatch_construct (ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_builtin_reference_error_dispatch_call (arguments_list_p, arguments_list_len);
|
||||
} /* ecma_builtin_reference_error_dispatch_construct */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ReferenceError built-in description
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_ID
|
||||
# define OBJECT_ID(builtin_object_id)
|
||||
#endif /* !OBJECT_ID */
|
||||
|
||||
#ifndef NUMBER_VALUE
|
||||
# define NUMBER_VALUE(name, number_value, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !NUMBER_VALUE */
|
||||
|
||||
#ifndef STRING_VALUE
|
||||
# define STRING_VALUE(name, magic_string_id, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !STRING_VALUE */
|
||||
|
||||
#ifndef OBJECT_VALUE
|
||||
# define OBJECT_VALUE(name, obj_getter, prop_writable, prop_enumerable, prop_configurable)
|
||||
#endif /* !OBJECT_VALUE */
|
||||
|
||||
/* Object identifier */
|
||||
OBJECT_ID (ECMA_BUILTIN_ID_REFERENCE_ERROR)
|
||||
|
||||
/* Number properties:
|
||||
* (property name, number value, writable, enumerable, configurable) */
|
||||
|
||||
// 15.11.3
|
||||
NUMBER_VALUE (ECMA_MAGIC_STRING_LENGTH,
|
||||
1,
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
/* Object properties:
|
||||
* (property name, object pointer getter) */
|
||||
|
||||
// 15.7.3.1
|
||||
OBJECT_VALUE (ECMA_MAGIC_STRING_PROTOTYPE,
|
||||
ecma_builtin_get (ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE),
|
||||
ECMA_PROPERTY_NOT_WRITABLE,
|
||||
ECMA_PROPERTY_NOT_ENUMERABLE,
|
||||
ECMA_PROPERTY_NOT_CONFIGURABLE)
|
||||
|
||||
#undef OBJECT_ID
|
||||
#undef SIMPLE_VALUE
|
||||
#undef NUMBER_VALUE
|
||||
#undef STRING_VALUE
|
||||
#undef OBJECT_VALUE
|
||||
#undef CP_UNIMPLEMENTED_VALUE
|
||||
#undef ROUTINE
|
||||
@@ -140,6 +140,16 @@ ecma_builtin_bin_search_for_magic_string_id_in_array (const ecma_magic_string_id
|
||||
ERROR_UL, \
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE, \
|
||||
type_error_prototype) \
|
||||
macro (REFERENCE_ERROR, \
|
||||
TYPE_FUNCTION, \
|
||||
ERROR_UL, \
|
||||
ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE, \
|
||||
reference_error) \
|
||||
macro (REFERENCE_ERROR_PROTOTYPE, \
|
||||
TYPE_GENERAL, \
|
||||
ERROR_UL, \
|
||||
ECMA_BUILTIN_ID_ERROR_PROTOTYPE, \
|
||||
reference_error_prototype) \
|
||||
macro (TYPE_ERROR, \
|
||||
TYPE_FUNCTION, \
|
||||
ERROR_UL, \
|
||||
|
||||
@@ -72,3 +72,41 @@ catch (e)
|
||||
|
||||
assert(!(e instanceof Function));
|
||||
}
|
||||
|
||||
|
||||
/* ReferenceError */
|
||||
e = new ReferenceError ();
|
||||
assert (e.name === "ReferenceError");
|
||||
assert (e.message === "");
|
||||
assert (e.toString() === "ReferenceError");
|
||||
|
||||
e = new ReferenceError("some message");
|
||||
assert (e.name === "ReferenceError");
|
||||
assert (e.message === "some message");
|
||||
assert (e.toString() === "ReferenceError: some message");
|
||||
|
||||
e.name = "";
|
||||
assert (e.toString() === "some message");
|
||||
e.message = "";
|
||||
assert (e.toString() === "");
|
||||
|
||||
assert (ReferenceError.prototype.toString === Error.prototype.toString);
|
||||
assert (ReferenceError.prototype.constructor === ReferenceError);
|
||||
assert (ReferenceError.prototype.name === "ReferenceError");
|
||||
assert (ReferenceError.prototype.message === "");
|
||||
assert (ReferenceError.prototype.toString() === "ReferenceError");
|
||||
|
||||
try
|
||||
{
|
||||
var a = non_existing_variable;
|
||||
|
||||
assert (false);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
assert(e instanceof ReferenceError);
|
||||
assert(e instanceof Error);
|
||||
assert(e instanceof Object);
|
||||
|
||||
assert(!(e instanceof Function));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user