Chromium Code Reviews| Index: runtime/lib/object.cc |
| =================================================================== |
| --- runtime/lib/object.cc (revision 35921) |
| +++ runtime/lib/object.cc (working copy) |
| @@ -16,6 +16,7 @@ |
| DECLARE_FLAG(bool, enable_type_checks); |
| DECLARE_FLAG(bool, trace_type_checks); |
| +DECLARE_FLAG(bool, warn_on_javascript_incompatibility); |
| DEFINE_NATIVE_ENTRY(Object_equals, 1) { |
| @@ -109,6 +110,41 @@ |
| } |
| +static void WarnOnJSIntegralNumTypeTest( |
| + const Instance& instance, |
| + const TypeArguments& instantiator_type_arguments, |
| + const AbstractType& type) { |
| + const bool instance_is_int = |
| + instance.IsSmi() || instance.IsMint() || instance.IsBigint(); |
|
srdjan
2014/05/08 18:11:05
Why not instance.IsInteger()?
regis
2014/05/09 21:03:42
Done.
|
| + const bool instance_is_double = instance.IsDouble(); |
| + if (!(instance_is_int || instance_is_double)) { |
| + return; |
| + } |
| + AbstractType& instantiated_type = AbstractType::Handle(type.raw()); |
| + if (!type.IsInstantiated()) { |
| + instantiated_type = type.InstantiateFrom(instantiator_type_arguments, NULL); |
| + } |
| + if (instance_is_double) { |
| + if (instantiated_type.IsIntType()) { |
| + const double value = Double::Cast(instance).value(); |
| + if (floor(value) == value) { |
| + Exceptions::JSWarning(ICData::Handle(), // ic_data must be looked up. |
| + "javascript incompatibility: integral value of " |
| + "type 'double' is also considered to be of " |
| + "type 'int'"); |
| + } |
| + } |
| + } else { |
| + ASSERT(instance_is_int); |
| + if (instantiated_type.IsDoubleType()) { |
| + Exceptions::JSWarning(ICData::Handle(), // ic_data must be looked up. |
| + "javascript incompatibility: integer value is " |
| + "also considered to be of type 'double'"); |
| + } |
| + } |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Object_instanceOf, 5) { |
| const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
| // Instantiator at position 1 is not used. It is passed along so that the call |
| @@ -122,6 +158,12 @@ |
| ASSERT(type.IsFinalized()); |
| ASSERT(!type.IsMalformed()); |
| ASSERT(!type.IsMalbounded()); |
| + |
| + // Check for javascript incompatibility. |
| + if (FLAG_warn_on_javascript_incompatibility) { |
| + WarnOnJSIntegralNumTypeTest(instance, instantiator_type_arguments, type); |
| + } |
| + |
| Error& bound_error = Error::Handle(); |
| const bool is_instance_of = instance.IsInstanceOf(type, |
| instantiator_type_arguments, |
| @@ -170,6 +212,12 @@ |
| if (instance.IsNull()) { |
| return instance.raw(); |
| } |
| + |
| + // Check for javascript incompatibility. |
| + if (FLAG_warn_on_javascript_incompatibility) { |
| + WarnOnJSIntegralNumTypeTest(instance, instantiator_type_arguments, type); |
| + } |
| + |
| const bool is_instance_of = instance.IsInstanceOf(type, |
| instantiator_type_arguments, |
| &bound_error); |