Chromium Code Reviews| 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) | |
|
haraken
2013/09/18 00:25:12
Is there any reason why we can't call Isolate::Get
do-not-use
2013/09/18 06:35:15
My understanding was that we wanted to avoid calls
haraken
2013/09/18 07:02:15
Understood.
| |
| 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 { return m_isolate; } | |
|
haraken
2013/09/18 00:25:12
Even if we cannot ensure that m_isolate is not 0 f
do-not-use
2013/09/18 06:35:15
Yes, this sounds like a good idea.
do-not-use
2013/09/18 07:18:46
Done.
| |
| 79 | |
| 73 static ScriptValue createNull() | 80 static ScriptValue createNull() |
| 74 { | 81 { |
| 75 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 82 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 76 return ScriptValue(v8::Null(isolate), isolate); | 83 return ScriptValue(v8::Null(isolate), isolate); |
| 77 } | 84 } |
| 78 static ScriptValue createBoolean(bool b) | 85 static ScriptValue createBoolean(bool b) |
| 79 { | 86 { |
| 80 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 87 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 81 return ScriptValue(b ? v8::True(isolate) : v8::False(isolate), isolate); | 88 return ScriptValue(b ? v8::True(isolate) : v8::False(isolate), isolate); |
| 82 } | 89 } |
| 83 | 90 |
| 84 ScriptValue& operator=(const ScriptValue& value) | 91 ScriptValue& operator=(const ScriptValue& value) |
| 85 { | 92 { |
| 86 if (this != &value) | 93 if (this != &value) { |
| 87 m_value = value.m_value; | 94 m_value = value.m_value; |
| 95 m_isolate = value.m_isolate; | |
| 96 } | |
| 88 return *this; | 97 return *this; |
| 89 } | 98 } |
| 90 | 99 |
| 91 bool operator==(const ScriptValue& value) const | 100 bool operator==(const ScriptValue& value) const |
| 92 { | 101 { |
| 93 if (hasNoValue()) | 102 if (hasNoValue()) |
| 94 return value.hasNoValue(); | 103 return value.hasNoValue(); |
| 95 if (value.hasNoValue()) | 104 if (value.hasNoValue()) |
| 96 return false; | 105 return false; |
| 97 return *m_value == *value.m_value; | 106 return *m_value == *value.m_value; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 return !m_value.get() || m_value->isEmpty(); | 157 return !m_value.get() || m_value->isEmpty(); |
| 149 } | 158 } |
| 150 | 159 |
| 151 PassRefPtr<SerializedScriptValue> serialize(ScriptState*); | 160 PassRefPtr<SerializedScriptValue> serialize(ScriptState*); |
| 152 PassRefPtr<SerializedScriptValue> serialize(ScriptState*, MessagePortArray*, ArrayBufferArray*, bool&); | 161 PassRefPtr<SerializedScriptValue> serialize(ScriptState*, MessagePortArray*, ArrayBufferArray*, bool&); |
| 153 static ScriptValue deserialize(ScriptState*, SerializedScriptValue*); | 162 static ScriptValue deserialize(ScriptState*, SerializedScriptValue*); |
| 154 | 163 |
| 155 void clear() | 164 void clear() |
| 156 { | 165 { |
| 157 m_value = 0; | 166 m_value = 0; |
| 167 m_isolate = 0; | |
|
haraken
2013/09/18 00:25:12
Do we need to clear an isolate? In other words, is
do-not-use
2013/09/18 06:35:15
I honestly have no idea. I chose the "safe" approa
haraken
2013/09/18 07:02:15
I believe you can remove m_isolate=0. V8 heaps are
do-not-use
2013/09/18 07:18:46
Done.
| |
| 158 } | 168 } |
| 159 | 169 |
| 160 v8::Handle<v8::Value> v8Value() const | 170 v8::Handle<v8::Value> v8Value() const |
| 161 { | 171 { |
| 162 return m_value.get() ? m_value->newLocal(v8::Isolate::GetCurrent()) : v8 ::Handle<v8::Value>(); | 172 return m_value.get() ? m_value->newLocal(m_isolate) : v8::Handle<v8::Val ue>(); |
| 163 } | 173 } |
| 164 | 174 |
| 165 bool getString(ScriptState* scriptState, String& result) const { return getS tring(result, scriptState->isolate()); } | 175 bool getString(String& result) const; |
| 166 bool getString(String& result) const { return getString(result, v8::Isolate: :GetCurrent()); } | 176 String toString() const; |
| 167 bool getString(String& result, v8::Isolate*) const; | |
| 168 String toString(ScriptState*) const; | |
| 169 | 177 |
| 170 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const; | 178 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const; |
| 171 | 179 |
| 172 private: | 180 private: |
| 181 v8::Isolate* m_isolate; | |
| 173 RefPtr<SharedPersistent<v8::Value> > m_value; | 182 RefPtr<SharedPersistent<v8::Value> > m_value; |
| 174 }; | 183 }; |
| 175 | 184 |
| 176 } // namespace WebCore | 185 } // namespace WebCore |
| 177 | 186 |
| 178 #endif // ScriptValue_h | 187 #endif // ScriptValue_h |
| OLD | NEW |