Add check for setTime implementation to see if the this argument is really a Date object.
JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
This commit is contained in:
@@ -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 ();
|
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||||
|
|
||||||
/* 1. */
|
if (!ecma_is_value_object (this_arg)
|
||||||
ECMA_OP_TO_NUMBER_TRY_CATCH (t, time, ret_value);
|
|| ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
|
||||||
ecma_number_t *value_p = ecma_alloc_number ();
|
{
|
||||||
*value_p = ecma_date_time_clip (t);
|
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. */
|
/* 2. */
|
||||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
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_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
|
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_prop_p->u.internal_property.value);
|
||||||
*prim_value_num_p = *value_p;
|
*prim_value_num_p = *value_p;
|
||||||
|
|
||||||
/* 3. */
|
/* 3. */
|
||||||
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (value_p));
|
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (value_p));
|
||||||
ECMA_OP_TO_NUMBER_FINALIZE (t);
|
ECMA_OP_TO_NUMBER_FINALIZE (t);
|
||||||
|
}
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
} /* ecma_builtin_date_prototype_set_time */
|
} /* ecma_builtin_date_prototype_set_time */
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user