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

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

Issue 12926003: Merge 144458 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1410/
Patch Set: Created 7 years, 9 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
« no previous file with comments | « no previous file | Source/WebCore/bindings/v8/ScriptValue.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) 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 "ScopedPersistent.h"
35 #include "ScriptState.h" 34 #include "ScriptState.h"
35 #include "SharedPersistent.h"
36 #include <v8.h> 36 #include <v8.h>
37 #include <wtf/PassRefPtr.h> 37 #include <wtf/PassRefPtr.h>
38 #include <wtf/RefPtr.h> 38 #include <wtf/RefPtr.h>
39 #include <wtf/Vector.h> 39 #include <wtf/Vector.h>
40 #include <wtf/text/WTFString.h> 40 #include <wtf/text/WTFString.h>
41 41
42 #ifndef NDEBUG 42 #ifndef NDEBUG
43 #include "V8GCController.h" 43 #include "V8GCController.h"
44 #endif 44 #endif
45 45
46 namespace WTF { 46 namespace WTF {
47 class ArrayBuffer; 47 class ArrayBuffer;
48 } 48 }
49 49
50 namespace WebCore { 50 namespace WebCore {
51 51
52 class InspectorValue; 52 class InspectorValue;
53 class MessagePort; 53 class MessagePort;
54 class SerializedScriptValue; 54 class SerializedScriptValue;
55 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; 55 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
56 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; 56 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray;
57 57
58 class ScriptValue { 58 class ScriptValue {
59 public: 59 public:
60 ScriptValue() { } 60 ScriptValue() { }
61 virtual ~ScriptValue(); 61 virtual ~ScriptValue();
62 62
63 ScriptValue(v8::Handle<v8::Value> value) 63 ScriptValue(v8::Handle<v8::Value> value)
64 : m_value(value.IsEmpty() ? 0 : SharedPersistent<v8::Value>::create(valu e))
64 { 65 {
65 if (value.IsEmpty())
66 return;
67 m_value.set(value);
68 } 66 }
69 67
70 ScriptValue(const ScriptValue& value) 68 ScriptValue(const ScriptValue& value)
69 : m_value(value.m_value)
71 { 70 {
72 if (value.hasNoValue())
73 return;
74 m_value.set(value.m_value.get());
75 } 71 }
76 72
77 ScriptValue& operator=(const ScriptValue& value) 73 ScriptValue& operator=(const ScriptValue& value)
78 { 74 {
79 if (this == &value) 75 if (this != &value)
80 return *this; 76 m_value = value.m_value;
81
82 m_value.clear();
83
84 if (value.hasNoValue())
85 return *this;
86
87 m_value.set(value.m_value.get());
88 return *this; 77 return *this;
89 } 78 }
90 79
91 bool operator==(const ScriptValue& value) const 80 bool operator==(const ScriptValue& value) const
92 { 81 {
93 return m_value.get() == value.m_value.get(); 82 return v8ValueRaw() == value.v8ValueRaw();
94 } 83 }
95 84
96 bool isEqual(ScriptState*, const ScriptValue& value) const 85 bool isEqual(ScriptState*, const ScriptValue& value) const
97 { 86 {
98 return m_value.get() == value.m_value.get(); 87 return operator==(value);
99 } 88 }
100 89
101 bool isFunction() const 90 bool isFunction() const
102 { 91 {
103 return m_value->IsFunction(); 92 ASSERT(!hasNoValue());
93 return v8ValueRaw()->IsFunction();
104 } 94 }
105 95
106 bool operator!=(const ScriptValue& value) const 96 bool operator!=(const ScriptValue& value) const
107 { 97 {
108 return !operator==(value); 98 return !operator==(value);
109 } 99 }
110 100
111 bool isNull() const 101 bool isNull() const
112 { 102 {
113 return m_value->IsNull(); 103 ASSERT(!hasNoValue());
104 return v8ValueRaw()->IsNull();
114 } 105 }
115 106
116 bool isUndefined() const 107 bool isUndefined() const
117 { 108 {
118 return m_value->IsUndefined(); 109 ASSERT(!hasNoValue());
110 return v8ValueRaw()->IsUndefined();
119 } 111 }
120 112
121 bool isObject() const 113 bool isObject() const
122 { 114 {
123 return m_value->IsObject(); 115 ASSERT(!hasNoValue());
116 return v8ValueRaw()->IsObject();
124 } 117 }
125 118
126 bool hasNoValue() const 119 bool hasNoValue() const
127 { 120 {
128 return m_value.isEmpty(); 121 return !m_value.get() || m_value->get().IsEmpty();
129 } 122 }
130 123
131 PassRefPtr<SerializedScriptValue> serialize(ScriptState*); 124 PassRefPtr<SerializedScriptValue> serialize(ScriptState*);
132 PassRefPtr<SerializedScriptValue> serialize(ScriptState*, MessagePortArray*, ArrayBufferArray*, bool&); 125 PassRefPtr<SerializedScriptValue> serialize(ScriptState*, MessagePortArray*, ArrayBufferArray*, bool&);
133 static ScriptValue deserialize(ScriptState*, SerializedScriptValue*); 126 static ScriptValue deserialize(ScriptState*, SerializedScriptValue*);
134 127
135 void clear() 128 void clear()
136 { 129 {
137 m_value.clear(); 130 m_value = 0;
138 } 131 }
139 132
140 v8::Handle<v8::Value> v8Value() const { return m_value.get(); } 133 v8::Handle<v8::Value> v8Value() const
134 {
135 return v8::Local<v8::Value>::New(v8ValueRaw());
136 }
137
138 // FIXME: This function should be private.
139 v8::Handle<v8::Value> v8ValueRaw() const
140 {
141 return m_value.get() ? m_value->get() : v8::Handle<v8::Value>();
142 }
141 143
142 bool getString(ScriptState*, String& result) const { return getString(result ); } 144 bool getString(ScriptState*, String& result) const { return getString(result ); }
143 bool getString(String& result) const; 145 bool getString(String& result) const;
144 String toString(ScriptState*) const; 146 String toString(ScriptState*) const;
145 147
146 PassRefPtr<InspectorValue> toInspectorValue(ScriptState*) const; 148 PassRefPtr<InspectorValue> toInspectorValue(ScriptState*) const;
147 149
148 private: 150 private:
149 ScopedPersistent<v8::Value> m_value; 151 RefPtr<SharedPersistent<v8::Value> > m_value;
150 }; 152 };
151 153
152 } // namespace WebCore 154 } // namespace WebCore
153 155
154 #endif // ScriptValue_h 156 #endif // ScriptValue_h
OLDNEW
« no previous file with comments | « no previous file | Source/WebCore/bindings/v8/ScriptValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698