| 1 | /* |
| 2 | * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #include "Node.h" |
| 29 | #include <wtf/FastMalloc.h> |
| 30 | #include <wtf/HashMap.h> |
| 31 | #include <wtf/RefCounted.h> |
| 32 | #include <wtf/Variant.h> |
| 33 | #include <wtf/Vector.h> |
| 34 | #include <wtf/text/WTFString.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | class TypeConversions : public RefCounted<TypeConversions> { |
| 39 | public: |
| 40 | static Ref<TypeConversions> create() { return adoptRef(*new TypeConversions()); } |
| 41 | |
| 42 | struct OtherDictionary { |
| 43 | int longValue; |
| 44 | String stringValue; |
| 45 | }; |
| 46 | |
| 47 | struct Dictionary { |
| 48 | int longValue; |
| 49 | String stringValue; |
| 50 | String treatNullAsEmptyStringValue; |
| 51 | Vector<String> sequenceValue; |
| 52 | Variant<RefPtr<Node>, Vector<String>, OtherDictionary> unionValue; |
| 53 | int clampLongValue; |
| 54 | int enforceRangeLongValue; |
| 55 | }; |
| 56 | |
| 57 | int8_t testByte() { return m_byte; } |
| 58 | void setTestByte(int8_t value) { m_byte = value; } |
| 59 | int8_t testEnforceRangeByte() { return m_byte; } |
| 60 | void setTestEnforceRangeByte(int8_t value) { m_byte = value; } |
| 61 | int8_t testClampByte() { return m_byte; } |
| 62 | void setTestClampByte(int8_t value) { m_byte = value; } |
| 63 | uint8_t testOctet() { return m_octet; } |
| 64 | void setTestOctet(uint8_t value) { m_octet = value; } |
| 65 | uint8_t testEnforceRangeOctet() { return m_octet; } |
| 66 | void setTestEnforceRangeOctet(uint8_t value) { m_octet = value; } |
| 67 | uint8_t testClampOctet() { return m_octet; } |
| 68 | void setTestClampOctet(uint8_t value) { m_octet = value; } |
| 69 | |
| 70 | int16_t testShort() { return m_short; } |
| 71 | void setTestShort(int16_t value) { m_short = value; } |
| 72 | int16_t testEnforceRangeShort() { return m_short; } |
| 73 | void setTestEnforceRangeShort(int16_t value) { m_short = value; } |
| 74 | int16_t testClampShort() { return m_short; } |
| 75 | void setTestClampShort(int16_t value) { m_short = value; } |
| 76 | uint16_t testUnsignedShort() { return m_unsignedShort; } |
| 77 | void setTestUnsignedShort(uint16_t value) { m_unsignedShort = value; } |
| 78 | uint16_t testEnforceRangeUnsignedShort() { return m_unsignedShort; } |
| 79 | void setTestEnforceRangeUnsignedShort(uint16_t value) { m_unsignedShort = value; } |
| 80 | uint16_t testClampUnsignedShort() { return m_unsignedShort; } |
| 81 | void setTestClampUnsignedShort(uint16_t value) { m_unsignedShort = value; } |
| 82 | |
| 83 | int testLong() { return m_long; } |
| 84 | void setTestLong(int value) { m_long = value; } |
| 85 | int testEnforceRangeLong() { return m_long; } |
| 86 | void setTestEnforceRangeLong(int value) { m_long = value; } |
| 87 | int testClampLong() { return m_long; } |
| 88 | void setTestClampLong(int value) { m_long = value; } |
| 89 | unsigned testUnsignedLong() { return m_unsignedLong; } |
| 90 | void setTestUnsignedLong(unsigned value) { m_unsignedLong = value; } |
| 91 | unsigned testEnforceRangeUnsignedLong() { return m_unsignedLong; } |
| 92 | void setTestEnforceRangeUnsignedLong(unsigned value) { m_unsignedLong = value; } |
| 93 | unsigned testClampUnsignedLong() { return m_unsignedLong; } |
| 94 | void setTestClampUnsignedLong(unsigned value) { m_unsignedLong = value; } |
| 95 | |
| 96 | long long testLongLong() { return m_longLong; } |
| 97 | void setTestLongLong(long long value) { m_longLong = value; } |
| 98 | long long testEnforceRangeLongLong() { return m_longLong; } |
| 99 | void setTestEnforceRangeLongLong(long long value) { m_longLong = value; } |
| 100 | long long testClampLongLong() { return m_longLong; } |
| 101 | void setTestClampLongLong(long long value) { m_longLong = value; } |
| 102 | unsigned long long testUnsignedLongLong() { return m_unsignedLongLong; } |
| 103 | void setTestUnsignedLongLong(unsigned long long value) { m_unsignedLongLong = value; } |
| 104 | unsigned long long testEnforceRangeUnsignedLongLong() { return m_unsignedLongLong; } |
| 105 | void setTestEnforceRangeUnsignedLongLong(unsigned long long value) { m_unsignedLongLong = value; } |
| 106 | unsigned long long testClampUnsignedLongLong() { return m_unsignedLongLong; } |
| 107 | void setTestClampUnsignedLongLong(unsigned long long value) { m_unsignedLongLong = value; } |
| 108 | |
| 109 | const String& testString() const { return m_string; } |
| 110 | void setTestString(const String& string) { m_string = string; } |
| 111 | const String& testUSVString() const { return m_usvstring; } |
| 112 | void setTestUSVString(const String& usvstring) { m_usvstring = usvstring; } |
| 113 | const String& testByteString() const { return m_byteString; } |
| 114 | void setTestByteString(const String& byteString) { m_byteString = byteString; } |
| 115 | const String& testTreatNullAsEmptyString() const { return m_treatNullAsEmptyString; } |
| 116 | void setTestTreatNullAsEmptyString(const String& string) { m_treatNullAsEmptyString = string; } |
| 117 | |
| 118 | const Vector<WTF::KeyValuePair<String, int>>& testLongRecord() const { return m_longRecord; } |
| 119 | void setTestLongRecord(const Vector<WTF::KeyValuePair<String, int>>& value) { m_longRecord = value; } |
| 120 | const Vector<WTF::KeyValuePair<String, RefPtr<Node>>>& testNodeRecord() const { return m_nodeRecord; } |
| 121 | void setTestNodeRecord(const Vector<WTF::KeyValuePair<String, RefPtr<Node>>>& value) { m_nodeRecord = value; } |
| 122 | const Vector<WTF::KeyValuePair<String, Vector<String>>>& testSequenceRecord() const { return m_sequenceRecord; } |
| 123 | void setTestSequenceRecord(const Vector<WTF::KeyValuePair<String, Vector<String>>>& value) { m_sequenceRecord = value; } |
| 124 | |
| 125 | using TestUnion = Variant<String, int, bool, RefPtr<Node>, Vector<int>>; |
| 126 | const TestUnion& testUnion() const { return m_union; } |
| 127 | void setTestUnion(TestUnion&& value) { m_union = value; } |
| 128 | |
| 129 | const Dictionary& testDictionary() const { return m_testDictionary; } |
| 130 | void setTestDictionary(Dictionary&& dictionary) { m_testDictionary = dictionary; } |
| 131 | |
| 132 | |
| 133 | using TestClampUnion = Variant<String, int, Vector<int>>; |
| 134 | const TestClampUnion& testClampUnion() const { return m_clampUnion; } |
| 135 | void setTestClampUnion(const TestClampUnion& value) { m_clampUnion = value; } |
| 136 | |
| 137 | using TestEnforceRangeUnion = Variant<String, int, Vector<int>>; |
| 138 | const TestEnforceRangeUnion& testEnforceRangeUnion() const { return m_enforceRangeUnion; } |
| 139 | void setTestEnforceRangeUnion(const TestEnforceRangeUnion& value) { m_enforceRangeUnion = value; } |
| 140 | |
| 141 | using TestTreatNullAsEmptyStringUnion = Variant<String, int, Vector<String>>; |
| 142 | const TestTreatNullAsEmptyStringUnion& testTreatNullAsEmptyStringUnion() const { return m_treatNullAsEmptyStringUnion; } |
| 143 | void setTestTreatNullAsEmptyStringUnion(const TestTreatNullAsEmptyStringUnion& value) { m_treatNullAsEmptyStringUnion = value; } |
| 144 | |
| 145 | double testImpureNaNUnrestrictedDouble() const { return bitwise_cast<double>(0xffff000000000000ll); } |
| 146 | double testImpureNaN2UnrestrictedDouble() const { return bitwise_cast<double>(0x7ff8000000000001ll); } |
| 147 | double testQuietNaNUnrestrictedDouble() const { return std::numeric_limits<double>::quiet_NaN(); } |
| 148 | double testPureNaNUnrestrictedDouble() const { return JSC::pureNaN(); } |
| 149 | |
| 150 | private: |
| 151 | TypeConversions() = default; |
| 152 | |
| 153 | int8_t m_byte { 0 }; |
| 154 | uint8_t m_octet { 0 }; |
| 155 | int16_t m_short { 0 }; |
| 156 | uint16_t m_unsignedShort { 0 }; |
| 157 | int m_long { 0 }; |
| 158 | unsigned m_unsignedLong { 0 }; |
| 159 | long long m_longLong { 0 }; |
| 160 | unsigned long long m_unsignedLongLong { 0 }; |
| 161 | String m_string; |
| 162 | String m_usvstring; |
| 163 | String m_byteString; |
| 164 | String m_treatNullAsEmptyString; |
| 165 | Vector<WTF::KeyValuePair<String, int>> m_longRecord; |
| 166 | Vector<WTF::KeyValuePair<String, RefPtr<Node>>> m_nodeRecord; |
| 167 | Vector<WTF::KeyValuePair<String, Vector<String>>> m_sequenceRecord; |
| 168 | |
| 169 | Dictionary m_testDictionary; |
| 170 | |
| 171 | TestUnion m_union; |
| 172 | TestClampUnion m_clampUnion; |
| 173 | TestEnforceRangeUnion m_enforceRangeUnion; |
| 174 | TestTreatNullAsEmptyStringUnion m_treatNullAsEmptyStringUnion; |
| 175 | }; |
| 176 | |
| 177 | } // namespace WebCore |
| 178 | |