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

Unified Diff: Source/wtf/UnionType.h

Issue 15076011: Support union return type for anonymous named/indexed getter (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: updated Created 7 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
Index: Source/wtf/UnionType.h
diff --git a/Source/wtf/BitArray.h b/Source/wtf/UnionType.h
similarity index 59%
copy from Source/wtf/BitArray.h
copy to Source/wtf/UnionType.h
index 9ad1e0a1f95af02ac4c8e8eeced254d260a9255a..c49461324f59a0bd2a1ee4e91d9314740ec6a802 100644
--- a/Source/wtf/BitArray.h
+++ b/Source/wtf/UnionType.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
haraken 2013/05/15 12:09:43 Please use this: /* * Copyright (C) 2013 Google
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -20,43 +20,55 @@
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef BitArray_h
-#define BitArray_h
-
-#include <string.h>
-#include <wtf/Assertions.h>
+#ifndef UnionType_h
+#define UnionType_h
namespace WTF {
-template<unsigned arraySize>
-class BitArray {
+/*
+ * UnionTypeN holds multiple types of objects.
haraken 2013/05/15 12:09:43 Nit: Blink uses // for multiline comments.
+ *
+ * WebIDL(UnionType):
+ * http://www.w3.org/TR/WebIDL/#prod-UnionType
+ *
+ * Example IDL:
+ * http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlformcontrolscollection
+ */
+template<typename Type0, typename Type1>
+class UnionType2 {
public:
- BitArray()
+ explicit UnionType2()
haraken 2013/05/15 12:09:43 'explicit' is needed only for one-argument constru
{
- memset(m_data, 0, sizeof(m_data));
}
-
- void set(unsigned index)
+ explicit UnionType2(PassRefPtr<Type0> value)
{
- ASSERT_WITH_SECURITY_IMPLICATION(index < arraySize);
- m_data[index / 8] |= 1 << (index & 7);
+ m_value0 = value;
}
-
- bool get(unsigned index) const
+ explicit UnionType2(PassRefPtr<Type1> value)
{
- ASSERT_WITH_SECURITY_IMPLICATION(index < arraySize);
- return !!(m_data[index / 8] & (1 << (index & 7)));
+ m_value1 = value;
+ }
+ bool isNull() const
+ {
+ return !m_value0 && !m_value1;
+ }
+ PassRefPtr<Type0> enabledValue0() const
jsbell 2013/05/15 21:37:52 Naming suggestion: in Web IDL, a UnionType is comp
+ {
+ return m_value0;
+ }
+ PassRefPtr<Type1> enabledValue1() const
+ {
+ return m_value1;
}
-
private:
- unsigned char m_data[arraySize / 8 + 1];
+ RefPtr<Type0> m_value0;
+ RefPtr<Type1> m_value1;
};
-} // namespace WTF
-using WTF::BitArray;
+} // namespace WTF
-#endif // BitArray_h
+#endif // UnionType_h

Powered by Google App Engine
This is Rietveld 408576698