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

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

Issue 1532413002: Added Dartium changes onto 45.0.2454.104 (Closed) Base URL: http://src.chromium.org/blink/branches/chromium/2454
Patch Set: Created 5 years 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2014 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30
31 #ifndef DartScriptValue_h
32 #define DartScriptValue_h
33
34 #include "bindings/common/AbstractScriptValue.h"
35 #include "bindings/core/dart/DartPersistentValue.h"
36 #include "bindings/core/dart/DartScriptState.h"
37 #include "bindings/core/dart/V8Converter.h"
38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefPtr.h"
40 #include "wtf/text/WTFString.h"
41 #include <dart_api.h>
42
43 namespace blink {
44
45 class JSONValue;
46 class ScriptState;
47
48 class DartScriptValue : public AbstractScriptValue {
49 WTF_MAKE_NONCOPYABLE(DartScriptValue);
50 public:
51 virtual ~DartScriptValue();
52
53 static PassRefPtr<DartScriptValue> create(DartScriptState *scriptState, Dart _Handle value)
54 {
55 return adoptRef(new DartScriptValue(scriptState, value));
56 }
57
58 static PassRefPtr<DartScriptValue> create()
59 {
60 return adoptRef(new DartScriptValue());
61 }
62
63 ScriptState* scriptState() const
64 {
65 return m_scriptState.get();
66 }
67
68 bool isDart() const { return true; }
69
70 Dart_Handle dartValue() const { return m_value.value(); }
71
72 v8::Handle<v8::Value> v8Value() const
73 {
74 // FIXMEMULTIVM: Should not be converting v8 values. Major culprit is ID B.
75 Dart_Handle exception = 0;
76 v8::Handle<v8::Value> value = V8Converter::toV8(m_value.value(), excepti on);
77 if (exception)
78 return v8::Undefined(m_scriptState->v8ScriptState()->isolate());
79 ASSERT(!value.IsEmpty());
80 return value;
81 }
82
83 bool equals(AbstractScriptValue* other) const
84 {
85 if (!other->isDart())
86 return false;
87
88 DartScriptValue* dartOther = static_cast<DartScriptValue*>(other);
89 if (isEmpty())
90 return dartOther->isEmpty();
91 if (dartOther->isEmpty())
92 return false;
93 return Dart_IdentityEquals(dartValue(), dartOther->dartValue());
94 }
95
96 bool isFunction() const
97 {
98 ASSERT(!isEmpty());
99 return Dart_IsClosure(dartValue());
100 }
101
102 bool isNull() const
103 {
104 ASSERT(!isEmpty());
105 return Dart_IsNull(dartValue());
106 }
107
108 bool isUndefined() const
109 {
110 ASSERT(!isEmpty());
111 return false;
112 }
113
114 bool isObject() const
115 {
116 ASSERT(!isEmpty());
117 return true;
118 }
119
120 bool isEmpty() const
121 {
122 return !dartValue();
123 }
124
125 void clear()
126 {
127 m_value.clear();
128 }
129
130 bool toString(String& result) const;
131
132 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const;
133
134 PassRefPtr<AbstractScriptPromise> toPromise() const;
135 PassRefPtr<AbstractScriptPromise> toRejectedPromise() const;
136
137 IDBKey* createIDBKeyFromKeyPath(const IDBKeyPath&);
138 bool canInjectIDBKey(const IDBKeyPath&);
139 IDBKey* toIDBKey();
140 IDBKeyRange* toIDBKeyRange();
141
142 private:
143 RefPtr<DartScriptState> m_scriptState;
144 DartPersistentValue m_value;
145
146 explicit DartScriptValue()
147 : m_scriptState(nullptr)
148 , m_value(0)
149 {
150 }
151
152 explicit DartScriptValue(DartScriptState* scriptState, Dart_Handle value)
153 : m_scriptState(scriptState)
154 , m_value(value)
155 {
156 }
157 };
158
159 } // namespace blink
160
161 #endif // DartScriptValue_h
OLDNEW
« no previous file with comments | « Source/bindings/core/dart/DartScriptState.cpp ('k') | Source/bindings/core/dart/DartScriptValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698