Chromium Code Reviews| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 */ | 253 */ |
| 254 function wrap(value) { | 254 function wrap(value) { |
| 255 // As of crrev.com/1316933002, typeof() for some elements will return | 255 // As of crrev.com/1316933002, typeof() for some elements will return |
| 256 // 'function', not 'object'. So we need to check for both non-null objects, as | 256 // 'function', not 'object'. So we need to check for both non-null objects, as |
| 257 // well Elements that also happen to be callable functions (e.g. <embed> and | 257 // well Elements that also happen to be callable functions (e.g. <embed> and |
| 258 // <object> elements). Note that we can not use |value instanceof Object| here | 258 // <object> elements). Note that we can not use |value instanceof Object| here |
| 259 // since this does not work with frames/iframes, for example | 259 // since this does not work with frames/iframes, for example |
| 260 // frames[0].document.body instanceof Object == false even though | 260 // frames[0].document.body instanceof Object == false even though |
| 261 // typeof(frames[0].document.body) == 'object'. | 261 // typeof(frames[0].document.body) == 'object'. |
| 262 if ((typeof(value) == 'object' && value != null) || | 262 if ((typeof(value) == 'object' && value != null) || |
| 263 (typeof(value) == 'function' && value instanceof Element)) { | 263 (typeof(value) == 'function' && value.nodeName && |
| 264 value.nodeType == Node.ELEMENT_NODE)) { | |
|
PhistucK
2017/01/13 09:15:40
For consistency, I think you should use the above
samuong
2017/01/13 18:26:42
Sounds reasonable, I've created https://codereview
| |
| 264 var nodeType = value['nodeType']; | 265 var nodeType = value['nodeType']; |
| 265 if (nodeType == NodeType.ELEMENT || nodeType == NodeType.DOCUMENT | 266 if (nodeType == NodeType.ELEMENT || nodeType == NodeType.DOCUMENT |
| 266 || (SHADOW_DOM_ENABLED && value instanceof ShadowRoot)) { | 267 || (SHADOW_DOM_ENABLED && value instanceof ShadowRoot)) { |
| 267 var wrapped = {}; | 268 var wrapped = {}; |
| 268 var root = getNodeRootThroughAnyShadows(value); | 269 var root = getNodeRootThroughAnyShadows(value); |
| 269 wrapped[ELEMENT_KEY] = getPageCache(root, w3cEnabled).storeItem(value); | 270 wrapped[ELEMENT_KEY] = getPageCache(root, w3cEnabled).storeItem(value); |
| 270 return wrapped; | 271 return wrapped; |
| 271 } | 272 } |
| 272 | 273 |
| 273 var obj = (typeof(value.length) == 'number') ? [] : {}; | 274 var obj = (typeof(value.length) == 'number') ? [] : {}; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 var returnValue = wrap(func.apply(null, unwrap(args, cache))); | 347 var returnValue = wrap(func.apply(null, unwrap(args, cache))); |
| 347 } catch (error) { | 348 } catch (error) { |
| 348 status = error.code || StatusCode.UNKNOWN_ERROR; | 349 status = error.code || StatusCode.UNKNOWN_ERROR; |
| 349 var returnValue = error.message; | 350 var returnValue = error.message; |
| 350 } | 351 } |
| 351 return { | 352 return { |
| 352 status: status, | 353 status: status, |
| 353 value: returnValue | 354 value: returnValue |
| 354 } | 355 } |
| 355 } | 356 } |
| OLD | NEW |