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

Side by Side Diff: Source/bindings/dart/DartScriptValue.h

Issue 289083003: [dartium] Dart half of ScriptValue refactoring. (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/1916
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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/dart/DartPersistentValue.cpp ('k') | Source/bindings/dart/DartScriptValue.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 isDart() const { return true; }
62
63 Dart_Handle dartValue() const { return m_value; }
64
65 v8::Handle<v8::Value> v8Value() const
66 {
67 // FIXMEMUTLIVM: Should not be converting v8 values. Major culprit is ID B.
68 Dart_Handle exception = 0;
69 return V8Converter::toV8(m_value, exception);
70 }
71
72 bool equals(AbstractScriptValue* other) const
73 {
74 if (!other->isDart())
75 return false;
76
77 DartScriptValue* dartOther = static_cast<DartScriptValue*>(other);
78 if (hasNoValue())
79 return dartOther->hasNoValue();
80 if (dartOther->hasNoValue())
81 return false;
82 return Dart_IdentityEquals(m_value, dartOther->m_value);
83 }
84
85 bool isFunction() const
86 {
87 ASSERT(!hasNoValue());
88 return Dart_IsClosure(m_value);
89 }
90
91 bool isNull() const
92 {
93 ASSERT(!hasNoValue());
94 return Dart_IsNull(m_value);
95 }
96
97 bool isUndefined() const
98 {
99 ASSERT(!hasNoValue());
100 return false;
101 }
102
103 bool isObject() const
104 {
105 ASSERT(!hasNoValue());
106 return true;
107 }
108
109 bool hasNoValue() const
110 {
111 return !m_value;
112 }
113
114 void clear()
115 {
116 m_value = 0;
117 }
118
119 bool getString(String& result) const;
120 String toString() const;
121
122 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const;
49 123
50 private: 124 private:
51 Dart_PersistentHandle m_value; 125 Dart_Handle m_value;
126
127 explicit DartScriptValue()
128 : m_value(0)
129 {
130 }
131
132 explicit DartScriptValue(Dart_Handle value)
133 : m_value(value)
134 {
135 }
52 }; 136 };
53 137
54 } 138 } // namespace WebCore
55 139
56 #endif // DartScriptValue_h 140 #endif // DartScriptValue_h
OLDNEW
« no previous file with comments | « Source/bindings/dart/DartPersistentValue.cpp ('k') | Source/bindings/dart/DartScriptValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698