OLD | NEW |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 namespace WebCore { | 50 namespace WebCore { |
51 | 51 |
52 class JSONValue; | 52 class JSONValue; |
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 : m_isolate(0) |
| 62 { } |
| 63 |
61 virtual ~ScriptValue(); | 64 virtual ~ScriptValue(); |
62 | 65 |
63 ScriptValue(v8::Handle<v8::Value> value, v8::Isolate* isolate) | 66 ScriptValue(v8::Handle<v8::Value> value, v8::Isolate* isolate) |
64 : m_value(value.IsEmpty() ? 0 : SharedPersistent<v8::Value>::create(valu
e, isolate)) | 67 : m_isolate(isolate) |
| 68 , m_value(value.IsEmpty() ? 0 : SharedPersistent<v8::Value>::create(valu
e, isolate)) |
65 { | 69 { |
66 } | 70 } |
67 | 71 |
68 ScriptValue(const ScriptValue& value) | 72 ScriptValue(const ScriptValue& value) |
69 : m_value(value.m_value) | 73 : m_isolate(value.m_isolate) |
| 74 , m_value(value.m_value) |
70 { | 75 { |
71 } | 76 } |
72 | 77 |
| 78 v8::Isolate* isolate() const |
| 79 { |
| 80 if (!m_isolate) |
| 81 m_isolate = v8::Isolate::GetCurrent(); |
| 82 return m_isolate; |
| 83 } |
| 84 |
73 static ScriptValue createNull() | 85 static ScriptValue createNull() |
74 { | 86 { |
75 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 87 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
76 return ScriptValue(v8::Null(isolate), isolate); | 88 return ScriptValue(v8::Null(isolate), isolate); |
77 } | 89 } |
78 static ScriptValue createBoolean(bool b) | 90 static ScriptValue createBoolean(bool b) |
79 { | 91 { |
80 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 92 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
81 return ScriptValue(b ? v8::True(isolate) : v8::False(isolate), isolate); | 93 return ScriptValue(b ? v8::True(isolate) : v8::False(isolate), isolate); |
82 } | 94 } |
83 | 95 |
84 ScriptValue& operator=(const ScriptValue& value) | 96 ScriptValue& operator=(const ScriptValue& value) |
85 { | 97 { |
86 if (this != &value) | 98 if (this != &value) { |
87 m_value = value.m_value; | 99 m_value = value.m_value; |
| 100 m_isolate = value.m_isolate; |
| 101 } |
88 return *this; | 102 return *this; |
89 } | 103 } |
90 | 104 |
91 bool operator==(const ScriptValue& value) const | 105 bool operator==(const ScriptValue& value) const |
92 { | 106 { |
93 if (hasNoValue()) | 107 if (hasNoValue()) |
94 return value.hasNoValue(); | 108 return value.hasNoValue(); |
95 if (value.hasNoValue()) | 109 if (value.hasNoValue()) |
96 return false; | 110 return false; |
97 return *m_value == *value.m_value; | 111 return *m_value == *value.m_value; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 PassRefPtr<SerializedScriptValue> serialize(ScriptState*, MessagePortArray*,
ArrayBufferArray*, bool&); | 166 PassRefPtr<SerializedScriptValue> serialize(ScriptState*, MessagePortArray*,
ArrayBufferArray*, bool&); |
153 static ScriptValue deserialize(ScriptState*, SerializedScriptValue*); | 167 static ScriptValue deserialize(ScriptState*, SerializedScriptValue*); |
154 | 168 |
155 void clear() | 169 void clear() |
156 { | 170 { |
157 m_value = 0; | 171 m_value = 0; |
158 } | 172 } |
159 | 173 |
160 v8::Handle<v8::Value> v8Value() const | 174 v8::Handle<v8::Value> v8Value() const |
161 { | 175 { |
162 return m_value.get() ? m_value->newLocal(v8::Isolate::GetCurrent()) : v8
::Handle<v8::Value>(); | 176 return m_value.get() ? m_value->newLocal(m_isolate) : v8::Handle<v8::Val
ue>(); |
163 } | 177 } |
164 | 178 |
165 bool getString(ScriptState* scriptState, String& result) const { return getS
tring(result, scriptState->isolate()); } | 179 bool getString(String& result) const; |
166 bool getString(String& result) const { return getString(result, v8::Isolate:
:GetCurrent()); } | 180 String toString() const; |
167 bool getString(String& result, v8::Isolate*) const; | |
168 String toString(ScriptState*) const; | |
169 | 181 |
170 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const; | 182 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const; |
171 | 183 |
172 private: | 184 private: |
| 185 mutable v8::Isolate* m_isolate; |
173 RefPtr<SharedPersistent<v8::Value> > m_value; | 186 RefPtr<SharedPersistent<v8::Value> > m_value; |
174 }; | 187 }; |
175 | 188 |
176 } // namespace WebCore | 189 } // namespace WebCore |
177 | 190 |
178 #endif // ScriptValue_h | 191 #endif // ScriptValue_h |
OLD | NEW |