OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include <wtf/HashSet.h> | 7 #include <wtf/HashSet.h> |
8 #include <wtf/RefPtr.h> | 8 #include <wtf/RefPtr.h> |
9 #include <wtf/Vector.h> | 9 #include <wtf/Vector.h> |
10 | 10 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 const String &function_name, | 151 const String &function_name, |
152 const String& json_args, | 152 const String& json_args, |
153 String* exception) { | 153 String* exception) { |
154 v8::HandleScope scope; | 154 v8::HandleScope scope; |
155 ASSERT(!context.IsEmpty()); | 155 ASSERT(!context.IsEmpty()); |
156 if (context.IsEmpty()) { | 156 if (context.IsEmpty()) { |
157 *exception = "No window context."; | 157 *exception = "No window context."; |
158 return ""; | 158 return ""; |
159 } | 159 } |
160 v8::Context::Scope context_scope(context); | 160 v8::Context::Scope context_scope(context); |
161 | |
162 DebuggerAgentManager::UtilityContextScope utility_scope; | |
163 | |
161 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast( | 164 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast( |
162 context->Global()->Get(v8::String::New("devtools$$dispatch"))); | 165 context->Global()->Get(v8::String::New("devtools$$dispatch"))); |
163 | 166 |
164 v8::Handle<v8::String> function_name_wrapper = v8::Handle<v8::String>( | 167 v8::Handle<v8::String> function_name_wrapper = v8::Handle<v8::String>( |
165 v8::String::New(function_name.utf8().data())); | 168 v8::String::New(function_name.utf8().data())); |
166 v8::Handle<v8::String> json_args_wrapper = v8::Handle<v8::String>( | 169 v8::Handle<v8::String> json_args_wrapper = v8::Handle<v8::String>( |
167 v8::String::New(json_args.utf8().data())); | 170 v8::String::New(json_args.utf8().data())); |
168 v8::Handle<v8::Value> args[] = { | 171 v8::Handle<v8::Value> args[] = { |
169 function_name_wrapper, | 172 function_name_wrapper, |
170 json_args_wrapper | 173 json_args_wrapper |
171 }; | 174 }; |
172 | 175 |
173 v8::TryCatch try_catch; | 176 v8::TryCatch try_catch; |
174 v8::Handle<v8::Value> res_obj = function->Call(context->Global(), 2, args); | 177 v8::Handle<v8::Value> res_obj = function->Call(context->Global(), 2, args); |
175 if (try_catch.HasCaught()) { | 178 if (try_catch.HasCaught()) { |
176 *exception = WebCore::toWebCoreString(try_catch.Message()->Get()); | 179 *exception = WebCore::toWebCoreString(try_catch.Message()->Get()); |
177 return ""; | 180 return ""; |
178 } else { | 181 } else { |
179 return WebCore::toWebCoreStringWithNullCheck(res_obj); | 182 return WebCore::toWebCoreStringWithNullCheck(res_obj); |
180 } | 183 } |
181 } | 184 } |
182 | 185 |
186 String DebuggerAgentImpl::EvaluateJavaScript( | |
187 v8::Handle<v8::Context> utility_context, | |
188 const String& source, | |
189 String* exception) { | |
190 v8::HandleScope scope; | |
191 ASSERT(!utility_context.IsEmpty()); | |
192 if (utility_context.IsEmpty()) { | |
193 *exception = "No window utility context."; | |
194 return ""; | |
195 } | |
196 | |
197 v8::Handle<v8::Value> res_obj; | |
198 { // Do evaluate. | |
199 DebuggerAgentManager::UtilityContextScope utility_scope; | |
200 v8::Handle<v8::Context> v8Context = V8Proxy::context(GetPage()->mainFrame()) ; | |
pfeldman
2009/07/27 07:50:15
80 chars
yurys
2009/07/27 07:52:05
Done.
| |
201 if (v8Context.IsEmpty()) { | |
202 *exception = "No window context."; | |
203 return ""; | |
204 } | |
205 V8Proxy* proxy = V8Proxy::retrieve(GetPage()->mainFrame()); | |
206 v8::Context::Scope context_scope(v8Context); | |
207 v8::TryCatch try_catch; | |
208 v8::Handle<v8::Script> script = proxy->compileScript( | |
209 v8ExternalString(source), | |
210 String(), // url | |
211 0); // source start | |
212 res_obj = proxy->runScript(script, true); | |
213 if (try_catch.HasCaught()) { | |
214 v8::Handle<v8::String> msg = try_catch.Message()->Get(); | |
215 if (!msg.IsEmpty()) { | |
216 *exception = WebCore::toWebCoreString(msg); | |
217 } else { | |
218 *exception = "Failed to evaluate."; | |
219 } | |
220 return ""; | |
221 } | |
222 DCHECK(!res_obj.IsEmpty()); | |
223 } | |
224 | |
225 { // Wrap the result. | |
226 v8::Context::Scope context_scope(utility_context); | |
227 | |
228 v8::Handle<v8::Object> devtools = v8::Local<v8::Object>::Cast( | |
229 utility_context->Global()->Get(v8::String::New("devtools$$obj"))); | |
230 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast( | |
231 devtools->Get(v8::String::New("serializeConsoleObject"))); | |
232 | |
233 v8::Handle<v8::Value> args[] = { | |
234 res_obj | |
235 }; | |
236 res_obj = function->Call(devtools, 1, args); | |
237 return WebCore::toWebCoreStringWithNullCheck(res_obj); | |
238 } | |
239 } | |
240 | |
183 WebCore::Page* DebuggerAgentImpl::GetPage() { | 241 WebCore::Page* DebuggerAgentImpl::GetPage() { |
184 return web_view_impl_->page(); | 242 return web_view_impl_->page(); |
185 } | 243 } |
OLD | NEW |