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

Side by Side Diff: Source/bindings/v8/ScriptValue.h

Issue 147333004: Revert of Limit the usage of SharedPersistent to ScriptValue only (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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/v8/ScriptController.cpp ('k') | Source/bindings/v8/SharedPersistent.h » ('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) 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009 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
(...skipping 13 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 ScriptValue_h 31 #ifndef ScriptValue_h
32 #define ScriptValue_h 32 #define ScriptValue_h
33 33
34 #include "bindings/v8/ScopedPersistent.h" 34 #include "bindings/v8/SharedPersistent.h"
35 #include "wtf/RefCounted.h" 35 #include "wtf/PassRefPtr.h"
36 #include "wtf/RefPtr.h" 36 #include "wtf/RefPtr.h"
37 #include "wtf/text/WTFString.h" 37 #include "wtf/text/WTFString.h"
38 #include <v8.h> 38 #include <v8.h>
39 39
40 namespace WebCore { 40 namespace WebCore {
41 41
42 class JSONValue; 42 class JSONValue;
43 class ScriptState; 43 class ScriptState;
44 44
45 class ScriptValue { 45 class ScriptValue {
46 public: 46 public:
47 ScriptValue() 47 ScriptValue()
48 : m_isolate(0) 48 : m_isolate(0)
49 { } 49 { }
50 50
51 virtual ~ScriptValue(); 51 virtual ~ScriptValue();
52 52
53 ScriptValue(v8::Handle<v8::Value> value, v8::Isolate* isolate) 53 ScriptValue(v8::Handle<v8::Value> value, v8::Isolate* isolate)
54 : m_isolate(isolate) 54 : m_isolate(isolate)
55 , m_value(value.IsEmpty() ? 0 : SharedPersistent::create(value, isolate) ) 55 , m_value(value.IsEmpty() ? 0 : SharedPersistent<v8::Value>::create(valu e, isolate))
56 { 56 {
57 } 57 }
58 58
59 ScriptValue(const ScriptValue& value) 59 ScriptValue(const ScriptValue& value)
60 : m_isolate(value.m_isolate) 60 : m_isolate(value.m_isolate)
61 , m_value(value.m_value) 61 , m_value(value.m_value)
62 { 62 {
63 } 63 }
64 64
65 v8::Isolate* isolate() const 65 v8::Isolate* isolate() const
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 { 158 {
159 return m_value.get() ? m_value->newLocal(m_isolate) : v8::Handle<v8::Val ue>(); 159 return m_value.get() ? m_value->newLocal(m_isolate) : v8::Handle<v8::Val ue>();
160 } 160 }
161 161
162 bool getString(String& result) const; 162 bool getString(String& result) const;
163 String toString() const; 163 String toString() const;
164 164
165 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const; 165 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const;
166 166
167 private: 167 private:
168 class SharedPersistent : public RefCounted<SharedPersistent> {
169 WTF_MAKE_NONCOPYABLE(SharedPersistent);
170 public:
171 static PassRefPtr<SharedPersistent> create(v8::Handle<v8::Value> value, v8::Isolate* isolate)
172 {
173 return adoptRef(new SharedPersistent(value, isolate));
174 }
175
176 v8::Local<v8::Value> newLocal(v8::Isolate* isolate) const
177 {
178 return m_value.newLocal(isolate);
179 }
180
181 bool isEmpty() { return m_value.isEmpty(); }
182
183 bool operator==(const SharedPersistent& other)
184 {
185 return m_value == other.m_value;
186 }
187
188 private:
189 SharedPersistent(v8::Handle<v8::Value> value, v8::Isolate* isolate)
190 : m_value(isolate, value)
191 {
192 }
193
194 ScopedPersistent<v8::Value> m_value;
195 };
196
197 mutable v8::Isolate* m_isolate; 168 mutable v8::Isolate* m_isolate;
198 RefPtr<SharedPersistent> m_value; 169 RefPtr<SharedPersistent<v8::Value> > m_value;
199 }; 170 };
200 171
201 } // namespace WebCore 172 } // namespace WebCore
202 173
203 #endif // ScriptValue_h 174 #endif // ScriptValue_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptController.cpp ('k') | Source/bindings/v8/SharedPersistent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698