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

Side by Side Diff: webkit/glue/devtools/debugger_agent_impl.cc

Issue 159395: DevTools: make pause work for script evaluations (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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
OLDNEW
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
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 =
201 V8Proxy::context(GetPage()->mainFrame());
202 if (v8Context.IsEmpty()) {
203 *exception = "No window context.";
204 return "";
205 }
206 V8Proxy* proxy = V8Proxy::retrieve(GetPage()->mainFrame());
207 v8::Context::Scope context_scope(v8Context);
208 v8::TryCatch try_catch;
209 v8::Handle<v8::Script> script = proxy->compileScript(
210 v8ExternalString(source),
211 String(), // url
212 0); // source start
213 res_obj = proxy->runScript(script, true);
214 if (try_catch.HasCaught()) {
215 v8::Handle<v8::String> msg = try_catch.Message()->Get();
216 if (!msg.IsEmpty()) {
217 *exception = WebCore::toWebCoreString(msg);
218 } else {
219 *exception = "Failed to evaluate.";
220 }
221 return "";
222 }
223 DCHECK(!res_obj.IsEmpty());
224 }
225
226 { // Wrap the result.
227 v8::Context::Scope context_scope(utility_context);
228
229 v8::Handle<v8::Object> devtools = v8::Local<v8::Object>::Cast(
230 utility_context->Global()->Get(v8::String::New("devtools$$obj")));
231 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast(
232 devtools->Get(v8::String::New("serializeConsoleObject")));
233
234 v8::Handle<v8::Value> args[] = {
235 res_obj
236 };
237 res_obj = function->Call(devtools, 1, args);
238 return WebCore::toWebCoreStringWithNullCheck(res_obj);
239 }
240 }
241
183 WebCore::Page* DebuggerAgentImpl::GetPage() { 242 WebCore::Page* DebuggerAgentImpl::GetPage() {
184 return web_view_impl_->page(); 243 return web_view_impl_->page();
185 } 244 }
OLDNEW
« no previous file with comments | « webkit/glue/devtools/debugger_agent_impl.h ('k') | webkit/glue/devtools/debugger_agent_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698