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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/RuntimeModel.js

Issue 2236033002: [DevTools] Simplify evaluation callbacks on frontend (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-was-thrown
Patch Set: addressed comments Created 4 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
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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 544
545 WebInspector.ExecutionContext.prototype = { 545 WebInspector.ExecutionContext.prototype = {
546 /** 546 /**
547 * @param {string} expression 547 * @param {string} expression
548 * @param {string} objectGroup 548 * @param {string} objectGroup
549 * @param {boolean} includeCommandLineAPI 549 * @param {boolean} includeCommandLineAPI
550 * @param {boolean} doNotPauseOnExceptionsAndMuteConsole 550 * @param {boolean} doNotPauseOnExceptionsAndMuteConsole
551 * @param {boolean} returnByValue 551 * @param {boolean} returnByValue
552 * @param {boolean} generatePreview 552 * @param {boolean} generatePreview
553 * @param {boolean} userGesture 553 * @param {boolean} userGesture
554 * @param {function(?WebInspector.RemoteObject, boolean, ?RuntimeAgent.Remot eObject=, ?RuntimeAgent.ExceptionDetails=)} callback 554 * @param {function(?WebInspector.RemoteObject, !RuntimeAgent.ExceptionDetai ls=)} callback
555 */ 555 */
556 evaluate: function(expression, objectGroup, includeCommandLineAPI, doNotPaus eOnExceptionsAndMuteConsole, returnByValue, generatePreview, userGesture, callba ck) 556 evaluate: function(expression, objectGroup, includeCommandLineAPI, doNotPaus eOnExceptionsAndMuteConsole, returnByValue, generatePreview, userGesture, callba ck)
557 { 557 {
558 // FIXME: It will be moved to separate ExecutionContext. 558 // FIXME: It will be moved to separate ExecutionContext.
559 if (this.debuggerModel.selectedCallFrame()) { 559 if (this.debuggerModel.selectedCallFrame()) {
560 this.debuggerModel.evaluateOnSelectedCallFrame(expression, objectGro up, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback); 560 this.debuggerModel.evaluateOnSelectedCallFrame(expression, objectGro up, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback);
561 return; 561 return;
562 } 562 }
563 this._evaluateGlobal.apply(this, arguments); 563 this._evaluateGlobal.apply(this, arguments);
564 }, 564 },
565 565
566 /** 566 /**
567 * @param {string} objectGroup 567 * @param {string} objectGroup
568 * @param {boolean} returnByValue
569 * @param {boolean} generatePreview 568 * @param {boolean} generatePreview
570 * @param {function(?WebInspector.RemoteObject, boolean, ?RuntimeAgent.Remot eObject=, ?RuntimeAgent.ExceptionDetails=)} callback 569 * @param {function(?WebInspector.RemoteObject, !RuntimeAgent.ExceptionDetai ls=)} callback
571 */ 570 */
572 globalObject: function(objectGroup, returnByValue, generatePreview, callback ) 571 globalObject: function(objectGroup, generatePreview, callback)
573 { 572 {
574 this._evaluateGlobal("this", objectGroup, false, true, returnByValue, ge neratePreview, false, callback); 573 this._evaluateGlobal("this", objectGroup, false, true, false, generatePr eview, false, callback);
575 }, 574 },
576 575
577 /** 576 /**
578 * @param {string} expression 577 * @param {string} expression
579 * @param {string} objectGroup 578 * @param {string} objectGroup
580 * @param {boolean} includeCommandLineAPI 579 * @param {boolean} includeCommandLineAPI
581 * @param {boolean} doNotPauseOnExceptionsAndMuteConsole 580 * @param {boolean} doNotPauseOnExceptionsAndMuteConsole
582 * @param {boolean} returnByValue 581 * @param {boolean} returnByValue
583 * @param {boolean} generatePreview 582 * @param {boolean} generatePreview
584 * @param {boolean} userGesture 583 * @param {boolean} userGesture
585 * @param {function(?WebInspector.RemoteObject, boolean, ?RuntimeAgent.Remot eObject=, ?RuntimeAgent.ExceptionDetails=)} callback 584 * @param {function(?WebInspector.RemoteObject, !RuntimeAgent.ExceptionDetai ls=)} callback
586 */ 585 */
587 _evaluateGlobal: function(expression, objectGroup, includeCommandLineAPI, do NotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, userGesture, callback) 586 _evaluateGlobal: function(expression, objectGroup, includeCommandLineAPI, do NotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, userGesture, callback)
588 { 587 {
589 if (!expression) { 588 if (!expression) {
590 // There is no expression, so the completion should happen against g lobal properties. 589 // There is no expression, so the completion should happen against g lobal properties.
591 expression = "this"; 590 expression = "this";
592 } 591 }
593 592
594 /** 593 /**
595 * @this {WebInspector.ExecutionContext} 594 * @this {WebInspector.ExecutionContext}
596 * @param {?Protocol.Error} error 595 * @param {?Protocol.Error} error
597 * @param {!RuntimeAgent.RemoteObject} result 596 * @param {!RuntimeAgent.RemoteObject} result
598 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails 597 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails
599 */ 598 */
600 function evalCallback(error, result, exceptionDetails) 599 function evalCallback(error, result, exceptionDetails)
601 { 600 {
602 if (error) { 601 if (error) {
603 console.error(error); 602 console.error(error);
604 callback(null, false); 603 callback(null);
605 return; 604 return;
606 } 605 }
607 606 callback(this.runtimeModel.createRemoteObject(result), exceptionDeta ils);
608 var wasThrown = !!exceptionDetails;
609 if (returnByValue)
610 callback(null, !!wasThrown, wasThrown ? null : result, exception Details);
611 else
612 callback(this.runtimeModel.createRemoteObject(result), !!wasThro wn, undefined, exceptionDetails);
613 } 607 }
614 this.target().runtimeAgent().evaluate(expression, objectGroup, includeCo mmandLineAPI, doNotPauseOnExceptionsAndMuteConsole, this.id, returnByValue, gene ratePreview, userGesture, false, evalCallback.bind(this)); 608 this.target().runtimeAgent().evaluate(expression, objectGroup, includeCo mmandLineAPI, doNotPauseOnExceptionsAndMuteConsole, this.id, returnByValue, gene ratePreview, userGesture, false, evalCallback.bind(this));
615 }, 609 },
616 610
617 /** 611 /**
618 * @param {string} expressionString 612 * @param {string} expressionString
619 * @param {string} prefix 613 * @param {string} prefix
620 * @param {boolean} force 614 * @param {boolean} force
621 * @param {function(!Array.<string>, number=)} completionsReadyCallback 615 * @param {function(!Array.<string>, number=)} completionsReadyCallback
622 */ 616 */
(...skipping 17 matching lines...) Expand all
640 completionsReadyCallback([]); 634 completionsReadyCallback([]);
641 return; 635 return;
642 } 636 }
643 637
644 if (!expressionString && this.debuggerModel.selectedCallFrame()) 638 if (!expressionString && this.debuggerModel.selectedCallFrame())
645 this.debuggerModel.selectedCallFrame().variableNames(receivedPropert yNames.bind(this)); 639 this.debuggerModel.selectedCallFrame().variableNames(receivedPropert yNames.bind(this));
646 else 640 else
647 this.evaluate(expressionString, "completion", true, true, false, fal se, false, evaluated.bind(this)); 641 this.evaluate(expressionString, "completion", true, true, false, fal se, false, evaluated.bind(this));
648 642
649 /** 643 /**
644 * @param {?WebInspector.RemoteObject} result
645 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails
650 * @this {WebInspector.ExecutionContext} 646 * @this {WebInspector.ExecutionContext}
651 */ 647 */
652 function evaluated(result, wasThrown) 648 function evaluated(result, exceptionDetails)
653 { 649 {
654 if (!result || wasThrown) { 650 if (!result || !!exceptionDetails) {
655 completionsReadyCallback([]); 651 completionsReadyCallback([]);
656 return; 652 return;
657 } 653 }
658 654
659 /** 655 /**
660 * @param {?WebInspector.RemoteObject} object 656 * @param {?WebInspector.RemoteObject} object
661 * @return {!Promise<?WebInspector.RemoteObject>} 657 * @return {!Promise<?WebInspector.RemoteObject>}
662 */ 658 */
663 function extractTarget(object) 659 function extractTarget(object)
664 { 660 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 else if (object.type === "object" || object.type === "function") 724 else if (object.type === "object" || object.type === "function")
729 object.callFunctionJSON(getCompletions, [WebInspector.Remote Object.toCallArgument(object.subtype)], receivedPropertyNames.bind(this)); 725 object.callFunctionJSON(getCompletions, [WebInspector.Remote Object.toCallArgument(object.subtype)], receivedPropertyNames.bind(this));
730 else if (object.type === "string" || object.type === "number" || object.type === "boolean") 726 else if (object.type === "string" || object.type === "number" || object.type === "boolean")
731 this.evaluate("(" + getCompletions + ")(\"" + result.type + "\")", "completion", false, true, true, false, false, receivedPropertyNamesFromE val.bind(this)); 727 this.evaluate("(" + getCompletions + ")(\"" + result.type + "\")", "completion", false, true, true, false, false, receivedPropertyNamesFromE val.bind(this));
732 } 728 }
733 729
734 extractTarget(result).then(completionsForObject.bind(this)); 730 extractTarget(result).then(completionsForObject.bind(this));
735 } 731 }
736 732
737 /** 733 /**
738 * @param {?WebInspector.RemoteObject} notRelevant 734 * @param {?WebInspector.RemoteObject} result
739 * @param {boolean} wasThrown 735 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails
740 * @param {?RuntimeAgent.RemoteObject=} result
741 * @this {WebInspector.ExecutionContext} 736 * @this {WebInspector.ExecutionContext}
742 */ 737 */
743 function receivedPropertyNamesFromEval(notRelevant, wasThrown, result) 738 function receivedPropertyNamesFromEval(result, exceptionDetails)
744 { 739 {
745 this.target().runtimeAgent().releaseObjectGroup("completion"); 740 this.target().runtimeAgent().releaseObjectGroup("completion");
746 if (result && !wasThrown) 741 if (result && !exceptionDetails)
747 receivedPropertyNames.call(this, /** @type {!Object} */(result.v alue)); 742 receivedPropertyNames.call(this, /** @type {!Object} */(result.v alue));
748 else 743 else
749 completionsReadyCallback([]); 744 completionsReadyCallback([]);
750 } 745 }
751 746
752 /** 747 /**
753 * @param {?Object} propertyNames 748 * @param {?Object} propertyNames
754 * @this {WebInspector.ExecutionContext} 749 * @this {WebInspector.ExecutionContext}
755 */ 750 */
756 function receivedPropertyNames(propertyNames) 751 function receivedPropertyNames(propertyNames)
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 /** 1022 /**
1028 * @return {boolean} 1023 * @return {boolean}
1029 */ 1024 */
1030 isNormalListenerType: function() 1025 isNormalListenerType: function()
1031 { 1026 {
1032 return this._listenerType === "normal"; 1027 return this._listenerType === "normal";
1033 }, 1028 },
1034 1029
1035 __proto__: WebInspector.SDKObject.prototype 1030 __proto__: WebInspector.SDKObject.prototype
1036 } 1031 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698