Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: chrome/test/chromedriver/js/call_function.js

Issue 2620803002: [chromedriver] Use nodeType instead of instanceof. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/chromedriver/test/run_py_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/chromedriver/test/run_py_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698