Changeset 188897 in webkit for trunk/Source/WebInspectorUI/UserInterface/Test/InspectorProtocol.js
- Timestamp:
- Aug 24, 2015, 4:58:31 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/UserInterface/Test/InspectorProtocol.js
r188639 r188897 27 27 InspectorProtocol = {}; 28 28 InspectorProtocol._dispatchTable = []; 29 InspectorProtocol._placeholderRequestIds = []; 29 30 InspectorProtocol._requestId = -1; 30 31 InspectorProtocol.eventHandler = {}; … … 39 40 this._dispatchTable[++this._requestId] = handler; 40 41 let messageObject = {method, params, id: this._requestId}; 41 this. sendMessage(messageObject);42 this._sendMessage(messageObject); 42 43 43 44 return this._requestId; … … 47 48 { 48 49 let {method, params} = args; 50 let messageObject = {method, params, id: ++this._requestId}; 51 52 return this.awaitMessage(messageObject); 53 } 54 55 InspectorProtocol.awaitMessage = function(messageObject) 56 { 57 // Send a raw message to the backend. Mostly used to test the backend's error handling. 49 58 return new Promise((resolve, reject) => { 50 this._dispatchTable[++this._requestId] = {resolve, reject}; 51 let messageObject = {method, params, id: this._requestId}; 52 this.sendMessage(messageObject); 59 let requestId = messageObject.id; 60 61 // If the caller did not provide an id, then make one up so that the response 62 // can be used to settle a promise. 63 if (typeof requestId !== "number") { 64 requestId = ++this._requestId; 65 this._placeholderRequestIds.push(requestId); 66 } 67 68 this._dispatchTable[requestId] = {resolve, reject}; 69 this._sendMessage(messageObject); 53 70 }); 54 71 } … … 66 83 } 67 84 }); 85 } 86 87 InspectorProtocol._sendMessage = function(messageObject) 88 { 89 let messageString = typeof messageObject !== "string" ? JSON.stringify(messageObject) : messageObject; 90 91 if (ProtocolTest.dumpInspectorProtocolMessages) 92 console.log(`frontend: ${messageString}`); 93 94 InspectorFrontendHost.sendMessageToBackend(messageString); 68 95 } 69 96 … … 94 121 } 95 122 96 InspectorProtocol.sendMessage = function(messageObject)97 {98 // This matches the debug dumping in InspectorBackend, which is bypassed99 // by InspectorProtocol. Return messages should be dumped by InspectorBackend.100 if (ProtocolTest.dumpInspectorProtocolMessages)101 console.log("frontend: " + JSON.stringify(messageObject));102 103 InspectorFrontendHost.sendMessageToBackend(JSON.stringify(messageObject));104 }105 106 123 InspectorProtocol.checkForError = function(responseObject) 107 124 { … … 122 139 // If the message has an id, then it is a reply to a command. 123 140 let messageId = messageObject.id; 141 142 // If the id is 'null', then it may be an error response. 143 if (messageId === null) 144 messageId = InspectorProtocol._placeholderRequestIds.shift(); 145 146 // If we could figure out a requestId, then dispatch the message. 124 147 if (typeof messageId === "number") { 125 148 let handler = InspectorProtocol._dispatchTable[messageId]; … … 132 155 let {resolve, reject} = handler; 133 156 if ("error" in messageObject) 134 reject(messageObject.error .message);157 reject(messageObject.error); 135 158 else 136 159 resolve(messageObject.result); … … 150 173 let {resolve, reject} = handler; 151 174 if ("error" in messageObject) 152 reject(messageObject.error .message);175 reject(messageObject.error); 153 176 else 154 177 resolve(messageObject.result);
Note:
See TracChangeset
for help on using the changeset viewer.