forked from mirrors/gecko-dev
		
	Bug 1360237 - Make gDevToolsBrowser.inspectNode more readable by using async/await. r=pbro
MozReview-Commit-ID: 37zPhpCTnDa --HG-- extra : rebase_source : 2013976afd3db1a75f4e1afc6dc6201adfe5b782
This commit is contained in:
		
							parent
							
								
									0456b4d6eb
								
							
						
					
					
						commit
						b4c0d1615b
					
				
					 1 changed files with 28 additions and 34 deletions
				
			
		|  | @ -296,52 +296,46 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = { | |||
|     } | ||||
|   }, | ||||
| 
 | ||||
|   inspectNode: function (tab, node) { | ||||
|   async inspectNode(tab, node) { | ||||
|     let target = TargetFactory.forTab(tab); | ||||
| 
 | ||||
|     // Generate a cross iframes query selector
 | ||||
|     let selectors = []; | ||||
|     while(node) { | ||||
|     while (node) { | ||||
|       selectors.push(findCssSelector(node)); | ||||
|       node = node.ownerDocument.defaultView.frameElement; | ||||
|     } | ||||
| 
 | ||||
|     return gDevTools.showToolbox(target, "inspector").then(toolbox => { | ||||
|       let inspector = toolbox.getCurrentPanel(); | ||||
|     let toolbox = await gDevTools.showToolbox(target, "inspector"); | ||||
|     let inspector = toolbox.getCurrentPanel(); | ||||
| 
 | ||||
|       // new-node-front tells us when the node has been selected, whether the
 | ||||
|       // browser is remote or not.
 | ||||
|       let onNewNode = inspector.selection.once("new-node-front"); | ||||
|     // new-node-front tells us when the node has been selected, whether the
 | ||||
|     // browser is remote or not.
 | ||||
|     let onNewNode = inspector.selection.once("new-node-front"); | ||||
| 
 | ||||
|       // Evaluate the cross iframes query selectors
 | ||||
|       function querySelectors(nodeFront) { | ||||
|         let selector = selectors.pop(); | ||||
|         if (!selector) { | ||||
|           return Promise.resolve(nodeFront); | ||||
|         } | ||||
|         return inspector.walker.querySelector(nodeFront, selector) | ||||
|           .then(node => { | ||||
|             if (selectors.length > 0) { | ||||
|               return inspector.walker.children(node).then(({ nodes }) => { | ||||
|                 return nodes[0]; // This is the NodeFront for the document node inside the iframe
 | ||||
|               }); | ||||
|             } | ||||
|             return node; | ||||
|           }).then(querySelectors); | ||||
|     // Evaluate the cross iframes query selectors
 | ||||
|     async function querySelectors(nodeFront) { | ||||
|       let selector = selectors.pop(); | ||||
|       if (!selector) { | ||||
|         return nodeFront; | ||||
|       } | ||||
|       inspector.walker.getRootNode() | ||||
|         .then(querySelectors) | ||||
|         .then(node =>  { | ||||
|           // Select the final node
 | ||||
|           inspector.selection.setNodeFront(node, "browser-context-menu"); | ||||
|         }); | ||||
|       nodeFront = await inspector.walker.querySelector(nodeFront, selector); | ||||
|       if (selectors.length > 0) { | ||||
|         let { nodes } = await inspector.walker.children(nodeFront); | ||||
|         // This is the NodeFront for the document node inside the iframe
 | ||||
|         nodeFront = nodes[0]; | ||||
|       } | ||||
|       return querySelectors(nodeFront); | ||||
|     } | ||||
|     let nodeFront = await inspector.walker.getRootNode(); | ||||
|     nodeFront = await querySelectors(nodeFront); | ||||
|     // Select the final node
 | ||||
|     inspector.selection.setNodeFront(nodeFront, "browser-context-menu"); | ||||
| 
 | ||||
|       return onNewNode.then(() => { | ||||
|         // Now that the node has been selected, wait until the inspector is
 | ||||
|         // fully updated.
 | ||||
|         return inspector.once("inspector-updated"); | ||||
|       }); | ||||
|     }); | ||||
|     await onNewNode; | ||||
|     // Now that the node has been selected, wait until the inspector is
 | ||||
|     // fully updated.
 | ||||
|     await inspector.once("inspector-updated"); | ||||
|   }, | ||||
| 
 | ||||
|   _getContentProcessTarget: function (processId) { | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Alexandre Poirot
						Alexandre Poirot