Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: src/objects.cc

Issue 24360017: Expose SameValue equality comparison algorithm (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 998
999 999
1000 bool Object::SameValue(Object* other) { 1000 bool Object::SameValue(Object* other) {
1001 if (other == this) return true; 1001 if (other == this) return true;
1002 1002
1003 // The object is either a number, a name, an odd-ball, 1003 // The object is either a number, a name, an odd-ball,
1004 // a real JS object, or a Harmony proxy. 1004 // a real JS object, or a Harmony proxy.
1005 if (IsNumber() && other->IsNumber()) { 1005 if (IsNumber() && other->IsNumber()) {
1006 double this_value = Number(); 1006 double this_value = Number();
1007 double other_value = other->Number(); 1007 double other_value = other->Number();
1008 return (this_value == other_value) || 1008 bool equal = this_value == other_value;
1009 (std::isnan(this_value) && std::isnan(other_value)); 1009 // SameValue(NaN, NaN) is true.
1010 if (!equal) return std::isnan(this_value) && std::isnan(other_value);
1011 // SameValue(0.0, -0.0) is false.
1012 return (this_value != 0) || ((1 / this_value) == (1 / other_value));
yusukesuzuki 2013/09/24 12:58:26 According to the comment of Object::SameValue in o
1010 } 1013 }
1011 if (IsString() && other->IsString()) { 1014 if (IsString() && other->IsString()) {
1012 return String::cast(this)->Equals(String::cast(other)); 1015 return String::cast(this)->Equals(String::cast(other));
1013 } 1016 }
1014 return false; 1017 return false;
1015 } 1018 }
1016 1019
1017 1020
1018 void Object::ShortPrint(FILE* out) { 1021 void Object::ShortPrint(FILE* out) {
1019 HeapStringAllocator allocator; 1022 HeapStringAllocator allocator;
(...skipping 15082 matching lines...) Expand 10 before | Expand all | Expand 10 after
16102 #define ERROR_MESSAGES_TEXTS(C, T) T, 16105 #define ERROR_MESSAGES_TEXTS(C, T) T,
16103 static const char* error_messages_[] = { 16106 static const char* error_messages_[] = {
16104 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16107 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16105 }; 16108 };
16106 #undef ERROR_MESSAGES_TEXTS 16109 #undef ERROR_MESSAGES_TEXTS
16107 return error_messages_[reason]; 16110 return error_messages_[reason];
16108 } 16111 }
16109 16112
16110 16113
16111 } } // namespace v8::internal 16114 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.cc ('k') | test/cctest/test-api.cc » ('j') | test/cctest/test-api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698