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

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

Issue 1888813003: [DevTools] Move InjectedScript.lastResult to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return !outObject->IsEmpty(); 259 return !outObject->IsEmpty();
260 } 260 }
261 261
262 String16 InjectedScript::objectGroupName(const RemoteObjectId& objectId) const 262 String16 InjectedScript::objectGroupName(const RemoteObjectId& objectId) const
263 { 263 {
264 return m_native->groupName(objectId.id()); 264 return m_native->groupName(objectId.id());
265 } 265 }
266 266
267 void InjectedScript::releaseObjectGroup(const String16& objectGroup) 267 void InjectedScript::releaseObjectGroup(const String16& objectGroup)
268 { 268 {
269 v8::HandleScope handles(m_context->isolate());
270 m_native->releaseObjectGroup(objectGroup); 269 m_native->releaseObjectGroup(objectGroup);
271 if (objectGroup == "console") { 270 if (objectGroup == "console")
272 V8FunctionCall function(m_context->debugger(), m_context->context(), v8V alue(), "clearLastEvaluationResult"); 271 m_lastEvaluationResult.Reset();
273 bool hadException = false;
274 function.call(hadException);
275 ASSERT(!hadException);
276 }
277 } 272 }
278 273
279 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) 274 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled)
280 { 275 {
281 v8::HandleScope handles(m_context->isolate()); 276 v8::HandleScope handles(m_context->isolate());
282 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value (), "setCustomObjectFormatterEnabled"); 277 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value (), "setCustomObjectFormatterEnabled");
283 function.appendArgument(enabled); 278 function.appendArgument(enabled);
284 bool hadException = false; 279 bool hadException = false;
285 function.call(hadException); 280 function.call(hadException);
286 ASSERT(!hadException); 281 ASSERT(!hadException);
287 } 282 }
288 283
289 bool InjectedScript::canAccessInspectedWindow() const 284 bool InjectedScript::canAccessInspectedWindow() const
290 { 285 {
291 v8::Local<v8::Context> callingContext = m_context->isolate()->GetCallingCont ext(); 286 v8::Local<v8::Context> callingContext = m_context->isolate()->GetCallingCont ext();
292 if (callingContext.IsEmpty()) 287 if (callingContext.IsEmpty())
293 return true; 288 return true;
294 return m_context->debugger()->client()->callingContextCanAccessContext(calli ngContext, m_context->context()); 289 return m_context->debugger()->client()->callingContextCanAccessContext(calli ngContext, m_context->context());
295 } 290 }
296 291
297 v8::Local<v8::Value> InjectedScript::v8Value() const 292 v8::Local<v8::Value> InjectedScript::v8Value() const
298 { 293 {
299 return m_value.Get(m_context->isolate()); 294 return m_value.Get(m_context->isolate());
300 } 295 }
301 296
302 bool InjectedScript::setLastEvaluationResult(ErrorString* errorString, v8::Local <v8::Value> value) 297 void InjectedScript::setLastEvaluationResult(v8::Local<v8::Value> value)
303 { 298 {
304 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value (), "setLastEvaluationResult"); 299 m_lastEvaluationResult.Reset(m_context->isolate(), value);
dgozman 2016/04/14 19:19:06 Inline it?
kozy 2016/04/14 19:24:49 Done.
305 function.appendArgument(value); 300 }
306 bool hadException = false; 301
307 function.call(hadException, false); 302 v8::Local<v8::Value> InjectedScript::lastEvaluationResult() const
308 return !hasInternalError(errorString, hadException); 303 {
304 if (m_lastEvaluationResult.IsEmpty())
305 return v8::Undefined(m_context->isolate());
306 return m_lastEvaluationResult.Get(m_context->isolate());
309 } 307 }
310 308
311 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error String, protocol::Runtime::CallArgument* callArgument) 309 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error String, protocol::Runtime::CallArgument* callArgument)
312 { 310 {
313 if (callArgument->hasObjectId()) { 311 if (callArgument->hasObjectId()) {
314 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin g, callArgument->getObjectId("")); 312 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin g, callArgument->getObjectId(""));
315 if (!remoteObjectId) 313 if (!remoteObjectId)
316 return v8::MaybeLocal<v8::Value>(); 314 return v8::MaybeLocal<v8::Value>();
317 if (remoteObjectId->contextId() != m_context->contextId()) { 315 if (remoteObjectId->contextId() != m_context->contextId()) {
318 *errorString = "Argument should belong to the same JavaScript world as target object"; 316 *errorString = "Argument should belong to the same JavaScript world as target object";
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 356
359 void InjectedScript::wrapEvaluateResult(ErrorString* errorString, v8::MaybeLocal <v8::Value> maybeResultValue, const v8::TryCatch& tryCatch, const String16& obje ctGroup, bool returnByValue, bool generatePreview, OwnPtr<protocol::Runtime::Rem oteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::ExceptionDe tails>* exceptionDetails) 357 void InjectedScript::wrapEvaluateResult(ErrorString* errorString, v8::MaybeLocal <v8::Value> maybeResultValue, const v8::TryCatch& tryCatch, const String16& obje ctGroup, bool returnByValue, bool generatePreview, OwnPtr<protocol::Runtime::Rem oteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::ExceptionDe tails>* exceptionDetails)
360 { 358 {
361 v8::Local<v8::Value> resultValue; 359 v8::Local<v8::Value> resultValue;
362 if (!tryCatch.HasCaught()) { 360 if (!tryCatch.HasCaught()) {
363 if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue ))) 361 if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue )))
364 return; 362 return;
365 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, resultValue, objectGroup, returnByValue, generatePreview); 363 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, resultValue, objectGroup, returnByValue, generatePreview);
366 if (!remoteObject) 364 if (!remoteObject)
367 return; 365 return;
368 if (objectGroup == "console" && !setLastEvaluationResult(errorString, re sultValue)) 366 if (objectGroup == "console")
369 return; 367 setLastEvaluationResult(resultValue);
370 *result = remoteObject.release(); 368 *result = remoteObject.release();
371 if (wasThrown) 369 if (wasThrown)
372 *wasThrown = false; 370 *wasThrown = false;
373 } else { 371 } else {
374 v8::Local<v8::Value> exception = tryCatch.Exception(); 372 v8::Local<v8::Value> exception = tryCatch.Exception();
375 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o bjectGroup, false, generatePreview && !exception->IsNativeError()); 373 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o bjectGroup, false, generatePreview && !exception->IsNativeError());
376 if (!remoteObject) 374 if (!remoteObject)
377 return; 375 return;
378 *result = remoteObject.release(); 376 *result = remoteObject.release();
379 if (exceptionDetails) 377 if (exceptionDetails)
(...skipping 29 matching lines...) Expand all
409 return false; 407 return false;
410 m_context = m_injectedScript->context()->context(); 408 m_context = m_injectedScript->context()->context();
411 m_context->Enter(); 409 m_context->Enter();
412 return true; 410 return true;
413 } 411 }
414 412
415 bool InjectedScript::Scope::installCommandLineAPI() 413 bool InjectedScript::Scope::installCommandLineAPI()
416 { 414 {
417 ASSERT(m_injectedScript && !m_context.IsEmpty()); 415 ASSERT(m_injectedScript && !m_context.IsEmpty());
418 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(), "commandLineAPI"); 416 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(), "commandLineAPI");
419 return installGlobalObjectExtension(function); 417 v8::Local<v8::Object> extensionObject;
418 if (!installGlobalObjectExtension(function).ToLocal(&extensionObject))
419 return false;
420 return extensionObject->Set(m_context, toV8StringInternalized(m_context->Get Isolate(), "$_"), m_injectedScript->lastEvaluationResult()).FromMaybe(false);
420 } 421 }
421 422
422 bool InjectedScript::Scope::installRemoteObjectAPI(const String16& objectGroupNa me) 423 bool InjectedScript::Scope::installRemoteObjectAPI(const String16& objectGroupNa me)
423 { 424 {
424 ASSERT(m_injectedScript && !m_context.IsEmpty()); 425 ASSERT(m_injectedScript && !m_context.IsEmpty());
425 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(), "remoteObjectAPI"); 426 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(), "remoteObjectAPI");
426 function.appendArgument(objectGroupName); 427 function.appendArgument(objectGroupName);
427 return installGlobalObjectExtension(function); 428 v8::Local<v8::Object> extensionObject;
429 return installGlobalObjectExtension(function).ToLocal(&extensionObject);
428 } 430 }
429 431
430 bool InjectedScript::Scope::installGlobalObjectExtension(V8FunctionCall& functio n) 432 v8::MaybeLocal<v8::Object> InjectedScript::Scope::installGlobalObjectExtension(V 8FunctionCall& function)
431 { 433 {
432 bool hadException = false; 434 bool hadException = false;
433 v8::Local<v8::Value> extension = function.call(hadException, false); 435 v8::Local<v8::Value> extension = function.call(hadException, false);
434 if (hadException || extension.IsEmpty()) { 436 if (hadException || extension.IsEmpty() || !extension->IsObject()) {
435 *m_errorString = "Internal error"; 437 *m_errorString = "Internal error";
436 return false; 438 return v8::MaybeLocal<v8::Object>();
437 } 439 }
438 440
439 ASSERT(m_global.IsEmpty()); 441 ASSERT(m_global.IsEmpty());
440 m_extensionSymbol = V8Debugger::scopeExtensionSymbol(m_debugger->isolate()); 442 m_extensionSymbol = V8Debugger::scopeExtensionSymbol(m_debugger->isolate());
441 v8::Local<v8::Object> global = m_context->Global(); 443 v8::Local<v8::Object> global = m_context->Global();
442 if (!global->Set(m_context, m_extensionSymbol, extension).FromMaybe(false)) { 444 if (!global->Set(m_context, m_extensionSymbol, extension).FromMaybe(false)) {
443 *m_errorString = "Internal error"; 445 *m_errorString = "Internal error";
444 return false; 446 return v8::MaybeLocal<v8::Object>();
445 } 447 }
446 448
447 m_global = global; 449 m_global = global;
448 return true; 450 return extension.As<v8::Object>();
449 } 451 }
450 452
451 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() 453 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole()
452 { 454 {
453 ASSERT(!m_ignoreExceptionsAndMuteConsole); 455 ASSERT(!m_ignoreExceptionsAndMuteConsole);
454 m_ignoreExceptionsAndMuteConsole = true; 456 m_ignoreExceptionsAndMuteConsole = true;
455 m_debugger->client()->muteConsole(); 457 m_debugger->client()->muteConsole();
456 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl: :DontPauseOnExceptions); 458 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl: :DontPauseOnExceptions);
457 } 459 }
458 460
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl* session) 543 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl* session)
542 { 544 {
543 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId); 545 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId);
544 if (!remoteId) 546 if (!remoteId)
545 return; 547 return;
546 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); 548 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal());
547 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get() ); 549 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get() );
548 } 550 }
549 551
550 } // namespace blink 552 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698