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

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

Issue 177633006: Implement IDBVersionChangeEvent ctor w/ IDBVersionChangeEventInit dict (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase, handle null, and simplify Created 6 years, 10 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 | « Source/bindings/v8/Dictionary.h ('k') | Source/modules/indexeddb/IDBDatabase.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/Nullable.h
diff --git a/Source/bindings/v8/Nullable.h b/Source/bindings/v8/Nullable.h
new file mode 100644
index 0000000000000000000000000000000000000000..0f8356c472d399a03fad26c4fcbcda01f3f8ce64
--- /dev/null
+++ b/Source/bindings/v8/Nullable.h
@@ -0,0 +1,51 @@
+// Copyright 2014 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.
+
+#ifndef Nullable_h
+#define Nullable_h
+
+#include "wtf/Assertions.h"
+
+namespace WebCore {
jsbell 2014/02/27 20:59:06 Could be in wtf, but I started conservatively.
+
+template <typename T>
+class Nullable {
+public:
+ Nullable()
jsbell 2014/02/27 20:59:06 I also considered Nullable<type>::null() as a stat
+ : m_value()
+ , m_isNull(true) { }
+
+ Nullable(const T& value)
+ : m_value(value)
+ , m_isNull(false) { }
+
+ Nullable(const Nullable& other)
+ : m_value(other.m_value)
+ , m_isNull(other.m_isNull) { }
+
+ Nullable& operator=(const Nullable& other)
+ {
+ m_value = other.m_value;
+ m_isNull = other.m_isNull;
+ return *this;
+ }
+
+ T get() const { ASSERT(!m_isNull); return m_value; }
jsbell 2014/02/27 20:59:06 I did NOT expose an `operator T()` conversion, fav
+ bool isNull() const { return m_isNull; }
+
+ operator bool() const { return !m_isNull && m_value; }
jsbell 2014/02/27 20:59:06 This was required by the Dictionary. I'll admit I
+
+ bool operator==(const Nullable& other) const
+ {
+ return (m_isNull && other.m_isNull) || (!m_isNull && !other.m_isNull && m_value == other.m_value);
+ }
+
+private:
+ T m_value;
+ bool m_isNull;
+};
+
+} // namespace WebCore
+
+#endif // Nullable_h
« no previous file with comments | « Source/bindings/v8/Dictionary.h ('k') | Source/modules/indexeddb/IDBDatabase.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698