* Converts an object to its JSON representation in the WebDriver wire protocol. * When converting values of type object, the following steps will be taken: * * if the object is a WebElement, the return value will be the element's * server ID * if the object defines a {@link Sym
(obj)
| 146 | * representation. |
| 147 | */ |
| 148 | async function toWireValue(obj) { |
| 149 | let value = await Promise.resolve(obj) |
| 150 | if (value === void 0 || value === null) { |
| 151 | return value |
| 152 | } |
| 153 | |
| 154 | if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') { |
| 155 | return value |
| 156 | } |
| 157 | |
| 158 | if (Array.isArray(value)) { |
| 159 | return convertKeys(value) |
| 160 | } |
| 161 | |
| 162 | if (typeof value === 'function') { |
| 163 | return '' + value |
| 164 | } |
| 165 | |
| 166 | if (typeof value[Symbols.serialize] === 'function') { |
| 167 | return toWireValue(value[Symbols.serialize]()) |
| 168 | } else if (typeof value.toJSON === 'function') { |
| 169 | return toWireValue(value.toJSON()) |
| 170 | } |
| 171 | return convertKeys(value) |
| 172 | } |
| 173 | |
| 174 | async function convertKeys(obj) { |
| 175 | const isArray = Array.isArray(obj) |
no test coverage detected