diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp index 92f01acd3d..9bde7135f0 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp @@ -347,24 +347,32 @@ ecma_builtin_date_prototype_set_time (ecma_value_t this_arg, /**< this argument { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); - /* 1. */ - ECMA_OP_TO_NUMBER_TRY_CATCH (t, time, ret_value); - ecma_number_t *value_p = ecma_alloc_number (); - *value_p = ecma_date_time_clip (t); + if (!ecma_is_value_object (this_arg) + || ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL) + { + ret_value = ecma_raise_type_error ("Incompatible type"); + } + else + { + /* 1. */ + ECMA_OP_TO_NUMBER_TRY_CATCH (t, time, ret_value); + ecma_number_t *value_p = ecma_alloc_number (); + *value_p = ecma_date_time_clip (t); - /* 2. */ - ecma_object_t *obj_p = ecma_get_object_from_value (this_arg); + /* 2. */ + ecma_object_t *obj_p = ecma_get_object_from_value (this_arg); - ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p, - ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE); + ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p, + ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE); - ecma_number_t *prim_value_num_p = ECMA_GET_NON_NULL_POINTER (ecma_number_t, + ecma_number_t *prim_value_num_p = ECMA_GET_NON_NULL_POINTER (ecma_number_t, prim_value_prop_p->u.internal_property.value); - *prim_value_num_p = *value_p; + *prim_value_num_p = *value_p; - /* 3. */ - ret_value = ecma_make_normal_completion_value (ecma_make_number_value (value_p)); - ECMA_OP_TO_NUMBER_FINALIZE (t); + /* 3. */ + ret_value = ecma_make_normal_completion_value (ecma_make_number_value (value_p)); + ECMA_OP_TO_NUMBER_FINALIZE (t); + } return ret_value; } /* ecma_builtin_date_prototype_set_time */ diff --git a/tests/jerry/regression-test-issue-566.js b/tests/jerry/regression-test-issue-566.js new file mode 100644 index 0000000000..0df354c620 --- /dev/null +++ b/tests/jerry/regression-test-issue-566.js @@ -0,0 +1,47 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// Copyright 2015 University of Szeged. +// +// 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 setMethods = +[ + "setTime", + "setMilliseconds", + "setSeconds", + "setUTCMilliseconds", + "setSeconds", + "setUTCSeconds", + "setMinutes", + "setUTCMinutes", + "setHours", + "setUTCHours", + "setDate", + "setUTCDate", + "setMonth", + "setUTCMonth", + "setFullYear", + "setUTCFullYear" +] + +for(var i in setMethods) +{ + var setMethod = setMethods[i]; + try + { + ({method: Date.prototype[setMethod]}).method(0); + } + catch (e) + { + assert(e instanceof TypeError); + } +}