Commit 5b0187a5 authored by Albert J. Wong's avatar Albert J. Wong Committed by Commit Bot

Fix WeakResult::IsNull(). Was inverted.

Bug: 1083392
Change-Id: I3fb0fdd5d54e069d4f4e7bd1bf2b8fdc96cc3302
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2295690Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Auto-Submit: Albert J. Wong <ajwong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788322}
parent 2e46fdc8
...@@ -289,6 +289,7 @@ jumbo_source_set("wtf_unittests_sources") { ...@@ -289,6 +289,7 @@ jumbo_source_set("wtf_unittests_sources") {
"scoped_logger_test.cc", "scoped_logger_test.cc",
"shared_buffer_test.cc", "shared_buffer_test.cc",
"testing/run_all_tests.cc", "testing/run_all_tests.cc",
"text/atomic_string_table_test.cc",
"text/atomic_string_test.cc", "text/atomic_string_test.cc",
"text/case_map_test.cc", "text/case_map_test.cc",
"text/integer_to_string_conversion_test.cc", "text/integer_to_string_conversion_test.cc",
......
...@@ -57,15 +57,17 @@ class WTF_EXPORT AtomicStringTable final { ...@@ -57,15 +57,17 @@ class WTF_EXPORT AtomicStringTable final {
CHECK(!str || str->IsAtomic() || str == StringImpl::empty_); CHECK(!str || str->IsAtomic() || str == StringImpl::empty_);
} }
bool operator==(const AtomicString& s) const { return *this == s.Impl(); } bool IsNull() const { return ptr_value_ == 0; }
bool operator==(const String& s) const { return *this == s.Impl(); }
bool operator==(const StringImpl* str) const {
return reinterpret_cast<uintptr_t>(str) == ptr_value_;
}
bool IsNull() const { return ptr_value_ != 0; }
private: private:
friend bool operator==(const WeakResult& lhs, const WeakResult& rhs);
friend bool operator==(const WeakResult& lhs, const String& rhs);
friend bool operator==(const String& rhs, const WeakResult& lhs);
friend bool operator==(const WeakResult& lhs, const AtomicString& rhs);
friend bool operator==(const AtomicString& rhs, const WeakResult& lhs);
friend bool operator==(const WeakResult& lhs, const StringImpl* rhs);
friend bool operator==(const StringImpl* lhs, const WeakResult& rhs);
// Contains the pointer a string in a non-deferenceable form. Do NOT cast // Contains the pointer a string in a non-deferenceable form. Do NOT cast
// back to a StringImpl and dereference. The object may no longer be alive. // back to a StringImpl and dereference. The object may no longer be alive.
uintptr_t ptr_value_ = 0; uintptr_t ptr_value_ = 0;
...@@ -135,6 +137,41 @@ class WTF_EXPORT AtomicStringTable final { ...@@ -135,6 +137,41 @@ class WTF_EXPORT AtomicStringTable final {
DISALLOW_COPY_AND_ASSIGN(AtomicStringTable); DISALLOW_COPY_AND_ASSIGN(AtomicStringTable);
}; };
inline bool operator==(const AtomicStringTable::WeakResult& lhs,
const AtomicStringTable::WeakResult& rhs) {
return lhs.ptr_value_ == rhs.ptr_value_;
}
inline bool operator==(const AtomicStringTable::WeakResult& lhs,
const String& rhs) {
return lhs == rhs.Impl();
}
inline bool operator==(const String& lhs,
const AtomicStringTable::WeakResult& rhs) {
return lhs.Impl() == rhs;
}
inline bool operator==(const AtomicStringTable::WeakResult& lhs,
const AtomicString& rhs) {
return lhs == rhs.Impl();
}
inline bool operator==(const AtomicString& lhs,
const AtomicStringTable::WeakResult& rhs) {
return lhs.Impl() == rhs;
}
inline bool operator==(const AtomicStringTable::WeakResult& lhs,
const StringImpl* rhs) {
return rhs == lhs;
}
inline bool operator==(const StringImpl* lhs,
const AtomicStringTable::WeakResult& rhs) {
return reinterpret_cast<uintptr_t>(lhs) == rhs.ptr_value_;
}
} // namespace WTF } // namespace WTF
using WTF::AtomicStringTable; using WTF::AtomicStringTable;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/wtf/text/atomic_string_table.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace WTF {
TEST(WeakResultTest, BasicOperations) {
AtomicStringTable::WeakResult null;
EXPECT_TRUE(null.IsNull());
EXPECT_TRUE(null == AtomicStringTable::WeakResult());
AtomicString s("astring");
AtomicStringTable::WeakResult not_null(s.Impl());
AtomicStringTable::WeakResult not_null2(s.Impl());
EXPECT_TRUE(not_null == not_null2);
EXPECT_FALSE(not_null == null);
EXPECT_FALSE(not_null.IsNull());
EXPECT_TRUE(not_null == s);
EXPECT_TRUE(s == not_null);
String s2(s);
EXPECT_TRUE(s2 == not_null);
}
} // namespace WTF
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment