| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Enum for WebDriver status codes. | 6 * Enum for WebDriver status codes. |
| 7 * @enum {number} | 7 * @enum {number} |
| 8 */ | 8 */ |
| 9 var StatusCode = { | 9 var StatusCode = { |
| 10 STALE_ELEMENT_REFERENCE: 10, | 10 STALE_ELEMENT_REFERENCE: 10, |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 value.nodeType == NodeType.ELEMENT)) { | 264 value.nodeType == NodeType.ELEMENT)) { |
| 265 var nodeType = value['nodeType']; | 265 var nodeType = value['nodeType']; |
| 266 if (nodeType == NodeType.ELEMENT || nodeType == NodeType.DOCUMENT | 266 if (nodeType == NodeType.ELEMENT || nodeType == NodeType.DOCUMENT |
| 267 || (SHADOW_DOM_ENABLED && value instanceof ShadowRoot)) { | 267 || (SHADOW_DOM_ENABLED && value instanceof ShadowRoot)) { |
| 268 var wrapped = {}; | 268 var wrapped = {}; |
| 269 var root = getNodeRootThroughAnyShadows(value); | 269 var root = getNodeRootThroughAnyShadows(value); |
| 270 wrapped[ELEMENT_KEY] = getPageCache(root, w3cEnabled).storeItem(value); | 270 wrapped[ELEMENT_KEY] = getPageCache(root, w3cEnabled).storeItem(value); |
| 271 return wrapped; | 271 return wrapped; |
| 272 } | 272 } |
| 273 | 273 |
| 274 var obj = (typeof(value.length) == 'number') ? [] : {}; | 274 var obj; |
| 275 for (var prop in value) | 275 if (typeof(value.length) == 'number') { |
| 276 obj[prop] = wrap(value[prop]); | 276 obj = []; |
| 277 for (var i = 0; i < value.length; i++) |
| 278 obj[i] = wrap(value[i]); |
| 279 } else { |
| 280 obj = {}; |
| 281 for (var prop in value) |
| 282 obj[prop] = wrap(value[prop]); |
| 283 } |
| 277 return obj; | 284 return obj; |
| 278 } | 285 } |
| 279 return value; | 286 return value; |
| 280 } | 287 } |
| 281 | 288 |
| 282 /** | 289 /** |
| 283 * Unwraps the given value by converting from object IDs to the cached | 290 * Unwraps the given value by converting from object IDs to the cached |
| 284 * objects. | 291 * objects. |
| 285 * | 292 * |
| 286 * @param {*} value The value to unwrap. | 293 * @param {*} value The value to unwrap. |
| 287 * @param {Cache} cache The cache to retrieve wrapped elements from. | 294 * @param {Cache} cache The cache to retrieve wrapped elements from. |
| 288 * @return {*} The unwrapped value. | 295 * @return {*} The unwrapped value. |
| 289 */ | 296 */ |
| 290 function unwrap(value, cache) { | 297 function unwrap(value, cache) { |
| 291 if (typeof(value) == 'object' && value != null) { | 298 if (typeof(value) == 'object' && value != null) { |
| 292 if (ELEMENT_KEY in value) | 299 if (ELEMENT_KEY in value) |
| 293 return cache.retrieveItem(value[ELEMENT_KEY]); | 300 return cache.retrieveItem(value[ELEMENT_KEY]); |
| 294 | 301 |
| 295 var obj = (typeof(value.length) == 'number') ? [] : {}; | 302 var obj; |
| 296 for (var prop in value) | 303 if (typeof(value.length) == 'number') { |
| 297 obj[prop] = unwrap(value[prop], cache); | 304 obj = []; |
| 305 for (var i = 0; i < value.length; i++) |
| 306 obj[i] = unwrap(value[i], cache); |
| 307 } else { |
| 308 obj = {}; |
| 309 for (var prop in value) |
| 310 obj[prop] = unwrap(value[prop], cache); |
| 311 } |
| 298 return obj; | 312 return obj; |
| 299 } | 313 } |
| 300 return value; | 314 return value; |
| 301 } | 315 } |
| 302 | 316 |
| 303 /** | 317 /** |
| 304 * Calls a given function and returns its value. | 318 * Calls a given function and returns its value. |
| 305 * | 319 * |
| 306 * The inputs to and outputs of the function will be unwrapped and wrapped | 320 * The inputs to and outputs of the function will be unwrapped and wrapped |
| 307 * respectively, unless otherwise specified. This wrapping involves converting | 321 * respectively, unless otherwise specified. This wrapping involves converting |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 var returnValue = wrap(func.apply(null, unwrap(args, cache))); | 361 var returnValue = wrap(func.apply(null, unwrap(args, cache))); |
| 348 } catch (error) { | 362 } catch (error) { |
| 349 status = error.code || StatusCode.UNKNOWN_ERROR; | 363 status = error.code || StatusCode.UNKNOWN_ERROR; |
| 350 var returnValue = error.message; | 364 var returnValue = error.message; |
| 351 } | 365 } |
| 352 return { | 366 return { |
| 353 status: status, | 367 status: status, |
| 354 value: returnValue | 368 value: returnValue |
| 355 } | 369 } |
| 356 } | 370 } |
| OLD | NEW |