Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef DartScriptValue_h | 31 #ifndef DartScriptValue_h |
| 32 #define DartScriptValue_h | 32 #define DartScriptValue_h |
| 33 | 33 |
| 34 #include "bindings/dart/DartIsolateDestructionObserver.h" | 34 #include "bindings/common/AbstractScriptValue.h" |
| 35 | 35 #include "bindings/dart/V8Converter.h" |
| 36 #include "wtf/PassRefPtr.h" | |
| 37 #include "wtf/RefPtr.h" | |
| 38 #include "wtf/text/WTFString.h" | |
| 36 #include <dart_api.h> | 39 #include <dart_api.h> |
| 37 #include <wtf/Noncopyable.h> | |
| 38 #include <wtf/RefPtr.h> | |
| 39 | 40 |
| 40 namespace WebCore { | 41 namespace WebCore { |
| 41 | 42 |
| 42 class DartScriptValue : public DartIsolateDestructionObserver { | 43 class JSONValue; |
| 44 class ScriptState; | |
| 45 | |
| 46 class DartScriptValue : public AbstractScriptValue { | |
| 43 WTF_MAKE_NONCOPYABLE(DartScriptValue); | 47 WTF_MAKE_NONCOPYABLE(DartScriptValue); |
| 44 public: | 48 public: |
| 45 explicit DartScriptValue(Dart_Handle value); | 49 virtual ~DartScriptValue(); |
| 46 ~DartScriptValue(); | |
| 47 | 50 |
| 48 Dart_PersistentHandle value() { return m_value; } | 51 static PassRefPtr<DartScriptValue> create(Dart_Handle value) |
| 52 { | |
| 53 return adoptRef(new DartScriptValue(value)); | |
| 54 } | |
| 55 | |
| 56 static PassRefPtr<DartScriptValue> create() | |
| 57 { | |
| 58 return adoptRef(new DartScriptValue()); | |
| 59 } | |
| 60 | |
| 61 bool isV8() const { return false; } | |
|
siva
2014/05/21 21:56:17
Is this needed? AbstractScriptValue already has th
rmacnak
2014/05/22 20:27:19
Removed.
| |
| 62 bool isDart() const { return true; } | |
| 63 | |
| 64 Dart_Handle dartValue() const { return m_value; } | |
| 65 | |
| 66 v8::Handle<v8::Value> v8Value() const | |
| 67 { | |
| 68 // FIXMEMUTLIVM: Should not be converting v8 values. Major culprit is ID B. | |
| 69 Dart_Handle exception = 0; | |
| 70 return V8Converter::toV8(m_value, exception); | |
| 71 } | |
| 72 | |
| 73 bool equals(AbstractScriptValue* other) const | |
| 74 { | |
| 75 if (!other->isDart()) | |
| 76 return false; | |
| 77 | |
| 78 DartScriptValue* dartOther = static_cast<DartScriptValue*>(other); | |
| 79 if (hasNoValue()) | |
| 80 return dartOther->hasNoValue(); | |
| 81 if (dartOther->hasNoValue()) | |
| 82 return false; | |
| 83 return Dart_IdentityEquals(m_value, dartOther->m_value); | |
| 84 } | |
| 85 | |
| 86 bool isEqual(ScriptState*, const DartScriptValue& other) const | |
|
siva
2014/05/21 21:56:17
Why do we have this unused parameter ScriptState*
rmacnak
2014/05/22 20:27:19
Hm, isEqual is is no longer used and is already re
| |
| 87 { | |
| 88 if (hasNoValue()) | |
| 89 return other.hasNoValue(); | |
| 90 if (other.hasNoValue()) | |
| 91 return false; | |
| 92 return Dart_IdentityEquals(m_value, other.m_value); | |
| 93 } | |
| 94 | |
| 95 bool isFunction() const | |
| 96 { | |
| 97 ASSERT(!hasNoValue()); | |
| 98 return Dart_IsClosure(m_value); | |
| 99 } | |
| 100 | |
| 101 bool isNull() const | |
| 102 { | |
| 103 ASSERT(!hasNoValue()); | |
| 104 return Dart_IsNull(m_value); | |
| 105 } | |
| 106 | |
| 107 bool isUndefined() const | |
| 108 { | |
| 109 ASSERT(!hasNoValue()); | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 113 bool isObject() const | |
| 114 { | |
| 115 ASSERT(!hasNoValue()); | |
| 116 return true; | |
| 117 } | |
| 118 | |
| 119 bool hasNoValue() const | |
| 120 { | |
| 121 return !m_value; | |
| 122 } | |
| 123 | |
| 124 void clear() | |
| 125 { | |
| 126 m_value = 0; | |
| 127 } | |
| 128 | |
| 129 bool getString(String& result) const; | |
| 130 String toString() const; | |
| 131 | |
| 132 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const; | |
| 49 | 133 |
| 50 private: | 134 private: |
| 51 Dart_PersistentHandle m_value; | 135 Dart_Handle m_value; |
| 136 | |
| 137 explicit DartScriptValue() | |
| 138 : m_value(0) | |
| 139 { | |
| 140 } | |
| 141 | |
| 142 explicit DartScriptValue(Dart_Handle value) | |
| 143 : m_value(value) | |
| 144 { | |
| 145 } | |
| 52 }; | 146 }; |
| 53 | 147 |
| 54 } | 148 } // namespace WebCore |
| 55 | 149 |
| 56 #endif // DartScriptValue_h | 150 #endif // DartScriptValue_h |
| OLD | NEW |