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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp

Issue 1707043002: [DevTools] Support CommandLineAPI in snippets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 if (!persistScript) 209 if (!persistScript)
210 return; 210 return;
211 211
212 String scriptValueId = String::number(script->GetUnboundScript()->GetId()); 212 String scriptValueId = String::number(script->GetUnboundScript()->GetId());
213 OwnPtr<v8::Global<v8::Script>> global = adoptPtr(new v8::Global<v8::Script>( isolate, script)); 213 OwnPtr<v8::Global<v8::Script>> global = adoptPtr(new v8::Global<v8::Script>( isolate, script));
214 m_compiledScripts.set(scriptValueId, global.release()); 214 m_compiledScripts.set(scriptValueId, global.release());
215 *scriptId = scriptValueId; 215 *scriptId = scriptValueId;
216 } 216 }
217 217
218 void V8RuntimeAgentImpl::runScript(ErrorString* errorString, const ScriptId& scr iptId, int executionContextId, const String* const objectGroup, const bool* cons t doNotPauseOnExceptionsAndMuteConsole, RefPtr<RemoteObject>& result, RefPtr<Exc eptionDetails>& exceptionDetails) 218 void V8RuntimeAgentImpl::runScript(ErrorString* errorString, const ScriptId& scr iptId, int executionContextId, const String* const objectGroup, const bool* cons t doNotPauseOnExceptionsAndMuteConsole, const bool* includeCommandLineAPI, RefPt r<RemoteObject>& result, RefPtr<ExceptionDetails>& exceptionDetails)
219 { 219 {
220 if (!m_enabled) { 220 if (!m_enabled) {
221 *errorString = "Runtime agent is not enabled"; 221 *errorString = "Runtime agent is not enabled";
222 return; 222 return;
223 } 223 }
224 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (executionContextId); 224 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (executionContextId);
225 if (!injectedScript) { 225 if (!injectedScript) {
226 *errorString = "Inspected frame has gone"; 226 *errorString = "Inspected frame has gone";
227 return; 227 return;
228 } 228 }
(...skipping 12 matching lines...) Expand all
241 v8::Local<v8::Context> context = injectedScript->context(); 241 v8::Local<v8::Context> context = injectedScript->context();
242 v8::Context::Scope scope(context); 242 v8::Context::Scope scope(context);
243 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script Id); 243 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script Id);
244 v8::Local<v8::Script> script = scriptWrapper->Get(isolate); 244 v8::Local<v8::Script> script = scriptWrapper->Get(isolate);
245 245
246 if (script.IsEmpty()) { 246 if (script.IsEmpty()) {
247 *errorString = "Script execution failed"; 247 *errorString = "Script execution failed";
248 return; 248 return;
249 } 249 }
250 v8::TryCatch tryCatch(isolate); 250 v8::TryCatch tryCatch(isolate);
251
252 v8::Local<v8::Symbol> commandLineAPISymbolValue = V8Debugger::commandLineAPI Symbol(isolate);
dgozman 2016/02/17 23:47:43 Let's move this to InjectedScript to avoid exposin
kozy 2016/02/18 00:27:33 Done.
253 v8::Local<v8::Object> global = context->Global();
254 if (asBool(includeCommandLineAPI)) {
255 v8::Local<v8::Value> commandLineAPI = injectedScript->commandLineAPI();
256 if (commandLineAPI->IsObject())
257 global->Set(commandLineAPISymbolValue, commandLineAPI->ToObject(isol ate));
258 }
259
251 v8::Local<v8::Value> value; 260 v8::Local<v8::Value> value;
252 v8::MaybeLocal<v8::Value> maybeValue = m_debugger->client()->runCompiledScri pt(context, script); 261 v8::MaybeLocal<v8::Value> maybeValue = m_debugger->client()->runCompiledScri pt(context, script);
253 if (maybeValue.IsEmpty()) { 262 if (maybeValue.IsEmpty()) {
254 value = tryCatch.Exception(); 263 value = tryCatch.Exception();
255 v8::Local<v8::Message> message = tryCatch.Message(); 264 v8::Local<v8::Message> message = tryCatch.Message();
256 if (!message.IsEmpty()) 265 if (!message.IsEmpty())
257 exceptionDetails = createExceptionDetails(isolate, message); 266 exceptionDetails = createExceptionDetails(isolate, message);
258 } else { 267 } else {
259 value = maybeValue.ToLocalChecked(); 268 value = maybeValue.ToLocalChecked();
260 } 269 }
261 270
271 if (asBool(includeCommandLineAPI))
272 global->Delete(context, commandLineAPISymbolValue);
273
262 if (value.IsEmpty()) { 274 if (value.IsEmpty()) {
263 *errorString = "Script execution failed"; 275 *errorString = "Script execution failed";
264 return; 276 return;
265 } 277 }
266 278
267 result = injectedScript->wrapObject(value, objectGroup ? *objectGroup : ""); 279 result = injectedScript->wrapObject(value, objectGroup ? *objectGroup : "");
268 } 280 }
269 281
270 void V8RuntimeAgentImpl::setInspectorState(PassRefPtr<JSONObject> state) 282 void V8RuntimeAgentImpl::setInspectorState(PassRefPtr<JSONObject> state)
271 { 283 {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 RefPtr<ExceptionDetails> exceptionDetails = ExceptionDetails::create().setTe xt(toWTFStringWithTypeCheck(message->Get())); 413 RefPtr<ExceptionDetails> exceptionDetails = ExceptionDetails::create().setTe xt(toWTFStringWithTypeCheck(message->Get()));
402 exceptionDetails->setLine(message->GetLineNumber()); 414 exceptionDetails->setLine(message->GetLineNumber());
403 exceptionDetails->setColumn(message->GetStartColumn()); 415 exceptionDetails->setColumn(message->GetStartColumn());
404 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace(); 416 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace();
405 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount() > 0) 417 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount() > 0)
406 exceptionDetails->setStack(m_debugger->createStackTrace(messageStackTrac e, messageStackTrace->GetFrameCount())->buildInspectorObject()); 418 exceptionDetails->setStack(m_debugger->createStackTrace(messageStackTrac e, messageStackTrace->GetFrameCount())->buildInspectorObject());
407 return exceptionDetails.release(); 419 return exceptionDetails.release();
408 } 420 }
409 421
410 } // namespace blink 422 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698