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

Unified Diff: Source/bindings/v8/V8StringResource.h

Issue 276613007: Refactor V8StringResource::prepare (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/V8StringResource.h
diff --git a/Source/bindings/v8/V8StringResource.h b/Source/bindings/v8/V8StringResource.h
index e11002e5b0492b719f3bb4e560c5610ef63c0dce..c7fbdf8a317ad4937dc6856dcdefd114d5e4c5a7 100644
--- a/Source/bindings/v8/V8StringResource.h
+++ b/Source/bindings/v8/V8StringResource.h
@@ -176,16 +176,16 @@ public:
{
}
- bool prepare();
- operator String() const { return toString<String>(); }
- operator AtomicString() const { return toString<AtomicString>(); }
-
-private:
- bool prepareBase()
+ bool prepare()
{
if (m_v8Object.IsEmpty())
return true;
+ if (!isValid()) {
+ setString(String());
+ return true;
+ }
+
if (LIKELY(m_v8Object->IsString()))
return true;
@@ -204,6 +204,11 @@ private:
}
return true;
}
+ operator String() const { return toString<String>(); }
+ operator AtomicString() const { return toString<AtomicString>(); }
+
+private:
+ bool isValid() const;
void setString(const String& string)
{
@@ -225,27 +230,19 @@ private:
String m_string;
};
-template<> inline bool V8StringResource<DefaultMode>::prepare()
+template<> inline bool V8StringResource<DefaultMode>::isValid() const
{
- return prepareBase();
+ return true;
}
-template<> inline bool V8StringResource<WithNullCheck>::prepare()
+template<> inline bool V8StringResource<WithNullCheck>::isValid() const
{
- if (m_v8Object.IsEmpty() || m_v8Object->IsNull()) {
- setString(String());
- return true;
- }
- return prepareBase();
+ return !m_v8Object->IsNull();
}
-template<> inline bool V8StringResource<WithUndefinedOrNullCheck>::prepare()
+template<> inline bool V8StringResource<WithUndefinedOrNullCheck>::isValid() const
{
- if (m_v8Object.IsEmpty() || m_v8Object->IsNull() || m_v8Object->IsUndefined()) {
- setString(String());
- return true;
- }
- return prepareBase();
+ return !m_v8Object->IsNull() && !m_v8Object->IsUndefined();
}
} // namespace WebCore
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698