Chromium Code Reviews| Index: runtime/lib/identical.cc |
| diff --git a/runtime/lib/identical.cc b/runtime/lib/identical.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1718bee40773cddd05fa7f7972fd2f1eff2957ac |
| --- /dev/null |
| +++ b/runtime/lib/identical.cc |
| @@ -0,0 +1,33 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +#include "vm/bootstrap_natives.h" |
| + |
| +#include "vm/object.h" |
| + |
| +namespace dart { |
| + |
| +DEFINE_NATIVE_ENTRY(Identical_comparison, 2) { |
| + GET_NATIVE_ARGUMENT( |
| + Instance, a, arguments->NativeArgAt(0)); |
|
srdjan
2012/12/17 23:30:20
Can this fit in one line (80 chars).
|
| + GET_NATIVE_ARGUMENT( |
| + Instance, b, arguments->NativeArgAt(1)); |
|
srdjan
2012/12/17 23:30:20
Ditto.
|
| + if (a.raw() == b.raw()) return Bool::True(); |
| + if (a.IsInteger() && b.IsInteger()) { |
| + return Bool::Get(a.Equals(b)); |
| + } |
| + if (a.IsDouble() && b.IsDouble()) { |
| + if (a.Equals(b)) return Bool::True(); |
| + // Check for NaN |
|
srdjan
2012/12/17 23:30:20
Terminate comment with a period.
|
| + const Double& a_double = Double::Cast(a); |
| + const Double& b_double = Double::Cast(b); |
| + if (isnan(a_double.value()) && isnan(b_double.value())) { |
| + return Bool::True(); |
| + } |
| + } |
| + return Bool::False(); |
| +} |
| + |
| + |
| +} // namespace dart |