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

Side by Side Diff: third_party/WebKit/Source/core/inspector/InjectedScript.cpp

Issue 1622213002: DevTools: make InjectedScript heap-allocated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (!parsedObjectId->asObject(&object)) 327 if (!parsedObjectId->asObject(&object))
328 return; 328 return;
329 int boundId = 0; 329 int boundId = 0;
330 if (!object->getNumber("id", &boundId)) 330 if (!object->getNumber("id", &boundId))
331 return; 331 return;
332 m_native->unbind(boundId); 332 m_native->unbind(boundId);
333 } 333 }
334 334
335 PassRefPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal) 335 PassRefPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal)
336 { 336 {
337 ASSERT(!isEmpty());
338 ScriptFunctionCall function(injectedScriptObject(), "wrapCallFrames"); 337 ScriptFunctionCall function(injectedScriptObject(), "wrapCallFrames");
339 function.appendArgument(callFrames); 338 function.appendArgument(callFrames);
340 function.appendArgument(asyncOrdinal); 339 function.appendArgument(asyncOrdinal);
341 bool hadException = false; 340 bool hadException = false;
342 ScriptValue callFramesValue = callFunctionWithEvalEnabled(function, hadExcep tion); 341 ScriptValue callFramesValue = callFunctionWithEvalEnabled(function, hadExcep tion);
343 ASSERT(!hadException); 342 ASSERT(!hadException);
344 RefPtr<JSONValue> result = toJSONValue(callFramesValue); 343 RefPtr<JSONValue> result = toJSONValue(callFramesValue);
345 if (result && result->type() == JSONValue::TypeArray) 344 if (result && result->type() == JSONValue::TypeArray)
346 return Array<CallFrame>::runtimeCast(result); 345 return Array<CallFrame>::runtimeCast(result);
347 return Array<CallFrame>::create(); 346 return Array<CallFrame>::create();
348 } 347 }
349 348
350 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(const ScriptValue& value, const String& groupName, bool generatePreview) const 349 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(const ScriptValue& value, const String& groupName, bool generatePreview) const
351 { 350 {
352 ASSERT(!isEmpty());
353 ScriptFunctionCall wrapFunction(injectedScriptObject(), "wrapObject"); 351 ScriptFunctionCall wrapFunction(injectedScriptObject(), "wrapObject");
354 wrapFunction.appendArgument(value); 352 wrapFunction.appendArgument(value);
355 wrapFunction.appendArgument(groupName); 353 wrapFunction.appendArgument(groupName);
356 wrapFunction.appendArgument(canAccessInspectedWindow()); 354 wrapFunction.appendArgument(canAccessInspectedWindow());
357 wrapFunction.appendArgument(generatePreview); 355 wrapFunction.appendArgument(generatePreview);
358 bool hadException = false; 356 bool hadException = false;
359 ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException); 357 ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException);
360 if (hadException) 358 if (hadException)
361 return nullptr; 359 return nullptr;
362 RefPtr<JSONObject> rawResult = toJSONValue(r)->asObject(); 360 RefPtr<JSONObject> rawResult = toJSONValue(r)->asObject();
363 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); 361 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult);
364 } 362 }
365 363
366 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapTable(const S criptValue& table, const ScriptValue& columns) const 364 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapTable(const S criptValue& table, const ScriptValue& columns) const
367 { 365 {
368 ASSERT(!isEmpty());
369 ScriptFunctionCall wrapFunction(injectedScriptObject(), "wrapTable"); 366 ScriptFunctionCall wrapFunction(injectedScriptObject(), "wrapTable");
370 wrapFunction.appendArgument(canAccessInspectedWindow()); 367 wrapFunction.appendArgument(canAccessInspectedWindow());
371 wrapFunction.appendArgument(table); 368 wrapFunction.appendArgument(table);
372 if (columns.isEmpty()) 369 if (columns.isEmpty())
373 wrapFunction.appendArgument(false); 370 wrapFunction.appendArgument(false);
374 else 371 else
375 wrapFunction.appendArgument(columns); 372 wrapFunction.appendArgument(columns);
376 bool hadException = false; 373 bool hadException = false;
377 ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException); 374 ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException);
378 if (hadException) 375 if (hadException)
379 return nullptr; 376 return nullptr;
380 RefPtr<JSONObject> rawResult = toJSONValue(r)->asObject(); 377 RefPtr<JSONObject> rawResult = toJSONValue(r)->asObject();
381 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); 378 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult);
382 } 379 }
383 380
384 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const 381 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const
385 { 382 {
386 ASSERT(!isEmpty());
387 return m_native->objectForId(objectId.id()); 383 return m_native->objectForId(objectId.id());
388 } 384 }
389 385
390 String InjectedScript::objectIdToObjectGroupName(const String& objectId) const 386 String InjectedScript::objectIdToObjectGroupName(const String& objectId) const
391 { 387 {
392 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); 388 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId);
393 if (!parsedObjectId) 389 if (!parsedObjectId)
394 return String(); 390 return String();
395 RefPtr<JSONObject> object; 391 RefPtr<JSONObject> object;
396 if (!parsedObjectId->asObject(&object)) 392 if (!parsedObjectId->asObject(&object))
397 return String(); 393 return String();
398 int boundId = 0; 394 int boundId = 0;
399 if (!object->getNumber("id", &boundId)) 395 if (!object->getNumber("id", &boundId))
400 return String(); 396 return String();
401 return m_native->groupName(boundId); 397 return m_native->groupName(boundId);
402 } 398 }
403 399
404 void InjectedScript::releaseObjectGroup(const String& objectGroup) 400 void InjectedScript::releaseObjectGroup(const String& objectGroup)
405 { 401 {
406 ASSERT(!isEmpty());
407 m_native->releaseObjectGroup(objectGroup); 402 m_native->releaseObjectGroup(objectGroup);
408 if (objectGroup == "console") { 403 if (objectGroup == "console") {
409 ScriptFunctionCall releaseFunction(injectedScriptObject(), "clearLastEva luationResult"); 404 ScriptFunctionCall releaseFunction(injectedScriptObject(), "clearLastEva luationResult");
410 bool hadException = false; 405 bool hadException = false;
411 callFunctionWithEvalEnabled(releaseFunction, hadException); 406 callFunctionWithEvalEnabled(releaseFunction, hadException);
412 ASSERT(!hadException); 407 ASSERT(!hadException);
413 } 408 }
414 } 409 }
415 410
416 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) 411 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled)
417 { 412 {
418 ASSERT(!isEmpty());
419 ScriptFunctionCall function(injectedScriptObject(), "setCustomObjectFormatte rEnabled"); 413 ScriptFunctionCall function(injectedScriptObject(), "setCustomObjectFormatte rEnabled");
420 function.appendArgument(enabled); 414 function.appendArgument(enabled);
421 RefPtr<JSONValue> result; 415 RefPtr<JSONValue> result;
422 makeCall(function, &result); 416 makeCall(function, &result);
423 } 417 }
424 418
425 void InjectedScript::initialize(ScriptValue injectedScriptObject, InspectedState AccessCheck accessCheck) 419 void InjectedScript::initialize(ScriptValue injectedScriptObject, InspectedState AccessCheck accessCheck)
426 { 420 {
427 m_injectedScriptObject = injectedScriptObject; 421 m_injectedScriptObject = injectedScriptObject;
428 m_inspectedStateAccessCheck = accessCheck; 422 m_inspectedStateAccessCheck = accessCheck;
429 } 423 }
430 424
431 bool InjectedScript::canAccessInspectedWindow() const 425 bool InjectedScript::canAccessInspectedWindow() const
432 { 426 {
433 ASSERT(!isEmpty());
434 return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState()); 427 return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState());
435 } 428 }
436 429
437 const ScriptValue& InjectedScript::injectedScriptObject() const 430 const ScriptValue& InjectedScript::injectedScriptObject() const
438 { 431 {
439 return m_injectedScriptObject; 432 return m_injectedScriptObject;
440 } 433 }
441 434
442 ScriptValue InjectedScript::callFunctionWithEvalEnabled(ScriptFunctionCall& func tion, bool& hadException) const 435 ScriptValue InjectedScript::callFunctionWithEvalEnabled(ScriptFunctionCall& func tion, bool& hadException) const
443 { 436 {
444 ASSERT(!isEmpty());
445
446 ScriptState* scriptState = m_injectedScriptObject.scriptState(); 437 ScriptState* scriptState = m_injectedScriptObject.scriptState();
447 ScriptState::Scope scope(scriptState); 438 ScriptState::Scope scope(scriptState);
448 bool evalIsDisabled = !scriptState->evalEnabled(); 439 bool evalIsDisabled = !scriptState->evalEnabled();
449 // Temporarily enable allow evals for inspector. 440 // Temporarily enable allow evals for inspector.
450 if (evalIsDisabled) 441 if (evalIsDisabled)
451 scriptState->setEvalEnabled(true); 442 scriptState->setEvalEnabled(true);
452 443
453 ScriptValue resultValue = function.call(hadException); 444 ScriptValue resultValue = function.call(hadException);
454 445
455 if (evalIsDisabled) 446 if (evalIsDisabled)
456 scriptState->setEvalEnabled(false); 447 scriptState->setEvalEnabled(false);
457 448
458 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); 449 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( ));
459 return resultValue; 450 return resultValue;
460 } 451 }
461 452
462 void InjectedScript::makeCall(ScriptFunctionCall& function, RefPtr<JSONValue>* r esult) 453 void InjectedScript::makeCall(ScriptFunctionCall& function, RefPtr<JSONValue>* r esult)
463 { 454 {
464 if (isEmpty() || !canAccessInspectedWindow()) { 455 if (!canAccessInspectedWindow()) {
465 *result = JSONValue::null(); 456 *result = JSONValue::null();
466 return; 457 return;
467 } 458 }
468 459
469 bool hadException = false; 460 bool hadException = false;
470 ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException ); 461 ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException );
471 462
472 ASSERT(!hadException); 463 ASSERT(!hadException);
473 if (!hadException) { 464 if (!hadException) {
474 *result = toJSONValue(resultValue); 465 *result = toJSONValue(resultValue);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 String text = !message.IsEmpty() ? toCoreStringWithUndefinedOrNullCheck( message->Get()) : "Internal error"; 513 String text = !message.IsEmpty() ? toCoreStringWithUndefinedOrNullCheck( message->Get()) : "Internal error";
523 *exceptionDetails = TypeBuilder::Debugger::ExceptionDetails::create().se tText(text); 514 *exceptionDetails = TypeBuilder::Debugger::ExceptionDetails::create().se tText(text);
524 } else { 515 } else {
525 *result = toJSONValue(resultValue); 516 *result = toJSONValue(resultValue);
526 if (!*result) 517 if (!*result)
527 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 518 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
528 } 519 }
529 } 520 }
530 521
531 } // namespace blink 522 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698