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:
Peter Gal
2015-09-16 17:36:00 +02:00
parent 6f77460509
commit 08c618e8c5
2 changed files with 68 additions and 13 deletions
@@ -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 */
+47
View File
@@ -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);
}
}