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

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

Issue 2899163002: DevTools: Promisify Runtime domain (Closed)
Patch Set: addressing comments Created 3 years, 7 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 this._agent.setCustomObjectFormatterEnabled(enabled); 240 this._agent.setCustomObjectFormatterEnabled(enabled);
241 } 241 }
242 242
243 /** 243 /**
244 * @param {string} expression 244 * @param {string} expression
245 * @param {string} sourceURL 245 * @param {string} sourceURL
246 * @param {boolean} persistScript 246 * @param {boolean} persistScript
247 * @param {number} executionContextId 247 * @param {number} executionContextId
248 * @param {function(!Protocol.Runtime.ScriptId=, ?Protocol.Runtime.ExceptionDe tails=)=} callback 248 * @param {function(!Protocol.Runtime.ScriptId=, ?Protocol.Runtime.ExceptionDe tails=)=} callback
249 */ 249 */
250 compileScript(expression, sourceURL, persistScript, executionContextId, callba ck) { 250 async compileScript(expression, sourceURL, persistScript, executionContextId, callback) {
251 this._agent.compileScript(expression, sourceURL, persistScript, executionCon textId, innerCallback); 251 var response = await this._agent.invoke_compileScript({
252 expression: expression,
253 sourceURL: sourceURL,
254 persistScript: persistScript,
255 executionContextId: executionContextId
256 });
252 257
253 /** 258 if (response[Protocol.Error]) {
254 * @param {?Protocol.Error} error 259 console.error(response[Protocol.Error]);
255 * @param {!Protocol.Runtime.ScriptId=} scriptId 260 return;
256 * @param {?Protocol.Runtime.ExceptionDetails=} exceptionDetails
257 */
258 function innerCallback(error, scriptId, exceptionDetails) {
259 if (error) {
260 console.error(error);
261 return;
262 }
263 if (callback)
264 callback(scriptId, exceptionDetails);
265 } 261 }
262 if (callback)
263 callback(response.scriptId, response.exceptionDetails);
266 } 264 }
267 265
268 /** 266 /**
269 * @param {!Protocol.Runtime.ScriptId} scriptId 267 * @param {!Protocol.Runtime.ScriptId} scriptId
270 * @param {number} executionContextId 268 * @param {number} executionContextId
271 * @param {string=} objectGroup 269 * @param {string=} objectGroup
272 * @param {boolean=} silent 270 * @param {boolean=} silent
273 * @param {boolean=} includeCommandLineAPI 271 * @param {boolean=} includeCommandLineAPI
274 * @param {boolean=} returnByValue 272 * @param {boolean=} returnByValue
275 * @param {boolean=} generatePreview 273 * @param {boolean=} generatePreview
276 * @param {boolean=} awaitPromise 274 * @param {boolean=} awaitPromise
277 * @param {function(?Protocol.Runtime.RemoteObject, ?Protocol.Runtime.Exceptio nDetails=)=} callback 275 * @param {function(?Protocol.Runtime.RemoteObject, ?Protocol.Runtime.Exceptio nDetails=)=} callback
278 */ 276 */
279 runScript( 277 async runScript(
278 scriptId, executionContextId, objectGroup, silent, includeCommandLineAPI, returnByValue, generatePreview,
279 awaitPromise, callback) {
280 var response = await this._agent.invoke_runScript({
280 scriptId, 281 scriptId,
281 executionContextId, 282 executionContextId,
282 objectGroup, 283 objectGroup,
283 silent, 284 silent,
284 includeCommandLineAPI, 285 includeCommandLineAPI,
285 returnByValue, 286 returnByValue,
286 generatePreview, 287 generatePreview,
287 awaitPromise, 288 awaitPromise
288 callback) { 289 });
289 this._agent.runScript(
290 scriptId, executionContextId, objectGroup, silent, includeCommandLineAPI , returnByValue, generatePreview,
291 awaitPromise, innerCallback);
292 290
293 /** 291 if (response[Protocol.Error]) {
294 * @param {?Protocol.Error} error 292 console.error(response[Protocol.Error]);
295 * @param {!Protocol.Runtime.RemoteObject} result 293 return;
296 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
297 */
298 function innerCallback(error, result, exceptionDetails) {
299 if (error) {
300 console.error(error);
301 return;
302 }
303 if (callback)
304 callback(result, exceptionDetails);
305 } 294 }
295 if (callback)
296 callback(response.result, response.exceptionDetails);
306 } 297 }
307 298
308 /** 299 /**
309 * @param {!Protocol.Runtime.RemoteObject} payload 300 * @param {!Protocol.Runtime.RemoteObject} payload
310 * @param {!Object=} hints 301 * @param {!Object=} hints
311 */ 302 */
312 _inspectRequested(payload, hints) { 303 _inspectRequested(payload, hints) {
313 var object = this.createRemoteObject(payload); 304 var object = this.createRemoteObject(payload);
314 305
315 if (hints.copyToClipboard) { 306 if (hints.copyToClipboard) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 /** 630 /**
640 * @param {string} expression 631 * @param {string} expression
641 * @param {string} objectGroup 632 * @param {string} objectGroup
642 * @param {boolean} includeCommandLineAPI 633 * @param {boolean} includeCommandLineAPI
643 * @param {boolean} silent 634 * @param {boolean} silent
644 * @param {boolean} returnByValue 635 * @param {boolean} returnByValue
645 * @param {boolean} generatePreview 636 * @param {boolean} generatePreview
646 * @param {boolean} userGesture 637 * @param {boolean} userGesture
647 * @param {function(?SDK.RemoteObject, !Protocol.Runtime.ExceptionDetails=, st ring=)} callback 638 * @param {function(?SDK.RemoteObject, !Protocol.Runtime.ExceptionDetails=, st ring=)} callback
648 */ 639 */
649 _evaluateGlobal( 640 async _evaluateGlobal(
650 expression, 641 expression, objectGroup, includeCommandLineAPI, silent, returnByValue, gen eratePreview, userGesture, callback) {
651 objectGroup,
652 includeCommandLineAPI,
653 silent,
654 returnByValue,
655 generatePreview,
656 userGesture,
657 callback) {
658 if (!expression) { 642 if (!expression) {
659 // There is no expression, so the completion should happen against global properties. 643 // There is no expression, so the completion should happen against global properties.
660 expression = 'this'; 644 expression = 'this';
661 } 645 }
662 646
663 /** 647 var response = await this.runtimeModel._agent.invoke_evaluate({
664 * @this {SDK.ExecutionContext} 648 expression: expression,
665 * @param {?Protocol.Error} error 649 objectGroup: objectGroup,
666 * @param {!Protocol.Runtime.RemoteObject} result 650 includeCommandLineAPI: includeCommandLineAPI,
667 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails 651 silent: silent,
668 */ 652 contextId: this.id,
669 function evalCallback(error, result, exceptionDetails) { 653 returnByValue: returnByValue,
670 if (error) { 654 generatePreview: generatePreview,
671 console.error(error); 655 userGesture: userGesture,
672 callback(null, undefined, error); 656 awaitPromise: false
673 return; 657 });
674 } 658
675 callback(this.runtimeModel.createRemoteObject(result), exceptionDetails); 659 var error = response[Protocol.Error];
660 if (error) {
661 console.error(error);
662 callback(null, undefined, error);
663 return;
676 } 664 }
677 this.runtimeModel._agent.evaluate( 665 callback(this.runtimeModel.createRemoteObject(response.result), response.exc eptionDetails);
678 expression, objectGroup, includeCommandLineAPI, silent, this.id, returnB yValue, generatePreview, userGesture,
679 false, evalCallback.bind(this));
680 } 666 }
681 667
682 /** 668 /**
683 * @return {string} 669 * @return {string}
684 */ 670 */
685 label() { 671 label() {
686 return this._label; 672 return this._label;
687 } 673 }
688 674
689 /** 675 /**
(...skipping 13 matching lines...) Expand all
703 return; 689 return;
704 } 690 }
705 if (this.name) { 691 if (this.name) {
706 this._label = this.name; 692 this._label = this.name;
707 return; 693 return;
708 } 694 }
709 var parsedUrl = this.origin.asParsedURL(); 695 var parsedUrl = this.origin.asParsedURL();
710 this._label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : ''; 696 this._label = parsedUrl ? parsedUrl.lastPathComponentWithFragment() : '';
711 } 697 }
712 }; 698 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698